akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int N,K,R,S,P,a,i;
string T;
bool f[1<<17];
int main(){
	cin>>N>>K>>R>>S>>P>>T;
	for(i=0;i<N;i++){
		if(i<K||T[i-K]!=T[i]||!f[i-K]){
			a+=T[i]=='r'?P:T[i]=='s'?R:S;
			f[i]=true;
		}
	}
	cout<<a<<endl;
}


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

int main() {
	while (1) {
		int sdice[4], dice0[4], dice1[4], p, k, w;
		int dice0p = 0, dice1p = 0, player = 0;
		char str[256];
		dice0[0] = 1, dice0[1] = 2, dice0[2] = 6, dice0[3] = 5;
		dice1[0] = 1, dice1[1] = 3, dice1[2] = 6, dice1[3] = 4;
		scanf("%d", &w);
		if (w == 0) break;
		for (k=0;k < w;k++) {
			scanf("%s", str);
			if (!strcmp(str, "North")) {
				sdice[0] = dice0[0];
				sdice[1] = dice0[1];
				sdice[2] = dice0[2];
				sdice[3] = dice0[3];

				p = dice0[0];
				dice0[0] = sdice[1];
				dice0[1] = sdice[2];
				dice0[2] = sdice[3];
				dice0[3] = p;
				dice1[0] = dice0[0];
				dice1[1] = dice1[1];
				dice1[2] = 7 - dice0[0];
				dice1[3] = 7 - dice1[1];
			} else if (!strcmp(str, "East")) {
				sdice[0] = dice1[0];
				sdice[1] = dice1[1];
				sdice[2] = dice1[2];
				sdice[3] = dice1[3];

				p = dice1[2];
				dice1[0] = sdice[3];
				dice1[1] = sdice[0];
				dice1[2] = sdice[1];
				dice1[3] = p;
				dice0[0] = dice1[0];
				dice0[1] = dice0[1];
				dice0[2] = 7 - dice0[0];
				dice0[3] = 7 - dice0[1];
			} else if (!strcmp(str, "West")) {
				sdice[0] = dice1[0];
				sdice[1] = dice1[1];
				sdice[2] = dice1[2];
				sdice[3] = dice1[3];

				p = dice1[0];
				dice1[0] = sdice[1];
				dice1[1] = sdice[2];
				dice1[2] = sdice[3];
				dice1[3] = p;
				dice0[0] = dice1[0];
				dice0[1] = dice0[1];
				dice0[2] = 7 - dice0[0];
				dice0[3] = 7 - dice0[1];
			} else if (!strcmp(str, "South")) {
				sdice[0] = dice0[0];
				sdice[1] = dice0[1];
				sdice[2] = dice0[2];
				sdice[3] = dice0[3];

				p = dice0[0];
				dice0[0] = sdice[3];
				dice0[1] = p;
				dice0[2] = sdice[1];
				dice0[3] = sdice[2];
				dice1[0] = dice0[0];
				dice1[1] = dice1[1];
				dice1[2] = 7 - dice0[0];
				dice1[3] = 7 - dice1[1];
			} else if (!strcmp(str, "Right")) {
				sdice[0] = dice0[0];
				sdice[1] = dice0[1];
				sdice[2] = dice0[2];
				sdice[3] = dice0[3];

				dice0[0] = sdice[0];
				dice0[1] = dice1[1];
				dice0[2] = sdice[2];
				dice0[3] = dice1[3];

				dice1[0] = sdice[0];
				dice1[1] = sdice[3];
				dice1[2] = sdice[2];
				dice1[3] = sdice[1];
			} else if (!strcmp(str, "Left")) {
				sdice[0] = dice0[0];
				sdice[1] = dice0[1];
				sdice[2] = dice0[2];
				sdice[3] = dice0[3];

				dice0[0] = sdice[0];
				dice0[1] = dice1[3];
				dice0[2] = sdice[2];
				dice0[3] = dice1[1];

				dice1[0] = sdice[0];
				dice1[1] = sdice[1];
				dice1[2] = sdice[2];
				dice1[3] = sdice[3];
			}
			player += dice0[0];
			/*
			printf("%d:%d\n", player, dice0[0]);
			p = 0;
			while (p < 4) {
				printf("    %d %d\n", dice0[p], dice1[p]);
				p += 1;
			}
			*/
		}
		printf("%d\n", player+1);
	}
	return 0;
}

Measured memory_bytes: 604
import java.util.*;

public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int[] input = new int[3];
      	for(int i = 0; i < 3; i++){
          	input[i] = sc.nextInt();
        }
      
      	int candidate = input[0];
      	if(candidate == input[1])
          	System.out.println(input[2]);
      	else if(candidate == input[2])
          	System.out.println(input[1]);
      	else
          	System.out.println(input[0]);
    }
}

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

