akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

    map<int, int> a;
    int input;
    for (int i = 0; i < N; i++) {
        cin >> input;
        a[input]++;
    }

    int output = 0;
    int target, count;

    for (auto num : a) {
        target = num.first;
        count = num.second;
        if (target < count) {
            output += count - target;
        } else if (target > count) {
            output += count;
        }
    }

    cout << output << endl;

    return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    int ans = 1e8;
    for (int i = 1; i < n; ++i) {
        int a = i;
        int b = n - i;
        int keta_sum_a = 0;
        int keta_sum_b = 0;
        while(1) {
            if (a == 0) break;
            keta_sum_a += a % 10;
            a /= 10;
        }
        while(1) {
            if (b == 0) break;
            keta_sum_b += b % 10;
            b /= 10;
        }
        ans = min(ans, keta_sum_a + keta_sum_b);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define pb          push_back
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define endl        "\n"
#define fast        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int         long long int
#define mod         1000000007
#define test        int t;cin>>t;while(t--)
#define REP(i,a,b)  for(int i=a,i<=b;i++)
#define MAXN        200001

int32_t main()
{
	string str;
	cin>>str;

	int val=0;
	for(auto ch:str){
		val+=(ch-'0');
	}

	if(val%9==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3708
import sys
import os

MOD = 10 ** 9 + 7


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

    N = int(sys.stdin.buffer.readline().rstrip())
    print('AGC' if N >= 2800 else 'ARC' if N >= 1200 else 'ABC')


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpl_str(): return list(sys.stdin.readline().split())

N, M, K = inpl()
A = [0]
B = [0]
A += inpl()
B += inpl()
for i in range(N):
    A[i+1] += A[i]
for i in range(M):
    B[i+1] += B[i]
ans = 0
j = 0
for i in range(N, -1, -1):
    while (j <= M) and (A[i] + B[j] <= K):
        ans = max(ans, i+j)
        j += 1
print(ans)

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

int main() {
    int ans=-1;
    int x,y;
    cin>>x>>y;
    if(y>=x*2&&y<=x*4&&(y%2==0||y%4==0))
    {
      cout<<"Yes"<<endl;
    }
    else
    {
      cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3632
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  if(n < 105)System.out.println("0");
  else if(n <135)System.out.println("1");
  else if(n <165)System.out.println("2");
  else if(n <189)System.out.println("3");
  else if(n <195)System.out.println("4");
  else System.out.println("5");
}}

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

int main() {
    int N;
    cin >> N;
    vector<int> T(N);
    for (int i = 0; i < N; i++)
        T[i] = i;
    vector<double> X(N), Y(N);
    for (int i = 0; i < N; i++)
        cin >> X[i] >> Y[i];

    double sum = 0;
    do {
        double s = 0;
        for (int i = 1; i < N; i++) {
            s += sqrt(pow(X[T[i - 1]] - X[T[i]], 2.0) + pow(Y[T[i - 1]] - Y[T[i]], 2.0));
        }
        sum += s;
    } while (next_permutation(T.begin(), T.end()));

    double fact = 1;
    for (int i = 1; i <= N; i++)
        fact *= i;

    printf("%.10f\n", sum / fact);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
   char s[3] ;
   int i , a=0 , b=0 , c=0 ;

   scanf("%s",s);

   if((s[0]!=s[1])&&(s[1]!=s[2])&&(s[2]!=s[0]))
      printf("Yes\n");
   else
      printf("No\n");

   return 0 ;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(void){
	int A,B,C,D,N;
	int CD;
	char S[200001];
	int ia,ib;
	int i;
	int flag=0;
	scanf("%d %d %d %d %d",&N,&A,&B,&C,&D);
	scanf("%s",&S[1]);

	
	if(C<B){
		for(i=A;i<C-1;i++){
			if(S[i+1]=='#' && S[i+2]=='#'){
				printf("No");
				return 0;
			}
		}
		for(i=B;i<D-1;i++){
			if(S[i+1]=='#' && S[i+2]=='#'){
				printf("No");
				return 0;
			}
		}
		printf("Yes");
		return 0;
	}else if(C<D){//B<C<D
		for(i=B;i<D-1;i++){
			if(S[i+1]=='#' && S[i+2]=='#'){
				printf("No");
				return 0;
			}
		}
		for(i=A;i<C-1;i++){
			if(S[i+1]=='#' && S[i+2]=='#'){
				printf("No");
				return 0;
			}
		}
		printf("Yes");
		return 0;
		
		
	}else{// if (D<C)
		for(i=A;i<C-1;i++){
			if(S[i+1]=='#' && S[i+2]=='#'){
				printf("No");
				return 0;
			}
		}
		for(i=B;i<=D;i++){
			if(S[i-1]=='.' && S[i]=='.' && S[i+1]=='.'){
				flag =1;
				break;
			}
		}

		if(flag==0){
			printf("No");
			return 0;
		}
		
		for(i=B;i<D-1;i++){
			if(S[i+1]=='#' && S[i+2]=='#'){
				printf("No");
				return 0;
			}
		}
		printf("Yes");
		return 0;
		
		
	}
}


Measured memory_bytes: 384
import java.util.Scanner;

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

        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H == 0 && W == 0){
                break;
            }
            for(int i = 0; i < H; i++){
                for(int j = 0; j < W; j++){
                    System.out.print("#");
                }
                System.out.println("");  
            }
            System.out.println("");
        }
    }
}


