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

#define int long long

string s;
string t = "keyence";

// keyence
bool c1() {
  return s == t;
}

// xxxkeyence
bool c2() {
  int k = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'k') {
      k = i;
      break;
    }
  }

  return s.substr(k, 7) == t;
}

// keyencexxx
bool c3() {
  return s.substr(0, 7) == t;
}

// k...e
bool c4() {
  int front = 0;
  for (int i = 0; i < s.size(); i++) {
    if (i >= t.size()) break;;
    if (t[i] == s[i]) {
      front++;
    } else {
      break;
    }
  }

  int back = 0;
  string rs = s;
  reverse(rs.begin(), rs.end());
  string rt = t;
  reverse(rt.begin(), rt.end());
  for (int i = 0; i < s.size(); i++) {
    if (i >= t.size()) break;;
    if (rt[i] == rs[i]) {
      back++;
    } else {
      break;
    }
  }

  return front + back >= 7;
}

signed main() {
  cin >> s;

  if (c1() || c2() || c3() || c4()) {
    puts("YES");
  } else {
    puts("NO");
  }

  return 0;
}

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

using namespace std;

#define LL long long
#define int long long
#define fi first
#define se second
#define pll pair<LL, LL>
#define pii pair<LL, LL>
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

constexpr int N = 100+5;
constexpr int M = 1e9+7;

// #define DEBUG 1  //调试开关
struct IO {
#define MAXSIZE (1 << 20)
#define isdigit(x) (x >= '0' && x <= '9')
    char buf[MAXSIZE], *p1, *p2;
    char pbuf[MAXSIZE], *pp;

    IO() : p1(buf), p2(buf), pp(pbuf) {}
    ~IO() { fwrite(pbuf, 1, pp - pbuf, stdout); }

    inline char gc() {
        if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin);
        return p1 == p2 ? ' ' : *p1++;
    }
    inline bool blank(char ch) {
        return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
    }
    template <class T>
    inline void read(T &x) {
    double tmp = 1;
    bool sign = 0;
    x = 0;
    char ch = gc();
    for (; !isdigit(ch); ch = gc())
        if (ch == '-') sign = 1;
    for (; isdigit(ch); ch = gc()) x = x * 10 + (ch - '0');
    if (ch == '.')
        for (ch = gc(); isdigit(ch); ch = gc())
        tmp /= 10.0, x += tmp * (ch - '0');
    if (sign) x = -x;
    }
    inline void read(char *s) {
    char ch = gc();
    for (; blank(ch); ch = gc())
        ;
    for (; !blank(ch); ch = gc()) *s++ = ch;
    *s = 0;
    }
    inline void read(char &c) {
    for (c = gc(); blank(c); c = gc())
        ;
    }
    inline void push(const char &c) {
    #if DEBUG  //调试，可显示字符
    putchar(c);
    #else
    if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
    *pp++ = c;
    #endif
    }
    template <class T>
    inline void write(T x) {
    if (x < 0) x = -x, push('-');  // 负数输出
    static T sta[35];
    T top = 0;
    do {
        sta[top++] = x % 10, x /= 10;
    } while (x);
    while (top) push(sta[--top] + '0');
    }
    template <class T>
    inline void write(T x, char lastChar) {
    write(x), push(lastChar);
    }
} io;

int dp[N][N][2];
int n, m;
char a[N][N];

signed main() {
    fastio;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j];
    memset(dp, 0x3f, sizeof(dp));
    if (a[1][1] == '.')
        dp[1][1][0] = 0;
    else
        dp[1][1][1] = 1;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) {
            if (i+1 <= n) {
                if (a[i+1][j] == '.') {
                    dp[i+1][j][0] = min(dp[i+1][j][0], dp[i][j][a[i][j]=='#']);
                } else {
                    dp[i+1][j][1] = min(dp[i+1][j][1], dp[i][j][a[i][j]=='#']+(a[i][j]!='#'));
                }
            }
            if (j+1 <= m) {
                if (a[i][j+1] == '.') {
                    dp[i][j+1][0] = min(dp[i][j+1][0], dp[i][j][a[i][j]=='#']);
                } else {
                    dp[i][j+1][1] = min(dp[i][j+1][1], dp[i][j][a[i][j]=='#']+(a[i][j]!='#'));
                }
            }
        }
    cout << dp[n][m][a[n][m]=='#'] << endl;
    return 0;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace CSharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            string s = ReadString();
            int count = s.Distinct().Count();
            bool ans = count > 1;
            Console.WriteLine(ans ? "Yes" : "No");
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        #endregion
    }
}

Measured memory_bytes: 13152
#include "bits/stdc++.h"
#define INT long long
using namespace std;

