akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python

import sys

n=int(sys.stdin.readline())
b=[ int(x) for x in sys.stdin.readline().split() ]
b= [b[0]] + b + [b[-1]]
c=0
for i in range(1,n+1):
    c+= min(b[i-1],b[i])
print( c )


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define LL long long
using namespace std;
LL ans,sum,c,d;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>d>>c;
		sum+=c*d;ans+=c; 
	}
	ans=ans-1+(sum-1)/9;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N,K;
  cin>>N>>K;
  cout<<((N+1)/2>=K?"YES":"NO")<<endl;
  return 0;
}


Measured memory_bytes: 256
function bomb(y,x){
   if(N==max)return;
   if(x<0)x=n-1;
   if(y<0)y=n-1;
   if(x>=n)x=0;
   if(y>=n)y=0;
   if(yx[y][x]!=-1){bomb(y+1,x-1);}
   else {yx[y][x]=("   "+N).slice(-4);N++;bomb(y+1,x+1);}
}

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n").map(Number);
for(var i=0;i<Arr.length;i++){
   var n=Arr[i];
   var max=n*n+1;
   if(n==0)break;
   var yx=[];
   for(var j=0;j<n;j++){
      yx[j]=[];
      for(var k=0;k<n;k++){
         yx[j][k]=-1;
      }
   }
   var x=Math.floor(n/2);
   var y=x+1;
   yx[y][x]="   "+1;
   var N=2;
   bomb(y+1,x+1);
   console.log(yx.join("\n").replace(/\,/g,""));
}

Measured memory_bytes: 8644
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int m;
        cin >> m;
        if(m == 0)
            return 0;
        vector<int> a(m);
        for(int i=0; i<m; ++i)
            cin >> a[i];

        int n = 32;
        for(int i=0; ; (++i)%=m){
            n -= (n - 1) % 5;
            cout << n << endl;

            n -= a[i];
            n = max(n, 0);
            cout << n << endl;
            if(n == 0)
                break;
        }
    }
}

Measured memory_bytes: 0
N, A, B, C, D = map(int, input().split())
S = str(input())

# ##となっていたら無理
# C < D のとき、それぞれが移動可能かでわかる
# C > D のときは? 追い越しは...となる箇所があればいける

if '##' in S[min(A, B)-1:max(D, C)]:
    print('No')
    quit()

if C < D:
    print('Yes')
else:
    if '...' in S[B-2:D+1]:
        print('Yes')
        quit()
    print('No')

Measured memory_bytes: 40560
n=int(input())
M={}
l=0
for i in range(4):
    for j in range(3):
        for k in range(10):
            M[(i+1,j+1,k+1)]=0
 
while l<n:
    L=input().split( )
    b=int(L[0])
    f=int(L[1])
    r=int(L[2])
    v=int(L[3])
    M[(b,f,r)]=M[(b,f,r)]+v
    l+=1
 
 
for i in range(4):
    for j in range(3):
        for k in range(10):
            print (f" {M[(i+1,j+1,k+1)]}",end="")
        print()
    if i<3:
        print("####################")


Measured memory_bytes: 5636
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
同一直線状は0か
横の順or縦の順でしかとりえない。
BFSでいいかな
うーん、union?
距離が短い順につなげていく。
もしunionだったらスルー
N-1回つないだら終了とか

*/

vector<bool> seen;
vector<vector<ll>> G;
struct UnionFind{
  vector<ll> par,siz;
  
  UnionFind(ll N):par(N+1),siz(N+1,1){
    for(int i=0; i<=N; i++)
      par[i]=i;
  }
  
  void mkpar1(ll parent, ll n){//親は最上位
    for(auto next_n: G[n]){
      if(seen[next_n]) continue;
      seen[next_n]=true;
      par[next_n]=parent;
      mkpar1(parent, next_n);
    }
  }
  
  void mkpar2(ll n){//親は1個うえ
    for(auto next_n: G[n]){
      if(seen[next_n]) continue;
      seen[next_n]=true;
      par[next_n]=n;
      mkpar2(next_n);
    }
  }
  
  ll root(ll x){
    if(par[x]==x)
      return x;
    return par[x]=root(par[x]);
  }
  
  void unite(ll x, ll y){
    if(x>y) swap(x,y);
    ll rx=root(x), ry=root(y);
    if(rx==ry)
      return;
    par[ry]=rx;
    siz[rx]+=siz[ry];
  }
  
  bool issame(ll x, ll y){
    return root(x)==root(y);
  }
  
  ll size(ll x){
    return siz[root(x)];
  }
};
//2点間の距離と頂点番号
//近距離順にとっていく。
//頂点番号同士でunionかどうか。unionならスルー

struct V{
  ll dis,to1,to2;
};

