akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) { 
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

// ax + by = gcd(a, b) となる {x, y, gcd(a, b)} を返す
// O(log(min(a, b)))
ll extgcd(ll a, ll b, ll &x, ll &y) {
    ll g = a; x = 1, y = 0;
    if(b != 0) g = extgcd(b, a%b, y, x), y -= (a/b) * x;
    return g;
}

// a^-1 mod n を返す　存在しなければ-1
// O(log(n))
ll inv(ll a, ll n) {
    ll s, t;
    extgcd(a, n, s, t);
    return (n+s) % n;
}

// O(a.size*logM)
// 連立線形合同式 a[i] * x ≡ b[i] (mod m[i]) を解く
// オーバーフローには注意
pair<ll, ll> crt(const vector<ll>& a, const vector<ll>& b, const vector<ll>& m) {
    // (答えx, mod)
    pair<ll, ll> ret(0, 1);
    REP(i, a.size()) {
        ll s = a[i] * ret.second;
        ll t = b[i] - a[i] * ret.first;
        ll d = __gcd(m[i], s);
        if(t % d != 0) return make_pair(-1, -1);
        ll u = t / d * inv(s / d, m[i] / d) % (m[i] / d);
        ret.first += ret.second * u;
        ret.second *= m[i] / d;
        ret.first = (ret.first % ret.second + ret.second) % ret.second;
    }
    return ret;
}

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

    ll n, m, d;
    cin >> n >> m >> d;
    vector<ll> a(m);
    REP(i, m) cin >> a[i];
    REP(i, d) {
        vector<ll> x, y;
        REP(j, m) {
            ll r;
            cin >> r;
            if(r == -1) continue;
            x.push_back(r);
            y.push_back(a[j]);
        }

        vector<ll> v(x.size(), 1);
        PII p = crt(v, x, y);
        // p.second * k + p.first <= n である最大の整数
        if(p.first == -1 || n < p.first) {
            cout << -1 << endl;
            return 0;
        }
        ll k = (n-p.first) / p.second;
        n = p.second * k + p.first;
        // cerr << "x:" << x << endl;
        // cerr << "y:" << y << endl;
        // cerr << p << " " << n << endl;
    }
    cout << n << endl;

    return 0;
}



Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    set<int> si;
    for (int i = 0; i < K && A + i <= B; i++) si.insert(A + i);
    for (int i = 0; i < K && B - K + i + 1 >= A; i++) si.insert(B - K + i + 1);
    for (int ans : si) cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

int A, B, C, K;

signed main()
{
	cin >> A >> B >> C >> K;
	if (K % 2 == 0)
	{
		cout << (A - B) << endl;
	}
	else
	{
		cout << (B - A) << endl;
	}
}







Measured memory_bytes: 256
S = input()

if S == "SUN":
	print("7")
elif S == "MON":
	print("6")
elif S == "TUE":
	print("5")
elif S == "WED":
	print("4")
elif S == "THU":
	print("3")
elif S == "FRI":
	print("2")
elif S == "SAT":
	print("1")

Measured memory_bytes: 9088
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

int main(){
  int D,G;
  cin >> D >> G;
  int p[D],c[D];
  for(int i = 0; i < D; i++){
    cin >> p[i] >> c[i];
  }

  int total,cnt;
  int Ans = 100000000;
  for(int bit = 0; bit < (1<<D); bit++){
    total = 0;
    cnt = 0;
    for(int i = 0; i < D; i++){
      if(bit & (1<<i)){
        total += 100*(i+1)*p[i] + c[i];
        cnt += p[i];
      }
    }

    if(G > total){
      for(int i = D-1; i >= 0; i--){
        if(!(bit & (1<<i))){
          if((G-total+100*(i+1)-1)/(100*(i+1))<p[i]){
            cnt += (G-total+100*(i+1)-1)/(100*(i+1));
          }else{
            cnt = Ans;
          }
          break;
        }
      }
    }

    Ans = min(Ans,cnt);
  }

  printf("%d\n",Ans);
  return 0;

}


Measured memory_bytes: 256
#include <stdio.h>
#define NUM 1200

int main(void) {
  char str[NUM];
  int i,j;

  scanf("%[^\n]",str);
  while(str[i]!=0){
    if('A'<=str[i]&&str[i]<='Z')
      str[i]+=32;
    else if('a'<=str[i]&&str[i]<='z')
      str[i]-=32;
    i++;
  }
  printf("%s\n",str);

  return 0;
}