Measured memory_bytes: 34848
#!/usr/bin/env python3
import sys
import numpy as np

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, A: "List[int]", B: "List[int]"):
                    # time          #lim

    tasks = [(b, a) for a,b in zip(A,B)]
    tasks = sorted(tasks)
    times = [time for lim, time in tasks]
    lims = [lim for lim, time in tasks]

    c = np.cumsum(times)
    if (c <= lims).all() :
        print(YES)
    else:
        print(NO)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 47080
using System;

class main
{
    public static int Main()
    {
        string xx=Console.ReadLine();
        string[] xxx = xx.Split(' ');
        int a = int.Parse(xxx[0]);
        int b = int.Parse(xxx[1]);
        int menseki = a * b;
        int syu = a * 2 + b * 2;
        Console.WriteLine(menseki + " " + syu);
        return 0 ;
    }
}

Measured memory_bytes: 9180
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <functional>
using namespace std;
typedef long long ll;

int main(){
  int X,Y;
  cin >> X >> Y;
  int ans = 0;

  if(X == 3)ans += 100000;
  if(X == 2)ans += 200000;
  if(X == 1)ans += 300000;

  if(Y == 3)ans += 100000;
  if(Y == 2)ans += 200000;
  if(Y == 1)ans += 300000;

  if(X == 1 && Y == 1)ans += 400000;

  cout << ans << endl;


}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    String c = sc.next();

    if (c.equals("Sunny")) {
      System.out.println("Cloudy");
    } else if (c.equals("Cloudy")) {
      System.out.println("Rainy");
    } else {
      System.out.println("Sunny");
    }
  }
}


Measured memory_bytes: 35204
N = int(input())
a = list(map(int, input().split()))
box = [0 for _ in range(N + 1)]
ans = []
for i in range(1, N + 1)[:: -1]:
    k = 1
    my_sum = 0
    while i * k <= N: 
        my_sum += box[i * k]
        k += 1
    if my_sum % 2 != a[i - 1]:
        box[i] = 1
        ans.append(i)
if len(ans) > 0:
    print(len(ans))
    print(" ".join(map(str, ans)))
else:
    print(0)

Measured memory_bytes: 19896
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    string s;
    cin >> s;
    ll ans = 0;
    ll che  =0;
    for(int i=0;i<s.size();i++){
        if(s.at(i)=='R')che++;
        else {
            ans=max(che,ans);
            che=0;
        }
    }
    ans = max(che,ans);
    cout<<ans<<endl;
}
    



Measured memory_bytes: 3616
H, W = map(int, raw_input().split())
# print(H, W)

slist = []
slist.append(["." for j in range(W+2)] )
for i in range(H):
    l = [j for j in raw_input()]
    l.insert(0, ".")
    l.append(".")
    slist.append(l)
slist.append(["." for j in range(W+2)])
# for s in slist:
#     print(s)

for i in range(1, H):
    for j in range(1, W):
        if slist[i][j] == "#":
            if slist[i+1][j] == "." and slist[i][j+1] == "." and \
               slist[i-1][j] == "." and slist[i][j-1] == ".":
                print("No")
                exit(0)
print("Yes")


Measured memory_bytes: 2692
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(br.readLine());

        int result = n;
        int soinshi = 2;

        if (n % soinshi == 0) {
            result /= soinshi;
            do {
                n /= soinshi;
            } while (n % soinshi == 0);
        }

        soinshi = 3;
        while (soinshi <= (n / soinshi)) {
            if (n % soinshi == 0) {
                result = result / soinshi * (soinshi - 1);
                do {
                    n /= soinshi;
                } while (n % soinshi == 0);
            }
            soinshi += 2;
        }

        if (n > 1) {
            result = result / n * (n - 1) ;
        }

        System.out.println(result);
    }
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)

#define SORT(c) sort((c).begin(),(c).end())
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define N 100

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

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

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int M[N][N];
int n, tt, d[N], f[N];
int color[N]; //-1:unvisited, 0:visited, 1:finished
int nt[N];

#define WHITE 0
#define GRAY 1
#define BLACK 2


int next(int u){
  FOR(v, nt[u], n){
    nt[u]=v+1;
    if (M[u][v]) return v; // where v is first next_to_u
  }
  return -1;
}