int main(){
  ll N; cin>>N;
  seen.assign(N+1,false);
  vector<vector<ll>> A(N+10,vector<ll>(2,0)),B(N+10,vector<ll>(2,0)),Z(N+10,vector<ll>(2,0)),G(N+10,vector<ll>(0,0));
  vector<V> D(0);
    for(ll i=1; i<=N; i++){
    ll x,y; cin>>x>>y;
    A[i][0]=x;
    A[i][1]=i;
    B[i][0]=y;
    B[i][1]=i;
    Z[i][0]=x;
    Z[i][1]=y;
  }
  sort(A.begin()+1, A.begin()+N+1, [](auto& x, auto& y){return x[0] < y[0];});
  sort(B.begin()+1, B.begin()+N+1, [](auto& x, auto& y){return x[0] < y[0];});
//Vをいれてく
  for(ll i=1; i<N; i++){
    ll a1=A[i][0],a2=A[i+1][0];
    ll b1=B[i][0],b2=B[i+1][0];
    ll n=a2-a1,m=b2-b1;
    ll to1=A[i][1];
    ll to2=A[i+1][1];
    ll to11=B[i][1];
    ll to22=B[i+1][1];
    if(to1>to2) swap(to1,to2);
    if(to11>to22) swap(to11,to22);
    D.push_back({n,to1,to2});
    D.push_back({m,to11,to22});
  }
  sort(D.begin(), D.end(), [](auto& x, auto& y){return x.dis < y.dis;});
  
  UnionFind tree(N);
  ll cnt=0,i=-1,ans=0;
  while(cnt<N-1){
    V v=D[++i];
//cout<<"i:"<<i<<" ans:"<<ans<<" dis:"<<v.dis<<" to1:"<<v.to1<<" to2:"<<v.to2<<endl;
    if(tree.issame(v.to1,v.to2))continue;
    ans+=v.dis;
    tree.unite(v.to1,v.to2);
    cnt++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 27376
import java.util.*;

public class Main {
	public static class UnionFind {
		int[] param;
		int[] rank;
		int N;
		int xlen;
		
		public UnionFind(int n) {
			N=n;
			param = new int[N];
			rank = new int[N];
			for(int i=0; i<N; i++)
				param[i] = i;
		}
		
		public void init() {
			for(int i=0; i<N; i++)
				param[i] = i;
			Arrays.fill(rank, 0);
		}
		
		public UnionFind(int x, int y) {
			this(x*y);
			xlen=y;
		}
		
		public boolean same(int a, int b) {
			return getRoot(a)==getRoot(b);
		}
		
		public int getRoot(int a) {
			if(param[a]==a) return a;
			else return (param[a] = getRoot(param[a]));
		}
		
		public void unite(int a, int b) {
			a = getRoot(a);
			b = getRoot(b);
			if(a==b)
				return;
			
			if(rank[a] < rank[b]) {
				param[a] = b;
			} else {
				param[b] = a;
				if(rank[a]==rank[b])
					rank[a]++;
			}
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		
		UnionFind uf = new UnionFind(N);
		int[] speaker = new int[M];
		Arrays.fill(speaker, -1);
		
		for(int i=0; i<N; i++) {
			int K = sc.nextInt();
			for(int j=0; j<K; j++) {
				int L = sc.nextInt()-1;
				if(speaker[L]>=0)
					uf.unite(speaker[L], i);
				else
					speaker[L] = i;
			}
		}
		boolean ok = true;
		for(int i=1; i<N; i++)
			if(!uf.same(0, i))
				ok = false;
		
		System.out.println(ok ? "YES" : "NO");
		sc.close();
	}
}


Measured memory_bytes: 63344
#include <iostream>
#include <string>
#include <vector>
using namespace std;

#define MP make_pair
#define PB push_back

int main(void){
  int n,h;

  while(cin >> n >> h){
    if((n|h) == 0) break;
    string str;
    int p,q,ret=n*n*n;
    vector<pair<int,int> > xy,xz,yz;
    for(int i=0;i<h;i++){
      cin >> str >> p >> q;
      if(str == "xy"){
	xy.PB(MP(p,q));
      }else if(str == "xz"){
	xz.PB(MP(p,q));
      }else{
	yz.PB(MP(p,q));
      }
    }
    //xy
    ret -= xy.size()*n;
    //xz
    for(int i=0;i<xz.size();i++){
      int tmp=n;
      for(int j=0;j<xy.size();j++){
	if(xz[i].first == xy[j].first) tmp--;
      }
      ret -= tmp;
    }
    //yz
    for(int i=0;i<yz.size();i++){
      int tmp=n;
      for(int j=1;j<=n;j++){
	bool dosub = false;
	for(int k=0;k<xy.size();k++){
	  if(j == xy[k].first && xy[k].second == yz[i].first){
	    dosub = true;
	  }
	}
	for(int k=0;k<xz.size();k++){
	  if(j == xz[k].first && xz[k].second == yz[i].second){
	    dosub = true;
	  }
	}
	if(dosub) tmp--;
      }
      ret -= tmp;
    }

    cout << ret << endl;
  }
}

Measured memory_bytes: 0
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")


N = int(sys.stdin.readline())
L = list(map(int, sys.stdin.readline().split()))

if max(L) < sum(L) - max(L):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 13564
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
-- import Data.List
import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace
-- trace _ = id

lim :: Int
lim = 10 ^ 10

solve :: Int -> Int -> [Int] -> Int
solve bigN bigK hs = sub 1 (VU.cons 0 (VU.replicate (bigK-1) lim))
  where
    vH = VU.fromListN (bigN+1) (0:hs)
    sub i vX
      | i == bigN = VU.head vX
      | otherwise =
          sub (i+1) (VU.zipWith f
                     (VU.drop (i+1) vH) (VU.snoc (VU.tail vX) lim))
      where f h x = min x ((VU.head vX) + abs (h - (vH VU.! i)))

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n, bs_k]:remLines1 = remLines0
      n = readBInt bs_n
      k = readBInt bs_k
      line2:remLines2 = remLines1
      hs = map readBInt line2
  in solve n k hs

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents


Measured memory_bytes: 2428
arr = [0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
for i in range(0, len(arr)):
    if i == k:
        print(arr[k])



Measured memory_bytes: 3060
def dfs(n):
    ret = 0
    if n%2 == 0:
        ret = dfs(n/2) + 1
    return ret


N = int(input())
A = list(map(int,input().split()))

lis = []

for i in range(N):
    lis.append(dfs(A[i]))

print(sum(lis))

Measured memory_bytes: 4148
#lista2=[16,100,4000]
#ans2=lista2[0]

def gcd2(a,b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b

def gcd3(lista):
    ans=lista[0]
    for i in range(1,3):
        ans=gcd2(ans,lista[i])
    return ans

K=int(input())
sums=0
for i in range(K):
    for j in range(K):
        for k in range(K):
            sums+=gcd3([1+i,1+j,1+k])
print(sums)

Measured memory_bytes: 74944
from collections import deque

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

def make_dict(x,y):
    for i in ll:
        if i[x] in d.keys():
            d[i[x]]+=[i[y]]
        else:
            d[i[x]]=[i[y]]

cnt=0
for i in range(m):
    ll=l[:i]+l[i+1:]
#    print(ll)
    d={}
    make_dict(0,1)
    make_dict(1,0)
#    print(d)
    k_l=list(d.keys())
    v_l=list(d.values())
#    print(k_l)

    x=0
    sk=k_l[x]
    dq=deque()
    dq.append(sk)
#    while dq:
#    print(dq)
#    x=0
    seen=[]
    while dq:
#    while n<10:
        k=dq.pop()
        k_ll=d[k]
        seen.append(k)
#        print(k_ll)
        for i in k_ll:
            if i not in seen:
                dq.append(i)
#        d=d.pop(sk)
#        print(dq)
        x+=1
#    print(set(seen),len(set(seen)))
    if len(set(seen))!=n:
        cnt+=1
print(cnt)

Measured memory_bytes: 3316
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	bool operator<(const struct Info &arg) const{
		if(x != arg.x){
			return x < arg.x;
		}else{
			return y < arg.y;
		}
	}
	double x,y,r;
};

int N;
Info info[100001];

bool compare_y(Info left,Info right){

	return left.y < right.y;

}

double calc_dist(int a,int b){
	return sqrt((info[a].x-info[b].x)*(info[a].x-info[b].x)+(info[a].y-info[b].y)*(info[a].y-info[b].y))-(info[a].r+info[b].r);
}

double calc_y_dist(int a,int b){
	return (info[b].y-info[b].r)-(info[a].y+info[a].r);
}

double closest_pair(Info* array,int tmp_N){
	if(tmp_N <= 1)return DBL_MAX;

	int mid = tmp_N/2;

	double x = array[mid].x;
	double dist = min(closest_pair(array,mid),closest_pair(array+mid,tmp_N-mid));
	inplace_merge(array,array+mid,array+tmp_N,compare_y);

	vector<int> V;


	int left,right,m,search_left;

	for(int i = 0; i < tmp_N; i++){

		for(int k = 0; k < min((int)V.size(),2); k++){
			dist = min(dist,calc_dist(V[V.size()-1-k],i));
		}

		V.push_back(i);
	}
	return dist;
}

void func(){

	for(int i = 0; i < N; i++){
		scanf("%lf %lf %lf",&info[i].r,&info[i].x,&info[i].y);
	}
	sort(info,info+N);

	printf("%.10lf\n",closest_pair(info,N));
}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}



Measured memory_bytes: 6924
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
using namespace std;
const int MAXN = 1005;
const int MAXX = 5005;
const int INF = (LL)1e9 + 5;
 
int X[MAXN], minv[MAXN], dp[MAXX], N;
vector<int> ch[MAXN];
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N;
	for (int i = 2; i <= N; i++) {
		int p;
		cin >> p;
		ch[p].push_back(i);
	}
	
	bool ok = true;
	for (int i = 1; i <= N; i++) cin >> X[i];
	for (int v = N; v >= 1; v--) {
		fill(dp, dp + 5001, INF);
		dp[0] = 0;
		
		for (int to : ch[v]) {
			int c1 = X[to], c2 = minv[to];
			for (int j = 5000; j >= 0; j--) {
				int a = INF, b = INF;
				if (j >= c1) a = dp[j - c1] + c2;
				if (j >= c2) b = dp[j - c2] + c1;
				dp[j] = min({INF, a, b});
			}
		}
		
		minv[v] = *min_element(dp, dp + X[v] + 1);
		if (minv[v] == INF) {
			ok = false;
			break;
		}
	}
	
	if (!ok) cout << "IM";
	cout << "POSSIBLE\n";
	
	return 0;
	
	/**** Note MAXN ****/
}

Measured memory_bytes: 384
import numpy as np

def input_numbers():
    temp = list(map(int, input().split()))
    return temp

def GCD(a, b):
    if(a < b):
        temp = a
        a = b
        b = temp
    a = a % b
    if(a == 0):
        return b
    else:
        return GCD(a, b)

n = int(input())

a = input_numbers()
b = input_numbers()


mx = 0
for i in range(n):
    sum = 0
    for j in range(n):
        if(j < i):
            sum += a[j]
        if(j == i):
            sum += a[j] + b[j]
        if(j > i):
            sum += b[j]

    mx = max(mx, sum)

print(mx)

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

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

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

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

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '('<<'L' << __LINE__ << ')' << ' ' << __FILE__ << endl;

#define POSSIBLE cout<<"POSSIBLE"<<endl; return 0;
#define IMPOSSIBLE cout<<"IMPOSSIBLE"<<endl; return 0;

LL gcd(LL a,LL b){
    if(a<b){swap(a,b);}
    if(b==0) return a;
    return gcd(b,a%b);
}

LL mod_pow(LL x, LL n, LL mod){
    LL res=1ULL;
    while(n>0LL){
        if(n&1LL) res=res*x%mod;//最下位bitが立っている時だけresをかける
        x=x*x%mod;//xを2乗していく
        n>>=1LL;
    }
    return res;
}

LL mod=1000000007LL;

int main(){
    double a,b,c,d;
    cin>>a>>b;
    cout<<(int)ceil((a+b)/2.0 )<<endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0041
"""
import sys
from itertools import permutations, product


def make_ten(digits):
    """
    4????????°????????????(9**4)??????????????????????????????(3**3)????????????????????????????????????(6) ?????????????????§?????§????????????
    """
    result = '0'
    for a, b, c, d in permutations(digits, 4): #  4????????°??????????????°??????2??????????????¢????????§??????????????§???permutations
        if result != '0':
            break
        for op1, op2, op3 in product(['+', '-', '*'], repeat=3): #  ??????????????????????????????????????????????????????OK
            # 1, 2, 3???????????§?¨????????????????????????????????????????
            exp = '(({} {} {}) {} {}) {} {}'.format(a, op1, b, op2, c, op3, d)
            if eval(exp) == 10:
                result = exp
                break
            # 1, 3, 2
            exp= '(({} {} {}) {} ({} {} {}))'.format(a, op1, b, op2, c, op3, d)
            if eval(exp) == 10:
                result = exp
                break
            # 2, 1, 3
            exp = '(({} {} ({} {} {})) {} {})'.format(a, op1, b, op2, c, op3, d)
            if eval(exp) == 10:
                result = exp
                break
            # 3, 1, 2
            exp = '({} {} (({} {} {}) {} {}))'.format(a, op1, b, op2, c, op3, d)
            if eval(exp) == 10:
                result = exp
                break
            # 3, 2, 1
            exp = '({} {} ({} {} ({} {} {})))'.format(a, op1, b, op2, c, op3, d)
            if eval(exp) == 10:
                result = exp
                break
            # 2, 3, 1
            exp =  '(({} {} {}) {} ({} {} {}))'.format(a, op1, b, op2, c, op3, d)
            if eval(exp) == 10:
                result = exp
                break
    return result


# ????????°????????????????????????10?????????????????????????????¢?????°????????§?????????????????????????????°??????????????¨???????????????????????¨??????????´????????????????
# ????????°????????°?????????????????????????????°??????????????´???????????°????????????????????????????????£????????\
Memo = {}
def solve(digits):
    global Memo
    digits.sort(reverse=True)   #  1234 ??§??? 4321 ??§???????????????(data)??????????????????????????§?????????
    data = ''.join(map(str, digits))
    if not data in Memo:
        Memo[data] = make_ten(digits)
    return Memo[data]


def main(args):
    while True:
        digits = [int(x) for x in input().strip().split(' ')]
        # digits = [int(x) for x in '{:04d}'.format(count)]
        if digits[0] == 0 and digits[1] == 0 and digits[2] == 0 and digits[3] == 0:
            break
        result = solve(digits)
        print(result)


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

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

int main(){
  int n, d, x;
  cin >> n;
  cin >> d >> x;
  int a[n];
  for(int j=0;j<n;j++){
    cin >> a[j];
  }

  int sum=0;
  for(int i=0;i<n;i++){
    if(a[i]<d){
      sum = sum + ((d - 1) / a[i]);
      sum = sum + 1;
    }
    else{
      sum = sum + 1;
    }
  }
  sum = sum + x;

  cout << sum << endl;

  return 0;
}



Measured memory_bytes: 256
#200802D
N = int(input())
#C = list(map(str,input().split()))
C = list(str(input()))

#print(C)
Rnum = C.count('R')

ans = 0
#print(C[0])

for i in range(Rnum):
    if C[i]=='W':
        ans += 1

print(ans)
    

Measured memory_bytes: 10760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

const int INF = (1<<28);
char field[55][55];
int d[55][55];
int v1[4] = {-1, 0, 1, 0};
int v2[4] = {0, 1, 0, -1};

void bfs(pair<int, int> pa){
    queue<pair<int, int>> q;
    q.push(pa);
    d[pa.first][pa.second] = 0;

    while(!q.empty()){
        pair<int, int> u = q.front(); q.pop();
        for(int i=0; i<4; i++){
            if(d[u.first + v1[i]][u.second + v2[i]] == INF && field[u.first + v1[i]][u.second + v2[i]] == '.'){
                pair<int, int> np = {u.first + v1[i], u.second + v2[i]};
                d[np.first][np.second] = d[u.first][u.second]+1;
                q.push(np);
            }
        }
    }
}

int main(){
    int H, W; cin >> H >> W;
    int white = 0;

    for(int j=0; j<W+2; j++) field[0][j] = field[H+1][j] = '#';

    for(int i=1; i<=H; i++){
        for(int j=0; j<W+2; j++){
            if(j == 0 || j == W+1){
                field[i][j] = '#';
                continue;
            }
            else{
                char c; cin >> c;
                if(c == '.') white++;
                field[i][j] = c;
            }
            
        }
    }

    for(int i=0; i<H+2; i++) for(int j=0; j<W+2; j++) d[i][j] = INF;

    bfs({1, 1});

    if(d[H][W] == INF) cout << -1 << endl;
    else{
        cout << white - d[H][W] - 1 << endl;
    }
}

Measured memory_bytes: 256
N = gets.to_i
A = gets.split.map(&:to_i).sort.reverse
B = gets.split.map(&:to_i)
C = gets.split.map(&:to_i).sort

ans = 0

B.each do |b|
  a_cnt = A.bsearch_index { |a| a < b } || A.size
  c_cnt = C.bsearch_index { |c| c > b } || C.size

  ans += (A.size - a_cnt) * (C.size - c_cnt)
end

puts ans


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

inline long gcc(int a, int b, int c)
{
	int n = 2;
	int v = 1;
	while(n <= a && n <= b && n <= c){
		if(a % n == 0 && b % n == 0 && c % n == 0){
			a /= n;
			b /= n;
			c /= n;
			v *= n;
		}else{
			n++;
		}
	}
	
	return v;
}

int main() 
{
	int K;
	cin >> K;
	
	long sum = 0;
	
	for(int a = 1; a <= K; a++){
      for(int b = 1; b <= K; b++){
        for(int c = 1; c <= K; c++){
            sum += gcc(a, b, c);
        }
      }
	}

	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 3632
w=input()
letters_dict={}
for n in range(0,len(w)):
    letter=w[n]
    if letter in letters_dict:
        letters_dict[letter]+=1
    else:
        letters_dict[letter]=1
for n in range(0,len(letters_dict)):
    if list(letters_dict.values())[n]%2==1:
        print("No")
        break
else:
    print("Yes")


Measured memory_bytes: 3060
#include <stdio.h>

int main(){
  int N, M;
  int a[60] = {};
  int b[60] = {};
  int count;

  scanf("%d%d", &N, &M);
  for(int i = 1; i <= M; i++){
    scanf("%d%d", &a[i], &b[i]);
  }

  for(int i = 1; i <= N; i++){
    count = 0;
    for(int j = 1; j <= M; j++){
      if(a[j]==i || b[j]==i){
        count++;
      }
    }
    printf("%d\n", count);
  }
  
  return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int k;
    string s;
    cin >> k >> s;
    if (s.length() > k) {
        cout << s.substr(0, k) << "..." << endl;
    } else {
        cout << s;
    }
    return 0;
}


Measured memory_bytes: 3652
X = input().split()
N = int(X[0])
K = int(X[1])

H = input().split()
A = [int(z) for z in H]
B = []
s = []

for z in range(N):
	B.append(0)
	s.append(0)

C = 1
B[0] +=1
s[0] = 0

for i in range(K):
	C = A[C-1] 
	B[C-1] += 1
	if(B[C-1] == 2):
		break
	s[C-1] = i+1

r = i+1 - s[C-1]

if not r == 0:
	#uに余りを入れる
	t = (K - s[C-1])
	u = t % r
	for g in range(u):
		C = A[C-1] 

print(C)


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

int main(){
	int n = 0,w = 0,s = 0,e = 0;
	string str;
	cin >> str;
	for(auto c:str){
		if(c == 'N') n++;
		else if(c == 'W') w++;
		else if(c == 'S') s++;
		else e++;
	}
	cout << ((n == 0 && s != 0) || (n != 0 && s == 0) || (w == 0 && e != 0) || (w != 0 && e == 0) ? "No" : "Yes") << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long a = in.nextLong() - 1;
        long b = in.nextLong();
        long c = in.nextLong();
        long d = in.nextLong();

        long s1 = a - (a / c + a / d - a / lcm(c, d));
        long s2 = b - (b / c + b / d - b / lcm(c, d));

        System.out.println(s2 - s1);
    }

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

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


Measured memory_bytes: 21712
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  double a[n];
  rep(i, n) cin >> a[i];
  sort(a, a + n);
  double ans = a[0];
  for (int i = 1; i < n; i++) {
    ans = (ans + a[i]) / 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

int main(){
	int V, E, r;
	cin >> V >> E >> r;
	typedef pair<int, ll> LP;
	//vec[i][j]: iとつながる道路とそのコスト
	vector<vector<LP>> vec(V, vector<LP>());
	for(int i=0; i<E; i++){
		int s, t, d;
		cin >> s >> t >> d;
		vec[s].emplace_back(t, d);
		//vec[t].emplace_back(s, d);//有向グラフでしたのでコメントアウト
	}

	const ll INF = 1001001001001001001;
	vector<ll> ans(V, INF);
	ans[r] = 0;
	typedef pair<int, int> P;
	//st.first: 注目ノード， second: 注目ノードの親
	//stack<P> st;
	//st.push(P(r, -1));
	queue<P> qu;
	qu.push(P(r, -1));
	// while(!st.empty()){
	while(!qu.empty()){
		// int node = st.top().first;
		// int parent = st.top().second;
		// st.pop();
		int node = qu.front().first;
		int parent = qu.front().second;
		qu.pop();

		for(int i=0; i<vec[node].size(); i++){
			int child = vec[node][i].first;
			if(child == parent) continue;
			int cost = vec[node][i].second;
			if(ans[child] <= ans[node]+cost) continue;
			ans[child] =  ans[node]+cost;
			// st.push(P(child, node));
			qu.push(P(child, node));
		}
	}
	for(int i=0; i<V; i++){
		if(ans[i] == INF) cout << "INF" << endl;
		else		cout << ans[i] << endl;
	}

}




Measured memory_bytes: 18096
#include <iostream>

int main() {
  int n, a, b;
  int i;

//  std::cin >> n;
  std::cin >> a;
  std::cin >> b;

//  std::cout << (a * (n / (a + b)) + std::min(a, n % (a + b))) << std::endl;


  for (i = 0; i < 1250; i++) {
    if (static_cast<int>(static_cast<double>(i) * 0.08) != a) continue;
    if (static_cast<int>(static_cast<double>(i) * 0.1) != b) continue;
    std::cout << i << std::endl;
    break;
  }
  if (i == 1250) {
    std::cout << -1 << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
public class Main {

	public static void main(String[] args) {
		java.util.Scanner scanner = new java.util.Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		
		
		if(a < b&&b< c){
			System.out.println("Yes");
		}else{
		     System.out.println("No");
	
		

	}
}
}

Measured memory_bytes: 26224
// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)	cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
#define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 1000005
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1e8;
ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {

	fast
	ll n, k;
	cin >> n >> k;
	vl a(n + 1);
	FOR(i, 1, n)	cin >> a[i];
	vl pres(n + 1, -1);
	vl path;
	path.pb(1);
	pres[1] = 0;
	ll i = 0;
	while (pres[a[path[i]]] == -1)
	{
		path.pb(a[path[i]]);
		pres[a[path[i]]] = i + 1;
		++i;
	}
	if (k < pres[a[path[i]]])
	{
		cout << path[k] << END;
	}
	else
	{
		k -= pres[a[path[i]]];
		vl newpath;
		FOR(j, pres[a[path[i]]], path.size() - 1)
		{
			newpath.pb(path[j]);
		}
		cout << newpath[k % newpath.size()] << END;
	}



// #ifndef ONLINE_JUDGE
// 	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
// #endif
	return 0;
}

Measured memory_bytes: 10624
#include <stdio.h>
#define N 100001

int binarySearch(int*,int,int);

int main(){
  int a[N],b[N],i,n1,n2,cnt = 0;

  scanf("%d",&n1);
  for(i=0;i<n1;++i) scanf(" %d",&a[i]);

  scanf(" %d",&n2);
  for(i=0;i<n2;i++)scanf(" %d",&b[i]);

  i=0;
  while(i<n2){
    cnt += binarySearch(a,n1,b[i++]);
  }
  printf("%d\n",cnt);
  return 0;
}

int binarySearch(int *g,int n1,int Snum){
  int L=0,R,M;

  R = n1;

  while(L<R){
    M = (L + R)/2;
    if(g[M] == Snum) return 1;
    else if (g[M] > Snum) R = M;

    else L = M + 1;

  }
  return 0;
}



Measured memory_bytes: 2444
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << "\n"; }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}


#line 2 "abc168_a.cpp"

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  if (n % 10 == 3) {
    cout << "bon" << endl;
  } else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) {
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }
}


Measured memory_bytes: 3612
using System;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');

            int A = int.Parse(s[0]);
            int B = int.Parse(s[1]);
            int K = int.Parse(s[2]);

            int counter = 0;
            for(int i=100;i>0;i--)
            {
                if (A % i == 0 && B % i ==0)
                {
                    counter++;

                    if(counter == K)
                    {
                        Console.WriteLine(i.ToString());
                        return;
                    }
                }
            }

            Console.ReadKey();
        }

    }
}


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

    #define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #define rep(i,a,b) for(int i=a; i<b; i++)
    #define ll long long
    #define pb push_back
    #define inf 1e+18L
    #define MOD 1000000007
    #define MAXN 1000007

    int n;
    long double dp[307][307][307];

    long double solve(int a, int b, int c)
    {
        if(a<0 || b<0 || c<0) return 0;
        if(dp[a][b][c] != -1) return dp[a][b][c];
        long double A=a, B=b, C=c;
        long double currans = 0;
        currans = (A/n * solve(a-1,b,c)) + (B/n * solve(a+1,b-1,c)) + (C/n * solve(a,b+1,c-1)) + 1;
        currans *= n;
        currans /= (a+b+c);
        dp[a][b][c] = currans;
        return dp[a][b][c];
    }

    int main()
    {
        FastIO
        for(int i=0;i<307;i++){
            for(int j=0;j<307;j++){
                for(int k=0;k<307;k++){
                    dp[i][j][k]=-1;
                }
            }
        }
        dp[0][0][0]=0;
        cin >> n;
        vector<int> cnt(4,0);
        int x;
        rep(i,0,n)
        {
            cin >> x;
            cnt[x]++;
        }
        cout << fixed << setprecision(10) << solve(cnt[1], cnt[2], cnt[3]);
        return 0;
    }

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

int main() {
	string S;
	cin >> S;
	int tmp1 = 0, tmp2 = 0;
	for (int i = 0; i < S.size(); ++i) {
		if (i % 2) {
			if (S[i] == '0') ++tmp1;
		}
		else {
			if (S[i] == '1') ++tmp1;
		}
	}
	for (int i = 0; i < S.size(); ++i) {
		if (i % 2) {
			if (S[i] == '1') ++tmp2;
		}
		else {
			if (S[i] == '0') ++tmp2;
		}
	}
	cout << min(tmp1, tmp2);
}

Measured memory_bytes: 512
#include <cstdio>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
  int i, j, n;
  int **p;
  vector<double> ans;

  while (1) {
    scanf("%d", &n);
    if (n < 3) break;
    else p = new int*[n];
    for (i = 0; i < n; i++) {
      p[i] = new int[2];
      scanf("%d %d", &p[i][0], &p[i][1]);
    }

    double a = 0.0;
    for (i = 0; i < n; i++) {
      if (i + 1 >= n) j = 0;
      else j = i + 1;
      a +=
        (double)p[i][0] * (double)p[j][1] -
        (double)p[j][0] * (double)p[i][1];
    }
    ans.push_back(fabs(a / 2));

    for (i = 0; i < n; i++)
      delete[] p[i];
    delete[] p;
  }

  for (i = 0; i < ans.size(); i++)
    printf("%d %.1lf\n", i + 1, ans[i]);
  return 0;
}

Measured memory_bytes: 0
/*
 * Author: $%U%$
 * Time: $%Y%$-$%M%$-$%D%$
**/

#include <bits/stdc++.h>
#include <fstream>
#include <iomanip>
#include <stdio.h>
#include <cmath>

using namespace std;

//typedef
typedef string STR;
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef priority_queue<int> PQI;
typedef vector<LL> VLL;
typedef vector<ULL> VULL;
typedef vector<STR> VS;
typedef vector<char> VC;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef pair<STR,int> PSI;
typedef pair<int,STR> PIS;
typedef vector<PII> VII;
typedef map<int,int> MII;
typedef map<LL,LL> MLL;
typedef map<STR,int> MSI;
typedef map<char,int> MCI;
typedef map<int,STR> MIS;
typedef set<STR> SS;
typedef set<int> SI;
typedef set<LL> SLL;

//symbolic const
#define MOD 1000000007
#define MAXN 1e9
#define SIZE 10000

//STL keywords
#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair
#define all(v) v.begin(), v.end()

//functions
#define dec(n) cout<<fixed<<setprecision(n);
#define f(i, n)   for(LL i=0; i<n; i++)
#define fa(i,a,n) for(LL i=a; i<n; i++)

//IO
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test int t;cin>>t;while(t--){solve();}

LL maxLL(LL a, LL b){return (a>b?a:b);}
LL minLL(LL a, LL b){return (a<b?a:b);}

void solve() {
   int n;
   cin>>n;
   VLL a(n), b(n), c(n);
   f(i, n) cin>>a[i]>>b[i]>>c[i];
   LL dp[3][n]={0};
   dp[0][0]=a[0];
   dp[1][0]=b[0];
   dp[2][0]=c[0];

    for(LL i=1; i<n; i++){
        dp[0][i]=maxLL(dp[1][i-1], dp[2][i-1])+a[i];
        dp[1][i]=maxLL(dp[0][i-1], dp[2][i-1])+b[i];
        dp[2][i]=maxLL(dp[0][i-1], dp[1][i-1])+c[i];

    }
    cout<<maxLL(dp[0][n-1], maxLL(dp[1][n-1], dp[2][n-1]));
}

int main() {
    sync;
    //test;
    solve();
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
using namespace std;
#define REP(i,n) for(int i=0; i<n;i++)


int main(){
    int i,j,n, k, v;
    int s,t;
    int a[100001];
    cin >> n >> k;
    REP(i,n){
        cin >> a[i];
        if(a[i]==1) v = i;
    }
    
    s = 1;
    for(i=0;s < n;i++){
        s += (k-1);
    }
    t = n-1;
    for(j=0; t > 0;j++){
        t -= (k-1);
    }
    
    if(i<j) cout << i << endl;
    else cout << j << endl;
    
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin>>n;
  vector<int> a(n);
  int b;
  for(int i=0; i<n; i++){
    cin>>b;
    a[b-1] = i+1;
  }
  for(int i=0; i<n-1; i++){
    cout<<a[i]<<" ";
  }
  cout<<a[n-1]<<endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string N;
  cin >> N;
  int T = 0;
  int U = N.size();
  for (int i = 0; i < U; i++) {
    char a = N.at(i);
    if (a == '1') {T += 1;}
    else if (a == '2') {T += 2;}
    else if (a == '3') {T += 3;}
    else if (a == '4') {T += 4;}
    else if (a == '5') {T += 5;}
    else if (a == '6') {T += 6;}
    else if (a == '7') {T += 7;}
    else if (a == '8') {T += 8;}
    else if (a == '9') {T += 9;}    
  }
  if (T % 9 == 0) {cout << "Yes" << endl;}
  else {cout << "No" << endl;}
}

Measured memory_bytes: 3752
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    vector<ll> p(N); for(auto& in:p) cin >> in;
    auto t = p;
    sort(t.begin(),t.end());
    int cnt =0;
    for(int i = 0; i < N;i++){
        if(t[i] != p[i]) cnt++;
    }
    if(cnt <= 2){
        return "YES";
    }else{
        return "NO";
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<string>() << endl;
    return 0;
}


Measured memory_bytes: 256
import math

n = int(input())
x = list(map(float, input().split()))
y = list(map(float, input().split()))

p1 = sum([math.fabs(x[i]-y[i]) for i in range(n)])
p2 = math.sqrt(sum([math.fabs(x[i]-y[i])**2 for i in range(n)]))
p3 = math.pow(sum([math.fabs(x[i]-y[i])**3 for i in range(n)]), 1/3)
pp = max([math.fabs(x[i]-y[i]) for i in range(n)])

print("{0:.6f}".format(p1))
print("{0:.6f}".format(p2))
print("{0:.6f}".format(p3))
print("{0:.6f}".format(pp))


Measured memory_bytes: 5732
import sys
input = sys.stdin.readline

N, x = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
a.sort()
ans = 0
for i, ai in enumerate(a):
    x -= ai
    if (x > 0 and i != len(a)-1) or x == 0:
        ans += 1
    else:
        break
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String... args) {
        // 入力
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] x = new int[n];
        for (int i=0;i<n;i++) {
            x[i] = sc.nextInt();
        }

        int result = 1;
        for (int i=1;i<n;i++) {
            boolean canSee = true;
            for (int j=0;j<i;j++) {
                if (x[i] < x[j]) {
                    canSee = false;
                    break;
                }
            }
            if (canSee) {
                result++;
            }
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

ll x; 

ll f(ll n){
    ll res = n/x + 1;
    if(n < 0) res = 0LL;
    return res;
}

int main(){
    ll a, b; cin >> a >> b >> x;
    ll ans = f(b) - f(a-1);//0が入ることに注意
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <map>

class union_find {
  std::vector<intmax_t> tree;

public:
  union_find(size_t n): tree(n, -1) {}

  size_t find(size_t v) {
    if (tree[v] < 0)
      return v;

    return (tree[v] = find(tree[v]));
  }

  bool unite(size_t u, size_t v) {
    u = find(u);
    v = find(v);
    if (u == v)
      return false;

    if (-tree[u] >= -tree[v])
      std::swap(u, v);

    tree[v] += tree[u];
    tree[u] = v;
    return true;
  }

  bool connected(size_t u, size_t v) {
    return (find(u) == find(v));
  }

  size_t size(size_t v) {
    return -tree[find(v)];
  }
};

int main() {
  size_t N, K, L;
  scanf("%zu %zu %zu", &N, &K, &L);

  union_find uf1(N);
  for (size_t i = 0; i < K; ++i) {
    size_t p, q;
    scanf("%zu %zu", &p, &q);
    --p;
    --q;
    uf1.unite(p, q);
  }

  union_find uf2(N);
  for (size_t i = 0; i < L; ++i) {
    size_t r, s;
    scanf("%zu %zu", &r, &s);
    --r;
    --s;
    uf2.unite(r, s);
  }

  std::map<std::pair<size_t, size_t>, int> res;
  for (size_t i = 0; i < N; ++i)
    ++res[{uf1.find(i), uf2.find(i)}];

  for (size_t i = 0; i < N; ++i)
    printf("%d%c", res[{uf1.find(i), uf2.find(i)}], i+1<N? ' ':'\n');
}


Measured memory_bytes: 15104
import math

def primes(n):
    rn = int(math.sqrt(n))
    sieve = [1] * (rn + 1)
    for i in range(2, rn + 1):
        j = i * 2
        while j <= rn:
            sieve[j] = 0
            j += i
    p = [i for i in range(2, rn + 1) if sieve[i] == 1]
    return p

def factorize(n, p):
    out = ["{}:".format(n)]
    while n > 1:
        for q in p:
            if n % q == 0:
                out += [str(q)]
                n //= q
                break
        else:
            out += [str(n)]
            break
    print(" ".join(out))

line = input()
n = int(line)
p = primes(n)
factorize(n, p)


Measured memory_bytes: 5904
#include<bits/stdc++.h>
#define maxn 100005
#define inf (1<<30)
#define mod 1000000007
using namespace std;
typedef long long LL;
int read()
{
	char c=getchar();int f=1,sum=0;
	while(c<'0' || c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0' && c<='9'){sum=sum*10+c-'0';c=getchar();}
	return sum*f;
}
int k; 
int main()
{
	k=read();
	printf("%d\n",(k&1)?((k-1)/2*(k+1)/2):((k/2)*(k/2)));
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl '\n'
#define ld long double
typedef pair<ll,ll> pii;
const int maxn=100005;
const int mod=1e9+7;
int n,k;
int ban[maxn];
bool chk(int x)
{
    int tp=x;
    while(x)
    {
        if(ban[x%10])
            return false;
        x/=10;
    }
    cout<<tp<<endl;
    return true;
}
int main()
{
    #ifdef local
    freopen("in.txt","r",stdin);
    #endif // local
    IOS;
    cin>>n>>k;
    for(int i=1;i<=k;i++)
    {
        int x;
        cin>>x;
        ban[x]=1;
    }
    for(int i=n;;i++)
        if(chk(i))
            return 0;
}


Measured memory_bytes: 256
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
# define maxn 100005
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define sz(x) (int)((x).size())
# define int ll
using namespace std;

int n,a[1 << 21],x,mn = 1e18,sum;

int32_t main(){_
    //freopen("input","r",stdin);
    cin >> n;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    int x = 0;
    for(int i = 1;i < n;i++)
    {
        x += a[i];
        mn = min(mn,abs(sum - x - x));
    }
    rc(mn);
}


Measured memory_bytes: 1792
t = int(input())
data = []
ans = []
c = 0
for i in range(t):
    n, p = map(str, input().split())
    p = int(p)
    data.append([n, p, i+1]) #name #point #count
data = sorted(data, key=lambda x: x[1], reverse=True)
data = sorted(data, key=lambda x: x[0])
#print(data) #[0] = name [1] = point [2] = count

for i in range(len(data)):
    ans.append([i, data[i][2]])
#print(ans)
ans = sorted(ans, key=lambda x:x[0])
#print(ans)
for i in ans:
    print(i[1])


Measured memory_bytes: 38384
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++) {
		a[i] = i + 1;
	}
	vector<int>p(n);
	vector<int>q(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	for (int j = 0; j < n; j++) {
		cin >> q[j];
	}
	int x, y,count = 1,check = 0;
	do {
		for (int i = 0; i < n; i++) {
			if (a[i] == p[i]) {
				check++;
			}
		}
		if (check == n) {
			x = count;
		}
		check = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] == q[i]) {
				check++;
			}
		}
		if (check == n) {
			y = count;
		}
		check = 0;
		count++;

	} while (next_permutation(a.begin(), a.end()));
	cout << abs(x - y) << endl;
	return 0;
}



Measured memory_bytes: 256