akhauriyash/Code-Regression huggingface dataset:
import math

S = int(input())
t = math.sqrt(S)
a = b = math.ceil(t)

if a*(b-1) >= S:
  b -= 1

d = a*b - S
if d == 0:
  c = 0
else:
  c = 1
print("0 0 {} {} {} {}".format(a, c, d, b))

Measured memory_bytes: 62120
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    int ans = 0;
    int cur = 0;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        if (x == i) {
            cur++;
        }
        else {
            ans += (cur + 1) / 2;
            cur = 0;
        }
    }
    ans += (cur + 1) / 2;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
arr_ = [tuple(map(int, input().split())) for _ in range(m)]

one = set([b for a, b in arr_ if a == 1])
last = set([a for a, b in arr_ if b == n])
connect = one & last
if len(connect) >= 1:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 44296
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
constexpr int ms = 5000013;
struct Query {
  int l, r, idx;
};
inline bool cmp(Query x, Query y) { return x.r < y.r; }
void update(int idx, int val, vector<int> &bit, int n) {
  for (; idx <= n; idx += idx & -idx)
    bit[idx] += val;
}
int query(int idx, vector<int> &bit) {
  int sum = 0;
  for (; idx > 0; idx -= idx & -idx)
    sum += bit[idx];
  return sum;
}
void solve(vector<int> &arr, int n, vector<Query> &queries, int q) {
  vector<int> bit(n + 1, 0), last_visit(ms, -1), ans(q);
  int query_counter = 0;
  for (int i = 0; i < n; i++) {
    if (last_visit[arr[i]] != -1)
      update(last_visit[arr[i]] + 1, -1, bit, n);
    last_visit[arr[i]] = i;
    update(i + 1, 1, bit, n);
    while (query_counter < q && queries[query_counter].r == i) {
      ans[queries[query_counter].idx] =
          query(queries[query_counter].r + 1, bit) -
          query(queries[query_counter].l, bit);
      query_counter++;
    }
  }
  for (int &a : ans)
    cout << a << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, q;
  cin >> n >> q;
  vector<int> arr(n);
  for (int &x : arr)
    cin >> x;
  vector<Query> queries(q);
  for (int i = 0; i < q; ++i) {
    cin >> queries[i].l >> queries[i].r;
    queries[i].l--;
    queries[i].r--;
    queries[i].idx = i;
  }
  sort(all(queries), cmp);
  solve(arr, n, queries, q);
  return 0;
}


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

double p;
int n;
vector<pii> g[125252];

double ans1;
double dfs1(int pos,int bef,double r){
  double ret = 0.0;
  r *= p;
  for(pii P : g[pos])if(P.first!=bef){
    ret += P.second*r + dfs1(P.first,pos,r);
  }
  return ret;
}
double dfs2(int pos,int bef,double r){
  double ret = ans1*r;
  r *= p;
  for(pii P : g[pos])if(P.first!=bef){
    ret += P.second*r + dfs2(P.first,pos,r);
  }
  return ret;
}

int main(){
  scanf("%lf",&p);
  scanf("%d",&n);
  REP(i,n-1){
    int x,y,c;
    scanf("%d%d%d",&x,&y,&c);
    --x;--y;
    g[x].push_back(pii(y,c));
    g[y].push_back(pii(x,c));
  }
  ans1 = dfs1(0,-1,1.0);
  printf("%.9f\n",dfs2(0,-1,1.0));
  return 0;
}

Measured memory_bytes: 17084
#include<stdio.h>
int main(){
    int a,b,d,r;
    double f;
    scanf("%d %d",&a,&b);
    d=a/b;
    r=a%b;
    f=1.0000000*a/b;
    printf("%d %d %.81f\n",d,r,f);
}


Measured memory_bytes: 2060
s=input()
t=input()
u=[]
c=0
for i in range(len(s)):
  v=[s[i],t[i]]
  if v not in u:
    u.append(v)
u.sort()
for k in range(len(u)):
  for m in range(len(u)):
    if u[k][0]==u[m][0]:
      if u[k][1]!=u[m][1]:c+=1
for p in range(len(u)):
  for q in range(len(u)):
    if u[p][1]==u[q][1]:
      if u[p][0]!=u[q][0]:c+=1
if c==0:print('Yes')
else:print('No')

Measured memory_bytes: 3632
from collections import defaultdict
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    S = input()[:-1]
    GX, GY = map(int, input().split())

    # 連続するFをまとめる ex.)FF->2
    # 連続するTをまとめる ex.)TTT->T
    S_parsed = []
    prev = S[0]
    seq = 1
    for c in S[1:]:
        if c == "F":
            if c == prev:
                seq += 1
            else:
                prev = c
                if seq % 2 == 0:
                    pass
                else:
                    S_parsed.append("T")
                seq = 1
        elif c == "T":
            if c == prev:
                seq += 1
            else:
                S_parsed.append(seq)
                seq = 1
            prev = c
    else:
        if S[-1] == "F":
            S_parsed.append(seq)

    # x,yを分離して考える
    x_move = []
    y_move = []

    dir_x = True
    for c in S_parsed:
        if c == "T":
            dir_x = not dir_x
        else:
            if dir_x:
                x_move.append(c)
            else:
                y_move.append(c)

    # x,y分けて、GX,GYに到達できるかをdpで判定
    dp_x = defaultdict(bool)
    if len(x_move) > 0:
        if S[0] != "T":
            dp_x[x_move[0]] = True
        else:
            dp_x[x_move[0]] = True
            dp_x[-x_move[0]] = True
    else:
        dp_x[0] = True

    for x in x_move[1:]:
        tmp = defaultdict(bool)
        for key, val in dp_x.items():
            tmp[key+x] = True
            tmp[key-x] = True
        dp_x = tmp

    dp_y = defaultdict(bool)
    if len(y_move) == 0:
        dp_y[0] = True
    else:
        dp_y[y_move[0]] = True
        dp_y[-y_move[0]] = True
    for y in y_move[1:]:
        tmp = defaultdict(bool)
        for key, val in dp_y.items():
            tmp[key+y] = True
            tmp[key-y] = True
        dp_y = tmp

    if dp_x[GX]and dp_y[GY]:
        print("Yes")
    else:
        print("No")


