akhauriyash/Code-Regression huggingface dataset:
#include <fstream>
#include <numeric>
#include <unordered_set>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>

#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size())
#define pb push_back
#define ll long long
#define int long long
#define pii pair <int, int>
#define print(x) for(auto it : x) cout << it << ' ';

using namespace std;

const int N = (int)(1e6) + 322;
const int MAXN = (int)(1e7) + 100;
const int inf = (int)(1e18) + 322;
const int mod = 998244353;
const double eps = 1e-6;
#define endl "\n" // remove

vector <int> v;

void gen(int len, int cur, int last) {
    if (len > 10) return;
    v.pb(cur);
    for(int i = 0; i < 10; ++i) {
        if (len == 0) {
            gen(len + 1, cur * 10 + i, i);
        }else if (abs(last - i) <= 1) {
            gen(len + 1, cur * 10 + i, i);
        }
    }
}

signed main () {
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
    gen(0, 0, 0);
    sort(all(v));
    v.resize(unique(all(v)) - v.begin());
    int k; cin >> k;
    cout << v[k];

    return 0;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define repi(i, a, b) for(int i=(a); i>(b); i--)
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define ll long long
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll, ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define fi first
#define se second
#define umap unordered_map
#define uset unordered_set
#define pqueue priority_queue
#define si(a) scanf("%d", &a)
#define sll(a) scanf("%lld", &a)
#define bitcount(x) __builtin_popcount(x)
#define cps CLOCKS_PER_SEC
#define PI acos(-1.0)
#define EPS 1e-9
#define mod 1000000007
#define MOD 1000000007
#define N 205
using namespace std;

template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

template<typename T>
using maxpq = priority_queue<T>;

//All indexing is 0-based
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
			 tree_order_statistics_node_update> ordered_set;
//methods: find_by_order(k); & order_of_key(k);
//To make it an ordered_multiset, use pairs of (value, time_of_insertion)
//to distinguish values which are similar.

//a and b are assumed to be taken modulo p
inline int add(int a, int b, int p = mod){ ll c = a + b; if(c >= p) c -= p; return c;}
inline int sub(int a, int b, int p = mod){ int c = a - b; if(c < 0) c += p; return c;}
inline int mul(int a, int b, int p = mod){ return (a * 1ll * b) % p;}

vi adj[N];

main()
{	
	#ifndef ONLINE_JUDGE
		//freopen("/home/tarun/Desktop/input.txt", "r", stdin);
//		freopen("/home/tarun/Desktop/output.txt", "w", stdout);
	#endif
	sync;
	clock_t clk = clock();
	cerr << "I will return...\n";
	
	int n; cin >> n;
	for(int i = 1; i <= n; i++) {
		for(int j = i; j <= n; j += i){
			adj[j].pb(i);
		}
	}

	int ans = 0;
	rep(i, 1, n+1) {
		if(i % 2 == 1 && adj[i].sz == 8) ans++;
	}

	cout << ans << '\n';

	cerr << "...don't you ever hang your head.\n";
	cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / cps << '\n';
}

//Compile using:
//g++ -o filename.exe --std=c++11 filename.cpp
//Use -D CP for defining a macro CP in the local environment







Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(2000000)


    N = int(input())
    edges = [[]for _ in range(N+1)]
    for _ in range(N-1):
        u,v,w = map(int,input().split())
        edges[u].append((v,w%2))
        edges[v].append((u,w%2))
    colors = [0]*(N+1)
    def dfs(n,p,c):
        colors[n] = c
        for nx,w in edges[n]:
            if nx != p:
                if w%2 == 0:
                    dfs(nx,n,c)
                else:
                    dfs(nx,n,(c+1)%2)

    dfs(1,0,0)
    for i in range(1,N+1):
        print(colors[i])

main()

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)

typedef long long LL;
typedef pair<LL, LL> pii;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;
#define pow10(n) int(1e##n + n)

struct edge
{
    int to;
    LL cost;
};

LL d[pow10(5)];