Measured memory_bytes: 524
#include <iostream>
int main(void) {
  std::string s;
  std::cin >> s;

  int64_t count = 0;
  int64_t chokuA = 0;

  if (s.length() <= 2) {
    std::cout << 0 << std::endl;
    return 0;
  }

  for (int i = 0, end = s.length() - 1; i < end; ++i) {
    if (s[i] == 'A') {
      ++chokuA;
    } else if ((s[i + 0] == 'B') && (s[i + 1] == 'C')) {
      count += chokuA;
      ++i;
    } else {
      chokuA = 0;
    }
  }

  std::cout << count << std::endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
int mypow(int a,int b,int c){
	if(b==0)return 1;
	if(b%2)return mypow(a,b-1,c)*a%c;
	int z=mypow(a,b/2,c);
	return z*z%c;
}
signed main(){
	int a,aa,b,z,ans=0;
	cin>>a>>aa;
	int sum=1;
	if(a==2){
		int x=0,y=0;
		f(i,aa){
			cin>>b;
			if(i%2&&b==1)x++;
			else if(b==1)y++;
			ans=min((aa+1)/2-y+x,y+aa/2-x);
		}
		cout<<ans<<endl;
		return 0;
	}
	f(i,aa){
		cin>>b;
		if(i){
			if(b!=z){
				ans+=sum/2;
				sum=1;
			}
			else sum++;
		}
		z=b;
	}
	ans+=sum/2;
	cout<<ans<<endl;
}




Measured memory_bytes: 3116
#include<iostream>
#include<vector>

using namespace std;

const int MOD = 1e9 + 7;
int N;

int main() {
    cin >> N;
    vector<bool> prime(N + 1, false);
    long long ans = 1;
    for (int i = 2; i <= N; i++) {
        bool flag = true;
        for (int j = 2; j < i; j++)
            if (i % j == 0)
                flag = false;
        if (flag)
            prime[i] = true;
    }
    for (int i = 2; i <= N; i++) {
        if(prime[i]) {
            long long res = 0, temp = i;
            while(temp <= N) {
                res += N / temp;
                temp *= i;
            }
            ans *= (res + 1) % MOD;
            ans %= MOD;
        }
    }
    cout << ans % MOD << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
#define MAX_C 1000000001
#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<ll> a(n), b(n), c(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n; i++) cin >> c[i];

  //cout << (int) a.size() << endl;

  sort(a.begin(), a.end());
  //sort(b.begin(), b.end());
  sort(c.begin(), c.end());

  ll cnt = 0;
  for (int i = 0; i < n; i++) {
    ll bi = b[i];
    //auto ita = lower_bound(a.begin(), a.end(), bi);
    //if (ita == a.begin()) continue;
    //ita--;
    //auto itc = upper_bound(c.begin(), c.end(), bi);
    //cnt += (ll) (ita - a.begin() + 1) * (c.end() - itc);
    //cnt += (ll) (distance(a.begin(), ita) + 1) * (distance(itc, c.end()));
    //cnt += (ll) (ita - a.begin()) * (c.end() - itc);
    ll p = lower_bound(a.begin(), a.end(), bi) - a.begin();
    ll q = c.end() - upper_bound(c.begin(), c.end(), bi);
    cnt += p * q;
  }

  cout << cnt << endl;
}


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

using namespace std;


int main(){
    long H, W, N;
    cin>>H>>W>>N;
    long sr, sc;
    cin>>sr>>sc;
    string S, T;
    cin>>S>>T;

    long p;
    p = sr;
    for(int i=0; i<N; ++i){
        if(S[i] == 'U'){
            p-=1;
        }
        if(p==0){
            cout<<"NO"<<endl;
            return 0;
        }

        if(T[i] == 'D' && p!=H){
            p+=1;
        }
    }
    p = sr;
    for(int i=0; i<N; ++i){
        if(S[i] == 'D'){
            p+=1;
        }
        if(p==H+1){
            cout<<"NO"<<endl;
            return 0;
        }

        if(T[i] == 'U' && p!=1){
            p-=1;
        }
    }

    p = sc;
    for(int i=0; i<N; ++i){
        if(S[i] == 'L'){
            p-=1;
        }
        if(p==0){
            cout<<"NO"<<endl;
            return 0;
        }

        if(T[i] == 'R' && p!=W){
            p+=1;
        }
    }
    p = sc;
    for(int i=0; i<N; ++i){
        if(S[i] == 'R'){
            p+=1;
        }
        if(p==W+1){
            cout<<"NO"<<endl;
            return 0;
        }

        if(T[i] == 'L' && p!=1){
            p-=1;
        }
    }

    cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 776
Q = 10**9+7
def main():
    N = int( input())
    T = list( map( int, input().split()))
    A = list( map( int, input().split()))
    ANS = [0]*N
    now = 0
    AC = [False]*N
    for i in range(N):
        if now < T[i]:
            ANS[i] = T[i]
            AC[i] = True
        now = T[i]
    now = 0
    for i in range(N-1,-1,-1):
        if now < A[i]:
            if AC[i]:
                if A[i] != T[i]:
                    print(0)
                    return
            else:
                if A[i] > T[i]:
                    print(0)
                    return
                else:
                    ANS[i] = A[i]
        now = A[i]
    # for i in range(N):
    #     if ANS[i] == 0:
    #         ANS[i] = min(A[i],B[i])
    ans = 1
    for i in range(N):
        if ANS[i] == 0:
            ans *= min(A[i],T[i])
            ans %= Q
    print(ans)
if __name__ == '__main__':
    main()


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

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

    int dp[n];
    dp[0] = 0;

    for (int i = 1; i < n; ++i) {
        if (i <= 2) dp[i] = dp[0] + abs(h[i] - h[0]);
        else {
            if (dp[i - 1] + abs(h[i] - h[i - 1]) < dp[i - 2] + abs(h[i] - h[i - 2])) dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
            else dp[i] = dp[i - 2] + abs(h[i] - h[i - 2]);
        }
    }

    cout << dp[n - 1] << endl;
}


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

struct Card {
  int rank;
  char suit;
};

const int N = 100000;
const int INFTY = 1000000001;

int partition(int l, int r, Card A[]) {
  int i, j, x;

  x = A[r].rank;
  i = l - 1;

  for (j = l; j < r; j++) {
    if (A[j].rank <= x) {
      i++;
      swap(A[j], A[i]);
    }
  }
  swap(A[i+1], A[r]);

  return i + 1;
}

void quick_sort(int l, int r, Card A[]) {
  if (l < r) {
    int q = partition(l, r, A);
    quick_sort(l, q-1, A);
    quick_sort(q+1, r, A);
  }
}

void merge(int l, int m, int r, Card A[]) {
  int i, j, k;
  int n1 = m - l;
  int n2 = r - m;
  Card L[n1+1], R[n2+1];

  for (i = 0; i < n1; i++) L[i] = A[i+l];
  L[n1].rank = INFTY;
  for (i = 0; i < n2; i++) R[i] = A[i+m];
  R[n2].rank = INFTY;

  j = 0;
  k = 0;  
  for (i = l; i < r; i++) {
    if (L[j].rank <= R[k].rank) A[i] = L[j++];
    else A[i] = R[k++];
  }
}

void merge_sort(int l, int r, Card A[]) {
  if (l + 1 < r) {
    int m = (l + r) / 2;
    merge_sort(l, m, A);
    merge_sort(m, r, A);
    merge(l, m, r, A);
  }
}

bool is_stable(int n, Card A[], Card B[]) {
  for (int i = 0; i < n; i++) {
    if (A[i].suit != B[i].suit) return false;
  }
  return true;
}

int main() {
  int i, n;
  Card A[N], B[N];

  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> A[i].suit >> A[i].rank;
    B[i] = A[i];
  }

  quick_sort(0, n-1, A);
  merge_sort(0, n, B);

  if (is_stable(n, A, B)) cout << "Stable" << endl;
  else cout << "Not stable" << endl;
  for (i = 0; i < n; i++) cout << A[i].suit << " " << A[i].rank << endl;

  return 0;
}