solve()


Measured memory_bytes: 4580
n = int(input())
t = [[0,0,0]]

for i in range(n):
    t.append(list(map(int,input().split())))

can = True

for i in range(n):
    dt = t[i+1][0] - t[i][0]
    dist = abs(t[i+1][1] - t[i][1]) + abs(t[i+1][2] - t[i][2])
    if dt < dist:
        can = False
    if dt % 2 != dist % 2:
        can = False

if can:
    print('Yes')
else:
    print('No')

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

using namespace std;

typedef long long LL;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define LC k<<1
#define RC k<<1|1

const int N=110000;
const int M=1100000;
const LL mod=1e9+7;
char s[810000];
int base=410000;
int head,tail,n,q;
int rev;
int main()
{
	scanf("%s",s+base);
	n=strlen(s+base);
	head=base,tail=base+n-1;
	scanf("%d",&q);
	while (q--)
	{
		int op1,op2;
		char x;
		scanf("%d",&op1);
		if (op1==1) rev^=1;
		else
		{
			scanf("%d %c",&op2,&x);
			if (rev==0)
			{
				if (op2==1) s[--head]=x;
				else s[++tail]=x;
			}
			else
			{
				if (op2==1) s[++tail]=x;
				else s[--head]=x;
			}
		}
		
	}
	if (rev) reverse(s+head,s+tail+1);
		printf("%s\n",s+head);	
	return 0;
}

