akhauriyash/Code-Regression huggingface dataset:
n,m=map(int,input().split())
if 2<=n and 2<=m:
    print((m-2)*(n-2))
elif n==1 and m==1:
    print(1)
elif n==1 and 2<=m:
    print(m-2)
elif m==1 and 2<=n:
    print(n-2)
    

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

using namespace std;

const int N = 200005;

int n;
int a[N], b[N];

int main() {
	scanf("%d", &n);

	for(int i = 0; i < n; i++) scanf("%d", a + i);
	for(int i = 0; i < n; i++) scanf("%d", b + i);
	reverse(b, b + n);

	int l = 0;
	while(l < n and a[l] != b[l]) l++;

	if(l < n) {
		int r = l;
		while(r + 1 < n and a[r + 1] == b[r + 1]) r++;
		int pos = l;
		for(int i = 0; i < l and pos <= r; i++) {
			if(a[i] != b[pos] and b[i] != b[pos]) {
				swap(b[i], b[pos++]);
			}
		}
		for(int i = r + 1; i < n and pos <= r; i++) {
			if(a[i] != b[pos] and b[i] != b[pos]) {
				swap(b[i], b[pos++]);
			}
		}
		if(pos <= r) return printf("No\n"), 0;
	}

	printf("Yes\n");
	for(int i = 0; i < n; i++) {
		printf("%d%c", b[i], " \n"[i + 1 == n]);
	}
}


Measured memory_bytes: 5404
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

char s[100003];
int n;

int main() {
	while (~scanf("%s", s + 1)) {
		n = strlen(s + 1);
		int ans = 0;
		for (int i = 2; i <= n; ++i)
			if (s[i] != s[i - 1]) ++ans;
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
    int n;
    cin >> n;
    string s;
    long long ans = 0;
    long long a = 0, b = 0, c = 0;
    for (int i = 0; i < n; i++) {
        cin >> s;
        for (int i = 0; i < s.size() - 1; i++) {
            if (s.substr(i, 2) == "AB") {
                ans++;
            }
        }
        if (s[0] == 'B' && s[s.size() - 1] == 'A') {
            c++;
        }
        else if (s[0] == 'B') {
            b++;
        }
        else if (s[s.size() - 1] == 'A') {
            a++;
        }
    }
    long long z = 0;
    if (a != b) {
        ans += min(a, b);
        ans += max(z, c - 1);
        long long d = min(a, b);
        a -= d;
        b -= d;
        if (c!=0){
            if (a != 0) {
                ans++;
            }
        if (b != 0) {
            ans++;
        }
        }
    }
    else if (a != 0) {
        ans += c + 1;
        ans += a - 1;
    }
    else {
        ans += max(z, c - 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
# AOJ 0198 Trouble in Shinagawa's Artifacts
# Python3 2018.6.20 bal4u

r = [ \
	[0,1,2,3,4,5,6], [0,1,3,5,2,4,6], [0,1,4,2,5,3,6], [0,1,5,4,3,2,6], \
	[0,2,6,3,4,1,5], [0,2,3,1,6,4,5], [0,2,1,4,3,6,5], [0,2,4,6,1,3,5], \
	[0,3,1,2,5,6,4], [0,3,2,6,1,5,4], [0,3,5,1,6,2,4], [0,3,6,5,2,1,4], \
	[0,4,1,5,2,6,3], [0,4,2,1,6,5,3], [0,4,5,6,1,2,3], [0,4,6,2,5,1,3], \
	[0,5,1,3,4,6,2], [0,5,3,6,1,4,2], [0,5,4,1,6,3,2], [0,5,6,4,3,1,2], \
	[0,6,2,4,3,5,1], [0,6,3,2,5,4,1], [0,6,5,3,4,2,1], [0,6,4,5,2,3,1]]

def same(x, y):
	t = ['']*7
	for i in range(24):
		for j in range(1, 7): t[j] = a[y][r[i][j]]
		if a[x] == t: return True
	return False

while True:
	n = int(input())
	if n == 0: break
	f = [0]*n
	a = [['' for j in range(7)] for i in range(n)]
	for i in range(n):
		s = list(input().split())
		for j in range(6): a[i][j+1] = s[j]
	for i in range(n):
		if f[i] == 1: continue
		for j in range(i+1, n):
			if same(i, j): f[j] = 1
	print(sum(f))



Measured memory_bytes: 5648
n,w=map(int,input().split())
w_sub,v_sub=map(int,input().split())
w0=w_sub
inf=1000000001
x=[[inf,v_sub],[inf],[inf],[inf]]
for i in range(n-1):
    w_sub,v_sub=map(int,input().split())
    w_sub-=w0
    x[w_sub].append(v_sub)
for i in range(4):
    x[i].sort(key=lambda x:-x)
    x[i][0]=0
    l_sub=len(x[i])
    for j in range(1,l_sub):
        x[i][j]+=x[i][j-1]

ma=0
l3=len(x[3])
l2=len(x[2])
l1=len(x[1])
l0=len(x[0])
for i in range(l3):
    for j in range(l2):
        d=w-i*(w0+3)-j*(w0+2)
        if d>=0:
            for k in range(l1):
                d=w-i*(w0+3)-j*(w0+2)-k*(w0+1)
                if d>=0:
                    ma=max(ma,x[3][i]+x[2][j]+x[1][k]+x[0][min(d//w0,l0-1)])
                else:
                    break
        else:
            break

print(ma)


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

using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using ll = long long int;
using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>;
using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using cdouble = complex<double>;

const double INFD = numeric_limits<double>::infinity();
const double PI = 3.14159265358979323846;
#define Loop(i, n) for(int i = 0; i < (int)(n); i++)
#define Loop1(i, n) for(int i = 1; i <= (int)(n); i++)
#define Loopr(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)(n); i >= 1; i--)
#define Foreach(buf, container) for(auto buf : container)
#define Loopdiag(i, j, h, w, sum) for(int i = ((sum) >= (h) ? (h) - 1 : (sum)), j = (sum) - i; i >= 0 && j < (w); i--, j++)
#define Loopdiagr(i, j, h, w, sum) for(int j = ((sum) >= (w) ? (w) - 1 : (sum)), i = (sum) - j; j >= 0 && i < (h); j--, i++)
#define Loopdiagsym(i, j, h, w, gap) for (int i = ((gap) >= 0 ? (gap) : 0), j = i - (gap); i < (h) && j < (w); i++, j++)
#define Loopdiagsymr(i, j, h, w, gap) for (int i = ((gap) > (h) - (w) - 1 ? (h) - 1 : (w) - 1 + (gap)), j = i - (gap); i >= 0 && j >= 0; i--, j--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(ex_i, vector.size()) { cout << vector[ex_i] << " "; } cout << endl;
#define printmx(matrix) Loop(ex_i, matrix.size()) { Loop(ex_j, matrix[ex_i].size()) { cout << matrix[ex_i][ex_j] << " "; } cout << endl; }
#define quickio() ios::sync_with_stdio(false); cin.tie(0);
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
#define Comp(type_t) bool operator<(const type_t &another) const
#define fst first
#define snd second
bool nearlyeq(double x, double y) { return abs(x - y) < 1e-9; }
bool inrange(int x, int t) { return x >= 0 && x < t; }
bool inrange(vi xs, int t) { Foreach(x, xs) if (!(x >= 0 && x < t)) return false; return true; }
ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); }
ll floorsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (m * m <= x ? 0 : -1); }
ll ceilsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (x <= m * m ? 0 : 1); }
ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); }
ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); }
ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); }
ll lcm(ll m, ll n) { return m * n / gcd(m, n); }