Measured memory_bytes: 5344
#include<algorithm>
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<list>
#include<sstream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	cout<<a-b+1;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <string>
using namespace std;
int main(){
	int ans=0;
	char c[100]="";
	string str;
	while(cin>>str){
		for(int i=0;i<str.size();i++){
			c[i]=str[i];
			switch(c[i]){
			case'I':
				ans+=1;
				break;
			case'V':
				if(c[i-1]=='I'){
					ans+=3;
					break;
				}else{
					ans+=5;
					break;
				}
			case'X':
				if(c[i-1]=='I'){
					ans+=8;
					break;
				}else{
					ans+=10;
					break;
				}
			case'L':
				if(c[i-1]=='X'){
					ans+=30;
					break;
				}else{
					ans+=50;
					break;
				}
			case'C':
				if(c[i-1]=='X'){
					ans+=80;
					break;
				}else{
					ans+=100;
					break;
				}
			case'D':
				if(c[i-1]=='C'){
					ans+=300;
					break;
				}else{
					ans+=500;
					break;
				}
			case'M':
				if(c[i-1]=='C'){
					ans+=800;
					break;
				}else{
					ans+=1000;
					break;
				}
			}
		}
		cout<<ans<<endl;
		ans=0;
		int c[100];
	}
	return 0;
}

Measured memory_bytes: 2988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll ans=1;
	for(ll i=1;i<n;i++){
		if(s[i-1]!=s[i]){
			ans++;
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
 int gcd(int a,int b);
int main(){
	int n;
	int num[100000];
	int gcdNum[100000][3];
	int max =1;
	int min =0;
	std::cin>>n;
	for(int i=0;i<n;i++){
	    std::cin>>num[i];
	    if(num[i]==1){
	        std::cout<<1;
	        return 0;
	    }
	}
	gcdNum[0][0] = num[0];
	gcdNum[1][0] = num[0];
	for(int i=2;i<n;i++){
	    gcdNum[i][0] = gcd( gcdNum[i-1][0],num[i-1]);
	}
	gcdNum[n-1][1] = num[n-1];
	gcdNum[n-2][1] = num[n-1];
	for(int i=n-3;i>=0;i--){
	    gcdNum[i][1] = gcd( gcdNum[i+1][1],num[i+1]);
	}
	gcdNum[0][0] = gcdNum[0][1];
	gcdNum[n-1][1] = gcdNum[n-1][0];
	for(int i=0;i<n;i++){
	    gcdNum[i][2]=gcd(gcdNum[i][0] ,gcdNum[i][1] );
	    max = (gcdNum[i][2]>max)?(gcdNum[i][2]):(max);
	} 
	std::cout<<max;
  	return 0;
}
inline int gcd(int a,int b)
{
    if (a < b)std::swap(a, b);
	if (a%b==0)
	{
		return(b);
    }
	else
	{
		return(gcd(b,a%b));
    }
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public void Run()
        {
            string S, T;
            S = Console.ReadLine();
            T = Console.ReadLine();
            Console.WriteLine(Check(S, T) && Check(T, S) ? "Yes" : "No");
        }

        public bool Check(string S, string T)
        {

            int[] A = new int[26];
            for (int i = 0; i < 26; i++)
            {
                A[i] = -1;
            }

            for (int i = 0; i < S.Length; i++)
            {
                int c = S[i] - 'a';
                if (A[c] == -1)
                {
                    A[c] = T[i] - 'a';
                }
                else
                {
                    if (A[c] != T[i] - 'a')
                    {
                        return false;
                    }
                }
            }

            return true;
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

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

using namespace std;

int main(){
	
	int sum;
	
	int a,b;
	cin >> a >> b ;
	
	sum =0;
	
	for (int i=1; i < b-a;i++ ){
		sum = sum + i;
		
	}
	cout << sum - a;
	
	
	
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;
  cout << 1000*ceil(n/1000.0) - n << endl;
  return 0;
}

Measured memory_bytes: 3760
package main

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

func main() {
	var H, W int
	fmt.Scanf("%d %d", &H, &W)

	sc := bufio.NewScanner(os.Stdin)
	maps := make([][]byte, H)
	for i := 0; i < H; i++ {
		sc.Scan()
		maps[i] = sc.Bytes()
	}

	count := 0
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			if maps[i][j] == '.' {
				count++
			}
		}
	}

	que := make(queue, 0)
	que = que.Push([]int{0, 0, 1})
	dones := make([]bool, H*W)
	dones[0*W+0] = true
	for len(que) != 0 {
		var target []int
		target, que = que.Pop()
		newTargets := [][]int{
			{target[0] + 1, target[1], target[2] + 1},
			{target[0] - 1, target[1], target[2] + 1},
			{target[0], target[1] + 1, target[2] + 1},
			{target[0], target[1] - 1, target[2] + 1},
		}

		for _, next := range newTargets {
			if next[0] >= 0 && next[0] < H &&
				next[1] >= 0 && next[1] < W &&
				!dones[next[0]*W+next[1]] && maps[next[0]][next[1]] == '.' {
				if next[0] == H-1 && next[1] == W-1 {
					fmt.Println(count - next[2])
					return
				}
				que = que.Push(next)
				dones[next[0]*W+next[1]] = true
			}
		}
	}
	fmt.Println(-1)
}

type queue [][]int

func (q queue) Push(p []int) queue {
	return append(q, p)
}

func (q queue) Pop() ([]int, queue) {
	if len(q) == 1 {
		return q[0], make(queue, 0)
	}
	return q[0], q[1:]
}


Measured memory_bytes: 1152
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];

		ArrayList<int[]> list = new ArrayList<int[]>();
		int[] digit_sum = new int[30];
		for (int i=0;i<N;i++) {
			a[i] = sc.nextInt();
			int tmp = a[i];
			int[] digit = new int[30];
			for (int j=0;j<30;j++) {
				digit[j] = tmp%2;
				digit_sum[j] += digit[j];
				tmp/=2;
			}
			list.add(digit);
		}

		ArrayList<int[]> ans = new ArrayList<int[]>();
		StringBuilder sb = new StringBuilder();
		for (int i=0;i<N;i++) {
			int[] digit = new int[30];
			for (int j=0;j<30;j++) {
				if (digit_sum[j]%2 == 0) {
					if (list.get(i)[j] == 1) {
						digit[j] = 1;
					} else { // list.get(i)[j] == 0
						digit[j] = 0;
					}
				} else { // digit_sum[j]%2 == 1
					if (list.get(i)[j] == 1) {
						digit[j] = 0;
					} else {
						digit[j] = 1;
					}
				}
			}
			long tmp = 0L;
			long val = 1L;
			for (int j=0;j<30;j++) {
				tmp += val*digit[j];
				val *= 2;
			}
			sb.append(tmp);
			if (i != N-1) sb.append(" ");
			ans.add(digit);
		}
		System.out.println(sb);
	}
}