void dfs_visit(int r){
  REP0(i,n) nt[i]=0;

  stack<int> S;
  S.push(r);
  color[r] = GRAY;
  d[r] = ++tt;

  while (!S.empty()) {
    int u=S.top();
    int v=next(u);
    if (v!=-1) {
      if (color[v]==WHITE) {
        color[v]=GRAY;
        d[v]=++tt;
        S.push(v);  //次のループで取り出されるu
      }
    }else{ //隣接未探索なし
      S.pop();
      color[u]=BLACK;
      f[u]=++tt;
    }
  }

}


void dfs(){
  REP0(i,n){
    color[i]=WHITE;
    nt[i]=0;
  }
  tt=0;
  REP0(i,n) if (color[i]==WHITE) dfs_visit(i);
  REP0(i,n) std::cout << i+1 << " " << d[i] << " " << f[i] << '\n';
}


void input(int n){
  int v1, v2, d;
  REP0(i,n) { REP0(j,n) M[i][j]=0; }
  REP0(i,n){
    std::cin >> v1 >> d;
    color[v1-1]=-1;
    REP0(j,d){
      std::cin >> v2; M[v1-1][v2-1]=1;
    }
  }
}


int main(int argc, char const *argv[]) {
  cin.tie(0); ios::sync_with_stdio(false);
  std::cin >> n;
  input(n);
  dfs();
  return 0;
}



Measured memory_bytes: 3220
using System;

namespace E
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(solver());
        }
        static long solver()
        {
            var N = long.Parse(Console.ReadLine());
            if ((N % 2) == 1) return 0;
            var result = 0L;
            var temp2 = 10L;
            result += N / 10;
            for (int i = 1; i <= 36; i++)
            {
                temp2 *= 5;
                result += N / temp2;
            }
            return result;
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char* argv[]) {
  int H, W;
  cin >> H >> W;

  char s[H][W];
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cin >> s[i][j];
    }
  }

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (s[i][j] == '.')
        continue;
      bool is_okay = false;
      for (int m = -1; m < 2; ++m) {
        for (int n = -1; n < 2; ++n) {
          if ((m == 0 && n == 0) || (abs(n) == 1 && abs(m) == 1))
            continue;
          if ((i + m >= 0 && i + m < H) && (j + n >= 0 && j + n < W)) {
            if (s[i + m][j + n] == '#') {
              is_okay = true;
              break;
            }
          }
        }
        if (is_okay)
          break;
      }
      if (!is_okay) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 256
N,A,B=map(int,input().split())
h=[]
hmax=0
for i in range(N):
    i=int(input())
    hmax=max(hmax,i)
    h.append(i)

