akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 924844033;
//long long int MOD = 1e9 + 7;

int main(){
    long long int N, K;
    cin >> N >> K;
    long long int fact[2100] = {};
    fact[0] = 1;
    for(int i = 1; i <= N; i++){
        fact[i] = fact[i - 1] * i % MOD;
    }
    long long int DP[2100] = {};
    DP[0] = 1;
    for(int i = 1; i <= min(N, K); i++){
        long long int DPs[2100][3] = {};
        int cnt = (N - i) / K;
        DPs[0][1] = 1;
        if(cnt >= 1){
            DPs[1][2] = 1;
        }
        for(int j = 1; 2 * j <= cnt; j++){
            for(int k = j + 1; k > 0; k--){
                DPs[k][1] += DPs[k][0] + DPs[k][2];
                DPs[k][1] %= MOD;
                DPs[k][0] = DPs[k - 1][0] + DPs[k - 1][1];
                DPs[k][0] %= MOD;
                DPs[k][2] = DPs[k - 1][0] + DPs[k - 1][1] + DPs[k - 1][2];
                DPs[k][2] %= MOD;
            }
        }
        long long int S[2100] = {};
        int maxS = 0;
        for(int j = 0; 2 * (j - 1) - 1 <= cnt; j++){
            S[j] = DPs[j][0] + DPs[j][1];
            if(cnt % 2 == 1){
                S[j] += DPs[j][2];
            }
            maxS = j;
        }
        for(int loop = 0; loop < 2; loop++){
            for(int j = 2010; j >= 0; j--){
                for(int k = 1; k <= min(j, maxS); k++){
                    DP[j] += DP[j - k] * S[k];
                    DP[j] %= MOD;
                }
            }
        }
    }
    long long int ans = 0;
    long long int sig = 1;
    for(int i = 0; i <= N; i++){
        ans += sig * (DP[i] * fact[N - i] % MOD) + MOD;
        ans %= MOD;
        sig *= -1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int testCase,clearedTestCase;

		testCase=sc.nextInt();
		clearedTestCase=sc.nextInt();

		if(testCase==clearedTestCase) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

		sc.close();
	}

}


Measured memory_bytes: 22868
N = gets.to_i
H = gets.split.map &:to_i
 
dp = Array.new(N, nil)
dp[0] = 0
 
N.times do |i|
    next if i >= N - 1
    cost = (H[i+1] - H[i]).abs + dp[i]
    dp[i+1] = cost if dp[i+1].nil? || cost < dp[i+1]
 
    next if i >= N - 2
    cost = (H[i+2] - H[i]).abs + dp[i]
    dp[i+2] = cost if dp[i+2].nil? || cost < dp[i+2]
end
 
p dp[-1]

Measured memory_bytes: 20952
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#define ms(x) memset(x, 0, sizeof(x))
#define inf 0x3f3f3f3f
using namespace std;
const int N = 200005;
vector<int >book[N];
int faf[N], fag[N];
int vis[N];
map<pair<int, int> , int>mp;
void init() {
    for(int i=0; i<N; i++) {
        faf[i] = fag[i] = i;
    }
}
int Find(int *f, int x){
    if(f[x] == x) return x;
    else{
        f[x] = Find(f, f[x]);
        return f[x];
    }
}
void Merge(int *f, int x, int y){
    int a = Find(f, x) , b = Find(f, y);
    if(a!=b){
        f[b] = a;
    }
}
int main() {
    int n, k, l;
    while(cin>>n>>k>>l) {
        int u, v;
        init();
        for(int i=0; i<k; i++) {
            scanf("%d%d",&u,&v);
            Merge(faf, u, v);
        }
        for(int i=0;i<l;i++){
            scanf("%d%d",&u,&v);
            Merge(fag, u, v);
        }
        for(int i=1;i<=n;i++){
            ++mp[{Find(faf, i), Find(fag, i)}];        //将同一个连通块中的点 集合起来
        }
        for(int i=1;i<=n;i++){
            printf("%d%c", mp[{Find(faf, i), Find(fag, i)}],i==n?'\n':' ');
        }
    }
    return 0;
}


Measured memory_bytes: 18304
#include<stdio.h>
int main (){
int k,t,i,x=0;
int max=0;
int a[100]={};
scanf("%d %d",&k,&t);
for(i=0;i<t;i++){
scanf("%d",&a[i]);
if(a[i]>max) max=a[i];
}
if(k%2==0){
if(max<=k/2)x=0;
else x=2*max-k-1;
}else{
if(max<=k/2+1) x=0;
else x=2*max-k-1;
}
printf("%d\n",x);
return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int a,b,c,d; cin >> a >> b >> c >> d;
    string s = to_string(a) + to_string(b)+ to_string(c)+to_string(d);
    sort(all(s));
    cout << ((s == "1479") ? "YES" : "NO") << endl;
}




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

