akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      if ((a * b) % 2 == 0) {
         System.out.println("Even");
      } else {
         System.out.println("Odd");
      }
   }
}

Measured memory_bytes: 21840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int n,m;
char g[22][22];
bool ch(int i,int j){
	if(i>0&&j>0&&i<=n&&j<=m)return true;
	return false;
}
int bfs(int i,int j){
	bool vstd[n+1][m+1];
	memset(vstd,false,sizeof vstd);
	int dst[n+1][m+1];
	for(int z=0;z<=n;z++){
		for(int zz=0;zz<=m;zz++)dst[z][zz]=1e9;
	}
	dst[i][j]=0;
	queue<pair<int,int> >q;
	q.push({i,j});
	while(q.size()){
		int ndx=q.front().first,ndy=q.front().second;
		q.pop();
		if(vstd[ndx][ndy])continue;
		vstd[ndx][ndy]=true;
		if(ch(ndx+1,ndy)&&g[ndx+1][ndy]=='.'){
			if(dst[ndx+1][ndy]>dst[ndx][ndy]+1){
				dst[ndx+1][ndy]=dst[ndx][ndy]+1;
				q.push({ndx+1,ndy});
			}
		}
		if(ch(ndx-1,ndy)&&g[ndx-1][ndy]=='.'){
			if(dst[ndx-1][ndy]>dst[ndx][ndy]+1){
				dst[ndx-1][ndy]=dst[ndx][ndy]+1;
				q.push({ndx-1,ndy});
			}	
		}
		if(ch(ndx,ndy+1)&&g[ndx][ndy+1]=='.'){
			if(dst[ndx][ndy+1]>dst[ndx][ndy]+1){
				dst[ndx][ndy+1]=dst[ndx][ndy]+1;
				q.push({ndx,ndy+1});
			}
		}
		if(ch(ndx,ndy-1)&&g[ndx][ndy-1]=='.'){
			if(dst[ndx][ndy-1]>dst[ndx][ndy]+1){
				dst[ndx][ndy-1]=dst[ndx][ndy]+1;
				q.push({ndx,ndy-1});
			}
		}
	}
	int mx=0;
	for(int z=1;z<=n;z++)
		for(int zz=1;zz<=m;zz++){
		if(g[z][zz]=='.')mx=max(mx,dst[z][zz]);
	}
	return mx;
}
int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>g[i][j];
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(g[i][j]=='.')ans=max(ans,bfs(i,j));
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int p[110];
int n;
int s(int x){
  int sum=0;
  for(int i=0;i<n;i++){
    sum+=(p[i]-x)*(p[i]-x);
  }
  return sum;
}
int main(){

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>p[i];
  }
  sort(p,p+n);
  int sum=s(p[0]);
  for(int i=p[0]+1;i<=p[n-1];i++){
    int t=s(i);
    if(t>=sum) break;
    sum=t;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(ll i=0;i<N;++i)
typedef long long int ll;
ll INF = 1LL<<60;

int main(){
    int m,d; cin >> m >> d;
    int ans = 0;
    for(int i=1;i<=m;i++){
        for(int j=1;j<=d;j++){
            int d1 = j / 10;
            int d2 = j % 10;
            if(i == d1 * d2 && d1 >= 2 && d2 >= 2){
                //cout << i << " " << d1 << " " << d2 << endl;
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
    char str[1001],order[1001];
    int a,b,q;
    int i,j,n;
    scanf("%s %d",str,&q);
    for(i=0;i<q;i++){
        scanf("%s",order);
        if(strcmp(order,"print")==0){
            scanf("%d %d",&a,&b);
            for(j=a;j<=b;j++){
                printf("%c",str[j]);
            }
            printf("\n");
        }else if(strcmp(order,"reverse")==0){
            scanf("%d %d",&a,&b);
            strcpy(order,str);
            for(j=a,n=b;n-a>=0;j++,n--){
                str[j]=order[n];
            }
        }else{
            scanf("%d %d %s",&a,&b,order);
            for(j=a;j<=b;j++){
                str[j]=order[j-a];
            }

        }
    }
    return 0;
}


Measured memory_bytes: 2088
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7

dp=[1]
col=[]
for i in range(N):
    if A[i]==0:
        col.append(1)
        dp.append(dp[-1]*(4-len(col)))
    else:
        p=0
        for c in range(len(col)):
            if col[c]==A[i]:
                p+=1
                if p==1:
                    col[c]+=1
        dp.append(dp[-1]*p%mod)

print(dp[-1]%mod)


Measured memory_bytes: 20620
ansl = []
s = input()
for i in range(len(s)):
  if s[i] == "0":
    ansl.append("0")
  elif s[i] == "1":
    ansl.append("1")
  elif s[i] == "B":
    if len(ansl) > 0:
      ansl.pop()
s=""
for i in range(len(ansl)):
  s += ansl[i]
print(s)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<(int)(b);(i)++)
#define RREP(i,a,b) for(int (i)=(a);(i)>=(int)(b);(i)--)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;



int main(){
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    a *= 100;
    b *= 100;

    vector<int> w, s;
    REP(i,0,f + 1){
        REP(j,0,f + 1){
            if (a * i + b * j > f) continue;
            if (i == 0 && j == 0) continue;
            w.push_back(a * i + b * j);
        }
    }

    REP(i,0,f + 1){
        REP(j,0,f + 1){
            if (c * i + d * j > f) continue;
            s.push_back(c * i + d * j);
        }
    }

    int answ, anss;
    double maxc = 0.0;
    double limc = 1.0 * 100 * e / (100 + e);
    REP(i,0,w.size()){
        REP(j,0,s.size()){
            if (w[i] + s[j] > f) continue;
            double temp = 1.0 * (100 * s[j]) / (w[i] + s[j]);
            if (temp > limc) continue;
            if (maxc <= temp){
                maxc = temp;
                answ = w[i];
                anss = s[j];
            }
        }
    }

    cout << answ + anss << " " << anss << endl;
    
    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  int n; cin>>n;
  VI a(n),b(n); rep(i,n) cin>>a[i]>>b[i];
  ll cnt = 0;
  REP(i,n){
    cnt += (b[i]-(a[i]+cnt)%b[i])%b[i];
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 1024
iN ,iX  = [int(x) for x in input().split()]
aCum = [0]
for x in input().split():
    aCum += [aCum[-1] + int(x)]

def fCeil(iT,iR):
    return -1 * iT // iR * -1
def fCalcCost(iN,iX,aCum,iK):
    iCost = (iN + iK ) * iX + 5 * aCum[iN]
    for i in range(2,fCeil(iN,iK) ):
        iCost += 2 * aCum[iN - i * iK ]
    return iCost
def fSearchLowCost(iL,iLCost,iU,iUCost,iN,iX,aCum):
    if iU - iL <= iX :
        iTotalCost = min(iLCost,iUCost)
        for iK in range(iL+1,iU) :
            iThisCost = fCalcCost(iN,iX,aCum,iK)
            iTotalCost = min(iThisCost,iTotalCost)
        return iTotalCost
    else:
        iM = (iU + iL) // 2
        iMCost = fCalcCost(iN,iX,aCum,iM)
        if iLCost < iUCost :
            return fSearchLowCost(iL,iLCost,iM,iMCost,iN,iX,aCum)
        else :
            return fSearchLowCost(iM,iMCost,iU,iUCost,iN,iX,aCum)

if 1 < iN :
    iULim = fCeil(iN,2)+1
    iLLim = 1
    print(fSearchLowCost(iLLim,fCalcCost(iN,iX,aCum,iLLim),iULim,fCalcCost(iN,iX,aCum,iULim),iN,iX,aCum))
else:
    print(2*iX + 5*aX[0])


Measured memory_bytes: 27244
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
 
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}
int N,x;

vector<long long> value;

void update(int i,long long x){
	i += N - 1;
	value[i] = x;
	while(i > 0){ 
		i = (i - 1) / 2;
		value[i] = gcd(value[i * 2 + 1],value[i * 2 + 2]);
	}
}

long long getgcd(int a,int b,int k,int l,int r){
	if(r <= a || b <= l) return x;
	if(a <= l && r <= b) return value[k];
	else{
		long long c1 = getgcd(a,b,2 * k + 1,l,(l + r) / 2);
		long long c2 = getgcd(a,b,2 * k + 2,(l + r) / 2,r);
		return gcd(c1,c2);
	}
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	cin >> x;
	a[0] = x;
	N = 1;
	while(N < n) N *= 2;
	value.resize(2 * N - 1,x);
	int maxv;
	reps(i,n-1){
		cin >> a[i];
		update(i,a[i]);
	}
	/*
	rep(i,value.size()){
		cout << (i == 0 ? "" : " ") << value[i];
	}
	cout << '\n';
	*/
	maxv = getgcd(0,n,0,0,N);	
//	cout << maxv << '\n';
	reps(i,n-1){
		int tmp = a[i];
		update(i,x);
		maxv = max(maxv,getgcd(0,n,0,0,N));
		update(i,tmp);
//		cout << maxv << '\n';
	}
	update(0,a[n-1]);
	x = a[n-1];
/*	rep(i,value.size()){
		cout << (i == 0 ? "" : " ") << value[i];
	}
	cout << '\n';
	*/
	maxv = max(maxv,getgcd(0,n,0,0,N));
	cout << maxv << '\n';

	return 0;
}


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

#define pb push_back
#define fst first
#define snd second
#define ALL(s) s.begin(),s.end()
#define fill(a,c) memset(&a, c, sizeof(a))
#define fore(i,x,y) for(ll i=x;i<y;i++)
#define SZ(x) ((int)(x).size())
#define PI acos(-1)
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef long long ll;
using namespace std;

const int MAXN = 1e5+10;
ll dp[110][MAXN];
const ll mod = 1e9+7;

int main() {FIN;
    int n,k; cin>>n>>k;
    vector<int> c(n);
    fore(i,0,n) cin>>c[i];
    memset(dp,0,sizeof(dp));
    fore(i,0,n+1) dp[i][0] = 1;
    fore(i,0,k+1) dp[0][i] = 1;
    fore(i,1,n+1){
        fore(j,1,k+1){
            ll a = (j-c[i-1]-1>=0)?dp[i-1][j-c[i-1]-1]:0;
            ll b = dp[i-1][j];
            dp[i][j] = ((b-a+mod)%mod+(i == n?0:dp[i][j-1]))%mod;
        }
    }
    cout<<dp[n][k]<<"\n";
    return 0;
}



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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  int as = a.size(), bs = b.size(), cs = c.size();
  vector<bool> ab(8001), ac(8001), bc(8001);
  for (int i = -4000; i <= 4000; i++) {
    for (int j = 0; j < 2000; j++) {
      if (j - i < 0) continue;
      if (j < as && j - i < bs
          && a.at(j) != '?' && b.at(j - i) != '?' && a.at(j) != b.at(j - i)) {
        ab.at(i + 4000) = true;
      }
      if (j < as && j - i < cs
          && a.at(j) != '?' && c.at(j - i) != '?' && a.at(j) != c.at(j - i)) {
        ac.at(i + 4000) = true;
      }
      if (j < bs && j - i < cs
          && b.at(j) != '?' && c.at(j - i) != '?' && b.at(j) != c.at(j - i)) {
        bc.at(i + 4000) = true;
      }
    }
  }
  int ans = 6000;
  for (int i = -4000; i <= 4000; i++) {
    for (int j = -4000; j <= 4000; j++) {
      if (!ab.at(i + 4000) && !ac.at(j + 4000)
          && (j - i + 4000 < 0 || 8000 < j - i + 4000 || !bc.at(j - i + 4000))) {
        int l = min({0, i, j}), r = max({as, bs + i, cs + j});
        ans = min(ans, r - l);
      }
    }
  }
  cout << ans << endl;
}


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

using namespace std;
const int N = 1e6+100;
typedef long long ll;
vector<pair<int,pair<int,int> > > roadwork;
set<pair<ll,ll> > peo;
ll ans[N];
int main(){
	ll n,q;
	ll s,t,x,d;
	cin>>n>>q;
	for(ll i=1;i<=n;i++){
		cin>>s>>t>>x;
		roadwork.push_back({x,{s-x,t-1-x}});
	}
	for(ll i=1;i<=q;i++){
		cin>>d;
		peo.insert({d,i});
		ans[i]=-1;
	}
	sort(roadwork.begin(),roadwork.end());
	for(auto work:roadwork){
		ll L=work.second.first;
		ll R=work.second.second;
		if(peo.empty()) continue;
		auto it=peo.lower_bound({L,-1});
		while(!peo.empty()&&it!=peo.end()&&(*it).first<=R){
			ans[(*it).second]=work.first;
			peo.erase(it++);
		}
	} 
	for(ll i=1;i<=q;i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 18288
A = list(map(int,open(0).read().split()))
k = A.pop()
 
ans = 'Yay!'
 
for i in range(len(A)-1):
    for j in range(i+1, len(A)):
        d = abs(A[i] - A[j])
        if d > k:
            ans = ':('
print(ans)

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

int L;
string S,T,ans;

int main()
{
    scanf("%d",&L);
    cin >> S >> T;
    ans = "";
    if(S + T > T + S)swap(S,T);

    for(int i = L; i >= 0; i--)
    {
        if(S.size() * i > L)continue;
        if((L - (S.size() * i)) % T.size() == 0)
        {
            for(int j = 0; j < i; j++)ans += S;
            while(L != ans.size())ans += T;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1544
x1,y1,x2,y2 = (int(i) for i in input().split())
x3 = x2 + (y1-y2)
y3 = y2 + (x2-x1)
x4 = x3 + (x1-x2)
y4 = y3 + (y1-y2)
print(x3,y3,x4,y4)

Measured memory_bytes: 2940
#include<stdio.h>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;
/*#### modular_arithmetic */
class modular_arithmetic{
public:
	int mod, range;

	modular_arithmetic(){
		mod = 1000000007;
	}
	//No specific settings.
	void set_mod(int _mod){mod = _mod;}
	int add(int x,int y){return (x+y)%mod;}
	int sub(int x,int y){return (x-y+mod)%mod;}
	int mul(int x,int y){return (int)((long long int)x*y%mod);}
	int pw(int x,int y){
		int r = 1;
		while(1){
			if(y&1)r=mul(r,x);
			if(y>>=1)x=mul(x,x);else
				break;
		}
		return r;
	}
};
/*####*/

modular_arithmetic ma;

int n;bool ff;
vector<int> e[5005];
int sz[5005];

int m,a[5005];
void dfs(int x,int fat){
	sz[x] = 1;
	int mx = 0;
	for(vector<int>::iterator it = e[x].begin(); it != e[x].end(); it++){
		int y = *it;
		if(y == fat)continue;
		dfs(y, x);
		sz[x] += sz[y];
		if(sz[y] + sz[y] == n){
			ff = true;
		}
		mx = max(mx, sz[y]);
	}
	mx = max(mx, n - sz[x]);
	if(mx + mx < n){
		a[m++] = n-sz[x];
		for(vector<int>::iterator it = e[x].begin(); it != e[x].end(); it++){
			int y = *it;
			if(y == fat)continue;
			a[m++] = sz[y];
		}
	}
}

int fac[5005],ifac[5005];
void init(){
	fac[0] = 1;
	for(int i=1; i<=n; i++)
		fac[i] = ma.mul(fac[i-1],i);
	ifac[n] = ma.pw(fac[n],ma.mod-2);
	for(int i=n; i>=1; i--)
		ifac[i-1] = ma.mul(ifac[i], i);
}

int d[5005],d2[5005];
int solve(){
	memset(d,0,sizeof(d));
	d[0] = 1;
	int N = 0;
	sort(a,a+m);
	for(int i=0; i<m; i++){
		memset(d2,0,sizeof(d2));
		for(int j=0; j<=N; j++)if(d[j])
			for(int k=0; k<=a[i]; k++){
				int W = ma.mul(fac[a[i]], ifac[a[i]-k]);
				W = ma.mul(W, W);
				W = ma.mul(W, ifac[k]);
				d2[j+k] = ma.add(d2[j+k], ma.mul(d[j], W));
			}
		memcpy(d,d2,sizeof(d2));
		N += a[i];
	}

	int res = 0;
	for(int i=0; i<=N; i++){
		int cur = ma.mul(d[i], fac[N-i]);
		if(i%2)res = ma.sub(res, cur);else
			res = ma.add(res, cur);
	}
	return res;
}


int solve_1(){
	init();
	int ret = solve();
	a[m++] = 1;
	return ma.add(ret, solve());
}

int main(){
	scanf("%d",&n);
	for(int i=1; i<n; i++){
		int x,y;
		scanf("%d%d",&x,&y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	ff = false;
	dfs(1,1);
	if(ff){
		int res = 1;
		for(int i=1; i+i<=n; i++)
			res = ma.mul(res, i);
		res = ma.mul(res, res);
		printf("%d\n",res);
	}else{
		printf("%d\n",solve_1());
	}
	return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  ll a, b, m;
  cin >> a >> b >> m;
  vll A(a), B(b);
  vin(A);
  vin(B);
  ll ans = *min_element(all(A)) + *min_element(all(B));
  rep(i, 0, m){
    ll x, y, z;
    cin >> x >> y >> z;
    if(ans > A.at(x - 1) + B.at(y - 1) - z) ans = A.at(x - 1) + B.at(y - 1) - z;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int a,b,c,x,y;cin>>a>>b>>c>>x>>y;
    ll ans=0;
    if(c*2<a+b){
        ans+=min(x,y)*2*c;
        if(c*2<a){
            ans+=2*(x-min(x,y))*c;
        }
        else
            ans+=(x-min(x,y))*a;
        if(c*2<b){
            ans+=2*(y-min(x,y))*c;
        }
        else
            ans+=(y-min(x,y))*b;
    }
    else{
        ans+=a*x+b*y;
    }
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 256
object Main extends App{
  val sc = new java.util.Scanner(System.in)
  var n = sc.nextInt()
  val a = Array.fill(n)(sc.nextLong())
  var num = BigInt("1")
  if (a.indexOf(0) != -1) {print(0);sys.exit()}
  for (i <- 0 until n){
    num *= a(i)
    if (num > 1000000000000000000L){ print(-1);sys.exit();}
  }
  println(num)
}

Measured memory_bytes: 61028
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		int[] point = new int[6];
		Boolean Same = true;
		Scanner scan = new Scanner(System.in);
		int max = 0;
		for(int i = 0; i<6; i++){
			point[i]=scan.nextInt();
			if(point[i]>max){
				max=point[i];
			}
		}
		Dice3 dice = new Dice3(point);
		for(int i = 0; i<6; i++){
			point[i]=scan.nextInt();
		}
		Dice3 dice_o = new Dice3(point);
		scan.close();
		
		dice_o.MoveToBottom(max);
		dice.MoveToBottom(max);
		
		if(dice_o.T!=dice.T){
			Same=false;
		}
		
		if(Same){
			for(int i=0;i<4;i++){
				if(dice_o.F==dice.F&&dice_o.B==dice.B&&dice_o.L==dice.L&&dice_o.R==dice.R){
					Same=true;
					break;
				}
				else
					Same=false;
					dice.Move('R');
			}
		}
		
		if(Same)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}
class Dice3{
	int T,F,R,L,B,D;

	public Dice3(int[] point){
		this.T=point[0];
		this.F=point[1];
		this.R=point[2];
		this.L=point[3];
		this.B=point[4];
		this.D=point[5];
	}
	
	public void MoveToBottom(int point){
		while(true){
			if(this.D==point){
				break;
			}
			else if(this.T==point){
				this.Move('S');
				this.Move('S');
				break;
			}
			else if(this.F==point){
				this.Move('S');
				break;
			}
			else{
				this.Move('R');
			}
		}
	}
	
	public void Move(char move){
		int temp;
		switch(move){
			case 'E':
				temp=this.D;
				this.D=this.R;
				this.R=this.T;
				this.T=this.L;
				this.L=temp;
				break;
			case 'S':
				temp=this.D;
				this.D=this.F;
				this.F=this.T;
				this.T=this.B;
				this.B=temp;
				break;
			case 'W':
				temp=this.D;
				this.D=this.L;
				this.L=this.T;
				this.T=this.R;
				this.R=temp;
				break;
			case 'N':
				temp=this.D;
				this.D=this.B;
				this.B=this.T;
				this.T=this.F;
				this.F=temp;
				break;
			case 'R':
				temp=this.F;
				this.F=this.R;
				this.R=this.B;
				this.B=this.L;
				this.L=temp;
		}
	}
}


Measured memory_bytes: 26380
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>
#include <iomanip>


using namespace std;
const int N = 4 * 1000 + 5;
const int inf = 1000 * 1000 * 1000;

char c[N];
int a[N];
int n;
int dp[N][N];
int black[N][N];
int white[N][N];
int cBlack[N];
int cWhite[N];

int main() 
{
    cin >> n;
    for(int i = 1; i <= 2 * n; i++) 
    {
        cin >> c[i];
        cin >> a[i];
    }
    for (int i = 1; i <= n * 2; i++) 
    {
        if (c[i] == 'B') 
        {
            for (int j = 0; j <= n; j++) 
            {
                black[a[i]][j] = cBlack[a[i] + 1] + cWhite[j + 1];
            }
            for (int j = 0; j <= a[i]; j++) 
            {
                cBlack[j]++;
            }
        }
        else 
        {
            for(int j = 0; j <= n; j++) 
            {
                white[j][a[i]] = cBlack[j + 1] + cWhite[a[i] + 1];
            }
            for(int j = 0; j <= a[i]; j++) 
            {
                cWhite[j]++;
            }
        }
    }
    for(int i = 0; i <= n; i++) 
    {
        for(int j = 0; j <= n; j++) 
        {
            if (!i && !j)
            {
            	dp[i][i] = 0;
            }
            else 
            {
            	dp[i][j] = inf;
            }
            if (i) 
            {
            	dp[i][j] = min(dp[i][j], dp[i - 1][j] + black[i][j]);
            }
            if (j) 
            {
            	dp[i][j] = min(dp[i][j], dp[i][j - 1] + white[i][j]);
            }
        }
    }
    cout << dp[n][n] << endl;
}






























Measured memory_bytes: 98048
N=int(input())
n=N-1
B_list=list(map(int,input().split()))

ans=0
if N==2:
    print(B_list[0]*2)
else:
    ans+=B_list[0]
    for i in range(n-1):
        ans+=min(B_list[i],B_list[i+1])
    ans+=B_list[n-1]
    print(ans)

Measured memory_bytes: 3060
h = 0
f = 0
sum = 0
k = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
for i in range(0,k):
  h = a[i]
  sum += b[h-1]
  
for i in range(0,k-1):
  if a[i] + 1 == a[i+1]:
    f = a[i] - 1 
    sum += c[f]
    
print(sum)




Measured memory_bytes: 3064
#! /usr/bin/python3
# 3人でカードゲームイージー / Card Game for Three (ABC Edit)
"""
    1≤|SA|≤100
    1≤|SB|≤100
    1≤|SC|≤100
    SA、SB、SC に含まれる文字はそれぞれ a、b、c のいずれか
"""

test_mode = False

S_A = list(str(input()))
S_B = list(str(input()))
S_C = list(str(input()))

def turn(player):
    """
    プレイヤー player のターンを消化する関数
    """
    if player == 'a':   # Aのターン
        try:
            card = S_A[0]
            del S_A[0]
            if test_mode:
                print('Aのターン :', card)
            return turn(card)
        except IndexError:
            return 'A'

    if player == 'b':   # Bのターン
        try:
            card = S_B[0]
            del S_B[0]
            if test_mode:
                print('Bのターン :', card)
            return turn(card)
        except IndexError:
            return 'B'

    if player == 'c':   # Cのターン
        try:
            card = S_C[0]
            del S_C[0]
            if test_mode:
                print('Cのターン :', card)
            return turn(card)
        except IndexError:
            return 'C'

def main():
    """
    ゲームの結果を出力
    """
    print(turn('a'))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
//*
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <functional>
#define MOD 1000000007
#define MAX 0x3f3f3f3f
#define MAX2 0x3f3f3f3f3f3f3f3fll
#define ERR 1e-10
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#pragma warning(disable:4996)
using namespace std;

typedef long long ll;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

int n;
int a[30000];

int x[30000], y[30000];

int main()
{
	int i, j, k, l;
	cin>>n;
	for(i=0;i<n;i++) scanf("%d", &a[i]);
	for(i=0;i<n;i++) x[i]=1+30000*i;
	for(i=0;i<n;i++) y[i]=1+30000*(n-1-i);
	for(i=0;i<n;i++) x[a[i]-1]+=i;
	for(i=0;i<n;i++) printf("%d ", x[i]);
	printf("\n");
	for(i=0;i<n;i++) printf("%d ", y[i]);
	printf("\n");
	return 0;
}
//*/

Measured memory_bytes: 896
x,k,d=map(int,input().split())
if x<0 and x+k*d<0:
    print(-x-k*d)
else:
    x-=k*d
    if x>=0:
        print(x)
    else:
        x*=-1
        x%=2*d
        print(min(x,2*d-x))


Measured memory_bytes: 61856
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
	#endif

	map<int,int> o,e;
	int n;
	cin>>n;
	int x;
	vector<int> oo,ee;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(i&1)
		{
			oo.push_back(x);
			o[x]++;
		}
		else
		{
			ee.push_back(x);
			e[x]++;
		}
	}
	int mxe=0,mxo=0;
	int mxato=-1;
	for(auto i:oo)
	{
		if(o[i]>mxo)
		{
			mxo=o[i];
			mxato=i;

		}

	}
	for(auto i:ee)
	{
		if(i!=mxato)mxe=max(mxe,e[i]);
	}

	int ans=(n-mxe-mxo);
	mxe=0;mxo=0;
	mxato=-1;

	for(auto i:ee)
	{
		if(e[i]>mxe)
		{
			mxe=e[i];
			mxato=i;

		}

	}
	for(auto i:oo)
	{
		if(i!=mxato)mxo=max(mxo,o[i]);
	}


	ans=min(ans,n-mxe-mxo);
	cout<<ans;



	



	
}

Measured memory_bytes: 10136
#include <stdio.h>

#define STRING_LENGTH 200000
#define ARRAY_SIZE (STRING_LENGTH + 1)

void longestLengthAtoZ(char s[ARRAY_SIZE]);


int main()
{
  char s[ARRAY_SIZE];

  scanf("%s", &s);

  longestLengthAtoZ(s);

  return 0;
}

void longestLengthAtoZ(char s[ARRAY_SIZE])
{
  int i;
  int indexOfA, indexOfZ;

  i = 0;
  indexOfA = -1;
  indexOfZ = -1;
  while (s[i] != '\0')
    {
      if (s[i] == 'A' && indexOfA == -1)
	{
	  indexOfA = i;
	}
      else if (s[i] == 'Z')
	{
	  indexOfZ = i;
	}
      
      i++;
    }
  printf("%d\n", indexOfZ - indexOfA + 1);
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>

using namespace std;

int kk[3];

int ind(char c) {
	return c == 'R' ? 0 : c == 'G' ? 1 : 2;
}

int main() {
	int n; cin >> n;
	string s; cin >> s;
	long long bad = 0;
	for (int j = n - 1; j >= 0; j--) {
		for (int i = 0; i < j; i++)
			if (s[i] == s[j])
				bad += n - 1 - j;
			else {
				bad += kk[ind(s[i])] + kk[ind(s[j])] + 1;
				int l = j - i;
				if (j + l >= n)
					bad--;
				if (j + l < n && s[j + l] == s[i])
					bad--;
				if (j + l < n && s[j + l] == s[j])
					bad--;
			}
		kk[ind(s[j])]++;
	}
	cout << (long long) n * (n - 1) * (n - 2) / 6 - bad << '\n';
	return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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;
}
 
using namespace std;


void solve(){
  int a,b;
  cin>>a>>b;
  rep(i,1000){
    double x=(double)i+1.0;
    if(int(0.08*x)==a){
      if(int(0.1*x)==b){
        cout<<x<<endl;
        return;
      }
    }
  }
  cout<<-1;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
//	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

/* 配列の要素を順番に出力 */
void trace(int A[],int N) {
    int i;
    for(i=0;i<N;i++) {
        /* 隣接する要素の間に1つの空白を出力 */
        if(i>0) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}

/* 挿入ソート(0オリジン配列) */
void insertionSort(int A[], int N) {
    int i,j,v;
    for(i=1;i<N;i++) {
        v=A[i];
        j=i-1;
        while(j>=0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1]=v;
        trace(A,N);
    }
}

int main(void)
{
    int N, i;
    int A[100];
    scanf("%d",&N);
    for(i=0;i<N;i++) scanf("%d",&A[i]);
    
    trace(A,N);
    insertionSort(A,N);
    return 0;
}



Measured memory_bytes: 2036
#include <iostream>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
const ll MOD = 1e9+7;
const int M = 2e6+5;

ll fac[M], ifac[M];

ll inv(ll x) {
	ll ans = 1;
	ll p = MOD-2;
	while(p > 0) {
		if(p&1) ans = (ans*x) % MOD;
		p >>= 1;
		x = (x*x) % MOD;
	}
	return ans;
}

ll ifa(int i) {
	if(!ifac[i]) ifac[i] = inv(fac[i]);
	return ifac[i];
}

ll C(int n, int k) {
	return (((fac[n]*ifa(k)) % MOD) * ifa(n-k)) % MOD;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	fac[0] = 1;
	for(int i = 1; i < M; ++i) fac[i] = (fac[i-1]*i) % MOD;

	int K;
	cin >> K;
	string S;
	cin >> S;
	int n = S.size();
	ll ans = 0;
	ll p25 = 1, p26 = 1, i26 = inv(26);
	for(int k = 0; k < K; ++k) p26 = (p26*26) % MOD;
	for(int k = 0; k <= K; ++k) {
		ll a = (p25 * C(k+n-1, n-1)) % MOD;
		a = (a * p26) % MOD;
		ans = (ans + a) % MOD;
		p25 = (p25*25) % MOD;
		p26 = (p26*i26) % MOD;
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 27688
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        Integer N = scan.nextInt();
        long H[] = new long[N];
        for(int i = 0; i < N; i++) {
            H[i] = scan.nextInt();
        }
        for (int i = N - 1 ; 0 < i ; i--) {
            if(H[i-1] <= H[i])
                continue;
            else if(H[i-1] - 1 == H[i])
                H[i-1] = H[i-1] - 1;
            else {
                os.println("No");
                return;
            }
        }

        os.println("Yes");
    }
}

Measured memory_bytes: 49816
#include <algorithm>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <tuple>
#include <bitset>
#include <unordered_map>
using namespace std;
typedef long long ll;

void print(vector<int> vi) {
    for (int i=0; i<(int)vi.size(); ++i) {
        cout << (i == 0 ? "" : " ") << vi[i];
    }
    cout << endl;
}

int main() {
    ios::sync_with_stdio(false);

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

    print(A);
    for (int j=1; j<n; ++j) {
        int key = A[j];
        int i = j - 1;
        while (i >= 0 && A[i] > key) {
            A[i+1] = A[i];
            -- i;
        }
        A[i+1] = key;
        print(A);
    }

    return 0;
}

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

ll gcd(ll a, ll b){
    if(a<b) swap(a,b);
    if(a%b == 0) return b;
    else return gcd(b,a%b);
}

int main(){
    const ll c=26;
    ll n; cin >> n;
    ll cnt=0;
    ll rmv=26;
    while(true){
        n-=rmv;
        cnt++;
        if(n<=0) {
            n+=rmv;
            break;
        }
        rmv*=c;
    }
    if(n>0) n--;
    vector<int> ans(cnt);
    rep(i,cnt){
        ans[i]=n%c;
        n/=c;
    }

    vector<char> alp(26);
    iota(alp.begin(),alp.end(),'a');

    // rep(i,c) cout << alp[i] << endl;

    rep(i,cnt){
        char OUT=alp[ans[cnt-i-1]];
        cout << OUT;
    }
    cout << endl;
}

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

int main() {
  int N, K; cin >> N >> K;
  int MOD = 1000000007;
  int MAX_C = 2001;
  vector<vector<long long>> Com(MAX_C, vector<long long>(MAX_C));
  Com.at(0).at(0) = 1;
  for (int i = 1; i < MAX_C; i++) {
    Com.at(i).at(0) = 1;
    for (int j = 1; j <= i; j++) {
      Com.at(i).at(j) = (Com.at(i-1).at(j-1) + Com.at(i-1).at(j)) % MOD;
    }
  }
  for (int i = 1; i <= K; i++) {
    cout << Com.at(N-K+1).at(i) * Com.at(K-1).at(i-1) % MOD << endl;
  }
}

Measured memory_bytes: 31616
#![allow(unused_imports)]
#![allow(non_snake_case, unused)]

use std::cmp::*;
use std::collections::*;
use std::ops::*;

macro_rules! eprint {
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = write!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! eprintln {
	() => { eprintln!(""); };
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = writeln!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! dbg {
	($v:expr) => {{
		let val = $v;
		eprintln!("[{}:{}] {} = {:?}", file!(), line!(), stringify!($v), val);
		val
	}}
}

macro_rules! mat {
	($($e:expr),*) => { Vec::from(vec![$($e),*]) };
	($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
	($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
	($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

macro_rules! ok {
	($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => {
		$a$([$i])*.$f($($t),*)
	};
	($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { {
		let t = $e;
		ok!($a$([$i])*.$f($($es),*)$(@$t)*@t)
	} };
}

pub fn readln() -> String {
	let mut line = String::new();
	::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
	line
}

macro_rules! read {
	($($t:tt),*; $n:expr) => {{
		let stdin = ::std::io::stdin();
		let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
			let line = line.unwrap();
			let mut it = line.split_whitespace();
			_read!(it; $($t),*)
		}).collect::<Vec<_>>();
		ret
	}};
	($($t:tt),*) => {{
		let line = readln();
		let mut it = line.split_whitespace();
		_read!(it; $($t),*)
	}};
}

macro_rules! _read {
	($it:ident; [char]) => {
		_read!($it; String).chars().collect::<Vec<_>>()
	};
	($it:ident; [u8]) => {
		Vec::from(_read!($it; String).into_bytes())
	};
	($it:ident; usize1) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
	};
	($it:ident; [usize1]) => {
		$it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
	};
	($it:ident; [$t:ty]) => {
		$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
	};
	($it:ident; $t:ty) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
	};
	($it:ident; $($t:tt),+) => {
		($(_read!($it; $t)),*)
	};
}

pub fn main() {
	let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}

const MOD: usize = 1_000_000_007;
const INF: i64 = std::i64::MAX/2;

fn solve() {
	let s = read!(String);
	let c = s.chars().collect::<Vec<char>>();
	let n = c.len();
	let mut v = vec![];
	for i in (0..c.len()).rev() {
		v.push(c[i] as i64 - '0' as i64);
	}
	let mut res = vec![0;n];
	let mut list = vec![0;2019];
	list[0] = 1;
	let mut sum = 0;
	let mut base = 1;
	for i in 0..n {
		sum += v[i]*base;
		sum %= 2019;
		base *= 10;
		base %= 2019;
		res[i] = sum;
		list[res[i] as usize]+=1;
	}
	let mut ans = 0;
	for i in 0..2019 {
		ans += list[i]*(list[i]-1)/2;
	}
	println!("{}", ans);
}

fn run() {
    solve();
}


Measured memory_bytes: 5196
def main(a,b,c,d):
  if a<b:return 'No'
  if d<b:return 'No'
  if b<=c+1:return 'Yes'
  if d%b==0:
    if a%b<=c:return 'Yes'
    return 'No'
  # 任意のiで(a+i*d)%b<=cを満たせばOK
  import math
  g=math.gcd(d%b,b)
  e0=a%d
  if g*((b-1-e0)//g)+e0<=c:return 'Yes'
  return 'No'


t=int(input())
abcd=[list(map(int,input().split())) for _ in range(t)]
for a,b,c,d in abcd:
  print(main(a,b,c,d))

Measured memory_bytes: 9180
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main() {
  int n;
  readf (" %d", &n);
  auto a = new int[n];
  foreach (t; 0 .. n) { 
    readf (" %d", &a[t]);
  }
  int last = a[0];
  int res;
  foreach (i; 1 .. n) {
    if (a[i] == last) {
      last = int.max;
      ++res;
    } else {
      last = a[i];
    }
  }
  writeln (res);
}


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

int main(){
	int n;
	string s;
	bool flg=true;
	cin >>n>>s;
	if(n%2==1){
		cout <<"No"<<endl;
		return 0;
	}
	rep(i,n/2){
		if (s[i]!=s[i+(n/2)])
			flg=false;
	}
	if (!flg)
		cout <<"No";
	else
		cout <<"Yes";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);

		String S = sc.next();


		int mae = Integer.parseInt(S.substring(0, 2));
		int ato = Integer.parseInt(S.substring(2, 4));

		String ans;
		boolean maeM=false;
		boolean atoM=false;
		if ((mae>=1)&(mae<=12)) {
			maeM = true;
		}
		if ((ato>=1)&(ato<=12)) {
			atoM = true;
		}

		if(maeM) {
			if (atoM) {
				ans = "AMBIGUOUS";
			} else {
				ans = "MMYY";
			}
		} else {
			if (atoM) {
				ans = "YYMM";
			} else {
				ans = "NA";
			}
		}

		System.out.println(ans);

	}


}

Measured memory_bytes: 20948
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

bool check(vector<int> &v, int k){
    int V = v.size();
    const int M = V/2;

    vector<int> pos[M];
    rep(i,V) pos[v[i]].pb(i);
    rep(i,M){
        int val = 0;
        for(int j=pos[i][0]; j<=pos[i][1]; ++j) val ^= v[j];
        if(val != k) return false;
    }
    return true;
}

int main(){
    int m,k;
    cin >>m >>k;

    vector<int> v;
    if(m==0){
        if(k==0) rep(i,2) v.pb(0);
    }
    else if(m==1){
        if(k==0) rep(i,1<<m)rep(j,2) v.pb(i);
    }
    else{
        int M = 1<<m;
        if(0<=k && k<M){
            v.pb(k);
            rep(i,M)if(i!=k) v.pb(i);
            v.pb(k);
            for(int i=M-1; i>=0; --i)if(i!=k) v.pb(i);
        }
    }

    // if(!v.empty()) assert(check(v,k));
    int V = v.size();
    if(V==0) cout << -1 << "\n";
    else rep(i,V) cout << v[i] << " \n"[i==V-1];
    return 0;
}


Measured memory_bytes: 2932
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

const double pi = 3.141592653589793;
// -------------------------------------------------------
int N, Y;

int main() {
  cin >> N >> Y;
  repe(x, 0, 2000) {
    repe(y, 0, 2000) {
      int z = N - x - y;
      if (z < 0) continue;

      if (10000 * x + 5000 * y + 1000 * z == Y) {
        cout << x << " " << y << " " << z << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
}


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


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while(true){
			int n = Integer.parseInt(br.readLine());
			
			if(n == 0){
				break;
			}
			
			int input[] = new int[n];
			
			String[] tmpArray = br.readLine().split(" ");
			
			for(int i = 0; i < n; i++){
				input[i] = Integer.parseInt(tmpArray[i]);
			}
			
			Arrays.sort(input);
			
			int minDiff = Integer.MAX_VALUE;
			for(int i = 0; i < n - 1; i++){
				if(input[i + 1] - input[i] < minDiff){
					minDiff = input[i + 1] - input[i];
				}
			}
			
			System.out.println(minDiff);
		}
	}

}

Measured memory_bytes: 31044
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{

  int w,h,c;
  int box;
  int ans;
  cin >> w >> h >> c;

  box = __gcd(w,h);
  ans = ((w*h)/(box*box))*c;

  cout << ans << endl;  

  return 0;

}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define mp(a, b) make_pair(a, b)
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 2e5 + 10;
int n;
ll a[maxn], tot, cur;
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
	cur = a[1];
	for(int i = 2; i <= n; ++i)
	{
		if(cur > a[i])
			tot += cur - a[i];
		else
			cur = a[i];
	}
	printf("%lld\n", tot);
	return 0;
}
	

Measured memory_bytes: 5316
#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 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 swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N, D;

	cin >> N >> D;
	cout << (N + D * 2) / (D * 2 + 1) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int ctoi(const char c)
{
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}

int main()
{
    string N; cin >> N;
    int res = 0;
    for (const auto c : N) res += ctoi(c);
    if (stoi(N) % res == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

const int MAX_N=10000000;
 
int n;
int dat[MAX_N*2-1];
 
void init(){
    int i=n;
    n=2;

	while (n<i)n*=2;
	
	fill(dat,dat+n*2,0);
}
 
void update(int i,int x){
	i+=n-1;
	while(i>0){
		dat[i]+=x;
		i=(i-1)/2;
	}
	dat[0]+=x;
}

long long int query(int a,int b,int k,int l,int r){
	if(r<a||b<l)return 0;
	if(a<=l&&r<=b) return dat[k];
	else{
		int vl=query(a,b,k*2+1,l,(l+r)/2);
		int vr=query(a,b,k*2+2,(l+r)/2+1,r);
	    return vl+vr;
	}
}

int main(){
    int q,a,b,c;
    cin>>n>>q;
    
    init();
    
    while(q--){
        cin>>a>>b>>c;
        if(a)cout<<query(b-1,c-1,0,0,n-1)<<endl;
        else update(b-1,c);
        
        /*for(int i=0;i<n*2;i++){
            cout<<dat[i]<<" ";
        }
        cout<<endl;*/
    }
    
}

Measured memory_bytes: 4112
#include <iostream>
//#include <string>
using namespace std;


int main() {
  int N, M, C;
  int A[30][30];
  int B[30];
  
  cin >> N >> M >> C;
  for(int j=0; j < M; j++){
      cin >> B[j];
  }
  for(int i=0; i < N; i++){
      for(int j=0; j < M; j++)
          cin >> A[i][j];
  }
  
  int count=0;
  for(int i=0; i < N; i++){
      int siki=0;
      for(int j=0; j < M; j++){
          siki += A[i][j]*B[j];
      }
      siki += C;
      if(siki>0){
          count++;
      }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc047/tasks/abc047_b
"use strict";
function Main(input) {
  const [basePoint, ...points] = input.trim().split("\n");
  const [W, H, N] = basePoint.trim().split(" ").map(Number);
  const field = Array(W)
    .fill()
    .map(() => Array(H).fill(1));

  for (let i = 0; i < N; i++) {
    const [x, y, a] = points[i].trim().split(" ").map(Number);

    let [jmin, jmax, kmin, kmax] = [0, 0, 0, 0];
    if (a === 1) {
      [jmin, jmax, kmin, kmax] = [0, x, 0, H];
    } else if (a === 2) {
      [jmin, jmax, kmin, kmax] = [x, W, 0, H];
    } else if (a === 3) {
      [jmin, jmax, kmin, kmax] = [0, W, 0, y];
    } else if (a === 4) {
      [jmin, jmax, kmin, kmax] = [0, W, y, H];
    }

    for (let j = jmin; j < jmax; j++) {
      for (let k = kmin; k < kmax; k++) {
        field[j][k] = 0;
      }
    }
  }

  const area = field.flat().reduce((acc, cur) => acc + cur, 0);
  console.log(area);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 36268
//
//  main.cpp
//  AtCoder_Regular_Contest_78
//
//  Created by lee on 2017/7/15.
//  Copyright © 2017年 lee. All rights reserved.
//

#include <iostream>
#include <algorithm>
using namespace std;

int main() {
//C
    int n;
    cin >> n;
    int* arr = new int[n];
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    long long int min = 2000000000 + 1000;
    long long int answer = 0;
    long long int total = 0;
    
    for(int i = 0 ; i < n; i++) {
        total += arr[i];
    }
    
    long long int topValue = 0;
    
    for(int i = 0 ; i < n-1; i++) {
        topValue += arr[i];
        if(abs(topValue * 2 - total) < min) {
            min = abs(topValue * 2 - total);
        }
    }
    
    
    answer = min;
    cout << answer;
    
//C END
    
//D
    
//E
    
//F
    
    
    
    return 0;
}

Measured memory_bytes: 1024
use std::io::Read;
use std::collections::HashMap;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let k: usize = iterator.next().unwrap().parse().unwrap();

    let mut map: HashMap<usize, usize> = HashMap::with_capacity(n);
    for _ in 0..n {
        let a: usize = iterator.next().unwrap().parse().unwrap();
        *map.entry(a).or_insert(0) += 1;
    }

    let mut values: Vec<usize> = map.values().map(|u| u.clone()).collect();
    values.sort();
    for _ in 0..min(k, map.len()) {
        values.pop().unwrap();
    }

    let ans: usize = values.iter().sum();

    return ans.to_string();
}


Measured memory_bytes: 14588