def check(t):
    l=[]
    for i in h:
        i-=t*B
        if i > 0:
            l.append(i)
    if len(l) != 0:
        while t>=0:
            i=l.pop()
            t-=-(-i//(A-B))
            if (len(l)==0) and (t>=0):
                return True
        return False
    else:
        return True

min=0
max=hmax
while max != min + 1:
    j=(max-min)//2+min
    if check(j) == True:
        max = j
    else:
        min = j
print(max)


Measured memory_bytes: 119256
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

#define int long long
//region TEMPLATE
////@formatter:off
#define double long double
typedef long long ll;
typedef unsigned long long ull;
template<typename T>void __read(T &a) { cin >> a; }
template<typename T, typename ... Args> void __read(T &a, Args &... args) { cin >> a;__read(args...);}
#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i];
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T> void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
auto __fast_io__ = (ios_base::sync_with_stdio(false), cin.tie(nullptr)); // NOLINT(cert-err58-cpp,cppcoreguidelines-interfaces-global-init)
////@formatter:on
//endregion


int32_t main() {
    make(int, n, m, x);
    VVI a(n, VI(m));
    VI c(n);
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
        for (int j = 0; j < m; ++j) {
            cin >> a[i][j];
        }
    }
    int ans = INT_MAX;
    for (int mask = 1; mask < (1 << n); ++mask) {
        int tans = 0;
        VI sm(m);
        for (int i = 0; i < n; ++i) {
            if ((mask >> i) & 1) {
                tans += c[i];
                for(int j = 0 ; j < m; ++j){
                    sm[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        for(int j = 0; ok && j < m; ++j){
            ok = sm[j] >= x;
        }
        if (ok){
            ans = min(ans, tans);
        }

    }
    if (ans == INT_MAX) ans = -1;
    cout << ans;
    return 0;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
const int N=105;
const double eps=1e-8;
double sum,Min=100;
int n,a[N],pos;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]),sum+=a[i];
	sum=(double)sum/n;
	for (int i=1;i<=n;i++)
	  if (Min-fabs(a[i]-sum)>eps) Min=fabs(a[i]-sum),pos=i;
	printf("%d\n",pos-1);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <climits>
#include <math.h>
 
using namespace std;
typedef unsigned long ul;
typedef pair<long, int> P;

int main() {
	int v[50];
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++) {
		cin>>v[i];
	}

	int maxValue = 0;
	int m = min(n,k);
	for(int left=0;left<=m;left++) {
		for(int right=0;right<=m-left;right++) {
			int value = 0;
			priority_queue<int, vector<int>, greater<int> > que;
			for(int i=0;i<left;i++) { que.push(v[i]); value += v[i]; }
			for(int i=0;i<right;i++) { que.push(v[n-1-i]); value += v[n-1-i]; }
			for(int i=0;i<k-left-right&&!que.empty()&&que.top()<0;i++) { value -= que.top(); que.pop(); }
			maxValue = max(maxValue, value);
		}
	}
	cout<<maxValue<<endl;
}

Measured memory_bytes: 256
n = int(input())
s = input()

ok, ng = 0, n//2+1
while ng-ok > 1:
	x = (ok+ng)//2
	possible = False
	d = set()
	for i in range(n-2*x+1):
		d.add(hash(s[i:i+x]))
		if hash(s[i+x:i+2*x]) in d:
			possible = True
			break
	if possible:
		ok = x
	else:
		ng = x
print(ok)

Measured memory_bytes: 3376
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n, k;
	cin >> n >> k;
	ll ans = 0;
	REP(i, n-1) {
		ans += (ans/(k-1))+1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3068
#include<iostream>
#include<vector>
#include<iomanip>
#include<cmath>
#include<algorithm>

using namespace std;
using P = pair<double, pair<int, int> >;

double p[200][3];
double v[200][3];
double r[200];
double rv[200];
double life[200];
bool die[200];
double tdie[200];

int n;

double coll_time(int i, int j) {
    double R = r[i] + r[j];
    double RV = rv[i] + rv[j];
    double ce2 = - RV * RV;
    double ce1 = 2 * R * RV;
    double ce0 = - R * R;

    for (int k = 0; k < 3; ++k) {
        double P = p[i][k] - p[j][k];
        double V = v[i][k] - v[j][k];
        ce2 += V * V;
        ce1 += 2 * P * V;
        ce0 += P * P;
    }

    double ans;
    if (ce2 != 0) {
        double D = ce1 * ce1 - 4 * ce0 * ce2;
        if (D < 0) return -1;
        ans = (- ce1 - sqrt(D)) / (2 * ce2);
    } else {
        ans = - ce0 / ce1;
    }
    if (ans < 0) return -1;
    return ans;
}

void solve() {
    vector<P> death;
    for (int i = 0; i < n; ++i) {
        cin >> p[i][0] >> p[i][1] >> p[i][2] >> v[i][0] >> v[i][1] >> v[i][2] >> r[i] >> rv[i];
        life[i] = r[i] / rv[i];
        death.push_back(make_pair(life[i], make_pair(i, -1)));
        die[i] = false;
    }

    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            double collt = coll_time(i, j);
            if (collt < 0) continue;
            death.push_back(make_pair(collt, make_pair(i, j)));
        }
    }

    sort(death.begin(), death.end());

    int cnt = 0;
    for (P d : death) {
        double t = d.first;
        int i = d.second.first;
        int j = d.second.second;

        //cout << t << ", " << i << ", " << j << endl;
        if (j == -1 && !die[i]) {
            die[i] = true;
            tdie[i] = t;
            cnt++;
        } else if (j != -1 && !die[i] && !die[j]) {
            die[i] = true;
            die[j] = true;
            tdie[i] = t;
            tdie[j] = t;
            cnt += 2;
        }
        if (cnt >= n) break;
    }

    for (int i = 0; i < n; ++i) {
        cout << fixed << setprecision(10) << tdie[i] << endl;
    }
}

int main() {
    while (cin >> n) {
        if (n == 0) return 0;
        //cout << "=============" << endl;
        solve();
    }
}



Measured memory_bytes: 3792
#include<bits/stdc++.h>
typedef long long ll;
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;
void fast()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
int main()
{
    fast();
    ll n,temp,c,i=0;
    char a,b[20];
    cin>>n;
    while(n>26)
    {
       if(n%26)
       {
           temp=n/26;
         c=n-temp*26;
         n=temp;
       }
       else
       {
           c=26;
           n=(n/26)-1;
       }
       b[i++]='a'+(c-1);
    }
    b[i++]='a'+(n-1);
    while(i--)
    {
        cout<<b[i];
    }
    return 0;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}

ll dp[2020][2020];
ll sum[2020][2020];
int main(void) {
  ll N, M;
  cin >> N >> M;
  ll s[2020], t[2020];
  ll i, j;
  
  for(i=0; i<N; i++) cin >> s[i];
  for(i=0; i<M; i++) cin >> t[i];
  
  for(i=0; i<=N; i++) dp[i][0]=1;
  for(j=0; j<=M; j++) dp[0][j]=1;
  
  for(i=0; i<N; i++) {
    for(j=0; j<M; j++) {
      if(s[i]==t[j])
        moC(dp[i+1][j+1], +, dp[i+1][j]+dp[i][j+1]);
      else
        moC(dp[i+1][j+1], +, dp[i+1][j]+dp[i][j+1]-dp[i][j]);
    }
  }
  
  pt(dp[N][M]);
  
}







Measured memory_bytes: 33024
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
long long int __lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
 //__gcd 最大公約数
 //__lcm 最小公倍数

int main() {
  int a;
  cin>>a;
  vector<int> b(a);
  for(int i=0;i<a;i++)
    cin>>b[i];
  int c=0,d=0,e=100000001;
  for(int i=0;i<a;i++)
    c+=b[i];
  for(int i=0;i<a;i++){
    d+=b[i];
    e=min(e,max(c-2*d,2*d-c));
    }
  cout<<e;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < n; i++)
typedef long long ll;
// Welcome to my source code!

int F[45] = {};

int fibonacci(int n) {
    if (n == 0 || n == 1) return F[n] = 1;
    if (F[n]) return F[n];
    return F[n] = fibonacci(n-2) + fibonacci(n-1); 
}

int main() {
    int n;
    cin >> n;
    cout << fibonacci(n) << endl;
}


Measured memory_bytes: 3120
N = int(input())
S = input()
A = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
Y = []

for s in S:
    ix = ( A.index(s) + N ) % 26 
    Y.append(A[ix])

print(''.join(Y))


Measured memory_bytes: 3060
package main

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

func main() {
	a := getStdinInt()
	fmt.Printf("%d\n", a+a*a+a*a*a)
}

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, _ := sc.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 1808
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000

int MOD=1000000007;
int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}
////////////////////////////////////////////////////////////

