akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(){
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(r<=x && x<=W-r){
		if(r<=y && y<=H-r){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 584
require 'bigdecimal'

n = gets
until n.nil?
 a = n.split
 x1 = a[0].to_f
 y1 = a[1].to_f
 x2 = a[2].to_f
 y2 = a[3].to_f
 x3 = a[4].to_f
 y3 = a[5].to_f
 x4 = a[6].to_f
 y4 = a[7].to_f

 x12 = BigDecimal(x1.to_s) - BigDecimal(x2.to_s)
 x34 = BigDecimal(x3.to_s) - BigDecimal(x4.to_s)
 y12 = BigDecimal(y1.to_s) - BigDecimal(y2.to_s)
 y34 = BigDecimal(y3.to_s) - BigDecimal(y4.to_s)
 
 if x12.to_f == 0.0 && y12.to_f == 0.0
  puts "NO"
 elsif x34.to_f == 0.0 && y34.to_f == 0.0
  puts "NO"
 elsif y12.to_f == 0.0
  if x34.to_f == 0.0 
   puts "YES"
  else
   puts "NO"
  end
 elsif y34.to_f == 0.0
  if x12.to_f == 0.0
   puts "YES"
  else
   puts "NO"
  end
 elsif x12.to_f == 0.0
  if y34.to_f == 0.0
   puts "YES"
  else
   puts "NO"
  end
 elsif x34.to_f == 0.0
  if y12.to_f == 0.0
   puts "YES"
  else
   puts "NO"
  end
 else
 ab = BigDecimal(x12.to_s) / BigDecimal(y12.to_s)
 cd = BigDecimal(x34.to_s) / BigDecimal(y34.to_s)
 ad = BigDecimal(ab.to_s) * BigDecimal(cd.to_s)
  if ad.to_f == -1.0
   puts "YES"
  else
   puts "NO"
  end
 end

 n = gets
end



Measured memory_bytes: 7036
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

a,b,c,d = map(int,input().split())
lcm = int(c*d/gcd(c,d))

total = b-a+1
totalc = b//c-(a-1)//c
totald = b//d-(a-1)//d
totalcd = b//lcm-(a-1)//lcm
print(total - (totalc + totald - totalcd))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
    #define MAXN 2550
    #define pii pair<int, int>
    #define ff first
    #define ss second
    #define ll long long
    #define in_range(x, y, n) (x >= 0 and x < n and y >= 0 and y < n)
    using namespace std;
    const ll mod = 1e9 + 7;


    int main() {
        ios_base::sync_with_stdio(false);
        int n;
        cin >> n;
        vector<int> v(n);

        for (int& x: v) cin >> x;

        sort(v.begin(), v.end());
        int ans = 0;

        for (int i=0; i<n-2; i++){
            for (int j=i+1; j<n-1; j++){
                for (int k = j+1; k<n; k++){
                    if (v[k] >= v[i] + v[j]) break;
                    ans++;
                }
            }
        }

        cout << ans << endl;
        return 0;
    }

Measured memory_bytes: 3680
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




int main(){

	char S[5];
	scanf("%s",S);

	int num = 0;
	for(int i = 0; S[i] != '\0'; i++){

		if(S[i] == '+'){

			num++;
		}else{

			num--;
		}
	}

	printf("%d\n",num);

	return 0;
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

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

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


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

bool g[101][101];

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

    ll sum = 0;
    vector<ll> A(N);
    REP(i, N) {
        cin >> A[i];
        sum += A[i];
    }

    if (sum % (N * (N + 1) / 2) != 0) {
        cout << "NO" << endl;
        return 0;
    }


    ll k = sum / (N * (N + 1) / 2);

    vector<ll> d(N);
    REP(i, N) {
        if (i + 1 == N) d[i] = A[0] - A[i] - k;
        else d[i] = A[i + 1] - A[i] - k; 
    }

    bool ans = true;
    ll cnt = 0;
    REP(i, N) {
        if(d[i] == 0) continue;
        if(d[i] > 0 || (-d[i]) % N != 0) {
            ans = false;
            break;
        }

        cnt += (-d[i]) / N;
    }

    if (ans && cnt == k) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007 
#define pb push_back
//#define mp make_pair
#define INF 2000000011LL
#define INFLL 1000000000000000011LL
#define eps 1e-9
#define pp pair < pair<ll,ll> , ll> 
#define fo(i,j,k) for(int i=j;i<=k;i++)
#define foll(i,j,k) for(ll i=j;i<=k;i++)
#define clr(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vll vector<ll>
#define sz(a) a.size()
#define len(a) a.length()
#define all(a) a.begin(),a.end()
#define io_file freopen("Contest/input_file.in", "r", stdin); freopen("Contest/output_file.in", "w", stdout)

const int MAXN = 2e5+5;
using namespace std;
ll power(ll x, ll y)
{
  ll res = 1;
  while(y>0)
  {
    if(y&1)
       {
         res = (res*x)%mod;
        }
     x = (x*x)%mod;
     y = y>>1;
  }
    return res;
}
// std::vector<ll> divi[100004];
// void divisor(int n)
// {
//    for(ll i=1;i<=n;i++)
//    {
//      for(ll j=i;j<=n;j+=i)
//      {
//        divi[j].pb(i);
//      }
//    }
// }
ll n;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    ll x,r,d;
    cin>>r>>d>>x;
    for(int i=1;i<=10;i++)
    {
      x = r*x - d;
      cout<<x<<endl;
    }
    cout<<endl;
    return 0;

}



Measured memory_bytes: 256
class Otoshidama():
    def calculate(self, N, Y):
        for a in range(N+1):
            for b in range(N+1):
                c = N - a -b
                if c < 0:
                    break
                res = 10000 * a + 5000 * b + 1000 * c
                if Y == res:
                    print("{} {} {}".format(a,b,c))
                    return
        print("-1 -1 -1")

if __name__ == '__main__':
    N, Y = map(int, input().split())
    o = Otoshidama()
    o.calculate(N, Y)

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

int main(){
    int n;
    cin>>n;
    int l[n];
    int sum=0;
    for(int i=0;i<n;i++){
        cin>>l[i];
        sum+=l[i];
    }
    sort(l,l+n,greater<>());
    if(sum-l[0]>l[0]) cout<< "Yes"<<endl;
    else cout<<"No" << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long K = sc.nextLong();
		if (K <= A) {
			A -= K;
		} else if (A < K) {
			B -= (K - A);
			A = 0;
			if (B < 0) {
				B = 0;
			}
		}
		System.out.println(A + " " + B);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<int> vec[25];

bool judge(int a,int b)
{
    double tmp=0;
    for(int i=0;i<vec[a].size();++i)
        tmp+=(vec[a][i]-vec[b][i])*(vec[a][i]-vec[b][i]);

    ll aa=tmp;
    ll tt=sqrt(tmp);
    if(tt*tt==aa)
        return true;
    return false;
}

int main()
{
    int n,d;
    cin>>n>>d;
    for(int i=0; i<n; ++i)
    {
        int t;
        for(int j=0; j<d; ++j)
        {
            cin>>t;
            vec[i].push_back(t);
        }
    }
    int ans=0;
    for(int i=0;i<n-1;++i)
        for(int j=i+1;j<n;++j)
            ans+=judge(i,j);
    cout<<ans;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  bool hasA = false;
  bool hasB = false;
  bool hasC = false;
  for(auto c : S)
  {
    if(c == 'a')
      hasA = true;
    else if(c == 'b')
      hasB = true;
    else if(c == 'c')
      hasC = true;
  }

  if(hasA&&hasB&&hasC)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

using namespace std;

typedef pair<int,int> pii;

struct Edge{
	int src,dst;
	Edge(){}
	Edge(int s,int d):src(s),dst(d){}
};
typedef vector<vector<Edge>> Graph;

bool ok(const map<pii,int>& ishead,pii head,pii foot)
{
	for(int i=0;i<4;i++){
		int nx,ny;
		nx=head.first+"\xff\x1\0\0"[i],ny=head.second+"\0\0\xff\x1"[i];
		if(pii(nx,ny)!=foot && ishead.count(pii(nx,ny)) && !ishead.at(pii(nx,ny)))
			return false;
		nx=foot.first+"\xff\x1\0\0"[i],ny=foot.second+"\0\0\xff\x1"[i];
		if(pii(nx,ny)!=head && ishead.count(pii(nx,ny)) && ishead.at(pii(nx,ny)))
			return false;
	}
	return true;
}

bool dfs(const vector<pair<pii,pii>>& ps,const Graph& g,int v,vector<int>& vis,map<pii,int>& ishead)
{
	if(vis[v]) return true;
	vis[v]=1;
	
	if(ok(ishead,ps[v].first,ps[v].second))
		ishead[ps[v].first]=1,ishead[ps[v].second]=0;
	else if(ok(ishead,ps[v].second,ps[v].first))
		ishead[ps[v].second]=1,ishead[ps[v].first]=0;
	else
		return false;
	
	for(Edge e:g[v])
		if(!dfs(ps,g,e.dst,vis,ishead))
			return false;
	return true;
}

int main()
{
	for(int n;cin>>n,n;){
		vector<pair<pii,pii>> ps(n);
		for(int i=0;i<n;i++){
			int x,y; char d; cin>>x>>y>>d;
			ps[i].first=pii(x,y);
			if(d=='x')
				ps[i].second=pii(x+1,y);
			else
				ps[i].second=pii(x,y+1);
		}
		
		map<pii,int> grid;
		for(int i=0;i<n;i++){
			grid[ps[i].first]=i;
			grid[ps[i].second]=i;
		}
		
		Graph g(n);
		for(int i=0;i<n;i++)
			for(int j=0;j<2;j++){
				int cx=(!j?ps[i].first:ps[i].second).first;
				int cy=(!j?ps[i].first:ps[i].second).second;
				for(int k=0;k<4;k++){
					int nx=cx+"\xff\x1\0\0"[k];
					int ny=cy+"\0\0\xff\x1"[k];
					if(!grid.count(pii(nx,ny))) continue;
					int v=grid.at(pii(nx,ny));
					if(v!=i){
						g[i].emplace_back(i,v);
						g[v].emplace_back(v,i);
					}
				}
			}
		
		map<pii,int> ishead;
		vector<int> vis(n);
		bool res=true;
		for(int i=0;i<n;i++) if(!vis[i])
			res&=dfs(ps,g,i,vis,ishead);
		cout<<(res?"Yes":"No")<<endl;
	}
}

Measured memory_bytes: 10764
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
int main(){
	string s;
	cin>>s;
	int a[500000];
	int n=s.size();
	fill(a,a+n+1,-1);
	vector<int> hoge;
	for(int i=0;i+1<n;i++){
		if(s[i]=='>'&&s[i+1]=='<'){
			a[i+1]=0;
			hoge.push_back(i+1);
		}
	}
	if(s[0]=='<'){
		a[0]=0;
		hoge.push_back(0);
	}
	if(s[n-1]=='>'){
		a[n]=0;
		hoge.push_back(n);
	}
	for(int i=0;i<hoge.size();i++){
		int now=hoge[i];
		now--;
		while(now>=0&&a[now]==-1&&s[now]=='>'){
			a[now]=a[now+1]+1;
			now--;
		}
		now=hoge[i];
		now++;
		while(now<=n&&a[now]==-1&&s[now-1]=='<'){
			a[now]=a[now-1]+1;
			now++;
		}
	}
	for(int i=0;i<n;i++){
		if(s[i]=='<'){
			if(a[i]>=a[i+1]){
				a[i+1]=a[i]+1;
			}
		}else if(s[i]=='>'){
			if(a[i]<=a[i+1]){
				a[i]=a[i+1]+1;
			}
		}
	}
	long long ans=0; 
	for(int i=0;i<=n;i++){
		ans+=a[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3460
fun readList() = readLine()!!.split(" ").map{it.toInt()}
fun main(args:Array<String>){
  val n = readLine()!!.toInt()
  val b = readList()
  var answer = b[0]+b[n-2]
  for(i in 0 until n-2){
    answer += Math.min(b[i],b[i+1])
  }
  println(answer)
}

Measured memory_bytes: 37688
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# LANGUAGE BangPatterns      #-}
{-# LANGUAGE CPP               #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections     #-}

import           Control.Applicative
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString.Char8       as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           Unsafe.Coerce

main :: IO ()
main = do
    !n <- readLn :: IO Int
    xs <- U.unfoldrN n (B.readInt.B.dropWhile isSpace) <$> B.getLine
    print $ solve xs `mod` modulus

modulus :: Int
modulus = 1000000007

solve :: U.Vector Int -> Int
solve xs = go 1 1 1 . tail  $ U.toList xs
  where
    go !acc !len !prev (cur:xs)
      | cur-prev == 1 = go (acc * (len+1) `rem` modulus) len prev xs
      | otherwise = go acc (len+1) (prev+2) xs
    go acc len _ _ = foldl' (\acc x->acc*x`rem`modulus) acc [1..len]

Measured memory_bytes: 2940
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

points = {
    'r' : P,
    's' : R,
    'p' : S
}

ans = 0
for t in T:
    ans += points[t]

for k in range(K):
    left = k
    while left < N:
        right = left
        while right < N and T[right] == T[left]:
            right += K
        cnt = (right - left) // K
        ans -= points[T[left]] * (cnt // 2)
        left = right
print(ans)


Measured memory_bytes: 3316
#include "bits/stdc++.h"
using namespace std;
int GCD(int A, int B) {
	if (B == 0) return A;
	else return GCD(B, A % B);
}
int main() {
	int N, K;
	cin >> N >> K;
	vector<int>A(N);
	int MAX = 0;
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
		if (MAX < A.at(i)) MAX = A.at(i);
	}
	int gcd = A.at(0);
	for (int i = 0; i < N; i++) {
		gcd = GCD(gcd, A.at(i));
	}
	if (K % gcd == 0 && K <= MAX) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
}


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

using namespace std;

const int maxn = 110;
int a[maxn][maxn], dp[maxn][maxn], n, m;

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

        for (int i = 0; i < n; i++) {
                string s;
                cin >> s;
                for (int j = 0; j < m; j++)
                        a[i][j] = s[j] == '#';
        }

        memset(dp, 63, sizeof dp);
        dp[0][0] = a[0][0];
        for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                        dp[i][j + 1] = min(dp[i][j + 1], a[i][j] == a[i][j + 1] ? dp[i][j] : dp[i][j] + a[i][j + 1]);
                        dp[i + 1][j] = min(dp[i + 1][j], a[i][j] == a[i + 1][j] ? dp[i][j] : dp[i][j] + a[i + 1][j]);
                }
        }

        cout << dp[n - 1][m - 1];

        return 0;
}

Measured memory_bytes: 384
#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 vector<pii> vii;
typedef vector<pll> vll;

const double PI = acos(-1);
#define MOD 1000000007

#define PB push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define all(a) (a).begin(), (a).end()
#define sz(x) (int)x.size()
#define el <<'\n'
#define sp <<' '

#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (abs(a*b)/gcd(a,b))
#define sqr(a) (a*a)

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

///binary to decimal
long double btod(string a){
    long double i,c=sz(a)-1,s=0,d=0;
    for(i=c;i>=0;i--){
        a[i]-=48;
        s+=a[i]*pow(2,d);
        d++;
    }
    return s;
}

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











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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, t; double a;cin >> n >> t >> a;
    int idx = 0;
    double mn = 1e9;
    for(int i = 0; i < n ; i++){
        double aux; cin >> aux;
        if(abs(a - (t - aux*0.006 )) < mn){
            idx = i;
            mn = abs(a - (t - aux*0.006 ));
        }
    }
    cout << idx + 1 << "\n";
    return 0;        
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+9
#define MOD 1000000007
using namespace std;

int main(){
    int N;
    cin >> N ;
    int p[N];
    for(int i=0; i<N; i++){
        cin >> p[i];
        p[i]--;
    }
    
    int ans=0;
    for(int i=0; i<N-1; i++){
        if(p[i]==i){
            swap(p[i],p[i+1]);
            ans++;
        }
    }
    
    if(p[N-1]==N-1){
        ans++;
    }
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#define maxn 100005
#define LL long long
#define INF (LL)(1e16)
using namespace std;
LL n,m,val,l,r,x[maxn],g[maxn],s[maxn];
bool vis[maxn];
struct node { int v,i; };
vector<node> G[maxn];
void nosol()
{
	printf("0\n");
	exit(0);
}
void dfs(int u,LL z,LL w)
{
	g[u]=z,x[u]=w;
	for(int i=0;i<G[u].size();i++)
	{
		int v=G[u][i].v,k=G[u][i].i;
		if(!vis[k])
		{
			vis[k]=true;
			if(g[v]==-INF)
			{
				g[v]=s[k]-z; x[v]=-w;
				if(x[v]<0) r=min(r,g[v]),l=max(l,-z);
				else r=min(r,z),l=max(l,-g[v]);
				dfs(v,g[v],x[v]);
			}
			else
			{
				if(x[v]+x[u]==0)
				{	
					if(g[v]+z!=s[k])
						nosol();
					if(x[v]<0) r=min(r,g[v]),l=max(l,-z);
					else r=min(r,z),l=max(l,-g[v]);
				}
				if(x[v]==x[u])
				{
					if(x[v]<0) r=min(r,min(g[v],z));
					else l=max(l,max(-g[v],-z));
					if((s[k]-g[v]-z)%2) nosol();
					LL temp=(s[k]-g[v]-z)/(2*x[u]);
					if(temp<=0) nosol();
					if(temp==val||val==-1) val=temp;
					else nosol();
				}
			}
		}
	}
}
int main()
{
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int u; node p;
		scanf("%d%d%lld",&u,&p.v,&s[i]);
		p.i=i;
		G[u].push_back(p);
		swap(u,p.v);
		G[u].push_back(p);
	}
	val=-1,r=INF,l=0;
	for(LL i=1;i<=n;i++) g[i]=-INF;
	dfs(1,0,1);
	if(val==-1) printf("%lld\n",max(r-l-1,0ll));
	else if(l<val&&val<r) printf("1\n");
	else printf("0\n");
}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
 
/*
*****************code written By**********************
..................Marajul islam.......................
...................BSMRSTU,CSE........................
*/ 
 
int sc1() {int x; scanf("%d", &x); return x;}
 
long long sc2() {long long x; scanf("%lld", &x); return x;}
 
 
 
#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  Int              sc1()
#define  LL               sc2()
#define  For(n)           for(int i=0;i<n;i++)
#define  Forj(n)          for(int j=0;j<n;j++)
#define  Fork(n)          for(int k=0;k<n;k++)
#define  For1(n)          for(int i=1;i<=n;i++)
#define  ll               long long
#define  vi               std::vector<int>
#define  vll              std::vector<ll>
#define  qui              qu
#define  pb               push_back
#define  mpsi             std::map<string, int>
 
 
const int mod           = 1e9 + 7;
const int inf           = (int)2e9 + 5;
const ll  Inf           = (ll)1e18 + 5;
const int N             = 5e6 + 5;
 
inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (ll)a * b % mod;}
 
ll ans=0;

ll sol(ll h){
	
	if(h==1) return 1;
	else{
	 	ll ab=sol(h/2);
	 	return 2ll*ab+1;
	}
} 
 
int solve() {
 
	ll h=LL;
	ll k=sol(h);
	cout<<k<<endl;
 
	return 0;
}
 
 
 
 
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
 
	int test = 1, tc = 0;
	//scanf("%d", &test);
	//cin >> test;
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
 
	return 0;
 
 
 
 
}




Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AHappyBirthday solver = new AHappyBirthday();
        solver.solve(1, in, out);
        out.close();
    }

    static class AHappyBirthday {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            out.println(in.nextInt() > 8 || in.nextInt() > 8 ? ":(" : "Yay!");
        }

    }
}



Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define len(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "YES" << endl
#define pyes cout << "Yes" << endl
#define POK cout << "OK" << endl
#define PNO cout << "NO" << endl
#define pno cout << "No" << endl
#define PNG cout << "NG" << endl
#define ret return 0

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>


signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int l,r,d; cin >> l >> r >> d;
  int res=0;
  for(int i=l;i<=r;i++){
    res += i%d==0;
  }
  cout << res << endl;
  ret;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  int g, k;
  g = n * (n - 1) / 2;
  k = m * (m - 1) / 2;
  cout << g + k << endl;
}

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

int main(int argc, const char * argv[]) {
    int N;
    cin >> N;
    if (N > 81) {
        cout << "No" << endl;
        return 0;
    }
    
    if (N >= 1 && N<=9) {
        cout << "Yes" << endl;
        return 0;
    }
    
    for (int i = 2; i <= 9; i++) {
        int amari = N % i;
        if (amari == 0) {
            int div = N / i;
            if ((div / 10) == 0) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    
    cout << "No" << endl;
    return 0;
}

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

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

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

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main( ){
    int n;
    cin>>n;
    vi s(n);
    rep(i,0,n)cin>>s[i];
    sort(s.begin(),s.end());
    int res=0;
    rep(i,0,n)res+=s[i];
    if(res%10==0)
        for(int i=0;i<n;i++)
            if(s[i]%10!=0){
                res-=s[i];
                break;
            }
    if(res%10!=0)
    cout<<res<<endl;
    else
    cout<<0<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846

using namespace std;

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FILL(a, x) memset(a, x, sizeof(a))

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)

double dp[3005][3005];

int main() {
	int n;
	scanf("%d", &n);
	dp[0][0] = 1;
	REP(i, n) {
		double p;
		scanf("%lf", &p);
		REP(j, i+1) {
			dp[i + 1][j + 1] += dp[i][j] * p;
			dp[i + 1][j] += dp[i][j] * (1 - p);
		}
	}
	double ret = 0;
	for (int i = n; i >= (n + 1) / 2; i--)ret += dp[n][i];
	printf("%.12f\n", ret);
	return 0;
}

Measured memory_bytes: 68992
#pragma warning(disable:4996)
#include "bits/stdc++.h"
using namespace std;

//macro
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,a,b) for(int i=(int)(b) - 1;i>=(int)(a);i--)
#define rrep(i,n) RREP(i,0,n)
#define each(i, ctn) for (auto &&i : (ctn))
#define all(a) (a).begin(),(a).end()
#define mp make_pair
#define INFL 1145148100000000000LL
#define EPS (1e-8)
#define MOD 1000000007
#define PI 3.141592653589793
#define equals(a,b)(fabs((a)-(b))<EPS)

//alias
using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vs = vector<string>;
using P = pair<ll, ll>;
template<class T> using heap = priority_queue<T>;
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;

//func
template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H);	rep(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n)os << v[i] << (i == n - 1 ? "\n" : " "); return os; }
template <class T = int> inline T in() { T x; cin >> x; return x; }
template<class T> inline void print(const T &x) { cout << x << '\n'; }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } pre__;

