akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e5 + 5;
int n, t[maxn], ans;
int m, p[maxn], c[maxn];
void divide(int n) {
    for (int i = 2; i <= n / i; ++i)
        if (n % i == 0) {
            p[++m] = i, c[m] = 0;
            while (n % i == 0) n /= i, c[m]++;
        }
    if (n > 1) p[++m] = n, c[m] = 1;
}
signed main() {
    ios::sync_with_stdio(false); cin.tie(0);
    t[1] = 1;
    int indx = 1000;
    for (int i = 2; i <= indx; ++i)
        t[i] = t[i - 1] + i;
    // for (int i = 1; i <= indx / 10; ++i) cout << t[i] << endl;
    cin >> n;
    divide(n);
    // for (int i = 1; i <= m; ++i) cout << p[i] << " " << c[i] << endl;
    // cout << upper_bound(t + 1, t + indx + 1, 2) - t << endl;
    for (int i = 1; i <= m; ++i) {
        int tt = upper_bound(t + 1, t + indx + 1, c[i]) - t - 1;
        // cout << tt << endl;
        ans += tt;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3672
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

const inf = 100000

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}

	b := make([]int, N)
	b[0] = abs(a[0])
	sum := b[0]
	for i := 1; i < N; i++ {
		b[i] = asub(a[i], a[i-1])
		sum += b[i]
	}
	sum += abs(a[N-1])
	// out(b, sum)

	for i := 0; i < N; i++ {
		s := sum
		if i != 0 {
			s -= asub(a[i], a[i-1])
		} else {
			s -= abs(a[i])
		}

		if i != N-1 {
			s -= asub(a[i], a[i+1])
		} else {
			s -= abs(a[i])
		}

		if i == 0 {
			s += abs(a[i+1])
		} else if i == N-1 {
			s += abs(a[i-1])
		} else {
			s += abs(a[i+1] - a[i-1])
		}
		out(s)
	}

}


Measured memory_bytes: 4608
from heapq import heappop,heappush
N=int(input())
A=list(map(int,input().split()))
X=[]
Y=[]
Xnow=sum(A[0:N])
Ynow=-1*sum(A[2*N:3*N])
ansX=[Xnow]
ansY=[Ynow]
for i in range(N):
    heappush(X,A[i])
    heappush(Y,-1*A[i+2*N])
for i in range(N):
    a=A[N+i]
    Xnow+=a
    heappush(X,a)
    a=heappop(X)
    Xnow-=a
    ansX+=[Xnow]
    
    a=-1*A[2*N-1-i]
    Ynow+=a
    heappush(Y,a)
    a=heappop(Y)
    Ynow-=a
    ansY+=[Ynow]

ans=-1*float('inf')
for i in range(N+1):
    ans=max(ans,ansX[i]+ansY[N-i])
print(ans)

Measured memory_bytes: 38148
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int H, W;
	cin >> H >> W;
	int N;
	cin >> N;
	int a[N];
	rep(i, N) cin >> a[i];
	stack<int> st;
	rep(i, N) {
		while (a[i]--) st.push(i + 1);
	}
	int ans[H][W];
	rep(i, H) {
		if (i % 2 == 0) {
			rep(j, W) {
				ans[i][j] = st.top();
				st.pop();
			}
		}
		else {
			rrep(j, W - 1) {
				ans[i][j] = st.top();
				st.pop();
			}
		}
	}
	rep(i, H) {
		rep(j, W) {
			if (j != 0) cout << " ";
			cout << ans[i][j];
		}
		cout << endl;
	}
	


    return 0;
}


Measured memory_bytes: 384
import           Control.Applicative
import           Control.Monad
import           Debug.Trace

powerset :: [a] -> [[a]]
powerset xs = filterM (\x -> [True, False]) xs

main :: IO ()
main = do
    getLine
    as <- fmap read . words <$> getLine
    getLine
    ms <- fmap read . words <$> getLine
    let bs = fmap sum $ powerset as :: [Int]
    forM_ ms $ \m -> do
        if m `elem` bs
            then putStrLn "yes"
            else putStrLn "no"



Measured memory_bytes: 103420
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scr =new Scanner(System.in);
		
		int K = scr.nextInt();
		String S = scr.next();
		
		if(S.length() <= K) {
			System.out.println(S);
		}else {
			System.out.println(S.substring(0,K)+"...");
		}
		
	}
}

Measured memory_bytes: 38540
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	int n;cin>> n;
	vector<int> a(n);
	rep(i,n)cin >> a[i];
	a.push_back(a[n-1]+a[n-1]-a[n-2]);
	int ans = 0;
	for(int i=0;i<n;i++)
	{
		if(a[i]==a[i+1])continue;
		ans++;
		if(a[i]<=a[i+1])
		for(i;i<n&&a[i]<=a[i+1];i++)
		{
			//cout<<'u'<<endl;
		}
		else if(a[i]>=a[i+1])
		for(i;i<n&&a[i]>=a[i+1];i++)
		{
			//cout<<'d'<<endl;
		}
		//i--;
	}
	cout<<ans<<endl;
	return 0;
}

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