int main() {
    map<char, int> mp;
    string w;
    cin >> w;
    for (int i = 0; i < 26; i++) {
        char a = i + 'a';
        mp[a] = 0;
    }
    for (int i = 0; i < w.length(); i++) {
        mp[w[i]]++;
    }
    int count = 0;
    for (int i = 0; i < 26; i++) {
        char a = i + 'a';
        if (mp[a]%2 == 0) count++;
    }
    if (count == 26) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main()
{
    fast
    ll n,ans=0;
    cin>>n;
    string s;

    unordered_map<string,ll>mp;
    while(n--)
    {
        cin>>s;
        sort(s.begin(),s.end());
        mp[s]++;
    }
    for(auto it=mp.begin(); it!=mp.end() ; it++)
    {
        ans += (it->second)*(it->second-1)/2;
    }
    cout<<ans<<endl;
}


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

int main() {
  string S;
  cin >> S;
  if (S[0] == 'R') {
    if (S[1] == 'R') {
      if (S[2] == 'R') cout << 3 << endl;
      else cout << 2 << endl;
    }
    else cout << 1 << endl;
  }
  else {
    if (S[1] == 'R') {
      if (S[2] == 'R') cout << 2 << endl;
      else cout << 1 << endl;
    }
    else {
      if (S[2] == 'R') cout << 1 << endl;
      else cout << 0 << endl;
    }
  }
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<string> A(n);
    rep(i,n) cin>>A[i];
    vector<P> B,C(n,P(0,0));
    rep(i,n){
        ll a=0,b=0,z=0,c=0;
        rep(j,A[i].size()){
            if(A[i][A[i].size()-j-1]!='.'){
                if(z==0) b++;
                a+=(A[i][A[i].size()-j-1]-'0')*(ll)pow(10,c);
                c++;
            }
            else z=1;
        }
        if(z==0) b=0;
        B.push_back(P(a,b));
    }
    rep(i,n){
        while(B[i].first>0&&B[i].first%2==0) B[i].first/=2,C[i].first++;
        while(B[i].first>0&&B[i].first%5==0) B[i].first/=5,C[i].second++;
    }
    rep(i,n){
        C[i].first=B[i].second-C[i].first;
        C[i].second=B[i].second-C[i].second;
    }
    int num[100][100]={0};
    rep(i,n){
        num[C[i].first+50][C[i].second+50]++;
    }
    rep(i,99) num[0][i+1]+=num[0][i];
    rep(i,99) num[i+1][0]+=num[i][0];
    rep(i,99)rep(j,99){
        num[i+1][j+1]=num[i+1][j+1]+num[i+1][j]+num[i][j+1]-num[i][j];
    }
    ll ans=0;
    rep(i,n){
        ans+=num[50-C[i].first][50-C[i].second];
        if(C[i].first<=0&&C[i].second<=0) ans--;
    }
    cout<<ans/2<<"\n";
}

Measured memory_bytes: 17328
using System;
using System.Collections.Generic;
using System.Linq;
 
public class ABC0140_A2v2 {
    private static void Main(string[] args) {
        var numOfOrders = ReadInt();
        var orders = ReadIntArray();
        var satisfactionBases = ReadIntArray();
        var satisfactionCombos = ReadIntArray();

        var total = satisfactionBases.Sum();
        for (var index = 0; index < numOfOrders - 1; index++) {
            if (orders[index + 1] == (orders[index] + 1))
                total += satisfactionCombos[orders[index] - 1];
        }
        Console.WriteLine(total.ToString());
    }

    private static int ReadInt() => int.Parse(Console.ReadLine().Trim());
    private static int[] ReadIntArray() => Console.ReadLine().Trim().Split().Select(x => int.Parse(x)).ToArray();
}

Measured memory_bytes: 13396
from collections import Counter

N=int(input())
L=list(map(int,input().split()))
S=[0]*(N+1)
for i in range(1,N+1):
	S[i]=S[i-1]+L[i-1]
#print(S)
M=Counter(S)
#print(M)
ans=0
for i,j in M.items():
	ans+=(j*(j-1)//2)
print(ans)

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

// input
int N;
vector<int> s;


void input() {
    cin >> N;
    s = vector<int>(N);
    rep(i, N) cin >> s[i];
}


int main() {
    input();
    int ans = 0;
    sort(s.begin(), s.end());
    rep(i, N) ans += s[i];
    if (ans % 10 == 0) {
        rep(i, N) {
            if (s[i] % 10 != 0) {
                ans -= s[i];
                break;
            }
        }
    }
    if (ans % 10 == 0) ans = 0;
    cout << ans << endl;
}


Measured memory_bytes: 3572
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
 const int hhh=10001;
LL n,x,W,v,w;
LL dp[105][100005] = {0};
 
int main(){
	memset(dp,0x3f,sizeof(dp));
	dp[0][0] = 0;
	scanf("%lld %lld",&n,&W);
	x = n * 1000;
	for(LL i = 1;i <= n;i ++){
		scanf("%lld %lld",&w,&v);
		for(LL j = 0;j <= x;j ++){
			dp[i][j] = dp[i - 1][j];
			if(j >= v) dp[i][j] = min(dp[i][j],dp[i - 1][j - v] + w);
		}
	}
	for(LL i = x;i >= 0;i --){
		if(dp[n][i] <= W){
			printf("%lld\n",i);
			break;
		}
	}
	return 0;
}

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

namespace ConsoleApp1
{
    static class AServalVsMonster
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var h = int.Parse(input[0]);
            var a = int.Parse(input[1]);

            int count = h / a;
            if (h % a > 0)
            {
                count++;
            }

            Console.WriteLine(count);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 11092
import sys
input = sys.stdin.readline
class Unionfind:
     
    def __init__(self,n):
        self.uf = [-1]*n
 
    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]
 
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.uf[y] = x
        return True
 
    def size(self,x):
        x = self.find(x)
        return -self.uf[x]

n,q = map(int,input().split())
U = Unionfind(n)
for i in range(q):
    t,u,v = map(int,input().split())
    if t == 0:
        U.union(u,v)
    else:
        print(int(U.same(u,v)))


Measured memory_bytes: 79212
/*input
2000000000 0 0 2000000000
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<ll,ll>
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const int maxn=2e5+5;
const int maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#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())
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
int main(){
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int ans=0;
    if(k>=a){
        k-=a;
        ans+=a;
    }
    else{
        ans+=k;
        k=0;
    }
    if(k>=b){
        k-=b;

    }
    else{
        k=0;
    }
    if(k>=c){
        ans-=c;
        k-=c;
    }
    else{
        ans-=k;
        k=0;
    }
    cout<<ans;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String[] t = sc.nextLine().split(" ");
		long n = Long.parseLong(t[0]);
		long min = n == 0 ? 1 : 0;
		System.out.println(min);
	}
}


Measured memory_bytes: 35784
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

// フェルマーの小定理
ll mod_pow(ll n, ll p, ll mod=MOD) {
    if(p==0) return 1;
    ll res = mod_pow(n*n%mod, p/2, mod);
    if(p%2==1) res = res * n % mod;
    return res;
}
ll nCr(ll n, ll r, ll mod=MOD) {
    r = min(r, n-r);
    ll numer = 1, denom = 1;
    rep(i,r) {
        numer *= n-i;
        numer %= mod;
        denom *= i+1;
        denom %= mod;
    }
    return numer * mod_pow(denom, mod-2, mod) % mod;
}

ll g(ll r, ll c) {
    return nCr(r+c+2, r+1) - 1;
}

int main() {
	ll r1, c1, r2, c2;
	cin >> r1 >> c1 >> r2 >> c2;
    r1--; c1--;
    ll ans = g(r2, c2);
    ans -= g(r1, c2);
    ans -= g(r2, c1);
    ans += g(r1, c1);
    ans += MOD;
    ans %= MOD;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}

const int N=2e5+5;
int a[N];
// int dp[N][N];
int dp[N];
vector<int> v[N];

// int dp2[15][15];

int32_t main(){
    int n;
    cin>>n;
    v[0]={0};
    dp[0]=0;
    for(int i=1;i<=n+1;++i){
        if(i<=n)cin>>a[i];
        int d=a[i]-a[i-1];
        vector<int> po;
        for(int j:v[i-1]){
            po.pb(j);
            po.pb(j-1);
            po.pb(j+d);
        }
        sort(po.begin(),po.end());
        po.resize(unique(po.begin(),po.end())-po.begin());
        while(po.back()>a[i])po.pop_back();
        reverse(po.begin(),po.end());
        while(po.back()<0)po.pop_back();
        reverse(po.begin(),po.end());
        int pv=-1;
        for(int j:po){
            vector<pii> b;
            b.pb(0,dp[i-1]);
            b.pb(j+1,+1);
            b.pb(j-d+1,+1);
            for(int k:v[i-1])if(k)b.pb(k,-1);
            sort(b.begin(),b.end());
            int val=0,cu=b[0].f,res=N;
            dbg(j);
            for(pii p:b){
                dbg(p.f,p.s);
                if(p.f!=cu){
                    if(cu>=0&&cu<=a[i-1]){
                        dbg(cu,val);
                        upn(res,val);
                    }
                }
                val+=p.s;
                cu=p.f;
            }
            if(cu>=0&&cu<=a[i-1]){
                dbg(cu,val);
                upn(res,val);
            }
            dbg(j,res);
            if(!j)dp[i]=res;
            if(res!=pv)v[i].pb(j);
            pv=res;
        }
        dbg(dp[i]);
        for(int j:v[i])dbg(j);
        dbg("=======");
    }
    cout<<dp[n+1]<<'\n';
    // dbg("DP2");

    // forn(i,15)forn(j,15)dp2[i][j]=15;
    // dp2[0][0]=0;
    // for(int i=1;i<=n+1;++i){
    //     forn(j,a[i]+1){
    //         forn(k,a[i-1]+1){
    //             upn(dp2[i][j],dp2[i-1][k]+(int)(k>j)+(int)(a[i-1]-k<a[i]-j));
    //         }
    //     }
    //     dbg(dp2[i][0]);
    //     for(int j=1;j<=a[i];++j)
    //         if(dp2[i][j]<dp2[i][j-1])
    //             dbg(j);
    //     dbg("~~~~");
    // }

    return 0;
}


Measured memory_bytes: 17408
#include <stdio.h>

int main() {

	int array_value;	
	scanf("%d", &array_value);
	
	int array[array_value];
	for(int i = 0; i < array_value; i++) {
		scanf("%d", &array[i]);
	}


	int operation_count = 0;
	while(1) {
	
		for(int ai = 0; ai < array_value; ai++) {
			if((array[ai] % 2) == 0 ){
				array[ai] = array[ai] / 2;
			} else {
				printf("%d\n", operation_count);
				return 0;
			}
		}
      
      operation_count++;

	}
	
}

Measured memory_bytes: 1728
N,M = map(int,input().split())
S = input()
 
ans = []
i = N
while i > 0:
    for m in range(M,0,-1):
        if i-m <= 0:
            ans.append(i)
            i = 0
            break
        if S[i-m]=='0':
            ans.append(m)
            i -= m
            break
    else:
        print(-1)
        exit()
print(*ans[::-1])

Measured memory_bytes: 6372
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long t = sc.nextLong();
		long[] a = new long[n];
		for(int i=0; i<n; i++){
			a[i] = sc.nextLong();
		}
		sc.close();
		
		long cmax = 0;
		long maxv = 0;
		
		for(int i=n-1; i>=0; i--){
			if(a[i] > cmax){
				cmax = a[i];
			}
			if(cmax - a[i] >= maxv){
				maxv = cmax - a[i];
			}
		}
		
		int ans = 0;
		cmax = 0;
		
		for(int i=n-1; i>=0; i--){
			if(a[i] > cmax){
				cmax = a[i];
			}
			if(cmax - a[i] == maxv){
				ans++;
			}
		}
		
		System.out.println(ans);

	}

}

Measured memory_bytes: 46676
S =input()
T =input()

answer = len(T)
for i in range(len(S)-len(T)+1):
#	print(S[i:i + len(T)])
	count = 0
	for j in range(len(T)):
		if S[i + j] != T[j]:
			count = count + 1
	if count < answer:
		answer = count
print(answer)

Measured memory_bytes: 8932
# CODE FESTIVAL 2016 Final - A
# -*- encoding: UTF-8 -*-
h, w = map(int, input().split())

hx = 0
wx = 0

tTable = []
for i in range(h):
  tList = input().split()
  if "snuke" in tList:
    hx = i
    wx = tList.index("snuke")

print(chr(ord("A")+wx) + str(hx+1))


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

using namespace std;

struct Node {
    int64_t r;
    int64_t m;
    int64_t discount;
    Node(int64_t r = 0, int64_t m = 0, int64_t discount = 0): r(r), m(m), discount(discount){}
};

int main() {
    int64_t A, B, M;
    cin >> A >> B >> M;
    vector<int64_t> rv(A);
    vector<int64_t> mv(B);
    int64_t minr = INT_MAX, minm = INT_MAX;
    for (int i = 0; i < A; ++i) {
        cin >> rv[i];
        minr = min(minr, rv[i]);
    }
    for (int i = 0; i < B; ++i) {
        cin >> mv[i];
        minm = min(minm, mv[i]);
    }
    int64_t res = minr + minm;
    // vector<int> disv;
    // disv.reserve(M);
    for (int i = 0; i < M; ++i) {
        Node tmp;
        cin >> tmp.r >> tmp.m >> tmp.discount;
        // disv.push_back(tmp);
        res = min(res, rv[tmp.r-1] + mv[tmp.m-1] - tmp.discount);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N, T, A;
    cin >> N;
    cin >> T >> A;

    vector<int> H(N);
    REP(i, N) cin >> H[i];

    int ans = 0;
    FOR(i, 1, N) {
        if (abs(T - H[i] * 0.006 - A) < abs(T - H[ans] * 0.006 - A)) {
            ans = i;
        }
    }

    cout << ans + 1 << endl;

}


Measured memory_bytes: 256
s = input()
K = int(input())
n = len(s)
 
dp = [[[0 for _ in range(2)] for _ in range(4)] for _ in range(n+5)]
 
dp[0][0][0] = 1
 
for i in range(n):
    for j in range(4):
        for k in range(2):
            nd = int(s[i])  # 今見ている桁の数値
            for d in range(10):
                ni = i+1
                nj = j
                nk = k
                if d != 0:  # 0以外が一個増える
                    nj += 1
                if nj > K:  # これ以上0以外使えないとき
                    continue
                if k == 0:  # そこまでの桁はNと一致しているとき
                    if d > nd:  # Nを超えてしまう
                        continue
                    if d < nd:  # N以下確定である
                        nk = 1
                dp[ni][nj][nk] += dp[i][j][k]
ans = dp[n][K][0] + dp[n][K][1]
 
print(ans)

Measured memory_bytes: 3064
### SNIPPET
  # array = [*1..q].map { |_| gets.split.map(&:to_i) }
  # n = gets.split.map(&:to_i)
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さh = a * Math.sin(w / 180.0 * Math::PI)
  # 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
INF = Float::INFINITY
def chmin(a, b) a < b ? a : b end

n = gets.to_i

dp = [INF] * (n+9+1)

patern = [1]
t = 1
while 6 ** t < 10 ** 6  
  patern.push(6 ** t)
  t += 1
end 

t = 1
while 9 ** t < 10 ** 6  
  patern.push(9 ** t)
  t += 1
end 
patern.sort!
dp[0] = 0
(n+1).times do |i|
  patern.each do |j|
    if (i+j) <= n
      dp[i + j] = chmin(dp[i+j], dp[i]+1)
    end
  end
end

p dp[n]

Measured memory_bytes: 2556
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    int a, b, c, d;
    cin >> a >> b >> c >> d ;
    //*/
    
    /*
    vector<int> vec(4);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;
    
    sort(vec.begin(), vec.end());
    */
    
    /*
    if(a + b >= c){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    */
    
    cout << min(a, b) + min(c, d) << endl;

    return 0; 
}


Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
#include <fenv.h>
#include <algorithm>
#include <cstdio>

using namespace std;
int main()
{
 int a,b,c,d; cin >> a >> b >> c >> d;
 if(a+b == c+d) cout << "Balanced" << endl;
 if (a+b > c+d) cout << "Left" << endl;
 if(a+b < c+d) cout << "Right" << endl;
 return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    long x = sc.nextLong();
    long n=100;
    int i=1;
    for(i=0;n<x;i++){
      n=(long)(n*1.01);
    }
    pl(i+"");
  }

  public static int aa(int n){
    if(n>0){return 1;}
    return 0;
  }

  public static void pr(String str){
    System.out.print(str);
  }
  public static void pl(String str){
    System.out.println(str);
  }
}