int main()
{
    int a[5],b[5];
    char c[5]={'A','B','C','D','E'};
    for(;;){
        for(int i=0;i<5;i++){
            cin >> a[i] >>b[i];
            if(a[i]==0&&b[i]==0) return 0;
        }
        pair<int,char> p[5];
        for(int i=0;i<5;i++){
            p[i]=make_pair(a[i]+b[i],c[i]);
        }
        sort(p,p+5);
        reverse(p,p+5);
        cout << p[0].second << " " << p[0].first << endl;
    }
    return 0;
}



Measured memory_bytes: 3044
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String b = "ABC";
		String r = "ARC";

		if(S.equals(b))
		System.out.println("ARC");
		else if(S.equals(r))
		System.out.println("ABC");
		
	}
}

Measured memory_bytes: 35464
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
	static void Main(string[] args)
	{


		int n = int.Parse(Console.ReadLine());
		int cnt = n;

		for (int i = 0; i < n; i++)
		{


			int num = int.Parse(Console.ReadLine());
			int sprt = (int)Math.Sqrt(num);

			for (int j = 2; j <= sprt; j++)
			{
                
                if (num % j == 0) 
                {
                   cnt--;
                    break;
                }
			}

		}

        Console.WriteLine(cnt);

	

		return;
		//Console.WriteLine("");

	}
}

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

using namespace std;

int n,k;
double ans = 0;