/*******************************************************/

int main() {
	int n; cin >> n;
	vll a(n);
	ll ans = 0;
	Loop(i, n) {
		cin >> a[i];
	}
	int p = 0, q = 1;
	while (p < n) {
		while (q < n && a[q] > 0) q++;
		ans += accumulate(a.begin() + p, a.begin() + q, 0LL) / 2;
		p = q;
		q++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W,N;
string S,T;
int Y,X;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>N>>Y>>X>>S>>T;
	Y--,X--;
	
	x=X;
	FOR(i,N) {
		if(S[i]=='R') x++;
		if(x>=W) return _P("NO\n");
		if(T[i]=='L' && x>0) x--;
	}
	x=X;
	FOR(i,N) {
		if(S[i]=='L') x--;
		if(x<0) return _P("NO\n");
		if(T[i]=='R' && x<W-1) x++;
	}
	x=Y;
	FOR(i,N) {
		if(S[i]=='D') x++;
		if(x>=H) return _P("NO\n");
		if(T[i]=='U' && x>0) x--;
	}
	x=Y;
	FOR(i,N) {
		if(S[i]=='U') x--;
		if(x<0) return _P("NO\n");
		if(T[i]=='D' && x<H-1) x++;
	}
	cout<<"YES"<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 920
import sys
read = sys.stdin.readline


def main():
    n = int(read())
    V = 1000000

    g = [[] for _ in range(V)]
    deg = [0] * V
    vlist = set()

    for i in range(n):
        a = list(map(lambda x: int(x) - 1, read().rstrip().split()))
        for j in range(n - 1):
            v1 = min(i, a[j]) * 1000 + max(i, a[j])
            vlist.add(v1)
            if j == n - 2:
                break
            v2 = min(i, a[j + 1]) * 1000 + max(i, a[j + 1])
            g[v1].append(v2)
            deg[v2] += 1

    d = [0] * V
    check_cnt = 0
    q = []
    for v in vlist:
        if deg[v] == 0:
            q.append(v)

    if len(q) == 0:
        print(-1)
        exit()

    for v in q:
        check_cnt += 1
        for nv in g[v]:
            d[nv] = max(d[nv], d[v] + 1)
            deg[nv] -= 1
            if deg[nv] == 0:
                q.append(nv)
    if check_cnt == n * (n - 1) // 2:
        print(max(d) + 1)
    else:
        print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 237348
import java.io.*;

public class Main {
  public static void main(String[] args) throws java.io.IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    String[] strIn = in.readLine().split("\\s");

    if ((Integer.parseInt(strIn[0])*Integer.parseInt(strIn[1]))%2 == 0)
      System.out.println("Even");

    else
      System.out.println("Odd");
  }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}

lint g[200005];
  int main(){
    lint N,K;
    vector<lint>x;
    cin >>N>>K; lint M[N];
    rep(i,N){cin >> M[i];
        g[M[i]]++;
    }
    rep(i,200005){
        if(g[i]!=0)x.push_back(g[i]);
    }
    lint ans=0;
    sort(all(x));
    if(x.size()<=K)cout<<0;
    else {
        rep(i,x.size()-K){
                ans+=x[i];
        }
        cout<<ans;
    }
    

  }

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;

int main(){
    ll N, A, B; cin >> N >> A >> B;

    if(A > B) {
        cout << 0 << endl;
    } else if(N == 1 && B - A != 0) {
        cout << 0 << endl;
    } else if(N == 1 && B - A == 0) {
        cout << 1 << endl;
    } else {
        // cout << pow(B - A + 1, N - 2) << endl;
        cout << (B - A + 1) * (N - 2) - ((N - 2) - 1) << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1E9 + 7;
const int INF = 1 << 29;

int main() {
  int N;
  cin >> N;
  string tmp;
  map<string, int> S;
  rep(i, N) {
    cin >> tmp;
    S[tmp]++;
  }
  cout << S.size() << endl;
  return 0;
}

Measured memory_bytes: 19068
/*
 
                              Jai Shree Krishna !!
                                 Radhe Radhe !!
                                 
             उद्यमेन हि सिद्ध्यन्ति कार्याणि न मनोरथैः। नहि सुप्तस्य सिंहस्य मुखे प्रविशन्ति मृगाः।।
             
*/
   
   
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
typedef long long ll;
#define loop(i,n)  for(int i=0;i<n;i++)
#define read(a) int a; cin >>a;
#define readarr(a,n) int a[n] ; for(int i=0;i<n;i++) cin >> a[i];
#define readmat(a,n,m) int a[n][m]; for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin >> a[i][j];
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int,int>
#define vvi vector<vector<int>>
#define sti set<int>
#define vpi vector<pair<int,int>>
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define printmat(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define endl "\n"
#define mp make_pair
#define ins insert
#define rep(i,s,e)   for(int i=s;i<=e;i++)
#define repd(i,s,e)  for(int i=e;i>=s;i--)
#define vb vector<bool>
#define read2(n,m) int n,m; cin >> n >> m;
#define range(v) v.begin(),v.end()
#define sortd(v) sort(v.begin(),v.end(),greater<int>())
#define sorti(v) sort(v.begin(),v.end())
 
const ll inf = 1e18;
const ll mod = 1e9 + 7;
 
signed main()
{
 
    fast;
    // read(n);
    int a,c=0;
    string b;
    
    cin >> a >> b;
    // cout<<a<<" "<<b<<endl;
    // float x = a*b;
    // c=ceil(x);
    // cout<<c<<endl;
    string d="",f="";
    for(int i=0;i<b.length();i++){
    	if(b[i]=='.') c=1;
        else
        if(c==0)
    	d+=b[i];
    	else
    	if(c==1) 
    	f+=b[i];
    }
    int di = stoi(d);
    int fi = stoi(f);
    
    int x = di*a;
    x+= (fi*a)/100;
    cout<<x<<endl;
    
    return 0;
}
 
/* Pooja Yadav */

Measured memory_bytes: 3624
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<P,int>

ll n;
ll pow2(ll a,ll b){
    ll ret=1;
    for(int i=0;i<b;i++)ret*=a;
    return ret;
}

ll ko(ll i){
    return i/4LL*10LL+(i%4LL+1LL)*2LL;
}

int main(){
    

    cin>>n;
    if(n%2==1){
        cout<<0<<endl;
        return 0;
    }
    ll ans=0;
    for(ll f=1;f<=1000;f++){
        ll bai=pow2(5LL,f);
        if(bai>n)
            break;

        ll l=0,r=n/bai,mid=(r+l)/2;
        while(abs(r-l)>1){
            if(ko(mid)*bai>n)
                r=mid;
            else
                l=mid; 
            mid=(r+l)/2LL;           
        }
        //cout<<(mid+1)<<endl;
        //cout<<bai<<" "<<mid<<endl;
        if(mid==0&&ko(mid)*bai>n){

        }
        else
            ans+=(mid+1)*f;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N; cin >> N;
    vector<int> a(N);
    int total=0;
    for(int i=0;i<N;i++){
        cin >> a[i];
        total ^= a[i];
    }
    for(int i=0;i<N;i++){
        int ans = total^a[i];
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 4056
//
// Created by Daiki Kuyoshi on 2020/05/03.
//

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;

int main(){
    ll N, M;
    cin >> N >> M;
    vl H(N), a(M), b(M);
//vector<pair<ll, ll>> p;
    for(int i=0; i<N; i++){
        cin >> H.at(i);
    }
    for (int j = 0; j < M; ++j) {
        cin >> a.at(j) >> b.at(j);
    }

    vl ans(N, 1);

    for(int i=0; i<M; i++){
        if(H.at(a.at(i)-1) < H.at(b.at(i)-1)){
            ans.at(a.at(i)-1)--;
        }
        else if (H.at(a.at(i)-1) > H.at(b.at(i)-1)){
            ans.at(b.at(i)-1)--;
        }
        else{
            ans.at(a.at(i)-1)--;
            ans.at(b.at(i)-1)--;
        }
    }

    ll sum = 0;

    for(ll i=0; i<N; i++){
        if(ans.at(i)==1){
            sum++;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 6048
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,n)             for(ll i=1;i<=n;i++)
#define LOOP(i,n)            for(ll i=0;i<n;i++)
#define loop(a,b)            for(ll i=a;i<=b;i++)
#define sci(n)               scanf("%d",&n)
#define scl(n)               scanf("%lld",&n)
#define scd(n)               scanf("%lf",&n)
#define srt(g)               sort(g.begin(),g.end())
#define rvs(g)               reverse(g.begin(),g.end())
#define pl                   pair<long long,long long>
#define ll long long
#define pb push_back
#define mp make_pair
#define pi acos(-1.0)
#define f first
#define s second
int mod=2019;
int main()
{
    string s;
    cin >> s;
    vector<int>cnt(mod+10);
    ll ans=0;
    ll suf=0;
    cnt[suf]++;
    int p=1;
    for(ll i=s.size()-1;i>=0;i--)
    {
        int x=s[i]-'0';
        suf=(suf+x*p)%2019;
        p=10*p%2019;
        //cnt[suf]++;
        ans=ans+cnt[suf];
        cnt[suf]++;
    }
    cout << ans << "\n";
}


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

int main() {
  int h,w,k;
  cin >> h >> w >> k;
  vector<string>data(h);
  vector<vector<int>>ans(h,vector<int>(w,-1));
  vector<bool>no(h,false);
  int bnf = 400,bnl = 0;
  rep(i,0,h){
    cin >> data[i];
    bool f = true;
    rep(j,0,w) if(data[i][j] == '#') f = false;
    if(f) no[i] = true;
    else{
      bnf = min(bnf,i);
      bnl = max(bnl,i);
    }
  }
  int c = 1;
  rep(i,0,h){
    if(no[i]) continue;
    bool fst = true;
    rep(j,0,w){
      if(data[i][j] == '#'){
        if(fst) fst = false;
        else c++;
      }
      ans[i][j] = c;
    }
    c++;
  }
  rep(i,0,h){
    if(!no[i]) continue;
    rep(j,0,w){
      if(bnf > i) ans[i][j] = ans[bnf][j];
      else if(bnl < i) ans[i][j] = ans[bnl][j];
      else{
        int tmp = i;
        while(true){
          tmp++;
          if(!no[tmp]) break;
        }
        ans[i][j] = ans[tmp][j];
      }
    }
  }
  rep(i,0,h){
    rep(j,0,w){
      cout << ans[i][j];
      if(j != w-1) cout << " ";
      else cout << "" << endl;
    }
  }
}

Measured memory_bytes: 4152
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include <string>
using namespace std;
int s[100][100];
int main()
{
    int N,m;
    cin>>N;
    int t=0;
    for(int i=1; i<=N; i++)
    {
        if(i%10!=0)
        {
            int a=i%10;
            int b;
            int n=i;
            while(n>=10)
            {
               n=n/10;
            }
            b=n;
            s[b][a]++;
        }
    }
    for(int i=1;i<=9;i++)
    {
        for(int j=1;j<=9;j++)
        {
            t=t+s[i][j]*s[j][i];
        }
    }
    printf("%d",t);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string S;
  cin >> S;
  string ans = S.substr(0, 3);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define inf 0x7fffffff
#define eps 1e-4
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const double pi = acos(-1);
inline ll read(){
    ll x = 0, f = 1;
    char ch = getchar();
    while(ch > '9' || ch < '0') {if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x *10 + ch -'0';ch = getchar();}
    return x * f;
}
ll n,m,t,x; 
int main(){
    int i,j;
    //freopen("a.out","r",stdin);
    //freopen("a.ans","w",stdout);
    x=read();
	if(x<=599){puts("8");return 0;}
	if(x<=799){puts("7");return 0;}
	if(x<=999){puts("6");return 0;}
	if(x<=1199){puts("5");return 0;}
	if(x<=1399){puts("4");return 0;}
	if(x<=1599){puts("3");return 0;}
	if(x<=1799){puts("2");return 0;}
	if(x<=1999){puts("1");return 0;} 
    return 0;
}
/*
6
8 4
8 -4
5 5
5 -5
1 3
1 -3
*/

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
using ll = long long;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);

    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        A[i]--;
    }
    vector<ll> bucket(N);
    for (int i = 0; i < N; ++i) {
        bucket[A[i]]++;
    }
    ll count = 0;
    for (int i = 0; i < N; ++i) {
        count += bucket[i] * (bucket[i] - 1) / 2;
    }
    for (int i = 0; i < N; ++i) {
        ll current = A[i];
        cout << count - (bucket[current] * (bucket[current] - 1) / 2) + ((bucket[current] - 2) * (bucket[current] - 1) / 2) << endl;
    }

}


Measured memory_bytes: 5760
#include <iostream>
using namespace std;
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
typedef struct{
   int high;
   int p;
   int q;
}yoko_style;

void bsort(yoko_style yoko[],int m)
{
   int i,j;
   for(i=0;i<m-1;i++) {
      for(j=m-1;j>i;j--) {
         if(yoko[j].high < yoko[j-1].high) {
            yoko_style tmp = yoko[j-1];
            yoko[j-1] = yoko[j];
            yoko[j] = tmp;
         }
      }
   }
}

int judge(int a[],int c)
{
   yoko_style yoko[1000];
   int i;
   int now_high;
   int n,m;
   cin >> n >> m >> a[c];
   if(n || m || a[c]) ;
   else return 0;

   for(i=0;i<m;i++) {
      scanf("%d",&yoko[i].high);
      scanf("%d",&yoko[i].p);
      scanf("%d",&yoko[i].q);
   }

   bsort(yoko,m);
   now_high = yoko[m-1].high;
   for(i=m-1;i>-1;i--) {
      if(a[c] == yoko[i].p && yoko[i].high <= now_high) {
         a[c] = yoko[i].q;
         now_high = yoko[i].high - 1;
      }
      else if(a[c] == yoko[i].q && yoko[i].high <= now_high){
         a[c] = yoko[i].p;
         now_high = yoko[i].high - 1;
      }
   }
   return 1;
}
int main()
{
   int i,j,k,l;
   int memo_i;
   int a[1000];
   int iranai[3];
   int continuation=1;
   i = 0;
   while(continuation) {
      continuation = judge(a,i);
      i++;
   }
   i--;
   memo_i = i;
   for(i=0;i<memo_i;i++)
      printf("%d\n",a[i]);
}

Measured memory_bytes: 1240
n   = gets.split.map(&:to_i)
num = gets.split.map(&:to_i)
flag = 1

num.each{|t|
    if (t%2) == 0 then 
        if t%3 == 0 || t%5 == 0 then
            
        else
            flag = 0
        end
    end
}


if flag == 0 then
    puts("DENIED")
else  
    puts("APPROVED")
end


Measured memory_bytes: 1788
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
    long long n,m,d,s;
    scanf("%lld%lld%lld",&n,&m,&d);
    s=min(n+m+1,d);
    printf("%lld\n",m+s);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int in() {int x; cin>>x; return x;}
ll lin() {ll x; cin>>x; return x;}
string sin() {string x;cin>>x;return x;}
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;

bool ifprime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=2;i*i<=x;i++){if(x%i==0)return false;}
    return true;
}
ll mod(ll x, ll y){if(x>=0||x%y==0) return x%y;return y+x%y;} //mod including minus
ll dv0(ll x, ll y){if(x>=0||x%y==0)return x/y;return x/y-1;} //rnd down
ll dv1(ll x, ll y){if(x%y==0) return dv0(x,y);return dv0(x,y)+1;} //rnd up

//Start from Here
int main(){
    int N=in();
    int sum=0;
    int m=1000;
    int x;
    rep(i, N){
        cin>>x;
        sum+=x;
        if(x%10!=0){
            m=min(m, x);
        }
    }
    if(m==1000){
        cout<<0<<endl;
    }
    else{
        if(sum%10!=0){
            cout<<sum<<endl;
        }
        else{
            cout<<sum-m<<endl;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

typedef long long ll;

void solve() {
    int n; 
    cin >> n;
    vector <vector <int>> v;
    for(int i = 0; i < n; i++) {
        vector <int> v1(2, 0);
        cin >> v1[0] >> v1[1];
        v.push_back(v1);
    }
    for(int i = 0; i < n-2; i++) {
        if(v[i][0] == v[i][1] && v[i+1][0] == v[i+1][1] && v[i+2][0] == v[i+2][1]) {
            cout << "Yes" << endl;
            return;
        }
    }
    cout << "No" << endl;
    return;
}

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

    ll T = 1;

    while(T--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3648
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    ll a,b;
    cin >> a >> b;
    print(a*b);

    

}

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

Measured memory_bytes: 3636
import java.util.Scanner;

class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  private Scanner sc = new Scanner(System.in);

  private void run() {
    long N = sc.nextLong();
    long A = sc.nextLong();
    long B = sc.nextLong();

    long aSet = N / (A + B) * A;
    long mod = N % (A + B);

    System.out.println(aSet + Math.min(mod, A));
  }
}


Measured memory_bytes: 23764
import java.util.*;
import java.io.*;

public class Main{
	public static String judge(String[] str){
		int[][] point = new int[4][2];
		int index = 0;
		for(int i = 0; i < 8; i++){
			for(int j = 0; j < 8; j++){
				if( str[i].charAt(j) == '1' ){
					point[index][0] = i;
					point[index][1] = j;
					index++;
				}
			}
		}
		int a = point[3][0]-point[0][0];
		int b = point[3][1]-point[0][1];
		if( a == 1 && b == 1 ){
			return "A";
		} else if( a == 3 && b == 0 ){
			return "B";
		} else if( a == 0 ){
			return "C";
		} else if( a == 2 && b == -1 ){
			return "D";
		} else if( a == 1 && b == 2 ){
			return "E";
		} else if( a == 2 && b == 1 ){
			return "F";
		} else {
			return "G";
		}
	}
	
	public static void main(String[] args){
		Scanner stdIn = null;
		List<String> result = new ArrayList<String>();
		
		try{
			stdIn = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
			while( stdIn.hasNext() ){
				String[] str = new String[8];
				for(int i = 0; i < 8; i++){
					str[i] = stdIn.next();
				}
				result.add(judge(str));
			}
			for(String str : result){
				System.out.println(str);
			}
		} finally {
			if( stdIn != null ){
				stdIn.close();
			}
		}
	}
}

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

int main() {
	string s;
	cin >> s;
	vector<char> num = { '3','5','7' };
	int n = s.size();

	int ans = 0;
	for (int i = 3; i <= n; i++) {
		for (int j = 0; j < pow(3, i); j++) {
			int m = j;
			string c = "";
			vector<int> cnt = { 0,0,0 };
			for (int k = 0; k < i; k++) {
				int l = m % 3;
				m -= l;
				m /= 3;
				c += num[l];
				cnt[l]++;
			}
			if (cnt[0] * cnt[1] * cnt[2] == 0) continue;
			if (i == n) {
				if (c <= s) ans++;
			}
			else ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <bitset>
#define ll long long int
using namespace std;


int main(){
 
 int A,B,K; cin>>A>>B>>K;
 int cnt=0;

 for(int i=A*B;;i--){
  // cout<<cnt<<endl;
if(A%i==0 and B%i==0){
  cnt++;
  //c//out<<i<<endl;
  if(cnt==K){
    cout<<i<<endl;
    return 0;
  }
}
 }



  return 0;
}
  

Measured memory_bytes: 256
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

sem_result = sum(b_list)
for i in range(n-1):
    if a_list[i+1] - a_list[i] == 1:
        sem_result += c_list[a_list[i] - 1]

print(sem_result)

Measured memory_bytes: 3064
require 'pp'

s = gets.chomp!
k = gets.chomp!.to_i
chs = s.chars

chunk = chs.chunk_while{|i, j| i == j }.to_a
if chunk.length == 1
    puts chunk[0].length * k / 2
    exit 0
end

# 一回目
total = 0
chunk.each do |ch|
    total += ch.length / 2
end
#pp total
# 2回目以降
sub_total = 0
if k >= 2
    chunk.each do |ch|
        sub_total += ch.length / 2
    end
    if chunk[0][0] == chunk[-1][0]
        if chunk[0].length % 2 == 1 && chunk[-1].length % 2 == 1
            sub_total += 1
        end
    end
end

puts total + sub_total * (k-1)



Measured memory_bytes: 2044
#include <cstdio>

int S[100010], n;

 bool BinarySearch(int key) {
	 int left = 0;
	 int right = n;
	 int mid;
	 while (left < right) {
		 mid = (left + right) / 2;
		 if (key == S[mid]) return true;
		 if (key > S[mid]) left = mid + 1;
		 else if (key < S[mid]) right = mid;
	 }
	 return false;
}

int main() {
	int q, T;
	int cnt = 0;
	
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) scanf("%d", &S[i]);
	scanf("%d", &q);
	for (int i = 0; i < q; ++i) {
		scanf("%d", &T);
		if (BinarySearch(T)) cnt++;
	}
	printf("%d\n", cnt);
}


Measured memory_bytes: 2960
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    char arra[n+5][m+5];
    for(int i=0;i<n;i++) {
        for(int j=0;j<m;j++) {
            cin>>arra[i][j];
        }
    }
    int dp[n+5][m+5];
    memset(dp,0,sizeof(dp));
    
    dp[0][0]=1;
    for(int i=0;i<n;i++) {
        for(int j=0;j<m;j++) {
            if(i==0 && j!=0) {
                if(arra[i][j]=='#') {
                    dp[i][j]=0;

                }
                else {
                    dp[i][j]=dp[i][j-1];
                }
            }
            else if(j==0 && i!=0) {

                if(arra[i][j]=='#') {
                    dp[i][j]=0;

                }
                else {
                    dp[i][j]=dp[i-1][j];
                }

            }
            else  if(i>0 && j>0){
                if(arra[i][j]=='#') {
                    dp[i][j]=0;

                }
                else {
                    dp[i][j]=(dp[i-1][j]+dp[i][j-1])%1000000007;

                }
            }


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


}


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

void solve(long long R, long long G){
    cout << 2 * G - R << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long R;
    scanf("%lld",&R);
    long long G;
    scanf("%lld",&G);
    solve(R, G);
    return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn
import scala.annotation.tailrec

object Main{
  def main(args: Array[String]){
    StdIn.readLine()
    val line = StdIn.readLine().split(" ").toList.map(_.toInt)

    val res = sSort(List(), line, 0)
    println(res._1.mkString(" ") + "\n" + res._2)
  }

  @tailrec
  def sSort(sorted: List[Int], unsorted: List[Int], n: Int):(List[Int], Int)={
    if((sorted ::: unsorted).length == 1) (unsorted, n)
    else if(unsorted.sorted == unsorted) ((sorted ::: unsorted), n)
    else if(unsorted.indexWhere(_ == unsorted.min) == 0) sSort(sorted :+ unsorted.head, unsorted.tail, n)
    else {
      val pos = unsorted.indexWhere(_ == unsorted.min)
      val swapped = unsorted.updated(0, unsorted(pos)).updated(pos, unsorted.head)

      sSort(sorted :+ unsorted.min, swapped.tail, n+1)
    }
  }
}

Measured memory_bytes: 45240
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
	int p,i;
	string s;
	map<string,vector<int> > dt;
	while(cin >> s >> p)
	{
		dt[s].push_back(p);
	}

	for(map<string,vector<int> >::iterator it=dt.begin(); it!=dt.end(); it++)
	{
		cout << it->first << endl;
		sort(it->second.begin(),it->second.end());
		for(i=0; i<it->second.size()-1; i++)
		{
			cout << it->second[i] << " ";
		}
		cout << it->second[i] << endl;
	}

	return 0;
}

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

int f(int n, int k){
	if(n == 1) return 0;
	return (f(n-1, k) + k) % n;
}

void solve(int n, int k, int m){
	cout << (f(n-1, k) + m) % n + 1 << "\n";
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		int n, k, m;
		cin >> n >> k >> m;
		if(n+k+m == 0) return 0;
		solve(n, k, m);
	}
}


Measured memory_bytes: 3404
#include <iostream>
using namespace std;
int N,K;
int sum;
int main() {
	int DP[100][3][3]={0},EN[101]={0};
	cin >> N >> K;
	int x,y,can;
	
	for(int i=0;i<K;i++){
	cin >> x >> y;
		EN[x]=y;
		
	}

	for(int i=0;i<3;i++){
		if(EN[1]==0 || EN[1]==i+1)
			DP[0][i][(i+1)%3]=1;
	}
	for(int i=1;i<N;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				for(int l=0;l<3;l++){
					if((!(j==k && k==l)) && ((EN[i+1]==j+1) || EN[i+1]==0)){
				DP[i][j][k]=(DP[i][j][k]+DP[i-1][k][l])%10000;

					}
					
				}
				//cout << i << j << k << " " << DP[i][j][k] << endl;
			}
		}
	}
	
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				sum+=DP[N-1][j][k];
			}
		}
		cout << sum%10000 << endl;
	// your code goes here
	return 0;
}

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

int main()
{
	long N, M, Q;
	std::cin >> N >> M >> Q;

	std::vector<std::pair<long, long> > vM;
	for ( long i = 0; i < M; i++ )
	{
		long tmp1, tmp2;
		std::cin >> tmp1 >> tmp2;
		vM.emplace_back( std::make_pair( tmp1, tmp2 ) );
	}

	std::vector<std::pair<long, long> > vQ;
	for ( long i = 0; i < Q; i++ )
	{
		long tmp1, tmp2;
		std::cin >> tmp1 >> tmp2;
		vQ.emplace_back( std::make_pair( tmp1, tmp2 ) );
	}

	// 累積和を計算する
	long num[500][500] = { 0 };
	long sum[501][501] = { 0 };

	for ( auto &&it : vM )
	{
		// 区間(p, q)を走る本数をカウント
		num[it.first - 1][it.second - 1]++;
	}

	for ( long i = 1; i <= N; i++ )
	{
		for ( long j = 1; j <= N; j++ )
		{
			sum[i][j] = num[i - 1][j - 1] + sum[i][j - 1];
		}
	}

	// 問題Qiが含む区間(pi, qi)の合計を求める
	for ( auto &&it : vQ )
	{
		long counter = 0;
		for ( long i = it.first; i <= it.second; i++ )
		{
			counter += sum[i][it.second];
		}
		std::cout << counter << std::endl;
	}

	return ( 0 );
}


Measured memory_bytes: 12012
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

class  Main{
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        while (true) {
            int m = scan.nextInt();
            int nMin = scan.nextInt();
            int nMax = scan.nextInt();
            if(m==0 && nMin==0 && nMin==0){
                break;
            }
            Integer[] data= new Integer[m];
            for(int i=0;i<m;i++){
                data[i]=scan.nextInt();
            }
            Arrays.sort(data, Collections.reverseOrder());
            int[] ans={-1,-1};
            for(int i=nMin;i<=nMax;i++){
                int gap=data[i-1]-data[i];
                if(gap>=ans[0]){
                    ans[0]=gap;
                    ans[1]=i;
                }
//                for(int j=0;j<i;j++){
//                    System.out.println("ue="+j);
//                }
//                for(int j=i;j<m;j++){
//                    System.out.println("sita="+j);
//                }
//                System.out.println("");
            }
            System.out.println(ans[1]);
        }
    }
}


Measured memory_bytes: 57080
#include <bits/stdc++.h>
using namespace std;
vector<int> positions;
vector<int> a, b;
int n, k, c;

int left(int i) {
	if((int)positions.size() == 0) return -1;
	auto it = upper_bound(positions.begin(), positions.end(), i - c - 1);
	if(it == positions.begin()) return -1;
	return *prev(it);
}

int right(int i) {
	auto it = lower_bound(positions.begin(), positions.end(), i + c + 1);
	if(it == positions.end()) return -1;
	return *it;
}

int main() {
	cin >> n >> k >> c;
	string s;
	cin >> s;

	set<int> ans;
	a.assign(n, 0);
	b.assign(n, 0);

	for(int i = 0; i < n; i++) {
		if(s[i] == 'x') a[i] = (i - 1 >= 0 ? a[i - 1] : 0);
		else {
			int l = left(i);
			a[i] = (l != -1 ? a[l] : 0) + 1;
			positions.push_back(i);
			ans.insert(i);
		}
	}

	for(int i = n - 1; i >= 0; i--) {
		if(s[i] == 'x') b[i] = (i + 1 < n ? b[i + 1] : 0);
		else {
			int r = right(i);	
			b[i] = (r != - 1 ? b[r] : 0) + 1;
		}
	}

	vector<int> fa(k + 1, -1), fb(k + 1, -1);
	fa[0] = -1; fb[0] = n;

	for(int i = 0; i < n; i++) {
		if(fa[a[i]] == -1) fa[a[i]] = i;
		if(a[i] == k) break;
	}

	for(int i = n - 1; i >= 0; i--) {
		if(fb[b[i]] == -1) fb[b[i]] = i;
		if(b[i] == k) break;
	}
	
	for(int val_a = 0; val_a <= k; val_a++) {
		int val_b = k - val_a;
		int l = fa[val_a], r = fb[val_b];
		if(l < r) {
			auto it = ans.upper_bound(l);
			while(it != ans.end() && *it < r) {
				auto prev_it = it++;
				ans.erase(prev_it);
			}
		}
	}

	for(auto it = ans.begin(); it != ans.end(); it++) {
		cout << *it + 1 << '\n';
	}
}


Measured memory_bytes: 14968
#include<stdio.h>
int main()
{
	char input[25];
	scanf("%s",input);
	for(int i = 0;input[i] != '\0';i++)
	{
		if(input[i] >='a' && input[i] <='z')
		{
			printf("%c",input[i]);
		}
		else{
			printf(" ");
		}
	}
}

Measured memory_bytes: 2112
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}
pair<ll, ll> f(ll x) {
  string s = to_string(x);
  return make_pair(*s.begin()-'0', *(s.end()-1)-'0');
}

void solve(long long N){
  vector<vector<ll>> v(10, vector<ll>(10, 0));
  for(ll i= 1; i<=N; i++) {
    v[f(i).first][f(i).second]++;
  }
  ll ans = 0;
  for(ll i=0; i<10; i++) {
    for(ll j=0; j<10; j++) {
      ans += v[i][j]*v[j][i];
    }
  }
  std::cout << ans << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  solve(N);
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
  int N, K, R, S, P; cin >> N >> K >> R >> S >> P;
  string T; cin >> T; int ans = 0;
  rep(i, N){
    if(T[i]=='r') ans+=P;
    else if(T[i]=='s') ans+=R;
    else ans+=S;
  }
  int cnt[K];
  rep(i, K){
    cnt[i] = 1;
  }
  for(int i=K; i<N; i++){
    if(T[i]==T[i-K] && i<N-K) cnt[i%K]++;
    else{
      if(T[i]==T[i-K]) cnt[i%K]++;
      if(T[i-K]=='r') ans-=(cnt[i%K]/2)*P;
      else if(T[i-K]=='s') ans-=(cnt[i%K]/2)*R;
      else ans-=(cnt[i%K]/2)*S;
      cnt[i%K]=1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 768
#include<functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <string.h>
#include <string>
#include <math.h>
#include <time.h>
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
int n, d;
string s;
int dp[10001][2][100];
int calc(int idx, bool lmt, int sum) {
	if (idx == n) {
		if (sum == 0)
			return 1;
		return 0;
	}
	int &ret = dp[idx][lmt][sum];
	if (ret != -1)
		return ret;
	ret = 0;
	if (lmt) {
		for (int i = 0; i < s[idx] - '0'; ++i)
			ret = (ret + calc(idx + 1, false, (sum + i) % d)) % mod;
		ret = (ret + calc(idx + 1, true, (s[idx] - '0' + sum) % d)) % mod;
	}
	else
		for (int i = 0; i < 10; ++i)
			ret = (ret + calc(idx + 1, false, (sum + i) % d)) % mod;
	return ret;
}
int main() {
	//freopen("src.txt", "r", stdin);
	memset(dp, -1, sizeof dp);
	cin >> s >> d;
	n = s.size();
	int ans = 0;
	for (int i = 0; i < s[0] - '0'; ++i)
		ans = (ans + calc(1, false, i % d)) % mod;
	ans = (ans + calc(1, true, (s[0] - '0') % d)) % mod;
	cout << (ans - 1 + mod) % mod << endl;
	return 0;
}

Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define INF 1e18
#define REPL(i,a,b) for(int i=a;i<a;++i)
#define REPLE(i,a,b) for(int i=a;i<=a;++i)
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pi;

#define M_PI 3.14159265358979323846

int a[100005];
const int oo = 1e9+10;
const int mod = 7901;

ll gcd(ll a, ll b){return a==0 ? b : gcd(b%a, a);}

int dp[100005];
int n;

void solve(){
	cin>>n;
	for(int i = 0 ; i < n ; ++i)cin>>a[i];
	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);
	for(int i = 2 ; i < n ; ++i){
		dp[i] = min(abs(a[i]-a[i-1]) + dp[i-1] , abs(a[i]-a[i-2])+dp[i-2]);
	}
	cout << dp[n-1] << '\n';
}
int main(){   
    ios::sync_with_stdio(0);cin.tie(0);
	int t=1;
	while(t--){
		solve();
	}
}  





Measured memory_bytes: 4400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b;cin>>a>>b;
    if(a<=0&&0<=b)cout<<"Zero"<<endl;
    else if(a>0)cout<<"Positive"<<endl;
    else if(a%2==b%2)cout<<"Negative"<<endl;
    else cout<<"Positive"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

int main() {
    int a, b;
    cin>>a>>b;
    if((a*b)%2==0) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val rate = nextInt()
    if (rate < 1200) {
        println("ABC")
    } else {
        println("ARC")
    }
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 30008
#include <stdio.h>

int main(void)
{
	int pay;
	int cnt;
	
	while (1) {
		cnt = 0;
		scanf("%d", &pay);
		if (pay == 0) {
			break;
		}
		pay = 1000 - pay;
		while (pay > 0) {
			if (pay >= 500) {
				pay -= 500;
				cnt++;
			}
			else if (pay >= 100) {
				pay -= 100;
				cnt++;
			}
			else if (pay >= 50) {
				pay -= 50;
				cnt++;
			}
			else if (pay >= 10) {
				pay -= 10;
				cnt++;
			}
			else if (pay >= 5) {
				pay -= 5;
				cnt++;
			}
			else {
				pay -= 1;
				cnt++;
			}
		}
		printf("%d\n", cnt);
	}
	return (0);
}

Measured memory_bytes: 600
a = int(input()) #500
b = int(input()) #100
c = int(input()) #50
x = int(input()) #Total

count = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            total = 500*i + 100*j + 50*k
            if total == x:
                count = count + 1

print(count)

Measured memory_bytes: 3060
#include <iostream>
#define REP(i, a, n) for(int i = a; i <= n; i++)
#define SIZE 100001
using namespace std;


long N, A, B, X[SIZE];
long a, ans;

int main(void) {
  cin >> N >> A >> B;
  REP(i, 1, N) cin >> X[i];

  ans = 0;
  REP(i, 1, N - 1) {
    ans += min((X[i + 1] - X[i]) * A, B);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024