Measured memory_bytes: 112960
#include <bits/stdc++.h>
#pragma optimize("O2")
#define int long long
#define IOS cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false)
using namespace std;
typedef long long ll;
template <class T>
T powmod(T a, ll b, ll m){
	T res = 1;
	while(b){
		if(b % 2){
			res *= a;
			res %= m;
		}
		a = (a * a) % m;
		b /= 2;
	}
	return res;
}

ll modinv(ll a, ll m){
	ll b = a % m;
	a = m;
	ll x1 = 1, x2 = 0;
	ll y1 = 0, y2 = 1;
	while(b){
		ll d = a / b;
		x1 -= y1 * d;
		x2 -= y2 * d;
		a -= b * d;
		swap(x1, y1);
		swap(x2, y2);
		swap(a, b);
	}
	return (x2 + m) % m;
}

void genPrime(ll n, vector<ll> & _lp){
    _lp.resize(n + 1);
	vector<ll> primes;
	for (int i = 2; i <= _lp.size(); i++) {
	    if(_lp[i] == 0){
	        _lp[i] = i;
	        primes.push_back(i);
	    }
	    for(int j = 0; j < primes.size() && primes[j] <= _lp[i] && i * primes[j] <= _lp.size(); j++){
	    	_lp[i * primes[j]] = primes[j];
		}
	}
}

int m = 1e9 + 7;
int A[10000];
map<int, int> prod;
vector<int> lp(1000001);
int32_t main(){
	IOS;
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> A[i];
	}
	genPrime(1000001, lp);
	for(int i = 0; i < n; i++){
		map<int, int> X;
		int x = A[i];
		while(x != 1){
			X[lp[x]]++;
			x /= lp[x];
		}
		for(auto i : X){
			if(prod.find(i.first) == prod.end()){
				prod[i.first] = i.second;
			}else{
				prod[i.first] = max(prod[i.first], i.second);
			}
		}
	}
	int pro = 1;
	for(auto i : prod){
		int x = powmod<ll>(i.first, i.second, m);
		pro = (pro * x) % m;
	}
	int ans = 0;
	for(int i = 0; i < n; i++){
		ans += pro * modinv(A[i], m);
		ans %= m;
	}
	cout << ans << endl;
	return 0;
}

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

struct data {
    data (long a, int b) {
        this->a = a;
        this->b = b;
    }
    long a;
    int b;
};

bool operator<(const data& left, const data& right) {
    return left.a < right.a;
}