signed main() {
  string a,b,c;
  cin>>a>>b>>c;
  int as=0,bs=0,cs=0;
  int next=0;
  while(true){
    char ch;
    if(next==0){ch=a[as];as++;}
    else if(next==1){ch=b[bs];bs++;}
    else if(next==2){ch=c[cs];cs++;}
    if(as==a.size()&&ch=='a'){cout<<'A'<<endl;exit(0);}
    if(bs==b.size()&&ch=='b'){cout<<'B'<<endl;exit(0);}
    if(cs==c.size()&&ch=='c'){cout<<'C'<<endl;exit(0);}
    if(ch=='a')next=0;
    if(ch=='b')next=1;
    if(ch=='c')next=2;
  }
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define f(i,x,y) for(int i=x; i<=y; ++i)
#define fn(i,x,y) for(int i=x; i>=y; --i)
#define ll long long
#define pi acos(-1)
#define first F
#define second S
using namespace std;
int n;
string s;
ll ans=1, dem[200];
int main()
{
     ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
     cin >> n >> s;
     f(i,0,n-1) dem[s[i]]++;
     f(i,'a','z') if(dem[i]!=0) ans=(ans*(dem[i]+1))%1000000007;
     cout << ans-1;
     return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
const int maxn = 2e5 + 5;
const int mod = 998244353;
int n , p[maxn];
ii a[maxn];
int res = 0 , oy[maxn];
int bit[maxn];
void update(int x){
	for( ; x <= n ; x += x & -x)bit[x]++;
}
int query(int x){
	int res = 0;
	for( ; x > 0 ; x &= x - 1)res += bit[x];
	return res;
}
void add(int & x , ll y){
	if(y >= mod)y %= mod;
	x += y;
	if(x >= mod)x -= mod;
	if(x < 0)x += mod;
}
void Solve(){
	sort(a + 1 , a + n + 1);
	for(int i = 1 ; i <= n ; ++i)oy[i] = a[i].second;
	sort(oy + 1 , oy + n + 1);
	for(int i = 1 ; i <= n ; ++i){
		int y = lower_bound(oy + 1 , oy + n + 1 , a[i].second) - oy;
		add(res , p[query(y)]);
		add(res , p[i - query(y) - 1]);
		add(res , -p[i]);
		add(res , -p[n - i + 1]);
		update(y);
	}
	fill_n(bit,maxn,0);
	for(int i = n ; i >= 1 ; --i){
		int y = (lower_bound(oy + 1 , oy + n + 1 , a[i].second) - oy);
		add(res , p[query(y)]);
		add(res , p[n - i - query(y)]);
		update(y);
	}
	fill_n(bit,maxn,0);
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);	
	cin >> n;
	p[0] = 1;
	for(int i = 1 ; i <= n ; ++i)p[i] = p[i - 1] * 2 % mod;
	for(int i = 1 ; i <= n ; ++i){
		cin >> a[i].first >> a[i].second;
	}
	add(res , (ll)n * p[n]);
	add(res , -n);
	Solve();
	cout << res; 
    return 0;
}

Measured memory_bytes: 4224
import numpy as np

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

array = np.zeros([n,m])
for k1, i in enumerate(lst):
    for k2, j in enumerate(i):
        array[k1][j-1] += 1

print(sum(array.sum(axis=0)==n))

Measured memory_bytes: 21304
from numpy import*
M=10**9+7
m=lambda:map(int,input().split())
n,k=m()
b=eye(n,n,0,'O')
a=matrix([list(m())for i in b],'O')
while k:b=[b,b*a][k&1];a=a*a%M;k>>=1
print(sum(b)%M)

Measured memory_bytes: 14692
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    string s; cin>>s;
    int N=s.size();
    vint v;
    for(int i=0;i<N;){
        int j=i;
        while(j<N and s[j]==s[i]) j++;
        v.push_back(j-i);
        i=j;
    }

    REP(i,5) v.push_back(0);

    int ans=0;
    REP(i,v.size()-1){
        if(v[i]<=v[i+1]){
            ans+=v[i]*2;
            v[i+1]-=v[i];
            v[i]=0;
        }
        else{
            ans+=v[i+1]*2;
            v[i+2]+=v[i]-v[i+1];
            v[i]=v[i+1]=0;
        }
    }
    cout<<ans<<endl;
 
}


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