void solve()
{
    int V;
    cin >> V;
    vector<vector<edge>> adj(V);
    REP0 (i, V - 1)
    {
        int a, b;
        LL c;
        cin >> a >> b >> c;
        a--;
        b--;
        adj[a].push_back(edge{b, c});
        adj[b].push_back(edge{a, c});
        d[i] = LLINF;
    }
    int Q, K;
    cin >> Q >> K;
    K--;

    d[V - 1] = LLINF;
    d[K] = 0;

    // pair<mincost, vertex>
    priority_queue<pii, vector<pii>, greater<pii>> PQ;
    PQ.push(pii(0, K));
    while (PQ.size())
    {
        pii p = PQ.top();
        PQ.pop();
        int v = p.second;
        if (d[v] < p.first)
            continue;
        for (auto e : adj[v])
        {
            if (d[e.to] > d[v] + e.cost)
            {
                d[e.to] = d[v] + e.cost;
                PQ.push(pii(d[e.to], e.to));
            }
        }
    }

    REP0 (i, Q)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        std::cout << d[x] + d[y] << endl;
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


Measured memory_bytes: 11120
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	long long ans=0;
	if(a==0)
	{
		ans=ans+b/c+1;
		printf("%lld\n",ans);
	}
	else if(b==0)
		printf("1\n");
	else
	{
		ans=ans+b/c-(a-1)/c;
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 256
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#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 rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000000ll
#define all(x) x.begin(),x.end()
#define fi first
#define se second
using pint = pair<int,int>;
using vec = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
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; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    ll n;;
    cin>>n;
    vll a(n);
    vll cnt(200001,0);
    ll ans=0;
    rep(i,n){
        cin>>a[i];
        cnt[a[i]]++;
    }
    auto c = a;
    sort(all(a));
    ans = a[n-1];

    rep(i,n){
        if(ans>c[i]){
            cout<<ans<<endl;
        }else if(ans==c[i]){
            if(cnt[c[i]]>=2) cout<<ans<<endl;
            else cout<<a[n-2]<<endl;   
        }
    }
}

Measured memory_bytes: 7888
N, W = map(int, input().split())
WV = [list(map(int, input().split())) for i in range(N)]

dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
for i in range(N):
    for j in range(W+1):
        if j < WV[i][0]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - WV[i][0]] + WV[i][1])


print(dp[-1][-1])


Measured memory_bytes: 171712
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>

using namespace std;
typedef long long ll;

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

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

    for (int i = 0; i <= 10; i++) {
        if(1000*i >= n) {
            cout << 1000 * i - n << "\n";
            break;
        }
        
    }
}

Measured memory_bytes: 3632
def KMP_table(WW):
    TT = [-1] * (len(WW)+2)
    ii = 2
    jj = 0
    TT[0] = -1
    TT[1] = 0
    while ii < len(WW)+1:
        if WW[ii - 1] == WW[jj]:
            TT[ii] = jj + 1
            ii += 1
            jj += 1
        elif jj > 0:
            jj = TT[jj]
        else:
            TT[ii] = 0
            ii += 1
    return TT

def KMP(T):
    ret = -1
    
    m = 0
    i = 0
    RE = []
    while m + i < len(S):
        if W[i] == S[m + i]:
            i += 1
            if i == len(W):
                RE.append(m)
                m = m + i - T[i]
                if i > 0:
                    i = T[i]
        else:
            m = m + i - T[i]
            if i > 0:
                i = T[i]
    return RE

N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
S = ([A[i] ^ A[i-1] for i in range(N)] * 2)[:-1]
W = [B[i] ^ B[i-1] for i in range(N)]

T = KMP_table(W)
for i in KMP(T):
    print(i, A[i] ^ B[0])

Measured memory_bytes: 128208
#include <bits/stdc++.h>
 using namespace std;
#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)

int main() {
  string s;
  cin>>s;
  REP(i,s.size())cout<<'x';
  cout<<endl;
}
  

Measured memory_bytes: 256
// nextmayor.cpp
#include <iostream>
using namespace std;
int next_mayor(int n,int p);
int main()
{
	int n;//????£???? 3 ~ 50
	int p;//?°????????????° 2 ~ 50
	while(true){
	cin >> n >> p;
	if(n==0 && p==0){return 0;}
	cout << next_mayor(n,p) << endl;
	}
	cin.get();
	cin.get();
	return 0;
}
int next_mayor(int n,int p){
	int temoto[50];
	int ishi_all = p;
	for(int syoki=0;syoki<50;syoki++){
		temoto[syoki]=0;//???????????????
	}
	while(true){
		for(int i=0;i<n;i++){
			if(p>0){//?¢???????1??\???
				temoto[i] += 1;//n??????????????????????¢???????
					p -= 1;//?¢?????????????????????????
					if(p==0){//????????????????????´??????????????????
						if(temoto[i] == ishi_all){return i;}
				}
			}else if(p==0){//?¢????????????????
				p = temoto[i];
				temoto[i] = 0;
			}
		}
	}
}