Measured memory_bytes: 38748
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
using ll = 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> void drop(T x){cout<<x<<endl;exit(0);};
struct UnionFind{
  int num;
  vector<int> r, p;
  UnionFind(){}
  UnionFind(int n):num(n), r(n, 1), p(n, 0){iota(p.begin(), p.end(), 0);}

  int find(int x){
    return (x == p[x]? x:p[x] = find(p[x]));
  }

  bool same(int x, int y){
    return find(x) == find(y);
  }

  void unite(int x,int y){
    x = find(x), y = find(y);
    if(x == y) return;
    if(r[x] < r[y]) swap(x, y);
    r[x] += r[y];
    p[y] = x;
    num--;
  }

  int size(int x){
    return r[find(x)];
  }

  int count()const{
    return num;
  }
};


struct BiMatch{
  int n, time;
  vector<vector<int> > G;
  vector<int> match, used, dead;

  BiMatch(){}
  BiMatch(int n):n(n), time(0), G(n), match(n, -1), used(n, -1), dead(n, 0){}

  void add_edge(int u, int v){
    G[u].emplace_back(v);
    G[v].emplace_back(u);
  }

  int dfs(int v){
    used[v] = time;
    for(int u:G[v]){
      if(dead[u]) continue;
      int w = match[u];
      if((w < 0) || (used[w]<time && !dead[w] && dfs(w))){
        match[v] = u;
        match[u] = v;
        return 1;
      }
    }
    return 0;
  }