Measured memory_bytes: 896
//
//  main.cpp
//  Good Sequence
//
//  Created by S M HEMEL on 27/1/18.
//  Copyright © 2018 Eastern University. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
using namespace std;
set<int> s;
int cnt[111111];
int main(){
    int n,x,ans=0;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> x;
        if(x>100111){
            ans++;
            continue;
        }
        s.insert(x);
        cnt[x]++;
    }
    for(auto u: s){
        if(cnt[u]!=u){
            if(cnt[u]<u)
                ans += cnt[u];
            else if(cnt[u]>u)
                ans += (cnt[u]-u);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
  string s;
  cin >> s;
  int n = s.size();
  if (s[n-1] == '3') {
    cout << "bon" << endl;
  } else if (s[n-1] == '0' || s[n-1] == '1' || s[n-1] == '6' || s[n-1] == '8') {
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }
}


Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int N, k;
//int dp[200 + 10][100 + 10][1 << (10 + 1)];
//集合は、直近k+1個の数字を上(=1)or下(=0)においたときのbit集合

int m = 1000000007;

int cnt[30];

unsigned long long popcount(unsigned long long x) {
	x = ((x & 0xaaaaaaaaaaaaaaaaUL) >> 1) +
		(x & 0x5555555555555555UL);
	x = ((x & 0xccccccccccccccccUL) >> 2) +
		(x & 0x3333333333333333UL);
	x = ((x & 0xf0f0f0f0f0f0f0f0UL) >> 4) +
		(x & 0x0f0f0f0f0f0f0f0fUL);
	x = ((x & 0xff00ff00ff00ff00UL) >> 8) +
		(x & 0x00ff00ff00ff00ffUL);
	x = ((x & 0xffff0000ffff0000UL) >> 16) +
		(x & 0x0000ffff0000ffffUL);
	x = ((x & 0xffffffff00000000UL) >> 32) +
		(x & 0x00000000ffffffffUL);
	return x;
}

int main() {
	cin >> N >> k >> m;
	
	vector<vector<vector<int>>> dp(2 * N + 1, vector<vector<int>>(N + 1, vector<int>((1 << (k + 1)), 0)));
	dp[0][0][0] = 1;
	for (int i = 0; i < 2 * N; i++) {
		for (int j = (i + 1) / 2; j <= N; j++) {
			for (int bit = 0; bit < (1 << (k + 1)); bit++) {
				if (dp[i][j][bit] == 0)continue;

				//cout << i << " " << j << " " << bit << " " << dp[i][j][bit] << endl;	

				//今のメモした桁数。
				int keta = min(k + 1, i);
				if (keta == 0) {
					//i == 0, j == 0, bit == 0の時
					dp[i + 1][j + 1][1] = dp[i][j][bit];
					continue;
				}

				vector<int> ue;
				int shita = 0;
				for (int l = i; l >= i - keta + 1; l--) {
					if ((bit >> (i - l)) & 1) {
						//数字lを上に置いたとき
						ue.push_back(l);
					}
					else if (shita == 0) {
						shita = l;
					}
				}
				//下の制約がないとき
				if (shita == 0) {
					shita = i + 1;
				}

				int cpy = bit;
				//下に置く
				//j - (i - j) - 1がout of rangeする！
				if (i != 2 * j &&
					(abs(shita - (i + 1)) <= k
						&& abs(ue.at(j - (i - j) - 1) - (i + 1)) <= k)) {
					cpy = ((cpy << 1) & ((1 << (k + 1)) - 1));
					dp[i + 1][j][cpy] += dp[i][j][bit];
					dp[i + 1][j][cpy] %= m;
				}

				cpy = bit;
				//cout << i << " " << j << " " << bit << "A" << " " << ue.size() << endl;

				//cout << "ue == " << endl;
				//for (int i = 0; i < ue.size(); i++)cout << ue[i] << " ";
				//cout << endl;

				//条件が少しおかしいと思う
				//上に置く
				if ((j * 2 == i && abs(ue.front() - (i + 1)) <= k)|| 
					((j * 2 != i) && (i + 2 - shita <= k) && (i + 2 - ue.at(j - (i - j) - 1) <= k) && 
					abs(ue.front() - (i + 1)) <= k && j != N)) {
					cpy = ((cpy << 1) & ((1 << (k + 1)) - 1));
					cpy += (1 << 0);
					dp[i + 1][j + 1][cpy] += dp[i][j][bit];
					dp[i + 1][j + 1][cpy] %= m;
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < (1 << (k + 1)); i++) {
		ans += dp[2 * N][N][i];
		ans %= m;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 166712
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <climits>
#include <functional>

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

using namespace std;
typedef long long ll;
const int INF = INT_MAX / 4;

const int max_n = 1e3;


class BinaryIndexedTree
{
public:
  int n;
  int * tree;

  BinaryIndexedTree(int N)
    : n(N)
  {
    tree = new int[n + 1];
    for (int i = 0;i < n + 1;i++) {
      tree[i] = 0;
    }
  }

  void add(int a, int w) {
    for (int x = a; x <= n; x += (x & -x)) {
      tree[x] += w;
    }
  }

  int sum(int a) {
    int s = 0;
    for (int x = a; x > 0; x -= (x & -x)) {
      s += tree[x];
    }
    return s;
  }
};


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

  int N, Q;
  cin >> N >> Q;

  BinaryIndexedTree bit(N);
  int c, x, y;
  REP(i, Q) {
    cin >> c >> x >> y;
    if (c == 0) {
      bit.add(x, y);
    } else if (c == 1) {
      cout << bit.sum(y) - bit.sum(x-1) << "\n";
    }
  }

  return 0;
}

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

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

typedef long long ll;
using namespace std;

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

  int A, B, C;
  cin >> A >> B >> C;
  int tmp = A + B;
  tmp = max(tmp, A - B);
  tmp = max(tmp, A * B);
  cout << tmp << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int ara[n+5];
  for(int i=0;i<n;i++)cin>>ara[i];
  sort(ara,ara+n);
  reverse(ara,ara+n);
  int sum=0;
  for(int i=0;i<k;i++)sum+=ara[i];
  cout<<sum<<endl;
}

Measured memory_bytes: 256
def sum0(L, k):
  c = 0
  for i in L:
    if i>=0:
      c += i
    else:
      if k>0:
        k -= 1
      else:
        c += i
  return c

n, k = map(int, input().split())
V = list(map(int, input().split()))
m = min(n, k)
ans = 0
for i in range(m+1):
  for j in range(m+1-i):
    L = sorted(V[:i] + V[n-j:])
    ans = max(ans, sum0(L, k-(i+j)))
print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp6
{
	class Program
	{
		static void Main(string[] args)
		{
			string a = Console.ReadLine();
			int x = int.Parse(a);

			x = x * x * x;

			Console.WriteLine(x);

		}
	}
}



Measured memory_bytes: 15936
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int N;
	cin >> N;
	int c0 = 0, c1 = 0, c2 = 0;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		if (A % 4 == 0) c2++;
		else if (A % 2 == 0) c1++;
		else c0++;
	}
	if (c1 > 0) c0++;
	if (c2 >= c0 - 1) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <algorithm>
#include <unordered_map>
#define int                long long
#define pb                 push_back
#define pi                 pair<int,int>
#define vi                 vector<int>
#define all(v)             v.begin(),v.end()
#define MOD                1000000007
#define F                  first
#define S                  second
#define FOR(i,r)           for(int i=0;i<r;i++)
#define REP(i,l,r)         for(int i=l;i<r;i++)
#define RER(i,l,r)         for(int i=l;i>=r;i--)
#define print(v)           for(auto i : v)cout << i << ' ';
#define FASTIO             ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mem(arr,k)         memset(arr,k,sizeof(arr));
#define pii                acos(-1.0)
#define PI                 3.1415926535897932385
#define Sin(a)             sin((pi*a)/180)
#define test()             int x;cin >> x;while(x--){solve();}
#define test2()            int x;cin >> x;for(int i=1;i<=x;i++){cout << "Case #" << i << " : ";solve();}
#define watch(x)           cout << (#x) << " is " << (x) << endl
using namespace std;


/* Mathematical Functions */
int power(int x,int y);
bool isPrime(int n);
int modInv(int a,int b);
int gcdExtended(int a,int b,int *x,int* y);
int mpower(int a,int b,int p);

const int inf = (int)1e17;
const int N = (int)3e5+5;

int32_t main(){

	
	FASTIO;
	int n,k;
	cin >> n >> k;
	vector<int>v(n);
	REP(i,0,n){
		cin >> v[i];
		v[i]--;
	}
	map<int,int>cur;
	cur[0] = 1;
	vi res;
	res.pb(0);
	int st = 0,cyc = -1;
	while(1){
		int nxt = v[st];
		if(cur[nxt]){
			cyc = nxt;
			break;
		}
		res.pb(nxt);
		st = nxt; 
		cur[st] = 1;
	}
	if(res.size() > k){
		//cout << "here\n";
		cout << res[k]+1 << endl;
	}
	else{
		vector<int>nw;
		bool ok = 0;
		for(int i=0;i<res.size();i++){
			if(res[i] == cyc){
				nw.pb(res[i]);
				ok = 1;
			}
			else if(ok){
				nw.pb(res[i]);
			}
		}
		k -= res.size();
		cout << nw[k%nw.size()]+1 << endl;
	}
    return 0;

}
int modInv(int a, int m)
{
int x, y;
int g = gcdExtended(a, m, &x, &y);
int res = (x%m + m) % m;
return res;
}
 
int gcdExtended(int a, int b, int *x, int *y)
{
if (a == 0){
    *x = 0, *y = 1;
    return b;
  }
  int x1, y1;
  int gcd = gcdExtended(b%a, a, &x1, &y1);
  *x = y1 - (b/a) * x1;
  *y = x1;
  return gcd;
}
 
int mpower(int x, int y, int p)
{
int res = 1;
x = x % p;
while(y > 0){
    if(y & 1) res = (res*x) % p;
      y = y>>1;
      x = (x*x) % p;
    }
    return res;
}
int power(int x, int y)
{
int res = 1;
while (y > 0){
    if (y & 1) res = res*x;
      y = y>>1;
      x = x*x;
    }
    return res;
}
 
bool isPrime(int n)
{
if (n <= 1)  return false;
  if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
      int p=sqrt(n);
      for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
          return false;
      return true;
}

Measured memory_bytes: 19168
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	char op;
	int a,b,i,r,o,s,t;
	for(i=0;i<=20000;i++){
		cin>>a>>op>>b;
		if(op=='?'){
			break;
		}
		if(op=='+'){
			cout<<a+b<<endl;
		}else if(op=='-'){
			cout<<a-b<<endl;
		}else if(op=='*'){
			cout<<a*b<<endl;
		}else if(op=='/'){
			cout<<a/b<<endl;
		}
	}
}

Measured memory_bytes: 3060
N, K = map(int,input().split())
p = list(map(int,input().split()))

sum_p = 0

for i in range(K):
    sum_p += p[i]

max_p = sum_p

for j in range(K,N):
    sum_p -= p[j - K]
    sum_p += p[j]
    max_p = max(max_p,sum_p)

ex = (max_p - K + 2)/2

print(ex + K - 1)

Measured memory_bytes: 25060
n, *A = map(int, open(0).read().split())

def f(x):
  y = 0
  q, r = divmod(x, 2)
  while r == 0:
    y += 1
    q, r = divmod(q, 2)
  return y

B = [0] * 3
for a in A:
  b = f(a)
  B[0] += b == 0
  B[1] += b == 1
  B[2] += b >= 2
print('Yes' if B[0] + (B[1]!=0) <= B[2]+1 else 'No')

Measured memory_bytes: 14052
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int main(){
    long n;
    cin >> n;
    long a[n];
    long ans = 0;
    map<long, long> mpl;
    map<long, long> mpr;
    for (long i=0; i<n; i++) {
        cin >> a[i];
        mpl[i + 1 + a[i]]++;
        mpr[i + 1 - a[i]]++;
    }
    for (long i=0; i<n; i++) {
        ans += (mpl[i] * mpr[i]);
    }
    cout << ans << endl;
}

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

int main() {

int K, N;
string S;
cin >> N >> K >> S;

K--;
if( S.at(K) == 'A' ) {
S.at(K) = 'a';
}else if( S.at(K) == 'B' )  {
S.at(K) = 'b';
}else {
S.at(K) = 'c';
}

cout  << S << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define N 20
#define oo 1e9
#define For(i,x,y) for(int i=x;i<=y;i++)
#define Rep(i,x,y) for(int i=x;i<y;i++)
#define mp make_pair
#define pa pair<ll,int>
using namespace std;
inline int read(){
	int x=0,f=0;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-48;
	return f?-x:x;
}
int n,m,G[N][N],f[1<<N][N],s[1<<N],sum;
int main(){
	n=read();m=read();
	For(i,1,m){int x=read()-1,y=read()-1;G[x][y]=G[y][x]=read();sum+=G[x][y];}
	Rep(i,0,1<<n) Rep(j,0,n) if((i>>j)&1) Rep(k,j+1,n) if((i>>k)&1) s[i]+=G[j][k];
	Rep(i,0,1<<n) Rep(j,0,n) f[i][j]=-oo;
	Rep(i,0,1<<n) if(i&1) f[i][0]=s[i];
	Rep(i,0,1<<n) Rep(j,0,n) if((i>>j)&1) for(int k=i;k;k=(k-1)&i) if(k&1) Rep(l,0,n) if(((k>>l)&1)&&((~k>>j)&1)&&G[l][j]) f[i][j]=max(f[i][j],f[k][l]+G[l][j]+s[i^k]);
	printf("%d\n",sum-f[(1<<n)-1][n-1]);
	return 0;
}

Measured memory_bytes: 4480
#include<iostream>
using namespace std;
int main(){
  string s;
  cin >> s;
  int N = s.size();
  int fr, ed;
  fr = s.find("A");
  for(int i= 0; i < N; i ++){
    if(s[i] == 'Z') ed = i;
  }
  cout << ed +1 -fr << endl;
}

Measured memory_bytes: 640
import sys

input = sys.stdin.readline

def main():
    N, K, Q = map(int, input().split())
    a = [K-Q]*N
    for _ in range(Q):
        a[int(input())-1] += 1
    for i in range(N):
        if a[i] > 0:
            print('Yes')
        else:
            print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 6620
a, b, c = list(map(int, input().split()))
count = min(b, c)

b -= count
c -= count
count *= 2

if b > c:
    print(count+b)
else:
    tmp = min(a, c)
    a -= tmp
    c -= tmp
    if a == 0 and c > 0:
        print(count+tmp+1)
    else:
        print(count+tmp)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{
	int a,b,n,res=0;
	scanf("%d%d", &a,&b);
	while (a--)
	{
		scanf("%d", &n);
		if (n >= b)
			res++;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

/**
 * Affine Cipher
 */
public class Main {

	static final char[][] hints = {{'t', 'h', 'i', 's'}, {'t', 'h', 'a', 't'}};

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

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

		for (int i = 0; i < n; i++) {
			String s = br.readLine();
			int[] c = cipher(s);
			char[] d = new char['z' + 1];
			for (int j = 0; j < 26; j++) {
				d[(char) (((c[0] * j + c[1]) % 26) + 'a')] = (char) (j + 'a');
			}
			StringBuilder sb = new StringBuilder();
			for (int j = 0; j < s.length(); j++) {
				if (s.charAt(j) == ' ') {
					sb.append(' ');
				} else {
					sb.append(d[s.charAt(j)]);
				}
			}
			System.out.println(sb.toString());
		}
	}

	static int[] cipher(String s) {

		int[] ret = new int[2];

		StringTokenizer st = new StringTokenizer(s);

		while (st.hasMoreTokens()) {

			String w = st.nextToken();

			if (w.length() == 4) {

				char[] hint;

				if (w.charAt(0) != w.charAt(w.length() - 1)) {
					hint = hints[0];
				} else {
					hint = hints[1];
				}

				for (int a = 0; a < 26; a++) {
					if (a % 2 != 0 && a % 13 != 0) {
						for (int b = 0; b < 26; b++) {
							StringBuilder h = new StringBuilder();
							for (int i = 0; i < hint.length; i++) {
								h.append((char) (((a * (hint[i] - 'a') + b) % 26) + 'a'));
							}
							if (w.equals(h.toString())) {
								ret[0] = a;
								ret[1] = b;
								return ret;
							}
						}
					}
				}
			}
		}

		return ret;
	}
}

Measured memory_bytes: 27648
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1e18;
const int INT_INF = 1e9;
const ll MOD = 1e9+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; }
using namespace std;

int n;

int main() {
    cin >> n;
    int n_odd;
    if (n%2==0) n_odd=n/2;
    else n_odd=(n+1)/2;
    double ans = double(n_odd) / double(n);
    cout << ans << endl;
}


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

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	
	string s;
	cin >> s;

	if (s[1] == 'B') s[1] = 'R';
	else s[1] = 'B';

	cout << s << endl;
}


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

using namespace std;

const int MAX_N = 7.4 * 1e6;
int primes[MAX_N + 1]; //i????´???°??????true

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

    while (true)
    {
        int m, n;
        cin >> m >> n;
        if (m == 0 && n == 0)
            break;
        for (int i = 0; i < MAX_N; i++)
            primes[i] = true;
        int count = 0;
        primes[0] = primes[1] = false;
        for (int i = m; i <= MAX_N; i++)
        {
            if (primes[i])
            {
                for (int j = 2 * i; j <= MAX_N; j += i)
                    primes[j] = false;
                count++;
                if (count > n)
                {
                    cout << i << endl;
                    break;
                }
            }
        }
    }
}


Measured memory_bytes: 32044
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define INF 1000000000
typedef pair<int,int>P;
typedef pair<P,int>Q;
vector<int>node[100009];
int min_cost[100009][4];

int main(){
  int n,m,s,t;
  cin>>n>>m;
  for(int i=0;i<=n;i++){
    for(int j=0;j<3;j++){
      min_cost[i][j]=INF;
    }
  }
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    node[a].push_back(b);
  }
  cin>>s>>t;

  priority_queue<Q,vector<Q>,greater<Q> >pq;
  pq.push(Q(P(0,s),0));
  min_cost[s][0]=0;

  while(!pq.empty()){
    Q now=pq.top();pq.pop();
    int cost=now.fi.fi;
    int pos=now.fi.se;
    int mod=now.se;
    int nmod=(mod+1)%3;
    if(nmod==0)cost++;
    for(int i=0;i<node[pos].size();i++){
      int next=node[pos][i];
      if(cost<min_cost[next][nmod]){
        min_cost[next][nmod]=cost;
        pq.push(Q(P(cost,next),nmod));
      }
    }
  }

  if(min_cost[t][0]==INF){
    cout<<-1<<endl;
  }
  else{
    cout<<min_cost[t][0]<<endl;
  }

  return(0);
}


