akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
 string s;
    cin >> s;
    
    long long bcount =0;
    int wcount = 0;
    int bmemo = 0;
    int wmemo = 0;
    
    // 先頭のWは寄与しないので削除しておく
    for(int i = 0;i<s.size();i++) {
        if(s.at(i) == 'W') {
         wmemo++;
        }
     if(s.at(i) == 'B') {
      break;
     }
    }
    
    //末尾のＢは寄与しないので削除しておく
    for(int i = s.size()-1; i >= 0; i--) {
     if(s.at(i) == 'B') {
      bmemo++;
     }
        if(s.at(i) == 'W'){
            break;
        }
    }
  
    //削除
    s.erase(s.size()-bmemo,bmemo);
    s.erase(0,wmemo);
    
    
    for(int i = 0; i < s.size();i++) {
     if(s.at(i) == 'B'){
      bcount++;
     }
    }
   
    //使わなかった
    for(int i = 0;i <s.size(); i++) {
     if(s.at(i) == 'W'){
      wcount++;
     }
    }
    
    long long count = 0;
   
    for(int i = s.size() -1; i >=0;i--) {
     if(s.at(i) == 'B') {
      count += s.size()-i-1;
     }
    }
    
    count -= (1+bcount-1)*(bcount-1)/2;
    cout << count;
}

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int n, m; cin >> n >> m;
    string s; cin >> s;
    
    vector<int> v;
    for (int i = n - 1; i >= 0; i--) {
        int cnt = 1;
        while (s[i] == '1') i--, cnt++;
        v.push_back(cnt);
    }

    vector<int> ans;
    int num = 0;
    for (auto &e: v) {
        if (e > m) {
            cout << -1 << endl;
            return 0;
        }

        if (num + e > m) {
            ans.push_back(num);
            num = e;
        } else {
            num += e;
        }
    }
    ans.push_back(num);
    for (int i = (int)ans.size() - 1; i >= 0; i--) {
        cout << ans[i] << " \n"[i == 0];
    }
    return 0;
}


Measured memory_bytes: 1480
/*
 * B.cpp
 *
 *  Created on: 2020/07/11
 *      Author: 17k1028
 */



#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#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--)

int main(){
	int N;
	cin >> N;
	int a[N];
	REP(i,N){
		cin >> a[i];
	}
	int count=0;
	REP(i,N){
		if(a[i]%2==1){
			count++;
		}
		i++;
	}
	cout << count << endl;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int a,b; cin >>a>>b;
    
    int ans = (b-a - 1) * (b-a) / 2 - a;

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
 
using namespace std;
//using namespace __gnu_pbds;
//typedef tree< pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>
//ordered_set;
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
#define X first
#define Y second
#define int long long int 
const int N = (int)1e6 + 10;
const int MOD = (int) 1e9 + 7;

int id(char s){
    if(s == 'R') return 0;
    if(s == 'G') return 1;
    if(s == 'B') return 2;
    return 0;
}


void solve(){
    int n; cin >> n;
    string s; cin >> s;
    vector<int> v[3];
    for(int i = 0; i < (int)s.size(); ++i){
        v[id(s[i])].push_back(i);
    }
    int ans = 0;
    vector<int> perm(3);
    perm[0] = 0, perm[1] = 1, perm[2] = 2;
    do{
        int fr = perm[0];
        int sc = perm[1];
        int th = perm[2];
        for(int i = 0; i < v[fr].size(); ++i){
            int id1 = v[fr][i];
            if(v[sc].empty()) continue;
            if(v[sc].back() <= id1) continue;
            auto id22 = upper_bound(v[sc].begin(), v[sc].end(), id1) - v[sc].begin();
            for(int j = id22; j < v[sc].size(); ++j){
                int id2 = v[sc][j];
                if(v[th].empty()) continue;
                if(v[th].back() <= id2) continue;
                int diff = id2 - id1;
                int want = id2 + diff;
                auto id33 = upper_bound(v[th].begin(), v[th].end(), id2);
                int start = id33 - v[th].begin();
                ans += v[th].size() - start;
                //check if index id2 + diff exists
                auto idcheck = lower_bound(v[th].begin(), v[th].end(), want);
                if(*idcheck == want)
                    ans--;
            } 
        }
    } while ( next_permutation(perm.begin(), perm.end()) );
    cout << ans << '\n';
    
}

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
    //int t; cin >> t;
    //while(t--)
        solve();
    return 0;
}
/*
Sample inp
*/