int main()
{
    int n, m;
    std::cin >> n;
    std::cin >> m;
    std::vector<data> vec;
    for (int i=0; i<n; i++) {
        long a;
        int b;
        std::cin >> a;
        std::cin >> b;
        vec.push_back(data(a, b));
    }
    std::sort(vec.begin(), vec.end());
    long int ans = 0;
    int index = 0;
    for (int j=0; j<n; j++) {
        if (m >= vec.at(j).b) {
            ans += vec.at(j).a * vec.at(j).b;
            m -= vec.at(j).b;
        } else {
            ans += vec.at(j).a * m;
            break;
        }
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 2420
#include <iostream>

using namespace std;

int main() {
    int a,b,c,d;
    cin>>a>>b>>c;
    d=0;
    for(int i=a;i<=b;i++)
    {
        if (c%i==0)
        {
            d++;
        }
    }
    cout<<d<<endl;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    while(true){
        int h, w; cin >> h >> w;
        if(h == 0 and w == 0) return 0;
        else{
            int ansH = 0, ansW = 0;
            
            int sqMin = INF;
            int i, j;
            [&]{ // lumda式を使うことでループから楽に抜けられる
                for(int i = 0; j * j + i * i <= w * w + h * h; i++){ // ここ多分whileでもっとかっこよく書ける
                    for(int j = i + 1; j * j + i * i <= w * w + h * h; j++){ // j = i + 1にすることで正方形を回避
                        int men = (i + 1) * (i + 1) + (j + 1) * (j + 1);
                        if(i + 1 == h and j + 1 == w) continue; // 元の長方形と同じ奴はダメ
                        if(men == h * h + w * w and (i + 1) > h){ // 面積が同じ時、元の長方形よりもheightは高い必要がある
                            ansH = i + 1;
                            ansW = j + 1;
                            return ;
                        }
                        else if(men > h * h + w * w and sqMin > men){ // いままでに計算してきたやつより面積が小さいか
                            sqMin = men;
                            ansH = i + 1;
                            ansW = j + 1;
                        }
                    }
                }
            }();
            cout << ansH << " " << ansW << endl;
            
        }
    }
}


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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s,t; cin>>s>>t; cout<<t+s<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010];
int main(){
    int n, x, y, z;
    while(cin>>x>>y>>z){
        if(x+y+z>=22){
            cout<<"bust"<<endl;
        }
        else{
            cout<<"win"<<endl;
        }
    }
  return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
ll a,b,c,d;
ll gcd(ll a,ll b)
{
	return a == 0 ? b : gcd(b % a, a);
}
int main()
{
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    ll ans=b/c-a/c+b/d-a/d-(b/(c*d/gcd(c,d))-a/(c*d/gcd(c,d)));
    if(a%c==0)
        ans++;
    if(a%d==0)
        ans++;
    if(a%(c*d)==0)
        ans--;
    ans=b-a+1-ans;
    //cout<<ans<<endl;
    printf("%lld\n",ans);
}


Measured memory_bytes: 256
import math

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

cnt_1 = 0
for i in range(len(A)):
  for j in range(i+1, len(A)):
    if A[i] > A[j]:
      cnt_1 += 1

cnt_2 = 0
for i in range(len(A)):
  for j in range(len(A)):
    if A[i] > A[j]:
      cnt_2 += 1

cnt = cnt_1 * K + cnt_2 * int((K-1)*K//2)

print(cnt % (10**9 + 7))


Measured memory_bytes: 3188
#include <iostream>

using namespace std;

int main()
{
  	string S;
  	cin >> S;
  	int a = 0;
  	for(int i = 0; i < 3; i++){
      if(S.at(i) == '1'){
        a++;
      }
    }
  	cout << a;
  	return 0;
}

Measured memory_bytes: 256
r, g, b, n = map(int, input().split())
ans = 0
for i in range(n + 1):
    total = i * r
    if total > n:
        break
    for j in range(n + 1):
        total2 = total + j * g
        if total2 > n:
            break
        b_cnt = n - total2
        if b_cnt % b == 0:
            ans += 1
print(ans)

Measured memory_bytes: 9084
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Test | diff Test.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Test.cpp && ./a.out

/*

 7/7/2020

 21:55-

 */

const int MAX_N=300+1;
LL A[MAX_N][MAX_N];
int N;

void solve() {
  bool ok=true;
  REP(k,N)REP(i,N)REP(j,N) {
    ok&=(A[i][k]+A[k][j]>=A[i][j]);
    if(A[i][k]+A[k][j]<A[i][j]) {
      //dump(i,k,j,A[i][k],A[k][j],A[i][j]);
    }
  }
  if(!ok) {
    cout<<-1<<endl;
    return;
  }

  VV<int> skip(N,VI(N,0));
  REP(k,N)REP(i,N)REP(j,N) if(A[i][k]!=0&&A[k][j]!=0&&A[i][k]+A[k][j]==A[i][j]) {
    skip[i][j]=1;
    //dump(i,k,j,A[i][k],A[k][j],A[i][j]);
  }
  LL res=0;
  REP(j,N)REP(i,j) if(!skip[i][j]) res+=A[i][j];
  cout<<res<<endl;
}

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

  cin>>N;
  REP(i,N)REP(j,N) cin>>A[i][j];
  solve();

  return 0;
}


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

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    if((A-1)/D>=(C-1)/B) cout << "Yes";
    else cout << "No";

    return 0;
}



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

using namespace std;
typedef long long ll;

int T, n;
const int maxn = 2999+5;

double p[maxn];
double dp[maxn][maxn];

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for(int i = 1; i <= n; i++) cin>>p[i];
  dp[0][0] = 1.0;
  for(int i = 1; i <= n; i++)for(int j = 0; j <= i; j++)
  {
    dp[i][j] = dp[i-1][j]*(1.0-p[i]);
    if(j>0) dp[i][j] += dp[i-1][j-1]*p[i];
  }
  double ans = 0.0;
  for(int i = n/2+1; i <= n; i++) ans += dp[n][i]; //n odd
  cout << fixed << setprecision(10) <<  ans << endl;

  return 0;
}


