akhauriyash/Code-Regression huggingface dataset:
N = int(input())
a = list(map(int, input().split()))
b = [0] * (N + 1)
for i in range(N):
    b[a[i]] = i + 1
l = [i for i in range(N + 2)]
r = [i for i in range(N + 2)]
ans = 0
for i in range(N, 0, -1):
    m = b[i]
    x = l[m]
    y = r[m]
    ans += (m - x + 1) * (y - m + 1) * i
    r[x - 1] = y
    l[y + 1] = x
print(ans)

Measured memory_bytes: 88500
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<string>
#include<string.h>
using namespace std;
int n,m;
bool v[9];
vector<int> e[9];
int dfs(int c,int num){
	if (num == n)return 1;
	int ans = 0;
	int s = e[c].size();
	v[c] = 1;
	for (int i = 0; i < s; i++){
		int cnt = e[c][i];
		if (v[cnt] == 0){
			ans += dfs(cnt, num + 1);
		}
	}
	v[c] = 0;
	return ans;
}

int main(){
	int a, b;
	while (~scanf("%d%d", &n, &m)){
		for (int i = 1; i <= 8; i++){ e[i].clear(); }
		for (int i = 0; i < m; i++){
			scanf("%d%d", &a, &b);
			e[a].push_back(b);
			e[b].push_back(a);
		}
		int ans = 0;
		ans = dfs(1,1);
		printf("%d\n", ans);
	}
	return 0;
}

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

int main()
{
    int x, y;

    cin >> x >> y;

    int res = 4 * x - y;
    if (res >= 0 && res % 2 == 0 && res / 2 <= x)
        puts("Yes");
    else
        puts("No");
}

Measured memory_bytes: 3644
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
static const int inf = 1 << 30;

