akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const long long INF=1e15;
struct Tree{
	long long mn1,mn2;
	long long add;
}T[800010];
void update(int root)
{
	T[root].mn1=min(T[root<<1].mn1,T[root<<1|1].mn1);
	T[root].mn2=min(T[root<<1].mn2,T[root<<1|1].mn2);
	return ;
}
void add(int root,long long x)
{
	T[root].add+=x;
	T[root].mn1+=x;
	T[root].mn2+=x;
	return ;
}
void pushdown(int root)
{
	add(root<<1,T[root].add);
	add(root<<1|1,T[root].add);
	T[root].add=0;
	return ;
}
void build(int root,int l,int r)
{
	if(l==r){
		T[root].mn1=T[root].mn2=INF;
		return ;
	}
	int mid=(l+r)>>1;
	build(root<<1,l,mid);
	build(root<<1|1,mid+1,r);
	update(root);
	return ;
}
void Add(int root,int l,int r,int x,int y,int z)
{
	if(x>y)return ;
	if(x<=l&&r<=y){
		add(root,z);
		return ;
	}
	int mid=(l+r)>>1;
	pushdown(root);
	if(x<=mid)Add(root<<1,l,mid,x,y,z);
	if(y>mid)Add(root<<1|1,mid+1,r,x,y,z);
	update(root);
	return ;
}
void modify(int root,int l,int r,int x,long long z)
{
	if(l==r){
		z=min(z,T[root].mn1+l);
		T[root].mn1=z-l;
		T[root].mn2=z+l;
		return ;
	}
	int mid=(l+r)>>1;
	pushdown(root);
	if(x<=mid)modify(root<<1,l,mid,x,z);
	else modify(root<<1|1,mid+1,r,x,z);
	update(root);
	return ;
}
long long query1(int root,int l,int r,int x,int y)
{
	if(x<=l&&r<=y)return T[root].mn1;
	int mid=(l+r)>>1;
	pushdown(root);
	long long ans=INF;
	if(x<=mid)ans=min(ans,query1(root<<1,l,mid,x,y));
	if(y>mid)ans=min(ans,query1(root<<1|1,mid+1,r,x,y));
	update(root);
	return ans;
}
long long query2(int root,int l,int r,int x,int y)
{
	if(x<=l&&r<=y)return T[root].mn2;
	int mid=(l+r)>>1;
	pushdown(root);
	long long ans=INF;
	if(x<=mid)ans=min(ans,query2(root<<1,l,mid,x,y));
	if(y>mid)ans=min(ans,query2(root<<1|1,mid+1,r,x,y));
	update(root);
	return ans;
}
long long query(int root,int l,int r,int x)
{
	if(l==r)return T[root].mn1+l;
	int mid=(l+r)>>1;
	pushdown(root);
	if(x<=mid)return query(root<<1,l,mid,x);
	else return query(root<<1|1,mid+1,r,x);
}
int x[200010];
int main()
{
	int n,q,a,b;
	scanf("%d %d %d %d",&n,&q,&a,&b);
	build(1,1,n);
	x[0]=a;
	modify(1,1,n,b,0);
	for(int i=1;i<=q;i++)
	{
		scanf("%d",&x[i]);
		long long val;
		val=query1(1,1,n,1,x[i])+x[i];
		val=min(val,query2(1,1,n,x[i],n)-x[i]);
		int dis=abs(x[i]-x[i-1]);
		Add(1,1,n,1,n,dis);
		modify(1,1,n,x[i-1],val);
	}
	long long ans=INF;
	for(int i=1;i<=n;i++)
		ans=min(ans,query(1,1,n,i));
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 14720
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var k = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine(a.Sum(x => Min(x, k - x)) * 2);
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll int mod = 1000000007;
int main(){
  int n;
  cin >> n;
  string s = "ACGT";
  map<string, ll int> m[100];
  REP(i1, 4){
    REP(i2, 4){
      REP(i3, 4){
        string t = "xxx";
        t[0] = s[i1];
        t[1] = s[i2];
        t[2] = s[i3];
        m[0][t] = 1;
        if(t == "AGC") m[0][t] = 0;
        if(t == "GAC") m[0][t] = 0;
        if(t == "ACG") m[0][t] = 0;
      }
    }
  }
  FOR(i, 1, n - 3 + 1){
    for(auto itr = m[i-1].begin(); itr != m[i-1].end(); itr++){
      string status = itr->first;
      ll int val = itr->second;
      REP(j, 4){
        string nextstatus = status + s[j];
        string usiro3 = nextstatus.substr(1, 3);
        // cout << usiro3 << endl;
        if(usiro3 == "AGC" || usiro3 == "GAC" || usiro3 == "ACG") continue;
        if(s[j] == 'C' && status[0] == 'A' && status[1] == 'G') continue;
        if(s[j] == 'C' && status[0] == 'A' && status[2] == 'G') continue;
        if(m[i].count(usiro3) == 0) m[i][usiro3] = val;
        else m[i][usiro3] = (m[i][usiro3] + val) % mod;
        // cout << nextstatus << endl;
        // cout << m[usiro3] << endl;
      }
    }
    // m = newmap;
  }
  ll int ans = 0;
  for(auto itr = m[n - 3].begin(); itr != m[n - 3].end(); itr++){
    ll int d = itr->second;
    // cout << d << endl;
    ans = (ans + d) % mod;
  }
  cout << ans << endl;

}

Measured memory_bytes: 896
if __name__ == "__main__":
    N = int(input())
    #A = []
    d = {}
    for i in range(N):
        Ai = int(input())
        if Ai in d.keys():
            d[Ai] = not d[Ai]
        else:
            d[Ai] = True
    
    ans = 0
    for item in d.items():
        if item[1]:
            ans += 1
    
    print(ans)

Measured memory_bytes: 15072
S = input()
s_len = len(S)

s_kigo_map = [] # [[0,1],[1,2]] 0 = < , 1 = >
init_s = S[0]
right_count = 0
left_count = 0
max_len = 0
if S[0] == '<':
    s_num = 0
else:
    s_num = 1
s_count = 1
for i in range(1,s_len):
    if S[0] == '<':
        right_count += 1
    else:
        left_count += 1
    if init_s == S[i]:
        s_count += 1
    else:
        if max_len < s_count:
            max_len = s_count
        s_kigo_map.append([s_num,s_count])
        if S[i] == '<':
            s_num = 0
        else:
            s_num = 1
        init_s = S[i]
        s_count = 1
s_kigo_map.append([s_num,s_count])

next_num = 0
sum_num = 0

i = 0
if len(s_kigo_map) == 1:
    sum_num += (0 +s_kigo_map[i][1] )*(s_kigo_map[i][1]+1)//2
    print(sum_num)
else:
    if s_kigo_map[i][0] == 0: # <の時
        if s_kigo_map[i][1] >= s_kigo_map[i+1][1]:
            sum_num += (0 +s_kigo_map[i][1] )*(s_kigo_map[i][1]+1)//2
            #next_num = next_num + s_kigo_map[i][0]
        else: # `差分を増やす必要がある`
            sum_num += ( (0 +s_kigo_map[i][1] )*(s_kigo_map[i][1]+1)//2 )+ ( s_kigo_map[i+1][1] - s_kigo_map[i][1])
            #next_num = next_num + s_kigo_map[i+1][0] 
    else:  # >の時
        sum_num += (0 +s_kigo_map[i][1] )*(s_kigo_map[i][1]+1)//2
        #next_num = 0

    for i in range(1,len(s_kigo_map)):
        if s_kigo_map[i][0] == 0: # <の時
            if i == len(s_kigo_map) -1:
                sum_num += (1 +s_kigo_map[i][1] )*s_kigo_map[i][1]//2
                break
            if s_kigo_map[i][1] >= s_kigo_map[i+1][1]:
                sum_num += (1 +s_kigo_map[i][1] )*s_kigo_map[i][1]//2
                #next_num = next_num + s_kigo_map[i][0]
            else: # `差分を増やす必要がある`
                sum_num += ( (1 +s_kigo_map[i][1])*s_kigo_map[i][1]//2 ) + ( s_kigo_map[i+1][1] - s_kigo_map[i][1])
                #next_num = next_num + s_kigo_map[i+1][0] 
        else:  # >の時
            sum_num += (s_kigo_map[i][1] - 1 )*(s_kigo_map[i][1])//2
            #next_num = 0
    print(sum_num)

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

int main() {
	int H, W, K;
	scanf("%d %d %d", &H, &W, &K);
	char c[H][W];
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) scanf(" %c", &c[i][j]);
	}
	int ans = 0;
	rep(i,1<<H){
		rep(j,1<<W){
			int block=0;
			rep(k,H){
				rep(l,W){
					if(c[k][l]=='#' && (i & (1<<k)) && (j & (1<<l))) block++;
				}
			}
			if(block==K)ans++;
		}
	}	
	
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 3740
N = int(input())
H = list(map(int, input().split()))
dp = [float('inf')]*N
dp[0] = 0
dp[1] = abs(H[0]-H[1])
for i in range(2, N):
    dp[i] = min(dp[i-1]+abs(H[i]-H[i-1]), dp[i-2]+abs(H[i]-H[i-2]))

print(dp[N-1])


Measured memory_bytes: 13928
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

ll MOD = 1000000007;
ll lcm(ll a, ll b) { return (a / __gcd(a, b) * b); }

int main() {
  //
  string s;
  cin >> s;
  int cnt = 0;
  REP(i, 1, s.size()) {
    if (s[i] != s[i - 1]) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    ll a=0,b=0,k=1,s=0,n,w,m,min=100000000000,ans=1,max=0;
    string s1,s2;
    cin >> s1 >> s2;
    if (s1.size()>s2.size()){
        cout << "GREATER" << endl;
    }
    else if (s1.size()<s2.size()){
        cout << "LESS" << endl;
    }
    else if (s1==s2){
        cout << "EQUAL" << endl;
    }
    else {
        for(int i=0;i<s1.size();i++){
            if (s1[i] > s2[i]){
                cout << "GREATER" << endl;
                return 0;
            }
            else if (s1[i] == s2[i]){
               continue;
            }
            else {
                cout << "LESS" << endl;
                return 0;
            }
        }   

    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long A,B;
main()
{
    cin>>A>>B;
    long long ans=0;
    while(A%4!=0&&A<B)ans^=A++;
    while(B%4!=3&&A<B)ans^=B--;
    if(0<=B-A&&B-A<4)ans^=A++;
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;

struct Date {
	int y;
	int m;
	int d;
};

bool isAllBigMonth(int y) {
	return y % 3 == 0;
}

int hasDayOfMonth(int m, int y) {
	if (isAllBigMonth(y)) {
		return 20;
	}else {
		if (m % 2) {
			return 20;
		}else {
			return 19;
		}
	}
}

void addDay(Date &d) {
	if (++d.d > hasDayOfMonth(d.m, d.y)) {
		d.d = 1;
		if (++d.m > 10) {
			d.m = 1;
			++d.y;
		}
	}
}

int diffPremiumDay(Date d) {
	static const Date Premium = {1000, 1, 1};
	int diff = 0;

	while (Premium.y !=d.y || Premium.m != d.m || Premium.d != d.d) {
		addDay(d);
		diff++;
	}

	return diff;
}

int main(void) {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		Date d;
		cin >> d.y >> d.m >> d.d;

		int days = diffPremiumDay(d);
		cout << days << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  string s;
  cin >> s;

  int n = sz(s);

  if (n==1) {
    cout << s[0]-'0' << endl;
    return 0;
  }

  ll ans = 0;
  rep(b,1<<(n-1)) {
    ll cur = s[0]-'0';
    rep(i,n-1) {
      if (b&(1<<i)) {
        ans += cur;
        cur = s[i+1]-'0';
      }
      else {
        cur = 10*cur + s[i+1]-'0';
      }

      if (i == n-2) ans += cur;
    }
  }

  cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, k;
	cin >> n >> k;
	vector <int> v(n);
	for(int i = 0; i < n; i++){
		cin >> v[i];
	}	
	vector <ll> vec(n * (n + 1) / 2 + 1);
	for(int i = 0; i < n; i++){
		ll curr = 0;
		for(int j = i; j < n; j++){
			curr += v[j];
			vec.push_back(curr);
		}
	}
	ll res = 0;
	for(int i = 63; i >= 0; i--){
		int cnt = 0;
		for(auto x : vec){
			if(x & (1LL << i)) cnt++;
		}
		if(cnt >= k){
			res += (1LL << i);
			vector <ll> next;
			for(auto x : vec){
				if(!(x & (1LL << i))) continue;
				next.push_back(x);
			}
			vec = next;
		}
	}
	cout << res;
}

Measured memory_bytes: 10040
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld=long double;
 
int main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    int c=0;
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=0;i<n;i++){
        if(a[i]>=k)
        c++;
    }
    cout<<c;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;};
  Mint operator-(Mint a) const{return Mint(v)-=a;};
  Mint operator*(Mint a) const{return Mint(v)*=a;};
  Mint operator/(Mint a) const{return Mint(v)/=a;};

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  // find x s.t. a^x = b
  static T log(T a,T b){
    const T sq=40000;
    unordered_map<T, T> dp;
    dp.reserve(sq);
    Mint res(1);
    for(Int r=0;r<sq;r++){
      if(!dp.count(res.v)) dp[res.v]=r;
      res*=a;
    }
    Mint p=Mint(a).inv().pow(sq);
    res=b;
    for(Int q=0;q<=MOD/sq+1;q++){
      if(dp.count(res.v)){
        T idx=q*sq+dp[res.v];
        if(idx>0) return idx;
      }
      res*=p;
    }
    assert(0);
    return T(-1);
  }

  static Mint comb(long long n,Int k){
    Mint num(1),dom(1);
    for(Int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}

//INSERT ABOVE HERE
signed main(){
  Int n,k;
  cin>>n>>k;
  vector<Int> as(n);
  for(Int i=0;i<n;i++) cin>>as[i];
  using M = Mint<Int>;

  M ans{0};
  for(Int i=0;i<n;i++){
    Int b=0;
    for(Int j=0;j<i;j++)
      if(as[j]>as[i]) b++;

    Int d=0;
    for(Int j=0;j<n;j++)
      if(as[j]>as[i]) d++;

    // b + dx
    ans+=M(b)*M(k)+M(d)*M(k*(k-1)/2);
  }

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


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

int main() {
	int64_t N, x;
	cin >> N >> x;

	vector<int64_t> v(N);
	int64_t bsum = 0, asum = 0;
	for (int64_t i = 0; i < N; i++) {
		cin >> v.at(i);
		bsum += v.at(i);
	}
	//cout << "bsum:" << bsum << endl;

	for (int64_t i = 0; i < N; i++) {
		if (v.at(i) > x) {
			v.at(i) = x;
		}

		if (i > 0) {
			int64_t n = v.at(i - 1) + v.at(i);
			if (n > x) v.at(i) -= n - x;
		}
	}

	for (int64_t i = 0; i < N; i++) {
		asum += v.at(i);
	}
	//cout << "asum:" << asum << endl;

	cout << bsum - asum << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll gcd(ll a,ll b){
  ll r=a%b;
  while(r>0){
    a=b;
    b=r;
    r=a%b;
  }
  return b;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;cin>>n>>k;
  bool hoge=false;
  ll now;cin>>now;

  ll ma=now;
  if(now==k)hoge=true;
  for(int i=0;i<n-1;i++){
    ll a;cin>>a;
    ma=max(ma,a);
    if(a==k)hoge=true;
    now=gcd(now,a);
  }
  // cout<<now<<endl;
  if(k%now==0&&k<=ma||hoge)cout<<"POSSIBLE"<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
  return 0;
}


Measured memory_bytes: 256
/* Author VS_CODE */

#include<bits/stdc++.h>
#define int long long
#define TCI int t;cin>>t;while(t--)
#define foR(n) for(int i=1;i<=n;i++)
#define For(n) for(int i=0;i<n;i++)
#define ln "\n"
#define vpair vector< pair <int , int > >
#define fr first
#define sc second
#define pb emplace_back
#define vll vector<int>
#define inf INT64_MAX
#define Point complex<double>
using namespace std;

void online()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
/* CODE STARTS HERE */

const int N = 1e5;
int k=1;

void solve ()
{
	int n;
	cin>>n;
	int A[n];
	For(n) cin>>A[i];
	int mx=A[0];
	int ans=0;
	for(int i=1;i<n;i++)
	{
		if(A[i]<mx)
			ans+=mx-A[i];
		mx=max(mx,A[i]);

	}
	cout<<ans<<ln;
}


/* CODE ENDS HERE AND MAIN STaARTS */

int32_t main()
{
	online();
	// TCI
	solve();
}

Measured memory_bytes: 5140
import itertools
N = int(input())
counter = {'AC':0, 'WA':0, 'TLE':0, 'RE':0}
for i in range(N):
    s = input()
    counter[s] += 1
for x in ['AC', 'WA', 'TLE', 'RE']:
    print('{} x {}'.format(x, counter[x]))



Measured memory_bytes: 69992
#include <iostream>
#include <string>
#include <vector>
using namespace std;

void pok() {
  cout << "OK" << endl;
}
void png() {
  cout << "NG" << endl;
}

int main() {
  int N;
  vector<int> digits;
  cin >> N;
  if (N == 0) {
    cout << 0 << endl;
    return 0;
  }

  while(N != 0) {
    if (N % 2 == 0) {
      digits.push_back(0);
      N /= -2;
    } else {
      digits.push_back(1);
      N = (N-1)/(-2);
    }
  }

  for (auto it = digits.rbegin(); it != digits.rend(); it++) {
    cout << *it;
  }
  cout << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<functional>
#include <bitset>
#include<algorithm>
#include<fstream>
#include<string>
#include <cstring>
#include<stdio.h>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<vector>
#include<assert.h>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
// never lose hope ..
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define eps 1e-8
using namespace std;
double const  PI = 3.141592653;
const int OO = 1000000000 + 9;

void fast() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL), cout.tie(NULL);
}


int main()
{
	fast();

	int n;
	cin >> n;
	vector<int>v(n + 1, 0), dp(n + 1, OO);
	for (int i = 1;i <= n;i++) {
		cin >> v[i];
	}
	dp[1] = 0;
	dp[2] = dp[1] + abs(v[1] - v[2]);
	for (int i = 3;i <= n;i++) {
		dp[i] = min(dp[i - 1] + abs(v[i] - v[i - 1]), dp[i - 2] + abs(v[i] - v[i - 2]));
	}
	cout << dp[n];


	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  long int X,money;
  int year;
  scanf("%ld",&X);
  money=100;
  year=0;
  while(money<X){
    money=money*1.01;
    long int(money);
    year++;
  }
  printf("%d\n",year);
  return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const long long int MOD = 1000000007;
const int INF = 1000000000;

int n, m;
bool saw[8000000];

void solve(){
    memset(saw,0,sizeof(saw));
    for(int i = n; i < 8000000; i++){
        if(saw[i]) continue;
        if(m == 0){
            cout << i << endl;
            return;
        }
        m--;
        for(int j = i*2; j < 8000000; j += i){
            saw[j] = true;
        }
    }
}

int main(){
    while(cin >> n >> m){
        if(n == 0 && m == 0) break;
        solve();
    }
}

Measured memory_bytes: 10856
#include<iostream>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
string s;
int n;
ll pref[300001];
ll cnt[300001];
ll p2[300001];
ll cal[300001][2][2];
int main(){
	ios::sync_with_stdio(false);
	cin >> s;
	n=s.size();
	s='1'+s;
	p2[0]=1;
	for(int i=1; i<=n ;i++) p2[i]=p2[i-1]*2%mod;
	pref[1]=(s[1]!='0');
	for(int i=1; i<=n ;i++){
		cnt[i]=cnt[i-1]+(s[i]=='?');
	}
	for(int i=3; i<=n ;i+=2){
		int num=(s[i-1]=='?')+(s[i]=='?');
		int can=(s[i-1]!='0' && s[i]!='0');
		pref[i]=((pref[i-2]*p2[num]+(p2[cnt[i-2]]-pref[i-2])*can)%mod+mod)%mod;
	}
	cal[1][1][1]=1;
	for(int i=3; i<=n ;i+=2){
		cal[i][1][1]=p2[cnt[i-2]];
		cal[i][0][1]=pref[i-2];
		for(int j=0; j<2 ;j++){
			for(int k=0; k<2 ;k++){
				if(s[i-3]!=j+'0' && s[i-2]!=k+'0') cal[i][1][0]=(cal[i-2][1-j][1-k]+cal[i][1][0])%mod;
			}
		}
		for(int j=0; j<2 ;j++){
			for(int k=0; k<2 ;k++){
				if(s[i-3]!=j+'0' && s[i-2]!=k+'0') cal[i][0][0]=(cal[i-2][1-j][0]+cal[i][0][0])%mod;
			}
		}
	}
	ll ans=0;
	for(int j=0; j<2 ;j++){
		for(int k=0; k<2 ;k++){
			if(s[n-1]!=j+'0' && s[n]!=k+'0') ans=(ans+cal[n][1-j][1-k])%mod;
		}
	}
	cout << ans << endl;
}

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

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

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

int main(){
    int n, k;
    cin >> n >> k;
    int m = (n-2) * (n-1) / 2 - k;
    if(m < 0){
        cout << -1 << endl;
    }
    else{
        cout << n - 1 + m << endl;
        for(int i = 2; i <= n; i++){
            cout << 1 << " " << i << endl;
        }
        int c = 0;
        for(int i = 2; i <= n && c < m; i++){
            for(int j = i + 1; j <= n && c < m; j++){
                cout << i << " " << j << endl;
                c++;
            }
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
int b[101];
bool used[101];
vector<int>v;
int main(){
	cin>>N;
	REP(i,N){
		cin>>b[i];
		used[i]=false;
	}
	REP(i,101){
		int now=0;
		int pos=-1;
		REP(j,N){
			if(used[j]==false){
				now++;
				if(now==b[j]){
					pos=j;
				}
			}
		}
		if(pos!=-1){
			used[pos]=true;
			v.push_back(b[pos]);
		}
	}
	reverse(v.begin(),v.end());
	REP(i,N){
		if(used[i]==false){
			cout<<-1<<endl;
			return 0;
		}
	}
	REP(i,v.size()){
		cout<<v[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
//https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/14/ALDS1_14_B
#include <string>
#include <vector>
#include <tuple>
#include <iostream>
#include <set>
#include <cassert>

struct HashString{
public:
    using hashtype=long long;
    using hashcomptype=std::tuple<hashtype,hashtype,hashtype>;

    std::vector<hashtype> table1;
    std::vector<hashtype> table2;
    std::vector<hashtype> table3;
    std::vector<hashtype> powtable1;
    std::vector<hashtype> powtable2;
    std::vector<hashtype> powtable3;

    hashtype mod=1000000007ll;
    hashtype base1=1919ll;
    hashtype base2=114514ll;
    hashtype base3=334334ll;

    HashString(){}
    HashString(std::string s){
        table1.resize(s.size()+1);
        table2.resize(s.size()+1);
        table3.resize(s.size()+1);
        powtable1.resize(s.size()+1);
        powtable2.resize(s.size()+1);
        powtable3.resize(s.size()+1);

        table1[0]=0ll;
        table2[0]=0ll;
        table3[0]=0ll;
        powtable1[0]=1ll;
        powtable2[0]=1ll;
        powtable3[0]=1ll;

        for(int i=0;i < s.size(); ++i){
            table1[i+1]=table1[i]*base1+s[i];
            table2[i+1]=table2[i]*base2+s[i];
            table3[i+1]=table3[i]*base3+s[i];
            powtable1[i+1]=powtable1[i]*base1;
            powtable2[i+1]=powtable2[i]*base2;
            powtable3[i+1]=powtable3[i]*base3;

            table1[i+1]=table1[i+1]%mod;
            table2[i+1]=table2[i+1]%mod;
            table3[i+1]=table3[i+1]%mod;
            powtable1[i+1]=powtable1[i+1]%mod;
            powtable2[i+1]=powtable2[i+1]%mod;
            powtable3[i+1]=powtable3[i+1]%mod;
        }
    }

    bool operator == (HashString s){
        if(this->table1.size()!=s.table1.size())return false;
        if(this->table1.back()!=s.table1.back())return false;
        if(this->table2.back()!=s.table2.back())return false;
        if(this->table3.back()!=s.table3.back())return false;
        return true;//maybe :)
    }

    hashcomptype get_hash(int l,int r){//[l,r)でのhash
        assert(r-l>0);

        hashtype hash1=table1[r]-(powtable1[r-l]*table1[l]%mod);
        while(hash1<0)hash1+=mod;
        hash1=hash1%mod;

        hashtype hash2=table2[r]-(powtable2[r-l]*table2[l]%mod);
        while(hash2<0)hash2+=mod;
        hash2=hash2%mod;

        hashtype hash3=table3[r]-(powtable3[r-l]*table3[l]%mod);
        while(hash3<0)hash3+=mod;
        hash3=hash3%mod;

        //std::cout<<hash1<<" "<<hash2<<" "<<hash3<<std::endl;
        return std::make_tuple(hash1,hash2,hash3);
    }
};

int main(){
    std::string t,p;
    std::cin>>t>>p;
    HashString ht(t);
    HashString hp(p);
    
    /*
    int l1,r1,l2,r2;
    std::cin>>l1>>r1>>l2>>r2;
    std::cout<<t.substr(l1,r1-l1)<<" "<<p.substr(l2,r2-l2)<<std::endl;
    if(ht.get_hash(l1,r1)==hp.get_hash(l2,r2))std::cout<<"same"<<std::endl;
    else std::cout<<"different"<<std::endl;
    */
    
    
    for(int i=0;i+p.size() <= t.size(); ++i){
        if(ht.get_hash(i,i+p.size())==hp.get_hash(0,p.size())){
            std::cout<<i<<"\n";
        }
    }
    
    
    return 0;
}


Measured memory_bytes: 51972
import sys

input = sys.stdin.readline


def main():
    s = int(input())
    a = []
    while s not in a:
        a.append(s)
        s = s / 2 if s % 2 == 0 else s * 3 + 1
    print(len(a) + 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <stdio.h>
 
int main(void) {
  int i, j, key, n, array[100];
 
  scanf("%d", &n);
 
  for (i = 0; i < n; i++) {
    scanf("%d", &array[i]);
  }
 
  for (i = 0; i < n; i++) {
    key = array[i];
    j = i - 1;
    while (j >= 0 && array[j] > key) {
      array[j + 1] = array[j];
      j--;
    }
    array[j + 1] = key;
 
    for (j = 0; j < n; j++) {
      printf("%d%c", array[j], j == n - 1 ? '\n' : ' ');
    }
  }
 
  return 0;
}

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

vector<int> simple(string s){
	vector<int> v;
	for(int i = 0 ; i < s.size() ; i += 2 ){
		v.push_back((s[i]-'0')*16+s[i+1]-'0');
	}
	for(int i = 1 ; i <= v.size() ; i++){
		if( v.size() % i ) continue;
		int l = v.size() / i;
		int f = 1;
		for(int j = 0 ; j < v.size() ; j++){
			if( j % l && v[j] > 0 ) f = 0;
		}
		if(f){
			vector<int> t;
			for(int j = 0 ; j < v.size() ; j += l )
				t.push_back(v[j]);
			v = t;
			break;
		}
	}
	/*for(int i = 1 ; i <= v.size() ; i++){
		if( v.size() % i ) continue;
		int f = 1;
		for(int j = 0 ; j < v.size() ; j+=i){
			for(int k = 0 ; k < i ; k++){
				if( v[j+k] != v[k] ) f = 0;
			}
		}
		if(f){
			v.resize(i);
			return v;
		}
	}*/
	return v;
}
int main(){
	int T;
	cin >> T;
	while(T--){
		int n;
		cin >> n;
		int ans = 1;
		vector< vector<int> > vs;
		for(int i = 0 ; i < n ; i++){
			string r;
			cin >> r;
			vs.push_back(simple(r));
			ans = ans * vs.back().size() / __gcd(ans,(int)vs.back().size());
			ans = min(2000,ans);
		}
		if( ans > 1024 ){
			cout << "Too complex." << endl;
		}else{
			vector<int> a(ans);
			for(int i = 0 ; i < vs.size() ; i++){
				int span = ans / vs[i].size();
				for(int j = 0 ; j < vs[i].size() ; j++)
					a[span*j] |= vs[i][j];
			}
			for(int i = 0 ; i < a.size() ; i++)
				printf("%02X",a[i]);
			cout << endl;
		}
	}
}

Measured memory_bytes: 1320
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

def main():
    n, a, b = na()
    
    if (a == 0 and b == 0) or a == 0:
        print(0)
        return

    if n <= a:
        print(n)
        return
      
    AB = a + b
    if n <= AB:
        print(min(n, a))
        return 
    
    x = int(n / AB)

    print(x * a + min(n - (x * AB), a))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#Python Competetive Programming Template

from sys import stdin, stdout
from math import *

testing = False

def tp(s=""):
	if testing:
		stdout.write("{0}\n".format(s))

def main():
	n = int(stdin.readline())
	total = 0

	for a in range(1, n):
		count = (n-1)//a
		total += count
		tp(count)

	stdout.write("{0}\n".format(total))


	

main()

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

int main() {
    int N;
  	int ans = 1;
    cin >> N;
    int a[N];
    for (int i = 0; i < N; ++i) cin >> a[i];

    sort(a, a + N);
    for (int i = 0; i < N - 1; ++i) {
       if(a[i] < a[i+1]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	long long  n,m;//n:S, m:c
	cin >> n >> m;
	/* 
	n:Sのかず m:cの数

		2*n == m :ちょうど足りている。Sccは n

		2*n >= m :Sが多い。Sccはcに依存し、m/2個

		2*n < m:cが多い。Sccはcを用いて作る分を考慮する。n+


ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
		n >= 2*m;//Sが多い mこ
		n == 2*m;//　mこ
		n < 2*m//まずnこできる。そのあと(2*m-n)-(2*m-n)%4 / 4こ追加できる。
	*/
//	cout<< n << " "<<m<<endl; 
	long long  ans = 0;
	if(2*n == m) cout << n << endl;
	else if(2*n > m){
		cout << (m - m%2) / 2 << endl;
	}else {
		ans += n;

//		cout <<"other:" << ans << endl;
//cout <<((2*n-m)-((2*n-m)%4) ) / 4 <<endl;
		ans += ( (m-2*n) - ((m-2*n)%4) ) / 4;
		cout <<  ans << endl;
	}
	return 0;
}

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

int main(){
  int l=0;
  int i;
  int n,T;
  int min=1000;
  int minnum;

  scanf("%d %d",&n,&T);

  int c[n];
  int t[n];

  for(i=0; i<=n-1; i++){
    scanf("%d %d",&c[i],&t[i]);
  }

  for(i=0; i<=n-1; i++){
    if(t[i]>T){
      c[i]=1000;
      l++;
    }
  }

  if(l!=n){
    for(i=0; i<=n-1; i++){
      if(c[i]<min){
        min = c[i];
        minnum = i;
      }
    }
  }

  if(l==n){
    printf("TLE\n");
  }else{
    printf("%d\n",min);
  }

  return 0;
}


Measured memory_bytes: 128
fun main(args: Array<String>) {
    val n  =readLine()!!.toInt()
    val list = List(n) {
        readLine()!!
    }
    var count0 = 0
    var count1 = 0
    var count2 = 0
    var count3 = 0
    for(i in 0 until n) {
        when(list[i]) {
            "AC" -> count0++
            "WA" -> count1++
            "TLE" -> count2++
            "RE" -> count3++
            else -> {}
        }
    }
    println("AC x $count0")
    println("WA x $count1")
    println("TLE x $count2")
    println("RE x $count3")
}

Measured memory_bytes: 60328
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  bool res = true;
  if (S[0] != 'A') res = false;
  int C = 0;
  for (int i = 1; i < S.size(); i++){
    if (!islower(S[i])){
      if (i == 1 || i == S.size() - 1){
        res = false;
      } else if (S[i] != 'C'){
        res = false;
      } else {
        C++;
      }
    }
  }
  if (C != 1) res = false;
  cout << (res ? "AC" : "WA");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lowbit(i) ((i)&(-(i)))
#define lson(i) ((i)<<1)
#define rson(i) ((i)<<1|1)
#define sqr(x) ((x)*(x))
#define fi first
#define se second
#define mp(x,y) make_pair((x),(y))
#define pb push_back
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef pair<int,int> pii;
typedef vector<int> vii;
typedef vector<pii> vpi;
typedef queue<int> qii;

const int inf=0x3f3f3f3f;
const int maxn=100007;

ll n,s;
struct node{
	ll x,p;void init(){scanf("%lld%lld",&x,&p);}
}a[maxn];

pair<ll,ll> solve(ll l,ll r){
	if(a[r].x<s) {
		return mp(-1,s-a[l].x);
  	}else if(a[l].x>s) {
  		return mp(1,a[r].x-s);
    }
  	if(l==r){
		if(a[l].x<s) return mp(-1,s-a[l].x);
		else return mp(1,a[l].x-s);
	}
	if(a[l].p<a[r].p){
		a[r].p+=a[l].p;
		pair<ll,ll> t=solve(l+1,r);
		// cout<<l<<' '<<r<<' '<<a[l].p<<' '<<a[r].p-a[l].p<<' ';
		// cout<<t.fi<<' '<<t.se<<'\n';
		if(t.fi==-1) return mp(-1,t.se+a[l+1].x-a[l].x);
		else return mp(-1,t.se+a[r].x-a[l].x);
	}else{
		a[l].p+=a[r].p;
		pair<ll,ll> t=solve(l,r-1);
		// cout<<l<<' '<<r<<' '<<a[l].p-a[r].p<<' '<<a[r].p<<' ';
		// cout<<t.fi<<' '<<t.se<<'\n';
		if(t.fi==1) return mp(1,t.se+a[r].x-a[r-1].x);
		else return mp(1,t.se+a[r].x-a[l].x);
	}
}

int main(){
// 	freopen("","r",stdin);5
// 	freopen("","w",stdout);
	scanf("%lld%lld",&n,&s);
	for(int i=1;i<=n;i++) a[i].init();
	// for(int i=1;i<=n;i++) cout<<a[i].p<<' ';cout<<'\n';
	printf("%lld\n",solve(1,n).se);
	return 0;
}
/*
3 2
1 3
3 4
4 2
*/

Measured memory_bytes: 4352
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7

int max(int a, int b) {

	if (a > b)return a;
	else return b;

}
//aとbの大きい方

int min(int a, int b) {

	if (a < b)return a;
	else return b;

}
//aとbの小さい方

int avd_i(int a, int b) {

	if (a > b)return a - b;
	else return b - a;

}
double avd_d(double a, double b) {

	double re;
	if (a > b)re = a - b;
	else re = b - a;
	return re;

}
//aとbの差の絶対値

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

int main() {
	
	int N, A, B, passnum = 0, forenum = 0;
	string S;

	cin >> N >> A >> B >> S;

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

		switch (S[i]) {

		case 'a':
			if (passnum < A + B) {

				passnum++;
				cout << "Yes" << endl;

			}
			else cout << "No" << endl;
			break;

		case 'b':
			if (passnum < A + B&&forenum < B) {

				passnum++;
				forenum++;
				cout << "Yes" << endl;

			}
			else cout << "No" << endl;
			break;
		
		default:
			cout << "No" << endl;
			break;

		}

	}

	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

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

    double n,m,d;
    cin>>n>>m>>d;
    double l=2*(n-d)*(m-1);
    if(d==0)l/=2;
    double ans=l/(n*n);
    printf("%10f\n",ans);
    //cout<<l/(n*n)<<endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
bef_sum = sum(a)
for i in range(n):
  if b[i] >= a[i]:
    a[i+1] -= b[i]-a[i]
    a[i] = 0
    if a[i+1] < 0:
      a[i+1] = 0
  else:
    a[i] -= b[i]
print(bef_sum - sum(a))


Measured memory_bytes: 82148
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = ReadLine();
            string t = ReadLine();

            int cnt = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == t[i]) cnt++;
            }

            WriteLine(cnt);
        }

        static int InputNum()
        {
            return int.Parse(ReadLine());
        }
        static List<int> InputNumList()
        {
            return ReadLine().Split(' ').Select(int.Parse).ToList();
        }
    }
}



Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n;
    cin>>n;
    ll h[n];
    ll dp[n+1];
    for(ll i=0;i<n;i++)
    {
        cin>>h[i];
    }
    dp[0]=0;
    dp[1]=abs(h[0]-h[1]);
    for(ll i=2;i<n;i++)
    {
        dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
    }
    cout<<dp[n-1];
}


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

using namespace std;
typedef long long ll;

ll d[310][310];

void warshallFloyd(int n) {
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

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

  ll a[310][310];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }

  const ll INF = 1e13;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      d[i][j] = INF;
    }
    d[i][i] = 0;
  }

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      bool flag = false;
      for (int k = 0; k < n; k++) {
        if (k == i || k == j) continue;
        flag |= a[i][k] + a[k][j] == a[i][j];
      }
      if (!flag) {
        d[i][j] = d[j][i] = a[i][j];
        ans += a[i][j];
      }
    }
  }

  warshallFloyd(n);

  bool ng = false;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      ng |= a[i][j] != d[i][j];
    }
  }

  if (ng) ans = -1;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>

int main()
{
   int S, h, m, s;

   scanf("%d\n", &S);

   h = S / 3600;
   m = S % 3600 / 60;
   s = S % 3600 % 60;

   printf("%d:%d:%d\n", h, m, s);

   return 0;
}

   


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  int ans = 0;

  while (true) {
    if (a[0] == a[1] && a[1] == a[2]) break;
    sort(a, a+3);
    ans++;
    if (a[1]==a[2]) a[0]+=2;
    else {
      a[0]++; a[1]++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define int ll
//#define endl '\n'

vector<int> pos,neg;
int n;
int a[maxn],P,N;

int32_t main()
{
    IOS
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        cin>>a[i];
        if (a[i]>=0) P++;
        else N++;
    }
    if (P==0)
    {
        int maxx=-inf,att;
        for (int i=1;i<=n;i++)
        {
            if (a[i]>maxx) maxx=a[i],att=i;
        }
        for (int i=1;i<=n;i++)
        {
            if (i==att) pos.pb(a[i]);
            else neg.pb(a[i]);
        }
    }
    else if (N==0)
    {
        int minn=inf,att;
        for (int i=1;i<=n;i++)
        {
            if (a[i]<minn) minn=a[i],att=i;
        }
        for (int i=1;i<=n;i++)
        {
            if (i==att) neg.pb(a[i]);
            else pos.pb(a[i]);
        }
    }
    else
    {
        for (int i=1;i<=n;i++){
        if (a[i]>=0) pos.pb(a[i]);
        else neg.pb(a[i]);}
    }
    int ans=0;
    for (int i:pos) ans+=i;
    for (int i:neg) ans-=i;
    cout<<ans<<endl;
    ans=neg[0];
    for (int i=1;i<sz(pos);i++)
    {
        cout<<ans<<' '<<pos[i]<<endl;
        ans-=pos[i];
    }
    cout<<pos[0]<<' '<<ans<<endl;
    ans=pos[0]-ans;
    for (int i=1;i<sz(neg);i++)
    {
        cout<<ans<<' '<<neg[i]<<endl;
        ans-=neg[i];
    }
}



Measured memory_bytes: 2808
N = int(input())
S = input()
we = []
w = 0
e = 0

for i in range(N):
    if S[i] == "W":
        w += 1
    else:
        e += 1
    we.append([w,e])

e_count = we[-1][1]
ans = min(e_count,we[-1][0])
for i in range(N):
    ans = min(we[i][0] + abs(we[i][1] - e_count), ans)
print(ans)

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

int primes[1000000]={0};


int main(){
    primes[0] = -1;
    primes[1] = -1;
    for(int i=2; i<1000; i++){
        if(primes[i]==-1) continue;
        for(int j=i+1; j<1000000; j++){
            if(j%i==0) primes[j] = -1;
        }
    }
    int n;
    while(-1!=scanf("%d", &n)){
        int ans = 0;
        for(int i=2; i<=n; i++){
            if(primes[i] == 0) ans++;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 7004
#!/usr/bin/env python3
n = int(input())
k = len(str(n))
ans = 0
if k % 2 == 0:
    for i in range(k//2):
        ans += 10**((i*2)+1) - 10**(i*2)
else:
    for i in range(k//2):
        ans += 10**((i*2)+1) - 10**(i*2)
    ans += n - 10**(k-1) + 1
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std; 
int main() {

    jaldi

    long long int n;
    cin>>n;
    string s;
    cin>>s;
    vector<long long int> suffix (n+1,0);
    for(long long int i=n-1;i>=0;i--) {
        suffix[i]= suffix[i+1] + (s[i]=='R');
    }
    vector<long long int> prefix(n+1,0);
    for(long long int i=1;i<=n;i++){
        prefix[i]=prefix[i-1]+(s[i-1]=='W');
    }

    long long int i=0;
    long long int ans = LLONG_MAX;
    while(i<=n){ //i is number of R's
        long long int cost =0;
        long long int cntWinpre = prefix[i];
        long long int cntRsuff = suffix[i];
        if(cntRsuff>=cntWinpre) { //swapping
            cost+= cntWinpre;
            cost+= (cntRsuff-cntWinpre);
        }
        else {
            cost += (cntRsuff);
            cost += (cntWinpre - cntRsuff);
        }
        ans= min(ans,cost);
        i++;
    }
    cout<<ans<<'\n';
}


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

int main()
{
  int a, b, n;
  while (cin >> a >> b >> n) {
    int ans = 0;
    a *= 10;
    for (int i = 0; i < n; ++i, a *= 10) {
      ans += a / b % 10;
      a %= b;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<set>
#include<cctype>
#define INF 0x3f3f3f3f
#define inf 0x3f
#define fi first
#define se second
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define pb push_back

using namespace std;

inline ll read()
{
	ll f=1,sum=0;char c=getchar();
	while (!isdigit(c)) {if (c=='-') f=-1;c=getchar();}
	while (isdigit(c)) {sum=sum*10+c-'0';c=getchar();}
	return sum*f;
}
const int MAXN=100010;
char s[MAXN][11];
int num[MAXN][26];
ull P1[30];
ll P[30];
#define Mod 1000000007
#define pa pair<ll,ull>
map <pa,int> now;
int main()
{
	int n=read();
	ll ans=0;
	P1[1]=P[1]=1;
	for (int i=2;i<=26;i++) P1[i]=P1[i-1]*10,P[i]=P[i-1]*10%Mod;
	for (int i=1;i<=n;i++) scanf("%s",s[i]+1),sort(s[i]+1,s[i]+1+10);
	for (int i=1;i<=n;i++)
	{
		pa hsh=mp(0,0);
		for (int j=1;j<=10;j++) num[i][s[i][j]-'a'+1]++;
		for (int j=1;j<=26;j++) hsh.fi=hsh.fi+P[j]*num[i][j]%Mod,hsh.fi%=Mod,hsh.se=hsh.se+P1[j]*num[i][j];
		ans+=now[hsh];
		now[hsh]++;
	}	
	cout<<ans;
	return 0;
}


Measured memory_bytes: 17792
#include<bits/stdc++.h>
using namespace std;
int x_1, y_1, x_2, y_2;
int main(){
    cin >> x_1 >> y_1 >> x_2 >> y_2;
    cout << x_2 - (y_2 - y_1) <<" ";
    cout << y_2 + (x_2 - x_1) <<" ";
    cout << x_1 - (y_2 - y_1) <<" ";
    cout << y_1 + (x_2 - x_1) <<" ";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include<string>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define intarr(arr, n)  ll arr[n];  for (ll i = 0; i < n; i++)  cin >> arr[i]
#define inpvec(vec,n) for(ll i=0;i<n;i++){ll v;cin>>v;vec.push_back(v);}
#define ff first
#define ss second
#define pb push_back
#define mkp make_pair
#define vec vector<ll>
#define pi pair<ll,ll>
#define changeline cout<<endl
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(),v.end()
#define mod2 998244353
#define NO cout << "NO" <<endl
#define YES cout << "YES" <<endl
#define mem(arr,val) memset(arr,val,sizeof(arr));
const ll mod=1e9+7;

bool prime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
bool subsequence_checker(string str1, string str2, ll m, ll n) 
{ 
    if (m == 0) return true; 
    if (n == 0) return false; 
    if (str1[m-1] == str2[n-1]) 
        return subsequence_checker(str1, str2, m-1, n-1); 
    return subsequence_checker(str1, str2, m, n-1); 
}
ll inv(ll a)
{
    ll p=mod2;
    ll b=p-2,ans=1;
    for(;b > 0;a = a * a % p,b >>= 1)if(b & 1)ans = ans * a % p;
    return ans;
}
ll ncr(ll n,ll m)
{
    ll p=mod2;
    if(m > n)return 0;
    ll up=1,down=1;
    for(int i=n-m+1;i<n+1;i++)up*=i,up%=p;
    for(int i=1;i<m+1;i++)down*=i,down%=p;
    return up*inv(down)%p;
}

ll countDigit(ll n)
{   
    return floor(log10(n) + 1); 
}  
ll a_pow_b(ll a,ll b)
{
    ll p=1000000007;
    ll ans=1;
    for(;b > 0;a = a * a % p,b >>= 1)if(b & 1)ans = ans * a % p;
    return ans;
}
ll gcd(ll a,ll b) 
{ 
    if (b==0) 
        return a; 
    return gcd(b,a%b);      
} 
ll lcm(ll a, ll b)  
{  
    return (a*b)/gcd(a, b);  
}
bool isPerfectSquare(ll x) 
{   
  long double sr = sqrt(x); 
  return ((sr - floor(sr)) == 0); 
}
ll ncr123(ll n, ll k){
    if (k == 1) {
        return n;
    }
    if (k == 2) {
        return n * (n - 1) / 2;
    }
    if (k == 3) {
        return n * (n - 1) * (n - 2) / 6;
    }
}
bool com(const pi &a,const pi &b)   //acc to second element sort for vec of pi
{ 
    if(a.second==b.second)
        return a.first<b.first;
    return a.second<b.second;
}



void solve(){

    ll x;
    cin>>x;

    loop(i,-1000,1001){
        loop(j,-1000,1001){
            if(i*i*i*i*i - j*j*j*j*j ==x)
            {
                cout<<i<<" "<<j; return;
            }
        }
    }



    return ;
}
 
 
int main()
{
    IOS;
    ll t;
    //cin>>t;
    t=1;

    while(t--){
        solve();
        cout<<endl;
    }

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 3684