akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;

#define MAX_N 100000

int n;
int a[MAX_N] = {0};
int diff[MAX_N] = {0};
int mins[MAX_N] = {0};
int t;

void solve(){
    int tmp_min = a[0];

    for(int i = 0; i < n - 1; i++){
        mins[i] = min(tmp_min, a[i]);
        tmp_min = mins[i];
    }

    diff[0] = 0;
    int max_diff = 0;

    for(int i = 1; i < n; i++){
        diff[i] = a[i] - mins[i - 1];
        max_diff = max(max_diff, diff[i]);
    }

    int count = 0;
    for(int i = 1; i < n; i++){
        if (diff[i] == max_diff) count++; 
    }
    cout << count << endl;
    return ;
}


int main(){
    cin >> n >> t;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    solve();
    return 0;
}


Measured memory_bytes: 1408
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <random>
#include <set>
#include <sstream>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 1e18;
const double INFD = 1e30;
const double EPS = 1e-9;
const double PI = acos(-1);
const int MOD = 998244353;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 200005;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;
char _map[15][1005];
int bin[15];
int N;
bool test(int S, int& out) {
    vector<int> cut;
    for (int j = 0; j < n - 1; j++) {
        if ((S >> j) & 1) cut.push_back(j + 2);
    }
    cut.push_back(n + 1);
    int cur = cut.size() - 1;
    int sz = cur + 1;
    memset(bin, 0, sizeof(bin));
    for (int j = 1; j <= m; j++) {
        int st = 1, maxx = 0;
        int tmp[15];
        for (int k = 0; k < sz; k++) {
            tmp[k] = 0;
            for (; st < cut[k]; st++) tmp[k] += (_map[st][j] == '1');
            if (tmp[k] > N) return false;
            maxx = max(maxx, bin[k] + tmp[k]);
        }
        if (maxx > N) {
            cur++;
            for (int k = 0; k < sz; k++) bin[k] = tmp[k];
        } else {
            for (int k = 0; k < sz; k++) bin[k] += tmp[k];
        }
    }
    out = cur;
    return true;
}
int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    scanf("%d%d%d", &n, &m, &N);
    for (int i = 1; i <= n; i++) {
        scanf("%s", _map[i] + 1);
    }
    int ans = INF2;
    for (int i = 0; i < (1 << (n - 1)); i++) {
        int cur;
        if (test(i, cur)) {
            ans = min(ans, cur);
        }
    }
    printf("%d", ans);
    return 0;
}

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

int main() {
	int64_t N;
	cin >> N;
	int64_t l = 1, r = N;
	for (int i = 1;i <= (int)sqrt(N);++i) {
		if (N % i == 0 && i + N / i < l + r) {
			l = i, r = N / i;
		}
	}
	cout << l + r - 2 << endl;
	return 0;
}

Measured memory_bytes: 256
using System;

public class A
{
	public static void Main()
	{
		string s = Console.ReadLine();
		s = s.Replace("eraser", "");
		s = s.Replace("erase", "");
		s = s.Replace("dreamer", "");
		s = s.Replace("dream", "");
		if(s == "")
		{
			Console.WriteLine("YES");
		}
		else
		{
			Console.WriteLine("NO");
		}
	}
}

Measured memory_bytes: 13100
x,k,d = map(int, input().split())
m = abs(x)//d
if m>=k:
  print(abs(x)-k*d)
else:
  k -= m
  if x>=0:
    x -= m*d
  else:
    x += m*d
  
  if x>=0:
    x -= d
    if x<=0:
      if (k-1)%2==1:
        x += d
  else:
    x += d
    if x>=0:
      if (k-1)%2==1:
        x -= d
  print(abs(x))

Measured memory_bytes: 9196
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

#include "atcoder/all"
using namespace atcoder;

int op(int a, int b){return max(a, b);}
int e(){return(int)(0);}