int main() 
{
   int N, K;
   string S;
   cin >> N >> S >> K;

   char KS = S.at(K - 1);
   for (int i = 0; i < N; i++)
   {
      if (S.at(i) != KS)
         S.at(i) = '*';
   }
   cout << S << endl;
}


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

// 構造体
struct work {
  int A;
  int B;
};

// 比較関数
bool cmp (const work &a, const work &b) {
  if (a.B < b.B) {
    return true;
  }
  if (a.B > b.B) {
    return false;
  }
  if (a.A < b.A) {
    return true;
  }
  if (a.A > b.A) {
    return false;
  }
  return false;
}

int main() {

  int N;
  cin >> N;

  vector<work> W;
  for (int i = 0; i < N; i++) {
    int A_, B_;
    cin >> A_ >> B_;
    work w_ = work {A_, B_};
    W.push_back(w_);
  }

  // 比較関数で並び替え
  sort(W.begin(), W.end(), cmp);

  string answer = "Yes";
  int current = 0;
  int free = 0;
  for (int i = 0; i < N; i++) {
    current += W[i].A;
    if (W[i].B < current) {
      answer = "No";
      break;
    } else {
      free = W[i].B - current;
      if (free < 0) {
        answer = "No";
        break;
      }
    }
  }

  cout << answer << endl;

  return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    bool flag = 0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(a[i]%2!=0){
            flag = 1;
        }
    }
    if(flag){
        cout << "first" << endl;
    }else{
        cout << "second" << endl;
    }
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<string> W(N);
  for (int i=0 ; i<N ; i++) {
    cin >> W.at(i);
  }
  
  int judge1 = N;
  
  for (int i=0; i<N; i++) {
    for (int j=0; j<N; j++) {
      if ( W.at(i) == W.at(j) ) {
        judge1 = judge1 - 1;
      }
    }
  }
  
  int judge2 = N-1;
  
  for (int i=0; i<N-1; i++) {
    if (W.at(i).at(W.at(i).size()-1) == W.at(i+1).at(0)) {
     judge2 = judge2 - 1; 
    }
  }
  
  if (judge1 == 0 && judge2 == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
    
}
  
  
  

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

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

// 無限大の値
const ll  lINF = 1LL << 60;
const int iINF = 1 << 29;

int main(void){
  int k,s;
  cin >> k >> s;
  
  int ans = 0;
  for(int i=0; i<=min(k,s); i++){
    for(int j=0; j<=min(k,s-i); j++){
      if(k>=s-(i+j)) ans++;
    }
  }

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

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

//SegmentTree↓
int dat[2*N], n;
void init(){
    rep(i,2*N)dat[i]=0;
}
void add(int pos, int val) {
    for(dat[pos+=n] += val;pos > 1; pos>>=1) {
        dat[pos>>1] = dat[pos] + dat[pos^1];
    }
}

//void add(int i,int x){
  //  for(;i<N;i+=i&-i)dat[i]+=x;
//}

int rangesum(int l, int r) {
    r++;
    int ans = 0;
    l+=n, r+=n;
    while(l < r) {
        if(l&1) ans += dat[l++];
        if(r&1) ans += dat[--r];
        l>>=1, r>>=1;
    }
    return ans;
}

int sum(int i){
    int res=0;
    for(;i>0;i-=i&-i)res+=dat[i];
    return res;
}
//int rangesum(int l,int r){//[l,r]
  //  return sum(r)-sum(l-1);
//}
//SegmentTree↑

int a[N];
vector<int> ql[N],qid[N];
int ans[N];

int q,c[N];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin>>n>>q;
    for(int i=1;i<=n;i++)cin>>c[i];
    rep(i,q){
        int l,r;
        cin>>l>>r;
        ql[r].push_back(l);
        qid[r].push_back(i);
    }
    init();
    for(int i=1;i<=n;i++)a[i]=0;
    for(int i=1;i<=n;i++){
        if(a[c[i]]>0)add(a[c[i]],-1);
        add(i,+1);
        a[c[i]]=i;
        rep(j,ql[i].size()){
            ans[qid[i][j]]=rangesum(ql[i][j],i);
        }
    }
    rep(i,q)cout<<ans[i]<<"\n";
}