Measured memory_bytes: 7296
MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
ans = (sum(A)%MOD)**2 % MOD
for i in range(N):
  X = (A[i]%MOD)**2 % MOD
  ans = (ans-X)%MOD
ans = ans*pow(2, MOD-2, MOD)%MOD
print(ans)

Measured memory_bytes: 104788
#include <cstdio>
#include <cstdlib>
#include <utility>
#include <typeinfo>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() 
{
	int n;double w;
	while(cin>>n>>w&&!(n==0&&w==0))
	{
		double a[11]={};
		REP(i,n){double b;cin>>b;a[(int)(b/w)]++;}
	
		double haba(0);//横軸が何等分されるか
		double tmp(0);
		REP(i,11){
			tmp+=a[i];
			if(tmp==(double)n){
				haba=i+1;break;
			}
		}
		
		tmp=0;
		REP(i,haba){tmp=max(tmp,a[i]);}
		REP(i,haba){a[i]/=tmp;}
		
		double ans(0.01);
		REP(i,haba-1){ans+=a[i]*(haba-1-i)/(haba-1);}
		
		cout <<fixed << setprecision(7) << ans <<endl;
	}
	return 0;
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;cin>>n;
    vector<int> a;
    a.push_back(0);
    rep(i,n){
        int t;cin>>t;
        a.emplace_back(t);
    }
    a.push_back(0);
    ll sum = 0;
    for(int i=0; i<n+1; i++){
        sum += abs(a[i+1]-a[i]);
    }
    for(int i=1; i<=n; i++){
        ll ans;
        if(a[i-1] < a[i+1]){
            if(a[i]<a[i-1]){
                ans = sum - abs(a[i-1]-a[i]) * 2;
            }else if(a[i-1]<=a[i] && a[i]<=a[i+1]){
                ans = sum;
            }else{
                ans = sum - abs(a[i+1]-a[i])*2;
            }
        }else if(a[i-1]>a[i+1]){
            if(a[i] < a[i+1]){
                ans = sum-abs(a[i+1]-a[i])*2;
            } else if(a[i+1]<=a[i] && a[i]<a[i-1]){
                ans = sum;
            } else{
                ans = sum-abs(a[i-1]-a[i])*2;
            }
        } else{
            ans = sum - abs(a[i+1]-a[i])*2;
        }
        cout<<ans<<endl;
    }
}
// arc093_a