const int N_MAX = 300005;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	segtree<int, op, e> seg(N_MAX);
	rep(i,N_MAX) seg.set(i, 0);
	int ans = 0;
	rep(i,n){
		int a;
		cin >> a;
		int l = max(a-k, 0);
		int r = min(a+k, N_MAX-2);
		int x = seg.prod(l, r+1);
		seg.set(a, x+1);
		chmax(ans, x+1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8460
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second

using namespace std;
typedef long long ll;
int skip[100005];
int go[100005][19];

int f(int k, int curr){

    if(go[curr][k] != -1)return go[curr][k];

    if(k == 0){
        go[curr][k] = skip[curr];
        return skip[curr];
    }
    else{
        int x = f(k - 1, curr);
        go[curr][k] = f(k - 1, x);

        return go[curr][k];
    }
}


int main()
{
    int n;
    cin >> n;
    int a[n];
    fr(i, 0, n){
        cin >> a[i];
    }
    int L;
    cin >> L;

    int len = 0;
    int j = 0;
    fr(i, 0, n){
        if(j <= i){
            j = i;
            len = 0;
        }
        else{
            len -= a[i] - a[i - 1];
        }
        while(j + 1 < n && len + a[j + 1] - a[j] <= L){
            len += (a[j + 1] - a[j]);
            j ++;
        }
        skip[i] = j;
    }
    memset(go, -1, sizeof(go));
    fr(i, 0, n){
        f(18, i);
    }

    int q;
    cin >> q;
    while(q --){
        int x, y;
        cin >> x >> y;
        x --, y--;
        if(x > y) swap(x, y);
        int k = x;
        int len = 0;
        for(int i = 18; i >= 0; i --){
            while(go[k][i] < y){
                k = go[k][i];


                len += pow(2, i);
           }
        }
        cout << len + 1 << endl;
    }
/*
    fr(i, 0, n){
        cout << i <<' ';
    }
    cout << endl;
    fr(i, 0, n){
        cout << skip[i] <<' ';
    }
    cout << endl;
    cout << go[0][0] << endl;
    cout << go[0][1] << endl;
    cout << go[0][2] << endl;*/
    return 0;
}


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

using ll = long long;
using ld = long double;
using Graph = vector<vector<ll>>;

int main(void)
{
    ll n,m;
    cin >> n >> m;
    ll a,b;
    vector<ll> h(n),ma(n,0);

    for(int i=0;i<n;i++)
    {
        cin >> h[i];
    }
    for(int i=0;i<m;i++)
    {
        cin >> a >> b;
        a--;
        b--;
        ma[a]=max(ma[a],h[b]);
        ma[b]=max(ma[b],h[a]);
    }
    
    ll count=0;
    for(int i=0;i<n;i++)
    {
        if(h[i]>ma[i])
        {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 4772
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdint.h>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;

#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 DEBUG(x) cout << #x << ": " << x << endl

const string YES = "YES";
const string NO = "NO";

void solve(long long A, long long V, long long B, long long W, long long T) {
  if ((double)abs(A - B) <= T * (V - W)) {
    cout << YES << endl;
  } else {
    cout << NO << endl;
  }
}

int main() {
  long long A;
  scanf("%lld", &A);
  long long V;
  scanf("%lld", &V);
  long long B;
  scanf("%lld", &B);
  long long W;
  scanf("%lld", &W);
  long long T;
  scanf("%lld", &T);
  solve(A, V, B, W, T);
  return 0;
}


Measured memory_bytes: 3768
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define int long long
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define intl __int128
#define pii pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
const int mod = 1e9 + 7;
inline int ksm(int a, int b)
{
	int ans = 1;
	for (; b; b >>= 1, a = a * a % mod)
		if (b & 1)
			ans = ans * a % mod;
	return ans;
}
const int maxn = 1e6+20;
char s[maxn];
int dp[maxn][2];
signed main()
{
    //freopen("D:\\code\\text\\input.txt","r",stdin);
    //freopen("D:\\code\\text\\output.txt","w",stdout);
    s[0] = '0';
    scanf("%s", s + 1);
    int n = strlen(s + 1);
    dp[n][0] = (s[n] - '0');
    dp[n][1] = 10 - (s[n] - '0');
    for (int i = n - 1; i >= 0; --i)
    {
        dp[i][0] = min(dp[i + 1][0] + (s[i] - '0'), dp[i + 1][1] + (s[i] - '0') + 1);
        dp[i][1] = min(dp[i + 1][0] + 10 - (s[i] - '0'), dp[i + 1][1] + 10 - (s[i] - '0' + 1));
    }
    printf("%lld\n", min(dp[0][0], dp[0][1]));
    return 0;
}

/*

 4 6

 1  2  3   4 

*/

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    char b;
    cin >> b;
    if (b == 'A') {
        cout << "T" << endl;
    } else if (b == 'G') {
        cout << "C" << endl;
    } else if (b == 'T') {
        cout << "A" << endl;
    } else {
        cout << "G" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    vector<int> dp(31,0);
    dp[0]=1;
    dp[1]=1;
    dp[2]=2;
    for (int i=3; i<=30; i++){
        dp[i] = dp[i-1] + dp[i-2] + dp[i-3];
    }
    for(;;){
        int n;
        cin >> n;
        if(n==0) break;
        int ans = dp[n]/(365*10);
        if(dp[n]%(365*10)>0) ans++;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1196
from collections import defaultdict
s=input()
t=input()
dct=defaultdict(int)
for i in range(len(s)):
  if not dct[s[i]]:
    dct[s[i]]=t[i]
  elif dct[s[i]]!=t[i]:
    print("No")
    exit()
ls=[]
for i in dct.values():
  if i in ls:
    print("No")
    exit()
  else:
    ls.append(i)
print("Yes")

Measured memory_bytes: 4016
N = gets.to_i
A = Array.new(N) { gets.split.map(&:to_i) }.sort_by {|a, b| a + b }.reverse
x, y = 0, 0
A.size.times {|i| i.even? ? x += A[i][0] : y += A[i][1] }
p x - y

Measured memory_bytes: 12664
while True:
    n = int(input())
    if not n:
        break
    results = {(n,)}
    for i in range(1, n):
        right_list = list((k,) for k in range(1, n // (i + 1) + 1))
        for j in range(i - 1):
            next_list = []
            for right in right_list:
                for k in range(right[0], (n - sum(right)) // (i - j) + 1):
                    next_list.append((k,) + right)
            right_list = next_list
        for right in right_list:
            results.add((n - sum(right),) + right)
    for result in sorted(results, reverse=True):
        print(*result)

Measured memory_bytes: 9540
#include <cstdio>
#include <iostream>
#include <cassert>
#include <algorithm>    
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
// #define int long long
using namespace std;

typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef unsigned long long ull; 
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const int M = 1e9 + 7;
//__int128


signed main()
{
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n, m;
  cin >> n >> m;
  std::vector<long long> a(n), b(m);  
  for(int i = 0; i < n; ++i) {
  	cin >> a[i];
  }
  for(int i = 0; i < m; ++i) {
  	cin >> b[i];
  }
  long long x = 0;
  for(int i = 0; i < n; ++i) {
  	x += i * a[i] - (n - i - 1) * a[i];
  	x %= M;
  }
  long long y = 0;
  for(int i = 0; i < m; ++i) {
  	y += i * b[i] - (m - i - 1) * b[i];
  	y %= M;
  }
  cout << (x * y % M + M) % M << endl;
	return 0;
}

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

typedef long long ll;
using namespace std;
ll mod = 1'000'000'000 + 7;


int main() {
    string S;
    cin >> S;
    int l = S.length();
    int ans = l;
    for (int i = 1; i < l; i++) {
        if (S[i - 1] != S[i]) {
            int p = (i - 1) - 0 + 1, q = (l - 1) - i + 1;
            if (p < q) {
                ans = min(ans, q);
            } else {
                ans = min(ans, p);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())

using namespace std;
using ll = int64_t;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int N;
  cin >> N;
  string S;
  cin >> S;
  int R = 0, B = 0;
  for (char c : S) {
    if (c == 'R') ++R;
    else ++B;
  }

  if (R > B)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import Counter
N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]
cs = Counter(s)
ct = Counter(t)

ans = 0
for k, v in cs.items():
    tmp = v
    if k in ct.keys():
        tmp -= ct[k]

    ans = max(ans, tmp)

print(ans)


Measured memory_bytes: 65492
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define INF INT_MAX/2

int H, W, S;
int U[32][32];
int UU[33][33];

int getUsum(int sx, int sy, int tx, int ty)
{
	return (UU[ty + 1][tx + 1] - UU[ty + 1][sx] - UU[sy][tx + 1] + UU[sy][sx]);
}

int Usum, Glimit;

bool ismemo[32][32][32][32];
pair<int, int> memo[32][32][32][32];

pair<int, int> rec(int sx, int sy, int tx, int ty)
{
	if (ismemo[sx][sy][tx][ty]) return memo[sx][sy][tx][ty];

	if (getUsum(sx, sy, tx, ty) < Glimit)
	{
		ismemo[sx][sy][tx][ty] = true;
		return memo[sx][sy][tx][ty] = pair<int, int>(0, INF);
	}

	pair<int, int> ans(1, getUsum(sx, sy, tx, ty));
	rep(x, sx, tx)
	{
		auto le = rec(sx, sy, x, ty);
		if (le.first == 0) continue;
		auto ri = rec(x + 1, sy, tx, ty);
		if (ri.first == 0) continue;

		int gnum = le.first + ri.first;
		int sum = min(le.second, ri.second);

		if (ans.first < gnum)
		{
			ans.first = gnum;
			ans.second = sum;
		}
		else if (ans.first == gnum)
		{
			ans.second = max(ans.second, sum);
		}
	}

	rep(y, sy, ty)
	{
		auto le = rec(sx, sy, tx, y);
		if (le.first == 0) continue;
		auto ri = rec(sx, y + 1, tx, ty);
		if (ri.first == 0) continue;

		int gnum = le.first + ri.first;
		int sum = min(le.second, ri.second);

		if (ans.first < gnum)
		{
			ans.first = gnum;
			ans.second = sum;
		}
		else if (ans.first == gnum)
		{
			ans.second = max(ans.second, sum);
		}
	}

	ismemo[sx][sy][tx][ty] = true;
	return memo[sx][sy][tx][ty] = ans;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	while (cin >> H >> W >> S)
	{
		if (H == 0) return 0;

		rep(y, 0, H) rep(x, 0, W) cin >> U[y][x];
		rep(y, 0, H + 1) rep(x, 0, W + 1) UU[y][x] = 0;
		rep(y, 1, H + 1) rep(x, 1, W + 1) UU[y][x] = U[y - 1][x - 1] + UU[y - 1][x] + UU[y][x - 1] - UU[y - 1][x - 1];

		Usum = getUsum(0, 0, W - 1, H - 1);
		Glimit = Usum - S;

		rep(i, 0, 32) rep(ii, 0, 32) rep(j, 0, 32) rep(jj, 0, 32) ismemo[i][ii][j][jj] = false;
		auto ans = rec(0, 0, W - 1, H - 1);

		cout << ans.first << " " << (ans.second - Glimit) << endl;

		//return 0;
	}
}

Measured memory_bytes: 11988
#include <bits/stdc++.h>
	using namespace std;
	typedef long long int ll;
	
	#define mod					1000000007
	#define pii                 pair<int,int>
	#define vi                  vector<int>
	#define vii                 vector<std::vector<int>> v;
	#define mem(dp,a)           memset(dp,a,sizeof dp)
	#define sonic               ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	#define pb(x)               push_back(x)
	#define mkp(x,y)             make_pair(x,y)
	#define all(c)              c.begin(), c.end()
	#define ff                  first
	#define ss                  second
	#define INF                 INT_MAX
	
	/* Bit Manipulation */
	
	#define isOn(S, j) (S & (1 << j))
	#define setBit(S, j) (S |= (1 << j))
	#define clearBit(S, j) (S &= ~(1 << j)) // to turn off
	#define toggleBit(S, j) (S ^= (1 << j))
	#define lowBit(S) (S & (-S)) // to get lsb
	#define setAll(S, n) (S = (1 << n) - 1)
	
	#define modulo(S, N) ((S) & (N - 1))   // returns S % N, where N is a power of 2
	#define isPowerOfTwo(S) (!(S & (S - 1)))
	#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))
	#define turnOffLastBit(S) ((S) & (S - 1))
	#define turnOnLastZero(S) ((S) | (S + 1))
	#define turnOffLastConsecutiveBits(S) ((S) & (S + 1))
	#define turnOnLastConsecutiveZeroes(S) ((S) | (S - 1))
	
	void printSet(int vS) {                         // in binary representation
	  printf("S = %2d = ", vS);
	  stack<int> st;
	  while (vS)
	    st.push(vS % 2), vS /= 2;
	  while (!st.empty())                         // to reverse the print order
	    printf("%d", st.top()), st.pop();
	  printf("\n");
	}
	
// Main Starts...
	int main()
	{
	    sonic;
		int n,x,t;
		cin >> n >> x >> t;
		int i=1;
		while (1)
		{
			int p = t*i;
			int q = x*i;
			if (n <= q)
			{
				cout << p << endl;
				break;
			}
			i++;
		}
	}
	//******Main Ends here****************//
	
	
	


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

int main(){
	int n;
	string s;
	cin >> n;
	cin >> s;
	if(n%2==1){
		cout << "No" << endl;
		return 0;
	}
	rep(i,n/2){
		if(s[i] != s[n/2+i]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 384
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_f2(const void* a, const void* b) {
    return *((uint64_t*)a) > * ((uint64_t*)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static char S[100001];

int main(void) {
    scanf("%s", S);

    const size_t len = strlen(S);
    size_t count[2] = { 0,0 };

    for (size_t i = 0; i < len; i++) {
        if (i % 2 == 0) {
            count[S[i] - '0']++;
        }
        else {
            count[1 - (S[i] - '0')]++;
        }
    }

    printf("%zu\n", MIN(count[0], count[1]));

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	int n; 
	cin >> n;
	ll a[n], res=0;
	for(int i=0; i<n; ++i) cin >> a[i];
	for(int i=0; i<n-1; ++i)
	{
		if(a[i+1]<a[i])
		{
			res+=a[i]-a[i+1];
			a[i+1]+=a[i]-a[i+1];
		}	
	} 
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 5184
# from https://ikatakos.com/pot/programming_algorithm/contest_history/atcoder/2019/0106_educational_dp_2
def solve(n,hhh,aaa):
    n2=1<<n.bit_length()
    offset=n2-1
    data=[0]*((n2<<1)-1)

    def update(k,x):
        i=k+offset
        while i>=0:
            if data[i]<x:
                data[i]=x
            else:
                break
            i=(i-1)//2

    def get_max(k):
        i=k+offset
        ret=data[i]
        while i:
            if i%2==0:
                ret=max(ret,data[i-1])
            i=(i-1)//2
        return ret

    srt=sorted((h,i) for i,h in enumerate(hhh))
    for h,i in srt:
        update(i,get_max(i)+aaa[i])

    return data[0]



n=int(input())
hhh=[int(i) for i in input().split()]
aaa=[int(i) for i in input().split()]
print(solve(n,hhh,aaa))


Measured memory_bytes: 122960
import sys
from collections import Counter


input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    C = Counter()
    for a in A:
        if a % 4 == 0:
            C[4] += 1
        elif a % 2 == 0:
            C[2] += 1
        else:
            C[0] += 1
    if C[2] >= 1:
        if C[0] > C[4]:
            print("No")
        else:
            print("Yes")
    else:
        if C[0] > C[4] + 1:
            print("No")
        else:
            print("Yes")


if __name__ == '__main__':
    main()



Measured memory_bytes: 14636
h, w, m = map(int, input().split())
a = [0] * h
b = [0] * w
g = [[] for _ in range(h)]
for _ in range(m):
    y, x = map(int, input().split())
    a[y - 1] += 1
    b[x - 1] += 1
    g[y - 1].append(x - 1)
ma = max(a)
mb = max(b)
c = b.count(mb)
for i in range(h):
    if a[i] == ma:
        res = 0
        for p in g[i]:
            if b[p] == mb:
                res += 1
        if res < c:
            print(ma + mb)
            exit(0)
print(ma + mb - 1)


Measured memory_bytes: 110084
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using ul = unsigned long long;
using Bint = mp::cpp_int;
ll mod = 1000000007;

int main() {
source:
    string s;
    cin >> s;
    string temp = "hi";

    rep(i, 10) {
        if (s == temp) {
            cout << "Yes" << endl;
            return 0;
        }
        temp += "hi";
    }
    cout << "No" << endl;

    return 0;
}



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

using namespace std;

const double EPS = 1e-8;

typedef complex<double> Point;
typedef vector<Point> Polygon;

inline int sign(double x){
    return (x > EPS ? 1 : x < -EPS ? -1 : 0);
}

inline Point curr(const Polygon& a, int x){
    return a[x];
}
inline Point next(const Polygon& a, int x){
    return a[(x + 1) % a.size()];
}

double dot(Point a, Point b){
    return real(conj(a) * b);
}

double cross(Point a, Point b){
    return imag(conj(a) * b);
}

enum { OUT, ON, IN };
int contains(const Polygon& P, const Point& p){
    bool in = false;
    for(int i = 0; i < P.size(); i++){
        Point a = curr(P, i) - p;
        Point b = next(P, i) - p;
        if(a.imag() > b.imag()) swap(a, b);
        if(a.imag() <= 0 && 0 < b.imag() && cross(a, b) < 0){
            in = !in;
        }
        if(sign(cross(a, b)) == 0 && sign(dot(a, b)) <= 0) return ON;
    }
    return in ? IN : OUT;
}

int main(){
    double x1, y1, x2, y2, x3, y3, xp, yp;
    while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp){
        Polygon t;
        t.push_back(Point(x1, y1));
        t.push_back(Point(x2, y2));
        t.push_back(Point(x3, y3));
        if(contains(t, Point(xp, yp)) == IN){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1224
import           Control.Monad
import           Text.Printf

getLines :: Int -> IO [String]
getLines n = replicateM n getLine

getLinesInt :: Int -> IO [Int]
getLinesInt n = fmap read <$> getLines n

getInts :: IO [Int]
getInts = map (read :: String -> Int) . words <$> getLine

getDoubles :: IO [Double]
getDoubles = map (read :: String -> Double) . words <$> getLine

splitOn :: (Char -> Bool) -> String -> [String]
splitOn p s = case dropWhile p s of
    "" -> []
    s' -> w : splitOn p s'' where (w, s'') = break p s'

toInt :: [String] -> [Int]
toInt = map ((read :: String -> Int) . dropZero)

dropZero :: String -> String
dropZero s = if head s == '0' then drop 1 s else s

main :: IO ()
main = do
    s         <- getLine
    putStrLn $ let [y, m, d] = toInt $ splitOn (== '/') s in
        if func y m d > func 2019 4 30
            then "TBD"
            else "Heisei"


func y m d = y * 10000 + m * 100 + d

Measured memory_bytes: 508
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt(), h = sc.nextInt();
        int x = sc.nextInt(), y = sc.nextInt(), r = sc.nextInt();
        if (x - r < 0 || x + r > w || y - r < 0 || y + r > h) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 26308
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int d[310][310]; //d[from][to]:=2点間の最短距離
void Warshall_Floyd(int n){ //頂点数n
    rep(i,n){               //経由点i
        rep(j,n){           //始点j
            rep(k,n){       //終点k
				d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
            }
        }
	}
}
int main(){
    int n; cin>>n;
    int a[n][n];
    rep(i,n)rep(j,n) cin>>a[i][j];
    rep(i,n)rep(j,n) d[i][j]=a[i][j];
	Warshall_Floyd(n);
    long long ans=0;
    rep(i,n)rep(j,n){
        if(d[i][j]<a[i][j]){
            cout<<-1<<endl;
            return 0;
        }
        int mini=INF;
        rep(k,n){
            if(i==k||k==j) continue;
            mini=min(mini,d[i][k]+d[k][j]);
        }
        if(d[i][j]<mini) ans+=d[i][j];
    }
    cout<<ans/2<<endl;
	return 0;
}


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

int main() {
	int W, H;
	while(cin >> W >> H, W) {
		int b[20][15] = { 0 };
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				cin >> b[i][j];
			}
		}

		int dp[20][15] = { 0 };
		for(int i = 0; i < W; i++) {
			if(b[0][i] != 1) dp[0][i] = 1;
		}

		for(int i = 0; i < H - 1; i++) {
			for(int j = 0; j < W; j++) {
				if(b[i][j] == 0) {
					for(int d = -1; d <= 1; d++) {
						if(0 <= j + d &&  j + d < W && (b[i + 1][j + d] == 0) || (b[i + 1][j + d] == 2 && d == 0))
							dp[i + 1][j + d] += dp[i][j];
					}
				}
				else if(b[i][j] == 2) {
					dp[i + 2][j] += dp[i][j];
				}
			}
		}

		int ans = 0;
		for(int i = H - 1; i <= H; i++) {
			for(int j = 0; j < W; j++) {
				if(b[i][j] != 1)
					ans += dp[i][j];
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    int N,i,j,ans,ans1=0,x;
    cin>>N; vector<int> v1;
    for(i=0;i<N;i++) { cin>>x; v1.push_back(x); }
    sort(v1.begin(),v1.end());
    for(i=0;i<N;i++)
    {
        for(j=i+1;j<N;j++)
        {
            int t=v1[i]+v1[j];
            auto k=lower_bound(v1.begin(),v1.end(),t);
            k--;
            if(*k<t) 
            {
                ll p2=k-v1.begin();
                if(p2>j) ans1+=p2-j;
            }
        }
    }
    cout<<ans1<<endl;
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

N = int(input())
S = input()

dp = [[0 for j in range(N+1)] for i in range(N+1)]

for i in range(N-1,-1,-1):
    for j in range(N-1,i,-1):
        if S[i] == S[j]:
           dp[i][j] = dp[i+1][j+1] + 1
        else:
            dp[i][j] = 0

ans = 0
for i in range(N):
    for j in range(N):
        ans = max(ans, min(dp[i][j], j-i))

print(ans)

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

string str1,str2,str3;
int main()
{
	cin>>str1>>str2>>str3;

	string ans ="";
	ans+=char(str1[0] - 'a' + 'A');
	ans+=char(str2[0]-'a' + 'A');
	ans+=char(str3[0] - 'a' + 'A');
	
	cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 3576
n = input()
arr = [map(int,raw_input().split()) for _ in range(n)]

tou = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]

for line in arr:
    b,f,r,v = line
    tou[b-1][f-1][r-1] = tou[b-1][f-1][r-1] + v

for i in range(4):
    for j in range(3):
        print ' '+' '.join(map(str,tou[i][j]))
    if i < 3 :
        print '#'*20

Measured memory_bytes: 6352
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>
#include<cmath>
#include<cstring>
#include<map>
#include<sstream>
 
using namespace std;

char S[6];

int main(){
  cin>>S;

  if(S[2]==S[3] && S[4]==S[5]){
  	  cout<<"Yes"<<endl;
  }else{
  	cout<<"No"<<endl;
  }
  

}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}



P solve(const vi &a) {
  P p = P(45+a[0]*45, 1);
  FOR(i, 1, SZ(a)) {
    p.fi *= 2;
    p.se *= 2;
    p.fi += a[i] * 90;
  }
  return p;
}

int gcd(int a, int b) {
  return (b==0) ? a : gcd(b, a%b);
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  while(1) {
    string s; cin >> s;
    if(s == "#") break;
    vi a;
    int cnt = 0;
    while(cnt <= SZ(s)-1) {
      if(s[cnt] == 'n') {
        a.pb(-1);
        cnt += 5;
      } else {
        a.pb(1);
        cnt += 4;
      }
    }
    reverse(ALL(a));
    P p = solve(a);
    if(p.fi == 0) {
      cout << p.fi << endl;
      continue;
    }
    int g = gcd(p.fi, p.se);
    p.fi /= g;
    p.se /= g;
    if(p.se == 1) cout << p.fi << endl;
    else cout << p.fi << "/" << p.se << endl;
  }
}



Measured memory_bytes: 3080
import math
import itertools
n,d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
listA = list(itertools.combinations(x, 2))
a = 0
b = 0
for j in range(len(listA)):
    for k in range(d):
        a = a+(listA[j][0][k]-listA[j][1][k])**2
    if a**(0.5)==int(a**(0.5)):
        b = b+1
    a = 0
print(b)

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

int main() {
	cin >> a >> b >> c >> x >> y;
	int ans = 0;
	ans += min(x, y) * min(a + b, 2 * c);
	if (y >= x) {
		ans += (y - x) * min(b, 2 * c);
	} else {
		ans += (x - y) * min(a, 2 * c);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	iostream::sync_with_stdio(false);
	int n;
	cin >> n;
	stack<int> input;
	long long ans = 1;
	REP(i, n) {
		int a;
		cin >> a;
		input.push(a);
		if (input.top() < 2 * input.size() - 1) {
			ans *= (long long)input.size();
			ans %= MAX_MOD;
			input.pop();
		}
	}
	REP(i, input.size()) {
		ans *= (long long)(i + 1LL);
		ans %= MAX_MOD;
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  int A, B, i, a, b, x, y, z = 0;
  cin >> A >> B;
  for (int i = A; i < B + 1; i++){
    a = i / 10000;
    b = (i / 1000) % 10;
    x = i % 10;
    y = (i % 100) / 10;
    if (a == x && b == y){
      z += 1;
    }
    else
      continue;
  }
  cout << z << endl;
}


Measured memory_bytes: 3632
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define int ll
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
signed main(){
    int n; cin>>n;
    vector<int>v(n);
    vector<int>u(n);
    vector<int>g(n);
    rep(i,n)cin>>v[i];
    rep(i,n)cin>>u[i];
    rep(i,n)cin>>g[i];
    sort(all(v));
    sort(all(u));
    sort(all(g));
    vector<int>usum(n,0);
    rep(i,n){
        int index=(int)(upper_bound(all(g),u[i])-g.begin());
        usum[i]=n-index;
    }
    for(int i=n-1;i>0;i--){
        if(i)usum[i-1]+=usum[i];
    }
    int ans=0;
    rep(i,n){
        int temp=(int)(upper_bound(all(u),v[i])-u.begin());
        if(temp==n)continue;
        ans+=usum[temp];
    }
    cout<<ans<<endl;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> Ai;
  priority_queue<int> pq;
  
  rep(i,N){
    int tmpAi;
    cin >> tmpAi;
    Ai.push_back(tmpAi);
    pq.push(tmpAi);
  }

  int Max = pq.top();
  pq.pop();
  int Max2 = pq.top();
  
  rep(i,N){
    if(Ai.at(i) == Max){
      cout << Max2 << endl;
    }else{
      cout << Max << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 3436
#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

const int mod = (int)1e9 + 7;
const int mod2 = 998244353;

ll exp(ll taban, ll us, ll md) {
    ll carpan = taban % md;
	if(carpan == 0) return 0;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % md;
        temp /= 2;
        carpan = (carpan*carpan) % md;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}

ll mul(ll a, ll b, ll md){
	return a*b % md;
}

vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n){
	fact.resize(n+5);
	inv_fact.resize(n+5);
	fact[0] = inv_fact[0] = 1;
	for(int i = 1; i <= n; i++){
		fact[i] = (fact[i-1] * i) % mod;
		inv_fact[i] = exp(fact[i], mod-2, mod);
	}
}

ll komb(ll a, ll b){
	if(a < b) return 0;
	return fact[a] * (inv_fact[a-b] * inv_fact[b] % mod) % mod;
}


const int N = 2e5+5;

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL);
	string s; cin>>s;
	int n = s.size();
	string s_without_x;
	for(int i = 0; i < s.size(); i++){
		char x = s[i];
		if(x != 'x') s_without_x += x;
	}
	int m = s_without_x.size();
	for(int i = 0; i < m/2; i++){
		if(s_without_x[i] != s_without_x[m - 1 - i]){
			cout<<-1;
			return 0;
		}
	}
	int orta = 0;
	int ilk_orta = -1;
	int ikinci_orta = -1;
	for(int i = 0; i < s.size(); i++){
		char x = s[i];
		/*if(x != 'x' && m == 1){
			orta++;
			ilk_orta = i;
			ikinci_orta = i;
		}*/
		if(x != 'x' && orta < (m+1)/2){
			orta++;
			ilk_orta = i;
			ikinci_orta = i;
		}else if(orta == (m+1)/2 && m%2 == 0 && x != 'x'){
			orta++;
			ikinci_orta = i;
		}
	}
	if(ilk_orta == -1){
		cout<<0;
		return 0;
	}
	int ans = 0;
	int l = ilk_orta, r = ikinci_orta;
	//cout<<l<<" "<<r<<endl;
	while(l >= 0 || r < n){
		while(l >= 0 && s[l] != s[r] && r < n){
			if(s[l] == 'x'){
				l--;
				ans++;
			}else{
				r++;
				ans++;
			}
		}
		l--;
		r++;
		if(l < 0){
			while(r < n){
				ans++;
				r++;
			}
		}else if(r >= n){
			while(l >= 0){
				ans++;
				l--;
			}
		}
	}
	cout<<ans<<endl;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	if (v.size()) {
		os << v[0];
		for (int i = 1; i < v.size(); i++) os << " " << v[i];
	}
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	ll N; cin >> N;
	vll A(N); cin >> A;
	
	ll have = 1000 / A[0];
	ll money = 1000 - have*A[0];
	for (int i = 1; i < N; i++) {
		if (A[i-1] > A[i]) {
			money += have*A[i-1];
			have = 0;
			have = money / A[i];
			money = money - have*A[i];
		}
	}
	money += have*A[N-1];
	cout << money << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef _DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif

signed main() {

    int h, w;
    cin >> h >> w;
    rep(i,h){
        string s;
        cin >> s;
        cout << s << endl;
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))   
if len(b)==1:
    print(b[0])
    exit()
else:
    c=sorted(b)
    x=1
    while x>0:
        v=c[0]
        for i in range(len(c)):
            if i!=0:
                c[i]=c[i]%v
        while 0 in c:
            c.remove(0)
        c=sorted(list(set(c)))
        if len(c)==1:
            print(c[0])
            exit()
        if c[0]==1:
            x=0
print(1)
            
    





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

void solveA(){
  double t,x;
  cin >> t >> x;
  printf("%.10lf\n",t/x);
}
void solveB(){
  int n;
  cin >> n;
  int l[n];
  int sum = 0;
  

  for(int i=0;i<n;i++){
    cin >> l[i];
    sum += l[i];
  }

  sort(l,l+n);
  int maxl = l[n-1];

  if (maxl < sum - maxl){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

  
}

void solveC(){
}
void solveD(){
}

int main(){
  solveB();
}


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

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
// utility
#define all(i) (i).begin(), (i).end()
#define rep(i, n) for(int i=0;i<int(n);++i)
#define rrep(i, n) for(int i=int(n)-1;i>=0;--i)
#define repv(ele, vec) for (auto &ele : vec)
#define in(a, x, b) (a<=x && x<b)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
constexpr int MOD = 1000000007;

using namespace std;


signed main() {
  int H, W;
  cin >> H >> W;
  vector<string> vec(H);
  rep(i, H) cin >> vec[i];

  int h[H], w[W];
  rep(i, H) h[i] = 0;
  rep(i, W) w[i] = 0;
  rep(i, H){
    int flag = 0;
    rep(j, W) if(vec[i][j] == '#') flag = 1;
    if(flag) h[i] = 1;
  }
  rep(j, W){
    int flag = 0;
    rep(i, H) if(vec[i][j] == '#') flag = 1;
    if(flag) w[j] = 1;
  }
  rep(i, H){
    rep(j, W) if(h[i] && w[j]) cout << vec[i][j];
    if(h[i]) cout << endl;
  }

  return 0;
}

Measured memory_bytes: 256
n = int(input())
v = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

vc = [(v[i] - c[i]) for i in range(n)]
vc.sort(reverse=True)

result = 0
for profit in vc:
    if profit <= 0:
        break
    result += profit

print(result)


Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())



void init() {

}

void input() {

}

void solve() {
  int n ;
  cin >> n;
  double res = 0;
  REP(i, n) {
    double a;
    string s;
    cin >> a >> s;
    if (s == "JPY") {
      res += a;
    } else {
      res += a*380000.0;
    }
  }
  printf("%.10f\n", res);
}

int main() {
	init();
	input();
	solve();
	return 0;
}


Measured memory_bytes: 256