int main()
{
    scanf("%d%d",&n,&k);
    for(int i = 1;i <= n && i < k;i++)
    {
        int cou = 1;
        for(int j = 2 * i;j < k;j *= 2)
        {
            cou++;
        }
        ans += pow(0.5,cou);
    }
    ans /= n;
    if(n >= k)
        ans += (n - k + 1) * 1.0 / n;
    printf("%.10f\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

	
	string S;
	cin >> S;

	int SS = S.size();
	int SH = SS / 2;

	int kotae;

	if (SS % 2) {
		int base = S[SH];
		int tuika = 0;
		rep1(i, SH) {
			if (S[SH + i] != base || S[SH - i] != base) break;
			else tuika++;
		}

		kotae = SH + 1 + tuika;
	}
	else {
		int base = S[SH];
		int tuika = 0;
		rep1(i, SH) {
			if (S[SH + i - 1] != base || S[SH - i] != base) break;
			else tuika++;
		}

		kotae = SH + tuika;
	}

	co(kotae);
	Would you please return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007

 

int main() {
	string s, t; cin >> s >> t;
	for (int i = 0; i < s.length(); i++) {
		if (s == t) {
			print("Yes"); return 0;
		}
		s.insert(s.begin(), s.back());
		s.pop_back();
	}
	print("No");








	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define lli long long int
#include<climits>
#include<unordered_map>
#include<algorithm>
#include<bitset>
#include<map>
#include<cmath>
#include<queue>
#define pb push_back
#define N (int)(1e5)
using namespace std;
using namespace std;
int main()
{
    lli h;
    cin>>h;
    lli ans = 0;
    lli val = 1;
    
    while(h!=0)
    {
        h = h/2;
        ans = ans + val;
        val = val*2;
    }
    
    cout<<ans<<endl;
    
    
    

}



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

int main() {
  int N, P, A[50];
  cin >> N >> P;
  for (int i = 0; i < N; i++) cin >> A[i];
  int even = 0, odd = 0;
  for (int i = 0; i < N; i++) if (A[i] % 2 == 0) even++; else odd++;
  if (!odd&&P == 0) cout << (1ll << N) << endl;
  else if (!odd) cout << 0 << endl;
  else cout << (1ll << (N - 1)) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int Q; cin >> Q;
  while (Q--) {
    V<> deg(100, -1), v(100, -1);
    VV<> g(100);
    auto add_edge = [&](int i, int j) -> void {
      --deg[i], --deg[j];
      g[i].push_back(j);
      g[j].push_back(i);
    };
    int x, t = -1, n = 0;
    bool first = true;
    while (cin >> x, x) {
      if (x > 0) {
        v[++t] = n;
        deg[n] = x;
        if (!first) {
          add_edge(v[t - 1], n);
        }
        ++n;
      } else {
        add_edge(v[t + x], v[t]);
      }
      while (t >= 0 and !deg[v[t]]) {
        --t;
      }
      first = false;
    }
    for (int i = 0; i < n; ++i) {
      sort(begin(g[i]), end(g[i]));
      cout << i + 1;
      for (int e : g[i]) cout << ' ' << e + 1;
      cout << '\n';
    }
  }
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
double dp[303][303][303];
int n,a[4];

int main(){
	cin >> n;
	for(int i = 0 ; i < n ; i += 1){
		int b;
		cin >> b;
		a[b] += 1;
	}
	for(int sum = 1 ; sum <= a[1]+a[2]*2+a[3]*3 ; sum += 1){
		for(int k = 0 ; 3*k <= sum && k <= n ; k += 1){
			for(int j = 0 ; 3*k+2*j <= sum && j <= n ; j += 1){
				int i = sum-2*j-3*k;
				if(i > n){
					continue;
				}
				dp[i][j][k] = ((i > 0 ? i*(1.0+dp[i-1][j][k]) : 0.0) + (j > 0 ? j*(1.0+dp[i+1][j-1][k]) : 0.0) + (k > 0 ? k*(1.0+dp[i][j+1][k-1]) : 0.0) + double(n-i-j-k))/double(i+j+k);
			}
		}
	}
	cout << setprecision(9) << fixed;
	cout << dp[a[1]][a[2]][a[3]] << endl;
}

Measured memory_bytes: 217344
N, W = [int(i) for i in input().split()]
w, v = [0]*N, [0]*N
for i in range(N):
    w[i], v[i] = [int(i) for i in input().split()]

dp = [[-float('inf')]*(W+1) for i in range(N+1)]
for i in range(W+1):
    dp[0][i] = 0

for i in range(1, N+1):
    for j in range(W+1):
        if j >= w[i-1]:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]] + v[i-1])
        else:
            dp[i][j] = dp[i-1][j]
print(dp[N][W])

Measured memory_bytes: 309896
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://atcoder.jp/contests/arc098>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N,K,Q; cin >> N >> K >> Q;
    vector<ll> A(N);
    vector<ll> B(N);
    for(int i = 0 ; i<N;i++){
        cin >> A[i];
    }
    B = A;
    sort(A.begin(),A.end());
    res = LINF;
    for(int i = 0; i < N;i++){
        vector<vector<ll>> vals;
        vector<ll> now;
        for(int j = 0; j < N;j++){
            if(B[j] < A[i]){
                vals.push_back(now);
                now.clear();
            }else{
                now.push_back(B[j]);
            }
        }
        vals.push_back(now);
        
        vector<ll> V;
        for(auto& vec:vals){
            sort(vec.begin(),vec.end());
            int sz = (int)vec.size();
            for(int j = 0; j <= sz-K;j++){
                V.push_back(vec[j]);
            }
        }
        sort(V.begin(),V.end());
        if(V.size() < Q) break;
        res = min(res,V[Q-1] - V[0]);

    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 384
N, M, X, Y = map(int, input().split())
X_list = list(map(int, input().split()))
Y_list = list(map(int, input().split()))

x_max = max(X_list)
y_min = min(Y_list)

war = True
for Z in range(X+1, Y+1):    
    if x_max < Z <= y_min:
        war = False
        break

if war:
    print("War")
else:
    print("No War")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	ll N,A,B; cin>>N>>A>>B;
	vector<ll> X(N);
	for (int i=0; i<N; i++)
		cin>>X[i];
	ll ret=0;
	for (int i=1; i<N; i++)
		ret+=min(B,A*(X[i]-X[i-1]));
	cout<<ret<<"\n";
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<vector<int>> adj;
vector<int> d1, d2, d3, dt;

void dfs(int n, vector<int> &d) {
  for (auto x: adj[n]) {
    if (d[x]==-1) {
      d[x] = d[n]+1;
      dfs(x,d);
    }
  }
}

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

  adj.resize(N);
  rep(i,N-1) {
    int a, b; cin >> a >> b; a--; b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }

  d1.resize(N,-1); d1[0] = 1; dfs(0,d1);
  int far = 0; rep(i,N) if (d1[far]<d1[i]) far = i;
  d2.resize(N,-1); d2[far] = 1; dfs(far,d2);
  int farfar = 0; rep(i,N) if (d2[farfar]<d2[i]) farfar = i;
  d3.resize(N,-1); d3[farfar] = 1; dfs(farfar,d3);
  // debug(d1.begin(),d1.end());
  // debug(d2.begin(),d2.end());
  // debug(d3.begin(),d3.end());

  int maxd = 1; rep(i,N) maxd = max(maxd,d2[i]);
  int od[N]; rep(i,N) od[i] = max(d2[i], d3[i]) - (maxd/2+1);
  // debug(od, od+N);

  int r = (maxd+1)/2;
  ll result = LLINF;
  if (maxd%2) {
    dt.resize(N);
    rep(x,N) {
      if (od[x]!=1) continue;
      dt.assign(N,-1); dt[x] = 1; dfs(x,dt);
      int od2[N]; rep(i,N) od2[i] = min(od[i], dt[i]-1); 
      int ne[r] = {}; 
      rep(i,N) ne[od2[i]] = max(ne[od2[i]], (int)adj[i].size());
      rep(i,r-1) ne[i]--;
      // debug(od2,od2+N); debug(ne,ne+r);
      ll rt = 2; rep(i,r) if (ne[i]) rt *= ne[i];
      result = min(result, rt);
    }
  }
  int ne[r] = {}; 
  rep(i,N) ne[od[i]] = max(ne[od[i]], (int)adj[i].size());
  rep(i,r-1) if (maxd%2==0||i) ne[i]--;
  // debug(od,od+N); debug(ne,ne+r);
  ll rt = maxd%2 ? 1 : 2; rep(i,r) rt *= ne[i];
  result = min(result, rt);

  cout << r << " " << result << endl;
  // rep(i,N) cout << adj[i].size() << " "; cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//g++ -std=c++11 

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7

int main(){
	ll A, B, C;
	cin >> A >> B >> C;
	cout << max(0LL, C - (A-B)) << endl;
}



Measured memory_bytes: 3548
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <set>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)
int main(){
    int N,K;
    ll h[100001], cost[100001];
    cin>>N>>K;
    Rep(i,N) cin>>h[i];
    cost[1] = 0;
    Rep(i,N){
        if(i==1) continue;
        cost[i] = 10000 * 100000;
        for(int j=max(1,i-K);j<i;j++){
            cost[i] = min(cost[j] + abs(h[i] - h[j]), cost[i]);
        }
    }
    cout<<cost[N]<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <cctype>
using namespace std;
const int64_t INF=10000000000000000;
bool month_possible(string s){
    int m=stoi(s);
    return 1<=m&&m<=12;
}
int main(){
    string s;
    cin>>s;
    if(month_possible(s.substr(0,2))){
        if(month_possible(s.substr(2,2))){
            cout<<"AMBIGUOUS"<<endl;
        }else{
            cout<<"MMYY"<<endl;
        }
    }else{
        if(month_possible(s.substr(2,2))){
            cout<<"YYMM"<<endl;
        }else{
            cout<<"NA"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<Long,Long> map = new HashMap<>();
        long ans = 0;
        for(int i = 0; i < n; i++) {
            Long key = sc.nextLong();
            ans += key;
            if(map.containsKey(key)) {
                map.put(key, map.get(key) + 1);
            }else {
                map.put(key, 1l);
            }
        }
        int q = sc.nextInt();
        long[] b = new long[q];
        long[] c = new long[q];
        for (int i = 0; i < q; i++) {
            b[i] = sc.nextInt();
            c[i] = sc.nextLong();
        }
        for (int i = 0; i < q; i++) {
            long key = b[i];
            long val = c[i];
            if(map.containsKey(key)) {
                long diff = map.get(key);
                map.remove(key);
                ans += (val - key) * diff;
                if(map.containsKey(val)) {
                    map.put(val, diff + map.get(val));
                } else {
                    map.put(val, diff);
                }
            }
            System.out.println(ans);
        }
    }
}

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

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

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

    string s; cin >> s;
    int cnt = 0;

    for (int i = 0;i < 15;i++){
        if(i < s.size()){
            if(s[i] == 'o') cnt++;
        }else cnt++;
    }

    if(cnt >= 8) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;

}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N, M int
	var MOD int = 1e9 + 7
	fmt.Scan(&N, &M)
	dp := make([]int, N+1)
	for i := 0; i < M; i++ {
		var a int
		fmt.Scan(&a)

		dp[a] = -1
	}

	dp[0] = 1

	if dp[1] != -1 {
		dp[1] = 1
	}

	for i := 2; i < N+1; i++ {
		var calc int

		if dp[i] == -1 {
			continue
		}

		if dp[i-1] != -1 {
			calc = (calc + dp[i-1]) % MOD
		}

		if dp[i-2] != -1 {
			calc = (calc + dp[i-2]) % MOD
		}

		dp[i] = calc
	}

	ans := dp[N]

	fmt.Println(ans)
}


Measured memory_bytes: 5504
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 5010;
char s[SIZE];
int N;
int dp[SIZE][SIZE];
int main(){
    R(N);
    RS(s+1);
    int an=0;
    FOR(i,1,N){
        FOR(j,i+1,N){
            if(s[i]!=s[j])dp[i][j]=0;
            else{
                dp[i][j]=min(j-i,dp[i-1][j-1]+1);
                an=max(an,dp[i][j]);
            }
        }
    }
    W(an);
    return 0;
}


Measured memory_bytes: 96768
#include<bits/stdc++.h>
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;main(int N){cin>>N;int A[2*N],c[N+1]={},n,t,i;rep(i,2*N)cin>>A[i];rep(i,2*N)c[A[i]]++;if(*max_element(c,c+N+1)>N)printf("No");else{printf("Yes ");queue<int> s;rep(i,N)if(A[i]==A[N+i])s.push(i);while(!s.empty()){n=s.front(),t=N+rand()%N;s.pop();if(A[n]!=A[t]&A[t-N]!=A[n+N])swap(A[n+N],A[t]);else s.push(n);}rep(i,N)cout<<A[i+N]<<" ";}}

Measured memory_bytes: 6852
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

long long N;
string S;
int P = 2019;

long long solve() {
    if (P == 2 || P == 5) {
        long long res = 0;
        for (int i = 0; i < N; ++i) if ((S[N-i-1]-'0') % P == 0) res += N-i;
        return res;
    }
    vector<long long> val(P, 0);
    long long tenfactor = 1;
    long long cur = 0;
    val[cur]++;
    for (int i = 0; i < N; ++i) {
        cur = (cur + (S[N-i-1]-'0') * tenfactor) % P;
        tenfactor = (tenfactor * 10) % P;
        val[cur]++;
    }
    long long res = 0;
    for (int p = 0; p < P; ++p) res += val[p] * (val[p] - 1) / 2;
    return res;
}

int main() {
    cin >> S;
    N = S.size();
    cout << solve() << endl;
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  LL A, B, K;
  cin >> A >> B >> K;
  LL ta=A;
  A = max(0LL, A - K);
  K-=ta;
  if (K > 0) {
    B = max(0LL, B - K);
  }
  cout << A << " " << B << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;
ll mod=1e9+7;
ll d;
int n,x;
ll dp[2001][2001];

long long ex(long long a,long long e){
	if(e==0) return 1;
	long long tmp=ex(a,e/2);
	tmp*=tmp;
	tmp%=mod;
	if(e%2==1) tmp*=a;
	tmp%=mod;
	return tmp;
}

long long inv(long long a){
	return ex(a,mod-2);
}

int main(){
	while(true){
		cin>>n>>d>>x;
		if(n==0) break;
		dp[0][0]=1;
		rep1(i,min(d,(ll)n)){
			rep1(j,n){
				dp[i][j]=dp[i][j-1]+dp[i-1][j-1];
				if(j-x>=0) dp[i][j]-=dp[i-1][j-x];
				dp[i][j]=(dp[i][j]+mod)%mod;
			}
		}
		ll c=1,ans=0;
		rep(i,min((ll)n,d)+1){
			ans+=dp[i][n]*c;
			ans%=mod;
			c=c*((d-i)%mod)%mod*inv(i+1)%mod;
			c%=mod;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 32432
#include <iostream>

int main() {
int n, x;
int sum, count;

do{
count = 0;
std::cin >> n >> x;
for(int i = 0; i < n; i++){
for(int j = 1+i; j < n; j++){
for(int k = 1+j; k < n; k++){
sum = (n-i)+(n-j)+(n-k);
if(sum == x) {
count += 1;
}
}
}
}
if(!(n == 0 && x == 0)){
std::cout << count <<std::endl;
}
} while(!(n == 0 && x == 0));
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int A,B;
    cin>>A>>B;
    if(A==1&&B==3){cout<<2<<endl;}
    if(A==3&&B==1){cout<<2<<endl;}
    if(A==2&&B==3){cout<<1<<endl;}
    if(A==3&&B==2){cout<<1<<endl;}
    if(A==1&&B==2){cout<<3<<endl;}
    if(A==2&&B==1){cout<<3<<endl;}
    return 0;
}

Measured memory_bytes: 256
gcd=list(map(int,input().split()))

if gcd[0]<gcd[1]:
	gcd[0],gcd[1]=gcd[1],gcd[0]
while gcd[1]>0:
	r=gcd[0]%gcd[1]
	gcd[0]=gcd[1]
	gcd[1]=r
print(gcd[0])



Measured memory_bytes: 5600
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"

const ll MOD = 1000000007;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  std::string s;
  std::cin>>s;
  char prev=s[0];
  ll slen=s.size(),ans=s.size();
  rep(i,1,slen){
    if(prev!=s[i]){
      ans=std::min(ans,std::max(i,slen-i));
      prev=s[i];
    }
  }
  if(slen==1){
    std::cout<<1;
  }else{
    std::cout<<ans;
  }
  return 0;
}

Measured memory_bytes: 512
from collections import deque
h,w=map(int,input().split())
a=[input() for _ in range(h)]
dxy=[(0,1),(1,0),(-1,0),(0,-1)]
inf=float("inf")

dp=[[inf]*w for _ in range(h)]
q=deque()

for y,l in enumerate(a):
    for x,c in enumerate(l):
        if c=="#":
            dp[y][x]=0
            q.append((x,y))
ans=0
while q:
    x,y=q.popleft()
    d=dp[y][x]
    for dx,dy in dxy:
        nx,ny=x+dx,y+dy
        if not 0<=nx<w: continue
        if not 0<=ny<h: continue
        if dp[ny][nx]<=d+1: continue
        dp[ny][nx]=d+1
        q.append((nx,ny))
        ans=max(ans,d+1)
print(ans)


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

struct Node {
    int key;
    struct Node *right, *left, *parent;
};
typedef struct Node Node;

Node *root, *NIL;

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;
    
    z = (Node *)malloc(sizeof(Node));
    z->key   = k;
    z->left  = NIL;
    z->right = NIL;
    
    while(x != NIL) {
        y = x;
        if(z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    
    z->parent = y;
    if(y == NIL) {
        root = z;
    } else {
        if( z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

Node * find(Node *u, int k) {
    while(u != NIL && k != u->key) {
        if(k < u->key) u = u->left;
        else u = u->right;
    }
    return u;
}

void inorder(Node *u) {
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node *u) {
    if(u == NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}
    
int main(void) {
    int n, i, x;
    char com[16];
    scanf("%d",&n);
    
    for(i=0;i<n;i++) {
        scanf("%s",com);
        if(com[0] == 'f') {
            scanf("%d",&x);
            Node *t = find(root,x);
            if(t != NIL) printf("yes\n");
            else printf("no\n");
        } else if(!strcmp(com,"insert")) {
            scanf("%d",&x);
            insert(x);
        } else if(!strcmp(com,"print")) {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}


Measured memory_bytes: 20612
#include <bits/stdc++.h>
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define vll vector< ll >
//#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define fo(i,a,b) for(int i = a; i<= b; ++i)
#define pii pair<int,int>
#define vec(a) vector<a >
#define all(a) a.begin(),a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
//#define int unsigned long long
//#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long  
#define int long long
using namespace std;
//using ll = unsigned long long;
ll md=MD;
//ll M=1073741824;
ll M=1e9+7;
//ll exp(ll a,ll b){ll r=1;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll Min(int a,int b){if(a<b)return a; return b;}
ll Max(int a,int b){if(a>b)return a; return b;}
ll powM(ll a,ll b){if(a==1) return 1;ll ans=1;while(b>0){if(b&1)ans=(ans*a)%M;a=(a*a)%M;b=b>>1;}return ans;}
ll power(ll a,ll b){if(a==1) return 1;ll ans=1;while(b>0){if(b&1)ans=(ans*a);a=(a*a);b=b>>1;}return ans;}
const int INF=1000000000000000000;

//always try to hack ur soln before submitting (penalty-50 wrong submission 50 min sochle isse aacha)
// Abe n*m ke grid main y ke coordinates m se akm hone chahiye na ke n se 
int row[6],col[6],ans=0;

		vector<string > v(6);
		int n,m,k;
void fun(int x,int y)
{
	int x1=x,y1=y;
	for(int i=0;i<6;++i)row[i]=col[i]=0;
	int cnt=0;
	while(x>0)
	{
		if(x&1) row[cnt]=1;
		x=x>>1;
		++cnt;
	}
	cnt=0;
	while(y>0)
	{
		if(y&1) col[cnt]=1;
		y=y>>1;
		++cnt;
	}
	cnt=0;
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<m;++j)
		{
			if(!(row[i] || col[j]) && (v[i][j]=='#'))++cnt;
		}
	}
//	db3(cnt,x1,y1);
	if(cnt==k)
	{
		
		++ans;
	}
}


int32_t main()
{
	IOS;
	int t;
//	cin>>t;
	t=1;
	while(t--)
	{
		cin>>n>>m>>k;
		v.resize(n);
		for(int i=0;i<n;++i)cin>>v[i];
		
		for(int i=0;i<power(2,n);++i)
		{
			for(int j=0;j<power(2,m);++j)
			{
				fun(i,j);
			}
		}
		cout<<ans<<"\n";
	}
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
using namespace std;
unsigned long long N;
string out;

int main()
{
    cin>>N;
    out = "";
    while (N>0){

        N = N - 1;
        out = char(97 + (N % 26))+out;
        N = N / 26;
    }

    cout<<out<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;

template<class T> void chmin(T &a, T b) { a = min(a, b); }
template<class T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
    lint n;
    cin >> n;

    vector<P> lr(n);
    for(auto& elem : lr) cin >> elem.first >> elem.second;

    P rmin = {1e18, 1e18};
    for(auto& elem : lr) {
        if(elem.second < rmin.second) rmin = elem;
    }
    auto it = find(lr.begin(), lr.end(), rmin);
    lr.erase(it);
    n = lr.size();

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

    vector<P> dp1(n+1, {-1e18, 1e18}), dp2(n+1, {-1e18, 1e18});
    dp1[0] = rmin;
    for(lint i=0; i<n; i++) {
        chmax(dp1[i+1].first, dp1[i].first);
        chmin(dp1[i+1].second, dp1[i].second);

        chmax(dp1[i+1].first, lr[i].first);
        chmin(dp1[i+1].second, lr[i].second);
    }

    dp2[0] = {-1e18, 1e18};
    for(lint i=0; i<n; i++) {
        chmax(dp2[i+1].first, dp2[i].first);
        chmin(dp2[i+1].second, dp2[i].second);

        chmax(dp2[i+1].first, lr[n-i-1].first);
        chmin(dp2[i+1].second, lr[n-i-1].second);
    }

    lint ans = -1e18;

    // [0, i) と [i, n) で分割する場合
    for(lint i=0; i<n; i++) {
        lint s1 = max(-1LL, dp1[i].second - dp1[i].first);
        lint s2 = max(-1LL, dp2[n-i].second - dp2[n-i].first);
        chmax(ans, s1+s2+2);
    }

    // i番目を除く場合
    for(lint i=0; i<n; i++) {
        auto left = dp1[i];
        auto right = dp2[n-i-1];
        lint l = max(left.first, right.first);
        lint r = min(left.second, right.second);
        lint s1 = max(-1LL, r-l);
        lint s2 = max(-1LL, lr[i].second - lr[i].first);
        chmax(ans, s1+s2+2);
    }

    cout << ans << endl;
}

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

int main(){
  char c;
  cin >> c;
  if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o'){
    cout << "vowel";
  }
  else{
    cout << "consonant";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;

class MainClass
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int counter = 0;
        for (int i = 0; i < n; i++)
        {
            if (isPrime(int.Parse(Console.ReadLine()))) {
                counter++;
                }

        }
        Console.WriteLine(counter);
    }

    static private bool isPrime(int a)
    {
        if (a == 2) return true;
        if (a < 2 || a % 2 == 0)
        {
            return false;
        }

        int i = 3;
        while (i <= Math.Sqrt(a))
        {
            if (a % i == 0)
            {
                return false;
            }
            i = i + 2;
        }

        return true;

        
    }
}




Measured memory_bytes: 15868
// D.

#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[]) {
	const LL n = 50;
	LL k;
	cin >> k;

	LL a[n];
	fill(a, a + n, k / n + n - 1);
	for (LL i = 0; i < k % n; ++i) {
		int t = i % n;
		for (int j = 0; j < n; ++j) {
			if (t == j) {
				a[j] += n;
			} else {
				a[j] -= 1;
			}
		}
	}

	cout << n << endl;
	for (int i = 0; i < n; ++i) {
		if (i) {
			cout << " ";
		}
		cout << a[i];
	}
	cout << endl;
}


Measured memory_bytes: 256
void main() {
	auto S = rs.to!dstring;
	auto Q = ri;
	dstring right, left;
	bool flip = false;
	foreach(i; 0..Q) {
		auto ip = readln.split, T = ip[0];
		if(T == "1") {
			flip = !flip;
			continue;
		} else {
			auto F = ip[1].to!int, C = ip[2][0];
			if((F + flip + 1)  % 2) {
				right ~= C;
				debug writefln("right: %s", C);
			}
			else {
				left ~= C;
				debug writefln("left: %s", C);
			}
		}
	}
	dstring res = left.retro.array ~ S ~ right;
	if(flip) writeln(res.retro);
	else writeln(res);
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

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

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

  ll N; cin >> N;
  vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i];
  ll m = A[0];
  ll ans = 0;
  for (ll i = 1; i < N; i++) {
    m = max(m, A[i]);
    ans += (0, m - A[i]);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 4772
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+7;
int a[maxn],b[maxn],n,c[maxn];
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n;
    ll t = 0;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i],c[i] = b[i]-a[i],t += c[i];
    if(t>0)
        return cout<<-1<<endl,0;
    t = 0;/// remain time
    sort(c,c+n);
    int l = 0,ans = 0;
    for(int r=n-1;~r&&c[r]>0;r--){
        while(l<r && t<c[r])
            t -= c[l++],ans++;
        t -= c[r];
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll H, W;
    cin >> H >> W;
    vector<string> s(H);
    rep(i, H) cin >> s[i];

    ll sx = 0, sy = 0;
    ll gx = W - 1, gy = H - 1;

    ll INF = 1e18;
    vector<vector<ll>> d(H, vector<ll>(W, INF));
    
    typedef pair<ll, ll> P;
    queue<P> que;
 
    que.push(P(sx, sy));
    d[sy][sx] = 0;

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

    while (que.empty() == false) {
        P q = que.front();
        ll x = q.first;
        ll y = q.second;
        que.pop();

        rep(i, 4) {
            ll x2 = dx[i] + x;
            ll y2 = dy[i] + y;
            if (x2 < 0 || W <= x2 || y2 < 0 || H <= y2) {
                continue;
            }
            if (d[y2][x2] != INF) {
                // already visited
                continue;
            }
            if (s[y2][x2] == '.') {
                d[y2][x2] = d[y][x] + 1;
                que.push(P(x2, y2));
            }
        }
    }
    
    ll cost = d[gy][gx];
    if (cost == INF) {
        put(-1);
        return;
    }

    ll black = 0;
    rep(i, s.size()) {
        rep(j, s[i].size()) {
            if (s[i][j] == '#') {
                black++;
            }
        }
    }

    ll res = H * W - black - cost - 1;
    put(res);

}
signed main(){ Main();return 0;}

Measured memory_bytes: 3660
#include <stdio.h>

int main(void){
    int H, W, A, B, i, j, S[1005];
    scanf("%d%d%d%d", &H, &W, &A, &B);
    for (i=1; i<=W; i++) {
        if (i<=W-A) S[i]=1;
        else S[i]=0;
    }
    for (i=1; i<=H-B; i++) {
        for (j=1; j<=W; j++) printf("%d", S[j]);
        printf("\n");
    }
    for (i=1; i<=W; i++) {
        if (i<=W-A) S[i]=0;
        else S[i]=1;
    }
    for (i=1; i<=B; i++) {
        for (j=1; j<=W; j++) printf("%d", S[j]);
        if (i!=B) printf("\n");
    }
    return 0;
}


Measured memory_bytes: 1152
n = int(input())
a = list(int(i) for i in input().split())

number = 1
break_countr = 0

for k in range(n):
  if(a[k] == number):
    number += 1
  else:
    break_countr += 1

if(number == 1):
  if(1 not in a):
    print(-1)
  else:
    print(break_countr)
else:
  print(break_countr)

Measured memory_bytes: 24792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n,m,x;
    cin >> n >> m >> x;
    int a[m];
    rep(i,m)cin >> a[i];
    int cnt = 0;
    rep(i,m){
        if(a[i] < x)cnt++;
        else break;
    }
    cout << min(cnt,m-cnt) << endl;
    return 0;
}

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

int main() {
   #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
 ios_base::sync_with_stdio(0);
 cin.tie(0);
 cout.tie(0);
 ll t,a,b; cin>>t;
 ll x=1,y=1; 
 while(cin>>a>>b){

 
    ll da=((x-1)/a)+1;
    ll db=((y-1)/b)+1;
    ll dc=max(da,db);
    x=a*dc; y=b*dc;
  
  
 }
 cout<<x+y<<endl;
 return 0;
}


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

using namespace std;

int main(){
  int K,sum=0;
  cin >>K;
  
  for(int a=1;a<=K;a++){
  for(int b=1;b<=K;b++){
  for(int c=1;c<=K;c++){
    for(int i=min((a,b),c);i>0;i--){
      if(a%i==0 && b%i==0 && c%i==0){
        sum+=i;
        break;
      }
    }
  }
  }
  }
  cout << sum << endl;
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}


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

    size_t N, M, R;
    cin >> N >> M >> R;

    vector<int> r(R);
    for (auto &ri: r) {
        cin >> ri; ri--;
    }
    sort(r.begin(), r.end());

    vector<int> g[N];
    auto cost = make_v(0LL, N, N);
    for (size_t i = 0; i < M; ++i) {
        int a, b, c; cin >> a >> b >> c;
        a--, b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
        cost[a][b] = cost[b][a] = c;
    }

    auto dist = make_v(LINF, N, N);
    for (auto &ri: r) {
        queue<int> que;
        que.emplace(ri);

        dist[ri][ri] = 0;

        while (!que.empty()) {
            int now = que.front();
            que.pop();
            for (auto next: g[now]) {
                if (chmin(dist[ri][next], dist[ri][now] + cost[now][next])) {
                    que.emplace(next);
                }
            }
        }
    }

    intmax_t minv = LINF;
    do {
        intmax_t sum = 0;
        for (size_t i = 0; i < R - 1; ++i) {
            sum += dist[r[i]][r[i + 1]];
        }
        chmin(minv, sum);
    } while (next_permutation(r.begin(), r.end()));

    cout << minv << "\n";

    return 0;
}


Measured memory_bytes: 1152
import bisect

N = int(input())
aList = [0] * N
for i in range(N):
    aList[i] = int(input())

maxTmp = max(aList)
tmpList = sorted(aList, reverse=True)
max2Tmp = tmpList[1]
maxCnt = aList.count(maxTmp)
ansList = [0] * N

for i in range(N):
    if aList[i] == maxTmp:
        if maxCnt > 1:
            for j in range(N):
                ansList[j] = maxTmp
            break
        else:
            ansList[i] = max2Tmp

    else:
        ansList[i] = maxTmp

for i in ansList:
    print(i)

Measured memory_bytes: 15676