akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(){
    ll N;
    cin >> N;
    map<string, ll> names;
    string init = "MARCH";
    for(size_t i = 0; i < 5; i++)
    {
        names[init.substr(i,1)] = 0;
    }
    for(size_t i = 0; i < N; i++)
    {
        string s;
        cin >> s;
        if(init.find(s.substr(0,1)) != string::npos) {
            names[s.substr(0,1)]++;
        }
    }
    ll ret = 0;
    ret += names["M"] * names["A"] * names["R"];
    ret += names["M"] * names["A"] * names["C"];
    ret += names["M"] * names["A"] * names["H"];
    ret += names["M"] * names["R"] * names["C"];
    ret += names["M"] * names["R"] * names["H"];
    ret += names["M"] * names["C"] * names["H"];
    ret += names["A"] * names["R"] * names["C"];
    ret += names["A"] * names["R"] * names["H"];
    ret += names["A"] * names["C"] * names["H"];
    ret += names["R"] * names["C"] * names["H"];
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(int  i=(a); i<(b);++i)


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,d,x,y,cnt=0;
    cin>>n>>d;
    f(i,0,n) {
        cin>>x>>y;
        double a=sqrt(x*x+y*y);
        if(a<=d) cnt++;
        }
        cout<<cnt<<endl;
    return 0;
}




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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int N;
  cin >> N;

  if (N % 2 == 0) {
    cout << "0.5\n";
  }else {
    int even = N / 2;
    int odd = N - even;
    double p = (double)odd / N;
    cout << p << endl;
  }
  return 0;
}



Measured memory_bytes: 256
<?php /*atcoder.php*/

$t = new temp();

$t->stdin(fgets(STDIN));

unset($t);

class temp{
	private $stdin = array();
	
	public function __construct(){
	}

	public function stdin($data = null){
		echo str_replace('2017', '2018', $data);
	}
	
}

?>


Measured memory_bytes: 3576
S = str(input())
K = int(input())
s = list(S)

i = 0
p = 0
for i in range(len(s)):
    s[i] = int(s[i])
i = 0
while  i < len(s):
    if s[i] == 1:
        p = i + 1
    else:
        q = s[i]
        break
    i = i+1
if K < p + 1:
    print(1)
else:
    print(q)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