Measured memory_bytes: 3740
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <algorithm>
#include <unordered_map>
#include <iomanip>
#include <time.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(){
  int k, s;
  int sum=0;
  cin >> k >> s;

  rep(i, k + 1){
    rep(j, k + 1){
      if(i + j <= s && i + j + k >= s){
        sum++;
      }
    }
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  string s; cin >> s;
  int n = s.size();
  vector<vector<lint>> dp(n + 1, vector<lint> (3, -INF));
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      if (dp[i][j] == -INF) continue;
      // j == 0 なら，どんな分割でもあり
      if (j == 0) {
        dp[i + 1][1] = max(dp[i + 1][1], dp[i][j] + 1);
        if (i + 2 <= n) dp[i + 2][2] = max(dp[i + 2][2], dp[i][j] + 1);
        continue;
      }

      for (int nj = 1; nj <= 2; nj++) {
        if (i + nj <= n) {
          if (s.substr(i - j, j) == s.substr(i, nj)) continue;

          dp[i + nj][nj] = max(dp[i + nj][nj], dp[i][j] + 1);
        }
      }
    }
  }

  cout << max(dp[n][1], dp[n][2]) << endl;
  
  return 0;
}


Measured memory_bytes: 11396
#include <iostream>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <unordered_map>
#include <random>
#include <queue>
#include <iomanip>

#define MOD 1000000007
#define LLMAX 9223372036854775807
#define LLMIN (-9223372036854775808)

using namespace std;

int main(){
    string s;
    cin >> s;
    unordered_map<char,int> m;
    for(int i = 0;i < 4;++i){
        ++m[s[i]];
    }
    if(m.size() != 2){
        cout << "No" << endl;
        return 0;
    }
    if((*(++m.begin())).second == 2){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}




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

int main()
{
  int N,K;
  cin >> N>>K;
  int d,tmp;
  vector <int>sunuke(N,0);
  int ans=0;
  for(int i=0;i<K;i++){
    cin >>d;
    for(int j=0;j<d;j++){
      cin >>tmp;
      sunuke.at(tmp-1)++;
    }
  }
  for(int i=0;i<N;i++){
    if(sunuke.at(i)==0)
      ans++;
  }
  cout << ans<<endl;
}

Measured memory_bytes: 3628
/* */

#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;

#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
#else
	#define errp(...)
#endif
#define dbg(x) errp("%s = %s\n", #x, to_string(x).data())
#define dbg_al(s, x) for(auto e:x)s+=to_string(e)+" "
#define dbg_rt(x) string s="[ ";dbg_al(s,x);s+="]";return s;
#define dbg_fd1 template<typename T>string to_string
#define dbg_fd2 template<typename U, typename V>string to_string
#define dbg_d1(c) dbg_fd1(c<T>);
#define dbg_d2(c) dbg_fd2(c<U, V>);
#define dbg_f1(c) dbg_fd1(c<T> v){dbg_rt(v);}
#define dbg_f2(c) dbg_fd2(c<U, V> v){dbg_rt(v);}
string to_string (char s) { return "\'"+string(1, s)+"\'"; }
string to_string (string s) { return "\"" + s + "\""; }
dbg_d1(vector) dbg_d1(set) dbg_d2(map)
dbg_fd2(pair<U, V> p) { return "("+to_string(p.first)+", "+to_string(p.second)+")"; }
dbg_f1(vector) dbg_f1(set) dbg_f2(map)
/* ==================== */ 
const int M = 10010;
const int N = 110;
int f[N][M], n, s[N];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &s[i]);
	memset(f, 0, sizeof f);
	f[0][0] = f[0][s[0]] = true;
	for (int i = 0; i < n - 1; i++) {
		for (int j = 0; j < M; j++) if (f[i][j]) {
			f[i + 1][j] = 1;
			f[i + 1][j + s[i + 1]] = 1;
		}
	}
	int mx = 0;
	for (int i = 0; i < M; i++) if (f[n - 1][i] && i % 10)
		mx = i;
	printf("%d\n", mx);
}


Measured memory_bytes: 4608
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] road = new int[n];

		for(int i = 0 ; i < n ; i++) {
			road[i] = 0;
		}

		for(int i = 0 ; i < m ; i++) {
			int from = sc.nextInt();
			int to = sc.nextInt();
			road[from - 1] += 1;
			road[to - 1] += 1;
		}

		for(int i = 0 ; i < n ; i++) {
			System.out.println(road[i]);
		}
	}
}


Measured memory_bytes: 23508
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> ivec;
const ll N = 1e9+7;

int main(){
    int n; cin >> n;
    int damu[n];
    rep(i,n) cin >> damu[i];
    ll sum = 0;
    rep(i,n)sum += damu[i];
    // sum /= 2;
    int n2 = n/2;
    ll sum2 = 0;
    rep(i,n2){
        sum2 += damu[2*i]*2;
    }
    int yama[n];
    yama[n-1] = sum - sum2;
    yama[0] = damu[n-1]*2-yama[n-1];
    rep(i,n-1){
        if(i == 0)continue;
        yama[i] = damu[i-1]*2-yama[i-1];
    }
    // for(int i = n-2;i >= 0;i--){
    //     yama[i] = damu[i]
    // }

    rep(i,n)cout << yama[i] << " ";
    cout << endl;
    return 0; 

}

Measured memory_bytes: 2048
n, k = map(int, input().split())
a = list(map(int, input().split()))

d = {}
for i in range(1, n + 1):
    d[i] = a[i - 1]

did = set()
route = [1]