Measured memory_bytes: 68992
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int N;
  cin >> N;
  int even = N / 2;
  int odd = N / 2 + N % 2;
  cout << even * odd << endl;
  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable long INF = 1L << 58;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto Q = s[1];
    auto A = s[2];
    auto B = s[3];
    auto X = B ~ readln.split.map!(to!int).array;

    auto st1 = new LazySegmentTree!(long)(N+1);
    auto st2 = new LazySegmentTree!(long)(N+1);

    //AM.add(B, B, -INF-B);
    //AP.add(B, B, -INF+B);
    foreach (i; 0..N+1) {
        if (i == A) {
            st1.add(A, A, -A);
            st2.add(A, A, A);
        } else {
            st1.add(i, i, INF - i);
            st2.add(i, i, INF + i);
        }
    }

    foreach (i; 1..Q+1) {
        long m = min(st1.getVal(0, X[i]) + X[i], st2.getVal(X[i], N) - X[i]);
        st1.add(0, N, abs(X[i] - X[i-1]));
        st2.add(0, N, abs(X[i] - X[i-1]));
        long v1 = st1.getVal(X[i-1], X[i-1]);
        long v2 = st2.getVal(X[i-1], X[i-1]);
        long mv = min(m, v1 + X[i-1], v2 - X[i-1]);
        st1.add(X[i-1], X[i-1], -v1 + mv - X[i-1]);
        st2.add(X[i-1], X[i-1], -v2 + mv + X[i-1]);
    }

    long ans = INF;
    foreach (i; 0..N+1) ans = min(ans, st1.getVal(i, i) + i);
    foreach (i; 0..N+1) ans = min(ans, st2.getVal(i, i) - i);
    ans.writeln;
}



class LazySegmentTree(T) {
    T[] add_table;
    T[] min_table;
    int size;

    this(int n) {
        assert(bsr(n) < 29);
        size = 1 << (bsr(n) + 2);
        add_table = new T[](size);
        min_table = new T[](size);
    }

    void add(int a, int b, T num) {
        add(a, b, num, 0, 0, size/2-1);
    }

    void add(int a, int b, T num, int i, int l, int r) {
        if (a > r || b < l) {
            return;
        } if (a <= l && r <= b) {
            add_table[i] += num;
            min_table[i] += num;
        } else {
            add(a, b, num, i*2+1, l, (l+r)/2);
            add(a, b, num, i*2+2, (l+r)/2+1, r);
            min_table[i] = add_table[i] + min(min_table[i*2+1], min_table[i*2+2]);
        }
    }

    T getVal(int a, int b) {
        return getVal(a, b, 0, 0, size/2-1);
    }

    T getVal(int a, int b, int i, int l, int r) {
        if (a > r || b < l) {
            return INF * 5;
        } else if (a <= l && r <= b) {
            return min_table[i];
        }
        return
            add_table[i] + min(getVal(a, b, i*2+1, l, (l+r)/2),
                               getVal(a, b, i*2+2, (l+r)/2+1, r));
    }
}


Measured memory_bytes: 29072
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	
	public static int[] out = new int[]{0000, 1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999};
	public static int[] dir = new int[]{1000, 100, 10, 1};
	
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while(true){
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}else{
				boolean flag = false;
				for(int i : out){
					if(n == i){
						System.out.println("NA");
						flag = true;
						break;
					}
				}
				
				if(flag){
					continue;
				}
			}
			
			int count = 0;
			int cur = n;
			while(cur != 6174){				
				ArrayList<Integer> upper = new ArrayList<Integer>();
				ArrayList<Integer> downer = new ArrayList<Integer>();
				
				for(int i = 0; i < dir.length; i++){
					upper.add((cur / dir[i]) % 10);
					downer.add((cur / dir[i]) % 10);
				}
				
				Collections.sort(upper);
				Collections.sort(downer, Collections.reverseOrder());
				
				//System.out.println(upper);
				//System.out.println(downer);
				
				int up = 0, down = 0;
				for(int i = 0; i < dir.length; i++){
					up += upper.get(i) * dir[i];
					down += downer.get(i) * dir[i];
				}
				
				cur = down - up;
				count++;
				
				if(cur == 6174){
					break;
				}
			}
			
			System.out.println(count);
		}
		
		sc.close();
	}
}

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