ans = 0
for i in range(N):
    x = min(A[i], B[i])
    A[i] -= x
    B[i] -= x
    ans += x

    x = min(A[i+1], B[i])
    A[i+1] -= x
    B[i] -= x
    ans += x

print(ans)

Measured memory_bytes: 19116
# 基本はDPだけど時間短縮のため途中は必ず一番効率のいいやつを使う

N, M = map(int, input().split())
A = [int(a) for a in input().split()]    
L = [2, 5, 5, 4, 5, 6, 3, 7, 6]
B = [[A[i], L[A[i]-1]] for i in range(M)]
best = sorted(B, key = lambda x: x[1]*10-x[0])[0]
adj = max((N - 200),0)//best[1]
N -= best[1] * adj

X = [0] + [-10**9] * N
for i in range(1, N+1):
    if i > 50 and i < N-50:
        X[i] = X[i-best[1]]*10 + best[0]
    else:
        for b in B:
            if b[1] <= i:
                X[i] = max(X[i], X[i-b[1]]*10 + b[0])

ans = str(X[N])
ans = ans[:10] + str(best[0]) * adj + ans[10:]

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <unordered_map>
#include <algorithm> // std::sort(begin,end), std::min, std::max
#include <utility> // std::swap

using namespace std;

int main(int argc, char const* argv[])
{
  int n;
  string s;
  cin >> n >> s ;

  if( n % 2 ){
    cout << "No" << endl;
    return 0;
  }

  for(int i = 0; i < n/2; i++){
    if(s[i] != s[i+n/2]){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <climits>
#include <cassert>
#include <string>
#include <string_view>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <memory>

#define rep(i,n) for(int i = 0; i < (n); ++i)

using namespace std;

template<class T, class U>
istream& operator>>(istream& is, pair<T, U>& pair)
{
    is >> pair.first >> pair.second;
    return is;
}

template<class T>
istream& operator>>(istream& is, vector<T>& collection)
{
    for(auto& item : collection) is >> item;
    return is;
}

void solution()
{
    string s,t;
    cin >> s >> t;
    cout << (string_view(s) == string_view(t.data(), t.size() -1) ? "Yes" : "No") << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solution();
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define SUM(n) ((n)+1)*(n)/2
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = (1e9)+7;
#define all(v) v.begin(),v.end()
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

  int a, b, m, ma = INF, mb = INF;
  cin >> a >> b >> m;
  int x[a + 5], y[b + 5];
  reps(i, a){
    cin >> x[i];
    ma = min(ma, x[i]);
  }
  reps(i, b){
    cin >> y[i];
    mb = min(mb, y[i]);
  }
  int minv = INF;
  int A, B , c;
  rep(i,m){
    cin >> A >> B >> c;
    minv = min(x[A] + y[B] - c, minv);
  }
  cout << min(minv, ma + mb) << '\n';
  return 0;
}


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

using i64 = int64_t;

int main(){
    int n;
    cin >> n;
    i64 cnt = 0;
    for(int i=0;i<n;++i){
        i64 a;
        cin >> a;
        while(a%2==0){
            a >>= 1;
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long ans = Long.MAX_VALUE;
        for (long i = 1; i * i <= n; ++i) {
            if (n % i != 0) continue;
            long j = n / i;
            ans = Math.min(ans, i + j - 2);
        }
        System.out.println(ans);
    }
}

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

#define lp(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define MAXN 22

const int MAX=(1<<MAXN) ;
const int MOD=1e9+7;

using namespace std ;

int n ;
ll dp[MAXN][MAX] ;
int marc[MAXN][MAXN] ;

bool bitLigado(int x, int i)
{ return ( ( (1<<i) & x ) != 0 ) ; }

ll recursion(int wom, int bitmask)
{
  if(bitmask==( (1<<n)-1) ) return 1 ;
  if(wom==n) return 0 ;
  if(dp[wom][bitmask]!=-1) return dp[wom][bitmask] ;

  ll ans = 0 ;

  lp(i,0,n)
  if(marc[wom][i] && !bitLigado(bitmask,i) )
  ans = (ans + recursion(wom+1, (bitmask|(1<<i)) ) ) % MOD ;

  return dp[wom][bitmask]=ans ;

}

int main()
{
  lp(i,0,MAXN)
    lp(j,0,MAX) dp[i][j]=-1;
  scanf("%d",&n) ;
  lp(i,0,n)
  lp(j,0,n) scanf("%d", &marc[i][j]) ;

  printf("%lld\n", recursion(0,0) ) ;

}

Measured memory_bytes: 721280
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
signed main()
{
    int n;
    cin >> n;
    rep(a, 9) rep(b, 9) {
        if (n == (a +1) * (b+1)) {
            println("Yes")
            return 0;
        }
    }
    put("No")
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cfenv>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <limits>

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

int main() {
    string a, b;
    cin >> a >> b;

    string a_str, b_str;

    rep(i, atoi(b.c_str())){
        a_str += a;
    }
    rep(i, atoi(a.c_str())){
        b_str += b;
    }

    if (a_str > b_str) {
        cout << b_str << endl;
    } else {
        cout << a_str << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

ll count_digit(ll n) {
    ll res = 0;
    while(n) {
        n /= 10;
        res++;
    }
    return res;
}


int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    rep(i, 1, n+1) if(count_digit(i) % 2 == 1) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define N 1000000000
//int a[N];

int main()
{
   int n;
   int a[55];
   scanf("%d",&n);
for(int i=0;i<n;i++)
      scanf("%d",&a[i]);
      int sum=0;
      for(int i=0;i<n;i++)
      {
          for(int j=n-1;j>i;j--)
          {
              sum+=a[i]*a[j];
          }
      }
      printf("%d\n",sum);
    return 0;
}




Measured memory_bytes: 256
n,m = map(int,input().split())

class Unionfind:
     
    def __init__(self,n):
        self.uf = [-1]*n
 
    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]
 
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.uf[y] = x
        return True
 
    def size(self,x):
        x = self.find(x)
        return -self.uf[x]
#a = [i+1 for i in range(n)]
d = Unionfind(n)

for i in range(m):
    a,b = map(int,input().split())
    d.union(a-1,b-1)
    
L = []
for i in range(n):
    c = d.find(i)
    L.append(c)
#print(L)
print(len(set(L))-1)

Measured memory_bytes: 19032
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define BUF_SIZE 30

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

int get_int3(int *a1, int *a2, int *a3) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d %d", a1, a2, a3);
#else
#error
#endif
  return 0;
}

#define VERTEX_MAX 15
#define PAT_MAX (1<<15)
// 15*1000 <= INF
#define INF 0x01010101
#define min(a,b) ((a) > (b) ? (b) : (a))

int main(void) {
    int vs, es;
    get_int2(&vs, &es);
    int i, j;
    int mat[VERTEX_MAX][VERTEX_MAX] = {0};
    memset(mat, 0x01, sizeof(int)*VERTEX_MAX*VERTEX_MAX);
    for(i = 0; i < es; i++) {
        int src, dst, dist;
        get_int3(&src, &dst, &dist);
        mat[src][dst] = dist;
    }
    if(vs==2) {
        int res = mat[0][1] + mat[1][0];
        printf("%d\n", res >= INF ? -1 : res);
        return 0;
    }


    // dp[pat][last]
    static int dp[PAT_MAX][VERTEX_MAX] = {0};

    // size = 2
    for(i = 0; i < vs; i++) {
        int pat = (1<<i);
        dp[pat][i] = mat[0][i];
    }

    // size=>=3
    int pat;
    // exclude idx: 0
    for(pat = 2; pat < (1<<vs); pat+=2) {
        if(__builtin_popcount(pat) <= 1) continue;
        int last;
        for(last = 1; last < vs; last++) {
            if(!(pat & (1<<last))) continue;
            int prev_pat = pat & (~(1<<last));
            int res = INF;
            int prev_last;
            for(prev_last = 1; prev_last < vs; prev_last++) {
                if(!(prev_pat & (1<<prev_last))) continue;
                if(last == prev_last) continue;
                res = min(
                    res, dp[prev_pat][prev_last] + mat[prev_last][last]
                );
            }
#ifdef DEBUG
            printf("dp[pat: %d][last: %d] -> %d\n", pat, last, res);
#endif
            dp[pat][last] = res;
        }
    }

    pat = (1<<vs)-2; // 1111..110
    int ans = INF;
    for(i = 1; i < vs; i++) {
        // circuit
        ans = min(ans, dp[pat][i] + mat[i][0]);
    }
    printf("%d\n", ans >= INF ? -1 : ans);
    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>
int i[100012], d[100012]; 
int main()
{
  int n,a,x,y;
  int ans=0,now=1;
  scanf("%d",&n);
  for(a=0;a<n;a++)
    {
      scanf("%d%d",&x,&y);
      i[x]++;
      d[y]++;
    }
  for(a=2;a<=n+1;a++)
    {
      now+=i[a];
      if(now>=a)ans=a-1;
      now-=d[a];
    }
  printf("%d\n",ans);
  exit(0);
}

Measured memory_bytes: 1140
a,b=map(int,input().split())
mod=1000000007
ans=1
if abs(a-b)>1:
  print(0)
else:
  if abs(a-b)==0:
    ans=2
  while a>1:
    ans*=a
    ans%=mod
    a-=1
  while b>1:
    ans*=b
    ans%=mod
    b-=1
  print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

    int four = 0;
    int two = 0;
    int one = 0;
    for (int i=0; i<N; i++) {
        int temp;
        cin >> temp;
        if (temp % 4 == 0) {
          four++;
        } else if (temp % 2 == 0) {
          two++;
        } else {
          one++;
        }
    }
    cout << (four+1 >= (one + two % 2) ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
/+ dub.sdl:
    name "A"
    dependency "dcomp" version=">=0.0.2"
+/

import std.algorithm, std.range, std.stdio, std.math, std.conv, core.bitop;

// import dcomp.scanner;
// import dcomp.algorithm;

int n;
struct Edge {
    int to;
    long dist;
}
Edge[][] g;
long md;

T[N] toS(T, int N)(T[N] data){ return data; }

long[2][] dfs(int p) {
    if (g[p].empty) {
        return [[0L, 0L]];
    }
    Edge le = g[p][0], re = g[p][1];
    auto lt = dfs(le.to);
    auto rt = dfs(re.to);
    if (lt.length > rt.length) {
        swap(le, re);
        swap(lt, rt);
    }
    long ld = le.dist, rd = re.dist;
    auto buf = Appender!(long[2][])();
    foreach (co; lt) {
        //co[1] + ld + rd + rco[0] <= md
        int idx = binSearch!((i){return co[1]+ld+rd+rt[i][0] > md;})(-1, rt.length.to!int)-1;
        if (idx == -1) continue;
        buf.put([co[0]+ld, rt[idx][1]+rd].toS);
        buf.put([rt[idx][1]+rd, co[0]+ld].toS);
    }
    auto ans = buf.data;
    sort(ans);
    if (ans.empty) return ans;
    long ma = 10L^^15;
    int co = 0;
    foreach (ref e; ans) {
        if (ma <= e[1]) {
            continue;
        }
        ma = min(ma, e[1]);
        ans[co] = e;
        co++;
    }

    return ans[0..co];
}

//md以下にできるか？
bool solve(long _md) {
    md = _md;
    return !dfs(0).empty;
}

int main() {
    auto sc = new Scanner();
    int n;
    sc.read(n);
    g = new Edge[][](n);
    foreach (i; 1..n) {
        int a; long b;
        sc.read(a, b); a--;
        g[a] ~= Edge(i, b);
    }

    writeln(binSearch!solve(-1L, 10L^^12));
    return 0;
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

class Scanner {
    import std.stdio : File, readln, stdin;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeString, isDynamicArray;
    import std.algorithm : map;
    File f;
    this(File f = stdin) {
        this.f = f;
    }
    string[] buf;
    bool succ() {
        while (!buf.length) {
            if (f.eof) return false;
            buf = readln.split;
        }
        return true;
    }
    int read(Args...)(auto ref Args args) {
        foreach (i, ref v; args) {
            if (!succ()) return i;
            alias VT = typeof(v);
            static if (!isSomeString!VT && isDynamicArray!VT) {
                v = buf.map!(to!(ElementType!VT)).array;
                buf.length = 0;
            } else {
                v = buf.front.to!VT;
                buf.popFront();
            }
        }
        return args.length;
    }
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/algorithm.d */
// module dcomp.algorithm;

//[0,0,0,...,1,1,1]で、初めて1となる場所を探す。pred(l) == 0, pred(r) == 1と仮定
T binSearch(alias pred, T)(T l, T r) {
    while (r-l > 1) {
        T md = (l+r)/2;
        if (!pred(md)) l = md;
        else r = md;
    }
    return r;
}


Measured memory_bytes: 57596
N,M,C = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)
solver = 0
N.times do |i|
  a = gets.split.map(&:to_i)
  if ( M.times.map { |j| a[j] * B[j] }.inject(:+) + C ) > 0
    solver += 1
  end
end
puts solver

Measured memory_bytes: 1788
#include <stdio.h>

int main()
{
	int i, ans = 0;
	char S[5];
	scanf("%s", S);
	for (i = 0; i < 4; i++) {
		if (S[i] == '+') ans++;
		else ans--;
	}
	printf("%d\n", ans);
	fflush(stdout);
	return 0;
}

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

using namespace std;

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

    if (n >= m) {
        cout << 0 << endl;
        return 0;
    }
    
    vector<long long> x(m);
    for (int i = 0; i < m; ++i) {
        cin >> x[i];
    }
    sort(x.begin(), x.end());
    
    priority_queue<long long> pq;
    for (int i = 0; i + 1 < m; ++i) {
        pq.push(x[i + 1] - x[i]);
    }

    auto res = x[m - 1] - x[0];
    for (int i = 0; i < n - 1; ++i) {
        res -= pq.top();
        pq.pop();
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 2168
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>
#include <random>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
struct UnionFind{
    vector<ll> parent;
    vector<ll> s;
 
    UnionFind(ll n){
        parent.resize(n);
        s.resize(n, 1);
        for(int i = 0; i < n; i++) parent[i] = i;
    }
 
    ll root(ll node){
        if(parent[node] == node){
            return node;
        } else {
            return parent[node] = root(parent[node]);
        }
    }
 
    void unite(ll x, ll y){
        ll rootx = root(x);
        ll rooty = root(y);
        if(rootx == rooty) return;
        if(s[rootx] < s[rooty]) swap(rootx, rooty);
        s[rootx] += s[rooty];
        parent[rooty] = rootx;
    }
 
    bool isSame(ll x, ll y){
        return root(x) == root(y);
    }
 
    ll size(ll x){
        return s[root(x)];
    }
};
int main(void){
    ll n, m;
    cin >> n >> m;

    UnionFind uf(n);
    rep(i, m){
        ll a, b;
        cin >> a >> b;
        a--, b--;
        uf.unite(a, b);
    }

    set<ll> st;
    rep(i, n){
        st.insert(uf.root(i));
    }

    cout << st.size() - 1 << endl;
}



Measured memory_bytes: 8388
use std::collections::VecDeque;
use std::io;

fn main() {
    let s = parse_line::<String>();
    let q = parse_line::<usize>();
    let mut queries: Vec<Vec<char>> = Vec::with_capacity(q);
    for _ in 0..q {
        let line = parse_line::<String>();
        let cs: Vec<char> = line
            .split_whitespace()
            .map(|c| c.chars().next().unwrap())
            .collect();
        queries.push(cs);
    }
    let mut header_queue = VecDeque::with_capacity(q);
    let mut tail_queue = VecDeque::with_capacity(q);
    let mut reverse_state = false;
    for query in queries {
        if query[0] == '1' {
            reverse_state = !reverse_state;
        } else {
            if (query[1] == '1') ^ reverse_state {
                header_queue.push_back(query[2]);
            } else {
                tail_queue.push_back(query[2])
            }
        }
    }
    if reverse_state {
        let h: String = tail_queue.into_iter().rev().collect();
        let reverse_s: String = s.chars().rev().collect::<String>();
        let t: String = header_queue.into_iter().collect();
        println!("{}{}{}", h, reverse_s, t);
    } else {
        let h: String = header_queue.into_iter().rev().collect();
        let t: String = tail_queue.into_iter().collect();
        println!("{}{}{}", h, s, t);
    }
}

/// Parse line from io::stdin into T Value
fn parse_line<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

Measured memory_bytes: 16636
#include<stdio.h>
int main()
{
    int a[10],i;
    for(i=1;i<=5;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=1;i<=5;i++)
    {
        if(a[i]==0)
        {
            printf("%d\n",i);
        }
    }
    return 0;
}


Measured memory_bytes: 1728
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 1000000007;
//const int MOD = 998244353;
//const long long int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;

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

	cin >> N >> K;
	vector<int>v(N);
	for (auto &i : v)cin >> i;
	int ans = 0;
	for (int i = 0; i <= K; i++) {
		for (int j = 0; j <= min(i, (int)N); j++) {
			if (j <= i - j)continue;
			for (int k = 0; k <= j; k++) {
				int sum = 0;
				vector<int>w;
				for (int l = 0; l < k; l++) {
					sum += v[l];
					w.push_back(v[l]);
				}
				for (int l = 0; l < j - k; l++) {
					sum += v[N - 1 - l];
					w.push_back(v[N - 1 - l]);
				}
				sort(w.begin(), w.end());
				for (int l = 0; l < i - j; l++)sum -= min(0, w[l]);
				ans = max(ans, sum);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
/*
	https://atcoder.jp/contests/agc003/tasks/agc003_e
	
	If q[i] > q[i+1], q[i] is useless. Make queries increasing.
	Divide the final sequence into blocks of size q[i]-q[i-1].
	
	Let cnt[i] = number of times we count element i.
	We can remove an element i if we do cnt[x] += cnt[i], where x was the position of the
	copied by the position i.
	
	Process and pop blocks from right to left, updating cnt to obtain smaller equivalent situation.
	Updates are sum of prefix, so we can maintain cnt in compressed form
	(put one token on i = add 1 to cnt[1..i]).
	Break things correctly (euclidian div : Q*complete circle + a prefix => two tokens).
	
	Then we restore and print cnt[1...n] (suffix sum on tokens).
	
	Complexity: we can guess that the solution runs fast enough, because it's hard to reach large positions multiple times.

	More precisely, look at distinct positions of tokens. We have N "mandatory positions", the end of each block.
	Ignore these. These ones create N "original tokens".
	Then each original token create (at most) one new token (ignoring the mandatory one). In other words it moves.
	At each move, the position of a token is divided by at least 2. So we will process at most O(N log 1e18) distinct positions in the map.
*/

#include <bits/stdc++.h>
#define SZ(v) ((int)((v).size()))
using namespace std;
using ll = long long;

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

	int nbVal, nbQuery;
	cin >> nbVal >> nbQuery;
	vector<ll> queries {nbVal};
	for (int iQuery = 0; iQuery < nbQuery; ++iQuery) {
		ll x; cin >> x;
		while (!queries.empty() && queries.back() >= x) {
			queries.pop_back();
		}
		queries.push_back(x);
	}

	map<ll, ll> tokens;
	tokens[queries.back()-1]++;

	for (int iQuery = SZ(queries)-1; iQuery > 0; --iQuery) {
		ll before = queries[iQuery-1];
		ll deb = before;
		while (!tokens.empty()) {
			auto it = tokens.end(); --it;
			auto [posTok, nbOcc] = *it;
			if (posTok < deb) break;
			ll nbCompl = (posTok-deb)/before;
			tokens[deb-1] += nbOcc*(nbCompl+1);
			ll posMove = (posTok-deb)%before;
			assert(2*posMove <= posTok); // Position of the token divided by 2
			tokens[posMove] += nbOcc;
			tokens.erase(it);
		}	
	}

	for (ll i = queries.front()-1; i >= 1; --i) {
		tokens[i-1] += tokens[i];
	}
	for (int iVal = 0; iVal < nbVal; ++iVal) {
		cout << tokens[iVal] << "\n";
	}
}


Measured memory_bytes: 10344
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>

using namespace std;
typedef char CHAR;
typedef unsigned char UCHAR;
typedef short SHORT;
typedef unsigned short USHORT;
typedef int INT;
typedef unsigned int UINT;
typedef long long LLONG;
typedef unsigned long long ULLONG;

#define LengthOf(x)    (sizeof(x) / sizeof(x[0]))


#if 0
int main()
{
	INT N, M;
	cin >> N >> M;

	int work = 0;
	for (int i = 0; i < M; ++i) {
		int tmp = 0;
		cin >> tmp;
		work += tmp;
	}

	if (work > N) { cout << "-1"; }
	else {
		cout << N - work;
	}

	return 0;
}
#endif


#if 1
//No.1
int main()
{
	INT R;
	cin >> R;

	cout << 2 * R * 3.14159265359;
	return 0;
}
#endif

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()

int n, m, t, a[mxN];
vi v;

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

int main() {
  fast();
  int x;
  cin >> x >> n;
  set<int> u;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    u.insert(a);
  }
  int diff = 0;
  while (true) {
    int s = x - diff, b = x + diff;
    if (u.find(s) == u.end()) {
      cout << s;
      break;
    }
    if (u.find(b) == u.end()) {
      cout << b;
      break;
    }
    ++diff;
  }
  return 0;
}


Measured memory_bytes: 3656
import java.util.*;
import java.math.*;
import java.awt.geom.*;
import java.io.*;
    
    
public class Main {
	static ArrayList<Integer> list = new ArrayList<Integer>();
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		makePrimeList();
		int[] l = new int[list.size()+1];
		for(int i = 0; i < list.size(); i++) {
			l[i+1] = l[i] + list.get(i);
		}
		while(true) {
			int n = sc.nextInt();
			if(n == 0) break;
			int count = 0;
			for(int i = 0; i < l.length; i++) {
				for(int j = 0; j < i; j++) {
					if(l[i] - l[j] == n) count++;
					if(l[i] - l[j] <= n) break;
				}
			}
			System.out.println(count);
			
		}
		
	}
	static void makePrimeList() {
		boolean[] isntPrime = new boolean[10001];
		list.add(2);
		for(int i = 3; i < isntPrime.length; i += 2) {
			if(!isntPrime[i]) {
				list.add(i);
				for(int j = i + i; j < isntPrime.length; j += i) {
					isntPrime[j] = true;
				}
			}
		}
	}
	
}

Measured memory_bytes: 26976
/**
* Author : zzy
* Date : 2020-04-19-20.09.04 Sunday
*/
#include <bits/stdc++.h>

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) ((int)(x).size())

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = 2*(int)1e5+1000;
int cnt[maxn], n, a[maxn];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    ms(cnt, 0);
    cin >> n;
    forn(i, n) {
        cin >> a[i];
        ++cnt[a[i]];
    }
    for1(i, n) cout << cnt[i] << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


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

int main() {
  int n, a = 0;
  cin >> n;
  vector<int> v(n);
  for(int i = 0; i < n; i++)
    cin >> v.at(i);
  for(int i = 1; i < n - 1; i++){
    if((v[i-1] < v[i] && v[i+1] > v[i]) || (v[i-1] > v[i] && v[i+1] < v[i]))
      a++;
  }
  cout << a << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
main(){
	int n,i;
	unsigned int s,x,m;
	for(;scanf("%d",&n),n;){
		for(s=i=0;i<n;i++)scanf("%u",&x),s+=x;
		vector<unsigned int>v;
		for(i=0;i<n-1;i++)scanf("%u",&x),v.push_back(x);
		sort(v.begin(),v.end());
		for(i=n-1,m=s*n;i;m=s*i,i--)if(s+=v[i-1],s*i<m)break;
		printf("%u\n",m);
	}
}

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

ll n;
ll m;
ll q;
ll ans=0;
V a,b,c,d;

void dfs(V& now){
    if(now.size()==n){
        ll tmp=0;
        rep(i,q){
            if(now[b[i]]-now[a[i]]==c[i])tmp+=d[i];
        }
        ans=max(ans,tmp);
    }else if(now.size()!=0){
        ll e=now[now.size()-1];
        for(ll i=e;i<=m;i++){
            now.push_back(i);
            dfs(now);
            now.pop_back();
        }
    }else{
        for(ll i=1;i<=m;i++){
            now.push_back(i);
            dfs(now);
            now.pop_back();
        }
    }
}

int main() {
    cin>>n>>m>>q;
    a=V(q);
    b=V(q);
    c=V(q);
    d=V(q);
    rep(i,q){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        a[i]--;
        b[i]--;
    }
    V tmp;
    dfs(tmp);
    cout<<ans<<endl;
}


Measured memory_bytes: 3632
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

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

        int n = sc.nextInt();
        int k = sc.nextInt();
        Sushi[] sushis = new Sushi[n];
        for (int i = 0; i < n; ++i) {
            sushis[i] = new Sushi(sc.nextLong(), sc.nextLong());
        }

        // 寿司のおいしさで降順ソートする
        Arrays.sort(sushis, Comparator.reverseOrder());

        // 寿司の種類ごとの個数を保持っておく為の枠作り
        Map<Long, Integer> eats = new HashMap<>();
        for (int i = 0; i < n; i++) {
            eats.put((long) i + 1, 0);
        }

        // K個の寿司をまず降順ソートした順で食べる。種類は気にしない
        List<Sushi> normalSushi = new ArrayList<>();
        long delicious = 0;
        for (int i = 0; i < k; ++i) {
            Sushi sushi = sushis[i];
            long type = sushi.t;

            if (eats.get(type) > 0) {
                // ボーナスにならない寿司を詰める
                normalSushi.add(sushi);
            }

            delicious += sushi.d;
            eats.put(type, eats.get(type) + 1);
        }

        // 最初に食べた寿司以外を詰める
        List<Sushi> otherSushi = new ArrayList<>();
        Set<Long> otherVariety = new HashSet<>();
        for (int i = k; i < n; ++i) {
            Sushi item = sushis[i];
            long sushiType = item.t;
            if (eats.get(sushiType) == 0 && !otherVariety.contains(sushiType)) {
                otherVariety.add(sushiType);
                otherSushi.add(item);
            }
        }

        // 今何種類食べたかカウントする
        long variety = eats.values().stream().filter(s -> s != 0).count();

        long base = delicious + variety * variety;
        long ans = base;

        // 何個入れ替えるかでループ
        long loss = 0;
        for (int i = 0; i < Math.min(otherSushi.size(), normalSushi.size()); ++i) {
            int remIdx = i;
            int replIdx = normalSushi.size() - (i + 1);
            long gain = (2 * variety + i + 1) * (i + 1);
            loss += normalSushi.get(replIdx).d - otherSushi.get(remIdx).d;
            ans = Math.max(ans, base + gain - loss);
        }

        System.out.println(ans);
    }

    /**
     * 種類とおいしさを持った寿司クラス。 おいしさで降順ソートされる
     */
    static class Sushi implements Comparable<Sushi> {
        long t;
        long d;

        Sushi(long t, long d) {
            this.t = t;
            this.d = d;
        }

        @Override
        public int compareTo(Sushi o) {
            return (int) (this.d - o.d);
        }

        @Override
        public String toString() {
            return String.format("%s:%s", t, d);
        }

    }
}



Measured memory_bytes: 99868
#include <stdio.h>
int main(void){
    int i=0, a=0, f=0;
    char str[200000];
    //char ans[200000];
    scanf("%s", str);
    
    while(str[i] != 'A'){
        i++;
    }
    while(str[i] != '\0'){
        a++;
        if(str[i] == 'Z'){
            f = a;
        }
        i++;
    }
    printf("%d\n", f);
    
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

class Main{

	public static void main(String[] args){

    Scanner sc = new Scanner(System.in);

	int w = sc.nextInt();
	int h = sc.nextInt();
	int x = sc.nextInt();
	int y = sc.nextInt();
	int r = sc.nextInt();

	int max_x = x + r;
	int min_x = x - r;
	int max_y = y + r;
	int min_y = y - r;

		if(max_x <= w && min_x >= 0 && max_y <= h && min_y >= 0){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26292
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define powerof2 ()
#define mp make_pair
#define pi acos(-1)
using ll = long long;
const ll M = 1000000007;
const ll M1= 998244353;
using vl = vector<ll>;
using pll =  pair<ll,ll>;
/*ll power(ll x,ll y){
	if(y==0)
		return 1;
	ll res=power(x,y/2);
	res=(res*res);
	if(y&1)
		res=(res*x);
	return res;
}
 
ll powermod(ll x,ll y,ll mod){
	if(y==0)
		return 1;
	ll res=powermod(x,y/2,mod);
	res=(res*res)%mod;
	if(y&1)
		res=(res*x)%mod;
	return res;
}
ll binarysearch(ll va)
{
	ll n=1;
	ll l=va+1,u=n;
	ll st=num.order_of_key(va);
	while(l+1<u)
	{
		m=(l+u)/2;
		ll in=num.order_of_key(m);
		if(in-st==m-va)
		{
			l=m;
		}
		else
		{
            u=m;
		}
	}
	if(num1.find(l)==num1.end())
		return l;
	return u;
}
bool IsPrime(long long number) 
{
  long long root = sqrt(number) ;
   for(long long i=2; i<=root; i++) 
   {
      if(number%i == 0)
          return false;
   } 
   return true;
} */
void solve(){
	long long n;
	cin>>n;
	vector<pair<long long,long long> > v;
	for(ll i=1;i<=sqrt(n);i++){
        if(n%i==0){
            v.push_back(make_pair(i, n/i));
        }
    }
	ll mn=1e12;
	for(auto i:v){
         if(i.first+i.second-2<mn){
			 mn=i.first + i.second -2;
		 }}
		 cout<<mn<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    // cin>>t;
 
    for(int i=1;i<=t;i++)
    {//cout<<"Case #"<<i<<": ";
    solve();}
    return 0;
}

Measured memory_bytes: 3688
def input_from_console():
    n = int(input())
    p_list= list(map(int, input().strip().split()))
    return n, p_list


def solve(n, p_list):
    result = 0
    if n <= 2:
        return result
    for i in range(n - 2):
        if min(p_list[i], p_list[i+2]) < p_list[i+1] and max(p_list[i], p_list[i+2]) > p_list[i+1]:
            result += 1
    return result


def main():
    n, p_list = input_from_console()
    print(solve(n, p_list))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()

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

int main(void) {
    string s[2];
    cin >> s[0] >> s[1];

    if((s[0][0] == s[1][2])
        && (s[0][1] == s[1][1])
        && (s[0][2] == s[1][0]))
        cout << "YES\n";
    else
        cout << "NO\n";
    return 0;
}


Measured memory_bytes: 256
a, b, c, x, y = map(int, input().split())
if x < y:
  a, b, x, y = b, a, y, x # x >= y
m1 = y * 2 * c + (x - y) * a
m2 = a * x + b * y
m3 = x * c * 2
print(min(m1, m2, m3))

Measured memory_bytes: 8992
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9+7


def solve(f):
    n = f.read_int()
    a = f.read_int_list()

    asum = [0]
    for ai in a:
        asum.append(asum[-1]+ai)

    c = collections.Counter(asum)
    ans = 0
    for k, v in c.items():
        ans += v*(v-1)/2

    return ans


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)


Measured memory_bytes: 45072
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <set>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

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

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

	string s;
	cin >> s;

	int k;
	
	cin >> k;

	set<string> se;

	int len = s.size();

	rep(i, len)
	{
		for(int j=i; j < k+i; j++)
		{
			se.insert(s.substr(i, j-i+1));
		}
	}

	set<string>::iterator it = se.begin();

	int t = 1;

	for(; it != se.end(); it++)
	{
		if (t == k)
		{
			cout << *it << endl;
			break;
		}
		t++;
	}
	
	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define FOR(i,n,m) for(int i=n;i<int(m);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
using namespace std;

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

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}	

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int N_MAX=100010;

int main(){
	double n;
	cin>>n;
	for(int i=0;i<50000;i++){
		if((int)(i*1.08)==n){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<":("<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<vector>
#include<string>
#include <cmath>
#include <iomanip>
#include <math.h>
#include <numeric>
#include <utility>
using namespace std;

int main() {
	int D;
	cin >> D;
	if (D == 25)cout << "Christmas" << endl;
	if (D == 24)cout << "Christmas Eve" << endl;
	if (D == 23)cout << "Christmas Eve Eve" << endl;
	if (D == 22)cout << "Christmas Eve Eve Eve" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

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

	int a, b;
	cin >> a >> b;
    if(b==1){
      cout<<0<<endl;
      return 0;
    }
	int cnt = 1;
	int ans = 0;
	while (true) {
		cnt += a - 1;
		ans++;
		if (cnt >= b) {
			cout << ans << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
            int a,b;
            scanf("%d\n",&a);
            scanf("%d\n",&b);
            if (a<b){
                printf("a < b\n");
            }else if(a>b){
                printf("a > b\n");
            }else{
                printf("a == b\n");
            }
}


Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;
 
int A, L, d[6];
 
void toarray(int a) {
  REP(i, 0, L) {
    d[i] = a % 10;
    a /= 10;
  }
}
 
int number() {
  int n = 0;
  REP(i, 0, L) n = n * 10 + d[i];
  return n;
}
 
int find(int n, vector<int> &v) {
  REP(i, 0, v.size()) if(v[i] == n) return i;
  return -1;
}
 
int main(void) {
  while(cin >> A >> L, A || L) {
    vector<int> v;
    for(int i = 0; true; i++) {
      int idx;
      if((idx = find(A, v)) >= 0) {
        cout << idx << " " << A << " " << (i - idx) << endl;
        break;
      }
      v.push_back(A);
      toarray(A);
      sort(d, d + L);
      int nmin = number();
      reverse(d, d + L);
      int nmax = number();
      A = nmax - nmin;
    }
  }
 
  return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, n;
  cin >> A >> B;
  
  if(A >= 13)
    n=B;
    else if(A >= 6)
      n=B/2;
  		else
          n=0;
  
  cout << n<<endl;
  
}

Measured memory_bytes: 256