Measured memory_bytes: 54964
/*
	Auth: Loxilante
	Time: 2020/09/19
	Prog: ABC179D
	Lang: cpp
*/
#ifdef ONLINE_JUDGE
#pragma GCC optimize("O3")
#endif
#include <bits/extc++.h>
#define rep(i, l, r) for(int i = l; i < r; i++)
#define hrp(i, l, r) for(int i = l; i <= r; i++)
#define rev(i, r, l) for(int i = r; i >= l; i--)
#define ms(n, t) memset(n, t, sizeof(n))
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...) 97
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn = int> inline tn next(void) { tn k; cin>>k; return k; }
int n,k,dp[22222222], seg1[15], seg2[15];
const int MOD = 998244353;
int lowbit(int k)
{
    return k & -k;
}
void add(int x,int k)
{
    while(x<=n)
    {
        dp[x]+=k;
        dp[x]%=MOD;
        x+=lowbit(x);
    }
}
int su(int x)
{
    int ans=0;
    while(x!=0)
    {
        ans+=dp[x];
        ans%=MOD;
        x-=lowbit(x);
    }
    return ans;
}
int sum(int a, int b)
{
	return ((su(b) - su(a-1))+2*MOD)%MOD;
}
signed main(void)
{
	cin>>n>>k;
	rep(i, 0, k) cin>>seg1[i]>>seg2[i];

	add(1, 1);
	hrp(i, 1, n) rep(j, 0, k)
	{
		int t = i-seg1[j], tt = i-seg2[j];
		if (t <= 0) continue;
		if (tt <= 0) tt = 1;

		add(i, sum(tt, t));
		// hrp(T, 1, n) cout<<dp[T]<<" \n"[T == n];
	}
	
	cout<<sum(n, n)<<endl;

	return 0;
}

Measured memory_bytes: 5208
#include<iostream>
#include<numeric>
#include<math.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<climits>
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define mkp make_pair
#define pll pair<ll,ll>
#define rep(i,from,to) for(int i=from;i<to;i++)
#define repd(i,from,till) for(int i=from;i>=till;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define mod 1e9+7
#define inf1 1e18+1
#define pie 3.14159265358979323846
#define N 100005
using namespace std;
/*
ll bin(ll i,ll j){
	ll mid=(i+j)/2;
	if(a[mid]==x)reutrn mid;
	else if(ans>x)return bin(i,mid-1);
	else return bin(mid+1,j);
}/*
ll power(ll base,ll power){
    ll res=1;
    base=base%mod;
    while(power>0){
    	if(power&1){
    		res=(res*base)%mod;
		}
		power=power>>1;
		base=(base*base)%mod;
	}
	return res;
}
*/
/*
int nCr(int x, int y){
	if(y>x)return 0;
	int num=fact[x];
	num*=invfact[y];
	num%=mod;
	num*=invfact[x-y];
	num%=mod;
	return num;
}
*/
/*bool prime[n+1];
void SieveOfEratosthenes(int n){
	rep(i,0,n+1)prime[i]=true
    for (int p=2;p*p<=n;p++)
        if (prime[p])
            for (int i=p*p;i<=n;i+=p)prime[i]=false;
}*/
/*
int gcd(int a,int b){
	if(b==0)return a;
	else return gcd(b,a%b);
}
*/
int solve(){
	double a,b,h,m;
	cin>>a>>b>>h>>m;
	double degh=h*30.0+(m/2.0);
	double degm=m*6.0;
	double deg=degh-degm;
	double ans=a*a+b*b-2.0*a*b*(cos(deg*pie/180));
	ans=sqrt(ans);
	cout<<fixed<<setprecision(10)<<ans<<endl;
	return 0;
}
int main(){
    waste;
    int t;
    //cin>>t;
    t=1;
    while(t--){
       	solve();
    }
}