#define INF 114514810

using Weight = int;
struct Edge {
	int src, dst;
	Weight weight;
	Edge(int src_, int dst_, Weight weight_) : src(src_), dst(dst_), weight(weight_) { }
};
bool operator<(const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : e.dst < f.dst;
}
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void edgesToGraph(const Edges &edges, int V, Graph &g) {
	g.resize(V);
	for (auto e : edges) g[e.src].push_back(e);
}

void dijkstra(const Graph &g, int start,
	vector<Weight> &dist, vector<int> &prev) {
	size_t V = g.size();
	dist.assign(V, INF); dist[start] = 0;
	prev.assign(V, -1);
	priority_queue<Edge> q;
	for (q.push(Edge(-2, start, 0)); !q.empty(); ) {
		Edge e = q.top(); q.pop();
		if (prev[e.dst] != -1) continue;
		prev[e.dst] = e.src;
		for (auto a : g[e.dst]) {
			if (dist[a.dst] > e.weight + a.weight) {
				dist[a.dst] = e.weight + a.weight;
				q.push(Edge(a.src, a.dst, e.weight + a.weight));
			}
		}
	}
}

int main() {
	int H, W;
	cin >> H >> W;
	Edges edges;
	rep(i, 10) {
		rep(j, 10) {
			int C;
			cin >> C;
			if (i == j)continue;
			edges.emplace_back(Edge(i, j, C));
		}
	}
	Graph g;
	edgesToGraph(edges, 10, g);
	
	int cost = 0;
	rep(h, H) {
		rep(w, W) {
			int A;
			cin >> A;
			if (A == -1)continue;
			vector<Weight> dist;
			vector<int> prev;
			dijkstra(g, A, dist, prev);
			cost += dist[1];
		}
	}

	cout << cost << endl;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env pypy
from __future__ import division, print_function
from collections import defaultdict, Counter, deque
from future_builtins import ascii, filter, hex, map, oct, zip
from itertools import imap as map, izip as zip
from itertools import permutations
from __builtin__ import xrange as range
from math import ceil
from _continuation import continulet
from cStringIO import StringIO
from io import IOBase
import __pypy__
from math import log, ceil, floor
from bisect import bisect, insort, bisect_left, bisect_right
from heapq import heapify, heappop, heappush
import sys
import os
import re
inf = float('inf')
mod = int(1e9) + 7
mod_ = 998244353
 
'''

!!!!!!!!!!!!!!!!!!!!!!!!   WAIT FFS    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
DONOT SUBMIT RECKLESSLY
One wrong submission = 10 mins penalty!
Check for special cases (n=1)

'''

def printGrid(grid):
	for row in grid:
		print(' '.join(list(map(str, row))))


def main():
	n = int(input())
	prob = [0] + list(map(float, input().split()))
	dp = [[0]*(n+1) for i in range(n+1)]
	# dp[i][j] = prob of getting j heads with i coin tosses
	dp[0][0] = 1
	for i in range(1, n+1):
		for j in range(i+1):
			dp[i][j] = (dp[i-1][j-1] * prob[i] if j-1 >= 0 else 0) + dp[i-1][j] * (1 - prob[i])
			
	total = 0
	for i in range((n+1)//2, n+1):
		total += dp[n][i]

	# printGrid(dp)
	print(total)



# Fast IO
BUFSIZE = 8192
class FastI(IOBase):
	def __init__(self, file):
		self._fd = file.fileno()
		self._buffer = StringIO()
		self.newlines = 0
 
	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
		self.newlines = 0
		return self.buffer.read()
 
	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count("\n") + (not b)
			ptr = self._buffer.tell()
			self._buffer.seek(0, 2), self._buffer.write(
				b), self._buffer.seek(ptr)
		self.newlines -= 1
		return self._buffer.readline()
class FastO(IOBase):
	def __init__(self, file):
		self._fd = file.fileno()
		self._buffer = __pypy__.builders.StringBuilder()
		self.write = lambda s: self._buffer.append(s)
 
	def flush(self):
		os.write(self._fd, self._buffer.build())
		self._buffer = __pypy__.builders.StringBuilder()
def print(*args, **kwargs):
	sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop("end", "\n"))
	if kwargs.pop("flush", False):
		file.flush()
def gcd(x, y):
	while y:
		x, y = y, x % y
	return x
sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
	def bootstrap(cont):
		call, arg = cont.switch()
		while True:
			call, arg = cont.switch(to=continulet(
				lambda _, f, args: f(*args), call, arg))
	cont = continulet(bootstrap)
	cont.switch()
	main()

Measured memory_bytes: 170652
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 2e5 + 100, maxm = 1 << 26, INF = 0x3f3f3f3f;
int dp[maxm + 5];
char s[maxn];
inline int idx(char c){return c - 'a';}
int main()
{
	scanf("%s", &s);
	int len = strlen(s);
	memset(dp, INF, sizeof dp); dp[0] = 0;
	int tmp = 0;
	for(int i = 0; i < len; ++i)
	{
		tmp ^= (1 << idx(s[i]));
		for(int j = 0; j < 26; ++j) dp[tmp] = min(dp[tmp], dp[tmp^(1 << j)] + 1);
	}
	printf("%d\n", max(1, dp[tmp]));
	return 0;
}

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

#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define OUT(a) cout << (a) << "\n"
#define ll long long
#define uint unsigned int
#define ushort unsigned short
#define ulong unsigned long

ll MOD = 10e9 + 7;

int main() {
    string s;
    cin >> s;
    string out;
    REP(i, s.size()) {
        out += "x";
    }
    cout << out << endl;
    return 0;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define fake false
	

int main() {
	int K, S;
	cin >> K >> S;
	int cnt = 0;
	for (int X = 0; X <= K; X++) {
		for (int Y = 0; Y <= K && X + Y <= S; Y++) {
			int Z = S - X - Y;
			if (0 <= Z && Z <= K) cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define For(i, j, k) for(register int i = (j); i <= (k); ++i)
#define Forr(i, j, k) for(register int i = (j); i >= (k); --i)
using namespace std;

template <typename T>
inline void read(T &x){
	T p = 1, c = getchar();
	x = 0;
	while(!isdigit(c)){
		if(c == '-') p = -1;
		c = getchar();
	}
	while(isdigit(c)){
		x = (x << 1) + (x << 3) + (c ^ 48);
		c = getchar();
	}
	x *= p;
}

template<typename T> inline bool chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }

inline void File(){
#ifndef ONLINE_JUDGE
	freopen("C.in", "r", stdin);
	freopen("C.out", "w", stdout);
#endif
}

int A[5], limit;

int main(){
	For(i, 1, 3) read(A[i]), chkmax(limit, A[i]);
	int V = limit - A[1] + limit - A[2] + limit - A[3];
	if(!(V & 1)){
		printf("%d\n", V >> 1);
		return 0;
	}
	while((V + 3)&1){
		V += 3;
	}
	V += 3;
	printf("%d\n", V >> 1);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n,j,temp,prev,k,data[200005],order[200005][2],i,f=1,b,start=0,s,a;
  long m=0;
  scanf("%d",&n);
  scanf("%d",&s);
  for(i=0;i<n;i++){
  	scanf("%d",&data[i]);
    order[i][0] = -1;
    order[i][1] = i + 1;
  }
  order[n - 1][1] = -1;
  while (order[start][1] != -1) {
    i = start;
    prev = -1;
    while (i != -1) {
      j = i;
      k = order[j][1];
      if (k == -1) break;
      i = order[k][1];
      if (data[j] < data[k]) {
        if (prev == -1) {
          start = k;
        } else {
          order[prev][1] = k;
        }
        temp = j;
        j = k;
        k = temp;
      }
      order[j][1] = i;
      prev = j;
      while (k != -1) {
        if ((j == -1) | (data[j] < data[k])) {
          temp = order[k][0];
          order[k][0] = order[a][0];
          order[a][0] = k;
          a = k;
          k = temp;
      	} else {
          a = j;
          j = order[a][0];
        }
      }
    }
  }
  for (i = start,j=0; i != -1; i = order[i][0],j++) {
    if(j>=s) m+=data[i];
  }
  printf("%ld",m);
  return 0;
}

Measured memory_bytes: 2560
def main():
    """有向グラフの深さ優先探索
    
    Note: V[i]は頂点iから通じる頂点の集合を意味するが, 
             V[i]: {i}とV[i]: Noneは同値とされている。
    """
    stack = []
    passed_lines = []
    
    n = int(input())
    V = [None]*(n+1)
    D = [None]*(n+1)
    F = [None]*(n+1)
    passed_vertices = set()
    vertices = set(range(1, n+1))
    
    for i in range(1, n+1):
        _, _, *v = map(int, input().split())
        V[i] = set(v)

    i = 1
    time = 1
    stack.append(i)
    passed_vertices.add(i)
    D[i] = time
    while i <= n:
        new_vertices = list(V[i] - passed_vertices - {i})
        new_vertices.sort()
        if new_vertices:
            i = new_vertices[0]
            stack.append(i)
            time += 1
            if D[i] is None:
                D[i] = time
                passed_vertices.add(i)
            continue
        else:
            while stack:
                i = stack.pop()
                time += 1
                if list(V[i] - passed_vertices - {i}):
                    stack.append(i)
                    time -= 1
                    break
                if F[i] is None: 
                    F[i] = time
        if not list(V[i] - passed_vertices - {i}) and not stack:
            rest_vertices = list(vertices-passed_vertices)
            if rest_vertices:
                i = min(rest_vertices)
                stack.append(i)
                time += 1
                if D[i] is None:
                    D[i] = time
                    passed_vertices.add(i)
            else:
                break
    for id, d, f in zip(range(1, n+1), D[1:], F[1:]):
        print("{} {} {}".format(id, d, f))
        
if __name__ == "__main__":
    main()


Measured memory_bytes: 5628
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
delta = [0] * N
ans = 0
shortage = 0
for i in range(N):
	delta[i] = A[i] - B[i]
	if delta[i] < 0:
		ans += 1
		shortage += delta[i]
 
if shortage < 0:
    supply = [x for x in delta if x > 0]
    supply.sort(reverse=True)
    for i in supply:
        shortage += i
        ans += 1
        if shortage >= 0: break
 
if shortage >= 0:
	print(ans)
else:
	print(-1)

Measured memory_bytes: 18356
ans = {"AC" : 0,
	"WA" : 0,
	"TLE" : 0,
	"RE" : 0}
for t in range(int(input())):
	ans[input()] += 1

it = ["AC","WA","TLE","RE"]
for s in it:
	print("%s  x  %s" % (s,ans[s]))


Measured memory_bytes: 69848
//
#include <bits/stdc++.h>
using namespace std;
using lli=int64_t;
template<size_t SIZE, class T> inline size_t array_size(T (&arr)[SIZE]) {
    return SIZE;
}

int main() {
#if LOCAL&0
  	std::ifstream in("input.txt");
  	std::cin.rdbuf(in.rdbuf());
#endif
    int N;
    cin>>N;
    vector<string> sv(N);
    for (auto& s: sv) {
        cin>>s;
    }
    int ba=0;
    int xa=0;
    int bx=0;
    int num=0;
    for (const auto& s:sv) {
        for(int i=0;i<s.size()-1;++i){
            if(s[i]=='A'&&s[i+1]=='B'){
                ++num;
            }
        }

        bool a=false;
        bool b=false;
        if (s[0]=='B') b=true;
        if (s[s.size()-1]=='A') a=true;
        if (a&&b) {
            ++ba;
        } else if (a) {
            ++xa;
        } else if (b) {
            ++bx;
        }
    }
    num += std::max(ba-1,0);
    if (ba>0&&xa>0) {
        ++num;
    } else if (ba>0&&bx>0) {
        ++num;
    }
    num+=std::min(xa,bx);
    cout<<num<<endl;
    return 0;
}

Measured memory_bytes: 768
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
using namespace std;
typedef pair<int, int> pii;
typedef long long LL;
const int MAXN = 123456;
const int NEG = -MAXN;
vector<int> G[MAXN], nG[MAXN];
int type[MAXN], s, t, dis;

bool dfs(int cur, int par) {
     bool OK = type[cur] ? 1 : 0;
     for (auto i : G[cur]) {
         if (i != par && !dfs(i, cur)) {
            nG[cur].push_back(i);
            nG[i].push_back(cur);
            OK = 0;
         }
     }
     return OK;
}

void dfs2(int cur, int par, int cost) {
    if (cost >= dis) {
       dis = cost;
       if (!t) s = cur;
       else t = cur;
    }
    int deg = (int)nG[cur].size();
    if (deg == 1 && nG[cur][0] == par) {
       // printf("cur = %d cost = %d\n", cur, cost);
       return;
    }
    int offset = 0;
    deg = (deg - 1) % 2;
    if (deg ^ type[cur]) offset = 1;
    else offset = -1;
    // printf("cur = %d off = %d cost = %d deg = %d type = %d\n", cur, offset, cost, deg, type[cur]);
    for (auto i : nG[cur]) {
        if (i != par) {
           dfs2(i, cur, cost + 1 + offset);
        }
    }
}

int main() {
    int N;
    // freopen("1_064.txt", "r", stdin);
    scanf("%d", &N);
    for (int i = 0; i < N - 1; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        G[x].push_back(y);
        G[y].push_back(x);
    }
    int root = 0;
    for (int i = 1; i <= N; i++) {
        char c;
        scanf(" %c", &c);
        if (c == 'W') {
           type[i] = 0;
           root = i;
        } else {
           type[i] = 1;
        }
    }
    if (!root) return !printf("0\n");
    dfs(root, root);
    dfs2(root, root, 0);
    dis = 0;
    dfs2(s, s, 0);
    // if (!nG[root].size()) return !printf("1\n");
    int sum = 0;
    for (int i = 1; i <= N; i++) {
        int deg = (int)nG[i].size();
        sum += deg;
        deg %= 2;
        if (!(deg ^ type[i])) sum++;
    }
    // printf("sum = %d dis = %d\n", sum, dis);
    printf("%d\n", sum - dis);
    return 0;
}


Measured memory_bytes: 20480
#include<stdio.h>
#define N 100000
#define Q 50000
int main(){
  int S[N],T[Q],n,q,i,l,r,m,t=0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&q); 
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }
  
  for(i=0;i<q;i++){
    l=0;
    r=n;
    while(l<r){
      m=(l+r)/2;
      if(T[i]==S[m]){
	t++;
	break;
      }
      else if(T[i]<S[m]){
	r=m;
      }
      else {
	l=m+1;
      }
    }
  }

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

Measured memory_bytes: 1184
#include<stdio.h>

int main(void)
{
  long long i,j,N,sum=0;

  scanf("%lld",&N);

  for (i = 1; i*i <= N; i++)
  {
    if(N%i==0)
    {
      j = N/i-1;
      if(i<j) sum+=j;
    }
  }

  printf("%lld\n",sum);

  return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
double f[1005][1005],dis[1005],a[1005][3];
bool b[1005];
int main()
{
	int i,j,k,n;
	double xi,xs,ys,xt,yt;
	scanf("%lf%lf%lf%lf",&xs,&ys,&xt,&yt);
	scanf("%d",&n);
	a[0][0]=xs;a[0][1]=ys;a[0][2]=0;
	a[n+1][0]=xt;a[n+1][1]=yt;a[n+1][2]=0;
	for(i=1;i<=n;i++)
		scanf("%lf%lf%lf",&a[i][0],&a[i][1],&a[i][2]);
	n++;
	for(i=0;i<=n;i++)
		for(j=i+1;j<=n;j++)
			f[i][j]=f[j][i]=max(0.0,sqrt((a[i][0]-a[j][0])*(a[i][0]-a[j][0])+(a[i][1]-a[j][1])*(a[i][1]-a[j][1]))-(a[i][2]+a[j][2]));
	for(i=0;i<=1003;i++) dis[i]=1e18;
	dis[0]=0; 
	for(i=0;i<n;i++){ 
		xi=1e18;
		k=0; 
		for(j=0;j<=n;j++){
            if(b[j]==0&&dis[j]<xi){
				xi=dis[j]; 
				k=j; 
			} 
        }
		b[k]=1; 
		for(j=0;j<=n;j++)
			dis[j]=min(dis[j],dis[k]+f[k][j]);
	}
	printf("%.9lf",dis[n]);
}

Measured memory_bytes: 8192
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const ll MOD = 1e9 + 7;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


int main(){
   ll n,ans = 0; cin >> n;
   for(int i = 1; i <= 10000000; i ++){
       if((n-i) > 0 && (n-i)%i == 0){
           ll tmp = (n-i)/i;
           if(n%tmp == i) ans += (n-i)/i;

       }
   }
   cout << ans;
}

Measured memory_bytes: 3604