  int build(){
    int res = 0;
    for(int v=0;v<n;v++){
      if(dead[v]) continue;
      if(match[v] < 0){
        time++;
        res += dfs(v);
      }
    }
    return res;
  }
};


signed main(){
  int n,m;
  cin>>n>>m;
  BiMatch bm(n*2);
  vector<int> xs(m),ys(m);
  for(int i=0;i<m;i++) cin>>xs[i]>>ys[i];

  vector< vector<int> > G(n*2);
  for(int i=0;i<m;i++){
    xs[i]--;ys[i]--;

    G[0+xs[i]].emplace_back(i);
    G[n+ys[i]].emplace_back(i);

    bm.add_edge(0+xs[i],n+ys[i]);
  }

  UnionFind uf(m);
  for(int i=0;i<n*2;i++)
    for(int v:G[i])
      uf.unite(G[i][0],v);

  cout<<m-bm.build()<<" "<<m-uf.count()<<endl;
  return 0;
}



Measured memory_bytes: 3284
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;

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


ll dp[102][100005] = { 0 };

int main() {
	int n,w;
	cin >> n >> w;
	vector<int> W(n),v(n);
	rep(i, n) cin >> W[i] >> v[i];
	
	rep(i, n){
		for (int wi=0; wi <= w; wi++) {
			if (W[i] <= wi) {
				chmax(dp[i + 1][wi], dp[i][wi - W[i]] + v[i]);
			}
			chmax(dp[i + 1][wi], dp[i][wi]);
		}
	}

	cout << dp[n][w] << endl;
}