Measured memory_bytes: 1784
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath> // sqrt
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif


#define INF 10000

int main(void) {
    int num; int llimit;
    cin >> num >> llimit;
    vector<pii> arr(num);
    for(int i = 0; i < num; i++) {
        int count, bonus;
        cin >> count >> bonus;
        arr[i] = make_pair(count, bonus);
    }

    int ans = INF;
    for(int pat = 0; pat < (1<<num); pat++) {
        int sum = 0;
        int count = 0;
        for(int bit = 0; bit < num; bit++) {
            if(!(pat & (1<<bit))) continue;
            int point = (bit+1)*100;
            pii p = arr[bit];
            sum += (p.first*point + p.second);
            count += p.first;
        }
        for(int bit = num-1; bit >= 0; bit--) {
            if(pat & (1<<bit)) continue;
            pii p = arr[bit];
            int point = (bit+1)*100;
            int rem = llimit-sum;
            if(rem <= 0) break;
            int cnt = min(p.first, (rem-1)/point + 1);
            count += cnt;
            sum += point*cnt;
        }
        debug("cnt: %d -> %d\n", count, sum);
        if(sum >= llimit) ans = min(ans, count);
    }

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

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
using ll = long long;


int main(){
    ll n,m;
    cin >> n >> m;
    vector<pair<ll,ll>> array(n);
    for(int i=0;i<n;i++){
        cin >> array.at(i).first >> array.at(i).second;
    }
    sort(array.begin(),array.end());
    
    ll money = 0;
    
    for(int i=0;i<n;i++){
        if(m <= array.at(i).second){
            money += array.at(i).first * m;
            break;
        }else{
            money += array.at(i).first * array.at(i).second;
            m -= array.at(i).second;
        }
    }
    cout << money << endl;
}

Measured memory_bytes: 4848
# C - Special Trains
import math

N = int(raw_input())
C, S, F = [0]*(N-1), [0]*(N-1), [0]*(N-1)
for i in range(N-1):
  C[i], S[i], F[i] = map(int, raw_input().split())
result = [0] * N

for station in range(N):
  now = station
  time = 0
  while now != N-1:
    time = S[now] + C[now] if time <= S[now] else int(math.ceil(float(time)/float(F[now])))*F[now] + C[now]
    now += 1
  result[station] = time

for i in result: print i

Measured memory_bytes: 2696
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;

int main(){
    int n;cin>>n;
    vector<int> x(n);
    for(int i=0;i<n;i++){
        cin>>x[i];
    }

    int m=(1<<21);
    for(int i=1;i<=100;i++){
        int sum=0;
        for(int j=0;j<n;j++){
            sum+=(x[j]-i)*(x[j]-i);
        }
        m=min(m,sum);
    }

    cout<<m<<endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc140/tasks/abc140_c
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    int N;
    cin >> N;
    vector<int> B(N - 1);
    REP(i, N - 1) cin >> B[i];
    int ans = B[0] + B[N - 2];
    for (int i = 1; i <= N - 2; ++i)
    {
        ans += min(B[i], B[i - 1]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
#define pri(str) cout << str << endl
using ll = long long;
using P = pair<int, int>;


int main()
{
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    int t1 = h1*60+m1;
    int t2 = h2*60+m2;
    
    pri(t2-k-t1);
    return 0;
}


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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

void solve() {
    //const i64 mod = 1'000'000'007;
    i64 N;
    cin >> N;

    vector<vector<i64>> a(N,vector<i64>(N));
    rep(i,0,N){
        rep(j,0,N){
            cin >> a[i][j];
        }
    }

    const i64 maxN=16;
    static i64 cost[1<<maxN];
    fill_n((i64*)cost,maxN,0);

    rep(s,0,1<<N){
        rep(i,0,N){
            if((s&(1<<i))==0) continue;
            rep(j,i+1,N){
                if((s&(1<<j))==0) continue;
                cost[s]+=a[i][j];
            }
        }
    }

    static i64 memo[1<<maxN];
    static bool done[1<<maxN];
    fill_n((i64*)memo,1<<maxN,-inf64);
    fill_n((bool*)done,1<<maxN,false);

    function<i64(i64)> rec=[&](i64 s){
        auto& res=memo[s];
        if(done[s]) return res;
        done[s]=true;

        if(s==0){
            return res=0;
        }

        i64 t=s;
        do{
            t=(t-1)&s;
            chmax(res,rec(t)+cost[s&~t]);
        }while(t!=s);

        return res;
    };

    cout << rec((1<<N)-1) << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }

void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  set<int> s;
  rep(i, n) s.insert(a[i]);
  if (sz(s) == n) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 10368
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  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];
    }
  }
  ll l[h][w], r[h][w], u[h][w], d[h][w];
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (j == 0) {
        l[i][j] = (s[i][j] == '#' ? 0 : 1);
      } else {
        l[i][j] = (s[i][j] == '#' ? 0 : l[i][j - 1] + 1);
      }
    }
  }
  for (int i = 0; i < h; ++i) {
    for (int j = w - 1; j >= 0; --j) {
      if (j == w - 1) {
        r[i][j] = (s[i][j] == '#' ? 0 : 1);
      } else {
        r[i][j] = (s[i][j] == '#' ? 0 : r[i][j + 1] + 1);
      }
    }
  }
  for (int i = 0; i < w; ++i) {
    for (int j = 0; j < h; ++j) {
      if (j == 0) {
        u[j][i] = (s[j][i] == '#' ? 0 : 1);
      } else {
        u[j][i] = (s[j][i] == '#' ? 0 : u[j - 1][i] + 1);
      }
    }
  }
  for (int i = 0; i < w; ++i) {
    for (int j = h - 1; j >= 0; --j) {
      if (j == h - 1) {
        d[j][i] = (s[j][i] == '#' ? 0 : 1);
      } else {
        d[j][i] = (s[j][i] == '#' ? 0 : d[j + 1][i] + 1);
      }
    }
  }
  ll ans = -1;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      ans = max(ans, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3);
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