int main() {
    int n;
    cin>>n;
    int o=0,e=0;
    for(int i=0;i<n;++i){
        int t;
        cin>>t;
        if(t%2==0)++e;
        else ++o;
    }
    int ans=0;
    if(e==0||o==0){
        cout<<0<<endl;
        return 0;
    }

    if(o%2==1){
        e+=o/2;
        ans+=o/2;
        ans+=e;
    }
    else{
        e+=(o-2)/2;
        ans+=(o-2)/2;
        ans+=e;
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3092
#include <stdio.h>

int main(void) {
	int S[10000], T[500], n, q, i, count;
	count = 0;

	scanf("%d",&n);
	for (i = 0;i < n;i++)
		scanf("%d", &S[i]);

	scanf("%d",&q);
	for (i = 0;i < q;i++) {
		scanf("%d", &T[i]);
		if (linearSearch(S, T[i], n) == 1) {
			count++;
		}
	}

	printf("%d\n", count);
	return 0;

}

int linearSearch(int s[], int key, int n) {
	int i = 0;
	s[n] = key;

	while (s[i] != key)
		i++;
	if (i == n)
		return 0;
	return 1;
}


Measured memory_bytes: 1928
#include <bits/stdc++.h>
using namespace std;
long long N, A, B, C, D; 
map<long long, long long> dp; 
long long F(long long n){
	if(n == 1) return dp[1] = D; 
	if(n == 0) return dp[0] = 0; 
	if(dp[n]) return dp[n]; 
	long long c1, c2, c3; 
	long long c4 = 1e18; 
	if(n % 2 == 0) c1 = F(n/2) + A; 
	else c1 = min(F((n+1)/2), F((n-1)/2)) + A + D;
	if(n % 3 == 0) c2 = F(n/3) + B; 
	else if(n % 3 == 1) c2 = min(F((n-1)/3) + B + D, F((n+2)/3) + B + D * 2); 
	else c2 = min(F((n-2)/3) + B + D * 2, F((n+1)/3) + B + D); 
	if(n % 5 == 0) c3 = F(n/5) + C; 
	else if(n % 5 == 1) c3 = min(F((n-1)/5) + C + D, F((n+4)/5) + C + D * 4);  
	else if(n % 5 == 2) c3 = min(F((n-2)/5) + C + D * 2, F((n+3)/5) + C + D * 3); 
	else if(n % 5 == 3) c3 = min(F((n-3)/5) + C + D * 3, F((n+2)/5) + C + D * 2); 
	else if(n % 5 == 4) c3 = min(F((n-4)/5) + C + D * 4, F((n+1)/5) + C + D); 
	if(n <= (long long) 1000000000000000 / D) c4 = D * n; 
	return dp[n] = min({c1, c2, c3, c4}); 
}
int main(){
	int T; cin >> T; 
	while(T--){
		cin >> N >> A >> B >> C >> D; 
		cout << F(N) << endl; dp.clear(); 
	}
}

Measured memory_bytes: 4400
# include "iostream"
# include "cstdio"
# include "algorithm" 

using namespace std;

int main(){
	register int i; 
	int maxx,minn;
	scanf("%d",&maxx);
	minn=maxx;
	for(i=1;i<=2;i++){
		int now;
		scanf("%d",&now);
		minn=min(minn,now);
		maxx=max(maxx,now); 
	}
	printf("%d",maxx-minn);
	return 0; 
} 

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

int main() {
	int n;
	cin>>n;
	int b[n];
	cin>>b[0];
	int min=b[0],c=1;
	for(int i=1;i<n;i++){
	    cin>>b[i];
	if(b[i]<=min){
	    c++;
	    min=b[i];
	}
	    
	}
	cout<<c;
	
	
}


Measured memory_bytes: 4380
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()
typedef vector<int> vi;
const int INF = 1LL << 58;
const int MOD = 1000000007;
const int MAX_N = 200100;

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    string s, t;
    map<char, vi> mp;
    cin >> s >> t;
    REP(i, s.size())
    {
        mp[s.at(i)].emplace_back(i + 1);
        mp[s.at(i)].emplace_back((i + 1) + s.size());
    }
    REP(i, t.size())
    {
        if (!mp.count(t[i]))
        {
            cout << -1 << endl;
            return 0;
        }
    }
    for (auto i = mp.begin(); i != mp.end(); i++)
    {
        sort(ALL(i->second));
    }
    int ans = 0;
    int tmp = 0;
    REP(i, t.size())
    {
        char c = t[i];
        auto left = lower_bound(mp[c].begin(), mp[c].end(), tmp + 1);
        ans += (*left - tmp);
        tmp = *left;
        tmp %= s.size();
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2800
S = input()

if S == "SUN":
    print(7)
elif S == "MON":
    print(6)
elif S == "TUE":
    print(5)
elif S == "WED":
    print(4)
elif S == "THU":
    print(3)
elif S == "FRI":
    print(2)
else:
    print(1)

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

using namespace std;

int main() {
	int A, B;
	
	cin >> A >> B;
	
	if(A - (2*B) < 0) {
		cout << 0;
	} else {
		cout << A - (2*B);
	}
	
	return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MOD = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = 1LL << 31;
const static int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<llong> H(n);
    rep(i, n) cin >> H[i];

    for (int i = n - 2; i >= 0; --i) {
        if (H[i] > H[i + 1]) --H[i];
    }

    bool flag = true;
    for (int i = 1; i < n; ++i) {
        if (H[i] < H[i - 1]) flag = false;
    }
    
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>

int main(void)
{
	int n;
	char s[50][51];
	int alp[2][26] = { 0 };
	int i, j;
	
	/* 入力 */
	scanf("%d", &n);
	for(i=0; i<n; i++)
		scanf("%s", s[i]);
	
	/* 初期化 */
	for(i=0; s[0][i]!='\0'; i++)
		alp[0][ s[0][i]-'a' ]++;
	
	/* 調査 */
	for(i=1; i<n; i++){
		for(j=0; j<26; j++)
			alp[1][j] = 0;
		
		for(j=0; s[i][j]!='\0'; j++){
			alp[1][ s[i][j]-'a' ]++;
		}
		
		for(j=0; j<26; j++){
			if(alp[0][j] > alp[1][j])
				alp[0][j] = alp[1][j];
		}
	}
	
	/* 出力 */
	for(i=0; i<26; i++){
		for(j=0; j<alp[0][i]; j++)
			putchar('a'+i);
	}
	putchar('\n');
	
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const string YES = "Yes";
const string NO = "No";

void solve(std::string S, std::string T){
    for(int i=0;i<S.size();i++){
        if(S[i] != T[i]){
            cout << NO <<endl;
            return;
        }
    }
    cout << YES << endl;

}

int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[101][101];
	int n,u,k,x;
	memset(a,0,sizeof(a));
	cin>>n;
	for (int i=0; i<n; i++){
		cin>>u>>k;
		while (k--){
			  cin>>x;
			  a[u][x]=1;
		}
	}
	for (int i=1; i<=n; i++){
		cout<<a[i][1];
		for (int j=2; j<=n; j++)
		    cout<<' '<<a[i][j];
		cout<<'\n';
	}
	return 0;
}


Measured memory_bytes: 3112
module WeightedGraph
  (Vertex : sig
    type t
    val compare : t -> t -> int
  end)
  (Weight : sig
    type t
    val compare : t -> t -> int
  end) :
sig
  type 'a church_list = { fold : 'b. ('a -> 'b -> 'b) -> 'b -> 'b }

  val prim :
    (* 隣接リスト *)
    (Vertex.t -> (Vertex.t * Weight.t) church_list) ->
    (* 始点 *)
    Vertex.t ->
    (* 最小全域木に含まれる辺のリスト *)
    (Vertex.t * Vertex.t * Weight.t) church_list
end =
struct
  module VSet = Set.Make (Vertex)
  module WMap = Map.Make (Weight)

  type 'a church_list = { fold : 'b. ('a -> 'b -> 'b) -> 'b -> 'b }

  let prim es s =
    { fold = fun f init ->
        (*
         * プリム法のメインループ
         * acc : 最小全域木に使うのが確定した辺を入れるやつ
         * vs : 訪れた頂点の集合
         * q : 訪れた頂点から伸びる辺が重み順に入ったヒープ
         *)
        let rec prim acc vs q =
          match WMap.min_binding q with
          | exception Not_found -> acc
          | (w, []) -> prim acc vs (WMap.remove w q)
          | (w, (u, v) :: rest) ->
              ( if VSet.mem v vs
                (* vは既に訪れていた *)
                then prim acc vs
                (* vはまだ訪れていなかった *)
                else prim_aux (f (u, v, w) acc) vs v ) (WMap.add w rest q)
        (* vを訪れ，vから伸びる辺をキューに追加してループを続行する *)
        and prim_aux acc vs v q =
          prim acc (VSet.add v vs) @@
          (es v).fold (fun (u, w) q ->
            (* 現時点で既に訪れている頂点への辺は追加しない *)
            if VSet.mem u vs
            then q
            else WMap.add w ((v, u) :: try WMap.find w q with Not_found -> []) q) q in
        prim_aux init VSet.empty s WMap.empty }
end

module Int = struct
  type t = int
  let compare = compare
end

module G = WeightedGraph (Int) (Int)

let () = Scanf.scanf "%d\n" @@ fun n ->
  let xys = Array.to_list @@ Array.init n (fun i -> Scanf.scanf "%d %d\n" (fun x y -> x, y, i)) in
  let es = Array.make n [] in
  begin match List.sort (fun (x, _, _) (x', _, _) -> compare x x') xys with
  | [] -> ()
  | (x, y, i) :: rest ->
      ignore @@ List.fold_left (fun (x, y, i) (x', y', j) ->
        es.(i) <- (j, min (abs (x - x')) (abs (y - y'))) :: es.(i);
        es.(j) <- (i, min (abs (x - x')) (abs (y - y'))) :: es.(j);
        (x', y', j)) (x, y, i) rest
  end;
  begin match List.sort (fun (_, y, _) (_, y', _) -> compare y y') xys with
  | [] -> ()
  | (x, y, i) :: rest ->
      ignore @@ List.fold_left (fun (x, y, i) (x', y', j) ->
        es.(i) <- (j, min (abs (x - x')) (abs (y - y'))) :: es.(i);
        es.(j) <- (i, min (abs (x - x')) (abs (y - y'))) :: es.(j);
        (x', y', j)) (x, y, i) rest
  end;
  Printf.printf "%d\n" @@
  (G.prim (fun v -> { G.fold = fun f -> List.fold_right f es.(v) }) 0).fold (fun (_, _, w) -> ( + ) w) 0


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

int main(){
  int n , answer ;
  cin >> n ;
  vector<int> l(n) ;
  for(int i=0; i<n; i++)
    cin >> l.at(i) ;
  sort(l.begin(),l.end()) ;
  for(int i=0; i<n-2; i++){
    for(int j=1; j<n-i-1; j++){
      for(int k=1; k<n-i-j; k++){
        if(l.at(n-1-i)<l.at(n-1-i-j)+l.at(n-1-i-j-k))
          answer++ ;
        else
          break ;
      }
    }
  }
  cout << answer << endl ;
}

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

int main()
{
    int n, k;
    cin >> n >> k;
    long long tmp = 1;
    int ans = 1;
    while (1)
    {
        tmp *= k;
        if (tmp > n) break;
        ans++;
    } 
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<vector>
#include<queue>
#include<stdio.h>
#include<map>
#include<set>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#define mp make_pair
using namespace std;
typedef long long ll;
inline ll in()
{
    ll res=0,p=1;
    char c=getchar();
    while(c<'0'||c>'9') {if(c=='-') p=-1; c=getchar();}
    while(c>='0'&&c<='9') res=res*10+c-48,c=getchar();
    return p*res;
}
void out(ll x)
{
    if (x>9) out(x/10);
    putchar(x%10+48);
}
void outn(ll x)
{
    if (x<0){
        putchar('-');
        out(-x);
    }else out(x);
    putchar(10);
}
const int mod = 1e9 + 7, inf = 0x3f3f3f3f;
//const double pi = acos(-1.0);
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll quickpow(ll x, int k)
{
    ll res = 1;
    while(k){
        if(k & 1) res = (res * x) % mod;
        k >>= 1, x = (x * x) % mod;
    }
    return res;
}
ll fac[200005] = {1};
ll C(int n, int m){return (fac[n] * quickpow((fac[m] * fac[n - m]) % mod, mod - 2)) % mod;}
const int maxn = 1e5 + 5;

int main()
{
    for (int i = 1; i < 200005; ++i) fac[i] = (fac[i - 1] * i) % mod;
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    ll ans = 0;
    for (int i = b + 1; i <= w; ++i)
        ans = (ans + C(i - 1 + h - a - 1, h - a - 1) * C(w - i + a - 1, w - i)) % mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
function Main(input) {
  	const input_split = input.split("\n");
  	let member_shincho = input_split[1].split(" ")
    member_shincho = member_shincho.map(x => parseInt(x))
  	let member_shincho2 = member_shincho
    
    let output = 0
    
    for(i=1;i<member_shincho.length;i++){
    	if(member_shincho[i-1] > member_shincho[i]){
          output += member_shincho[i-1] - member_shincho[i]
          
          member_shincho[i] = member_shincho[i-1]
          
        }
    }
       
    
    
	console.log(output);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 50384