akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define INF INT_MAX

bool comp(int a,int b){
    return a > b;
}

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

    int N;
    cin >> N;
    map<int,int> m;
    bool ok = true;
    for(int i = 0 ; i < N ; i++){
        int x;cin >> x;
        if(m.count(x) > 0){
            ok = false;
        }else m[x]++;
    }
    if(ok)
        cout << "YES" << '\n';
    else
        cout << "NO" << '\n';

    return 0;
}


Measured memory_bytes: 9600
//?????????????????????????????????9?????????
//??????1?????????????????§????????????????????°???N-1??????
//?????????s???1??\???9??\?????????????????§???s??????????????°???[(s???????????? - 1)/9]???
//????????????????????????????????°???[(s???????????? - 1)/9] + N - 1???
//??????????????°??????Fabre wins, ????????§????????????Audrey wins.

#include <iostream>
#include <string>
using namespace std;

int main()
{
	int n;
	string s;
	
	cin >> n;
	for( int i = 0; i < n; i++ ){
		cin >> s;
		int digitNum = s.length();
		int digitSum = 0;
		for( int j = 0; j < digitNum; j++ ){
			digitSum += s[j] - '0';
		}
		int turnNum = (digitSum - 1) / 9 + digitNum - 1;
		if( turnNum % 2 ){
			cout << "Fabre wins." << endl;
		}
		else{
			cout << "Audrey wins." << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1192
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>

using namespace std;

typedef pair<int,int> P;

long long gcd(long long a,long long b){
	if(b==0) return a;
	return gcd(b,a%b);
}

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

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

	int n;
	cin >> n;

	long long t[n];
	for(int i=0;i<n;i++){
		cin >> t[i];
	}
	sort(t,t+n,greater<long long>());

	long long ans = t[0];
	for(int i=1;i<n;i++){
		ans = lcm(ans,t[i]);
	}
	
	cout << ans << "\n";
	
	return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case,unused_imports)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BinaryHeap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let N:usize = iter.next().unwrap().parse().unwrap();
    let A = (0..3*N)  .map(|_| iter.next().unwrap().parse::<i64>().unwrap()).collect::<Vec<_>>();

    let mut hq = BinaryHeap::new();
    let mut l_sum = Vec::new();
    let mut r_sum = Vec::new();

    for i in 0..N{
        hq.push(-A[i]);
    }
    l_sum.push(-hq.iter().sum::<i64>());

    for i in N..2*N{
        hq.push(-A[i]);
        let p = -hq.pop().unwrap();
        let v = l_sum[i-N];
        l_sum.push(v - p + A[i]);
    }
    let mut hq = BinaryHeap::new();
    for i in 2*N..3*N{
        hq.push(A[i]);
    }
    r_sum.push(hq.iter().sum::<i64>());
    for j in 0..N{
        let i = 2*N-1-j;
        hq.push(A[i]);
        let p = hq.pop().unwrap();
        let v = r_sum[j];
        r_sum.push(v - p + A[i]);
    }

    let ans = (0..N+1).map(|i| l_sum[i]-r_sum[N-i]).max().unwrap();

    println!("{}",ans);
}

Measured memory_bytes: 18424
import java.util.*;

public class Main{
	public static void main(String[]args){

		Scanner sc=new Scanner(System.in);

		int a=sc.nextInt();
		int b=sc.nextInt();
		if(a>b){
			System.out.println(a-1);
		}else{
			System.out.println(a);
		}

	}
}


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

const int N = 5e5 + 100;

char s[N];
int a[N], cnt;
int n;

int main () {
	scanf("%s", s); n = strlen(s);
	reverse(s, s + n);
	for (int i = 0; i < n; ++i) a[i] = (s[i] - '0') * 9;
	for (int i = 0; i < n; ++i) {
		a[i + 1] += a[i] / 10;
		a[i] %= 10;
		if (i == n - 1 && a[n]) ++n;
		cnt += a[i];
	}
	for (int k = 1, i; ; ++k) {
		for (cnt += 9, a[i = 0] += 9; a[i] > 9; ++i) {
			cnt -= 9;
			++a[i + 1];
			a[i] -= 10;
		}
		if (9 * k >= cnt) { printf("%d\n", k); break; }
	}
	return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll l;

struct edge {
    ll from,to,weight;
    edge(ll from, ll to, ll weight) : from(from), to(to), weight(weight){}
};

int main(void) {
    cin >> l;
    vector<edge> e;
    ll cnt;
    ll max_n=0;
    for(cnt=1;(1LL<<cnt)<=l;cnt++){
       e.push_back(edge(cnt,cnt+1,0)); 
       e.push_back(edge(cnt,cnt+1,(1LL<<cnt-1))); 
        max_n+=1LL<<cnt-1;
    }
    ll cur;
    while(max_n!=l-1){
        cur=log2(l-max_n-1)+1;
        DEBUG{
            cout << cur << endl;
        }
        e.push_back(edge(cur,cnt,max_n+1));
        max_n+=(1LL<<cur-1);
    }
    cout << cnt << " " << e.size() << endl;
    for(auto x:e){
        printf("%lld %lld %lld\n",x.from, x.to, x.weight);
    }

    return 0;
}


Measured memory_bytes: 512
from collections import deque
from collections import Counter
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
dis_lis = deque()
for i in range(N-1):
    for j in range(i+1, N):
        if abs(i-j)==1:
            dis_lis.append(1)
        else:
            min1 = abs(i-j)
            min2 = abs(i-X)+abs(j-Y)+1
            min3 = abs(i-Y)+abs(j-X)+1
            dis_lis.append(min(min1, min2, min3))
c = Counter(dis_lis)
for i in range(1, N):
    print(c[i])

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

ll mod_pow(ll a, ll b) {
	ll 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<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 T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}

int a, b, now, ans, dis[100005];
int main() {
	cin >> a >> b;
	for (int i = 1; i < a; ++i) {
		cin >> dis[i];
	}

	for (int i = 2; i < a; ++i) {
		dis[i] += dis[i - 1];
	}

	for (int i = 0; i < b; ++i) {
		int n;
		cin >> n;
		ans += abs(dis[now + n] - dis[now]);
		now += n;
		ans %= 100000;
	}

	cout << ans % 100000 << endl;
}



Measured memory_bytes: 3468
N, K = map(int, input().split())
D = list(map(int, input().split()))

d = set()
for i in range(K):
    d.add(str(D[i]))


for i in range(N, 100000):
    s = str(i)
    li = list(s)
    nowset = set(li)
    if not nowset & d:
        print(i)
        exit()



Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    string s; cin>>s;
    bool x=false;
    for(int i=0;i<s.size();i++){
        if(s[i]=='C'){
            x=true;
        }
        if(s[i]=='F'&&x){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
int main()
{
    ios;
    ll n , k;
    cin >> n >> k;
    ll dp[n+1];
    for(ll i=0;i<=n;++i) dp[i]= 3e18;
    vector<ll> v;
    v.push_back(0);
    for(ll i =1 ;i<=n ; ++i){
        ll x;
        cin >> x;
        v.push_back(x);
    }
    dp[1] = 0 ;
    dp[2] = abs(v[2] - v[1]);
    ll cost = 3e18;
    for(ll i =3 ; i <= n ; ++i){
        cost = 3e18;
        for(ll j=i-k;j<=i-1;++j){
            if(j<1 ) continue;

            ll c1 = dp[j] + abs(v[i]-v[j]);
            cost = min(cost , c1);
            //cout <<"i is "<<i <<" j is " << j << " c1 is "<< c1 << " cost is " <<cost <<endl ;
            dp[i] = min(dp[i] , cost);
            //cout <<" dp is " << dp[i] << endl ;
        }
    }
    cout << dp[n] << endl ;
    return 0 ;
}


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

using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    for(int i=0;i<4;i++){
        if(i==0){
            for(int j=sx;j<tx;j++){
                cout<<'R';
            }
            for(int j=sy;j<ty;j++){
                cout<<'U';
            }
        }else if(i==1){
            for(int j=tx;j>sx;j--){
                cout<<'L';
            }
            for(int j=ty;j>sy;j--){
                cout<<'D';
            }
        }else if(i==2){
            cout<<'D';
            for(int j=sx;j<tx+1;j++){
                cout<<'R';
            }
            for(int j=sy-1;j<ty;j++){
                cout<<'U';
            }
            cout<<'L';
        }else{
            cout<<'U';
            for(int j=tx;j>sx-1;j--){
                cout<<'L';
            }
            for(int j=ty+1;j>sy;j--){
                cout<<'D';
            }
            cout<<'R'<<endl;
        }
    }
    return 0;
}

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

#define int long long

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)
#define rrep(i, s) rep(i, s, >= 0, --)

#define all(c) begin(c), end(c)

template<typename T, typename U>bool maxup(T& a, U&& b) { if (a < b) { a = b; return true; }; }
template<typename T, typename U>bool minup(T& a, U&& b) { if (a > b) { a = b; return true; }; }

#define X first
#define Y second

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

int dp[51][2501];

signed main() {
	int n, a; cin >> n >> a;
	V xs(n); input(xs);
	dp[0][0] = 1;
	rep(i, n) for (int k = n; k >= 1; k--) rep(j, 2501) if(j - xs[i] >= 0) {
		dp[k][j] += dp[k - 1][j - xs[i]];
	}
	int ans = 0;
	rep(i, 1, n + 1) rep(j, 2501) if(dp[i][j]) ans += ((j % i == 0) && (j / i == a) ? dp[i][j] : 0);
	cout << ans << endl;
	system("pause");
}

Measured memory_bytes: 1408
def nCk(n, k):
    if k > n or min(n, k) < 0:
        return 0
    res = 1
    for i in range(1, k + 1):
        res = res * (n - i + 1) // i
    return res

def solveSmaller():
    return 9 ** k * nCk(n - 1, k)

def solveDp():
    global k
    dp = [[[0 for _ in range(2)] for _ in range(k + 1)] for _ in range(n)]  # i, used k, smaller
    dp[0][1][0] = 1
    dp[0][1][1] = int(s[0]) - 1
    cnt = 1
    for i in range(1, n):
        cnt += s[i] != '0'
        for k in range(1, k + 1):
            dp[i][k][0] = cnt == k
            dp[i][k][1] = dp[i - 1][k][1] + \
                          (dp[i - 1][k][0] if s[i] != '0' else 0) + \
                          dp[i - 1][k - 1][1] * 9 + \
                          dp[i - 1][k - 1][0] * max(0, int(s[i]) - 1)
    return dp[n - 1][k][0] + dp[n - 1][k][1]

s = input()
k = int(input())
n = len(s)
print(solveSmaller() + solveDp())

Measured memory_bytes: 63020
h, w, d = map(int, input().split())
l = [[0]]*(h*w+1)
for i in range(h):
  temp = list(map(int, input().split()))
  for j in range(len(temp)):
    l[temp[j]] = [i+1, j+1]

c = [0]*(h*w+1)
for i in range(d+1, h*w+1):
  pi, pj = l[i]
  qi, qj = l[i-d]
  c[i] = c[i-d] + abs(pi - qi) + abs(pj - qj)

q = int(input())

for i in range(q):
  l, r = map(int, input().split())
  print(c[r] - c[l])

Measured memory_bytes: 18508
#include<iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
#define fi(p) for(int i=0;i<(p);i++)
#define ce(d) cout<<d<<endl;

using namespace std;

const int MAX_N = 100000;
const int MAX_W = 100000;


int A[MAX_N+1];
int B[MAX_N+1];

void solve() {
	int n;
	
	cin >> n;

	vector<float> a(n);
	vector<float> b(n);

	fi(n) {
		cin >> a[i];
	}

	sort(a.begin(),a.end());
	
	fi(n-1) {
		float a1 = a[0];
		float a2 = a[1];
		a.insert(a.begin(),(a1+a2)/2);
		a.erase(a.begin() + 1);
		if (a.size() > 1) {
			a.erase(a.begin() + 1);
		}

	}

	ce(a[0])


}

int main()
{

	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    if (n % 2 == 0)
        cout << n << endl;
    else
        cout << 2 * n << endl;
    return 0;
}

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

#define SIZE 100005
#define INF 1000000000

vector<int> vec[SIZE];
int R[SIZE],L[SIZE];
int id[SIZE];
bool ans=true;
int N,K;
int a,b;

inline void solve(int v=0,int p=-1)
{
	L[v]=-INF-1,R[v]=INF+1;
	if(id[v]!=-1)	R[v]=L[v]=id[v];
	for(int i=0;i<vec[v].size();i++)
	{
		int to=vec[v][i];
		if(to==p)	continue;
		solve(to,v);
		if(L[to]<-INF/2)	continue;
		if(L[v]<-INF/2)
		{
			L[v]=L[to]-1;
			R[v]=R[to]+1;
		}
		else
		{
			if(abs(L[v])%2==abs(L[to])%2)
			{
				ans=false;
				return;
			}
			L[v]=max(L[v],L[to]-1);
			R[v]=min(R[v],R[to]+1);
		}
	}
	if(L[v]>R[v])	ans=false;
}

inline void make(int v=0,int p=-1)
{
	if(v==0&&id[v]==-1)	id[v]=L[v];
	for(int i=0;i<vec[v].size();i++)
	{
		int to=vec[v][i];
		if(to==p)	continue;
		if(id[to]==-1)
		{
			if(L[to]<=id[v]-1&&R[to]>=id[v]-1) id[to]=id[v]-1;
			else id[to]=id[v]+1;
		}
		make(to,v);
	}
}

int main()
{
	scanf("%d",&N);
	for(int i=0;i<N-1;i++)
	{
		scanf("%d %d",&a,&b);
		--a,--b;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	scanf("%d",&K);
	memset(id,-1,sizeof id);
	for(int i=0;i<K;i++)
	{
		scanf("%d %d",&a,&b);
		a--;
		id[a]=b;
	}
	solve();
	if(!ans)
	{
		puts("No");
	}
	else
	{
		make();
		puts("Yes");
		for(int i=0;i<N;i++)
			printf("%d\n",id[i]);
	}
	return 0;
}

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main(){
    int n;
    cin >> n;
    vector<int> a;
    rep(i, n) {
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    sort(a.begin(), a.end());
    int a_min = a[0];
    int a_max = a[a.size()-1];
    cout << a_max - a_min << endl;

    return 0;
}

Measured memory_bytes: 256
while True:
  a, op, b, *_ = input().split()

  if op == "?": break

  r = 0
  a = int(a)
  b = int(b)

  if op == "+":
    r = a + b
  elif op == "-":
    r = a - b
  elif op == "*":
    r = a * b
  elif op == "/":
    r = a / b

  print(int(r))




Measured memory_bytes: 5592
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

// https://atcoder.jp/contests/abc109/tasks/abc109_b
void solve() {
    int N;
    cin >> N;
    set<string> used;
    char back = '.';
    REP(_,N) {
        string s;
        cin >> s;
        if ((back == '.' || back == s[0]) && used.count(s) == 0) {
            back = s[s.size()-1];
            used.insert(s);
        } else {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[200010][2];
ll dp[20011];
int main()
{
    int i, j, k;
    ll H, N;
    ll ans = 1e11;
    cin >> H >> N;
    for(i = 1; i <= N; i++) {
        cin >> a[i][0] >> a[i][1];
    }
    memset(dp, 0x3f, sizeof(dp));
    dp[0] = 0;
    for(i = 1; i <= N; i++) {
        for(j = 1; j <= 20000; j++) {
            if(j-a[i][0] >= 0) {
                dp[j] = min(dp[j], dp[j-a[i][0]]+a[i][1]);
            }
        }
    }
    for(i = H; i <= 20000; i++) {
        ans = min(dp[i], ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    long long int x;
    vector<long long int > v;
    cin>>n;
    while(n--)
    {
        cin>>x;
        v.push_back(x);
    }
    map< long long int, int> m;
    for(auto u: v)
    {
        m[u]++;
    }
    int ans=0;
    for(auto u: m )
    {
        if(u.second >= u.first)
        ans+=abs(u.first - u.second);
        else ans+=u.second;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9844
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int h = Integer.parseInt(sc.next());
        int n = Integer.parseInt(sc.next());
        int[] an = new int[n];
        for(int i=0;i<n;i++){
            an[i] = Integer.parseInt(sc.next());
        }
        int sum  = 0;
        for(int j : an){
            sum = sum + j;
        }
        if(sum < h){
            System.out.println("No");
        }else{
            System.out.println("Yes");

        }

    }
}

Measured memory_bytes: 48200
#include <iostream>
#include <queue>
using namespace std;

int main(){
    int N,M;
    cin >> N >> M;
    int i,j;
    long int A;
    long int ans=0;

    priority_queue<long int> que;

    for(i=0; i<N; i++){
        cin >> A;
        que.push(A);
    }

    for(i=0; i<M; i++){
        que.push(que.top()/2);
        que.pop();
    }

    for(j=0; j<N; j++){
        ans+=que.top();
        que.pop();
    }

    cout << ans << endl;

    return 0;
}

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 1e2;
int n, a[nsz + 5], cnt[nsz + 5];

int main() {
    ios::sync_with_stdio(0);
    cin >> n;
    cont (i, n) {
        cin >> a[i];
        ++cnt[a[i]];
    }
    sort(a + 1, a + n + 1);
    int mn = a[1], mx = a[n];
    if (cnt[mn] == 1) {
        if (mx != 2 * mn) {
            cout << "Impossible" << ln;
            return 0;
        }
        circ (d, mn + 1, mx) {
            if (cnt[d] < 2) {
                cout << "Impossible" << ln;
                return 0;
            }
        }
    } else if (cnt[mn] == 2) {
        if (mx != 2 * mn - 1) {
            cout << "Impossible" << ln;
            return 0;
        }
        circ (d, mn + 1, mx) {
            if (cnt[d] < 2) {
                cout << "Impossible" << ln;
                return 0;
            }
        }
    } else {
        cout << "Impossible" << ln;
        return 0;
    }
    cout << "Possible" << ln;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
const int INF =100100100;
const int MOD = (int)1e9+7;
const double EPS = 1e-9;
typedef long long ll;
typedef long li;
#define pb push_back 
#define mp make_pair

signed main (){	
	map<string,bool> maps;
	int nn;
	cin >> nn;
	string temp[nn];
	rep(i,nn){
		cin >> temp[i];
		if(maps[temp[i]]){
			cout << "No" << endl;
			return 0;
		}
		maps[temp[i]] = true;
		if(i == 0) continue;
		else if(temp[i][0] != temp[i-1][temp[i-1].length()-1]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
 
const ll MOD=1e9+7;
const ll INF=1e18;
 
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};


bool prime[300100];
int p[] = {1,6};

int main(){
    prime[6] = true;
    for(int k = 0;k < 2;k++){
        for(int i = 1;7*i+p[k] < 300000;i++){
            prime[7*i+p[k]] = true;
        }
    }

    for(int i = 0;7*i+1 < 300000;i++){
        for(int j = 0;j < 2;j++){
            int num = 7*i+p[j];
            if(num == 1 || prime[num] == false)continue;
            for(int jj = 0;jj < 2;jj++){
                for(int ii = 0;(7*ii+p[jj])*num < 300000;ii++){
                    int num2 = (7*ii+p[jj])*num;
                    if(num2 == num) continue;
                    prime[num2] = false;
                }
            }
        }
    }

    int n;
    while(true){
        cin >> n;
        if(n == 1) break;
        cout << n << ":";
        for(int i = 2;i <= n;i++){
            if(prime[i] == false || n % i != 0) continue;
            if( ((n/i)-1)%7 == 0 || ((n/i)-6)%7 == 0) cout << " " << i;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3352
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n, a; cin >> n >> a;
    vector<ll> x(n);
    rep(i, n) cin >> x[i];
    ll mx = *max_element(all(x));
    ll dp[n+10][n+10][mx * n + 10];
    rep(i, n + 1) {
        rep(j, n + 1) {
            rep(k, mx * n + 1) {
                dp[i][j][k] = 0;
            }
        }
    }

    rep(j, n + 1 ) {
        rep(k, n + 1) {
            rep(s, mx * n + 1) {
                if (j == 0 && k == 0 && s == 0) dp[j][k][s] = 1;
                else if (j >= 1 && s < x[j-1]) dp[j][k][s] = dp[j-1][k][s];
                else if (j >= 1 && k >= 1 && s >= x[j-1]) dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j-1]];
                else dp[j][k][s] = 0;
            }
        }
    }

    ll count = 0;
    for (size_t i = 1; i <= n; i++) {
        count += dp[n][i][i * a];
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 61440
n,a,b=map(int,input().split())

if (a-b)%2==0:
  print(abs(a-b)//2)
else:
  if (a+b)//2<=n//2:
    if abs(a-b)==1:
      print(min(a,b)-1+1)
    else:
      print(min(a,b)-1+1+(abs(a-b)-1)//2)
  else:
    if abs(a-b)==1:
      print(n-max(a,b)+1)
    else:
      print(n-max(a,b)+1+(abs(a-b)-1)//2)


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

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
  
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define ll long long
#define fill fill_n
#define pf push_front
#define pb push_back
#define FOR(i,l,r) for(int i=l;i<r;i++)
#define ROF(i,r,l) for(int i=r;i>=l;i--)
#define all(v) (v).begin(),(v).end()
#define ff first
#define ss second
typedef vector<int> vi;
typedef vector<ll> vli;
typedef vector<pair<int,int>> vpi;

const int M = 1e9+7;
const int N = 2e5;
ll po(int,int);


void solve(){
    int n;cin>>n;
    pair<int,int> p[n];
    FOR(i,0,n){
        cin>>p[i].ff>>p[i].ss;
    }
    FOR(i,0,n-2){
        if(p[i].ff==p[i].ss &&(p[i+1].ff==p[i+1].ss)&&(p[i+2].ff==p[i+2].ss)){
            cout<<"Yes\n";
            return;
        }
    }
    
    cout<<"No\n";

}




int main() {
   
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);cout.tie(NULL);
    
   #ifndef ONLINE_JUDGE 
   freopen("input.txt", "r", stdin);  
   freopen("output.txt", "w", stdout); 
   #endif 

    int t=1;
    //cin>>t;
    FOR(i,1,t+1){
        //cout<<"Case #"<<i<<": "; 
        solve();
        
    }
    
    return 0;
    
    
}


ll po(int a,int b){
    if(b==0) return 1;
    ll ans=1;
    if(b%2==0){
        ans = po(a,b/2)%M;
        ans=(ans%M * ans%M)%M;
    }
    else{
        ans = po(a,(b-1)/2)%M;
        ans = (ans%M * ans%M * a)%M;
    }
    return ans%M;
}



Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>

using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		char c;
		cin >> c;
		if (i == K - 1) {
			cout << (char)(c - 'A' + 'a');
		}
		else {
			cout << c;
		}
	}
	return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Data.List
import Data.Bits
import Debug.Trace
import Data.Maybe
import qualified Data.ByteString.Char8 as C

main :: IO ()
main = do
  [n, m] <- readIntegers
  inputs <- readNIntegers (fromIntegral n)
  print $ solve n m inputs

solve n m inputs = solveSub 0 m sorted
  where
    solveSub money _ [] = money
    solveSub money remain !(x:xs) =
      if b > remain
        then money + a * remain
        else solveSub (money + a * b) (remain - b) xs
      where
        a = x !! 0
        b = x !! 1
    sorted = sortOn (!! 0) inputs

-- 以下ライブラリ

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

readNInts :: Int -> IO [[Int]]
readNInts = flip replicateM readInts

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . C.readInteger) . C.words <$> C.getLine

readNIntegers :: Int -> IO [[Integer]]
readNIntegers = flip replicateM readIntegers

getNLns :: Int -> IO [String]
getNLns = flip replicateM getLine

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

int m, d;

int main()
{
    cin >> m >> d;
    int ans = 0;
    for (int i = 1; i <= m; ++i)
    {
        for (int j = 10; j <= d; ++j)
        {
            if ((j % 10) >= 2 && (j / 10) >= 2 && (j % 10) * (j / 10) == i)
            {
                ++ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define SUBIF(a, b, x) ((x) ? (b) : (a))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define pb push_back
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using namespace std;


int gcd(int a, int b){
	if(a < b) swap(a, b);
	int r = a%b;
	while(r > 0){
		a = b;
		b = r;
		r = a%b;
	}
	return b;
}


llint lcm(int a, int b){
	return a*b/gcd(a, b);
}


signed main(){
	int N;
	cin >> N;

	cout << lcm(N, 2) << endl;

	return 0;
}


Measured memory_bytes: 256
def solve():
    a = read()
    result = think(a)
    write(result)


def read():
    n = read_int(1)[0]
    return read_int(n)


def read_int(n):
    return list(map(int, read_line().split(' ')))[:n]


def read_float(n):
    return list(map(float, read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a):
    n = len(a)
    dp = [[None for x in range(n)] for y in range(n)]
    for i in range(len(dp)):
        dp[i][i] = a[i]
    for l in range(n - 2, -1, -1):
        for r in range(l + 1, n):
            dp[l][r] = max(a[l] - dp[l + 1][r], a[r] - dp[l][r - 1])
    return dp[0][n - 1]


def write(result):
    print(result)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 169864
#include <bits/stdc++.h>
#define rep(k,i,n) for(long long i=k;i<n;++i)
using namespace std;
typedef long long ll;
int main(void){
    // Your code here!
    ll N,M;
    cin>>N>>M;
    priority_queue <ll> A;
    rep(0,i,N){
        ll B;
        cin>>B;
        A.push(B);
    }
    rep(0,i,M){
        ll B=A.top();
        A.pop();
        A.push(B/2);
    }
    ll ans=0;
    while(!A.empty()){
        ans+=A.top();
        A.pop();
    }
    cout<<ans<<endl;
}

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

int main(void){
    int A, B;
    cin >> A >> B;
    int a, b, c, d;
    int sum{0};
    for(int i{A}; i<=B; ++i){
        a = i/10000;
        b = i/1000%10;
        c = i/10%10;
        d = i%10;
        if(a==d and b==c)
            ++sum;
    }
    cout << sum << endl;

}


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

using namespace std;

long long dp(int N, int h[]) {
  long long c[N + 1];
  c[0] = c[1] = 0;
  c[2] = c[1] + abs(h[2] - h[1]);
  for (int i = 3; i <= N; i++) {
    c[i] = min(c[i - 1] + abs(h[i] - h[i - 1]), c[i - 2] + abs(h[i] - h[i - 2]));
  }
  return c[N];
}

int main()
{
  int N; cin >> N;
  int h[N + 1];
  h[0] = 0;

  for (int i = 1; i <= N; i++) {
    cin >> h[i];
  }
  cout << dp(N, h) << endl;
  return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define en '\n'
#define pb push_back
#define mp make_pair
#define P pair<int, int>

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;

struct aaa {
	aaa() {
		cin.tie(0);
		ios::sync_with_stdio(0);
		cout << fixed << setprecision(20);
	};
}aaaaa;

int main() {
	string s;
	cin >> s;

	string t = "keyence";

	bool ans = false;

	if (s.substr(0, 7) == t) {
		ans = true;
	}

	if (s.substr(s.size() - 7) == t) {
		ans = true;
	}

	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == t[cnt]) {
			cnt++;
		}
		else {
			break;
		}
	}

	if (s.substr(s.size() - (7 - cnt), 7 - cnt) == t.substr(cnt, 7 - cnt)) {
		ans = true;
	}

	if (ans) cout << "YES" << en;
	else cout << "NO" << en;
}

Measured memory_bytes: 256
use std::io;
use std::str::FromStr;
use std::cmp::{max,min};

static MOD: u64 = 1_000_000_007;

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn main() {
    let (n, m) = input_tuple();
    let mut ans = 1;
    if n > m + 1 || m > n + 1 {
        println!("0");
        return;
    }

    for i in 1..max(n+1,m+1) {
        ans *= i;
        ans %= MOD;
        if i == min(n, m) {
            ans *= ans;
            ans %= MOD;
        }
    }
    if n == m {
        println!("{}", ans * 2 % MOD);
    } else {
        println!("{}", ans);
    }

}


Measured memory_bytes: 4352
main = 
    interact (calc . map (read) . words)

calc :: [Int] -> String
calc (0:0:_) = ""
calc (h:w:xs) = 
    ln h w h ++ "\n" ++ calc xs

ln :: Int -> Int -> Int -> String
ln 0 _ _ = ""
ln h w max
    | h == 1 || h == max = (replicate w '#') ++ "\n" ++ ln (h-1) w max
    | otherwise = "#" ++ (replicate (w - 2) '.') ++ "#" ++ "\n" ++ ln (h-1) w max



Measured memory_bytes: 4832
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
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())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

a,b,x = lr()
inda = a//x
if a%x==0:
    inda-=1
indb = b//x
if a!=b:
    print(indb-inda)
else:
    if a%x==0:
        print(1)
    else:
        print(0)

Measured memory_bytes: 77368
#include<bits/stdc++.h>
#define N 100009
using namespace std;
typedef long long ll;
int head[N],tot,dp[N],du[N],rt,n;
inline ll rd(){
    ll x=0;char c=getchar();bool f=0;
    while(!isdigit(c)){if(c=='-')f=1;c=getchar();}
    while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
    return f?-x:x;
}
struct edge{int n,to;}e[N<<1];
inline void add(int u,int v){
    e[++tot].n=head[u];e[tot].to=v;head[u]=tot;du[u]++;
}
void dfs(int u,int fa){
    int cnt=0;;
    for(int i=head[u];i;i=e[i].n)if(e[i].to!=fa){
        int v=e[i].to;
        dfs(v,u);
        if(!dp[v])cnt++;
        dp[u]+=dp[v];
    }
    cnt--;
    if(cnt>0)dp[u]+=cnt;
}
int main(){
    n=rd();
    if(n==1){
        puts("0");
        return 0;
    }
    int u,v;
    for(int i=1;i<n;++i){
        u=rd()+1;v=rd()+1;
        add(u,v);add(v,u);
    }
    for(int i=1;i<=n;++i)if(du[i]>2){
        rt=i;break;
    }
    if(rt){
        dfs(rt,0);
        printf("%d",dp[rt]);
    }
    else puts("1");
    return 0;
}

Measured memory_bytes: 6400
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}



signed main() {
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


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

class D
{
	static void Main()
	{
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var h = read();
		var n = h[0];
		var p = read();
		var map = new int[n + 1].Select(_ => new List<int>()).ToArray();
		foreach (var r in new int[h[1]].Select(_ => read()))
		{
			map[r[0]].Add(r[1]);
			map[r[1]].Add(r[0]);
		}

		var c = 0;
		var used = new bool[n + 1];
		var q = new Queue<int>();
		var l = new List<int>();
		var z = new bool[n + 1];

		for (int i = 1; i <= n; i++)
		{
			if (used[i]) continue;
			used[i] = true;
			q.Enqueue(i);
			l.Add(i);

			while (q.Any())
				foreach (var np in map[q.Dequeue()])
				{
					if (used[np]) continue;
					used[np] = true;
					q.Enqueue(np);
					l.Add(np);
				}
			foreach (var k in l) z[k] = true;
			c += l.Count(x => z[p[x - 1]]);
			l.Clear();
			Array.Clear(z, 0, n + 1);
		}
		Console.WriteLine(c);
	}
}


Measured memory_bytes: 34720
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
//conversion
//------------------------------------------
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();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#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 SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
 
int main(){
  LL N;
  cin >> N;
  LL a[3*N];
  REP(i,3*N) cin >> a[i];
  sort(a,a+3*N);
  LL ans=0;
  LL sum=0;
  LL res=0;
  for(int i=1;i<=3*N-2;i=i+3){
    res+=a[i];
  }
  ans=max(ans,res);
  res=0;
 for(int i=N;i<=3*N-1;i=i+2){
    res+=a[i];
  }
  ans=max(ans,res);

  cout << ans;
  }

Measured memory_bytes: 2560
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

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

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h, w, n,m,k; string s;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}

int main() {
	double a, b, k;
	cin >> a >> b >> k;
	double res = 0;
	if (a * a * b/2 >= k) {
		res = (atan((a * b * b) / (2 * k)) * 180) / 3.14159265358979323846;
	}
	else {
		res = (atan((2 * (a*a*b-k))/ (a * a * a)) * 180) / 3.14159265358979323846;
	}
	
	cout << setprecision(10) << res << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    char c;
    cin >> c;
    char ans = (char)(c + 1);
    cout << ans << endl;
}


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

int main() {
    string S;
    cin >> S;
    int peanokazu = (S.size())/2, ans = 0;
    for (int i=0; i<peanokazu; i++){
        if (S.at(i) != S.at(S.size()-1 - i)){
            ans ++;

        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
N = int(input())
abc = [list(map(int,input().split())) for _ in range(N)]

A = [0]*N
B = [0]*N
C = [0]*N

for i,[a,b,c] in enumerate(abc):
  if i == 0:
    A[0],B[0],C[0] = a,b,c
  else:
    A[i] = max((B[i-1]+a),(C[i-1]+a))
    B[i] = max((A[i-1]+b),(C[i-1]+b))
    C[i] = max((A[i-1]+c),(B[i-1]+c))
  
print(max(A[-1],B[-1],C[-1]))

Measured memory_bytes: 42300
#include<cstdio>
#include<cstring>
typedef long long ll;

const int N=5010;
const int P=1e9+7;
int n;
int head[N],nxt[N<<1],to[N<<1],lst=0;
inline void adde(int x,int y) {
  nxt[++lst]=head[x]; to[lst]=y; head[x]=lst;
}
ll f[N][N],tmp[N],val[N];
int sz[N];
inline int Add(int x,int y) {x+=y; if(x>=P) x-=P; return x;}
void DP(int u,int fr) {
  f[u][1]=1; sz[u]=1;
  for(int i=head[u];i;i=nxt[i]) if(to[i]!=fr) DP(to[i],u);
  for(int i=head[u];i;i=nxt[i])
    if(to[i]!=fr) {
      int v=to[i];
      for(int j=0;j<=sz[u]+sz[v];j++) tmp[j]=0;
      for(int j=0;j<=sz[u];j++)
	for(int k=0;k<=sz[v];k++)
	  tmp[j+k]=Add(tmp[j+k],P-1ll*f[v][k]*f[u][j]%P);
      for(int j=0;j<=sz[u]+sz[v];j++) f[u][j]=tmp[j];
      sz[u]+=sz[v];
    }
  if(sz[u]%2==0) {
    for(int i=2;i<=sz[u];i+=2)
      f[u][0]=Add(f[u][0],P-1ll*f[u][i]*val[i]%P);
  }
}
signed main() {
  scanf("%d",&n);
  for(int i=1;i<n;i++) {
    int x,y; scanf("%d %d",&x,&y);
    adde(x,y); adde(y,x);
  }
  val[2]=1; for(int i=4;i<=n;i++) val[i]=1ll*val[i-2]*(i-1)%P;
  DP(1,0);
  // for(int i=1;i<=n;i++) {
  //   for(int j=0;j<=sz[i];j++)
  //     printf("%lld ",f[i][j]);
  //   printf("\n");
  // }
  printf("%lld\n",f[1][0]);
  return 0;
}


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

#define ll long long
#define int long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf (int)(1e18)
#define ps(x, y) fixed << setprecision(y) << x
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(p) p.begin(), p.end()
#define ub(a, b) upper_bound(all(a), b)
#define lb(a, b) lower_bound(all(a), b)
#define sz(x) (int)x.size()
#define PI 3.14159265
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void run()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
void solution()
{
    string s;
    cin >> s;
    int ans = 0;
    for (auto ele : s)
    {
        ans += (ele - '0');
    }
    if (ans % 9 == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return;
}
int32_t main()
{
    run();
    solution();
    return 0;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int k;cin>>k;
    int a=k/2;
    int b=k-a;
    cout<<a*b<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int K = scanner.nextInt();
    int S = scanner.nextInt();
    int total = 0;
    for (int X = 0; X <= K; X++) {
      total += Math.max(Math.min(K, S - X) - Math.max(S - K - X, 0) + 1, 0);
    }
    System.out.println(total);
  }
}


Measured memory_bytes: 21844