const int MAX = 2e5+10;

int arr[MAX];

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

    int n;
    cin >> n;

    int counter = 0;
    for(int i=0; i<n; i++){
        cin >> arr[i];
        if(arr[i] == counter + 1) counter++;
    }

    if(counter) cout << n-counter;
    else cout << -1;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	long long ans = 0;
	int mx = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (x >= mx) {
			mx = x;
		} else {
			ans += mx - x;
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
using namespace std;
int p=0;
string s,t;
int main(){
	cin>>s>>t;
	for(int i=0;i<s.size();i++)
		if(s[i]!=t[i])
			p++;
	cout<<p;
	return 0;
}

Measured memory_bytes: 3820
import java.util.*;

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

Measured memory_bytes: 35664
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	int n;
	vector<int> arr, sol;
	int i, j;
	int input;
	int res;
	
	arr.push_back(0);

	scanf("%d", &n);

	for (i = 0; i < n; i++)
	{
		scanf("%d", &input);

		arr.push_back(input);
	}

	for (i = n / 2; i >= 1; i--)
	{
		res = 0;

		for (j = n / i; j >= 1; j--)
		{
			res = res && !arr[j*i] || !res&&arr[j*i];
		}

		arr[i] = res;
	}

	for (i = 1; i <= n; i++)
	{
		if (arr[i])
		{
			sol.push_back(i);
		}
	}

	printf("%d\n", sol.size());

	for (i = 0; i < sol.size(); i++)
	{
		printf("%d ", sol[i]);
	}

	printf("\n");
	
	return 0;
}