Measured memory_bytes: 78336
def calc(s):
    def parse(a, b, c, d):
        nonlocal cur
        g = s[cur]; cur += 1
        if g == '-':
            return 1 ^ parse(a, b, c, d)
        if g == '(':
            p = parse(a, b, c, d)
            cmd = s[cur]; cur += 1
            q = parse(a, b, c, d)
            cur += 1 # ')'
            return p ^ q if cmd == '^' else p & q
        return eval(g)
    res = 0
    for b in range(16):
        cur = 0
        if parse(*map(int, format(b, '04b'))):
            res += 1 << b
    return res
base = "abcd10"
L = {}
for e in base:
    state = calc(e)
    L[state] = 1
ALL = 2**16-1
MAX = 10**18
for i in range(6):
    R = dict(L)
    for p in R:
        if R[p] < 16:
            L[p ^ ALL] = min(L.get(p ^ ALL, MAX), R[p] + 1)
        if R[p]+3 < 16:
            for q in R:
                if R[p] + R[q] + 3 <= 16:
                    L[p & q] = min(L.get(p & q, MAX), R[p] + R[q] + 3)
                    L[p ^ q] = min(L.get(p ^ q, MAX), R[p] + R[q] + 3)
while 1:
    s = input()
    if s == '.':
        break
    print(L[calc(s)])

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

