akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
#include<queue>
using namespace std;
using ll = long long;

struct Edge{
  int to;
  ll yen;
  ll snook;
  Edge(int t, ll y, ll s) : to(t), yen(y), snook(s){ };
};

using P = pair<ll, int>; // first:最短距離　second:頂点の番号
using Graph = vector<vector<Edge>>;

int n;
const ll INF = 1e15;

void dijkstra(int s, vector<ll> &d, const Graph &G, int m){
  // m = 1 の時円で考え、m = 0の時スヌークで考える
  priority_queue<P, vector<P>, greater<P>> que;
  d.assign(n, INF);
  d[s] = 0;
  que.push(P(0, s));

  while(!que.empty()){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;  //次のforループでd[next_v]が更新された時
    for(auto next_v : G[v]){
      if(m == 1 && d[next_v.to] > d[v] + next_v.yen){
        d[next_v.to] = d[v] + next_v.yen;
        que.push(P(d[next_v.to], next_v.to));
      }
      else if(m == 0 && d[next_v.to] > d[v] + next_v.snook){
        d[next_v.to] = d[v] + next_v.snook;
        que.push(P(d[next_v.to], next_v.to));
      }
    }
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int m, s, t;
  cin >> n >> m >> s >> t;
  s--; t--;
  Graph G(n);
  int u, v;
  ll a, b;
  for(int i=0; i<m; ++i){
    cin >> u >> v >> a >> b;
    u--; v--;
    G[u].push_back(Edge(v, a, b));
    G[v].push_back(Edge(u, a, b));
  }

  vector<ll> dy;
  vector<ll> ds;
  dijkstra(s, dy, G, 1);
  dijkstra(t, ds, G, 0);

  vector<ll> d(n);
  for(int i=0; i<n; ++i){
    d[i] = dy[i] + ds[i];
  }
  for(int i=n-2; i>=0; --i){
    d[i] = min(d[i], d[i+1]);
  }

  for(int i=0; i<n; ++i){
    cout << 1000000000000000 - d[i] << "\n";
  }
}

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

using namespace std;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int ar[3];
    ar[0] = a;
    ar[1] = b;
    ar[2] = c;
    sort(ar,ar+3);
    if(ar[0]==5 && ar[1]==5 && ar[2]==7){
        cout << "YES" << endl;}
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
def judge_passing_qualifying_domestic(i, line):
    if i < A+B:
        print('Yes')
        return i+1
    else:
        print('No')
        return i

def judge_passing_qualifying_foreign(i, rank_in_foreign, line, line_foreign):
    if (i < A+B)&(rank_in_foreign <= line_foreign):
        print('Yes')
        return i+1, rank_in_foreign+1
    else:
        print('No')
        return i, rank_in_foreign+1


if __name__ == "__main__":
    N, A, B = list(map(int, input().split()))
    S = input()
    num_of_pass = 0
    rank_in_foreign = 1
    for p in list(S):
        if p == 'a':
            num_of_pass = judge_passing_qualifying_domestic(num_of_pass, A+B)
        elif p =='b':
            num_of_pass, rank_in_foreign = judge_passing_qualifying_foreign(num_of_pass, rank_in_foreign, A+B, B)
        else:
            print('No')

Measured memory_bytes: 9844
'use strict';
(function(stdin) { 
  var inputs = stdin.toString();
  (function(S) {
    console.log(~~(S / (60 * 60) )+':'+~~(S % (60 * 60) / 60)+':'+~~(S % 60));
  }(parseInt(inputs.trim(),10)));
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 7640
from collections import deque

n,m = map(int,input().split())
liv = [list(map(int,input().split())) for _ in range(m)]

ans = 0
for i in range(m):
  litmp = [[] for _ in range(n)]
  for j in range(m):
    if j != i:
      a = liv[j][0]
      b = liv[j][1]
      litmp[a-1].append(b-1)
      litmp[b-1].append(a-1)
  seen = [False]*n
  todo = deque([])
  seen[0] = True
  todo.append(0)
  while len(todo) > 0:
    v = todo.pop()
    for vn in litmp[v]:
      if not seen[vn]:
        seen[vn] = True
        todo.append(vn)
  #print(seen)
  #print(todo)
  for j in range(n):
    if seen[j]:
      continue
    else:
      ans += 1
      break
print(ans)
  

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define EB emplace_back

typedef std::pair <int, int> pr;
const int N = 100054;

namespace F {
	#define ad(x) ((x - 1 ^ 1) + 1)

	const int N = ::N * 2, M = ::N * 8;

	struct edge {
		int u, v, f;
		edge (int u0 = 0, int v0 = 0, int f0 = 0) : u(u0), v(v0), f(f0) {}
	} e[M];

	int V = 2, E = 0, si = 1, ti = 2, flow;
	int first[N], next[M];
	int dep[N], cur[N], que[N];

	inline void addedge(int u, int v, int f) {
		e[++E] = edge(u, v, f), next[E] = first[u], first[u] = E;
		e[++E] = edge(v, u), next[E] = first[v], first[v] = E;
	}

	bool bfs() {
		int h, t = 1, i, x, y;
		memset(dep, -1, sizeof dep);
		que[0] = si, dep[si] = 0;
		for (h = 0; h < t; h++) {
			if ((x = que[h]) == ti) return true;
			for (i = first[x]; i; i = next[i])
				if (dep[y = e[i].v] == -1 && e[i].f)
					que[t++] = y, dep[y] = dep[x] + 1;
		}
		return false;
	}

	int dfs(int x, int lim) {
		int a, c, f = 0;
		if (x == ti || !lim) return lim;
		for (int &i = cur[x]; i; i = next[i])
			if (dep[e[i].v] == dep[x] + 1 && e[i].f) {
				a = std::min(lim - f, e[i].f);
				c = dfs(e[i].v, a);
				e[i].f -= c; e[ad(i)].f += c;
				if ((f += c) == lim) return f;
			}
		return f;
	}

	int Dinic() {
		for (flow = 0; bfs(); flow += dfs(si, INT_MAX))
			memcpy(cur, first, sizeof cur);
		return flow;
	}

	int get(int x) {
		for (int i = first[x]; i; i = next[i]) if (i & 1 && !e[i].f) return e[i].v;
		return -1;
	}
}

int n;
int que[N], match[N], matup[N];
std::vector <int> nb[N];

int main() {
	int i, v, m, h, t = 1;
	scanf("%d", &n);
	for (i = 1; i < n; ++i) {
		F::addedge(i + n + 1, 2, 1), scanf("%d", &m);
		for (; m; --m) scanf("%d", &v), nb[v].EB(i), F::addedge(v + 1, i + n + 1, 1);
	}
	for (i = 2; i <= n; ++i) F::addedge(1, i + 1, 1);
	if (F::Dinic() != n - 1) return puts("-1"), 0;
	for (i = 2; i <= n; ++i) match[ F::get(i + 1) - n - 1 ] = i;
	for (*que = 1, h = 0; h < t; ++h)
		for (int s : nb[v = que[h]]) if (!matup[s])
			matup[s] = v, que[t++] = match[s];
	if (t != n) return puts("-1"), 0;
	for (i = 1; i < n; ++i) printf(matup[i] < match[i] ? "%d %d\n" : "%2$d %1$d\n", matup[i], match[i]);
	return 0;
}

Measured memory_bytes: 26624
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
//#define   Y            imag()
//#define   X            real()
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
//#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
//#define    dp(a,b)          (((conj(a))*(b)).real())
//#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
//#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     PT                    complex<double>
#define outfile freopen("out.out", "w", stdout);
#define infile  freopen("in.in", "r", stdin);
#define PI acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
using namespace __gnu_pbds;
int dcmp(double a,double b){   return fabs(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(int num, int idx) {return num ^ (1<<idx);}
void FS(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
const int N=200009;
ll n,a,b,c;
const ll mod=1e9+7;
ll p1[N],p2[N],fact[N];
ll power(ll b,ll p)
{
    if(p==0)
        return 1;
    if(p&1ll)
        return ((b%mod)*(power(((b%mod)*(b%mod))%mod,p/2)%mod))%mod;
    else
        return power(((b%mod)*(b%mod))%mod,p/2)%mod;
}
int main()
{
    cin>>n>>a>>b>>c;
    fact[0]=1;
    for(int i=1;i<=2*n;i++)
    {
        fact[i]=(fact[i-1]*i)%mod;
    }

    p1[0]=1;
    p1[1]=(a*power(a+b,mod-2))%mod;
    for(int i=2;i<=2*n;i++)
    {
        p1[i]=(p1[i-1]*p1[1])%mod;
    }
    p2[0]=1;
    p2[1]=(b*power(a+b,mod-2))%mod;
    for(int i=2;i<=2*n;i++)
    {
        p2[i]=(p2[i-1]*p2[1])%mod;
    }
    ll ans=0;
    for(int m=n;m<=2*n-1;m++)
    {
         ans=(ans+ (((((( (p1[n]*p2[m-n])%mod+(p2[n]*p1[m-n])%mod )%mod*fact[m-1])%mod*100)%mod*m)%mod*power(100-c,mod-2))%mod
        *power((fact[(n-1)]*fact[m-n]),mod-2))%mod)%mod;

    }



    cout<<ans<<endl;
}


























Measured memory_bytes: 4992
#!/usr/bin/env python
import math

n = int(input())
m = int(math.sqrt(n))+1
x = y = z = 0 

def p(x, y, z): 
    return x*x + y*y + z*z + x*y + y*z + z*x 

anss = [0 for _ in range(n)]

for x in range(1, m): 
    for y in range(1, m): 
        for z in range(1, m): 
            if p(x, y, z)-1 <= n-1:
                anss[p(x, y, z)-1] += 1

for i in range(n):
    print(anss[i])


Measured memory_bytes: 9200
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define F first
#define S second
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sortv(X) sort(X.begin() , X.end()) ; 
#define ll long long 
#define ld long double
#define pii pair <int ,int >
#define bug(x)  cout<<"passed "<<x<<endl;
#define ashar(x , y , z) cout<<setprecision(x)<<fixed<<y ; if (z==1) cout<<"\n" ;
#define ppi pair <pair <int, int > , int > 
#define ordered_set tree<pair <long long  ,long long >, null_type,less<pair <long long ,long long > >, rb_tree_tag,tree_order_statistics_node_update> 
  
long long const inf = 3e18, linf = 2e9, mod = 1e9+7 , inf2 = 1e12;
int const mxn = 5e5 + 10 ;
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}



long long sumk , ans , A[mxn] ; 
int main(){
	int n ; 
	cin>>n ; 
	for (int i = 1 ; i <= n ; i++){
		cin>>A[i] ;
		sumk+=A[i] ;  
		sumk%=mod ; 
	}
	for (int i = 1 ; i <= n ; i++){
		sumk-=A[i] ; 
		sumk = (sumk+mod)%mod ; 
		ans += (A[i]*(sumk))%mod ; 
		ans%=mod ; 
	}
	cout<<ans ; 
}


Measured memory_bytes: 5164
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#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>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;
const double pi=3.141592653589793238;
int main(){
    int h,w,white=0;
    cin >> h >> w;
    vector<vector<char>> c(h,vector<char>(w));
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> c[i][j];
            if(c[i][j]=='.') white++;
        }
    }
    queue<pair<int,int>> q;
    vector<vector<int>> dist(h,vector<int>(w,-1));
    q.push(make_pair(0,0));
    dist[0][0]=1;
    while(!q.empty()){
        pair<int,int> p=q.front();
        q.pop();
        int ph=p.first,pw=p.second;
        int dh[4]={-1,0,0,1};
        int dw[4]={0,-1,1,0};
        for(int i=0; i<4; i++){
            int H=ph+dh[i],W=pw+dw[i];
            if(H<0 || W<0) continue;
            else if(H>=h || W>=w) continue;
            else if(c[H][W]=='#' || dist[H][W]!=-1) continue;
            else{
                dist[H][W]=dist[ph][pw]+1;
                q.push(make_pair(H,W));
            }
        }
        if(dist[h-1][w-1]!=-1) break;
    }
    if(dist[h-1][w-1]==-1) cout << dist[h-1][w-1] << endl;
    else cout << white-dist[h-1][w-1] << endl;
}



Measured memory_bytes: 3652
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main()
        {
            int[] numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int A = numbers[0];
            int B = numbers[1];

            if (A >= 10 || B >= 10)
            {
                Console.WriteLine(-1);
            }
            else
            {
                Console.WriteLine(A * B);
            }
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> number(N);
  for(int i = 0; i < N ; i++){
    cin >> number.at(i);
  }
 
  int count = 0;
    
  for(int i = 0; i < N ; i++){
    if(number.at(i) % 2 == 0 && !(number.at(i) % 3 == 0) && !(number.at(i) % 5 == 0) ){
      count++;
    }
  }
  
  if(count > 0){
    cout << "DENIED" << endl;
  }
  
  else{
    cout <<  "APPROVED" << endl;
    }
    


}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
#define int long long

int max(int a,int b){
  if(a>b)return a;
  return b;
}

signed main(){
  int a,b,k;
  cin >> a >> b >> k;
  cout << max(0, a-k) << " " << max(0,b-max(0,k-a)) << endl;
}


Measured memory_bytes: 256
import math
import numpy as np

def  XYZTriplets():

    num = int(input())
    
    list_num = []
    
    count = [0]*num
    
    for i in range(1, num+1):
        list_num.append(i)

    for x in range(1, int(math.sqrt(num))):
        for y in range(1, int(math.sqrt(num))):
            for z in range(1, int(math.sqrt(num))):
                
                function = x*x + y*y + z*z + x*y + y*z + z*x
                
                if function <= num and function > 0:
                    count[function-1] = count[function-1] + 1
 
    for i in range(0, num):
        print(count[i])
        

if __name__ == '__main__':
    XYZTriplets()


Measured memory_bytes: 27240
#include<bits/stdc++.h>
#include<iomanip>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
using namespace std;

const long long INF=9000000000000000;
typedef long long ll;


int main(){
char s[4];
cin>>s[0]>>s[1]>>s[2]>>s[3];
sort(s,s+4);
if(s[0]==s[1] and s[2]==s[3] and s[1]!=s[2])
cout<<"Yes"<<endl;
else{
  cout<<"No"<<endl;
}
}


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

using namespace std;
char c;
int main()
{
	cin>>c;
	if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')cout<<"vowel";
	else cout<<"consonant";
	cout<<"\n";
	
	return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N; cin >> N;
  ll A[N]; rep(i,N) cin >> A[i];
  ll count = 0; rep(i,N) count += A[i]%2;
  string result = (count%2==0) ? "YES" : "NO";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

using namespace std;

int n, m, p;
string s;
int acpe[100001][2];
int wa[100001];
int ac, pe;

int main() {
	cin >> n >> m;
	rep(i, m) {
		cin >> p >> s;
		if (s == "WA")wa[p]++;
		else if (s == "AC") {
			if (acpe[p][0] == 0) {
				acpe[p][0] += 1;
				acpe[p][1] = wa[p];
			}
		}
	}

	rep(i, 100001) {
		ac += acpe[i][0];
		pe += acpe[i][1];
	}

	cout << ac << " " << pe << endl;
	return 0;
}


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

const int MAX_N=1299709;
bool prime[MAX_N+1];

void sieve()
{
  prime[0]=prime[1]=false;
  for(int i=2;i<=MAX_N;i++)
    prime[i]=true;
  for(int i=2;i<=MAX_N;i++)
    if(prime[i])
      for(int j=i*2;j<=MAX_N;j+=i)
	prime[j]=false;
}

int is_prime(int n)
{
  return prime[n];
}

int main()
{
  int n,sum;

  sieve();
  for(;;){
    cin>>n;
    if(!n) break;

    sum=0;
    for(int i=n;;i++){
      if(is_prime(i)) break;
      sum++;
    }
    for(int i=n;;i--){
      if(is_prime(i)) break;
      sum++;
    }
    cout<<sum<<endl;
  }
}


Measured memory_bytes: 2428
N, D = map(int,input().split())

X = []
ans = 0
for i in range(N):
    X.append(list(map(int,input().split())))

    for j in range(i):
        dis = 0
        for k in range(D):
            dis += (X[i][k] - X[j][k])**2
            if k == D-1:
                if (dis) ** (1/2) - int((dis) ** (1/2)) == 0:
                    ans += 1

print(ans)

Measured memory_bytes: 9432
#include <stdio.h>
#include <string.h>
int main(void) {
	char s[200];
	char p[100];
	char ring[200];
	
	scanf("%s",s);
	scanf("%s",p);
	strcpy(ring,s);
	strcat(ring,s);
	
	if(strstr(ring,p)){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	
	
	return 0;
}

Measured memory_bytes: 540
#include<stdio.h>
int main(void){
	int a[5];
	int i,j,tmp;
	
	scanf("%d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4]);
	for(i=0;i<5;i++){
		for(j=4;j>i;j--){
			if(a[j]>a[j-1]){
				tmp=a[j];
				a[j]=a[j-1];
				a[j-1]=tmp;
			}
		}
	}
		printf("%d %d %d %d %d\n",a[0],a[1],a[2],a[3],a[4]);
	
	return 0;
}

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


void dfs(int x, vector<vector<int> > &g, vector<bool> &used, vector<int> &post, int& k){
  used[x] = true;
  for(size_t i = 0; i < g[x].size(); i++){
    if(!used[g[x][i]]){
      dfs(g[x][i], g, used, post, k);
    }
  }
  post.push_back(x);
  
  return;
}

double rdfs(int x, vector<vector<int> > &rg, vector<int> &id, vector<double>& p, int k, vector<set<int> >& newG){
  id[x] = k;
  
  double ans = p[x];
  for(size_t i = 0; i < rg[x].size(); i++){
    if(id[rg[x][i]] < 0){
      ans *= rdfs(rg[x][i], rg, id, p, k, newG);
    }
    else if(id[rg[x][i]] != k){
      newG[k].insert(id[rg[x][i]]);
    }
  }
  
  return ans;
}


int main(void){
  int n;
  while(true){
    cin >> n;
    if(n == 0){ break; }

    vector<double> p(n);
    vector<vector<int> > g(n);
    vector<vector<int> > rg(n);
    int m, a;
    for(int i = 0; i < n; i++){
      cin >> p[i] >> m;
      for(int j = 0; j < m; j++){
        cin >> a;
        --a;
        g[i].push_back(a);
        rg[a].push_back(i);
      }
    }

    int k = 0;
    vector<bool> used(n, false);
    vector<int> post;
    for(int i = 0; i < n; i++){
      if(!used[i]){
        dfs(i, g, used, post, k);
      } 
    }
    
    k = 0;
    vector<int> id(n, -1);
    used = vector<bool>(n, false);
    vector<set<int> > newG(n);
    vector<double> newP(n, 0);
    for(int i = n - 1; i >= 0; i--){
      if(id[post[i]] < 0){
        newP[k] = rdfs(post[i], rg, id, p, k, newG);
        //printf("[%.2f%c]", newP[k], newG[k].size() == 0 ? '*' : '0');
        k++;
      }
    }
    
    double ans = 1.0;
    for(int i = 0; i < n; i++){
      if(newG[i].size() == 0){
        ans *= (1.0 - newP[i]);
      }
    }
    printf("%.9f\n", ans);
  }

  return 0;
}



Measured memory_bytes: 3344
import java.util.Scanner;

public class Main {

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

        int N = scanner.nextInt();

        int max = 0;
        long sum = 0;
        for (int i = 0; i < N; i++) {
            int p = scanner.nextInt();
            sum += p;
            if (max < p) {
                max = p;
            }
        }

        System.out.println(sum - max / 2);
    }

}


Measured memory_bytes: 23252
n=int(input())
s=input()+'?'
ans=10**10
arr=[0]*n
ans1=n-s.count('#')
ans2=n-s.count('.')
if s[0]=='.':
  arr[0]=1
for i in range(1,n):
  if s[i]=='.':
    arr[i]=arr[i-1]+1
  else:
    arr[i]=arr[i-1]
for i in range(1,n):
  tmp=(i-arr[i-1])+(arr[-1]-arr[i])
  if tmp<ans:
    ans=tmp
print(min(ans,ans1,ans2))

Measured memory_bytes: 11240
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    string s;
    cin >> s;
    int n = s.size();
    vector<char> vec(n);
    rep(i, n) vec.at(i) = s.at(i);

    char mini = 'a';
    sort(all(vec));

    for(int i=0; i<n; i++){
        if(vec.at(i) == mini) mini++;
    }
    if(mini == '{') out("None");
    else out(mini);
}

Measured memory_bytes: 512
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
total = sum(A)
result = []
for i in A:
    if i >= (total * (1/(4*M))):
        result.append(i)
if len(result) < M:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3060
import scala.io.StdIn

object Main extends App {

  val n = StdIn.readLine().toInt
  var a = Array.fill(n)(0)

  (0 to n - 1).foreach {i =>
    a(i) = StdIn.readLine().toInt
  }

  val f = a.max
  val fcount  = a.filter(_ == f).length
  val sarray  = a.filter(_ != f)
  val s = if (sarray.isEmpty) f else sarray.max

  a.foreach { i =>
    if (i == f && fcount > 1) {
      println(f)
    } else if (i == f && fcount == 1) {
      println(s)
    } else {
      println(f)
    }
  }
}
  



Measured memory_bytes: 56480
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    var sdash = input[0];
    var t = input[1];

    var unrestorable = true;
    var matchPos = 0;
    for (var i = sdash.length - t.length; i >= 0; i--) {
        var isMatch = true;
        for (var j = 0; j < t.length; j++) {
            if (sdash.charAt(i + j) != '?' && sdash.charAt(i + j) != t.charAt(j)) {
                isMatch = false;
                break;
            }
        }
        if (isMatch) {
            unrestorable = false;
            matchPos = i;
            break;
        }
    }

    var s = '';
    if (unrestorable) {
        s = 'UNRESTORABLE';
    }
    else {
        for (var i = 0; i < sdash.length; i++) {
            if (i >= matchPos && i < matchPos + t.length) {
                s = s + t.charAt(i - matchPos);
            }
            else {
                if (sdash.charAt(i) == '?') {
                    s = s + 'a';
                }
                else {
                    s = s + sdash.charAt(i);
                }
            }
        }
    }

    console.log(s);

    return 0;
}


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

int main(){
  long long a, b, k;
  
  cin >> a >> b >> k;
  
  if(a > k)	cout << a-k << " " << b <<endl;
  else if(b > k - a){
    k -= a; a = 0;
    cout << 0 << " " << b - k << endl;
  }
  else cout << 0 << " " << 0 << endl;;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll inf = 12345678999999;
const ll wall = -12345678;
const ll max33 = wall;
int main()
{
	ll n;
	cin>>n;
	vector<ll> vi;
	for(int i=0;i<n;i++)
	{
		ll a;
		cin>>a;
		vi.push_back(a);	
	}
	ll ma = max33;
	ll cnt = 0;
	for(int i=0;i<n-1;i++)
	{
		if(vi[i]>=vi[i+1])
			cnt++;
		else
		{
			ma = max(ma,cnt);
			cnt = 0;
		}
	}
	ma = max(ma,cnt);
	cout<<ma<<endl;
	return 0;
}


Measured memory_bytes: 1400
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

//桁, smaller flag
ll dp[1000010][2];

ll solve(void){
  string L;
  cin >> L;
  ll n = L.size();
  dp[0][0] = 1;
  
  REP(i, n) {
    ll d = L[i]-'0';
    REP(j, 2) {
      for(int x=0; x<=(j?1:d); x++){
	/*
	REP(l, lim+1) {	
	  (dp[i+1][j||(l<d)][k||(d==1)||(d==0&&!k)] += (dp[i][j][k]%MOD))%MOD;
	}
	*/
	(dp[i+1][j||x<d] += dp[i][j]*(x+1)%MOD)%=MOD;
      }
    }
  }
  return (dp[n][0] + dp[n][1])%MOD;
}

int
main(void){
  ios_base::sync_with_stdio(false);

  cout << solve() << endl;  

  return 0;
}


Measured memory_bytes: 2012
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(void){
  int N,K;
  cin >> N >> K;
  
  vector<int>candle(N,0);
  
  for(int i=0;i<N;i++){
    cin >> candle[i];
  }
  
  long min = 9999999999;
  for(int i=0;i<=N - K;i++){
    if(abs(candle[i]) >= abs(candle[i + K - 1])){
      long ans = abs(candle[i + K - 1]) + abs(candle[i + K - 1] - candle[i]);
      if(ans < min)
        min = ans;
    }
    else{
      long ans = abs(candle[i]) + abs(candle[i + K - 1] - candle[i]);
      if(ans < min)
        min = ans;
    }
  }
  
  cout << min << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1e16;
#define int long long

const int MAX_N = 1010;
const int MAX_V = 110;



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);	
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	const int dx = tx - sx, dy = ty - sy;
	cout << string(dy, 'U') << string(dx, 'R');
	cout << string(dy, 'D') << string(dx, 'L');
	cout << 'L' << string(dy + 1, 'U') << string(dx + 1, 'R') << 'D';
	cout << 'R' << string(dy + 1, 'D') << string(dx + 1, 'L') << 'U';
	cout << endl;
	return 0;
}


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

long long int n;
string s[100000];

long long int matching_num=0;

long long int num[5];



int main(){

    cin>>n;

    for(int i=0;i<n;i++){
        cin>>s[i];
    }

for(int i=0;i<5;i++) {num[i]=0;}

for(int i=0;i<n;i++){
    if(s[i][0]=='M'){
        num[0]+=1;
    }
    else if(s[i][0]=='A'){
        num[1]+=1;
    }
    else if(s[i][0]=='R'){
        num[2]+=1;
    }
    else if(s[i][0]=='C'){
        num[3]+=1;
    }
    else if(s[i][0]=='H'){
        num[4]+=1;
    }
}



for(int i=0;i<5;i++){
    for(int j=i+1;j<5;j++){
        for(int k=j+1;k<5;k++){
            matching_num+=num[i]*num[j]*num[k];
        }
    }
}
    
cout<<matching_num<<endl;

}

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

int main() {
	int n;
	cin >> n;
	if (n < 2)
		cout << 1 << endl;
	else if (1 < n && n < 4)
		cout << 2 << endl;
	else if (3 < n && n < 8)
		cout << 4 << endl;
	else if (7 < n && n < 16)
		cout << 8 << endl;
	else if (15 < n && n < 32)
		cout << 16 << endl;
	else if (31 < n && n < 64)
		cout << 32 << endl;
	else
		cout << 64 << endl;
}

Measured memory_bytes: 256
n = gets.to_i

edges = []
g = Array.new(n+1){ [] }
(n-1).times do |i|
  a, b = gets.split.map(&:to_i)
  a, b = b, a if a > b # 辺は頂点 i < j の形で入れる。
  g[a] << b # 隣接リストに
  g[b] << a # 反対向きにも隣接リストに.無向グラフなので
  # gに隣接頂点だけでなく、何番目の辺の情報をいれることもある。
  edges << a+b*100_000 # 辺リストにいれる。辺が識別されてて、最後に辺リストから辺を回して色をとりだす。
end

colors = Hash.new() # Esge => color # 辺についてO(1)で使った色を見れる。O(1)はホントに?
colors_used = Hash.new # 頂点と色についてO(1)で使ったか確かめられる。
used = Array.new(n){false} # 頂点について探索済みかどうかO(1)でわかる。
que = [1] # 頂点1から見ていくので0が入っている # 探索待ちの未探索の頂点リスト

k = 0 # 答えとなる色の数
while v = que.shift # queにある頂点を取り出す. 破壊的メソッドなので先頭は削除される。なければnilを返す
  k = g[v].size if k < g[v].size  # 隣接する頂点数より色数が小さければ色数を更新
  cur = 1 # 使ってない色がわからないので、とりあず色1から見ていく。
  g[v].each do |w| # vの隣接頂点wを見ていく。
    next if used[w] #trueで、探索済みの頂点なら見ない。
    v<w ? (i,j = v,w) : (i,j = w,v) # i < jの並びで頂点を捉える。
    cur += 1 while colors_used[v+cur*100_000] == true # v周りの頂点で色をつかっていれば次の色に更新していく。塗る前に使ってない色にする。
    colors_used[v+cur*100_000] = true # vに色を使ったので記録する。
    colors_used[w+cur*100_000] = true # wに色を使ったので記録する。
    colors[i+j*100_000] = cur # 辺に使った色をいれる。
    que.push(w) #探索待ちの未探索頂点リストに頂点wを入れる。
  end
  used[v] = true # 頂点vを探索済みにする。
end

puts k
edges.each{ |e| puts colors[e] }

Measured memory_bytes: 33148
def acinput():
    return list(map(int,input().split(" ")))


N,X=acinput()
L=acinput()

count=0
h=0
for i in range(len(L)):
        count+=1
        h+=L[i]
        if h>X:
                break
        if i==len(L)-1:
                count+=1

if count==0:
        count=1
print(count)


Measured memory_bytes: 3060
#include <stdio.h>

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

Measured memory_bytes: 2088
// D.

#include <sstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main(int argc, char *argv[])
{
	int n;
	cin >> n;
	int a = sqrt(n * 2), b = a + 1;
	if (a * b == n * 2) {
		cout << "Yes" << endl;
		cout << b << endl;
		vector<int> u(n);
		for (int i = 0; i < b; ++i) {
			cout << a;
			vector<int> s(n + 1);
			int k = 0;
			for (int j = 0; j < a; ++j) {
				while (true) {
					if (!u[k]) {
						u[k] = i + 1;
						break;
					}
					if (u[k] >= 0 && !s[u[k]]) {
						s[u[k]] = 1;
						u[k] = -1;
						break;
					}
					++k;
				}
				cout << " " << (k + 1);
				++k;
			}
			cout << endl;
		}


	} else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

void solve(istream& cin, ostream& cout) {
  string s;
  cin >> s;
  if (s.find("7") < s.length()) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


Measured memory_bytes: 3676
/**
 *   author: sahushivam
 *   created: 01 September 2019 (Sunday)  17:57:33
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,a,b) for(int i = a; i<b; i++)
#define MOD 1000000009
#define INF 1e18
#define F first
#define S second
#define PB push_back
#define MP make_pair

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll ans=n*(n-1)/2;
    cout<<ans;
return 0;
}

Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
flag=0
for i in range(n):
  if A[i]%2==0:
    if A[i]%3!=0 and A[i]%5!=0:
     flag=1

if flag==0:
  print("APPROVED")
else:
  print("DENIED")

Measured memory_bytes: 9032
def solve(W,w):
    A=[1]*W
    for i in range(W-1,w-1,-1):
        A[i-w]=A[i]+1
    A[w-1::w]=[-i for i in range(1,W//w+1)]
    for i in range(W-2,-1,-1):
        A[i+1]-=A[i]
    return A

H,W,h,w=map(int, input().split())
if W%w:
    print("Yes")
    A=solve(W,w)
    for _ in range(H):
        print(*A)
elif H%h:
    print("Yes")
    A=solve(H,h)
    for i in range(H):
        print(*[A[i]]*W)
else:
    print("No")

Measured memory_bytes: 4436
#include<stdio.h>
#include<string.h>
int r,l,c;
char S[99];
int main()
{
	gets(S);
	for(r=strlen(S)-1,l=c=0;l<r;r--,l++)
	{
		if(S[l]=='('&&S[r]==')')continue;
		if(S[l]==')'&&S[r]=='(')continue;
		if((S[l]=='i'||S[l]=='w')&&S[l]==S[r])continue;
		c++;
	}
	if(l==r&&(S[r]==')'||S[r]=='('))c++;

	printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long


signed main(){
  int n;
  cin>>n;
  int ans=BIG;
  if(n<6){cout<<n<<endl;return 0;}
  int S=0;
  int N;
  int now=0;
  while(S<=n){
    N=(n-S)/9;
    N*=9;
    int ss=S;
    int nn=N;
    now=n-S-N;
    ss/=6;
    nn/=9;
    while(ss!=0){
      now+=ss%6;
      ss/=6;
    }
    while(nn!=0){
      now+=nn%9;
      nn/=9;
    }
    ans=min(ans,now);
    
    S+=6;
  }
  cout<<ans<<endl;
  return 0;
}


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

int main() {
    int X; cin >> X;
    bitset<100110> dp;
    dp[0] = 1;
    rep(v, 6) rep(i, 100000) {
        if(dp[i]) dp[i + 100 + v] = 1;
    }
    if(dp[X]) cout << 1 << '\n';
    else cout << 0 << '\n';
    return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second


int main(){
    ll n;
    cin >> n;
    vector<ll> b;

    rep(i,0,n){
        ll a;
        cin >> a;
        b.push_back(a);
    }

    vector<ll> ans;

    rep(k,0,n){
        rep(j,0,b.size()){
            ll i = b.size()-j-1;
            if(i+1 == b[i]){
                ans.push_back(i+1);
                b.erase(b.begin()+i);
                break;
            }
        }
    }
    if(b.empty()){
        rep(k,0,ans.size()){
            ll i = ans.size()-k-1;
            cout << ans[i] << endl;
        }
    }
    else{
        cout << -1 << endl;
    }

    return 0;
}


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

using namespace std;

#define ll long long

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> p(n),q(n);
    for(int i=0;i<n;i++) {
        cin >> p[i];
    }       
    for(int i=0;i<n;i++) {
        cin >> q[i];
    }
    vector<int> v(n);
    for(int i=0;i<n;i++) {
        v[i] = i+1;
    }
    int cnt = 0;
    int a = -1,b = -1;
    do {
        cnt++;
        if(v == p) {
            a = cnt;
        } 
        if(v == q) {
            b = cnt;
        }
        if(a != -1 && b != -1) {
            break;
        }
    } while(next_permutation(v.begin(),v.end()));
    cout << abs(a-b) << "\n"; 
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
 
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;
}
ll max(ll a, ll b){
    if(a > b) return a;
    else return b;
}
 
ll min(ll a, ll b){
    if(a < b) return a;
    else return b;
}

int main(void){
    int N; cin >> N;
    vector<int> a(N);
    int max_a = 0, min_a = 1100;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        max_a = max(max_a, a[i]);
        min_a = min(min_a, a[i]);
    }
    cout << max_a - min_a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <limits.h>
#include <vector>
#include <numeric>

using namespace std;



int wa(int n) {

	int result = 0;

	while (n > 0) {
		result += n % 10;
		n /= 10;
	}

	return result;


}


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

	int ans = INT_MAX;

	for (int i = 1; i <= (n + 1) / 2; i++) {

		ans = min(ans, wa(i) + wa(n - i));



	}

	cout << ans << endl;



	return 0;

}




Measured memory_bytes: 256
#include<stdio.h>

int main(){
  char S[11][5]={
    "pon",
    "pon",
    "hon",
    "bon",
    "hon",
    "hon",
    "pon",
    "hon",
    "pon",
    "hon"
  };
  int N;
  
  scanf("%d",&N);
  printf("%s\n",S[N%10]);
  
  return 0;
}

Measured memory_bytes: 1644
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N = I()
A = LI()


from math import gcd

g = 0  # Aiたちの最大公約数
for i in range(N):
    g = gcd(g,A[i])

if g != 1:
    print('not coprime')
    exit()


B = [0]*(10**6+1)
for i in range(N):
    B[A[i]] += 1

for d in range(2,5*10**5+1):
    a = sum(B[i] for i in range(d,10**6+1,d))
    if a >= 2:
        print('setwise coprime')
        break
else:
    print('pairwise coprime')

# 計算量 O(A*logA)
# A = max(Ai)


Measured memory_bytes: 197752
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define re register
using namespace std;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int N=5000+10;
const int mod=1e9+7;

struct edge { int v,nxt; } e[N<<1];
int head[N];

inline void addEdge(int u,int v) {
    static int e_cnt=0;
    e[++e_cnt]=(edge){v,head[u]},head[u]=e_cnt;
}

int n,sz[N];
int f[N][N],g[N],tmp[N];

inline void dfs(int u,int fa) {
    sz[u]=f[u][1]=1;
    for (re int i=head[u];i;i=e[i].nxt) {
        int v=e[i].v; if (v==fa) continue;
        dfs(v,u);
        for (re int j=1;j<=sz[u]+sz[v];++j) tmp[j]=0;
        for (re int j=1;j<=sz[u];++j)
            for (re int k=0;k<=sz[v];++k)
                tmp[j+k]=(tmp[j+k]+1ll*f[u][j]*f[v][k])%mod;
        sz[u]+=sz[v];
        for (re int j=1;j<=sz[u];++j) f[u][j]=tmp[j];
    }
    for (re int i=2;i<=sz[u];i+=2)
        f[u][0]=(f[u][0]-1ll*f[u][i]*g[i]%mod+mod)%mod;
}

int main() {
    n=read();
    for (re int i=1;i<n;++i) {
        int u=read(),v=read();
        addEdge(u,v),addEdge(v,u);
    }
    g[0]=1;
    for (re int i=2;i<=n;i+=2) g[i]=1ll*g[i-2]*(i-1)%mod;
    dfs(1,0); printf("%d\n",mod-f[1][0]);
    return 0;
}

Measured memory_bytes: 97024
def main():
  n, m, k = input_list()
  for x in range(n+1):
    for y in range(m+1):
      a = x*(m-y) + y*(n-x)
      if a == k:
        print('Yes')
        exit()
  print('No')
  
def input_list():
  return map(int, input().split())

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c 

import math
import fractions
from functools import reduce
main()

Measured memory_bytes: 5048
import java.util.Scanner

fun main(args: Array<String>) {
    println(
        a(args)
    )
}

fun a(args: Array<String>): String {
    val sc = Scanner(System.`in`)
    if (sc.nextInt() + sc.nextInt() + sc.nextInt() < 22) {
        return "win"
    }
    return "bust"
}

Measured memory_bytes: 31268
import itertools

N, M = map(int, input().split())
adj_matrix = [[0]* N for _ in range(N)]

for i in range(M): #隣接行列
    a, b = map(int, input().split())
    adj_matrix[a-1][b-1] = 1
    adj_matrix[b-1][a-1] = 1

cnt = 0

for each in itertools.permutations(range(N)):
    if each[0] != 0:
        break
    factor = 1
    for i in range(N-1):
        factor *= adj_matrix[each[i]][each[i+1]]
    cnt += factor

print(cnt)

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n,d,x;
  cin>>n>>d>>x;
  vi a(n);
  REP(i,n)cin>>a[i];
  REP(i,n){
    int e = 1;
    FOR(j,1,d+1)if(j==e){
      x++; e+=a[i];
    }
  }
  cout<<x<<endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

S = sum([abs(A[i] - A[i + 1]) for i in range(N - 1)]) + abs(A[0]) + abs(A[N - 1])

print(S - abs(A[0]) - abs(A[1] - A[0]) + abs(A[1]))
for i in range(1, N - 1):
    print(S - abs(A[i] - A[i - 1]) - abs(A[i] - A[i + 1]) + abs(A[i + 1]  - A[i - 1]))
print(S - abs(A[N - 1]) - abs(A[N - 1] - A[N - 2]) + abs(A[N - 2]))


Measured memory_bytes: 14044
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;
template<typename T>
inline void read(T& s)
{
    s=0;int f=1;char c=getchar();
    while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0' && c<='9'){s=s*10+c-'0';c=getchar();}
    s*=f;
}
//set<int>mp[200005];
set<int>vis[200005];
int n,m;
int k;
int x[200005];
int y[200005];
int main()
{
	read(n);
	read(m);
	read(k);
	for(int i=0;i<k;i++)
	{
		read(x[i]);
		read(y[i]);
		vis[y[i]].insert(x[i]);
	}
	for(int i=1;i<=m;i++)
		vis[i].insert(n+1);
	int cnt=0;
	int ans=12345678;
	bool o=0;
	int nx=1,ny=1;
	int ste=0;
	while(1)
	{
		cnt++;
		if(o==0)
		{
			if(vis[ny].count(nx+1)==0)
			{
				nx++;
				ste=0;
			}
			else
			{
				ste++;
				if(ste>=2)
				{
					ans=min(ans,(cnt+1)/2);
					break;
				}
			}
		}
		else
		{
			auto fie=*vis[ny].upper_bound(nx);
			ans=min(ans,cnt/2+fie-nx-1+(1-ste));
			if(ny<m && vis[ny+1].count(nx)==0)
			{
				ny++;
				ste=0;
			}
			else
			{
				ste++;
				if(ste>=2)
				{
					ans=min(ans,cnt/2);
					break;
				}
			}
		}
		o^=1;
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 29952
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;

ll D, G;

int main() {
    cin >> D >> G;

    vector<ll> p(D), c(D);
    rep(i, D) {
        cin >> p[i] >> c[i];
    }

    ll ans = 1e9;

    // 全探索
    rep(i, 1 << D) {
        ll sum = 0, count = 0;

        // ボーナス点を使う場合
        rep(j, D) {
            if (i >> j & 1) {
                sum += p[j] * (j + 1) * 100 + c[j];
                count += p[j];
            }
        }

        // 個別問題の高いものから解いていく 
        for (ll j = D - 1; j >= 0; j--) {
            if (i >> j & 1) continue;
            if (sum >= G) continue;

            int q = min((G - sum) / ((j + 1) * 100), p[j]);
            count += q;
            sum += (j + 1) * 100 * q;
        }

        if (sum >= G) {
            ans = min(ans, count);
        }
    }

    cout << ans << endl;
}

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

int main(){
  long long n, a, b;
  cin >> n >> a >> b;
  if(n == 1 && a != b){
    cout << 0 << endl;
    return 0;
  }
  long long ans = ((n-1)*b + a) - ((n-1)*a + b) + 1;
  cout << max(ans, 0LL) << endl;
  return 0;
}

Measured memory_bytes: 256