Measured memory_bytes: 2804
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  int n,m,a,b;
  cin >> n >> m >> b >> a;
  R(i,n){
    R(j,m)
      cout << ((i < a) ^ (j < b) ? 1:0);
    cout << "\n";
  }
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>

using namespace std;

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

	string ans;
	for (int i = 0; i < N; ++i) {
		ans += S[i];
		ans += T[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
N = int(input())
edge = [set() for _ in range(N)]
ab = []
for i in range(N-1):
    a, b = inpl()
    a -= 1
    b -= 1
    ab.append((a,b))
    edge[a].add(i)
    edge[b].add(i)

K = 0
ans = [0]*(N-1)
pool = [(0,0)]
while pool:
    node, prev = pool.pop()
    c = 0
    for i in edge[node]:
        c += 1
        if c == prev:
            c += 1
        a, b = ab[i]
        if node == a:
            x = b
        else:
            x = a
        edge[x].remove(i)
        ans[i] = c
        pool.append((x,c))
    if c >= K:
        K = c

print(K)
for i in range(N-1):
    print(ans[i])


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


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    bool ok1 = false, ok2 = false;
    rep(i, S.length()) {
        if(!ok1 && S[i] == 'C') ok1 = true;
        if(ok1 && S[i] == 'F') ok2 = true;
    }
    if(ok1 && ok2) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;
int main()
{
	string s;
	cin >> s;
	int tmp[26] = {0};
	for(int i=0; i<s.size(); i++){
		tmp[s[i] - 'a']++;
	}
	for(int i=0; i<26; i++){
		if(tmp[i] == 0){
			char ans[2] = {'a'};
			for(int j=0; j<i; j++){
				ans[0]++;
			}
			cout << ans[0] << endl;
			return 0;
		}
	}
	cout << "None" << endl;
	
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define pb push_back
#define m 1000000007
ll bigmod(ll a,ll b,ll c){
    if(b==0) return 1;
    if(b%2==0)
    {
        ll x=bigmod(a,b/2,c);
        return ((x%c)*(x%c))%c;
    }
    else return ((a%c) * (bigmod(a,b-1,c)%c))%c;
}
ll ncr(ll n,ll r){
    ll lob=1,hor=1;
    for(ll i=n,j=1;i>=n-r+1&&j<=r;i--,j++){
        lob=(lob*i)%m;
        hor=(hor*j)%m;
    }
    hor=bigmod(hor,m-2,m);
    //cout<<lob<<" "<<hor<<endl;
    return (lob*hor)%m;
}
int main(){
    fast;
    ll n,a,b;
    cin>>n>>a>>b;
    ll u=bigmod(2,n,m);
    a=ncr(n,a);
    b=ncr(n,b);
    //cout<<a<<" "<<b<<endl;
    a=(a+b)%m+1;
    u=(u-a)%m;
    ll ans=(u+m)%m;
    //cout<<ans<<endl;
    if(ans<=0)cout<<'0'<<endl;
    else cout<<ans<<endl;
    return 0;
}


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

std::string A, B;
int main() {
    std::cin >> A >> B;

    int lenA = A.length(), lenB = B.length();

    if(lenA > lenB) {
        std::cout << "GREATER" << std::endl;
    } else if (lenA < lenB) {
        std::cout << "LESS" << std::endl;
    } else {
        int res = A.compare(B);
        if(res > 0) {
            std::cout << "GREATER" << std::endl;
        } else if(res < 0) {
            std::cout << "LESS" << std::endl;
        } else {
            std::cout << "EQUAL" << std::endl;
        }

    }
}

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

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

    int A, B, K; cin >> A >> B >> K;
    for (int i = 100; i >= 1; i--) {
        if (A % i == 0 && B % i == 0) K--;
        if (K == 0) {
            cout << i << "\n";
            break;
        }
    }
}

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

typedef long long ll;

ll addsolve(ll a) {
  return (a+1)/2 % 2;
}

ll solve(ll a) {
  if ( a % 2 == 1 ) return addsolve(a);
  else return addsolve(a+1)^(a+1);
}

int main() {
  ll A,B; cin >> A >> B;
  cout << (solve(B)^solve(A-1)) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>
#include <iomanip>
#include <sstream>
#include <unordered_map>

using namespace std;
typedef long long ll;


ll ans, mx, mn, flag, sum=1, cnt;


int main(){
	ll a,b;
	cin>>a>>b;
	cout<<a*b<<endl;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e5+10;
#define fi first
#define se second
#define pb push_back
LL a,b;
int main() {
    ios::sync_with_stdio(false);
    cin>>a>>b;
    cout<<a*b/__gcd(a,b);
    return 0;
}

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

using namespace std;

int main()
{
    ll n;
    cin>>n;
    ll a[n];
    ll i,j,k,c=0;
    for(i=0;i<n;i++)
      cin>>a[i];
    sort(a,a+n);
   // map<pair<ll,ll>,ll>m;
    for(i=0;i<n-2;i++)
    {
       for(j=i+1;j<n-1;j++)
       {
          for(k=j+1;k<n;k++)
          {

             if(a[k]>(a[i]+a[j]))
               break;
             else if(a[i]<(a[j]+a[k])&&a[j]<(a[i]+a[k])&&a[k]<(a[i]+a[j]))
             {
                 c++;
             }
          }
       }
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
data = n.times.map do
    gets.chomp.split(" ").map(&:to_i)
end

pat = 1

for i in 1..n do
    pat = pat * i
end

distancelist = Array.new()

data.permutation(n) do |arr|
    red = 0.0
    sq = 0
    for j in 1..n-1 do
        x = arr[j - 1][0]
        y = arr[j - 1][1]
        xn = arr[j][0]
        yn = arr[j][1]
        sq = (x - xn)*(x - xn) + (y - yn)*(y - yn)
        red += Math.sqrt(sq)
    end
    distancelist.push(red)
end

result = (distancelist.inject(:+) / pat)
puts result

Measured memory_bytes: 2424