now = 1
for i in range(k):
    now = d[now]
    route.append(now)
    if now in did:
        break
    did.add(now)

if k < 10 ** 6:
    now = 1
    for i in range(k):
        now = d[now]

    print(now)

else:
    for i in range(len(route)):
        if route[i] == route[-1]:
            roop = route[i:-1]
            break

    print(roop[(k - i) % len(roop)])

Measured memory_bytes: 49220
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  priority_queue<int> que;
  rep(i, N) {
    cin >> H[i];
    que.push(H[i]);
  }
  for (int i = 0; i < K; i++) {
    if (que.empty()) break;
    que.pop();
  }
  ll ans = 0;
  while (!que.empty()) {
    ans += que.top(); que.pop();
  }
  cout << ans << '\n';
  return 0;
}

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<ld> Point;
typedef vector<vector<int>> Graph;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<vector<P>> testify;
    rep(i, n) {
        cin >> a[i];
        // debug(a[i]);
        vector<P> temp;
        rep(j, a[i]) {
            int c, b;
            cin >> c >> b;
            c--;
            temp.push_back(P(c, b));
        }
        testify.push_back(temp);
    }
    int ma = 0;
    for (int bit = 0; bit < (1 << n); bit++) {
        bool ok = true;
        int cnt = 0;
        rep(i, n) {
            if (bit & (1 << i)) {
                // do something
                cnt++;
                rep(j, a[i]) {
                    int to = testify[i][j].first;
                    int honest = testify[i][j].second;
                    // bool x = bit & (1 << to)
                    // debug(x);
                    // debug(to);
                    // if ((bit & (1 << to)) != honest) {
                    if (((bit >> to) & 1) ^ honest) {
                        ok = false;
                        goto check;
                    }
                }
            }
        }
    check:
        if (ok) ma = max(ma, cnt);
    }
    out(ma);
    return 0;
}


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