Measured memory_bytes: 1160
#include<cmath>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<string>
#include<map>
typedef long long ll;
using namespace std;
const double pi=4*atan(1.0);
const ll mod=1e9+7;
const int N=100005;
const int inf=0x3f3f3f3f;
bool vis[N];
int dis[N];
int n;
int pre[N];
vector<pair<int,int> >mp[N];
struct node
{
    int id;
    int len;
    friend bool operator <( node A,node B)
    {
        return A.len>B.len;
    }
};
void Dijkstra(int s)
{
    memset(dis,inf,sizeof(dis));
    memset(vis,false,sizeof(vis));
    dis[s]=0;
    priority_queue<node>Q;
    Q.push(node{s,0});
    while(!Q.empty())
    {
        node u=Q.top();
        Q.pop();
        int xx=u.id;
        if(vis[xx])
            continue;
        vis[xx]=true;
        for(int i=0; i<mp[xx].size(); i++)
        {
            int to=mp[xx][i].first;
            if(!vis[to]&&dis[to]>dis[xx]+mp[xx][i].second)
            {
                dis[to]=dis[xx]+mp[xx][i].second;
                Q.push(node{to,dis[to]});
                pre[to]=xx;
            }
        }
    }
}
int main()
{
    int n,m;

    cin>>n>>m;
    for(int i=0; i<m; i++)
    {
        int a,b;
        cin>>a>>b;
        mp[a].push_back(make_pair(b,1));
        mp[b].push_back(make_pair(a,1));
    }
    Dijkstra(1);

    for(int i=2; i<=n; i++)
    {
        if(dis[i]==inf)
        {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    for(int i=2; i<=n; i++)
    {
        printf("%d\n",pre[i]);
    }
    return 0;
}


Measured memory_bytes: 13632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
    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;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
int main(){
    int P,Q,R;
    cin >> P >> Q >> R;
    int sum = P + Q + R;
    cout << sum - max(P,max(Q,R)) << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>

int main(){

    unsigned long a,b,c,d;
    scanf("%ld %ld %ld %ld",&a,&b,&c,&d);
    
    unsigned long count=0;
    count += b-a+1;
    long x=c*d;
    count -= (b/c)-((a-1)/c)+(b/d)-((a-1)/d);

    long r = d % c;
    while(r!=0){
        d=c;
        c=r;
        r=d%c;
    }

    count += (b/(x/c))-((a-1)/(x/c));
        
    printf("%ld\n",count);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
namespace xxx{
using namespace std;
#define FAST_IO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define CaseT int T;cin >> T;for(int cas=1;cas<=T;cas++)
#define TCase int T;scanf("%d",&T);for(int cas=1;cas<=T;cas++)
#define clr(a,b) memset(a,b,sizeof(a))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define _1s __builtin_popcountll
#define sqr(x) ((x)*(x))
#define upd(a,b) (a%b?a/b+1:a/b)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define fst first
#define sec second
#define MAIN int main
#define GG exit(0)
#define bug cout << "!!!" << endl;
#define bugc(x) cout << "! " << (x) << endl;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const double EPS = 1e-8;
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;

inline ll rd(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
 
}using namespace xxx;
const int N = 1e5+20;

ll n, m;
ll ans;

void ck(ll x){
	if(m-x*(n-1)<1) return;
	if((m-x*(n-1))%x==0) ans = max(ans,x);
}

MAIN(){
	cin >> n >> m;
	ans = 1;
	for(ll i=1;i*i<=m;i++){
		if(m%i==0){
			ck(i);
			ck(m/i);
		}
	}
	cout << ans << endl;
	GG;
}

Measured memory_bytes: 256
solv a b k = go (min a b) (k-1) where
  go n k
    | a`mod`n==0 && b`mod`n==0
      = if k==0 then n else go (n-1) (k-1)
    | otherwise = go (n-1) k

main = do
  [a,b,k] <- map read . words <$> getLine
  print $ solv a b k


Measured memory_bytes: 508
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

using namespace std;

int main(void){
    long long money=100;
    int year=0;
    long long x;
    cin>>x;
    while(1){
        money*=1.01;
        year++;
        if(money>=x){
            cout<<year<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3636
n = int(input())
A = list(map(int, input().split()))

B = sorted(A)

median_a = B[n//2 - 1]
median_b = B[n//2]
# print(median_a, median_b)

for i in A:
    if i <= median_a:
        print(median_b)
    else:
        print(median_a)

Measured memory_bytes: 93780
from itertools import accumulate
import sys
input = sys.stdin.buffer.readline


def sieve(n):
    f = []
    is_prime = [True]*(n+1)
    is_prime[0] = False
    is_prime[1] = False

    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]:
            continue
        for j in range(i*2, n+1, i):
            is_prime[j] = False
    for i in range(n+1):
        if is_prime[i]:
            f.append(i)
    return f


s = sieve(10**5)
s = set(s)
number_2017 = [0]*(10**5+1)

for i in range(1, 10**5+1):
    if i % 2 == 0:
        continue
    if i in s and (i+1)//2 in s:
        number_2017[i] = 1


acc = list(accumulate(number_2017))

Q = int(input())
for _ in range(Q):
    l, r = map(int, input().split())
    print(acc[r]-acc[l-1])


Measured memory_bytes: 81600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;cin>>n;
  ll a[n],b[n];
  ll sa=0,sb=0;
  ll d=0;
  for(ll i=0;i<n;i++){
    cin>>a[i];
    sa+=a[i];
  }
  ll e=0;
  for(ll i=0;i<n;i++){
    cin>>b[i];
    sb+=b[i];
    d+=max((ll)0,a[i]-b[i]);
    if(b[i]>a[i])e+=(b[i]-a[i])%2;
  }
  if(sa>sb){
    cout<<"No"<<endl;
    return 0;
  }
  if(sb-sa<d+e){
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;
}

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

int n,now=0;

struct node
{
	int tim,limit;
}a[200005];

bool cmp(node a,node b)
{
	if (a.limit!=b.limit)  return a.limit<b.limit;
	else return a.tim<b.tim;
}

signed main()
{
	cin>>n;
	for (int i=1;i<=n;i++)  cin>>a[i].tim>>a[i].limit;
	
	sort(a+1,a+n+1,cmp);
	
	for (int i=1;i<=n;i++)
	{
		now+=a[i].tim;
		if (now>a[i].limit)  return cout<<"No"<<endl,0;
	}
	cout<<"Yes"<<endl;
	
	return 0;
}

Measured memory_bytes: 3328
#include<iostream> 
using namespace std;
int main(void) {
 int h, w;
 cin >> h >> w;

 string board[50];

 for (int i = 0; i < h; ++i) cin >> board[i];

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

 for (int i = 0; i < h; ++i) {
 for (int j = 0; j < w; ++j) {
 if (board[i][j] == '#') continue;

 int num = 0;
 for (int d = 0; d < 8; ++ d) {
 const int ni = i + dy[d];
 const int nj = j + dx[d];

 if (ni < 0 or h <= ni) continue;
 if (nj < 0 or w <= nj) continue;
 if (board[ni][nj] == '#') num++;
 }

 board[i][j] = char(num + '0');

 }
 }

 for (int i = 0; i < h; ++i) cout << board[i] << endl;

 return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		List<Integer> list = new ArrayList<Integer>();
		List<List<Integer>> listArray = new ArrayList<List<Integer>>();
		for (int i=0;i<N+1;i++) {
			List<Integer> temp = new ArrayList<Integer>();
			listArray.add(temp);
		}
		int result[] = new int[N+1];
		list.add(N+1);
		for (int i=0;i<M;i++) {
			int from = sc.nextInt();
			int to = sc.nextInt();
			if (from ==1) {
				list.add(to);
			} else if (to==1) {
				list.add(from);
			} else {
				List<Integer> temp = listArray.get(from);
				temp.add(to);
				temp = listArray.get(to);
				temp.add(from);
			}
		}
//		Queue<Integer> queue = new ArrayDeque<Integer>();
//		for (int i=0;i<list.size();i++) {
//			queue.add(list.get(i));
//		}
		int count =1;
//		while (queue.isEmpty()!=false) {
//		}
		int before = 0;
		while (list.size()!=0) {
			List<Integer> temp = new ArrayList<Integer> ();
			for (int i=0;i<list.size();i++) {
				if (list.get(i)>N) {
					before = list.get(i)-N;
					continue;
				}
				if (result[list.get(i)]==0) {
					result[list.get(i)] =before;
					temp.add(list.get(i)+N);
					for (int j=0;j<listArray.get(list.get(i)).size();j++) {
						temp.add(listArray.get(list.get(i)).get(j));
					}
				}
			}
			list = temp;
			count ++;
		}
		for (int i=2;i<=N;i++) {
			if (result[i]==0) {
				System.out.println("No");
				System.out.println(i);
				return ;
			}
		}
		System.out.println("Yes");
		for (int i=2;i<=N;i++) {
			System.out.println(result[i]);
		}
	}

}

Measured memory_bytes: 82492
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
const int MOD = 1000000007;


typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

bool pa(string s){
    string rs;
    rs = s;
    reverse(rs.begin(),rs.end());
    rep(i,s.size()/2){
        if(s[i]!=rs[i]){
            return false;
        }
    }
    return true;
}

int main(){
    string s,rs;
    bool ans=false;
    cin>>s;
    if(!pa(s)){
        cout<<"No";
        return 0;
    }
    string t1,t2;
    t1 = s.substr(0,s.size()/2);
    t2 = s.substr(s.size()/2+1,s.size()/2);
    if(pa(t1)&&pa(t2)){
        cout<<"Yes";
        return 0;
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <math.h>
#include <iostream>
#include<string>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
#include <stdlib.h>
using namespace std;

int main()
{
double N;
double a;
double ans=0;
double div=1;
cin >> N;
vector<int> x(N);
vector<int> y(N);
vector<int> order(N);
for(int i=0;i<N;i++)
{
order.at(i)=i;
cin >> x.at(i) >> y.at(i);
}
do {
a=0;
for(int i=0;i<N-1;i++)
{
double X=abs(x.at(order.at(i))-x.at(order.at(i+1)))*abs(x.at(order.at(i))-x.at(order.at(i+1)));
double Y=abs(y.at(order.at(i))-y.at(order.at(i+1)))*abs(y.at(order.at(i))-y.at(order.at(i+1)));
a+=sqrt(X+Y);
}
ans+=a;
}while(next_permutation(order.begin(),order.end()));
for(int i=N;i>0;i--){div*=i;}
ans/=div;
cout << fixed << setprecision(7) << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){

	int h;
	int hh;
	int w;
	int ww;
	string i;
	vector<string> lines;
	lines.reserve(100);

	cin >> h >> w;
	for ( int i = 0; i < h; ++i )
	{
		string s;
		cin >> s;
		lines.push_back(s);
	}

	for (ww = w + 2; ww > 0; ww--)
	{
		cout << "#";
	}
	cout << endl;
	for ( int i = 0; i < h; ++i ) {
		cout << "#" << lines[i] << "#" << endl;
	}
	for (ww = w + 2; ww > 0; ww--)
	{
		cout << "#";
	}
	cout << endl;

	
	return 0;
}

Measured memory_bytes: 256
dic = {}
base = ord("a")
for x in range(5):
  for y in range(5):
    dic[(x + 1, y + 1)] = chr(base + x * 5 + y)
dic[(6, 1)] = "z"
dic[(6, 2)] = "."
dic[(6, 3)] = "?"
dic[(6, 4)] = "!"
dic[(6, 5)] = " "

def to_mess(nums):
  if len(nums) % 2 == 1:
    return "NA"
  
  mess = ""
  for i in range(0, len(nums), 2):
    x, y = map(int, nums[i: i + 2])
    if (x, y) in dic:
      mess += dic[(x, y)]
    else:
      return "NA"

  return mess

while True:
  try:
    nums = input()
    print(to_mess(nums))
  except EOFError:
    break


Measured memory_bytes: 5596
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    def dfs(t,j,num):
        if num == 3:
            tt = tuple([tuple(t[k]) for k in range(H)])
            d[tt] = 1
        else:
            nt = [[t[y][x] for x in range(W)] for y in range(H)]
            for y in range(H-len(s[j])+1):
                for x in range(W-len(s[j][0])+1):
                    f = 0
                    for y_ in range(len(s[j])):
                        for x_ in range(len(s[j][0])):
                            if s[j][y_][x_]:
                                Y,X = y+y_,x+x_
                                if nt[Y][X]:
                                    f = 1
                                    break
                                nt[Y][X] = 1
                        if f:
                            break
                    if f:
                        nt = [[t[y][x] for x in range(W)] for y in range(H)]
                    else:
                        nj = j+1
                        if nj == i:
                            nj += 1
                        dfs(nt,nj,num+1)
                        nt = [[t[y][x] for x in range(W)] for y in range(H)]

    s = []
    for i in range(4):
        h,w = LI()
        b = SR(h)
        s.append([[1 if b[i][j] == "#" else 0 for j in range(w)] for i in range(h)])
    H,W = 4,10
    d = defaultdict(lambda : 0)
    for i in range(4):
        t = [[0]*W for i in range(H)]
        j = 0 if i > 0 else 1
        dfs(t,j,0)
    n = I()
    for i in range(n):
        b = SR(H)
        t = tuple([tuple([0 if b[i][j] == "#" else 1 for j in range(W)]) for i in range(H)])
        if d[t]:
            print("Yes")
        else:
            print("No")
    return


if __name__ == "__main__":
    solve()



Measured memory_bytes: 47520
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        h: usize,
        w: usize,
        a: [Chars; h],
    };
    for _ in 0..w + 2 {
        print!("#");
    }
    println!();
    for i in 0..h {
        print!("#");
        for j in 0..w {
            print!("{}", a[i][j]);
        }
        println!("#");
    }

    for _ in 0..w + 2 {
        print!("#");
    }
    println!();
}


Measured memory_bytes: 2212
# -*- coding: utf-8 -*-
"""
http://abc061.contest.atcoder.jp/tasks/abc061_c

"""
import sys
from sys import stdin
from itertools import accumulate
from bisect import bisect_left
input = stdin.readline


def main(args):
    N, K = map(int, input().split())

    freq = [0] * 100001
    for _ in range(N):
        a, b, = map(int, input().split())
        freq[a] += b

    acc = list(accumulate(freq))
    i = bisect_left(acc, K)
    print(i)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 10636
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    if (abs(a-c)<=d) 
        printf("Yes\n");
    else {
        if (a<=b && b<=c || c<=b && b<=a) {
            if(abs(a-b)<=d && abs(b-c)<=d) printf("Yes\n");
            else printf("No\n");
        } else {
            printf("No\n");
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define F first
#define S second


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

struct ant{int x,y,hp,te;};

main(){
  int w,h;
  while(cin>>w>>h,w|h){
    int dd[h][w];
    int sx,sy;
    rep(i,h)rep(j,w){
      cin>>dd[i][j];
      if(dd[i][j]==2)sx=i,sy=j;
    }

    int hp[h][w];
    memset(hp,-1,sizeof(hp));
    
    queue<ant> Q;
    ant t={sx,sy,6,0};
    Q.push(t);
    int ans=-1;
    
    while(!Q.empty()){
      t=Q.front();Q.pop();
      int cx=t.x,cy=t.y,chp=t.hp,cte=t.te;
      if(hp[cx][cy]==-1)hp[cx][cy]=chp;
      else if(hp[cx][cy]>=chp)continue;
      else hp[cx][cy]=chp;
      
      if(dd[cx][cy]==3){
        ans=cte;
        break;
      }
      
      if(chp==1){
        continue;
      }

      rep(i,4){
        int nx=cx+dx[i],ny=cy+dy[i],nhp=chp-1;
        if(nx<0 || nx>=h || ny<0 || ny>=w || dd[nx][ny]==0)continue;
        if(dd[nx][ny]==4)nhp=6;
        if(hp[nx][ny]>=nhp)continue;
        ant pu={nx,ny,nhp,cte+1};
        Q.push(pu);
      }
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc()) 
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int MOD = (int)(1e9 + 7);
inline void Add(int& x,int y) {
  x = x + y >= MOD ? x + y - MOD : x + y;
}
inline void Sub(int& x,int y) {
  x = x - y < 0 ? x - y + MOD : x - y;
}
int power(int a,int b) {
  int ret = 1;
  while (b) {
    if (b&1) ret = 1ll * ret * a % MOD;
    a = 1ll * a * a % MOD;
    b >>= 1;
  }
  return ret;
}

const int N = 1010, M = 2010;
int n, m;
struct data {
  int a, b, v;
  bool operator < (const data& x) const {
    return v < x.v;
  }
} edg[M];
int uni[N];
int getfa(int pos) {
  return uni[pos] == pos ? pos : uni[pos] = getfa(uni[pos]);
}
struct edge {
  int la,b,v;
} con[N << 1];
int tot, fir[N];
void add_edge(int from,int to,int val) {
  con[++tot] = (edge) {fir[from], to, val};
  fir[from] = tot;
}
int val[N], fa[N], dep[N], rec[M];
void dfs(int pos) {
  dep[pos] = dep[fa[pos]] + 1;
  for  (int i = fir[pos]; i; i = con[i].la) {
    if (con[i].b == fa[pos]) continue;
    fa[con[i].b] = pos;
    val[con[i].b] = con[i].v;
    dfs(con[i].b);
  }
}
int query(int a,int b) {
  int ret = 0;
  while (a != b) {
    if (dep[a] < dep[b]) swap(a, b);
    ret = max(ret, val[a]);
    a = fa[a];
  }
  return ret;
}
int solve(ll lim) {
  sort(edg + 1, edg + m + 1);
  rep (i, 1, n) uni[i] = i;
  tot = 0;
  memset(fir, 0, sizeof fir);
  memset(rec, 0, sizeof rec);
  ll cur = 0;
  rep (i, 1, m) {
    int x = edg[i].a, y = edg[i].b;
    if (getfa(x) == getfa(y)) continue;
    add_edge(x, y, edg[i].v);
    add_edge(y, x, edg[i].v);
    x = getfa(x), y = getfa(y);
    uni[x] = y;
    cur += edg[i].v;
    rec[i] = 1;
  }
  if (cur > lim) return power(2, m);
  dfs(1);
  int num = n-1;
  rep (i, 1, m) if (!rec[i]) {
    if (cur + edg[i].v - query(edg[i].a, edg[i].b) <= lim)
      ++ num;
  }
  return power(2, m - num + 1);
}
int main() {
  ll lim;
  read(n), read(m);
  read(lim);
  rep (i, 1, m)
    read(edg[i].a), read(edg[i].b), read(edg[i].v);
  if (n == 1) {
    if (lim == 0) puts("1");
    else puts("0");
    return 0;
  }
  int ans = solve(lim - 1);
  Sub(ans, solve(lim));
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

vector<pair<int, int>> p;
double s = 0;
int k = 0;
int n;
int v[8] = {};

void dfs(int j) {
    for (int i = 0; i < n; i++) {
        if (v[i]) continue;
        v[i] = 1;
        if (j >= 0) {
            int x = p[i].first - p[j].first;
            int y = p[i].second - p[j].second;
            s += sqrt(x * x + y * y);
            k++;
        }
        dfs(i);
        v[i] = 0;
    }
}

int main() {
    cin >> n;

    p = vector<pair<int, int>>(n);
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        p[i] = { x, y };
    }

    dfs(-1);

    printf("%.10f\n", s / (k / (n - 1)));

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
    int a,b,c,m,n;
    cin >> a >> b >> c;
    m=n=a;
    if(m>b)
        m=b;
    if(m>c)
        m=c;
    if(n<b)
        n=b;
    if(n<c)
        n=c;
    cout << n-m << endl;
    return 0;
}


Measured memory_bytes: 256
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}



int main(){
  int a,b;cin>>a>>b;
  cout << a+b/2 << endl;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        
        String s[] = sc.next().split("");
        boolean isEasy = true;

        for (int i = 1; i <= s.length; i++) {
            if (i % 2 == 0 && s[i-1].equals("R")) {
                isEasy = false;
            }
            if (i % 2 == 1 && s[i-1].equals("L")) {
                isEasy = false;
            }
        }

        if (isEasy) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
	}
}


Measured memory_bytes: 23764
#include <stdio.h>
int main(void) {
	int n, h[100001], i;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &h[i]);
		if (i == 0) {
			h[i] = h[i] - 1;
		}
		if (h[i - 1] < h[i]&&i>0) {
			h[i] = h[i] - 1;
		}
		if (h[i-1] > h[i]&&i>0) {
			printf("No\n");
			break;
		}
		if(n-1==i){
			printf("Yes\n");
		}

	}
	

	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(){
  int a,b,c,d;
  scanf("%d %d %d %d",&a,&b,&c,&d);
  if(a+b==c+d){
    printf("Balanced\n");
  }else if(a+b>c+d){
    printf("Left\n");
  }else{
    printf("Right\n");
  }
  return 0;
}

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

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

	if ((n / 10) % 111 == 0 || (n % 1000) % 111 == 0) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
from sys import stdin
input = stdin.readline

N , M = map(int,input().split())
start_input = set()
goal_input = set()

for _ in range(M):
    x , y = map(int,input().split())
    if x == 1:
        start_input.add(y)
    elif y == N:
        goal_input.add(x)
    
if start_input & goal_input:
    print("POSSIBLE")
else :
    print("IMPOSSIBLE")

Measured memory_bytes: 19024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)

struct edge{ int to, cost; };

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

    // 2^r <= L なる最大の r を求める
    int tmp = L, r = 0;
    while(tmp > 1){ 
        tmp /= 2;
        ++r;
    }

    int N = r+1, M = 0;
    vector<vector<edge>> G(N);
    // i -> i+1 に 0 と 2^i の辺を張ることで
    // 0 ~ 2^r-1 までの経路を作れる
    REP(i, N-1){
        G[i].push_back({i+1, 0});
        G[i].push_back({i+1, (int) pow(2, i)});
        M += 2;
    }

    // 残りの辺を張る
    for(int i = N-2; i >= 0; --i){
        int length = L - pow(2, i);
        if( length >= pow(2, r)){
            G[i].push_back({N-1, length});
            L -= pow(2, i);
            ++M;
        }
    }

    cout << N << " " << M << endl;
    REP(i, N){
        for(auto e: G[i]) cout << i+1 << " " << e.to+1 << " " << e.cost << endl;
    }

    return 0;
}

Measured memory_bytes: 640
from heapq import *
n, m = map(int, input().split())
a = sorted([list(map(int, input().split()))for _ in range(n)])
a.append([10**9])
r,j,x=0,0,[]
heapify(x)
for i in range(m):
    while a[j][0]<=i+1:heappush(x,-a[j][1]);j+=1
    if x:r-=heappop(x)
print(r)

Measured memory_bytes: 31968
table = {
  0 => [1, 3],
  1 => [5, 2],
  2 => [4, 0],
  3 => [5, 1],
  4 => [0, 3],
  5 => [4, 2]
}

dice = gets.split
gets.to_i.times do 
  top, front = gets.split.map {|x| dice.index(x) }
  side = 3 - [top, 5 - top].min - [front, 5 - front].min
  puts dice[table[top].include?(front) ? side : 5 - side]
end

Measured memory_bytes: 8684
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;

int main(){
	long long N;
	cin >> N;
	vector<long long> A(N);
	cin >> A.at(0);
	vector<long long> maxA(N);
	maxA.at(0) = A.at(0);

	for (int i = 1; i < N; i++) {
		cin >> A.at(i);
		if (A.at(i) < maxA.at(i - 1)) maxA.at(i) = maxA.at(i - 1);
		else maxA.at(i) = A.at(i);
	}

	long long ans = 0;
	for (int i = 0; i < N; i++) {
		ans += maxA.at(i) - A.at(i);
	}
	cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

string s;
ll n;

int main(){
    cin >> s >> n;
    for(int i = 0;i < s.size();i+=n)cout << s[i];
    cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define lp(i, n) for(int i = 0; i < n; i++)
#define int long long

int32_t main() {
ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
        int n; cin >> n;
        pair<int, int> p[10];
        lp(i, n) {
                int a, b; cin >>a>> b;
                p[i + 1] = {a, b};
        }
        vector<int> v;
        lp(i, n) { v.push_back(i + 1); }
        double avg = 0, wh = 0;
        do {
                for (int i = 1; i < v.size(); i++) {
                        avg += sqrt(pow((p[v[i]].first - p[v[i - 1]].first), 2) + pow(((p[v[i]].second - p[v[i - 1]].second)), 2));
                }
                wh++;
        }while (next_permutation(all(v)));
        avg /= wh;
        printf("%0.10f", avg);
return 0;
}


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

using namespace std;

int main(void){
    int points[3000];
    int i,j,n,x[3000],y[3000],p,q,ans,tmp;
    int *pp, *qp;
    cin >> n;
    while(n!=0){
        for(i=0; i<n; i++){
            cin >> x[i] >> y[i];
            points[i] = x[i]*5001 + y[i];
        }
        sort(points,points+n);
        ans = 0;
        for(i=0; i<n; i++){
            for(j=i; j<n; j++){
                if(i==j){
                    continue;
                }
                tmp = (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
                p = (x[i]+y[i]-y[j])*5001 + y[i]+x[j]-x[i];
                q = (x[j]+y[i]-y[j])*5001 + y[j]+x[j]-x[i];
                pp = lower_bound(points,points+n,p);
                qp = lower_bound(points,points+n,q);
                if(points[(int)(pp-points)] == p && points[(int)(qp-points)] == q){
                    ans = max(ans,tmp);
                }
                p = (x[i]-y[i]+y[j])*5001 + y[i]-x[j]+x[i];
                q = (x[j]-y[i]+y[j])*5001 + y[j]-x[j]+x[i];
                pp = lower_bound(points,points+n,p);
                qp = lower_bound(points,points+n,q);
                if(points[(int)(pp-points)] == p && points[(int)(qp-points)] == q){
                    ans = max(ans,tmp);
                }
            }
        }
        cout << ans << endl;
        cin >> n;
    }
    return 0;
}

Measured memory_bytes: 1212
/*input
coffee
*/
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define trace1(x) cout<<#x<<": "<<x<<endl
#define trace2(x, y) cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cout<<#x<<": " <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
 
//typedef long long ll;
#define int long long
#define ll long long

 
#define PI 3.141592653589793
#define MOD 1000000007
#define INF 1e15
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; a=a%m; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
/*prime m*/ template<typename T> T modInv(T a, T m){return pow(a,m-2,m);} 

#define MAX 505 
int32_t main() {
	IOS
	string s; cin>>s;
	if(s.size()<6 || s.size() > 6) cout<<"No"<<endl;
	else if (s[4]!= s[5]) cout<<"No"<<endl;
	else if (s[2]!= s[3]) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;


 
return 0;
}
 


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int i,j,k,s=0,n,x;
	for(;;){
		scanf("%d %d", &n,&x);
		
		if(n==0&&x==0){
		break;
		}
		s=0;
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
				for(k=1;k<=n;k++){
					if(i==j||i==k||k==j){
						
					}
						else{
							if(x==i+j+k) s++;
						}
					}
				}
			}
		printf("%d\n", s/6);
		}
	
return 0;
}



Measured memory_bytes: 2044
#include<stdio.h>

int main(void){
  int y,m,d;
  scanf("%d/%d/%d",&y,&m,&d);
  if(y<2019){
      printf("Heisei");
    }else{
      if(m<=4){
        printf("Heisei");
      }else{
        printf("TBD");
      }
    }

  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>
#include<list>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
typedef long long ll;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n + 2), S(n + 1);
	a[0] = a[n + 1] = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	int s = 0;
	for (int i = 0; i <= n; i++) {
		s += abs(a[i] - a[i + 1]);
	}
	for (int i = 1; i <= n; i++) {
		S[i] = s + abs(a[i - 1] - a[i + 1]) - abs(a[i] - a[i + 1]) - abs(a[i - 1] - a[i]);
	}
	for (int i = 1; i <= n; i++) {
		cout << S[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 2048
k,n=map(int,input().split())
a=list(map(int,input().split()))

check_l =[]
for i in range(len(a)-1):
	check_l.append(a[i+1]-a[i])

check_l.append(k+a[0]-a[n-1])
print(k-max(check_l))

Measured memory_bytes: 26420
def main():
    N = int(input())
    l = list(map(int, input().split()))
    ans = []
    X = sum(l)
    x = 0
    for i in range(N-1):
        x += l[i]
        ans.append(abs(X-2*x))
    print(min(ans))
if __name__ == '__main__':
    main()

Measured memory_bytes: 24832
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;


 int ans1,ans2;

 int arr[1000];


int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS

    

      int n;
      cin >> n;

      bool ok = true;

      set<string> mp;

      string prev = "";
      while(n--)
      {

        string s;
        cin >> s;
        if(mp.count(s))
        {
          cout << "No";
          return 0;
        }
        mp.insert(s);

        if(prev.size())
        {
          if(s[0] != prev[prev.size()-1])
          {
            cout << "No";
             return 0;
          }
        }
        prev = s;

      }

      cout << "Yes";






    return 0;   
}


Measured memory_bytes: 3628