Measured memory_bytes: 4244
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main() {
    int n;
    int times[101]={};

    while(cin>>n){
        if(n==0)break;
        times[n]++;
    }
    int maxi=-1;
    rep(i,100+1){
        maxi=max(maxi,times[i]);
    }
    rep(i,100+1){
        if(times[i]==maxi){
            cout<<i<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1160
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 1000 * 100 + 47;
struct Item
{
	int a, b, c;
	bool operator <(const Item& x) const
	{
		return b - c < x.b - x.c;
	}
};

Item A[MAX];
LL P[MAX];
LL S[MAX];
multiset<LL> SS;

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int x, y, z;
	cin >> x >> y >> z;
	int n = x + y + z;
	FOR(i, 0, n) cin >> A[i].a >> A[i].b >> A[i].c;
	
	sort(A, A + n);
	LL cur = 0;
	FOR(i, 0, n)
	{
		SS.insert(A[i].c - A[i].a);
		cur += A[i].c - A[i].a;
		if (SZ(SS) > z)
		{
			cur -= *SS.begin();
			SS.erase(SS.begin());
		}

		if (SZ(SS) != z)
		{
			P[i] = -LINF;
			continue;
		}

		P[i] = cur;
	}

	cur = 0;
	SS.clear();
	RFOR(i, n, 0)
	{
		SS.insert(A[i].b - A[i].a);
		cur += A[i].b - A[i].a;
		if (SZ(SS) > y)
		{
			cur -= *SS.begin();
			SS.erase(SS.begin());
		}

		if (SZ(SS) != y)
		{
			S[i] = -LINF;
			continue;
		}

		S[i] = cur;
	}

	LL ans = -LINF;
	LL s = 0;
	FOR(i, 0, n) s += A[i].a;

	FOR(i, 0, n - 1)
	{
		if (P[i] == -LINF || S[i + 1] == -LINF) continue;

		ans = max(ans, s + P[i] + S[i + 1]);
	}

	cout << ans << endl;
}


Measured memory_bytes: 7424
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003LL;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

#include <atcoder/maxflow>

// Main
int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<char>> grid(n, vector<char>(m));
    rep(i, n) rep(j, m) cin >> grid[i][j];
    
    atcoder::mf_graph<int> g(n * m + 2);
    const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
    int s = n * m, t = n * m + 1;
    rep(i, n) rep(j, m) {
        if (grid[i][j] == '#') continue;
        if ((i + j) & 1) {
            g.add_edge(s, i * m + j, 1);
            rep(k, 4) {
                if (i + dx[k] < 0 || i + dx[k] >= n || j + dy[k] < 0 || j + dy[k] >= m) continue;
                if (grid[i + dx[k]][j + dy[k]] == '#') continue;
                g.add_edge(i * m + j, (i + dx[k]) * m + (j + dy[k]), 1);
            }
        } else {
            g.add_edge(i * m + j, t, 1);
        }
    }
    
    cout << g.flow(s, t) << "\n";
    
    auto edges = g.edges();
    for (auto &e : edges) {
        if (e.from == s || e.to == t || e.flow == 0) continue;
        int i0 = e.from / m, j0 = e.from % m, i1 = e.to / m, j1 = e.to % m;
        if (i0 + 1 == i1) {
            grid[i0][j0] = 'v';
            grid[i1][j1] = '^';
        }
        if (i0 - 1 == i1) {
            grid[i0][j0] = '^';
            grid[i1][j1] = 'v';
        }
        if (j0 + 1 == j1) {
            grid[i0][j0] = '>';
            grid[i1][j1] = '<';
        }
        if (j0 - 1 == j1) {
            grid[i0][j0] = '<';
            grid[i1][j1] = '>';
        }
    }
    
    rep(i, n) {
        rep(j, m) cout << grid[i][j];
        cout << "\n";
    }
    return 0;
}


Measured memory_bytes: 5656
#include <algorithm>
    #include <iostream>
    #include <string>
    using namespace std;
     
    int main() {
    	string s,t;
    	cin >> s;
    	sort(s.begin(), s.end());    	
    	cin >> t;
    	sort(t.rbegin(), t.rend());    	
    	if (s < t)
          cout << "Yes" << endl;
    	else
          cout << "No" << endl;
    }

Measured memory_bytes: 256
//hinagata.cpp
/*includes*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <numeric>
#include <iomanip>
#include <limits>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPi(i,a,b) for(int i=(a);i<(b);i++)
#define REPRi(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

int main(){
    int N,M;
    cin>>N>>M;
    vector<int> X(M);
    REP(i,M)cin>>X[i];
    sort(ALL(X));
    vector<int> L(M-1);
    REP(i,M-1)L[i]=X[i+1]-X[i];
    sort(ALL(L));
    int sum=0;
    if(N>=M){
        cout<<0<<endl;
    }else{
        REP(i,M-N){
            sum+=L[i];
        }
        cout<<sum<<endl;
    }
}

Measured memory_bytes: 1024
def minimumStoolHeight(A):
    stool_tot = 0
    height_min = 0
    
    if len(A) == 1:
        return 0
    
    height_min = A[0]
    for i in range(1, len(A)):
        if A[i] < height_min:
            stool_tot += (height_min - A[i])
        else:
            height_min = A[i]         
            
    return stool_tot  
  
N = int(input())
A = list(map(int, input().rstrip().split()))
print(minimumStoolHeight(A))

Measured memory_bytes: 93912