int main()
{
	int len;
	int i;
	int ans;
	char *a = (char *)malloc(200004);
	scanf("%s", a);

	len = strlen(a);
	ans = len;

	for (i = 0; i < len;)
	{
		if (a[i] == 'S' && a[i + 1] == 'T')
		{
			memmove(&a[i], &a[i + 2], len - i);
			--i;
		}
		else
		{
			++i;
		}
	}

	printf("%d\n", strlen(a));

	return 0;
}


Measured memory_bytes: 384
//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring> 
using namespace std;
long long bas; 
int main()
{
 	//freopen("","r",stdin);
	//freopen("","w",stdout);
	long long k,n;cin>>k;n=50;
	bas+=k/n;long long nn=k%n;cout<<n<<endl;
	for(long long i=0;i<n;i++)
	{
		if(i<nn)cout<<n+bas;else cout<<n-nn-1+bas;if(i!=n-1)cout<<" ";
	}cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;

int main() {
    int d;
    cin >> d;
    cout << "Christmas";
    if (d <= 24) cout << " " << "Eve";
    if (d <= 23) cout << " " << "Eve";
    if (d <= 22) cout << " " << "Eve";
    cout << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int N, M;
int x[114514], y[114514];

int yosinagasayuri[114514];
int hamamie[114514];

int main(void) {
	int i;
	int yakusimaruhiroko = 0;
	if (scanf("%d%d", &N, &M) != 2) return 1;
	for (i = 0; i < M; i++) {
		if (scanf("%d%d", &x[i], &y[i]) != 2) return 1;
	}

	yosinagasayuri[1] = 1;
	for (i = 1; i <= N; i++) hamamie[i] = 1;

	for (i = 0; i < M; i++) {
		hamamie[x[i]]--;
		hamamie[y[i]]++;
		if (yosinagasayuri[x[i]]) yosinagasayuri[y[i]] = 1;
		if (hamamie[x[i]] <= 0) yosinagasayuri[x[i]] = 0;
	}
	for (i = 1; i <= N; i++) {
		yakusimaruhiroko += yosinagasayuri[i];
	}
	printf("%d\n", yakusimaruhiroko);
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>


int main()
{
	int mountain,first=1, second=1, third=1;

	for(int i=0;i<10;++i)
	{
		std::cin >> mountain;

		

		if(first<mountain )
		{
			third = second;

			second = first;

			first = mountain;
		}

		else if(second<mountain)
		{
			third = second;

			second = mountain;
		}

		else if(third<mountain)
		{
			third = mountain;
		}

	}

	std::cout << first << '\n' << second << '\n' << third << '\n';
}

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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<long long,long long> ii;
vector<pair<long long,ii>> edge;
long long n,up[100005],sz[100005];
pair<ii,long long> x[100005];

bool cmp(const pair<ii,long long> &a,const pair<ii,long long> &b){
    return a.fi.fi<b.fi.fi;
}
bool cmp1(const pair<ii,long long> &a,const pair<ii,long long> &b){
    return a.fi.se<b.fi.se;
}
int findSet(int x){
    if(x==up[x]) return x;
    else return findSet(up[x]);
}
void unionSet(int x,int y){
    long long x1=findSet(x),y1=findSet(y);
    if(sz[x1]<sz[y1]) swap(x1,y1);
    up[y1]=x1;
    sz[x1]+=sz[y1];
}
bool checkSet(int x,int y){
    long long x1=findSet(x),x2=findSet(y);
    if(x1==x2)
        return 1;
    else
        return 0;
}
int main(){
    cin.tie(0),cout.tie(0),ios::sync_with_stdio(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x[i].fi.fi>>x[i].fi.se;
        x[i].se=i;
    }
    sort(x+1,x+1+n,cmp);
    for(int i=1;i<=n;i++){
        up[i]=i;
        sz[i]=1;
    }
    for(int i=1;i<n;i++){
        long long x1=x[i].se,x2=x[i+1].se;
        long long val=abs(x[i].fi.fi-x[i+1].fi.fi),val1=abs(x[i].fi.se-x[i+1].fi.se);
        edge.pb(mp(min(val,val1),mp(x1,x2)));
    }
    sort(x+1,x+1+n,cmp1);
    for(int i=1;i<n;i++){
        long long x1=x[i].se,x2=x[i+1].se;
        long long val=abs(x[i].fi.fi-x[i+1].fi.fi),val1=abs(x[i].fi.se-x[i+1].fi.se);
        edge.pb(mp(min(val,val1),mp(x1,x2)));
    }
    long long sum=0;
    sort(edge.begin(),edge.end());
    for(int i=0;i<edge.size();i++){
        long long x1=edge[i].se.fi,x2=edge[i].se.se;
        if(checkSet(x1,x2)==0){
            unionSet(x1,x2);
            sum+=edge[i].fi;
        }
    }
    cout<<sum;
}

Measured memory_bytes: 12528
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <cmath>
#include <numeric>
#include <stack>
#include <iomanip>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

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

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t sz;
        inp(std::size_t _sz = 1) : sz(_sz) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(sz); for (std::size_t i = 0; i < sz; i++) std::cin >> a[i]; return a; }
    };

    // 2次元用の標準入出力
    template<typename T>
    struct inpn {
        std::size_t szi, szj;
        inpn(std::size_t _szi, std::size_t _szj) : szi(_szi), szj(_szj) {}
        operator std::vector<std::vector<T>>() const {
            std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
            for (std::size_t i = 0; i < szi; ++i)
                for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j];
            return a;
        }
    };

    inp inp1; // input one
}

