akhauriyash/Code-Regression huggingface dataset:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())

ans = 0
for i in range(len(t)):
    if i < k:
        if t[i] == "r":
            ans += p
        elif t[i] == "s":
            ans += r
        else:
            ans += s
    else:
        if t[i] == "r":
            if t[i - k] != "r":
                ans += p
            else:
                t[i] = "x"
        if t[i] == "s":
            if t[i - k] != "s":
                ans += r
            else:
                t[i] = "x"
        if t[i] == "p":
            if t[i - k] != "p":
                ans += s
            else:
                t[i] = "x"
                
print(ans)

Measured memory_bytes: 9872
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>

using namespace std;

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x[i]);
  }
  long long ans = LLONG_MAX;
  for (int i = 0; i + k - 1 < n; i++) {
    long long left = x[i];
    long long right = x[i + k - 1];
    if (left < 0 && right < 0) {
      ans = min(ans, -left);
    }
    else if (left > 0 && right > 0) {
      ans = min(ans, right);
    }
    else {
      ans = min(ans, -left + right + min(-left, right));
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <time.h>
#include <iostream>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>

using namespace std;

string str;

int isCat( int ptr ) {
	if( str[ptr] != 'm' ) {
		return -1;
	}
	ptr++;
	if( str[ptr] != 'e' ) {
		ptr = isCat(ptr);
		if( ptr == -1 ) return -1;
	}
	ptr++;
	if( str[ptr] != 'w' ) {
		ptr = isCat(ptr);
		if( ptr == -1 ) return -1;
	}
	ptr ++;
	return ptr;
}

int solve() {
	cin >> str;
	int p = isCat(0);
	if( p == str.length() || str == "" || str == "mew" )
		cout << "Cat" << endl;
	else
		cout << "Rabbit" << endl;
	return 1;
}
     
int main(void){
	while(1){
		if( solve() ) break;
	}
    return 0;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

template<typename T>
T Hungarian(const vector<vector<T> >& b){
    int p, q, n = len(b);
    vector<int> fx(n, 1<<28), fy(n, 0);
    vector<int> x(n, -1), y(n, -1);
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            fx[i] = max(fx[i], b[i][j]);
    for (int i = 0; i < n; ) {
        vector<int> t(n, -1), s(n+1, i);
        for (p = q = 0; p <= q && x[i] < 0; ++p)
            for (int k = s[p], j = 0; j < n && x[i] < 0; ++j)
                if (fx[k] + fy[j] == b[k][j] && t[j] < 0) {
                    s[++q] = y[j], t[j] = k;
                    if (s[q] < 0)
                        for (p = j; p >= 0; j = p)
                            y[j] = k = t[j], p = x[k], x[k] = j;
                }
        if (x[i] < 0) {
            int d = 1<<28;
            for (int k = 0; k <= q; ++k)
                for (int j = 0; j < n; ++j)
                    if (t[j] < 0) d = min(d, fx[s[k]] + fy[j] - b[s[k]][j]);
            for (int j = 0; j < n; ++j) fy[j] += (t[j] < 0 ? 0 : d);
            for (int k = 0; k <= q; ++k) fx[s[k]] -= d;
        } else ++i;
    }
    int ret = 0;
    for (int i = 0; i < n; ++i) ret += b[i][x[i]];
    return ret;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x,y,m;
    cin >> x >> y >> m;
    vvi cs(max(x,y),vi(max(x,y),0));
    rep(i,m){
        int a,b;
        cin >> a >> b;
        cs[a][b] = 1;
    }
    cout << Hungarian(cs) << "\n";
    return 0;
}



Measured memory_bytes: 3292
def main():
    N = input()
    lst = []
    result = 'Yes'
    for i in range(N):
        W = raw_input()
        # print lst
        if lst == []:
            lst.append(W)
            continue
        if W in lst:
            result = 'No'
            break
        elif W[0] != lst[-1][-1]:
            # print W[-1]
            # print lst[-1][-1]
            result = 'No'
            break
        else:
            lst.append(W)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2692
N, K = map(int, input().split())
S = input()
X = []
ch = S[0]
cnt = 1
for i in range(1, len(S)):
    if S[i] != ch:
        X.append([ch, cnt])
        cnt = 1
        ch = S[i]
    elif S[i] == ch:
        cnt += 1
X.append([ch, cnt])

st = None
if X[0][0] == '0':
    st = 0
else:
    st = 1
en = st +  2 * (K - 1)
re = K
for v in X:
    if v[0] == '0':
        re -= 1
        
if '0' not in S:
    print(N)
elif re > 0:
    print(N)
else:
    max_1 = 0
    for i in range(st, en + 1):
        max_1 += X[i][1]
    if st - 1 >= 0:
        max_1 += X[st - 1][1]
    if en + 1 < len(X):
        max_1 += X[en + 1][1]
    tmp = max_1
    while True:
        if en + 2 >= len(X):
            break
        if st == 0:
            tmp -= X[0][1]
        else:
            tmp -= X[st][1] + X[st - 1][1]
        if en + 2 == len(X) - 1:
            tmp += X[en + 2][1]
        else:
            tmp += X[en + 3][1] + X[en + 2][1]
        st = st + 2
        en = en + 2
        if tmp > max_1:
            max_1 = tmp
    print(max_1)


Measured memory_bytes: 59888
n = int(input())
s = list(input())
cnt = 0
ans_list = [0]
e_cnt = 0

for i in range(1,n):
    if s[i-1] == "E" and s[i] == "E":
        cnt -= 1
        e_cnt += 1
    if s[i-1] == "E" and s[i] == "W":
        cnt -= 0
    if s[i-1] == "W" and s[i] == "E":
        cnt += 0
        e_cnt += 1
    if s[i-1] == "W" and s[i] == "W":
        cnt += 1
    ans_list.append(cnt)

print(min(ans_list) + e_cnt)

Measured memory_bytes: 23428
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

bool equal(vl& a, vl& b) {
  rep(i, a.size()) {
    if (a[i] != b[i]) return false;
  }
  return true;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  ll a = 0, b = 0;
  vl x(n);
  vl p(n), q(n);
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> q[i];
  rep(i, n) x[i] = i + 1;
  do {
    if (equal(x, p)) break;
    a++;
  } while (next_permutation(x.begin(), x.end()));

  rep(i, n) x[i] = i + 1;
  do {
    if (equal(x, q)) break;
    b++;
  } while (next_permutation(x.begin(), x.end()));

  cout << abs(a - b) << endl;
  return 0;
}


Measured memory_bytes: 256
//╔╗───────────╔╗────────────────────╔╗─
//║║──────────╔╝╚╗──────────────────╔╝╚╗
//║╚═╗╔══╗╔══╗╚╗╔╝╔══╗╔═╗╔╗╔╗╔══╗ ╔╗╚╗╔╝
//║╔╗║║╔╗║║╔╗║─║║─║║═╣║╔╝║╚╝║║╔╗║─╣║─║║─
//║╚╝║║╔╗║║║║║─║╚╗║║═╣║║─║║║║║╚╝║─║║─║╚╗
//╚══╝╚╝╚╝╚╝╚╝─╚═╝╚══╝╚╝─╚╩╩╝╚══╝─╚╝─╚═╝ 

#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz size()
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define mod 1000000007
#define forn(i, n) for (int i = 0; i < (int) (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;

int main() {
    IO;
    string s;
    cin >> s;
    forn(i,s.sz-1){
        if(s[i] == s[i+1]){
            cout << i+1 << " " << i+2;
            return 0;
        }
    }
    forn(i,s.sz-2){
        if(s[i] == s[i+2]){
            cout << i+1 << " " << i+3;
            return 0;
        }
    }
    cout << "-1 -1";
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,m,x;
int c[15],a[15][15],p[15],ans=0x3f3f3f3f;
void dfs(int step,int price)
{
	
	if(step==n+1)
	{
		for(int i=1;i<=m;i++) 
		  if(p[i]<x)return;
		 ans=min(ans,price);
		 return; 
	 } 
	 
	 dfs(step+1,price);
	 for(int i=1;i<=m;i++) p[i]+=a[step][i];
	 dfs(step+1,price+c[step]); for(int i=1;i<=m;i++) p[i]-=a[step][i];
} 
int main()
{
	 cin>>n>>m>>x;
	
	 for(int i=1;i<=n;i++)
	  {cin>>c[i];
	  	for(int j=1;j<=m;j++)
	   {
	   	 cin>>a[i][j];
	   }
	   } 
	
  dfs(1,0);
  if(ans>1e9)cout<<-1;
  else cout<<ans;
return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include <string>
#include <algorithm>
#include <math.h>
#define MOD 1000000007
#define ll long long
using namespace std;

int main()
{
	ll int ans,pro,c,len;
	ll int in;
	cin >> in;
	int s[10];
	int i,j,k;
	ans = 0;
	pro = in;
	len = 0;
	for (i = 0; i < 10; i++){
		len += 1;
		pro = pro / 10;
		if (pro == 0){
			break;
		}
	}
	pro = in;
	for (i = 0; i < len; i++){
		s[len - i - 1] = pro % 10;
		pro = pro / 10;
	}
	for (i = 0; i < len; i++){
		for (j = 0; j < len - i; j++){
			pro = 0;
			for (k = 0; k < i + 1; k++){
				pro = pro * 10;
				pro = pro + s[j + k];
			}
			c = len - i - 3;
			if (j == 0){
				c += 1;
			}
			if (j + i + 1 == len){
				c += 1;
			}
			for (k = 0; k < c; k++){
				pro = pro * 2;
			}
			ans = ans + pro;
		}
	}
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>
 
 
int main()
{
    std::string s, rev;
    std::cin >> s;
    std::reverse_copy(s.begin(), s.end(), std::back_inserter(rev));
    int cnt = 0;
    std::cerr << s << std::endl;
    std::cerr << rev << std::endl;
    for(int i=0; i<s.length(); i++)
    {
        if(s[i]!=rev[i]) cnt++;
    }
    std::cout << cnt/2 << std::endl;
    return 0;
}

Measured memory_bytes: 256
//http://drken1215.hatenablog.com/entry/2019/02/04/013700
//勉強させて頂いた記事

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse

const int MAX_DIGIT=50;
ll dp[100][2];//i:桁,smaller:未満フラグ

int main(){
    ll N,K;
    cin>>N>>K;
    vector<ll> A(N);
    rep(i,N)cin>>A[i];

    memset(dp,-1,sizeof(dp));//初期化
    dp[0][0]=0;//初期条件
    for(int d=0;d<MAX_DIGIT;d++){//dはdigitのd
        ll mask=1LL<<(MAX_DIGIT-d-1);//桁決め

        //Aで元々d桁目にビットが立っているものの個数
        int num=0;
        rep(i,N)if(A[i]&mask)++num;

        //Xのd桁目を0,1にした時のコスト
        ll cost0=mask*num;//1->0
        ll cost1=mask*(N-num);//0->1
        //maskにはbitの情報が入っていて、どこのbitかで値が決まるのでコストの計算が成り立つ

        //smaller-> smaller 未満なので自由に選択してよいため。
        if(dp[d][1]!=-1){
            chmax(dp[d+1][1],dp[d][1]+max(cost0,cost1));//0でも1でも自在に大きい方
        }

        //exact->smaller 上限を超えない処理をする
        if(dp[d][0]!=-1){
            if(K&mask){//Kのd桁目が1だったら、Xのd桁目は0に 超えないように0にしている？
                chmax(dp[d+1][1],dp[d][0]+cost0);//cost0は1->0の変換コストを表す。
            }
        }
        //exact->exact(Kにぴったり合わせる)
        if(dp[d][0]!=-1){
            if(K&mask)chmax(dp[d+1][0],dp[d][0]+cost1);//合わせるので、1の時は1,0の時は0
            else chmax(dp[d+1][0],dp[d][0]+cost0);
        }
    }
    //MAX_DIGITまで更新をかけているから、また未満フラグあり、なしの大きい方が解となる
    cout<<max(dp[MAX_DIGIT][0],dp[MAX_DIGIT][1])<<endl;


    return 0;
}

//a=97,z=122

//4=100
//1=001
//  101=5

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define fastio  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD=1000000007;
#define PI acos(-1)
using namespace std;
int main(){
     ll r; cin >> r;
     cout << r*r << endl;
}

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

int pow(int x, int n) {
  int ans = 1;
  for(int i = 0; i < n; i++) {
    ans *= x;
  }
  return ans;
}
 
int main() {
  static int d[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
  while(1) {
    int room[3][3];
    fill(&room[0][0], &room[2][2]+1, 0);
    int n;
    cin >> n;
    if(n == 0) break;

    char s, t, b;
    cin >> s >> t >> b;
    int temp = (int)s-(int)'A';
    int sx = temp%3;
    int sy = temp/3;
    temp = (int)t-(int)'A';
    int gx = temp%3;
    int gy = temp/3;
    temp = (int)b-(int)'A';
    room[temp/3][temp%3] = 2;

    double value[3][3];
    fill(&value[0][0], &value[2][2]+1, 0);
    value[sy][sx] = 1;
    for(int t = 0; t < n; t++) {
      double newValue[3][3];
      fill(&newValue[0][0], &newValue[2][2]+1, 0);
      for(int i = 0; i < 3; i++) {
	for(int j = 0; j < 3; j++) {
	  for(int k = 0; k < 4; k++) {
	    int nx = j + d[k][0];
	    int ny = i + d[k][1];
	    if(nx < 0 || nx >= 3) nx = j;
	    if(ny < 0 || ny >= 3) ny = i;
	    if(room[ny][nx] == 2) {
	      nx = j;
	      ny = i;
	    }
	    newValue[ny][nx] += value[i][j]/4;
	  }
	}
      }
      for(int i = 0; i < 3; i++) {
	for(int j = 0; j < 3; j++) {
	  value[i][j] = newValue[i][j];
	}
      }
    }
    printf("%.8f\n", value[gy][gx]);
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1000000009
#define MAXN 50

int n, ma, mb, a[MAXN], b[MAXN], c[MAXN], dp[MAXN + 5][510][510], ans = INF;

signed main()
{
    for(int i = 0; i <= MAXN; i++){
        for(int j = 0; j <= 500; j++){
            for(int k = 0; k <= 500; k++){
                dp[i][j][k] = INF;
            }
        }
    }
    cin >> n >> ma >> mb;
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    dp[0][0][0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 500; j++){
            for(int k = 0; k < 500; k++){
                if(j < a[i] || k < b[i]){
                    dp[i + 1][j][k] = dp[i][j][k];
                }
                else{
                    dp[i + 1][j][k] = min(dp[i][j][k], dp[i][j - a[i]][k - b[i]] + c[i]);
                }
            }
        }
    }
    for(int i = 1; i * ma < 500 && i * mb < 500; i++){
        ans = min(ans, dp[n][i * ma][i * mb]);
    }
    if(ans == INF){
        printf("-1\n");
    }
    else cout << ans << endl;

    return 0;
}


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

using namespace std;
int main()
{
    int a,b,t;
    int ans=0,c;
    cin>>a>>b>>t;
    c=a;
    while(1)
    {
        if(c>t)
        {
            break;
        }
        ans +=b;
        c +=a;
    }
    cout<<ans<<endl;
}


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

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

int main() {
  int N;
  cin >> N;
  vector<int> ns(N);
  vector<int> mns(N);
  for(int i = 0; i < N; ++i) {
    cin >> ns[i];
    mns[i] = ns[i];
  }
  for(int i = N - 2; i >= 0; --i) {
    chmin(mns[i], mns[i + 1]);
  }
  for(int i = 0; i < N - 1; ++i) {
    if(ns[i] - 1 > mns[i + 1]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
	int i,a,flag=0;
	scanf("%d",&a);
		if(a/1000==a/100-a/1000*10||a/100-a/1000*10==a/10-a/100*10||a/10-a/100*10==a%10)flag=1;
	
	
	if(flag==1)printf("Bad\n");
	else printf("Good\n");
	
	return 0;
}


Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))


i = 0

for i in range(len(A)):
    if (A[i] % 2 != 0 or (A[i] % 3 == 0 or A[i] % 5 == 0)):
        continue
    else:
        print('DENIED')
        exit()


print('APPROVED')


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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;



void solve(){
	ll n,k,ans=1e18;
	cin>>n>>k;
	vll A(n);
	for(int i=0;i<n;i++)cin>>A[i];
	sort(all(A));
	for(int i=k-1;i<n;i++)
		ans=min(ans,A[i]-A[i-k+1]);
	cout<<ans<<"\n";

}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;

	//ll t;cin>>t;while(t--)
	solve();

}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<set>
#include<math.h>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=1e6+7;
int t;
int main(){
    char c;
    cin>>c;
    if(c>='a'&&c<='z') printf ("a\n");
    else printf ("A\n");



}



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

main() {
  int H, W, d; cin >> H >> W >> d;
  string RYGB = "RYGB";
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int color = 0;
      color += (i + j) / d % 2;
      color += (i - j + W) / d % 2 * 2;
      cout << RYGB[color];
    }
    cout << endl;
  }
}


Measured memory_bytes: 512
import numpy as np

n = int(input())
h_list = np.array(list(map(int, input().split())))

def index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]
  
num=0

def func(h_list):
    #print(h_list)
    global num
    num += min(h_list)
    #print(num)
    h_list = h_list - min(h_list)
    #print(h_list)
    index_list=index_multi(h_list,0)
    #print(index_list,"index")
    for i in range(len(index_list)):        
        if i ==0:
            if not index_list[i]==0:
                func(h_list[:index_list[i]])
                #print(h_list[:index_list[i]])
        else:
            if not index_list[i-1]+1 == index_list[i]:
                func(h_list[index_list[i-1]+1:index_list[i]])
                #print((h_list[index_list[i-1]+1:index_list[i]]))
                
        if i == len(index_list)-1:
            if not index_list[i]==len(h_list)-1:
                func(h_list[index_list[i]+1:])
                #print(h_list[index_list[i]+1:])

func(h_list)
print(num)

Measured memory_bytes: 12504
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<cctype>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int main(){
int v[6][2];
int x , buf;
string ans;
bool fit = true;
int count = 0;

for(int i = 0; i <2; i++){
for(int j = 0; j <6; j++){
  cin >> v[j][i];
}
}
while(count <= 10000){
x =  rand()%4 ;
switch(x){
            case 0:{
                buf = v[0][0];
                v[0][0] = v[1][0];
                v[1][0] = v[5][0];
                v[5][0] = v[4][0];
                v[4][0] = buf;
                break;
            }
            case 1:{
                buf = v[0][0];
                v[0][0] = v[3][0];
                v[3][0] = v[5][0];
                v[5][0] = v[2][0];
                v[2][0] = buf;
                break;
            }
            case 2:{
                buf = v[0][0];
                v[0][0] = v[2][0];
                v[2][0] = v[5][0];
                v[5][0] = v[3][0];
                v[3][0] = buf;
                break;
            }
            case 3:{
                buf = v[0][0];
                v[0][0] = v[4][0];
                v[4][0] = v[5][0];
                v[5][0] = v[1][0];
                v[1][0] = buf;
                break;
            }
}//switch

  if(v[0][0] == v[0][1] && 
  v[1][0] == v[1][1] && 
  v[2][0] == v[2][1] &&  
  v[3][0] == v[3][1] && 
  v[4][0] == v[4][1] &&
  v[5][0] == v[5][1] ){
    fit = false;
    break;
}
count++;
}//while
if(fit == true){
  ans = "No";
}else if(fit == false){
  ans = "Yes";
}
cout << ans << endl;
return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>

using namespace std;



int main() {
	map<char, int> al;
	for (int i = 0; i < 26; i++) {
		al['a' + i] = 0;
	}
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		al[s[i]]++;
	}
	char alph;
	bool tf = false;
	for (int i = 0; i < 26; i++) {
		if (al['a' + i] == 0) {
			tf = true;
			alph = 'a' + i;
			break;
		}
	}
	if (tf)cout << alph << endl;
	else cout << "None" << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int MID=2020;
int n,md,i,j,nxt,res,f[6020][MID*2];
int main() {
  scanf("%d%d",&n,&md);
  f[0][MID]=1;
  for (i=0; i<3*n; i++) for (j=0; j<MID*2; j++) if (f[i][j]) {
    nxt=max(j-1,0);
    f[i+1][nxt]=(f[i+1][nxt]+f[i][j])%md;
    nxt=min(j+1,MID*2-1);
    f[i+2][nxt]=(f[i+2][nxt]+f[i][j]*(i+1LL))%md;
    f[i+3][j]=(f[i+3][j]+f[i][j]*(i+1LL)*(i+2LL))%md;
  }
  for (j=0; j<=MID; j++) res=(res+f[i][j])%md;
  printf("%d\n",res);
  return 0;
}


Measured memory_bytes: 93568
x, y = map(int, input().split())
ans = 0

def solve(v):
    if v == 3:
        return 100000
    if v == 2:
        return 200000
    if v == 1:
        return 300000
    return 0

ans = solve(x) + solve(y)

if x == 1 and y == 1:
    ans += 400000

print(ans)

Measured memory_bytes: 38436
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
const ll DVSR = 1e9+7;

int main(int argc, char const *argv[])
{
  ll N; cin >> N;
  cout << (N/2+N%2) << endl;
  return 0;
}


Measured memory_bytes: 256
import heapq
N, M = map(int, input().split())
ABs = [list(map(int, input().split())) for _ in range(N)]

heapq.heapify(ABs)
availables = []
ans = 0
for i in range(1, M + 1):
    while ABs:
        a = heapq.heappop(ABs)
        if a[0] == i:
            heapq.heappush(availables, -a[1])
        else:
            heapq.heappush(ABs, a)
            break
    if availables:
        ans -= heapq.heappop(availables)

print(ans)


Measured memory_bytes: 27884
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b) {a = b; return true;}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b) {a = b; return true;}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;


int main(){
    ll n,m; cin >> n >> m;
    vpl d(n); rep(i,n) cin >> d[i].first, d[i].second = i;
    vl dist(n); rep(i,n) dist[i] = d[i].first;
    vvl G(n);
    sort(all(d));
    map<P,ll> edges;
    rep(i,m){
        ll u,v; cin >> u >> v; u--; v--;
        if(u>v) swap(u,v);
        G[u].push_back(v);
        G[v].push_back(u);
        edges[{u,v}] = i;
    }
    vl ans_v(n,-1);
    vl ans_e(m,1e9);
    rep(i,n){
        ll u = d[i].second;
        if(ans_v[u] != -1){
            for(auto v : G[u]){
                if(ans_v[v] == -1){
                    ans_v[v] = 1 - ans_v[u];
                    ans_e[edges[{min(u,v),max(u,v)}]] = dist[v];
                }
            }
        }else{
            bool flag = false;
            for(auto v : G[u]){
                if(dist[v] == dist[u]){
                    flag = true;
                    ans_e[edges[{min(u,v),max(u,v)}]] = dist[u];
                    ans_v[u] = 0;
                    ans_v[v] = 1;
                    break;
                }
            }
            if(!flag){
                cout << -1 << endl;
                return 0;
            }
            for(auto v : G[u]){
                if(ans_v[v] == -1){
                    ans_v[v] = 1 - ans_v[u];
                    ans_e[edges[{min(u,v),max(u,v)}]] = dist[v];
                }
            }
        }
    }
    rep(i,n) cout << (ans_v[i]==0 ? "B" : "W");
    cout << endl;
    rep(i,m) printf("%lld\n",ans_e[i]);
}

Measured memory_bytes: 27520
#!/usr/bin/env python

def solve():
    s = input()
    k = int(input())
    subs = sorted([s[i:] for i in range(len(s))])

    cnt = 0
    checked = set()
    for sub in subs:
        for i in range(len(sub)):
            term = sub[:i+1]
            if term not in checked:
                cnt += 1
                checked.add(term)
                if cnt == k:
                    print(term)
                    return


solve()


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

int main() {
	int N, K;
	cin >> N >> K;
	if((N-1) % (K-1) != 0){
		cout << (N-1) / (K-1) + 1 << endl;
	}
	else{
		cout << (N-1) / (K-1) << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
#include<ctype.h>
using namespace std;


int main() {
	int m;
	cin >> m;
	cout << 48 - m << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
    int n;
    while(cin >> n && n)
    {
        bool f[25][25];
        memset(f,0,sizeof(f));

        rep(i,n) {
            int x,y;
            cin >> x >> y;
            f[y][x] = true;
        }

        int m;
        cin >> m;

        int y = 10,x = 10;

        rep(i,m) {
            string s;
            cin >> s;

            int len;
            cin >> len;

            if(s == "N") {
                REP(j,1,len+1) {
                    if(f[y+j][x]) f[y+j][x] = false;
                }

                y += len;
            }
            else if(s == "E") {
                REP(j,1,len+1) {
                    if(f[y][x+j]) f[y][x+j] = false;
                }

                x += len;
            }
            else if(s == "S") {
                REP(j,1,len+1) {
                    if(f[y-j][x]) f[y-j][x] = false;
                }

                y -= len;
            }
            else if(s == "W") {
                REP(j,1,len+1) {
                    if(f[y][x-j]) f[y][x-j] = false;
                }

                x -= len;
            }
        }

        bool flag = true;
        rep(i,21) {
            rep(j,21) if(f[i][j]) flag = false;
        }

        if(flag) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}

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

int main(){
  int n, k, r, s, p;
  string t;
  cin >> n >> k >> r >> s >> p >> t;
  ll score = 0;
  vector<bool> ok(n, true);
  for(int i=0; i<n; i++){
    if(i-k >= 0){
      if(t[i] == t[i-k] && ok[i-k] == false) continue;
    }
    ok[i] = false;
    if(t[i] == 'r') score += p;
    else if(t[i] == 's') score += r;
    else score += s;
  }
  cout << score << endl;
}


Measured memory_bytes: 3784
module module_sort
    use iso_fortran_env
    implicit none

    interface quicksort
        module procedure :: int32_qsort
        module procedure :: int64_qsort
    end interface quicksort
contains

    recursive function int32_qsort(m) result(res)
        integer(int32), intent(in) :: m(:)
        integer(int32) :: res(size(m)) 

        if (size(m) <= 1) then; res = m
        else; res = [int32_qsort( pack(m(2:), m(2:) >= m(1)) ), m(1), int32_qsort( pack(m(2:), m(2:) < m(1)) )]
        end if

    end function int32_qsort

    recursive function int64_qsort(m) result(res)
        integer(int64), intent(in) :: m(:)
        integer(int64) :: res(size(m)) 

        if (size(m) <= 1) then; res = m
        else; res = [int64_qsort( pack(m(2:), m(2:) >= m(1)) ), m(1), int64_qsort( pack(m(2:), m(2:) < m(1)) )]
        end if

    end function int64_qsort

end module module_sort

program main
    use module_sort
    use iso_fortran_env
    implicit none
    integer(16) :: n
    integer(16), allocatable :: ai(:)
    integer(16) :: i, ie
    integer(16) :: ans

    read *, n
    allocate( ai(n) )
    read *, ai( 1:n )
!    ai = quicksort( ai )
!    call qsort( ai )
!    ai(n:1:-1) = ai(1:n)
    ai = intQsort( ai )
    ai(n:1:-1) = ai(1:n)

    if ( mod((n-1), 2) == 0 ) then
        ie = (n-1) / 2
        ans = ai(1) + ai(ie + 1)
    else
        ie = n / 2
        ans = ai(1)
    endif

    do i = 2, ie
        ans = ans + ai(i) * 2
    enddo

    print *, ans

contains

recursive subroutine qsort(a)
  implicit none
  integer(8),intent(inout) :: a(:)
  integer(8)::i,j,toobig,toosmall,pv,n

  n = size(a)
i = 1
j = n
pv = a((i+j)/2)
do
   do
     if (a(i) < pv) then
       i = i+1
     else
       exit
     end if
   end do
   do
     if(a(j) > pv) then
       j = j-1
     else
       exit
     end if
   end do
   if (i>=j) then
     exit
   else
     toobig = a(j)
     toosmall = a(i)
     a(i) = toobig
     a(j) = toosmall
     i = i+1
     j = j-1
   end if
 end do
 if (i > 2) then
   call qsort(a(1:i-1))
 end if
 if (j < n-1) then
   call qsort(a(j+1:n))
 end if
end subroutine qsort

pure recursive function intQsort( a ) result( r )
implicit none
integer(16), intent(in) :: a(:)
integer(16) :: r( size(a) )
integer(16) :: sample(3), len, i,j

len = size( a(:) )
if( len<=1 )then
  r = a
else
  !select pivot
  sample(1:3) = [a(1), a(len/2), a(len)]
  do i = 1,2
    do j = 2,3
      if( sample(i)>sample(j) )then
        len = sample(i) !len is buffer
        sample(i) = sample(j)
        sample(j) = len
      end if
    end do
  end do
  
  r = [ intQsort( pack(a(:), a(:)< sample(2)) ), &
                  pack(a(:), a(:)==sample(2))  , &
        intQsort( pack(a(:), a(:)> sample(2)) ) ]
end if
end function intQsort

end program main

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

int main() {

  long long N, K;
  cin >> N >> K;

  vector<long long> A(N);

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

  // ルート:root[i] -> i番目の移動先
  vector<int> root;

  // 通ったか否かを管理
  // 通った場合は、何番目に通ったかを記憶
  // 通っていない場合は、-1
  vector<int> visited(N + 1, -1);

  // 現在地点:1からスタートする
  int current = 1;

  // 同じ位置を通るまでループ
  while (visited[current] == -1) {

    // ルートに現在地点を追加
    root.push_back(current);

    // x番目に通った
    visited[current] = root.size();
    
    // 現在地点を更新
    current = A[current - 1];

  }

  // ループしている町の個数
  int roopSize = root.size() - visited[current] + 1;

  /*
  for (int i = 0; i <(int) root.size(); i++) {
    cout << root[i] << " ";
  }
  cout << endl;
  */

  // ループするまでに移動する町の個数
  int noRoopSize = visited[current] - 1;

  if (K < noRoopSize) {
    // K がループするまでに移動する町の個数より小さい場合は
    // K 番目を出力
    cout << root[K] << endl;
  } else {
    // そうじゃない場合は、余りの位置
    K -= noRoopSize;
    K %= roopSize;
    
    /*
    cout << roopSize << endl;
    cout << noRoopSize << endl;
    cout << K << endl;
    */
   
    cout << root[noRoopSize + K] << endl;
  }

  return 0;
}

Measured memory_bytes: 6676
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
#include <ctime>
#include <ostream>
using namespace std;
typedef long long ll;
int ver[105][105];
int a[1005],b[1005],c[1005];
int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL
    memset(ver,0x3f,sizeof ver);
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0; i<m; ++i)
    {
//        int a,b,c;
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
        ver[ a[i] ][ b[i] ]=c[i];
        ver[ b[i] ][ a[i] ]=c[i];
    }
    int mindis=1e9;
    for(int k=1; k<=n; k++)
        for(int i=1; i<=n; i++)
            for(int j=1; j<=n; ++j)
            {
                if(j==i)continue;
                ver[i][j]=min(ver[i][j],ver[i][k]+ver[k][j]);
                mindis=min(mindis,ver[i][j]);
            }
    int cnt=0;
    for(int i=0;i<m;++i)
    {
        if(ver[a[i]][b[i]]!=c[i])
            cnt++;
    }
    printf("%d",cnt);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

int main() {
	vector<ll> v(3);
	rep(i,3) cin >> v[i];
	sort(all(v));
	set<vector<ll> > s;
	s.insert(v);
	ll res = 0;
	while(v[0]%2+v[1]%2+v[2]%2 == 0) {
		vector<ll> vv(3);
		rep(i,3) {
			vv[i] = (v[(i+1)%3] + v[(i+2)%3]) / 2;
		}
		res++;
		v = vv;
		sort(all(v));
		if(s.find(v) != s.end()) {
			res = -1;
			break;
		}
		s.insert(v);
	}
	cout << res << endl;
	return 0;
}


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

int main() {
    int m, f, r;
    while (1) {
        cin >> m >> f >> r;
        if (m == -1 and f == -1 and r == -1) {
            return 0;
        }
        if (m == -1 or f == -1) {
            cout << "F" << endl;
        } else if (m + f >= 80) {
            cout << "A" << endl;
        } else if (m + f >= 65) {
            cout << "B" << endl;
        } else if (m + f >= 50 or (m + f >= 30 and m + f < 50 and r >= 50)) {
            cout << "C" << endl;
        } else if (m + f >= 30 && r < 50) {
            cout << "D" << endl;
        } else {
            cout << "F" << endl;
        }
    }
}

Measured memory_bytes: 2996
require "set"
n,k = gets.chomp.split(" ").map(&:to_i)
p_arr = gets.chomp.split(" ").map(&:to_i)
c_arr = gets.chomp.split(" ").map(&:to_i)

# 添字調整
p_arr.unshift(0)
c_arr.unshift(0)

cycle_arr = []

set = Set.new
# 閉路がいくつかあるのでそれを求める
(1..n).each do |i|
  start_index = i
  # 重複してたどるのを避ける
  next if set.include?(start_index)
  index = start_index
  in_cycle_arr = []
  sum = 0
  while true do
    # 問題文では移動先のスコアを計上するとあるが, 対象のグラフは閉路なので移動元のスコアで計上しても大丈夫
    score = c_arr[index]
    in_cycle_arr << score
    sum += score
    # 通った印づけ
    set << index
    # 次のindex
    index = p_arr[index]
    # ループ判定
    break if index == start_index
  end
  cycle_arr << [in_cycle_arr, sum]
end

# 負の無限大(c_iの最小値で良い)
max = (10 ** 9) * (-1)

# 各閉路の各indexで試す
cycle_arr.each do |(cycle, sum)|
  cycle.each_with_index do |c, i|
    c_length = cycle.length
    # sumが正ならなるべく繰り返した方がお得, 負なら繰り返さないほうがお得(0はどっちでもOK)
    if sum > 0
      loop_num = k / c_length
      r = k % c_length 
      if r == 0
        loop_num -= 1
        r = c_length
      end
      in_sum = sum * loop_num
      max = in_sum if in_sum > max
      r.times do |j|
        in_sum += cycle[(i + j) % c_length]
        max = in_sum if in_sum > max
      end
    else
      in_sum = 0
      c_length.times do |j|
        in_sum += cycle[(i + j) % c_length]
        max = in_sum if in_sum > max
      end
    end
  end
end

puts max

Measured memory_bytes: 15368
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    static int[] dp;
    static List<int>[] g;

    static int rec(int v)
    {
	if (dp[v] >= 0) return dp[v];

	int ret = 0;
	foreach (int nv in g[v])
	{
	    ret = Math.Max(ret, rec(nv) + 1);
	}

	return dp[v] = ret;
    }
    
    public static void Main()
    {
	var tmp = ReadIntArray();
	int n = tmp[0], m = tmp[1];

	g = new List<int>[n];
	for (int i = 0; i < n; i++) g[i] = new List<int>();
	
	for (int i = 0; i < m; i++)
	{
	    tmp = ReadIntArray();
	    int x = tmp[0], y = tmp[1];
	    g[x-1].Add(y-1);
	}

	dp = new int[n];
	for (int i = 0; i < n; i++) dp[i] = -1;

	int ans = 0;
	for (int i = 0; i < n; i++)
	    ans = Math.Max(ans, rec(i));

	WriteLine(ans);
    }
}


Measured memory_bytes: 33536
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printyn(a) printf(a ? "Yes\n" : "No\n");
#define printYN(a) printf(a ? "YES\n" : "NO\n");
#define all(x) (x).begin(), (x).end()

using ll = long long;

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
//#include <vector>

using namespace std;

int main() {

	int n, m, t[100], p, x, tamount = 0;
	scanf("%d", &n);
	rep(i, n) {
		scanf("%d", &t[i]);
		tamount += t[i];
	}
	scanf("%d", &m);
	rep(i, m) {
		scanf("%d%d", &p, &x);
		printf("%d\n", tamount - (t[p - 1] - x));
	}

	return 0;
}


Measured memory_bytes: 128
n, p = map(int, input().split(' '))
s = input()

if 10 % p == 0:
    ans = 0
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i + 1
    print(ans)
else:
    ans = 0
    d = [0 for _ in range(n + 1)]
    ten = 1
    for i in range(n - 1, -1, -1):
        a = int(s[i]) * ten % p
        d[i] = (d[i + 1] + a) % p
        ten *= 10
        ten %= p
    cnt = [0 for _ in range(p)]
    for i in range(n, -1, -1):
        ans += cnt[d[i]]
        cnt[d[i]] += 1
    print(ans)

Measured memory_bytes: 11208
def LI():return list(map(int,input().split()))
def yes():print("Yes")
def no():print("No")
from collections import deque

def main():
    n,m=LI()
    edge=[[] for i in range(n)]
    for i in range(m):
        a,b=LI()
        a-=1;b-=1
        edge[a].append(b)
        edge[b].append(a)
    
    ans=[-1]*(n)
    goal=deque([0])
    while goal:
        g=goal.popleft()
        for i in edge[g]:
            if ans[i]==-1:
                ans[i]=g+1
                goal.append(i)
    yes()
    print(*ans[1:])
main()
    


Measured memory_bytes: 97068
//デバッグ用オプション：-fsanitize=undefined,address

//コンパイラ最適化
#pragma GCC optimize("Ofast")

//インクルードなど
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

// vector set 等
#include <map>
#include <set>
#include <vector>

//マクロ
// forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
// FORAは範囲for文(使いにくかったら消す)
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto& i : I)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF 1000000000000  // 10^12:∞
#define MOD 1000000007     // 10^9+7:合同式の法
#define MAXR 100000        // 10^5:配列の最大のrange
//略記
#define PB push_back  //挿入
#define MP make_pair  // pairのコンストラクタ
#define F first       // pairの一つ目の要素
#define S second      // pairの二つ目の要素

// 負の数にも対応した % 演算
ll mod(ll x) {
  ll res = x % MOD;
  if (res < 0) x += MOD;
  return res;
}

ll mpow(ll x, ll n) {
  ll res = 1;
  while (n != 0) {
    if (n & 1) res = res * x % MOD;
    x = x * x % MOD;
    n = n >> 1;
  }
  return res;
}

// a^{-1} mod を計算する
ll minv(ll a) { return mpow(a, MOD - 2); }

signed main() {
  //入力の高速化用のコード
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll n, ans = 0;
  vector<string> strs{};
  map<string, int> m{};

  cin >> n;
  FOR(i, 1, n) {
    ans += n / i;
    if (n % i == 0) ans -= 1;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
float PHI = 1.6180339;
//const float  PI_F=3.14159265358979f;
#define MAX 100000 
#define endl "\n"    
//typedef long long float;
#define int long long
//#define float unsigned long long
  


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << setprecision(9);

    string s;
    cin>>s;
    int j=s.length()-1;
    int cnt=0;
    for(int i=0;i<s.length()/2;i++)
    {
        if(s[i]!=s[j])
        {
            ++cnt;
        }
        --j;
    }
    cout<<cnt<<endl;

}



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

class Dice{
	public:
	int face[6];
	
	Dice(){}
	void direction_side(){ rotate(1,2,4,3);}
	void direction_east(){ rotate(0,2,5,3);}
	void direction_north(){ rotate(0,4,5,1);}

	void rotate(int a,int b,int c,int d){
		int tmp = 0;

		tmp = face[a];
		face[a] = face[b];
		face[b] = face[c];
		face[c] = face[d];
		face[d] = tmp;
	}
};
void input(int face[6]){
		for(int i = 0;i < 6;i++){
				cin >> face[i];
		}
}
int check(int check1[6],int check2[6]){
		int num = 0;
		for(int i = 0;i < 6;i++){
				if(check1[i] == check2[i]){
						num++;
				}
		}
	return num;
}

int main(){
	Dice dice1,dice2,dice_reset;
	int t_num = 0,f_num = 0;
	
	input(dice1.face);
	input(dice2.face);
	dice_reset = dice2;
	for(t_num = 0;t_num < 6;t_num++){
			dice2 = dice_reset;
				switch(t_num){
					case 0: break;
					case 1:
							dice2.direction_north();
							break;
					case 2:
							for(int i = 0;i < 3;i++){
									dice2.direction_east();
							}
							break;
					case 3:
							dice2.direction_east();
							break;
					case 4:
							for(int i = 0;i < 3;i++){
									dice2.direction_north();
							}
							break;
					case 5:
							for(int i = 0;i < 2;i++){
									dice2.direction_north();
							}
							break;
				}
			for(f_num = 0;f_num < 4;f_num++){
					 dice2.direction_side();
					if( check(dice1.face,dice2.face) == 6){
							cout << "Yes" << endl;
							return 0;
					}

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

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

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    
    if((A-B) > 0){
        if((A-B)%2==0){
            cout << "Alice" << endl;
        }
        else{
            cout << "Borys" <<endl;
        }
    }
    else{
        if((B-A)%2==0){
            cout << "Alice" << endl;
        }
        else{
            cout << "Borys" <<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15

/* Debug Begins */ 
# define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(bool f) { if(f) return "True"; else return "False";}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
int Nerr;
template<typename A> string to_string(A *p) {return to_string(vector<A>(p, p + Nerr));}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
/***************************************************************/



signed main()
{
    ios_base::sync_with_stdio(0);
    int TESTS=1;
    // cin>>TESTS;
    while(TESTS--)
    {   
        int n;
        cin >> n;
        vector<int> a(n);
        rep(i,0,n) cin >> a[i];
        sort(all(a));
        int ans = 0;
        int cnt = 1;
        ans = a.back();
        int i = n-2;
        int f = 0;
        while(cnt < n - 1){
            ans += a[i];
            f++;
            cnt++;
            if(f == 2){
                f = 0;
                i--;
            } 
            // trace(ans);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 4844