int main()
{
    int ary[101] = {0};
    int a,b,c;
    int ans=0;
    cin>>a>>b>>c;
    ary[a]+=1;
    ary[b]+=1;
    ary[c]+=1;
    for(int i=1;i<101;i++)
        if(ary[i])
            ans+=1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
V = sum([i * (N - i + 1) for i in range(1, N + 1)])
E = 0
for i in range(N - 1):
    a, b = map(int, input().split())
    a, b = min(a, b), max(a, b)
    E += a * (N - b + 1)
print(V - E)


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

using namespace std;

int main() {
    int N, K;
    string S;
    cin >> N >> K >> S;

    vector<int> Nums;
    int now = 1;
    int cnt = 0;
    for(int i = 0; i < N; i++) {
        if(S[i] == (char)('0' + now)) cnt++;
        else {
            Nums.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    if(cnt != 0) Nums.push_back(cnt);
    if(Nums.size() % 2 == 0) Nums.push_back(0);

    vector<int> sum(Nums.size()+1);
    for(int i = 0; i < Nums.size(); i++) {
        sum[i+1] = sum[i] + Nums[i];
    }

    int Add = 2 * K + 1;
    int ans = 0;
    for(int i = 0; i < Nums.size(); i += 2) {
        int left = i;
        int right = min(i+Add, (int)Nums.size());
        int tmp = sum[right] - sum[left];

        ans = max(tmp, ans);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1272
import collections

N = int(input())
AList = list(map(int, input().split()))
Q = int(input())

c = collections.Counter(AList)

result = sum(AList)
resultList = []
for i in range(Q):
    B, C = map(int, input().split())
    tmp = C - B
    
    result += tmp * c[B]
    
    c[C] += c[B]
    c[B] = 0
    
    resultList.append(result)

for i in range(len(resultList)):
    print(resultList[i])

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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define dbg(var) {std::cout << #var << "  = " << var << nl;}
#define vi vector<int>
typedef long long ll;

using namespace std;


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0); 

	string s;
	cin >> s;
	
	int k;
	cin >> k;
	
	set<string> v;
	
	rep(i , s.size()){
		string tmp = "";
		tmp += s[i];
		v.insert(tmp);
		repi(j , 6){
			if(i + j >= s.size()) break;
			tmp += s[i + j];
			v.insert(tmp);
		}	
	}
	
	vector<string> vs;
	for(auto e : v) vs.pb(e);
	SORT(vs);
	cout << vs[k - 1];

	return 0;
}

Measured memory_bytes: 2944
#include <stdio.h>
 
int main(){
  char c[1301];
  int i=0,j;
  while(1){
    scanf("%c",&c[i]);
    if(c[i]=='\n'){
      break;
    }
    i++;
  }
  for(j=0; j<i; j++){
    if(c[j]>='A'&&c[j]<='Z')c[j]+=32;
    else if(c[j]>='a'&&c[j]<='z')c[j]-=32;
    printf("%c",c[j]);
    if(j==i-1)printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2132
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pi;
 
 
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
 
#define rep(i,a) for(int i=0;i<a;i++)
#define repn(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)

#define endl '\n'
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
 
const int MOD = 1000000007;
const ll INF = 1e18;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	ll k,n; cin>>k>>n;
	vector<long long> a(n); 
	for(int i=0; i<n; i++) cin>>a[i];
	ll x= abs(k-a[n-1]) + abs(a[0] -0);
	//cout<<x<<endl;
	for(int i=1; i<n; i++)
	{
		x = max(x, a[i]- a[i-1]);
		//cout<<x<<endl;
	}
	
	cout<<k-x;
	
	return 0;
	
}


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

signed main(void)
{
	string s, t, ans;

	cin >> s >> t;
	reverse(s.begin(), s.end());
	reverse(t.begin(), t.end());
	rep(i, s.size() - t.size() + 1)
	{
		bool ok = true;
		rep(j, t.size())
		{
			if (s[i + j] != '?'&& s[i + j] != t[j])
				ok = false;
		}
		if (ok)
		{
			rep(j, i)
			{
				if (s[j] == '?')
					ans += 'a';
				else
					ans += s[j];
			}
			ans += t;
			FOR (j, ans.size(), s.size())
			{
				if (s[j] == '?')
					ans += 'a';
				else
					ans += s[j];
			}
			reverse(ans.begin(), ans.end());
			cout << ans << endl;
			return 0;
		}
	}
	cout << "UNRESTORABLE" << endl;
	return 0;
}


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

int main() {
	string s;
	long long k;
	cin >> s >> k;
	for (int i = 0; i < s.size(); i++) {
		int tg = ('z' + 1) - s[i];
		if (s[i] == 'a')
			continue;
		if (tg <= k)
			k -= tg, s[i] = 'a';
	}
	if (k > 0) {
		long long tmp = k + (s[s.size() - 1] - 'a');
		tmp %= 26;
		s[s.size() - 1] = 'a' + tmp;
		}
	cout << s << endl;
	return 0;
}





Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

template <typename Ring>
vector<Ring> fzt(const vector<Ring> &a, bool superset, const Ring UNITY = 0, function<Ring(Ring, Ring)> fn = [](Ring a, Ring b) { return a + b; }) {
  int n = 1 << (32 - __builtin_clz(static_cast<int>(a.size()) - 1));
  vector<Ring> res(a);
  while (res.size() < n) res.emplace_back(UNITY);
  for (int i = 1; i < n; i <<= 1) REP(j, n) {
    if ((j & i) == 0) {
      if (superset) {
        res[j] = fn(res[j], res[j | i]);
      } else {
        res[j | i] = fn(res[j | i], res[j]);
      }
    }
  }
  return res;
}

int main() {
  int n; cin >> n;
  using P = pair<int, int>;
  vector<P> a(1 << n, {0, 0}); REP(i, 1 << n) cin >> a[i].first;
  function<P(P, P)> fn = [](P a, P b) {
    vector<int> tmp{a.first, a.second, b.first, b.second};
    sort(ALL(tmp), greater<int>());
    return make_pair(tmp[0], tmp[1]);
  };
  vector<P> f = fzt(a, false, {0, 0}, fn);
  vector<int> ans(1 << n);
  REP(i, 1 << n) ans[i] = f[i].first + f[i].second;
  FOR(i, 1, 1 << n) {
    chmax(ans[i], ans[i - 1]);
    cout << ans[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 8192
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

t = Array.new(n, -1)
now = 0
cnt = 0
check = -1
while true
  if t[now] != -1
    check = now
    break
  end
  t[now] = cnt
  now = a[now] - 1
  cnt += 1
end

if k - t[check] <= 0
  now = 0
  k.times do
    now = a[now] - 1
  end

  puts now + 1
else
  now = check
  y = (k - t[check]) % (cnt - t[check])
  y.times do
    now = a[now] - 1
  end

  puts now + 1
end

Measured memory_bytes: 28964
#include <bits/stdc++.h>
#define MOD (long long)(1E9+7)
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
  	vector<int> l(m);
  	vector<int> r(m);
  	rep(i, m)
      	cin >> l[i] >> r[i];
  	cout << max(0, *min_element(r.begin(), r.end()) - *max_element(l.begin(), l.end()) + 1) << endl;
}


Measured memory_bytes: 3988
#include <iostream>

using namespace std;

int prime(int n)
{
	if(n < 2){
		return 0;
	} else if(n == 2){
		return 1;
	}
	
	if(n % 2 == 0){
		return 0;
	}
	
	for(int i = 3; i*i <= n; i+= 2){
		if(n % i == 0){
			return 0;
		}
	}
	
	return 1;
}

int main(int argc, char **argv)
{
	int n, s, t;
	
	while(cin >> n){
		for(int i = n-1; i >= 2; i--){
			if(prime(i) == 1){
				s = i;
				break;
			}
		}
		for(int i = n+1; i <= 60000; i++){
			if(prime(i) == 1){
				t = i;
				break;
			}
		}
		
		cout << s << " " << t << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
N,M = map(int,input().split())
mod = 1000000007

dp = [0]*(N+1)
dp[0] = 1
A = []
for _ in range(M):
    k = int(input())
    A.append(k)
A = sorted(A,reverse = True)

if len(A)>0:
    a = A.pop()
else: a = -1
        
if a == 1:
    dp[1] = 0
    if len(A)>0:
        a = A.pop()
    if a == 2:
        dp[2] == 0
else:
    dp[1] = 1
    
for i in range(2,N+1):
    if i == a:
        if len(A)>0:
            a = A.pop()
        #continue
    else:
        #if dp[i-1] != 0 and dp[i-2] != 0:
        #    dp[i] = (dp[i-1] + dp[i-2])%mod
        dp[i] = (dp[i-1] + dp[i-2])%mod
        
        #elif dp[i-1] != 0:
        #    dp[i] = dp[i-1]%mod
        #elif dp[i-2] != 0:
        #    dp[i] = dp[i-2]%mod
        #else:
        #    dp[i] = 0
        
print(dp[-1])

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  for(int i=0; i<s.length(); i++){
    int x = s[i] - 'A';
    x = (n+x)%26;
    cout << char('A' + x);
  }
}
    
    

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<functional>
#include<bits/stdc++.h>
using namespace std;

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    double x;
    cin>>x;
    x?cout<<0<<endl:cout<<1<<endl;

    return 0;
}


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

int N;
vector<int> V;
int main(void){
    // Your code here!
    cin >> N;
    V.resize(N);
    for(int i = 0; i < N; i++) cin >> V[i];
    sort(V.begin(), V.end());
    
    int ans = 0;
    for(int i = 0; i < N-1; i++){
        for(int j = i+1; j < N; j++){
            auto itr = lower_bound(V.begin(), V.end(), V[i] + V[j]);
            int num = itr - V.begin();
            ans += (num - j - 1);
            
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

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

    for (int i = x - k + 1; i < x + k; ++i) {
        if (i == x - k + 1) printf("%d", i);
        else printf(" %d", i);
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 256
import bisect

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
#print(a,b,c)
x=0
for i in b:
    j=bisect.bisect_left(a,i)
    k=bisect.bisect_right(c,i)
    #print(j,k)
    x+=j*(n-k)
print(x)

Measured memory_bytes: 23360
#include<stdio.h>
#include<math.h>
#define INF 1000000000
void merge(int A[],int left,int mid, int right);
void mergesort(int A[],int left,int right);
void list(int A[]);
//int a[500001];

int cnt=0;
int n;
int main()
{
  int i,j;
  scanf("%d",&n);
 
  int a[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }


  
  mergesort(a,0,n);
  list(a);
  printf("%d\n",cnt);
  return 0;
}
void merge(int A[n],int left,int mid, int right){
  int n1,n2;
  n1=mid-left;
  n2=right-mid;
  int L[n1],R[n2],i,j,k;
  //printf("a\n");
  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  //printf("b\n");
  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  L[n1]=INF;
  R[n2]=INF;
  i=0;
  j=0;
  //printf("c\n");
  for(k=left;k<=right-1;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
       cnt++;
    }else{
      A[k]=R[j];
      j++;
       cnt++;
    }
  }
}
void mergesort(int A[n],int left,int right){
  //printf("test %d %d\n" ,left,right);
  int mid,i;
  // list(A);
  if(left+1<right){
    //printf("%d %d\n",left,right);
    mid=(left+right)/2;
    mergesort(A,left,mid);
    mergesort(A,mid,right);
    // printf("A\n");
    merge(A,left,mid,right);
  }//else
    //printf("!!\n");
}
void list(int A[n]){
  int i;
  //printf("segu\n");
  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i!=n-1)printf(" ");
  }
  printf("\n");
}



Measured memory_bytes: 5600
//به نامش
//how we code is who we are :))
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
const ll MAXN = 2e6 + 10, inf = 1e18, mod = 1e9 + 7;

struct pair_hash {
	template <class T1, class T2>
		std::size_t operator () (const std::pair<T1,T2> &p) const {
			auto h1 = std::hash<T1>{}(p.first);
			auto h2 = std::hash<T2>{}(p.second);

			return h1 ^ h2;  
		}
};

ll pw(ll te, ll tee) {
	if (tee == 0)	return 1;
	ll res = pw(te, tee / 2);
	return (tee % 2 ? te * res * res : res * res);
}


ll a, b, c;
void Read_input() {
	cin >> a >> b >> c;
}

void Solve() {
	cout << min(b / a, c);
}


int main() {

	ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0);
	//freopen("input.txt", "r", stdin),	freopen("output.txt", "w", stdout);

	Read_input(),	Solve();
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main 
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		String in = scanner.next();
		String out = "";
		
		for(int i=in.length(); i>0; i--)
		{
			out += in.substring(i-1, i);
		}
		System.out.println(out);
	}
}

Measured memory_bytes: 26040
#include<stdio.h>

int main(void){
        char x[1001];

        while(1){
                scanf("%s", x);

                int s = 0, i = 0;
                if(x[0] == '0')
                        break;
                while(x[i])
                        s += (x[i++] - '0');
                printf("%d\n", s);

        }

        return 0;
}

Measured memory_bytes: 536
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int num, i, ans = 0;
	cin >> num;
	string e;
	vector<string> s(num);
	vector<int> t(num);
	rep(i, num)
		cin >> s[i] >> t[i];
	cin >> e;
	rep(i, num) {
		if (s[i] == e) {
			i++;
			break;
		}
	}
	for (; i < num; i++) {
		ans += t[i];
	}
	cout << ans << "\n";
	return 0;
}

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

int main()
{
	string s;
	string t;
	cin>>s>>t;
	for(int i=0;i<s.size();i++)
		if(s[i]!=t[i])
			{cout<<"No"<<endl;return 0;}
	cout<<"Yes"<<endl; 
	return 0;
}


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

int d[51][51];
int n,m;
vector<bool> vis(51,true);

void dfs(int node){
    if(!vis[node]) return ;
    vis[node]=false;
    for(int i=1;i<=n;i++){
        if(d[node][i]==1){
            dfs(i);
        }
    }
}

int main(){

    cin >> n >> m;

    int a,b;

    for(int i=0;i<m;i++){
        cin >> a >> b;
        d[a][b]=1;
        d[b][a]=1;
    }
    bool f=false;
    int ans =0;

    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(d[i][j]==1){
                f=false;
                d[i][j]=0;
                d[j][i]=0;
                dfs(1);
                d[i][j]=1;
                d[j][i]=1;
                for(int k=1;k<=n;k++){
                    if(vis[k]){
                        f=true;
                    }else
                    vis[k]=true;
                }
                if(f){
                    ans++;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int ab[3][3+1];
    int min = 101;
    //3行読み込み、値をabに代入する
    for(int i = 0;i<3;i++){
        scanf("%d %d %d",&ab[i][0],&ab[i][1],&ab[i][2]);
        //一番左の列にある数値のうち、最小値を代入
        if(ab[i][0] < min){
            min = ab[i][0];
        }
    }
    //a1~a3、b1~b3を入れる箱を用意する
    int a[3];
    int b[3];
    //リセット用のフラグを用意する
    int flag = 0;
    //a1b1の値を0~minであると仮定し、他の値を代入して成り立つか確認する
    for(int i = 0;i<=min;i++){
        //配列a,bを初期化する
        memset(&a,0,sizeof(a));
        memset(&b,0,sizeof(b));
        //a[0]に仮定した値を代入し、他の値を求める
        a[0] = i;
        b[0] = ab[0][0] - i;
        b[1] = ab[0][1] - i;
        b[2] = ab[0][2] - i;
        a[1] = ab[1][0] - b[0];
        a[2] = ab[2][0] - b[0];

        // for(int j = 0;j<3;j++){
        //     if(b[j] < 0){
        //         flag++;
        //         break;
        //     }
        // }
        // if(flag != 0){
        //     flag = 0;
        //     continue;
        // }
        for(int j = 0;j<3;j++){
            if(flag != 0){
                break;
            }
            for(int k = 0;k<3;k++){
                if(ab[j][k] != a[j] + b[k]){
                    flag++;
                    break;
                }
            }
        }
        if(flag == 0){
            printf("Yes\n");
            return 0;
        }
        flag = 0;
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 128
n=int(input())
l=list(map(int,input().split()))
b=[]
for i in range(n):
  for j in range(n-i)[::-1]:
    if l[j]==j+1:
      del l[j]
      b.append(j+1)
      break
  else:
    print(-1)
    exit()
print(*b[::-1],sep="\n")

Measured memory_bytes: 3064
#include <iostream>
#include <string>

using namespace std;

int main(void){
    string s;
    for(int i = 0; i < 3; i++)
        cin >> s[i];

    for(int i = 0; i < 3; i++){
        if(s[i] == '1')
           cout << '9';
        else if(s[i] == '9')
            cout << '1'; 
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long t,num;
void dfs(long long x,long long q,long long w,long long e)
{
	if(x<=t&&q&&w&&e)
	{
		num++;
	} 
	else if(x>t) return;
	dfs(x*10+3,q+1,w,e);
	dfs(x*10+5,q,w+1,e);
	dfs(x*10+7,q,w,e+1);
}
int main()
{
	cin>>t;
	dfs(0,0,0,0);
	cout<<num<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#define ll long long
#define out(a) printf("%d",a)
using namespace std;
int n,a;
int read()
{
	int s=0,t=1; char c;
	while (c<'0'||c>'9'){if (c=='-') t=-1;c=getchar();}
	while (c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*t;
}
int main()
{
	n=read(); a=read();
	out(n*n-a);
}

Measured memory_bytes: 256
#include <stdio.h>
main(){
  int a,b,c;
  a=1;
  b=1;
  while(a<10){
    while(b<10){
      c=a*b;
      printf("%dx%d=%d\n",a,b,c);
      b++;
    }
    b=1;
    a++;
  }
return 0;
}

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

class WithIndex<T>
{
    public T Value;
    public int Index;
    public WithIndex(T value, int index)
    {
        this.Value = value;
        this.Index = index;
    }
}

static class Template
{
    public static int LineToInt()
    {
        return int.Parse(Console.ReadLine());
    }

    public static string[] LineToStrings()
    {
        return Console.ReadLine().Split();
    }

    public static int[] LineToInts()
    {
        return LineToStrings()
            .Select(s => int.Parse(s))
            .ToArray();
    }


    public static int[,] LinesToIntTable(int lineCount, int columnCount)
    {
        var value = new int[lineCount, columnCount];
        foreach (var y in Enumerable.Range(0, lineCount))
        {
            var ints = LineToInts();
            foreach (var x in Enumerable.Range(0, columnCount))
            {
                value[y, x] = ints[x];
            }
        }
        return value;
    }

    public static IEnumerable<WithIndex<T>> WithIndex<T>(this IEnumerable<T> sequence)
    {
        int index = 0;
        foreach (var item in sequence)
        {
            yield return new WithIndex<T>(item, index);
            index++;
        }
    }

    static int digit(int n)
    {
        return (n == 0) ? 1 : ((int)Math.Log10(n) + 1);
    }

    static void Main(string[] args)
    {
        var n = LineToInt();
        int count = 0;
        for (int i = 1; i <= n; i++)
        {
            if (digit(i) % 2 == 1) count++;
        }
        Console.WriteLine(count);

    }
}



Measured memory_bytes: 11092
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = a/3600;
		a %= 3600;
		int c = a/60;
		a %= 60;
		System.out.println(b+":"+c+":"+a);
	}
}

Measured memory_bytes: 26260
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */
namespace utils{

    class Repeater{
        int st;
        int ed;
        int d;
    public:
        class rep_iterator{
            int i; int d;
        public:
            rep_iterator(int x, int pd) :i(x), d(pd) {}

            int& operator*(){ return i; }
            bool operator==(const rep_iterator& k) const { return i == k.i; }
            bool operator!=(const rep_iterator& k) const { return i != k.i; }
            rep_iterator& operator++(){ i+=d; return *this; }
        };

        Repeater(int N) :st(0), ed(N), d(1) {}
        Repeater(int b, int e) :st(b), ed(e), d(1) {if(st > ed){ st--; ed--; d = -1; } }

        rep_iterator begin() const{ return rep_iterator(st, d); }
        rep_iterator end() const{ return rep_iterator(ed, d); }

    };

    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
};
using namespace utils;


void sub_main(istream &cin) {
    ll A, B, T;
    cin >> A >> B >> T;
    if(!cin) return;
    ll ans = 0;
    ll time = A;
    while(time <= T){
        time += A;
        ans += B;
    }
    cout << ans << endl;

}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    cerr << "DEBUG MODE" << endl;
    string test_cases = "test_A.txt";
    auto fs = fstream(test_cases, fstream::in);
    int lp = 0;
    while(fs) {
        lp++;
        cout << lp <<  "#------\n";
        sub_main(fs);
    }
    cout << "------#" << endl;
    if(lp <= 1) sub_main(cin);
#else
    sub_main(cin);
#endif
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    int N; cin >> N;
    vector<int> P(N);
    for(int i = 0; i < N; i++)
    {
        cin >> P[i];
    }
    int m = INF, ans = 0;
    for(int i = 0; i < N; i++)
    {
        if(m >= P[i]) ans++;
        m = min(m, P[i]);
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  int n;
  int input;

  cin >> n;
  int all = 1, tmp = 1;
  for(int i = 0; i < n; i++) all *= 3;

  for(int i = 0; i < n; i++){
    cin >> input;
    tmp *= (input%2)? 1 : 2;
  }
  cout << all - tmp << endl;
}


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

public class GFG
{
    static public void Main()
    {
        try
        {
            var n = Console.ReadLine();
            //var input1 = Console.ReadLine().Split(' ');
            //var n = int.Parse(input1[0]);
            //var L = int.Parse(input1[1]);

            //var aar = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();

            UnHappy(n);
        }
        catch (Exception ex)
        {
            Console.Write(ex);
        }
    }

    static void UnHappy(string n)
    {

        var s = n.ToCharArray();
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == 'B')
            {
                if(ans.Length>=1)
                ans.Remove(ans.Length - 1,1);
            }
            else
            {
                ans = ans.Append(s[i]);
            }
        }

        Console.Write(ans);

    }

}

Measured memory_bytes: 11220
import java.util.Scanner;

public class Main {
	private static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		long[] x = new long[100010];
		long[] d = new long[100010];
		for (int i = 1;i <= n;i++) {
			x[i] = sc.nextLong();
			if (i!=1) d[i] = x[i]-x[i-1];
		}
		long ret = 0;
		for (int i = 2;i <= n;i++) {
			long t = d[i]*a;
			if (t<b) {
				ret += t;
			} else {
				ret += b;
			}
		}
		System.out.println(ret);
	}
}


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

int main(void)
{
	unsigned h[10];
	int c = 0;

	for(int i = 0; i < 10; i++)
		cin >> h[i];

	do{
		int i = c;
		c = 10;
		for(int j = 9; j > i; j--) {
			if(h[j] > h[j - 1]) {
				unsigned tmp = h[j];
				h[j] = h[j - 1];
				h[j - 1] = tmp;
				c = j - 1;
			}
		}
	}while(c < 10);

	for(int i = 0; i < 3; i++)
		cout << h[i] << endl;

	return 0;
}

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

using namespace std;

#define ff first
#define ss second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double EPS = 1e-6;
const int MAX_N = 1e5 + 5;

int N, K;
ll h[MAX_N], dp[MAX_N];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> N >> K;
	for (int i = 0; i < N; ++i) {
		cin >> h[i];
	}

	for (int i = 0; i < N; ++i) {
		if (i != 0) dp[i] = 1e18;
		for (int j = 1; j <= K; ++j) {
			if (i - j >= 0) {
				dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
			}
		}
	}

	cout << dp[N - 1] << '\n';

	return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

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

	int64 N;
	cin >> N;
	vector<int64> x(N), y(N);
	vector<int64> ord(N);
	REP(i, N) {
	  cin >> x[i] >> y[i]; x[i]--; y[i]--;
	}
	iota(all(ord), 0);
	sort(all(ord), [&](int64 a, int64 b) {
	  return x[a] < x[b];
	});

	dsu uf(N);
	stack<PLL> st;
	for (auto i: ord) {
	  int ymin = y[i];
	  while (st.size() && st.top().fs < y[i]) {
	    uf.merge(st.top().sc, i);
	    chmin(ymin, st.top().fs);
	    st.pop();
	  }
	  st.emplace(ymin, i);
	}
	REP(i, N) cout << uf.size(i) << endl;
}


Measured memory_bytes: 8768
#include<bits/stdc++.h>
using namespace std;
int MOD = 1000000007;
//g++ -std==c++14
//setprecision(10)
int main(){
    int n;  cin >> n;
    int a[n];
    vector <int> edge;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    int va, cnt = 1;
    for(int i = 0; i < n; i++){
        if(i == 0)  va = a[i];
        else if(va == a[i]){
            cnt++;
            if(cnt % 2 == 0)
                edge.push_back(a[i]);
        }
        else{
            cnt = 1;
            va = a[i];
        }
    }
    if(edge.size() < 2)
        cout << 0 << endl;
    else{
        int b = *(edge.end() - 1), c = *(edge.end() - 2);
        cout << (long long int)b * c << endl;
    }
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int Q = scanner.nextInt();
        String S = scanner.next();
        int l[] = new int[Q];
        int r[] = new int[Q];
        char a[] = new char[N];
        int count[] = new int[N];

        for(int i = 0; i < N; i++){
            a[i] = S.charAt(i);
        }

        for (int i = 0; i < Q; i++) {
            l[i] = scanner.nextInt();
            r[i] = scanner.nextInt();
        }

        int sum[] = new int[N];

        for(int i = 0; i < N - 1; i++){
            if(a[i] == 'A' && a[i + 1] == 'C'){
                count[i + 1] += 1;
            }
        }

        for(int i = 1; i < N; i++){
            sum[i] += count[i] + sum[i - 1];
        }

        for(int i = 0; i < Q; i++){
            int total = sum[r[i] - 1] - sum[l[i] - 1];
            System.out.println(total);
        }
    }
}

Measured memory_bytes: 82008
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	LinkedList<Integer> list=new LinkedList<Integer>();

	void run(){
		for(;;){
			Scanner s=new Scanner(sc.nextLine());
			int count1=0;// 1ÌÂ
			int sum=0;
			for(; s.hasNext();){
				int a=s.nextInt();
				if(a==0){
					return;
				}
				if(a>10){
					sum+=10;
				}else{
					sum+=a;
				}
				if(a==1){
					count1++;
				}
			}
			int ans=0;
			for(int i=0; i<=count1; i++){
				if(sum<=21){
					ans=sum;
				}
				sum+=10;
			}
			println(""+ans);
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 13000
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

const MAX = 1000
const INF = 1000010000

func main() {
	sc.Split(bufio.ScanWords)

	H, W := nextInt(), nextInt()

	c := make([][]int, 10)
	for i := 0; i < 10; i++ {
		c[i] = make([]int, 10)
		for j := 0; j < 10; j++ {
			c[i][j] = nextInt()
		}
	}

	A := make([][]int, H)
	for i := 0; i < H; i++ {
		A[i] = make([]int, W)
		for j := 0; j < W; j++ {
			A[i][j] = nextInt()
		}
	}

	for k := 0; k < 10; k++ {
		for i := 0; i < 10; i++ {
			for j := 0; j < 10; j++ {
				c[i][j] = min(c[i][j], c[i][k]+c[k][j])
			}
		}
	}

	ans := 0
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			if 0 <= A[i][j] {
				ans += c[A[i][j]][1]
			}
		}
	}

	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 1024