struct UnionFind{
    vector<int> p, rank, v, mark, d[100000];
    int n;
    UnionFind(int siz){
        n = siz;
        p.resize(n), rank.resize(n, 0), v.resize(n, 0), mark.resize(n, 0);
        mark[0]++;
        for(int i = 0; i < n; i++)  p[i] = i;
        for(int i = 1; i < n; i++)  cin >> v[i], v[i]--;
        for(int i = 1; i < n; i++)  d[v[i]].push_back(i);
        dfs(0, 0);
    }

    void dfs(int pos, int dep){
        rank[pos] = dep;
        for(int next : d[pos])  dfs(next, dep+1);
    }

    int findSet(int x){
        if(p[x] != x)   p[x] = findSet(p[x]);
        return p[x];
    }

    void unite(int x, int y){
        x = findSet(x), y = findSet(y);
        if(x == y)  return;
        if(rank[x] < rank[y]){
            p[y] = x;
        }else{
            p[x] = y;
        }
    }

    void dfs2(int pos){
        if(pos != 0 && mark[pos] == 0){
            unite(pos, v[pos]);
        }
        for(int next : d[pos]){
            dfs2(next);
        }
    }
};

typedef long long ll;

int main(){
    int n, q;
    while(cin >> n >> q, n+q){
        UnionFind uf(n);
        char op[q];
        int x[q];
        for(int i = 0; i < q; i++){
            cin >> op[i] >> x[i];
            x[i]--;
            if(op[i] == 'M')    uf.mark[x[i]]++;
        }
        uf.dfs2(0);
        ll ans = 0;
        for(int i = q-1; i >= 0; i--){
            if(op[i] == 'Q'){
                ans += uf.findSet(x[i])+1;
            }else{
                uf.mark[x[i]]--;
                if(uf.mark[x[i]])   continue;
                uf.unite(x[i], uf.v[x[i]]);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 13248
#include<cstdio>
#include<algorithm>
#define rg register
using namespace std;
int n,m,x,val[1000],ans1,ans2;
inline int read(){
	int k=0,f=1; char c=getchar();
	while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
	while('0'<=c&&c<='9')k=k*10+c-'0',c=getchar();
	return k*f;
}
int main(){
	n=read(); m=read(); x=read();
	for(rg int i=1;i<=m;i++) val[read()]=1;
	for(rg int i=x;i<=n;i++) ans1+=val[i];
	for(rg int i=x;i>=0;i--) ans2+=val[i];
	printf("%d\n",min(ans1,ans2));
	return 0; 
} 

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}

#define NUM_MAX 100000

// a < b
int gcd(int a, int b) {
    if(a == 0) return b;
    return gcd(b%a, a);
}

void swap(int *a, int *b) {
    int tmp = *a;
    *a = *b;
    *b = tmp;
}

int gcd2(int a, int b) {
    if(a > b) swap(&a, &b);
    return gcd(a, b);
}

int main(void) {
    int num = get_int();
    static int arr[NUM_MAX+2];
    fget_array(&arr[1], num);

    static int cum[NUM_MAX+2];
    int i;
    for(i = 1; i <= num; i++) {
        cum[i+1] = gcd2(cum[i], arr[i]);
    }

    static int rcum[NUM_MAX+2];
    for(i = num; i >= 1; i--) {
        rcum[i-1] = gcd2(rcum[i], arr[i]);
    }

    int ans = 0;
    for(i = 1; i <= num; i++) {
        int res = gcd(cum[i], rcum[i]);
        ans = max(res, ans);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

bool solve(int h, int w, vector<string> &a, vector<string> &b){
  int n = b.size();
  bool ok = true;
  REP(i,n)REP(j,n){
    if(a[i+h][j+w] != b[i][j]) ok = false;
  }
  return ok;
}

int main(){
  int n, m;
  cin >> n >> m;
  vector<string> a(n);
  vector<string> b(m);
  REP(i,n) cin >> a[i];
  REP(i,m) cin >> b[i];


  bool  ok = false;
  REP(i,n)REP(j,n){
    if(i > n - m || j > n - m ) continue;
    //cout << i << " " << j << endl;
    if(solve(i,j,a,b)) {
      ok = true;
      break;
    }
  }

  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3584
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn = 100000;
char s[maxn + 5], t[maxn + 5];
LL n, m;
int main() {
	scanf("%lld%lld", &n, &m);
	scanf("%s%s", s + 1, t + 1);
	int g = __gcd(n, m);
	for(int i = 1, j = 1; i <= n && j <= m; i += n / g, j += m / g) {
		if(s[i] != t[j]) {
			printf("-1\n");
			return 0;
		}
	}
	printf("%lld\n", n * m / g);
	return 0;
}

Measured memory_bytes: 384
N=int(input())
b=[int(s) for s in input().split()]

a=[]
while len(b) > 0:
    filtered = [i for i in range(len(b)) if i == b[i] - 1]
    if len(filtered) == 0:
        print(-1)
        exit(0)
    j = filtered[-1]
    a.append(b[j])
    del b[j]

a.reverse()
for ai in a:
    print(ai)

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

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

int MOD=1e9+7;
ll INF=1e18;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int d[210][210];

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

int main(){
    int n, m, r; cin>>n>>m>>r;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(i==j) d[i][j]=0;
            else d[i][j]=MOD;
        }
    }

    vector<int> town(r);
    for(int i=0; i<r; i++){
        cin>>town[i];
        town[i]--;
    }

    for(int i=0; i<m; i++){
        int a, b, c; cin>>a>>b>>c;
        a--, b--;
        d[a][b]=c, d[b][a]=c;
    }

    warshall_floyd(n);

    int total=1;
    for(int i=1; i<=r; i++) total*=i;

    int ans=MOD;
    for(int i=0; i<total; i++){
        int sum=0;
        for(int j=0; j<r-1; j++){
            sum+=d[town[j]][town[j+1]];
        }
        ans=min(ans, sum);
        next_permutation(town.begin(), town.end());
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int n,mx=0,mx1=0;
    cin >> n;
    vector<int> vec(n);
    rep(i,n){
        cin >> vec.at(i);
        if(mx<=vec.at(i)){
            mx1=mx;
            mx=vec.at(i);
        }
        else if(mx1<vec.at(i))mx1=vec.at(i);
    }
    rep(i,n){
        if(vec.at(i)==mx)cout << mx1 << endl;
        else cout << mx << endl;
    }
}

Measured memory_bytes: 2432
x, n = map(int, input().split())

p = list(map(int, input().split()))

if x <= 50:
    minp = x
    minv = 0
    p.sort()
else:
    minp = abs(101 - x)
    minv = 101
    p.sort(reverse=True)

if n == 0:
    print(x)
elif n == 100:
    if x <= abs(101 - x):
        print(0)
    else:
        print(101)
else:
    for i in range(1, 101):
        if i in p:
            continue
        else:
            if abs(i - x) < minp:
                minp = abs(i - x)
                minv = i
            elif abs(i - x) == minp:
                if (minv > i):
                    minv = i
    print(minv)


Measured memory_bytes: 61924
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
typedef pair< double,double> dd;
#define pb push_back
#define eb emplace_back
#define sz(a) (int)a.size()
#define all(c) c.begin(),c.end()
#define FOR(i,a,b) for(i=a; i<b; i++)
#define FORR(i,a,b) for(i=a;i>=b;i--)
#define REP(i,n) FOR(i,0,n)
#define x first
#define y second
#define mp make_pair

const int INF = 1000000007;
const long long INFLL = (ll)INF * (ll)INF;

ll bigfuzzsum(int n)
{
	ll s=0;
	for(int i=1;i<=n;i++)
	{
		if(i%3!=0 && i%5!=0)
		s+=i;
	}
	return s;
}
int32_t main()
{
	IOS;
	int n;
	cin>>n;
	cout<<bigfuzzsum(n);
	return 0;
}


Measured memory_bytes: 3636
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class _0105
{
    public static void Main()
    {
        string data;
        SortedDictionary<string, SortedList<int, string>> di = new SortedDictionary<string, SortedList<int, string>>();
        di.Clear();
        while ((data = Console.ReadLine()) != null)
        {
            string[] d = data.Split();
            if (!di.ContainsKey(d[0])) di[d[0]] = new SortedList<int, string>();
            di[d[0]].Add(int.Parse(d[1]), d[1]);
        }
        foreach (KeyValuePair<string, SortedList<int, string>> p in di)
        {
            Console.WriteLine(p.Key);
            Console.WriteLine(String.Join(" ", p.Value.Values.ToArray()));
        }
    }
}

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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  string S;
  cin>>S;
  int l = S.size();
  bool can = true;
  if(S[l-1]=='1') can = false;
  S.erase(S.end()-1);
  l--;
  for(int i = 0; i < l; i++) {
    if(S[i]!=S[l-1-i]) can=false;
  }
  if(S[0]=='0') can = false;
  if(!can) cout<<-1<<endl;
  if(can){
    int parent = 0;
    int cnt = 1;
    for(int i = 0; i < l; i++){
      if(S[i]=='0') {
        cout<<parent+1<<" "<<cnt+1<<endl;
        cnt++;
      }
      if(S[i]=='1'){
        cout<<parent+1<<" "<<cnt+1<<endl;
        parent = cnt;
        cnt++;
      }
    }
  }
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
int main() {
     vector<int> C(3);
     for(int i = 0; i < 3; i++){
          cin >> C[i];
     }
     sort(C.begin(),C.end());
     if(C[0] + C[1] == C[2]) cout << "Yes" << endl;
     else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
    string S; cin >> S;
    int N = S.size()+1;
    set<int> s;
    if(S[0] == '<') s.insert(0);
    if(S[N-2] == '>') s.insert(N-1);
    rep(i,N-2){
        if(S[i] == '>' &&  S[i+1] == '<') s.insert(i+1);
    }
    ll ans = 0;
    int tmp = 0;
    if(S[0] == '>'){
        rep(i,N-2){
            if(S[i] == '>' && S[i+1] == '>') tmp++;
            else break;
        }
        ans += (ll)(tmp+1)*(tmp+2)/2;
    }
    for(int u : s){
        if(u != N-1){
            int cntl = 0;
            int cntr = 0;
            int now = u;
            repr(i,now,N-2){
                if(S[i] == '<' && S[i+1] == '<'){
                    cntl++;
                    now++;
                }
                else{
                    now++;
                    break;
                }
            }
            repr(i,now,N-2){
                if(S[i] == '>' && S[i+1] == '>'){
                    cntr++;
                    now++;
                }
                else break;
            }
            //cout << cntl << cntr << endl;
            int k = max(cntl,cntr);
            int m = min(cntl,cntr);
            ans += (ll)(k+1)*(k+2)/2 + (ll)m*(m+1)/2;
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 6532
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int n;
  cin>>n;
  rep(i,100000) if(i*i > n){cout<<(i-1)*(i-1)<<endl;return 0;}

  return 0;
}





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


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int n, m;
  cin >> n >> m;
  cout << (n-1)*(m-1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);


int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    ll N; cin>>N;
    vector<ll> X(N,0);
    vector<ll> Y(N,0);
    rep(i,N){
        cin>>X[i];
        Y[i]=X[i];
    }
    
    sort(all(Y));
    ll L=Y[N/2-1],R=Y[N/2];
    rep(i,N){
        if(X[i]<=L) cout<<R<<endl;
        else cout<<L<<endl;
    }
}


Measured memory_bytes: 6424
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 1000;
static const int VMAX = 10000;

int n, A[MAX], s;
int B[MAX], T[VMAX + 1];

int solve() {
  int ans = 0;

  bool V[MAX];
  for ( int i = 0; i < n; i++ ) {
    B[i] = A[i];
    V[i] = false;
  }
  sort(B, B + n);
  for ( int i = 0; i < n; i++ ) T[B[i]] = i;
  for ( int i = 0; i < n; i++ ) {
    if ( V[i] ) continue;
    int cur = i;
    int S = 0;
    int m = VMAX;
    int an = 0;
    while ( 1 ) {
      V[cur] = true;
      an++;
      int v = A[cur];
      m = min(m, v);
      S += v;
      cur = T[v];
      if ( V[cur] ) break;
    }
    ans += min(S + (an - 2) * m, m + S + (an + 1) * s);
  }
  return ans;
}

int main() {
  cin >> n;
  s = VMAX;
  for ( int i = 0; i < n; i++ ) {
    cin >> A[i];
    s = min(s, A[i]);
  }
  int ans = solve();
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int N, M, lmax = 0, rmin = 100000;
    cin >> N >> M;
    for (int i = 0, l, r; i < M; i++) {
        cin >> l >> r;
        if (l > lmax) lmax = l;
        if (r < rmin) rmin = r;
    }
    cout << max(0, rmin - lmax + 1) << endl;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace ABC102C
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));

            return;
        }

        public void Solve(ConsoleInput cin)
        {

            var N = cin.ReadInt;
            var A = cin.ReadIntArray(N);

            var A2 = new int[N];
            for(int i = 0; i < N; i++)
            {
                A2[i] = A[i] - i;
            }
            Array.Sort(A2);
            var median = A2[N / 2];

            long ans = 0;
            for(int i = 0; i < N; i++)
            {
                ans += Abs(A2[i] - median);
            }

            Console.WriteLine(ans);

        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 30852
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vec_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define vec_output(v) for(auto it=v.begin();it!=v.end();it++){if(it!=v.begin())cout<<" ";cout<<*it;}cout<<endl;
#define vec_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
template <typename T>T digitsum(T n);
template <typename T>bool isPrime(T n);
template <typename T>vector<pair<T, T>> prime_factor(T n);
long long int intpow(long long int,long long int);
template <typename T>T intlog(T);
long long int combination(long long int,long long int);
long long int arith_sum1(long long int,long long int,long long int);
long long int arith_sum2(long long int,long long int,long long int);
long long int series_sum(long long int);

int main(){
    int n,m,k;
    cin>>n>>m>>k;
    vector<ll> a(n),b(m);
    ll x,sum=0;
    vec_input(a);
    rep(i,m){
        cin>>x;
        sum+=x;
        b[i]=sum;
    }
    sum=0;
    ll ans=(ll)(upper_bound(all(b),k)-b.begin());
    ll hikaku;
    rep(i,n){
        sum+=a[i];
        if(sum<=k){
            hikaku=i+1+(ll)(upper_bound(all(b),k-sum)-b.begin());
            ans=max(ans,hikaku);
        }else{
            break;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6348
#include<iostream>
#define ll long long


using namespace std;
ll N;

void f(ll,ll,ll&);
int main(){
  cin >> N;
  ll result = 0;
  f(0,0,result);
  cout << result << endl;
}

void f(ll cur,ll use,ll &result){
  if(cur > N){
    return;
  }
  if(use == 0b111){
    result++;
  }

  f(cur * 10 + 7,use | 0b001,result);
  f(cur * 10 + 5,use | 0b010,result);
  f(cur * 10 + 3,use | 0b100,result);

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      (int)1e9+7
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;

int main(){
	int n;
	cin>>n;
	
	vi a(n);
	map<int,int> mp;
	REP(i,n){
		cin>>a[i];
		for(int j=-1;j<=1;++j) mp[a[i]+j]++;
	}
	
	int ans=0;
	for(auto elem:mp){
		ans=max(ans,elem.second);
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5120
#include<iostream>
#include<vector>
#include<string>

using namespace std;

using ll = int64_t;

/// <summary>
/// 単純なcoutの時に使う
/// </summary>
#define co(a) cout<<a<<"\n"


/// <summary>
/// [beg, end)の範囲を，添え字indexでループするfor文に置換します
/// </summary>
#define rep(i,a) for(ll i=0; i<a; ++i)
#define reps(i, a, b) for(ll i = a; i < b; ++i)

/// <summary>
/// 迷路等で使う方向のベクトル
/// </summary>
const vector<ll> dx = { 0, 1, 0, -1 }, dy = { 1, 0, -1, 0 };

/// <summary>
/// デバッグ時に使う
/// </summary>
#define DEBUG(x)     std::cout << #x << " : " << x << "\n"

///////////////////////////////////////////////////////////////////////////

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

	ll N;
	cin >> N;

	vector<double> A (N);

	rep (i, N) {
		cin >> A[i];
	}

	double hoge = 0;
	rep (i, N) {
		hoge += 1 / A[i];
	}

	double ans = 1;
	ans /= hoge;

	cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    int X, Y;
    cin >> X >> Y;

    int j;
    for (int i = 0; i <= X; i++)
    {
        j = X - i;
        if (i * 2 + j * 4 == Y)
        {
            printf("Yes\n");
            return (0);
        }
    }
    printf("No\n");
    return (0);
}

Measured memory_bytes: 3628
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    even = 0
    odd = 0
    for aa in a:
        if aa%2 == 0:
            even += 1
        else:
            odd += 1
    if odd % 2 == 1:
        print('NO')
        return
    print('YES')


if __name__ == '__main__':
    main()


Measured memory_bytes: 14108
N=input()
A=input()
B=input()
C=input()

count=0
for i,word in enumerate(A):

    if B[i]==C[i]:
        if B[i]==C[i] and B[i]==A[i]:
            count=count+1
        count=count-1
    if B[i]!=word:
        count=count+1
    if C[i]!=word:
        count=count+1

print(count)


Measured memory_bytes: 3060
n,m=map(int,input().split())
info=[]
for i in range(n):
    cost,maxbuy=map(int,input().split())
    info.append([cost,maxbuy])
info2=sorted(info) #安い順に並び替え
total=0
num=0
i=0
while num<=m:
    if num+info2[i][1]>=m:
        total+=(m-num)*info2[i][0]
        break
    num+=info2[i][1]
    total+=info2[i][0]*info2[i][1]
    i+=1
print(total)

Measured memory_bytes: 20832
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))




#62
h,w = map(int,input().split())

for i in range(w+2):
    print("#",end ="")
print()
for i in range(h):
    print("#",end ="")
    print(input(),end ="")
    print("#")
for i in range(w+2):
    print("#",end ="")
print()




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

int main(){
	int k,n;
	cin >> k >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a.at(i);
	}
	int aida = k+a.at(0)-a.at(n-1);
	for(int i=0;i<n-1;i++){
		if(aida<a.at(i+1)-a.at(i)){
			aida = a.at(i+1)-a.at(i);
		}
	}
	cout << k - aida << endl;
}

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

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i=0; i<N; ++i) cin >> a[i];
    sort(a.begin(), a.end());
    for (int i=0; i<(int)a.size()-1; ++i) {
        if (a[i] == a[i+1]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 1024
#O(|S|log|s|)
def main():
	s=input()
	t=input()
	n=len(s)
	now=-1
	ans=1
	if not set(t)<=set(s):#tがsの部分集合でない
		print(-1)
		exit()
	for x in t:
		now=s.find(x,now+1)#nowより大きいところからxを探す
		if now==-1:#nowより大きいところでxが見つからなかったら
			ans+=n
			now=s.find(x)
	print(ans+now)
if __name__ == '__main__':
	main()

Measured memory_bytes: 3316
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

const int MAX = 1e5 + 10;
bool cmp(int a, int b) {
    return a > b;
}
int main() {
    int N;
    scanf("%d", &N);
    int A[MAX];
    for(int i = 1; i <= N; i++) {
        scanf("%d", &A[i]);
    }
    sort(A + 1, A + N + 1, cmp);
    int pos = 1;
    for(int i = 1; i <= N; i++)
        if(A[i] >= i) pos = i;
    int dist1 = A[pos] - pos;
    int dist2 = 0;
    for(int i = pos + 1; i <= N; i++) {
        if(A[i] >= pos) dist2++;
    }
    //cout << pos << endl;
    //cout << dist1 << dist2 << endl;
    if((dist1 % 2) || (dist2 % 2)) printf("First\n");
    else  printf("Second\n");
}


Measured memory_bytes: 3492
#include<bits/stdc++.h>
using namespace std;
#define ot(x) cout<<x<<" ";
#define out(x) cout<<x<<"\n";
#define pb push_back
#define in insert
#define ll long long int
#define ld long double
#define ull unsigned long long int
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define yes cout<<"yes\n";
#define no cout<<"no\n";
#define Yes cout<<"Yes\n";
#define No cout<<"No\n";
#define fa(i,a) for(auto i:a)
#define f(i,x,a) for(i=x;i<a;i++)
#define next cout<<"\n";
#define sp(n) cout<<fixed<<setprecision(n);
#define  gcd(a,b)    __gcd(a,b)
#define bs  binary_search
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test int t;cin>>t;while(t-->0)
#define mod 1000000007



int main()
{
   fast
  string s;cin>>s;
  if(s[s.length()-1]=='s'){
    cout<<s+"es";
  }
  else{
    cout<<s+'s';
  }

  return 0;
}





Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int main()
{
	int n,i;
	cin>>n;
	int t[n+1],x[n+1],y[n+1];
	for (i=1;i<=n;i++)
		cin>>t[i]>>x[i]>>y[i];
	for (i=1;i<=n;i++)
		if (x[i]+y[i]>t[i]||(x[i]+y[i])%2!=t[i]%2)
		{
			cout<<"No";
			return 0;
		}
	cout<<"Yes";
	return 0;
}

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

template <typename T>
void print(const T &v);

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    sort(p.begin(), p.end());
    int sum = 0;
    rep(i, k)
    {
        sum += p[i];
    }
    cout << sum << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 3632
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#include <bits/stdc++.h>
#define MOD 1000000007
#define int long long
using namespace std;
#define ss second
#define ff first
int32_t main()
{
    fastio;
    int t,n,m,i,j,k,a,b,c;
    t=1;
    string str;
    while(t --> 0)
    {
        cin>>n;
      	cin>>str;
        vector<int> R,G;
        unordered_map<int,bool> B;
        for(i=0;i<n;i++)
        if( str[i] == 'R')
            R.emplace_back(i);
        else if( str[i] == 'G')
            G.emplace_back(i);
        else
            B[i]=true;

        m=B.size();
        int ans=R.size()*G.size()*m;
        for(auto a:R)
        for(auto b:G)
        {
            if( (a+b)%2==0 and B[(a+b)/2] )
                ans--;
            if( B[2*a-b])
                ans--;
            if( B[2*b-a])
                ans--;
        }
        cout<<ans;
    }
    return 0;
}


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

// 無限大を表す値
const long long INF = 1LL<<60;

int main() {
    // 頂点数，辺数
    int N, M;
    cin >> N >> M;

    // dp 配列 (INF で初期化します)
    vector<vector<long long> > dp(N, vector<long long>(N, INF));

    // dp 初期条件
    for (int e = 0; e < M; ++e) {
        int a, b;
        long long w;
        cin >> a >> b >> w;
        dp[a][b] = w;
    }
    for (int v = 0; v < N; ++v) dp[v][v] = 0;

    // dp 遷移 (Floyd--Warshall)
    for (int k = 0; k < N; ++k)
        for (int i = 0; i < N; ++i)
            for (int j = 0; j < N; ++j)
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);

    // 結果出力
    // もし dp[v][v] < 0 なら負閉路あり
    bool exist_negative_cycle = false;
    for (int v = 0; v < N; ++v) if (dp[v][v] < 0) exist_negative_cycle = true;
    if (exist_negative_cycle) {
        cout << "NEGATIVE CYCLE" << endl;
    }
    else {
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                if (j) cout << " ";
                if (dp[i][j] < INF/2) cout << dp[i][j];
                else cout << "INF";
            }
            cout << endl;
        }
    }                              
}



Measured memory_bytes: 3244
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = int_fast64_t;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;

template<class T> inline T sqr(T x) {return x*x;}

int gcd(int a, int b) {
    if (a < b) swap(a,b);
    while (b > 0) {
        a %= b;
        swap(a,b);
    }
    return a;
}

void solve() {
    LL n,m;
    string s,t;
    cin >> n >> m >> s >> t;
    //dump(gcd(n,m));
    LL l = n * m / gcd(n,m), g = gcd(n,m);
    //dump(g);
    if (g == 1) {
        if (s[0] == t[0]) cout << l << endl;
        else cout << -1 << endl;
    } else {
        REP(i,0,g) {
            if (s[i * n / g] != t[i * m / g]) {
                //dump(s[i * n / g]);
                //dump(t[i * m / g]);
                cout << -1 << endl;
                return;
            }
        }
        cout << l << endl;
    }
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 512
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import bisect
import fractions

def gcd(a, b):
    return fractions.gcd(a, b)

def lcm(a, b):
    return a * b // gcd(a, b)

def calc(n, a, b):
    return n//a + n//b - n//lcm(a,b)

if __name__ == '__main__':
    a, b, c, d = map(int, input().split())
    ## これで通った
    # num1 = b - calc(b,c,d)
    # num2 = (a-1) - calc(a-1, c,d)
    # print(num1-num2)

    ## これはとおらない
    ans = calc(b, c, d) - calc(a - 1, c, d)
    print(b - a + 1 - ans)


Measured memory_bytes: 5204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    ll N,a,b; cin >> N >> a >> b;

    if(N==1){
        if(a != b) cout << 0 << endl;
        else cout << 1 << endl;
        return 0;
    }

    if(a>b) cout << 0 << endl;
    else cout << a+b*(N-1) - (a*(N-1)+b-1) << endl;
    
}

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

typedef pair<int,int> P;

int main(){
  int N;
  cin>>N;
  vector<vector<int>> G(N);
  vector<P> vP;
  for(int i=1;i<N;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;	// 0 オリジンに
    G[a].push_back(b);
    G[b].push_back(a);

    vP.push_back({a,b});
  }

  int K=0;
  map<pair<int,int>,int> I;
  	/*
		map<key,data>
		keyを参照するとdataを出せる
	*/
  vector<int> inColor(N,0); // color of edge between its parent

  vector<int> used(N,0);
  queue<int> Q;
  used[0]=1;
  Q.push(0);
  while(Q.empty()==false){
    int now=Q.front();Q.pop();
    if(K<(int)G[now].size()) K=G[now].size();
    int color=1;
    for(int next:G[now]){
      if(used[next]) continue;
      if(color==inColor[now]) color++;

      inColor[next]=I[{now,next}]=I[{next,now}]=color++;
      used[next]=1;
	  Q.push(next);
    }
  }

  cout<<K<<endl;
  for(auto p:vP) cout<<I[p]<<endl;
  return 0;
}


Measured memory_bytes: 20084
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

template<typename V>
constexpr string join(const V &v, const string &sep) {
  stringstream ss;
  if (v.size()) ss << v[0];
  loop(i, 1, v.size()) ss << sep << v[i];
  return ss.str();
}

void solve() {
  int h, w;
  cin >> h >> w;
  vvi dp(h, vi(w));
  rep(i, h) rep(j, w) {
    char c;
    cin >> c;
    dp[i][j] = c == 'c' ? 0 : INF;
  }
  rep(i, h) loop(j, 1, w) cmin(dp[i][j], dp[i][j - 1] + 1);
  rep(i, h) rep(j, w) if (dp[i][j] == INF) dp[i][j] = -1;
  rep(i, h) cout << join(dp[i], " ") << endl;
}

Measured memory_bytes: 3184
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <cstdlib>
#include <cctype>

using namespace std;

typedef long long int lli;

struct St{
  St() {}
  St(map<lli, lli> _mpp): mpp(_mpp) {}
  map<lli, lli> mpp;

  bool check(lli key){
    return (mpp.find(key) != mpp.end());
  }
};

map<char, lli> ainfo;
map<char, St> minfo;

void setAry(string str)
{
  int p = 2, l =str.size()-1;
  string s = "";
  map<lli, lli> mp;

  while(p < l) s += str[p++];
  ainfo[str[0]] = atoll(s.c_str());
  minfo[str[0]] = St(mp);
}

lli getVal(string str)
{
  int p = 2;
  lli pt;
  char ch = str[0];

  if(ainfo.find(ch) == ainfo.end()) return -1;
  if(isalpha(str[p])){
    pt = getVal(str.substr(p));
    if(pt == -1) return -1;
  } else {
    string s = "";
    while(isdigit(str[p])) s += str[p++];
    pt = atoll(s.c_str());
  }

  if(ainfo[ch] <= pt) return -1;
  if(!minfo[ch].check(pt)) return -1;

  return minfo[ch].mpp[pt];
}

bool setVal(string str, lli v)
{
  int p = 2;
  lli pt;
  char ch = str[0];

  if(ainfo.find(ch) == ainfo.end()) return false;
  if(isalpha(str[p])){
    pt = getVal(str.substr(p));
    if(pt == -1) return false;
  } else {
    string s = "";
    while(isdigit(str[p])) s += str[p++];
    pt = atoll(s.c_str());
  }

  if(ainfo[ch] <= pt) return false;
  minfo[ch].mpp[pt] = v;

  return true;
}

int strfind(string str)
{
  int p = 0;
  for(; p < str.size() && str[p] != '='; ++p);

  return p;
}

int main()
{
  string str;
  int n, p;
  lli v;
  bool f;

  while(cin>>str && str != "."){
    n = 1;
    f = true;

    do {
      if(!f) continue;
      if((p=strfind(str)) == str.size()){
	setAry(str);
      } else {
	if(isalpha(str[p+1])){
	  if((v=getVal(str.substr(p+1))) == -1){
	    cout << n << endl;
	    f = false;
	    continue;
	  }
	} else {
	  v = atoll((str.substr(p+1)).c_str());
	}
	if(!setVal(str.substr(0, p-1), v)){
	  cout << n << endl;
	  f = false;
	  continue;
	}
      }

      ++n;
    } while(cin>>str && str != ".");

    if(f) cout << 0 << endl;
    ainfo.clear();
    minfo.clear();
  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

int main()
{
	int64 rr, gg, bb, nn, ans = 0;
	cin >> rr >> gg >> bb >> nn;
	for(int64 ii = 0;rr * ii <= nn;ii++)
	{
		for(int64 jj = 0;rr * ii + gg * jj <= nn;jj++)
		{
			if((nn - rr * ii - gg * jj) % bb == 0)
			{
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3560
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

int n,dp[100005],a[100005],k; 
int main(){
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for (int i=2;i<=n;i++){
		dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
		for (int j=max(1,i-k);j<i;j++){
			dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j])); 
		}
	}
	printf("%d\n",dp[n]);
	return 0;
} 

Measured memory_bytes: 896
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>

using namespace std;

typedef long long int lli;

int gcd(int a, int b) {
	return b != 0 ? gcd(b, a%b) : a;
}
lli gcd(lli a, lli b) {
	return b != 0 ? gcd(b, a%b) : a;
}
int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
lli lcm(lli a, lli b) {
	return a * b / gcd(a, b);
}

#define N_MAX 100000
#define MOD 1000000007

//lli fac[N_MAX], finv[N_MAX], inv[N_MAX];
//
//void COMinit() {
//	fac[0] = fac[1] = 1;
//	finv[0] = finv[1] = 1;
//	inv[1] = 1;
//	for (int i = 2; i < N_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;
//	}
//}
//
//lli 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;
//}
//
//lli modpow(lli base, lli p)
//{
//	if (0 == p) {
//		return 1;
//	}
//	if (0 == p % 2) {
//		lli val = modpow(base, p / 2);
//		return (val*val) % MOD;
//	}
//	else {
//		return (modpow(base, p - 1)*base) % MOD;
//	}
//}

pair<int,int> table[N_MAX];

void solv()
{
	int N, K, S; scanf("%d%d%d", &N, &K, &S);

	for (int i = 0; i < K; i++) {
		printf("%d ", S);
	}
	if (1000000000 == S) {
		for (int i = K; i < N; i++) {
			printf("%d ", 1);
		}
	}
	else {
		for (int i = K; i < N; i++) {
			printf("%d ", S + 1);
		}
	}

	return;

	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}


Measured memory_bytes: 1280
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    S = input().strip("\n")
    S += "0"
    count = 0
    nowCol = S[0]
    for i in range(1, N + 1):
        if S[i] != nowCol:
            count += 1
            nowCol = S[i]
    print(count)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        cin >> N;
        vll V(N);
        vll C(N);
        rep(i, 0, N) cin >> V[i];
        rep(i, 0, N) cin >> C[i];
        ll ans = 0;
        rep(i, 0, N) {
                ll tmp = V[i] - C[i];
                if (tmp <= 0) continue;
                ans += tmp;
        }
        cout << ans << endl;
}

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

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

  
  if (str.find("AB") != std::string::npos || str.find("BA") != std::string::npos ) {
   puts("Yes");
}
  else{
    cout << "No" <<endl;
  }
  
  
}


Measured memory_bytes: 256