int main() {

    int n, m;
    cin >> n >> m;
    vector<ll> h = inp(n);
    vector<int> a(m), b(m);
    rep(i, m) cin >> a[i] >> b[i];

    vector<vector<int>> G(n);

    rep(i, m) {
        G[a[i] - 1].push_back(b[i] - 1);
        G[b[i] - 1].push_back(a[i] - 1);
    }

    int ans = 0;
    rep(i, n) {
        int tmp = h[i];
        bool ok = true;
        for (auto u : G[i]) {
            if (tmp <= h[u]) {
                ok = false;
                break;
            }
        }
        if (ok) ++ans;
    }

    Cout(ans);

    return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(){

  int a,b;cin>>a>>b;
  if(a>b){out(a-1);}
  else out(a);

  return 0;
}


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

vector<int> ans;

bool dfs(vector<int> v){
    int n = v.size();
    if(n == 0){
        return true;
    }
    for(int i = n - 1; i >= 0; i--){
        if(v[i] > i){
            return false;
        }
        if(v[i] == i){
            ans.push_back(i);
            v.erase(v.begin() + i);
            return dfs(v);
        }
    }
    return false;
}

int main()
{
    int n;
    cin >> n;
    vector<int> b(n);
    for(int i = 0; i < n; i++){
        cin >> b[i];
        b[i]--;
    }
    if(dfs(b)){
        for(int i = 0; i < n; i++){
            cout << ans[n - i - 1] + 1 << endl;
        }
    }
    else{
        cout << -1 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int X,Y;cin>>X>>Y;
    cout<<X+Y/2<<endl;
}


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

//ビット演算を利用
int main() {
  //入力
  int N, M;
  cin >> N >> M;
  //N個のスイッチの状態を表すvector
  vector<int> a(N);
  //M個の電球それぞれについて
  for (int i = 0; i < M; i++) {
    int k;
    cin >> k;
    //電球 i に繋がっている k個のスイッチについて
    for (int j = 0; j < k; j++) {
      //k個のスイッチのうちs番スイッチについて
      int s;
      cin >> s;
      s--;
      //電球が繋がってるときは１となる（１と３が繋がってるときは 10100... となる）
      a[s] |= 1<<i;
    }
  }
  int p = 0;
  for (int i = 0; i < M; i++) {
    int x;
    cin >> x;
    p |= x<<i;
  }

  //処理
  int ans = 0;
  for (int s = 0; s < (1<<N); s++) {
    int t = 0;
    for (int i = 0; i < N; i++) {
      if (s>>i & 1) {
        t ^= a[i];
      }
    }
    if (t == p) {
      ans++;
    }
  }

  //出力
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		long ans = 0L;
		int t = 0;
		for (int i = 0; i < N; i++) {
			int a = sc.nextInt();
			if (t > a) {
				ans += t - a;
			}
			if (t <= a) {
				t = a;
			}
		}
		System.out.println(ans);
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 34792
#include "bits/stdc++.h"
using namespace std;

long long nCr(int n, int r) {
	long long ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	map<int, int> mapA;

	//cout << nCr(1, 2) <<  endl;

	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (mapA.count(A[i]) == 0)mapA[A[i]] = 1;
		else mapA[A[i]]++;
	}

	long long  sum = 0;

	for (auto x : mapA) {
		//cout << x.first << "," << x.second << endl;
		if (x.second > 1)sum += nCr(x.second, 2);
	}

	//cout << sum << endl;

	for (int k = 0; k < N; k++) {
		int num = A[k];
		if (mapA[num] > 1)cout << sum - nCr(mapA[num], 2) + nCr(mapA[num] - 1, 2) << endl;
		else cout << sum << endl;
	}
}

Measured memory_bytes: 8320
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv) {
  char s[101];
  scanf("%s", s);
  for (char *p = s; *p; p++) {
    printf("x");
  }
  printf("\n");
  return EXIT_SUCCESS;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>
#include <sstream>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	string S;
	vector<int> A,AA;
	cin >> S;

	for (int i = 0; i < S.size(); i++)
	{
		int c = (int)(S[i] - '0');
		A.push_back(c);
	}
	for (int i = 0; i < S.size()-2; i++)
	{
		int c =abs(753-(100*A[i]+10*A[i+1]+A[i+2]));
		AA.push_back(c);
	}
	sort(AA.begin(),AA.end());
	cout << AA.front() <<endl;

}

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

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N, K, ans = 1;

	cin >> N >> K;
	
	while (N / K > 0) {
		ans++;
		N /= K;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import sys
n = int(input())
s = set([])
last = str(input())
s.add(last)
for i in range(n-1):
    tmp = str(input())
    
    if not (last[len(last)-1] == tmp[0]):
        print('No')
        sys.exit()
    
    s.add(tmp)
    last = tmp

print('Yes') if len(s) == n else print('No')


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

int main() {
  string A, B;
  cin >> A; 
  cin >> B;
  if (A[0] == B[2] && A[1] == B[1] && A[2] == B[0])cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
import sys
from math import ceil

def divceil(a,b):
    if a%b > 0:
        return a/b+1
    else:
        return a/b

N, H = [int(x) for x in raw_input().split(" ")]
a, b = [], []
for n in xrange(N):
    _a, _b = [int(x) for x in raw_input().split(" ")]
    a.append(_a)
    b.append(_b)
maxA = max(a)
b = sorted(b, key = lambda x:-x)

damage_sum = 0
for i,_b in enumerate(b):
    if _b > maxA:
        damage_sum += _b
        if damage_sum >= H:
            print i + 1
            sys.exit()
    else:
        i -= 1
        break
print i + 1 + divceil(H-damage_sum, maxA)

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

// macro
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int n;cin>>n;
  vector<int> a(n);
  int i;
  rep(i,n)cin>>a[i];
  vector<ll> count(n+1,0);
  rep(i,n)count[a[i]]++;
  ll kans=0;
  for(i=1;i<=n;i++)
  {
    if(count[i]>0)kans+=count[i]*(count[i]-1)/2;
  }
  rep(i,n)
  {
    if(count[a[i]]>1)cout<<kans-(count[a[i]]-1)<<endl;
    else cout<<kans<<endl;
  }
}


Measured memory_bytes: 4992
#include <iostream>
#include <cctype>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	string s;
	cin >> s;
	string wa = "WA";
	string ac = "AC";
	string check_c = s.substr(2, s.size() - 3);
	int num_c  = count(check_c.begin(), check_c.end(), 'C');
	int id_c = (int)s.find_first_of("C");
	if (s.substr(0,1) != "A") {
		cout << wa << endl;
		return 0;
	} else if (num_c != 1) {
		cout << wa << endl;
		return 0;
	} else {
		for (size_t i = 0; i < s.size(); ++i) {
			if(i == 0 || i == id_c) continue;
			if (isupper(s[i])) {
				cout << wa << endl;
				return 0;
			}
		}
	}
	cout << ac << endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np
Q = int(input())
lr = [list(map(int, input().split())) for _ in range(Q)]

U = 10**5 * 1
is_prime = np.ones(U, dtype='bool')
is_prime[0:2] = False
for i in range(2, U):
    if i * i > 10**5:
        break
    if is_prime[i]:
        is_prime[i * 2::i] = False

like_2017 = np.zeros(U, dtype='bool')
for i in range(1, U):
    if 2 * i > U:
        break
    if is_prime[i] and is_prime[i * 2 - 1]:
        like_2017[i * 2 - 1] = True
cumsum = like_2017.cumsum()

for l, r in lr:
    print(cumsum[r] - cumsum[l - 1])


Measured memory_bytes: 38160
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := nextInts(n)
	ans := 0
	for i := range a {
		for a[i]&1 == 0 {
			a[i] >>= 1
			ans++
		}
	}
	puts(ans)
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 896