void A() {
    int n;
    cin>>n;
    vector<int> a(n,0);
    for(int i=0; i<n; i++)
        cin>>a[i];
    vector<int> dp(n+1,inf);
    dp[0]=0;
    for(int i=1; i<n; i++) {
        dp[i]=min(dp[i],dp[i-1]+abs(a[i]-a[i-1]));
        if(i>=2)
            dp[i]=min(dp[i],dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<dp[n-1]<<endl;

}
void B() {
    int n,k;
    cin>>n>>k;
    vector<int> dp(n+1,inf);
    vector<int> h(n,0);
    for(int i=0; i<n; i++)
        cin>>h[i];
    dp[0]=0;
    for(int i=1; i<n; i++) {
        for(int len=1; len<=min(k+1,i+1); len++) {
            int j=i-len+1;
            dp[i]=min(dp[i],dp[j]+abs(h[j]-h[i]));
        }
    }
    cout<<dp[n-1]<<endl;
}
void C() {
    int n;
    cin>>n;
    vector<vector<int>> a(n,vector<int>(3,0));
    for(int i=0;i<n;i++) cin>>a[i][0]>>a[i][1]>>a[i][2];
    vector<vector<int>> dp(n,vector<int>(3,0));
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for(int i=1; i<n; i++) {
        for(int j=0; j<3; j++) {
            for(int k=0; k<3; k++) {
                if(j==k)
                    continue;
                dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
                //cout<<dp[i][j]<<endl;
            }
        }
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    C();
}


Measured memory_bytes: 14264
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll A, B;
    cin >> A >> B;
    if (1 <= A && A < 10 && 1 <= B && B < 10) {
        cout << A * B << endl;
    } else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        while (true) {
            String line = reader.readLine();
            if (line == null || line.isEmpty()) {
                break;
            }
            double a = Double.parseDouble(line);
            double s = a;
            for (int i = 2; i <= 10; i++) {
                if (i % 2 == 0) {
                    a *= 2;
                } else {
                    a /= 3;
                }
                s += a;
            }
            out.println(s);
        }
    }
}

Measured memory_bytes: 9756
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define all(c) begin(c),end(c)
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
//最大公約数
ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}
//最小公倍数
ll lcm(ll x, ll y) {
  return x/gcd(x, y)*y;
}
//素因数分解
vector<pair<ll,int>> factorize(ll n) {
  vector<pair<ll,int>> res;
  for (ll i = 2; i*i <= n; ++i) {
    if (n%i) continue;
    res.emplace_back(i,0);
    while (n%i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1) res.emplace_back(n,1);
  return res;
}
 
 
 
 
int main() {
  ll a,b;
  cin>>a>>b;
  ll g=gcd(a,b);
  auto f=factorize(g);
  ll count=f.size()+1;
  cout<<count<<endl;
  
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)

using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


char maze[1010][1010];
bool checked[1010][1010]={};
int main(){

int h,w;
cin>>h>>w;
vector<queue<int>>q(2010);
rep2(i,h){
    rep2(k,w){
        cin>>maze[i][k];
        if(maze[i][k]=='#'){
            q[0].push(k);
            q[0].push(i);
            checked[i][k]=true;
        }
    }
}
long long  p=0;

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

while(1){
    bool finish=true;
    while(!q[p].empty()){
        int x=q[p].front();q[p].pop();
        int y=q[p].front();q[p].pop();
        rep(i,4){
        int nowx=x+dx[i];
        int nowy=y+dy[i];
            if(!checked[nowy][nowx] && nowx<=w && nowx>=1 && nowy<=h && nowy>=1)
            {
            q[p+1].push(nowx);
            q[p+1].push(nowy);
            finish=false;
            checked[nowy][nowx]=true;
            }
        } 
    }
    if(finish)break;
    p++;
}
cout<<p<<endl;
 return 0;
}
/*
3 3
...
.#.
...

2


6 6
..#..#
......
#..#..
......
.#....
....#.

3
*/

Measured memory_bytes: 11792
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define DBG 0
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int f(vector<int> &a, int x) {
  rep(i, 0, a.size()) { x = x / a[i] * a[i]; }
  return x;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int K;
  cin >> K;
  vector<int> A(K);
  rep(i, 0, K) { cin >> A[i]; }
  if (DBG) {
    rep(i, 2, 200) { dump(i, f(A, i)); }
  }

  int l = 1, r = INF;
  while (r - l > 1) {
    int m = (l + r) / 2;
    if (f(A, m) == 0)
      l = m;
    else
      r = m;
  }
  int x = r;
  int y = INF;

  if (f(A, r) != 2) {
    cout << -1 << endl;
  } else {
    while (y - x > 1) {
      int m = (y + x) / 2;
      if (f(A, m) == 2)
        x = m;
      else
        y = m;
    }
    cout << r << " " << x << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace __gnu_pbds;
using namespace std;
typedef tree<
ll,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
struct Node
{
    ll pos, val, color;
    bool operator<( const Node &A) const
    {
        return A.val > val;
    }
};


int main()
{
    ll a, b, c, d, i = 1;
    cin>>a>>b>>c>>d;
    while(a > 0 && c > 0)
    {
        if(i%2) c -= b;
        else a -= d;
        if(a <= 0) {
            puts("No");
            return 0;
        }
        if(c <= 0) {
            puts("Yes");
            return 0;
        }
        i++;
    }
    return 0;
}



Measured memory_bytes: 3636
#!/usr/bin/python

import re

def main():
    key = raw_input().split('.')[1:]
    indent = 0
    level = 0
    need_update = False
    while True:
        try:
            s = raw_input()
        except EOFError:
            break

        space = len(re.match(' *', s).group())
        if need_update:
            indent = space
            need_update = False

        if re.match(' *'+' '*indent+key[level]+':', s):
            indent = len(re.match(' *', s).group())
            level += 1
            need_update = True
            if len(key) == level:
                t = s[len(key[level-1])+indent+2:]
                if not t:
                    print 'object'
                else:
                    print 'string "'+t+'"'
                return

            t = s[len(key[level-1])+indent+2:]
            if t:
                break

        elif not s.startswith(' '*indent):
            break

        if space < indent:
            break

    print 'no such property'

if __name__ == '__main__':
    main()

Measured memory_bytes: 6604
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int N, A, B;

int main()
{
	in >> N >> A >> B;

	auto dif = B - A - 1;
	if (dif % 2 == 1) { out << "Alice" << std::endl; }
	else { out << "Borys" << std::endl; }
	return 0;
}

Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Clue = Tuple!(long, "x", long, "y", long, "h");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

long cnt;

void main()
{
    long k, n;
    scan(k, n);
    auto a = aryread();
    auto dif = new long[](n);
    foreach(i; iota(n))
    {
        dif[i] = a[(i + 1) % n] - a[i];
        if(dif[i] < 0)
            dif[i] += k;
    }
    dif.sort();
    writeln(k - dif[$ - 1]);
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


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

def main():
    N, M = map(int, input().split())
    A = [input().strip() for i in range(N)]
    B = [input().strip() for i in range(M)]

    ok = False
    for sy in range(N-M+1):
        for sx in range(N-M+1):
            ok = True
            for y in range(M):
                for x in range(M):
                    if A[sy+y][sx+x] != B[y][x]:
                        ok = False
                        break
                if not ok:
                    break
            if ok:
                break
        if ok:
            break
    
    if ok:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

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

int main(){
	int n, d;
	cin >> n >> d;
	vector<vector<int> >x(n, vector<int>(d));
	rep(i, n){
		rep(j, d){
			cin >> x[i][j];
		}
	}
	int ans = 0;
	rep(i, n){
		rep(j, i){
			int sq = 0;
			rep(k, d){
				int s = x[i][k] - x[j][k];
				sq += s * s;
			}
			int s = sqrt(sq) + 0.5;
			if(s * s == sq){
				ans++;
			}
		}
	}
	cout << ans << endl;

    return 0;
}


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

int main() {
  char a;
  
  cin >> a;
  
  if (a == 'A') {
    cout << 'T';
  }
  else if (a == 'T') {
    cout << 'A';
  }
  else if (a == 'C') {
    cout << 'G';
  }
  else if (a == 'G') {
    cout << 'C';
  }
  
  return 0;
}
  


Measured memory_bytes: 256
using System;

namespace ABC049C
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            int cur = 0;
            int N = S.Length;

            while (cur < (N - 4))
            {
                int curD = S.IndexOf("dream", cur, 5);
                int curE = S.IndexOf("erase", cur, 5);
                if (curD != curE) // find "dream" or "erase"
                {
                    cur += 5;
                    if (cur == N) { break; } // reach end of S
                    if (curD != -1) // appear "dream" faster 
                    {
                        if (S[cur] == 'e') // is "dreame*"?
                        {
                            if (S[cur + 1] != 'r') { cur = -1; break; } // is "dreamer"?
                            if((cur + 2) < N) // is "dreamer*"? else, it may be end as "dreamer"
                            {
                                if(S[cur + 2] != 'a') // dreamer[^a] ( == [de])  else, will continue "erase" after "dream"
                                {
                                    cur += 2;
                                }
                            }
                            else
                            {
                                cur += 2;
                            }
                        }
                    }
                    else // appear "erase" faster
                    {
                        if (S[cur] == 'r') // "eraser"
                        {
                            cur++;
                        }
                    }
                }
                else
                {
                    cur = -1;
                    break;
                }

            }

            Console.WriteLine((cur >= N) ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 13792
import java.util.*;

@SuppressWarnings("unused")
public class Main {

  private static void solve() {

    char[] s = ns();
    if (s[s.length - 1] == 's') {
      System.out.println(new String(s) + "es");
    } else {
      System.out.println(new String(s) + "s");
    }

  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 37076
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
ans = 0
xy = [LIST() for _ in range(n)]
arr = list(permutations(list(range(n)), n))
ans = 0
for i in range(len(arr)):
    for j in range(len(arr[i]) - 1):
        ans += sqrt((xy[arr[i][j]][0] - xy[arr[i][j + 1]][0]) ** 2 + (xy[arr[i][j]][1] - xy[arr[i][j + 1]][1]) ** 2)
ans /= len(arr)
print(ans)

Measured memory_bytes: 9924
N, K = map(int, input().split())
S = list(input())

seq = []
tmp = 0
for i in range(N-1):
    if S[i] != S[i+1]:
        tmp += 1
        seq.append(tmp)
        tmp = 0
            
    else:
        tmp += 1

seq.append(tmp+1)

seq_sum = [0 for _ in range(len(seq)+1)]

for i in range(len(seq)):
    seq_sum[i+1] = seq_sum[i] + seq[i]

res = -1
if S[0] == '0':
    for i in range(len(seq_sum)):
        if i%2 == 0:
            r = min(i + 2*K, len(seq_sum)-1)
            res = max(res, seq_sum[r] - seq_sum[i]) 
        else:
            r = min(i + 2*K+1, len(seq_sum)-1)
            res = max(res, seq_sum[r] - seq_sum[i])
        
else:
    for i in range(len(seq_sum)):
        if i%2 == 0:
            r = min(i + 2*K+1, len(seq_sum)-1)
            res = max(res, seq_sum[r] - seq_sum[i])
        else:
            r = min(i + 2*K, len(seq_sum)-1)
            res = max(res, seq_sum[r] - seq_sum[i]) 

            
print(res)

Measured memory_bytes: 8608
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
typedef long long int ll;
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define m0(x) memset(x,0,sizeof(x))

int main(void)
{
	ll k,a,b;
	scanf("%lld %lld %lld",&k,&a,&b);
	ll nokori;
	ll max;
	if (a+2>=b) max=1+k;
	else if(a+1>k) max=1+k;
	else {
		max=b;
		nokori=k-(a+1);
		max+=(nokori/2)*(b-a);
		if(nokori%2==1) max++;
	}
	printf("%lld\n",max);
	return 0;
}

Measured memory_bytes: 128
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int N;
    cin >> N;
    multiset<int> s;
    REP(i, N) {
        int a;
        cin >> a;
        s.insert(a);
    }

    int ans = 0;
    while (!s.empty()) {
        int a = *s.rbegin();
        s.erase(s.find(a));
        REV(i, 35, 1) {
            int t = 1LL << i;
            if (a > t) continue;

            if (s.count(t - a) > 0) {
                s.erase(s.find(t - a));
                ans++;
                break;
            }
        }
    }

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


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define iiordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define MOD (1000*1000*1000+7)
ll power(ll a,ll b, ll m=MOD)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
            res=(res*a)%MOD;
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll inverse(ll a,ll m=MOD)
{
    return power(a,m-2,m);
}
int ceil(int a,int b)
{
    return (a+b-1)/b;
}
#define INFl (1e18+5)
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<long long>
#define vvl vector<vl>
#define vll vector<pll>
#define vii vector<ii>
#define vvii vector<vii>
#define tri pair<int,ii>
#define F first
#define S second
#define forl(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define rforl(i,n)  for(int i=n-1;i>=0;i--)
#define rfore(i,n)  for(int i=n;i>=1;i--)
#define CASE(t) cout<<"Case #"<<(t)<<": ";
#define INF 1020000000
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define print(x)    for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<endl;
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) cout<<it->F<<' '<<it->S<<endl;  
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
int main()
{
  int n,m;
  cin>>n>>m;
  if(n==m)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
// template.cpp

// Defines.
//#define DEBUG
#define NUMBER_OF_DIGITS 6

// Includes.
#include <bits/stdc++.h>

#ifdef DEBUG
#include <chrono>
#endif

// Usings.
using namespace std;

// Main function.
int main()
{
#ifdef DEBUG
	chrono::system_clock::time_point start, end;
	
	start = chrono::system_clock::now();
#endif
	
	// settings.
	ios::sync_with_stdio(false);
	
	//cout << fixed;
	//cout << setprecision(NUMBER_OF_DIGITS);
	
	// logic.
	long long n;
	cin >> n;
	long long sqrt = (long long)pow((double)n, 0.5);
	for (long long a = sqrt; a >= 1; a--)
	{
		if ((n % a) == 0)
		{
			long long b = n / a;
			int digit = 0;
			while(true)
			{
				digit++;
				b /= 10;
				if (b == 0)
				{
					cout << digit << endl;
					break;
				}
			}
			
			break;
		}
	}

#ifdef DEBUG
	end = chrono::system_clock::now();
	
	double elapsed = chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
	cout << elapsed << "[ms]" << endl;
#endif
	
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    while (true) {
        int plen;
        cin >> plen;
        if (plen == 0) {
            break;
        }
        int cnum;
        cin >> cnum;
        int width;
        cin >> width;
        int cspace;
        cin >> cspace;
        vector<string> v;
        {
            string s;
            // ignore newline character after cspace
            getline(cin, s);
            while (true) {
                getline(cin, s);
                if (s == "?") {
                    break;
                }
                v.push_back(s);
            };
        }
        vector<string> columnLines;
        for (auto&& i : v) {
            if (i == "\n") {
                columnLines.emplace_back(width, '.');
            }
            else if (i.size() < width) {
                columnLines.push_back(i + string(width - i.size(), '.'));
            }
            else if (i.size() == width) {
                columnLines.push_back(i);
            }
            else {
                auto t = i;
                while (true) {
                    columnLines.push_back(
                        t.substr(0, static_cast<size_t>(width)));
                    t = t.substr(static_cast<size_t>(width));
                    if (t.size() < width) {
                        break;
                    }
                }
                if (!t.empty()) {
                    columnLines.push_back(t + string(width - t.size(), '.'));
                }
            }
        }
        auto emptyLines = columnLines.size() % (plen * cnum);
        if (emptyLines != 0) {
            auto s = string(static_cast<size_t>(width), '.');
            fill_n(back_inserter(columnLines), plen * cnum - emptyLines, s);
        }

        vector<vector<string>> pages;
        for (int i = 0; i < columnLines.size() / (plen * cnum); ++i) {
            vector<string> p;
            copy_n(begin(columnLines) + i * plen * cnum, plen * cnum,
                   back_inserter(p));
            pages.push_back(move(p));
        }

        for (auto&& page : pages) {
            for (int i = 0; i < plen; ++i) {
                stringstream ss;
                for (int j = 0; j < cnum; ++j) {
                    if (j != 0) {
                        ss << string(static_cast<size_t>(cspace), '.');
                    }
                    ss << page[i + j * plen];
                }
                cout << ss.str() << endl;
            }
            cout << '#' << endl;
        }

        cout << "?" << endl;
    }
}

Measured memory_bytes: 3216
def choose_integers(A: int, B: int, C: int) -> bool:
    n = A
    for _ in range(B):
        n %= B
        if n == C:
            return True
        n = (n + A)
    return False


if __name__ == "__main__":
    A, B, C = map(int, input().split())
    yes = choose_integers(A, B, C)
    print('YES' if yes else 'NO')


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

int main() {
	int a; cin >> a;
	cout << a + a * a + a * a*a;
}

Measured memory_bytes: 3616
#include<iostream>
#include<vector>

using namespace std;

int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0){break;}
		vector<int> vec;
		int ave = 0;
		for (int i = 0; i < n; i++) {
			int a;
			cin >> a;
			ave += a;
			vec.push_back(a);
		}
		int m = 0;
		ave = ave / n;
		for (int a : vec) {
			if (a <= ave) {
				m++;
			}
		}
		
		cout << m<<endl;
	}
	return 0;
	
}


Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n ; cin >> n; int mx =0;
    map < string , int > m;
    for (int x=0;x<n;x++){
        string s; cin >> s;
        m[s]++;
        mx = max (m[s],mx);
    }
    for (auto it=m.begin();it!=m.end();it++){
        if (it->second==mx){
            cout << it->first<<endl;
        }
    }
}


Measured memory_bytes: 19180
#include<bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  c = 0;
  cin >> a >> b;
  string s = to_string(a) + to_string(b);
  for (int i = 1; i < 1100; i++) {
    if (stoi(s) == pow(i, 2)) c++;
  }
  if (c != 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main(void)
{
  int i,j;
  int l;
  cin >> i;
  j = i % 1000;
  if (j==0){cout << j << endl;}
  else{
  l = 1000 - j;
  cout << l <<endl;
  }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pf push_front
#define pb push_back
#define P pair<int,int>
#define Pll pair<ll,ll>

template<class T, size_t N> size_t countof(const T (&array)[N]) { return N; }
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

void mprint(auto *matrix,auto N){
	REP(i,N) cout<<matrix[i]<<(i!=N-1?' ':'\n');
	return;
}


const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+17; //(+1までok)
const long MOD =1e+9+7;
#define PI 3.14159265258979

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

inline int in(){int x; cin>>x; return x;}

int main(void){
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	
	int N,d[100002],D[100002];
	cin>>N;
	FOR(i,1,N+1) cin>>d[i];
	d[0]=D[0]=d[N+1]=0;
	FOR(i,1,N+2) D[i]=(D[i-1]+abs(d[i]-d[i-1]));
	
	FOR(i,1,N+1) print(D[i-1]+abs(d[i+1]-d[i-1])+(D[N+1]-D[i+1]));
	return 0;
}




Measured memory_bytes: 2048
import numpy

str1=input().split(' ')
N=int(str1[0])
K=int(str1[1])
str2=input().split(' ')
h=[0]*N
result=0
for i in range(N):
	h[i]=int(str2[i])

for i in range(N):
	if h[i]>=K:
		result+=1

print(result)

Measured memory_bytes: 20676
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func scanLine() []int {
	var s []int
	scanner.Scan()
	for _, v := range strings.Split(scanner.Text(), " ") {
		i, _ := strconv.Atoi(v)
		s = append(s, i)
	}
	return s
}
func main() {
	var n int
	fmt.Scan(&n)
	p := scanLine()

	var result int
	for i := range p {
		if i == 0 || i == n-1 {
			continue
		}
		if p[i-1] < p[i] && p[i] < p[i+1] || p[i+1] < p[i] && p[i] < p[i-1] {
			result++
		}
	}
	fmt.Println(result)
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

// べき剰余 (x^k) % n
int powMod(int x, int k, int m){
    if(k == 0) return 1;
    if(k % 2 == 0) return powMod(x*x % m, k/2, m);
    else return x*powMod(x, k-1, m) % m;
}

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// ここに処理を記述

    int N, P;
    string S;

    cin >> N >> P;
    cin >> S;

    reverse(S.begin(),S.end());

    ll ans = 0;
    if(P == 2 || P == 5){
        REP(i,S.size()){
            if((S[i] - '0') % P == 0){
                ans += S.size() - i;
            }
        }
    }
    else{
        map<int,ll> count;
        int prev_amari = 0;
        REP(i,S.size()){
            int temp = (prev_amari + ((S[i] - '0') * powMod(10,i,P)) % P) % P;
            count[temp]++;
            prev_amari = temp;
        }

        for(auto itr = count.begin(); itr != count.end(); itr++){
            ll temp = itr->second;
            if(itr->first == 0){
                ans += temp;
            }
            ans += temp*(temp-1)/2;
        }
    }

    cout << ans << "\n";

return 0;
}

Measured memory_bytes: 1044
def main():
    from math import sqrt, factorial
    from itertools import permutations

    N = int(input())
    XY = [None]*N
    for i in range(N):
        x, y = map(int, input().split())
        XY[i] = (x, y)

    D = {}
    for i in range(N):
        x0, y0 = XY[i]
        for j in range(N):
            x1, y1 = XY[j]
            d = sqrt((x0 - x1) ** 2 + (y0 - y1)**2)
            D[(i,j)] = d

    d = 0
    for p in permutations(range(N)):
        for i, j in zip(p, p[1:]):
            d += D[(i, j)]

    print(d/factorial(N))

main()


Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <utility>
#include <functional>
#include <queue>

typedef long long ll;

template<class A, class B, class C> struct triple { A first; B second; C third; triple(A, B, C); triple(); };
template<class A, class B, class C> triple<A, B, C>::triple(A a, B b, C c) { first = a; second = b; third = c; }
template<class A, class B, class C> triple<A, B, C>::triple() { }
template<class A, class B, class C> triple<A, B, C> make_triple(A a, B b, C c) { triple<A, B, C> t(a, b, c); return t; }
template<class A, class B, class C> bool operator<(triple<A, B, C> a, triple<A, B, C> b) { if (a.first != b.first) return a.first < b.first; if (a.second != b.second) return a.second < b.second; return a.third < b.third;}

using namespace std;

vector<ll> v;
vector<ll> pref;
vector<vector<ll>> dp;

ll get(int l, int r)
{
	if (l == r) return v[l];

	if (dp[l][r] == -1)
	{
		for (int i = l; i < r; ++i)
		{
			if (dp[l][r] == -1 || dp[l][r] > get(l, i) + get(i + 1, r))
				dp[l][r] = get(l, i) + get(i + 1, r);
		}

		dp[l][r] += pref[r];
		if (l) dp[l][r] -= pref[l - 1];
	}

	return dp[l][r];
}

void solve()
{
	int n; cin >> n;
	v.resize(n);
	for (int i = 0; i < n; ++i)
		cin >> v[i];
	pref = v;
	for (int i = 1; i < n; ++i)
		pref[i] += pref[i - 1];

	dp.resize(n, vector<ll>(n, -1));

	cout << get(0, n - 1) - pref.back();
}

int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
#else
#endif
	solve();
	return 0;
}

Measured memory_bytes: 1536
#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, K;
  cin >> N >> K;
  int digit = 0;
  while(N > 0){
    N /= K;
    digit ++;
  }
  cout << digit << endl;
  //return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<string>
#include<math.h>
using namespace std;

int main(void) {
	int X=0, date[1001] = { 0 },ans;
	cin >> X;
	for (int b = 1;b <= 33;b++) {
		for (int p = 2;p <= 100;p++) {
			if (pow(b, p) > 1000)
				break;
			else
				date[(int) (pow(b, p) )] = 1;
		}
	}

	for (ans = X;ans > 0;ans--) {
		if (date[ans] == 1)
			break;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#define INF 10000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;
using namespace std;

int main(){
	int n;
	cin >> n;
	int o[n][26] = { };
	REP(i, n){
		string s;
		cin >> s;
		REP(j, s.size()) o[i][(int)(s[j]-'a')]++;
	}
	REP(i, 26){
		int m = 1000;
		REP(j, n){
			m = min(m, o[j][i]);
		}
		REP(j, m) cout << (char)(i + 'a');
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;


public class Main {
	private	static	BufferedReader	br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String						stdin  = null;
		Integer						client = 0;
		boolean						prev   = false;
		HashMap<Integer, Integer>	cmonth = new HashMap<Integer, Integer>();
		HashMap<Integer, Integer>	pmonth = new HashMap<Integer, Integer>();
		ArrayList<int[]>			result = new ArrayList<int[]>();

		while ((stdin = parseStdin()) != null) {
			if (stdin.isEmpty()) {
				prev = true;
				continue;
			}

			client = Integer.parseInt(stdin.split(",")[0]);

			if (!prev) {
				if (!cmonth.containsKey(client)) {
					cmonth.put(client, 1);
				}
				else {
					cmonth.put(client, cmonth.get(client) + 1);
				}
			}
			else {
				if (!pmonth.containsKey(client)) {
					pmonth.put(client, 1);
				}
				else {
					pmonth.put(client, pmonth.get(client) + 1);
				}
			}
		}

		for (Object o : pmonth.keySet().toArray()) {
			if (cmonth.containsKey(o)) {
				int[]	item = {(Integer)o, (cmonth.get(o) + pmonth.get(o))};
				result.add(item);
			}
		}

		Collections.sort(result, new MyComparator());

		for (Object o : result.toArray()) {
			int[]	item = (int[])o;
			System.out.printf("%d %d\n", item[0], item[1]);
		}
	}

	private static String parseStdin() {
		String	stdin = null;

		try {
			stdin = br.readLine();
		}
		catch (IOException e) {}

		return stdin;
	}
}

class MyComparator implements Comparator<int[]> {

    /** ソート対象のカラムの位置 */
    public int compare( int[] a1, int[] a2 ) {
        return a1[0] - a2[0];
    }
}

Measured memory_bytes: 16940
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp(a,b) std::make_pair(a,b)
#define pb push_back
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::set<int> si;
typedef std::string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
str s;
int main(){
  cin>>s;
  int ss=s.size();
  int res=INF;
  rep(i,26){
    char c='a'+i;
    int cnt=0,max=0;
    rep(i,ss){
      if(s[i]==c){
	max=std::max(max,cnt);
	cnt=0;
      }
      else cnt++;
    }
    max=std::max(max,cnt);
    res=std::min(res,max);
  }
  prin(res);
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val ss = (1..n).map {
    readLine()!!
      .toList()
      .sorted()
      .joinToString(separator="")
  }.sorted()
  val count : MutableMap<String, Int> = java.util.HashMap<String, Int>()
  for (str in ss) {
    val k = count.getOrPut(str, { 0 })
    count[str] = k + 1
  }
  val ans = count.map{
    val t = it.value.toLong()
    t * (t - 1) / 2
  }.sum()
  println(ans)
}


Measured memory_bytes: 77524
s=int(input())
mod=10**9+7
def f(a,b):
    x, y, lastx, lasty = 0, 1, 1, 0
    while b != 0:
        q = a // b
        a, b = b, a % b
        x, y, lastx, lasty = lastx - q * x, lasty - q * y, x, y
    return (lastx, lasty)
n=10**6+100
fa=[1 for i in range(n)]
fi=[1 for i in range(n)]
fa[0]=0
for i in range(2,n):
    fa[i]=(fa[i-1]*i)%mod
    fi[i]=(f(fa[i],mod)[0])%mod
#print(fa[:5],fi[:6])

c=lambda n,c:(((fa[n]*fi[n-c])%mod)*fi[c])%mod

#print(c(5,2))

ans=0
for i in range(1,s//3+1):
    if i*3>s:
        continue
    ans=(ans+c(s-i*3+i-1,i-1))%mod
    #print(ans,i)
print((ans)%mod if s!=3 else 1)

Measured memory_bytes: 166896
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#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 UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double PI = (double)acos(-1);
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
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();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

int N;
vec h;

signed main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    h.pb(tmp);
  }

  int ans = 0;
  for (int k = 0; k < 110; k++) {
    bool flag = false;
    for (int i = 0; i < N; i++) {
      if (!flag) {
        if (h[i]) {
          flag = true;
          h[i]--;
          ans++;
        }
      } else {
        if (h[i] != 0) {
          h[i]--;
        } else {
          flag = false;
        }
      }
    }
  }

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


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

int main() {
  int team;
  int num;
  long long kekka = 0;
  cin >> team;
  
  num = team * 3;
  vector<long long> vec(num);
  for(int i = 0; i < num; i++) cin >> vec.at(i);
  
  sort(vec.begin(), vec.end(),greater<long long>());
  for(int i = 0; i < team; i++){
    kekka += vec.at(i * 2 + 1);
  }
  
  cout << kekka;
}


Measured memory_bytes: 2560
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

def rl():
    return list(map(int, input().split()))


def solve():
    A = rl()
    print (A.index(0) + 1)





mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()


Measured memory_bytes: 64928
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

int abs (int x) {
  if (x < 0) {
    x *= (-1);
  }
  return x;
}

int main() {
  int n;
  scanf("%d", &n);
  vi a(n+2, 0);
  FOR (i, 1, n+1) {
    scanf("%d", &a[i]);
  }
  int sum = 0;
  rep (i, n+1) {
    sum += (abs(a[i+1] - a[i]));
  }
  FOR (i, 1, n+1) {
    int orig = 0;
    orig += abs(a[i] - a[i-1]);
    orig += abs(a[i+1] - a[i]);
    int chg = abs(a[i+1] - a[i-1]);
    printf("%d\n", sum - orig + chg);
  }
  return 0;
}


Measured memory_bytes: 1664
#include <stdio.h>

int main(void){
    int N;
    scanf("%d",&N);

    switch(N%10){
        case 3:
            printf("bon\n");
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            printf("pon\n");
            break;
        default:
            printf("hon\n");
            break;
    }

    return 0;
}

Measured memory_bytes: 1624
import java.util.*;

class Main{
  static int repow(int b,int p){
    System.err.println(b+"^"+p);
    int res=1;
    int a=b;
    while(p>0){
      if((p&1)==1){
        res*=a;
      }
      a*=a;
      p/=2;
    }
    System.err.println("="+res);
    return res;
  }
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int[] a=new int[n];
    int gu=0;
    int ki=0;
    for(int i=0;i<n;i++){
      a[i]=sc.nextInt();
      if((a[i]&1)==0){
        gu++;
      }else{
        ki++;
      }
    }
    System.out.println(repow(3,n)-repow(2,gu));
    System.err.println(repow(3,n)+"-"+repow(2,gu));
  }
}

Measured memory_bytes: 21716
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int a;
    int b;

    if(k%2==0){
      a=k/2;
      b=k/2;
      System.out.println(a*b);
    }else{
      a=k/2;
      b=k/2+1;
      System.out.println(a*b);
    }
  }
}


Measured memory_bytes: 21588