int main(void) {
  int N;
  cin >> N;
  vector<string> W, tmp;
  REP(i, N) {
    string g;
    cin >> g;
    W.push_back(g);
  }
  copy(W.begin(), W.end(), back_inserter(tmp));
  sort(tmp.begin(), tmp.end());
  tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
  if (W.size() != tmp.size()) {
    cout << "No" << endl;
    return 0;
  }
  string prevword = "################";
  for (string s : W) {
    if (prevword == "################") {
      prevword = s;
      continue;
    }
    if (prevword[prevword.size() - 1] == s[0]) {
      prevword = s;
    } else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
    #pragma comment(linker, "/stack:200000000")
    #pragma GCC optimize("Ofast")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include<bits/stdc++.h>
    #define int long long
    # define mo 1000000007
    using namespace std;
    #define goku ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    signed main(){
        goku
       int n;
       cin>>n;
       string s="",s1="",s2="";
       for(int i=0;i<n;i++)
       {
           int x;
           cin>>x;
           s.push_back('0'+i+1);
           s1.push_back('0'+x);
       }
       for(int i=0;i<n;i++)
       {
           int x;
           cin>>x;
           s2.push_back('0'+x);
       }
      // cout<<s<<" "<<s1<<" "<<s2<<endl;
       int a=-1,b=-1,c=0;
       while(next_permutation(s.begin(), s.end())&&(a==-1||b==-1))
       {

           if(s==s1)
            a=c;
           if(s==s2)
            b=c;
            c++;
       }
       cout<<abs(a-b);
       return 0;
    }


Measured memory_bytes: 256
N,W = map(int,input().split())
ls = []
for i in range(N):
    ls.append(list(map(int,input().split())))

dp = [[0]*(W+1) for i in range(N+1)]
# dp[i][j] はi-1番目までのものから重さj以下になるように選んだ最大値

for i in range(1,N+1):
    w,v = ls[i-1]
    for j in range(1,W+1):
        if j >= w:
            dp[i][j] = max(dp[i-1][j] ,dp[i-1][j-w]+v)
            #ここでj-wを指定してしまっていいのか-> dp[i-1][j-w]>dp[i-1][j-w-1]であるので良い　j-wはそれ以下の最大値になっている
        else:
            dp[i][j] = dp[i-1][j]
print(dp[-1][-1])


Measured memory_bytes: 120172
/**
 * File    : JOI_2010_cheese.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-3-8 21:40:42
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
const int infty = 1000000007;

typedef tuple<int, int> point;

int H, W, N;
string S[1010];
int d[1010][1010];
point P[20];
queue<point> Q[20];

bool valid(int x, int y)
{
  return (0 <= x && x < H && 0 <= y && y < W && S[x][y] != 'X');
}

int main()
{
  cin >> H >> W >> N;
  for (auto i = 0; i < H; i++)
  {
    cin >> S[i];
  }
  for (auto i = 0; i < H; i++)
  {
    for (auto j = 0; j < W; j++)
    {
      if (S[i][j] == 'S')
      {
        P[0] = point(i, j);
      }
      int t = S[i][j] - '0';
      if (1 <= t && t <= 9)
      {
        P[t] = point(i, j);
      }
    }
  }
  int ans = 0;
  for (auto i = 0; i < N; i++)
  {
    fill(&d[0][0], &d[0][0] + 1010 * 1010, infty);
    d[get<0>(P[i])][get<1>(P[i])] = 0;
    Q[i].push(P[i]);
    while (!Q[i].empty())
    {
      point p = Q[i].front();
      Q[i].pop();
      if (p == P[i+1])
      {
        ans += d[get<0>(p)][get<1>(p)];
#if DEBUG == 1
        cerr << "d[" << get<0>(p) << "][" << get<1>(p)
             << "] = " << d[get<0>(p)][get<1>(p)] << endl;
#endif
        break;
      }
      for (auto k = 0; k < 4; k++)
      {
        int nx = get<0>(p) + dx[k];
        int ny = get<1>(p) + dy[k];
        if (valid(nx, ny) && d[nx][ny] == infty)
        {
          d[nx][ny] = d[get<0>(p)][get<1>(p)] + 1;
          Q[i].push(point(nx, ny));
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 7988
#include<bits/stdc++.h>
#define FOR(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define FORN(i,b,a)for(int i=(b);_a=(a);i>=_a;i--)
#define REP(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define re return
#define vi vector<int>
#define pb push_back
#define si set<int>
#define in insert
#define fl float
#define db double
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
int main()
{
	string s;
	cin>>s;
	if(s.size()%2==1)
	{
		cout<<"No\n";
		return 0;
	}
	for(int i=0;i<s.size();i+=2)
	{
		if(s[i]!='h'||s[i+1]!='i')
		{
			cout<<"No\n";
			return 0;
		}
	 } 
	cout<<"Yes\n";
	return 0;
}



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

int main()
{
    ll k,n;
    cin >>k>>n;
    ll A[n];
    REP(i,n) cin >> A[i];

    ll ans =0;

    ans = k-A[n-1]+A[0];

    REP(i,n-1) ans = max(ans,A[i+1]-A[i]);

    cout << k- ans << endl;
}

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

int n,q,qi;
string s;
set<int> st[26];
int main(){
    cin>>n>>s>>q;
    rep(i,n) st[s[i]-'a'].insert(i);
    rep(i,26) st[i].insert(n+10);
    int l,r,ii,pi;
    char ci;
    rep(_,q){
        cin>>qi;
        if(qi==1){
            cin>>ii>>ci;
            --ii;
            pi=s[ii]-'a';
            st[pi].erase(ii);
            st[ci-'a'].insert(ii);
            s[ii]=ci;
        }
        else{
            cin>>l>>r;
            --l,--r;
            int ret=0,dl,dr;
            rep(i,26){
                dl=*st[i].lower_bound(l);
                dr=*st[i].upper_bound(r);
                if(dl!=dr) ++ret;
            }
            cout<<ret<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 24196
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author Silviase
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    Scanner in = new Scanner(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    CDistinctOrNot solver = new CDistinctOrNot();
    solver.solve(1, in, out);
    out.close();
  }

  static class CDistinctOrNot {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
      int n = in.nextInt();
      int[] a = new int[n];
      boolean f = true;
      for (int i = 0; i < n; i++) {
        a[i] = in.nextInt();
      }
      Arrays.sort(a);
      for (int i = 0; i < n - 1; i++) {
        f = f && !(a[i] == a[i + 1]);
      }
      out.println(f ? "YES" : "NO");
    }

  }
}



Measured memory_bytes: 64720
"use strict";
function Main(input) {
    let cin = new Inputer(input);
    let N = cin.getInt(), V = cin.getIntArray(N), C = cin.getIntArray(N);
    let VC = new Array(N);
    for (let n = 0; n < N; n++) {
        VC[n] = V[n] - C[n];
    }
    let ans = VC.reduce((ac, v) => ac + (v > 0 ? v : 0), 0);
    console.log(ans);
}
class Inputer{constructor(t){if(typeof t=='undefined')throw new Error('引数（stdin）を省略できません！');this.cnt=0,this.items=t.split(/\n|\s/)}getInt(){return this.items[this.cnt++]-0}getIntArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getInt();return r}getStr(){return this.items[this.cnt++]}getStrArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getStr();return r}}
if (typeof window == "undefined") Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <stdio.h>
int main(int argc, const char * argv[]) {
    int r, c, i, j, table[101][101] = {0};
    scanf("%d %d",&r,&c);
    
    for( i = 0 ; i < r ; i++ ){
        for( j = 0 ; j < c ; j++ ){
            scanf("%d",&table[i][j]);
            table[r][j] += table[i][j];
            table[i][c] += table[i][j];
            table[r][c] += table[i][j];
        }
    }
    
    for( i = 0 ; i <= r ; i++ ){
        for( j = 0 ; j <= c ; j++ ){
            printf("%d",table[i][j]);
            if( j != c ){
                printf(" ");
            }
        }
        printf("\n");
    }
    
    return 0;
}

Measured memory_bytes: 652
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    ll ans = 0;
    rep(i,(1<<(n-1))){
        ll sum = 0, tmp = s[0] - '0';
        rep(j,n-1){
            if(i>>j & 1){
                sum += tmp;
                tmp = s[j+1] - '0';
            }
            else{
                tmp = tmp * 10 + (s[j+1] - '0');
            }
        }
        sum += tmp;
        ans += sum;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	int getNumToRoman(char s){
		char [] list = {'I','V', 'X', 'L', 'C', 'D', 'M'};
		int [] num = {1,5,10,50,100,500,1000};
		for(int i=0; i < list.length; i++){
			if(list[i] == s){
				return num[i];
			}
		}
		return -1;
	}

	public void doIt(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String str = sc.next();
			int len = str.length();
			int pre = getNumToRoman(str.charAt(0));
			int now;
			int temp=0;
			int sum = 0;
			for(int i=1; i < len; i++){
				now = getNumToRoman(str.charAt(i));
				if(pre > now){
					sum += pre;
					sum += temp;
					temp =0;
				}
				else if(pre < now){
					sum -= pre;
					sum -= temp;
					temp =0;
				}
				else{
					temp += pre;
				}
				pre = now;
			}
			sum += pre + temp;
			System.out.println(sum);
		}


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

	}

}

Measured memory_bytes: 11000
#include <bits/stdc++.h>
#define ld long double
using namespace std;
int n;
ld a[110];
ld ans;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)ans+=1.0/a[i];
	cout<<fixed<<setprecision(15)<<1.0/ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define space " "
#define MOD (long long) 1000000007
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename T> void __f(const char* variable_name, T&& value){cout << variable_name << ": " << value << endl;}
template <typename T1, typename... T2> void __f(const char* names, T1&& arg1, T2&&... args){const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << ": " << arg1 << " |";__f(comma + 1, args...);}

const ll N = 5e5 + 5;
ll *v;
ll n, m;

void solve(){
    cin >> n >> m;
    string s;
    if(n == 1)
        s = "_";
    else if(n == 2)
        s = "__";
    else
        s = "___";
    bool poss = true;
    while(m--){
        ll si, xi;
        cin >> si >> xi;
        if(s[si - 1] == '_')
            s[si - 1] = xi + '0';
        else if(s[si - 1] != xi + '0'){
            poss = false;
        }else{
            continue;
        }
    }
    if(poss){
        if(s[0] == '0' && n > 1){
            cout << -1 << endl;
        }else{
            if(s[0] == '_' && n > 1)
                s[0] = '1';
            for(auto &i : s)
                if(i == '_')
                    i = '0';
            cout << s << endl;
        }
    }
    else
        cout << -1 << endl;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll t = 1;
    // cout << "\n\nBLAH BLAH BLAH\n\n";
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
#define vvll vector<vector<long long>>
#define pll pair<long long, long long>
using namespace std;
using ll = long long;
using ld = long double;

// グローバル変数（入力）
ll n,h;
vll a,b;

void input() { 
  cin >> n >> h;
  a.resize(n);
  b.resize(n);
  rep(i,n){
    cin >> a[i] >> b[i];
  }
}

ll solve() {
  sort(a.begin(),a.end(),greater<ll>());
  sort(b.begin(),b.end(),greater<ll>());
  ll ans=0;
  rep(i,n){
    if (b[i]>a[0]){
      ans++;
      if (h>b[i]){
        h-=b[i];
      } else {
        cout << ans << endl;
        return 0;
      }
    } 
  }
  cout << ans + (ll)ceil((ld)h/a[0]) << endl;
  return 0;
}

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


Measured memory_bytes: 4736
#include <iostream>
#include <stdint.h>
#include <unordered_map>

using namespace std;

int main()
{
  int N, M;
  cin >> N >> M;

  unordered_map<int32_t, unsigned> modA;
  modA[0] = 1;

  int64_t sum = 0;
  for (int64_t n=0; n<N; ++n) {
    int64_t a;
    cin >> a;
    sum += a;
    //sumA.push_back(sum%M);
    int32_t key = sum%M;
    try {
      modA.at(key)++;
    } catch (...) {
      modA[key] = 1;
    }
  }

  int64_t count = 0;
  for (auto kv : modA) {
    int32_t key = kv.first;
    unsigned value = kv.second;
    cerr << kv.first << ":" << kv.second << endl;
    if (value > 1) {
      count += static_cast<int64_t>(value) * (value-1) / 2;
    }
  }

  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 3724
#include<stdio.h>

int main() {
	int a, b, c, d;
	

	scanf("%d %d %d %d", &a, &b, &c, &d);

	if (c - a < 0) {
		if (c - a + (c - a)*-2 < 2*d) {
			printf("Yes\n");
		}
		else {
			printf("No\n");
		}
	}
	else if (c - a == 0) {
		printf("Yes\n");
	}
	else if (c - a > 0 && c - a < 2 * d) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<pair<int, int> > VPII;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define INF 999999999999999997;
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int dxx[8] = { 0,1,1,1,0,-1,-1,-1 };
int dyy[8] = { 1,1,0,-1,-1,-1,0,1 };

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	string s,ans="No";
	cin >> s;
	FOR(i, 0, s.length() - 1) {
		if (s[i] == 'A'&&s[i + 1] == 'C') {
			ans = "Yes";
			break;
		}
	}
	O(ans);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
using namespace std;
//#include <stdio.h>
#define ll long long

int main(void)
{
    ll k, num = 1, seven = 7;
    bool no = false;
    cin >> k;
    while(1) {
        if(k % 2 == 0) {
            no = true; break;
        }
        if(k == 7 || k == 1)
            break;

        num++;
        if(((seven % k) * 10 + 7) % k == 0) {
            break;
        }
        else
            seven = ((seven % k) * 10 + 7) % k;

        if(num >= 10000000) {
            no = true; break;
        }
    }

    if(no)
        cout << -1;
    else
        cout << num;
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

signed main()
{
  int sum = 0;
  REP(i,3) {
    int a; cin >> a; sum += a;
  }

  cout << (sum >= 22 ? "bust" : "win") << endl;

  return 0;
}


Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int to[30], to2[30];
string s, t;

int main(){
    INIT;
    cin >> s >> t;
    REP(i, 26)to[i] = -1, to2[i] = -1;
    REP(i, (int)s.size()){
        if(to2[t[i] - 'a'] == -1){
            to2[t[i] - 'a'] = s[i] - 'a';
        }
        if(to[s[i] - 'a'] == -1){
            to[s[i] - 'a'] = t[i] - 'a';
        }
        if((to2[t[i] - 'a'] != s[i] - 'a') || (to[s[i] - 'a'] != t[i] - 'a')){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 916
<?php
class In {
    private $array = [];
    private $length = 0;
    private $count = 0;

    function __construct()	{
        while (!feof(STDIN)) {
            $str = trim(fgets(STDIN));
            $this->array = array_merge($this->array, explode(' ', $str));
        }
        $this->length = count($this->array);
    }
    
    public function get(int $i){
        $this->array[$i];
    }

    public function next() {
        return $this->array[$this->count++];
    }
    public function hasNext() {
        return $this->count < $this->length;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
    public function nextString() {
        return (string)$this->next();
    }
}

class Out {
    public static function line($str = "") {
        echo $str . PHP_EOL;
    }
}

class Way{
    public $cost;
    public $time;

    function __construct($c, $t)
    {
        $this->cost = $c;
        $this->time = $t;
    }
}

function cmp($a, $b) {
    return ($a->cost > $b->cost);
}

$in = new In();

$n = $in->nextInt();
$limit = $in->nextInt();
$ways = [];

for ($i = 0; $i < $n; ++$i) {
    $temp = new Way($in->nextInt(), $in->nextInt());
    array_push($ways, $temp);
}
usort($ways , "cmp");

$out = "TLE";
for ($i = 0; $i < $n; ++$i) {
    if($ways[$i]->time <= $limit){
        $out = $ways[$i]->cost;
        break;
    }
}

Out::line($out);

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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            List<int> list = new List<int>();

            for (int i = 0; i < n; i++)
            {
                list.Add(int.Parse(Console.ReadLine()));
            }

            for (int j = 0; j < n; j++)
            {
                Console.WriteLine("Case {0}:", j+1);
                int value = list[j];
                for (int k = 0; k < 10; k++)
                {
                    value = (value * value % 1000000) / 100;
                    Console.WriteLine(value);
                }
            }

        }

    }
}

Measured memory_bytes: 5604
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

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

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

    int n, m, a[112345], b[112345];
    V g[112345];

    cin >> n >> m;
    REP(i, n)
    {
        cin >> a[i] >> b[i];
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }

    for (int i = 1; i <= n; i++)
    {
        if (g[i].size() % 2)
        {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

// retun n の約数の集合
vector<ll> divisors(ll n){
      vector<ll> y;
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0) y.push_back(i);
    }
      ll len = y.size();
      REP(i, len){
        if(y[i] == n / y[i]) continue;
        y.push_back(n / y[i]);
    }
    return y;
}

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

    ll a, b, c;
    cin >> a >> b >> c;

    vll y = divisors(c);
    ll res = 0;
    for (auto x : y) {
        if (x >= a && x <= b) res++;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3220
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline-------------------------------------------
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    ans = 0
    for i in range(N):
        if h[i] >= K:
            ans += 1
    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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; }

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    string s; int K;
    cin >> s >> K;

    set<string> ans;
    for(int i = 0; i < s.length(); i++){
        int w = min(K, int(s.length()- i));
        for(int j = 1; j <= w; j++){
            ans.insert(s.substr(i, j));
        }
    }
    
    auto itr = ans.begin();
    for(int i = 0; i < K-1; i++) itr++;
    cout << *itr << endl;
 
    return 0;
}


Measured memory_bytes: 1664
/*
auth - @sportykush
*/

#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
// using namespace __gnu_pbds;

typedef long long int ll;
typedef long double ld;

//#define mp make_pair
#define bug(v)                    cerr<<#v<<" = "<<(v)<<endl;
#define bug2(v1,v2)               cerr<<#v1<<" = "<<(v1)<< ' ' << #v2<<" = "<<(v2)<<endl;
#define ERASE(x)                  x.erase(unique(x.begin(),x.end()),x.end())
#define pb                        emplace_back
#define vii                       vector<int>
#define vll                       vector<ll>
#define vpll                      vector< pair <ll,ll> >
#define pll                       pair <ll,ll>
#define pii                       pair <int,int>
#define pq                        priority_queue< int >
#define khtm                      "\n"
#define F                         first
#define S                         second
#define fr(i,a,n)                 for(i=a;i<n;i++)
#define mem(arr,l)                memset(arr,l,sizeof arr)
#define ALL(x)                    x.begin(), x.end()
#define frr(i,a,n)                for(i=n-1;i>=a;i--)
#define fast                      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define testcase                  ll T; cin>>T; while(T--)


const double pi = 3.14159265359;
const int MAX = 1e6 +2;
const ll inf =  1e18;
const int N = 1010;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
//const ll mod = 998244353;
const ll mod = 1000000007;
inline ll add(ll a,ll b){a+=b;if(a>=mod)a-=mod;return a;}
inline ll mul(ll a,ll b){return (((a+mod)%mod)*(b+mod)%mod)%mod;}
inline ll power(ll a,ll b){ll rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline ll modInverse(ll n, ll p){ return power(n, p-2)%p; }

/*
important builtin functions
__gcd(value1, value2)
__builtin_ffs(x)
  Number of leading zeroes: __builtin_clz(x)
  Number of trailing zeroes : __builtin_ctz(x)
  Number of set bits: __builtin_popcount(x)
*/
 
void stArt()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}
void eNd()
{
	#ifndef ONLINE_JUDGE
  	cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s";
  	#endif
}

//////////////////// start /////////////////////////////////
 

ll i,j,k,l,m,r,n;
//ll a[MAX],b[MAX];


int main()
{
 
stArt();
fast
//cout << setprecision(15) << fixed;

cin >> n;
//(10^n-2)
if(n<2)
	cout << 0;
else
{
	k = power(10,n);
	k = add(power(8,n),k);
	m = power(9,n);
	m = add(power(9,n),m);
	//m = mul(m,6);
	//bug2(k,m)
	m = -m;
	m = (m+mod)%mod;
	k = add(k,m);
	cout << k;
}
  
 eNd();
  return 0;
 
}

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

int main(){
  ll A,B,C,K; cin>>A>>B>>C>>K;
  if(K%2==1){
    cout<<B-A<<endl;
  }else{
    cout<<A-B<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

ll dp[2502][5001];

void solve(long long N, string S){
	ll res = 0;
	ll s[N];
	rep(i,N) s[i] = S[i]-'a'+1;
	repn(i, N/2+1) {
		map<ll, ll> m;
		repn(j, N) {
			if (j+i-2 >= N) break;
			dp[i][j] = (dp[i-1][j]*27+(S[i+j-2]-'a'+1))%90071992547;
			if (res != i) {
				ll n = m[dp[i][j]];
				if (n > 0) {
					if (j > n+i-1) {
						res = i; 
					}
				} else {
					m[dp[i][j]] = j;
				}
			}
		}
		if (res != i) break;
	}
	cout << res << endl;
}

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



Measured memory_bytes: 97536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  ll a;
  string s;
  cin >> a >> s;

  if (a >= 3200)
    cout << s << endl;
  else
    cout << "red" << endl;
}

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


    int main(){
        int n, s;
        cin >> n;
        int a = n / 1000000000;
        int b = (n - a * 100000000) / 100000000;
        int c = (n - a * 1000000000 - b * 100000000) / 10000000;
        int d = (n - a * 1000000000 - b * 100000000 - c * 10000000) / 1000000;
        int e = (n - a * 1000000000 - b * 100000000 - c * 10000000 - d * 1000000) / 100000;
        int f = (n - a * 1000000000 - b * 100000000 - c * 10000000 - d * 1000000 - e * 100000) / 10000;
        int g = (n - a * 1000000000 - b * 100000000 - c * 10000000 - d * 1000000 - e * 100000 - f * 10000) / 1000;
        int h = (n - a * 1000000000 - b * 100000000 - c * 10000000 - d * 1000000 - e * 100000 - f * 10000 - g * 1000) / 100;
        int i = (n - a * 1000000000 - b * 100000000 - c * 10000000 - d * 1000000 - e * 100000 - f * 10000 - g * 1000 - h * 100) / 10;
        int j = n % 10;
        s = a + b + c + d + e + f + g + h + i + j;
            

        if (n%s == 0)cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
    }
   
    


Measured memory_bytes: 256
def main():
    A=[0]*3
    B=[0]*3
    for i in range(3):
        if i==1:
            A[i],B[i] = map(int,input().split())
        elif i==0:
            A[i],B[i] = input().split()
        else:
            A[i]=input()
    
    if A[2]==A[0]:
        A[1]-=1
    else:
        B[1]-=1
    print(A[1],B[1])

    
main()

Measured memory_bytes: 3064
import java.io.*;
public class Main{
    public static void main(String [] args) throws NumberFormatException, IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String[] st=br.readLine().split(" ");
        int a=Integer.parseInt(st[0]);
        int b=Integer.parseInt(st[1]);
        int c=Integer.parseInt(st[2]);
        System.out.println(a<b&&b<c?"Yes":"No");
    }}

Measured memory_bytes: 24360
N,Q=map(int,input().split())
E=[[] for i in range(N)]
for i in range(N-1):
  a,b=map(int,input().split())
  a,b=a-1,b-1
  E[a].append(b)
  E[b].append(a)
  
P=[0]*N
for i in range(Q):
  p,x=map(int,input().split())
  P[p-1]+=x
  
ans=[0]*N
stack=[]
# 点,親,ポイント
stack.append([0,-1,0])
while stack:
  node=stack.pop()
  v=node[0]
  parent=node[1]
  point=node[2]
  point+=P[v]
  ans[v]=point
  children=E[v]
  for child in children:
    if child==parent:
      continue
    stack.append([child,v,point])
    
print(*ans)

Measured memory_bytes: 64300
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;
int h, w;
char c[310][310];
ll ans;
int main()
{
	cin >> h >> w;
	rep(i, h)
	{
		rep(j, w)
		{
			cin >> c[i][j];
		}
	}
	ans=0;
	rep(j, w-1)
	{
		ll dp[310][310]={};
		rep(k, h)
		{
			if(c[k][j]==c[0][j+1])
			{
				dp[k+1][1]=1;
			}
			if(c[0][j]==c[k][j+1])
			{
				dp[1][k+1]=1;
			}
		}
		repp(k, 1, h)
		{
			repp(l, 1, h)
			{
				dp[k+1][l+1]=min(dp[k][l+1], dp[k+1][l]);
				dp[k+1][l+1]+=(dp[k][l]-min(dp[k-1][l], dp[k][l-1]));
				if(c[k][j]==c[l][j+1])
				{
					dp[k+1][l+1]++;
				}
			}
		}
		ans+=dp[h][h];
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<vector<char> > x(3,vector<char>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>x[i][j];
    }
  }
  for(int i=0;i<3;i++){
    cout<<x[i][i];
  }
}

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

 
int main() {
  string s;
  cin >> s;
  int now= 0,ans = 0;
  rep(i,s.size()){
    if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
      now ++;
    }else{
      ans = max(now,ans);
      now = 0;
    }
  }
  ans = max(ans,now);
  cout << ans << endl;
      
  return 0;
}



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

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

    auto GetCoord = [&](int x, int y) {
        if (x != 0 && x != r && y != 0 && y != c) return -1;
        if (y == 0) return x;
        if (x == r) return y + r;
        if (y == c) return r + c + r - x;
        return r + c + r + c - y;
    };

    vector<int> lv(n);
    vector<pair<int, int>> rv;
    set<int> s;
    for (int i = 0; i < n; ++i) {
        int x1, y1, x2, y2;
        scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
        int a = GetCoord(x1, y1);
        int b = GetCoord(x2, y2);
        if (a == -1 || b == -1) continue;
        if (a > b) swap(a, b);
        s.insert(a);
        lv[i] = a;
        rv.emplace_back(b, i);
    }
    sort(rv.begin(), rv.end());
    for (int i = 0; i < rv.size(); ++i) {
        s.erase(lv[rv[i].second]);
        auto it = s.lower_bound(rv[i].first);
        if (it != s.begin() && *prev(it) > lv[rv[i].second]) {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
    return 0;
}


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

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        public void solve(InputReader in, PrintWriter out) {
           long a  = in.nextLong();
           long b = in.nextLong();
           long c = in.nextLong();
           long k = in.nextLong();
            long resultSum = 0;
           if(k > 0){
               if(k > a){
                   resultSum += a;
                   k -= a;
               }
               else{
                   resultSum += k;
                   k = 0;
               }
           }
           if(k > 0){
               k -= (k  > b)? b : k;
           }

           if(k > 0){
            if(k > c){
                resultSum -= c;
                k -= c;
            }
            else{
                resultSum -= k;
                k = 0;
            }
           }
           out.println(resultSum);
        }

        
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong(){
          return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 32764
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>

using std::cin;
using std::cout;

std::string N;

const std::array<int, 3> digits = {3, 5, 7};

char cached[10][2][8];
int cache[10][2][8];

int solve(size_t pos, int sml = 0, int msk = 0)
{
  if (pos == N.size()) return (msk == 7) ? 1 : 0;
  int& res = cache[pos][sml][msk];
  auto& is_cached = cached[pos][sml][msk];
  if (is_cached) return res;
  is_cached = 1;
  res = msk ? 0 : solve(pos+1, 1, 0);
  for (size_t i = 0; i < digits.size(); ++i)
  {
    int v = digits[i];
    int cur = N[pos] - '0';
    if (!sml && v > cur) break;
    res += solve(pos+1, sml || (v < cur), msk | (1<<i));
  }

  return res;
}

int main(int argc, char* argv[])
{
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> N;
  cout << solve(0) << "\n";

  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double EPS = 1e-8;

const int tx[] = {0,1,0,-1};
const int ty[] = {-1,0,1,0};

P equation(const string &str, int pos=0);
P factor(const string &str, int pos = 0);
P term(const string &str, int pos = 0);

P equation(const string &str, int pos){
	P res = factor(str,pos);
	while(str[res.second] == '+' || str[res.second] == '-'){
		P res_ = factor(str,res.second+1);
		if(str[res.second] == '+') res.first += res_.first;
		else res.first -= res_.first;
		res.second = res_.second;
	}
	return res;
}

P factor(const string &str, int pos) {
	P res = term(str, pos);
	while (str[res.second] == '*' || str[res.second] == '/') {
		P res_ = term(str, res.second+1);
		if(str[res.second] == '*') res.first *= res_.first;
		else res.first /= res_.first;
		res.second = res_.second;
	}
	return res;
}

P term(const string &str, int pos) {
	if(str[pos] == '('){
		P res = equation(str,pos+1);
		res.second += 1;
		return res;
	} else {
		int val = 0;
		while(isdigit(str[pos])){
			val = val * 10 + (str[pos++]-'0');
		}
		return P(val,pos);
	}
}


int main(){
	string str;
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		cin>>str;
		P res = equation(str);
		cout << res.first << endl;
	}
}

Measured memory_bytes: 0
def run_length_compress(S):
    res = [[S[0], 1]]
    for c in S[1:]:
        if c == res[-1][0]:
            res[-1][1] += 1
        else:
            res.append([c, 1])
    return res


def solve():
    S = input()
    N = len(S)
    K = int(input())
    T = run_length_compress(S)
    if T[0][1] == N:
        return N * K // 2
    ans = sum(l // 2 for _, l in T) * K
    if T[0][0] == T[-1][0]:
        head_cnt, tail_cnt = T[0][1], T[-1][1]
        tmp = (head_cnt + tail_cnt) // 2 - head_cnt // 2 - tail_cnt // 2
        ans += tmp * (K - 1)
    return ans


print(solve())


Measured memory_bytes: 9148
/*
          , -- 、
        /;;;;;;', 　　　
        i二二二i
      , ' 　    ヽ ???
     i　ﾉﾉﾉﾉﾉﾍ .', 　　
     〉ﾘi' ﾟ ヮﾟﾉﾚく　 WAyon..........
  ○⊂}〈lﾄ--ｲl〉{つ● 　　
      ,ｒ/ー i-ヽヽ 　　　
     ｀｀i_ﾗi_ﾗ
*/

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
const int INF=(int)1e12;
const int mod=(int)1e9+7;
#define all(a) (a).begin(),(a).end()
typedef vector<vector<int>> graph;

#define pb push_back

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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


signed main() {
    int  n;cin >>n;
    vector<int> a(n);
    vector<int> cnt(n+100);
    rep(i,n)cin >>a[i];

    int ans=0;
    for(int i=n-1;i>=0;i--){
        if(a[i]+i<n+100)ans+=cnt[a[i]+i];
        if(i-a[i]>=0)cnt[i-a[i]]++;
    }
    cout <<ans<<endl;
}

















Measured memory_bytes: 6424
N,Q=[int(x) for x in input().split()]
S=list(input())

t=[0]

for i in range(1,N):
  if (S[i-1]=='A')&(S[i]=='C'):
    t.append(t[i-1]+1)
  else:
    t.append(t[i-1])

for i in range(Q):
  r,l = map(int, input().split(" "))
  print(abs(t[r-1]-t[l-1]))

Measured memory_bytes: 6876
n,w=map(int,input().split())
dp=[0]*(w+1)
for i in range(n):
	wt,val=map(int,input().split())
	for j in range(w,wt-1,-1):
		dp[j]=max(dp[j],dp[j-wt]+val)
	# print(dp)
print(dp[w])

Measured memory_bytes: 41580
import itertools
def dist(x,y):
    return ((x[0]-y[0])**2 + (x[1]-y[1])**2)**(1/2)
n = int(input())
def fact(n):
    if n == 1:
        return 1
    else:
        return n*fact(n-1)
data = [list(map(int,input().split()))for i in range(n)]
ans = 0
for v in itertools.permutations(data):
    for i in range(1,n):
        ans += dist(v[i],v[i-1])

print(ans/fact(n))

Measured memory_bytes: 42092
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson,csgraph_from_dense
from scipy.sparse import csr_matrix

h,w=map(int,input().split())
c=[list(map(int,input().split())) for i in range(10)]
a=[list(map(int,input().split())) for i in range(h)]

g=csr_matrix(c)
paths=shortest_path(g,method="FW")

cost=0
for i in range(h):
    for j in range(w):
        if a[i][j]!=-1 and a[i][j]!=1:
            cost+=int(paths[a[i][j]][1])

print(cost)

Measured memory_bytes: 15608