akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string.h>

using namespace std;

int main()
{

    int length;     cin >> length;
    string slime;   cin >> slime;
    int total = 1;

    for (int i = 0; i < length-1; i++){
        if (slime[i] != slime[i+1]){
            total++;
        }
    }

    cout << total << endl;

    return 0;
}


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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
#define mem(a,b) memset(a,b,sizeof(a))
#define shutdown ios::sync_with_stdio(false)
#define MAX 10e18+1000
#define INF 0x3f3f3f3f


int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b)
        cout<<c<<endl;
    else if(b==c)
        cout<<a<<endl;
    else
        cout<<b<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>
#include <set>

using ll = long long;
using namespace std;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

const ll MOD = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
const double INF3 = 900000000000000;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()



int main() {
	int n, m, a, b, x;
	string s, t, r;
	cin >> a >> b >> x;
	if (a + b >= x&&a<=x)cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 384
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
a=[]
x=0
for i in range(N):
  A=list(map(int,input().split()))
  for h in range(M):
    x+=A[h]*B[h]
  sum=x+C
  if sum>0:
    a.append(sum)
  sum=0
  x=0
  A=[]
print(len(a))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

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

	vector<int> B(M);
	vector<vector<int>> A(N, vector<int>(M));

	for (auto &x : B) {
		cin >> x;
	}
	for (auto &v : A) {
		for (auto &x : v) {
			cin >> x;
		}
	}

	int ans = 0;

	for (int i = 0; i < N; ++i) {
		if (inner_product(A[i].begin(), A[i].end(), B.begin(), C) > 0) {
			++ans;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
using namespace std;
int main() {
    char S;
    int count[26] = {};
    while(cin >> S){
        S = tolower(S);
        int num = S - 'a';
        count[num]++;
    }
    for(int i = 0; i < 26; ++i){
        cout << (char)('a' + i) << " : " << count[i] << endl; 
    }
	return 0;
}

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

int top, S[100];

void push(int x) {
	S[++top] = x;
}

int pop() {
	top--;
	return S[top + 1];
}

int main() {
	int a, b;
	top = 0;
	char s[99];

	while (scanf("%s", s) != EOF) {
		if (s[0] == '+') {
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (s[0] == '-') {
			b = pop();
			a = pop();
			push(a - b);
		}
		else if (s[0] == '*') {
			a = pop();
			b = pop();
			push(a * b);
		}
		else {
			push(atoi(s));
		}
	}
	
	printf("%d\n", pop());

	return 0;
}


Measured memory_bytes: 2068
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000009;

int dp[1010][1010];

int main(){
	string s, t;
	cin >> s >> t;
	
	//Fill DP table with INF
	for(int i=0; i<(int)s.size(); i++){
		for(int j=0; j<(int)t.size(); j++) dp[i][j] = INF;
	}
	
	//Set initial value
	for(int i=0; i<=(int)s.size(); i++) dp[i][0] = i;
	for(int j=0; j<=(int)t.size(); j++) dp[0][j] = j;
	
	//Caluculate DP table
	for(int i=0; i<(int)s.size(); i++){
		for(int j=0; j<(int)t.size(); j++){
			int cost = 1;
			if(s[i]==t[j]) cost = 0;
			dp[i+1][j+1] = min({dp[i][j]+cost, dp[i][j+1]+1, dp[i+1][j]+1});
		}
	}
	
	cout << dp[s.size()][t.size()] << endl;
	
	return 0;
}


Measured memory_bytes: 7124
fun main(arg: Array<String>) {
    var (X, Y, A, B, C) = listOfInt()
    val P = listOfLong().sortedDescending()
    val Q = listOfLong().sortedDescending()
    val R = listOfLong().toMutableList()
    R.addAll(P.subList(0, X))
    R.addAll(Q.subList(0, Y))
    R.sortDescending()
    var ans = R.subList(0, X + Y).sumByLong { it }
    println(ans)
}
inline fun <T> Iterable<T>.sumByLong(selector: (T) -> Long): Long {
    var sum = 0L
    for (element in this) sum += selector(element)
    return sum
}
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }
fun listOfLong(delta: Long = 0L) = listOfString().map { java.lang.Long.parseLong(it) + delta }
fun listOfDouble(delta: Double = 0.0) = listOfString().map { java.lang.Double.parseDouble(it) + delta }
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
fun listOfDouble() = listOfString().map(String::toDouble)


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

const int mod = 1e9+7;

int main(){
    string a, b, c;
    while(cin >> a, a != "0"){
        cin >> b >> c;
        reverse(a.begin(), a.end());
        reverse(b.begin(), b.end());
        reverse(c.begin(), c.end());
        int n = a.length();
        vector<vector<int>> dp(n+1, vector<int>(2, 0));
        dp[0][0] = 1;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < 2; j++){
                if(dp[i][j] == 0)   continue;
                for(int k = 0; k < 10; k++){
                    if(i == n-1 && k == 0)  continue;
                    if(a[i] != '?' && a[i]-'0' != k)    continue;
                    for(int l = 0; l < 10; l++){
                        if(i == n-1 && l == 0)  continue;
                        if(b[i] != '?' && b[i]-'0' != l)    continue;
                        if(c[i] == '?' || (j+k+l)%10 == c[i]-'0'){
                            dp[i+1][(j+k+l)/10] += dp[i][j];
                            dp[i+1][(j+k+l)/10] %= mod;
                        }
                    }
                }
            }
        }
        cout << dp[n][0] << endl;
    }
    return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

// x^n(mod M)
void solve(ll n, ll p, const string &s) {
    vector<ll> ten(n+1), x(n+1);
    ten[0] = 1;
    rep(i,n) {
        ten[i+1] = (ten[i]*10)%p;
        ten[i+1] %= p;
    }

    rep(i,n) {
        ll d = s[i]-'0';
        x[i+1] = (x[i]%p+(d*ten[i])%p)%p;
    }

    ll ans = 0;
    map<ll, ll> mp;
    rep(i,n+1) {
        if (!mp.count(x[i])) {
            mp[x[i]]++;
        }
        else {
            ans += mp[x[i]];
            mp[x[i]]++;
        }
    }

    cout << ans << '\n';
}


int main(int argc, char const *argv[]) {
    string s; cin>>s;
    int n = s.length();
    reverse(s.begin(), s.end());
    int p = 2019;

    solve(n,p,s);

    return 0;
}


Measured memory_bytes: 6760
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int n, m, p, d[10000];
	cin >> n >> m >> p;
	for (int i = 0; i < m; ++i) {
		cin >> d[i];
		d[i] = (d[i] - p + n) % n;
	}

	if (m == 1) {
		cout << min(d[0], n - d[0]) * 100 << endl;
		return 0;
	}

	sort(d, d + m);

	int ans = min(n - d[0], d[m - 1]);
	for (int i = 0; i < m - 1; ++i) {
		ans = min(ans, d[i] * 2 + n - d[i + 1]);
		ans = min(ans, (n - d[i + 1]) * 2 + d[i]);
	}

	cout << ans * 100 << endl;

	return 0;
}

Measured memory_bytes: 3164
import scala.io.StdIn

case class Node(n: Int, var reached: Boolean = false, var x: Int = 0, var subs: List[Node] = List()) {
  def addSub(sub: Node): Unit = this.subs +:= sub

  def trace(acc: Long, additions: Array[Int], result: Array[Long]): Array[Long] = {
    reached = true
    val _acc = acc + additions(n).toLong
    result(n) = _acc
    subs.filterNot(_.reached).foreach(_.trace(_acc, additions, result))
    result
  }

  override def toString: String = s"{ $n | +$x | (${subs.mkString(", ")}) }"
}

object Main extends App {
  val Array(n, q) = StdIn.readLine.split(" ").map(_.toInt)
  val abs = fromStdIn(n - 1)
  val pxs = fromStdIn(q)

  val nodes: Array[Node] = Array.ofDim(n + 1)
  abs.foreach { case (a, b) =>
    val na = if (nodes(a) != null) nodes(a) else Node(a)
    val nb = if (nodes(b) != null) nodes(b) else Node(b)
    na.addSub(nb)
    nb.addSub(na)
    nodes(a) = na
    nodes(b) = nb
  }

//  nodes.tail.foreach(
//    node => println(s"${node.n}: ${node.subs.map(_.n)}")
//  )

  val additions = Array.ofDim[Int](n + 1)
  for ((p, x) <- pxs) {
    additions(p) += x
  }

  val result = Array.ofDim[Long](n + 1)
  nodes(1).trace(0L, additions, result)

  println(result.tail.mkString(" "))

  def fromStdIn(n: Int): Seq[(Int, Int)] =
    for (_ <- 1 to n)
      yield {
        val line = StdIn.readLine.split(" ").map(_.toInt)
        (line(0), line(1))
      }
}


Measured memory_bytes: 144708
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

const int N=1000005;
ll l[N],r[N],b[N],rk[N],val[N],mark[N];
ll sum[N],n,x,aim,ans=2e18;

inline ll cmp(ll x,ll y){
	return val[x]>val[y];
}

inline ll calc(ll x,ll y){
	if(x>=y)return sum[x];
	return sum[x]+val[rk[y]];
}

inline ll doit(ll k,ll rem){
	if(rem<=0)return 0;
	if(rem<=l[k]*b[k])return (rem+l[k]-1)/l[k];
	return b[k]+(rem-l[k]*b[k]+r[k]-1)/r[k];
}

int main(){
	scanf("%lld%lld",&n,&x);
	rep(i,1,n){
		scanf("%lld%lld%lld",&b[i],&l[i],&r[i]);
		val[i]=b[i]*l[i]+(x-b[i])*r[i];
		aim+=b[i]*l[i];
		rk[i]=i;
		//cerr<<i<<" "<<val[i]<<endl;
	}
	sort(rk+1,rk+n+1,cmp);
	rep(i,1,n)
		sum[i]=sum[i-1]+val[rk[i]];
	rep(i,1,n){
		ll low=0,high=n,mid;
		while(low<high){
			mid=(low+high)>>1;
			if(calc(mid,i)>=aim)high=mid;
			else low=mid+1;
		}
		if(low<i){
			ll now=x*low+doit(rk[i],aim-sum[low]);
			ans=min(ans,now);
		}
		else{
			ll now=x*(low-1)+doit(rk[i],aim-sum[low]+val[rk[i]]);
			ans=min(ans,now);
		}
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 15360
# coding: utf-8
# Your code here!
from itertools import accumulate
#import numpy as np

N, M, K = map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))

sum_A = list(accumulate(A))
sum_B = list(accumulate(B))


#sum_A = np.cumsum(A)
#sum_B = np.cumsum(B)

list_N = [0 for i in range(len(A)+1)]

pre_n = len(B)

for i in range(len(A)+1):
    if i == 0:
        num_B = 0
        for j in range(pre_n)[::-1]:
            if sum_B[j] <= K:
                num_B = j+1
                break
            else:
                continue
        #len(buf[buf<=K])
        pre_n = num_B
        list_N[i] = i + num_B
    else:
        if K>=sum_A[i-1]:
            num_B = 0
            for j in range(pre_n)[::-1]:
                if sum_B[j] <= (K-sum_A[i-1]):
                    num_B = j+1
                    break
                else:
                    continue
            #len(buf[buf<=(K-sum_A[i-1])])
            pre_n = num_B
            list_N[i] = i + num_B
            #print(K-sum_A[i-1])
            #print(i, num_B)
        else:
            list_N[i] = 0
    
#print(A)
#print(B)
#print(sum_A)
#print(sum_B)
#print(list_N)
print(max(list_N))

Measured memory_bytes: 140264
import sys

#+++++
		
def main():
	a = int(input())
	s = input()
	if a == 1:
		return 1
	
	cc=s[0]
	count=1
	for c in s[1:]:
		#print(c)
		if c != cc:
			count+=1
			cc=c
	
	return count
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3316
#include "bits/stdc++.h"
#define   LF      '\n'
#define   ALL(x)  x.begin(), x.end()
#define   iostreamBooster()  do{cin.tie(nullptr);ios::sync_with_stdio(false);}while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f'3f3f3f3fLL;


signed main()
{
  int N;
  vector<int> a;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    int n;
    cin >> n;
    a.push_back(n);
  }

  sort(ALL(a));
  int sum = 0;
  for (int i = 0; i < N-1; ++i) sum += a[i];

  if (a.back() < sum) {
    puts("Yes");
  } else {
    puts("No");
  }
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <limits.h>
#include <vector>
#include <numeric>

using namespace std;

vector<pair<long long int, long long int>> getPrimeElements(long long int num) {

	long long int firstnum = num;

	vector<pair<long long int, long long int>> result;
	pair<long long int, long long int> wk;

	if (num % 2 == 0) {
		wk.first = 2;
		wk.second = 0;
		while (num % 2 == 0) {
			wk.second++;
			num /= 2;
		}

		result.push_back(wk);
	}

	long long int waru = 3;

	while (true) {

		if (num % waru == 0) {
			wk.first = waru;
			wk.second = 0;
			while (num % waru == 0) {
				wk.second++;
				num /= waru;
			}

			result.push_back(wk);
		}
		waru += 2;

		if (waru * waru > num) break;

	}

	if (num != 1) {
		wk.first = num;
		wk.second = 1;
		result.push_back(wk);

	}

	return result;
}


int getKeta(int num) {

	if (num == 0)return 1;

	int res = 0;

	while (num > 0) {
		num /= 10;
		res++;
	}

	return res;
}

vector<int> bunkai(int num) {

	string str = to_string(num);
	vector<int> res;

	for (int i = 0; i < str.size(); i++) {
		int a = str[i] - '0';
		res.push_back(a);
	}

	return res;

}


int main()
{
    
	long long int n;
	cin >> n;

	long long int ans = n * (n - 1) / 2;

	cout << ans << endl;

	return 0;

}




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

//関数
    
    
    
    
//main関数
int main() {
    
    
    
    //入力
    int N;
    string S;
    cin>>N>>S;

    
    
    
    
    
    
    
    
    
    
    //計算
    vector<int> alpha(26);
        for(int i=0;i<N;i++){
        alpha.at(S.at(i)-97)++;
    }
    long long result=1;
    for(int i=0;i<26;i++){
        result*=(alpha.at(i)+1);
        result%=1000000007;
        //cout<<alpha.at(i)<<" "<<result<<endl;
    }
    result+=1000000006;
    result%=1000000007;
    
    
    
    
    
    
    
    
    
    
    
    //出力
    cout<<result<<endl;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(){
	int dayc[]={31,29,31,30,31,30,31,31,30,31,30,31};
	char* week[]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
	int M,D;
	int A,B,C;
	while(1){
		scanf("%d %d",&M,&D);
		if(M==0)
			break;
		B=0;
		for(A=0;A<M-1;A++)
			B+=dayc[A];
		B+=D;
		printf("%s\n",week[(B+2)%7]);
	}
 	return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;




ll n,k;
ll a[100005];


int main(){


        int w,h,x,y;
        cin >> w >> h >> x >> y;
        double ans = (double)w*h/2;
        int num = (w == x*2 && h == y*2) ? 1 : 0; 
        printf("%.10f %d\n", ans, num);
        return 0;
}




Measured memory_bytes: 256
/// ローカル環境なら _in.txt から入力を受ける
fn read_input() -> String {
    use std::fs::File;
    use std::io::Read;
    let mut s = String::new();
    match option_env!("LOCAL") {
        Some(_) => File::open("src/_in.txt")
            .expect("File not found")
            .read_to_string(&mut s)
            .unwrap(),
        None => std::io::stdin().read_to_string(&mut s).unwrap(),
    };
    s
}

static mut MEMO: [i32; 100010] = [-1; 100010];

fn solve(n: i32) -> i32 {
    unsafe {
        if n <= 0 {
            return 0;
        }
        if MEMO[n as usize] >= 0 {
            return MEMO[n as usize];
        }

        let mut ret = vec![];

        let mut d = 9;
        while n - d >= 0 {
            ret.push(solve(n - d) + 1);
            d *= 9
        }
        let mut d = 6;
        while n - d >= 0 {
            ret.push(solve(n - d) + 1);
            d *= 6
        }
        ret.push(solve(n - 1) + 1);

        MEMO[n as usize] = *ret.iter().min().unwrap();
        MEMO[n as usize]
    }
}

fn main() {
    let s = read_input();
    let mut ws = s.split_whitespace();
    let in_n: i32 = ws.next().unwrap().parse().unwrap();
    let ans = solve(in_n);
    println!("{:?}", ans);
}


Measured memory_bytes: 5756
import java.util.Scanner;


public class Main{

	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		int[] values = null;
		int cnt = s.nextInt();
		values = new int[cnt];
		int i = 0;
		for(int j=0 ; j<cnt ; j++){
			values[i] = s.nextInt();
			i++;
		}
		solve(values);
	}

	public static void solve(int[] values) {
		int mini = values[0];
		int max = Integer.MIN_VALUE;

		for(int i=1 ; i<values.length ; i++) {
			max = Math.max(values[i] - mini, max);
			mini = Math.min(mini, values[i]);
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 96428
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;

struct UF
{
    vector<int> r, p, sz;
    UF(int n) : r(n, 0), p(n, 0), sz(n, 1)
    {
        iota(p.begin(), p.end(), 0);
    }
	
    int f(int x)
    {
        return (p[x] == x ? x : p[x] = f(p[x]));
    }
	
    void u(int i, int j)
    {
        int x = f(i), y = f(j);
        if (x == y)
            return;

        if (r[x] >= r[y])
        {
            p[y] = x;
            sz[x] += sz[y];
            if (r[x] == r[y])
                r[x]++;
        }
        else
        {
            p[x] = y;
            sz[y] += sz[x];
        }
    }

    bool s(int i, int j)
    {
        return f(i) == f(j);
    }
};


int main()
{
    int n, k, l;
    cin >> n >> k >> l;
    UF uf(n + 1);
    UF ug(n + 1);
    for (int i = 0; i < k; ++i)
    {
        int a, b;
        cin >> a >> b;
        uf.u(a, b);
    }
    for (int i = 0; i < l; ++i)
    {
        int a, b;
        cin >> a >> b;
        ug.u(a, b);
    }
    map<pair<int, int>, int> mp;
    for (int i = 1; i <= n; ++i)
        mp[{uf.f(i), ug.f(i)}]++;
    for (int i = 1; i <= n; ++i)
        cout << mp[{uf.f(i), ug.f(i)}] << ' ';
}


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

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

using namespace std;

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

int main() {
    int n,start;
    cin >> n >> start;
    vector<int> x(n), d(n);
    rep(i,n){
        cin >> x[i];
    }
    x.push_back(start);
    sort(x.begin(),x.end());
    //目的地間の距離, d[i]はx[i],x[i+1]間の距離と定義
    int ans = 0;
    rep(i, n){
        d[i] = abs(x[i] - x[i+1]);
        ans = gcd(d[i], ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
     
using namespace std;
     
int main() {
    string s;
    cin >> s;
    int col = 0;
    int no_change = 0;
    for (int i = 0; i < s.length(); i++) {
        if ((s[i] - '0') != col) {
            no_change++;
        }
        col = 1 - col;
    }
    cout << min(no_change, (int)(s.length() - no_change));
}

Measured memory_bytes: 3732
#include <stdio.h>
 
using namespace std;
 
int main(){
    int a,b;
    while(true){
        scanf("%d %d",&a,&b);
        if(a == 0 && b == 0) break;
        if(a > b) printf("%d %d\n",b,a);
        else{
            printf("%d %d\n",a,b);
        }
    }
}


Measured memory_bytes: 2696
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007

using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n,k;
	cin>>n>>k;
	
	int h[n];
	for(int i=0;i<n;i++) {
		cin>>h[i];
	}
	
	if(n<=k) {
		int ans = abs(h[0]-h[n-1]);
		cout<<ans;
		return 0;
	}
	
	int dp[n];
	for(int i=0;i<=k;i++) {
		if(!i) {
			dp[i] = 0;
		}
		else {
			dp[i] = abs(h[i]-h[0]);
		}
	}
	
	for(int i=k+1;i<n;i++) {
		dp[i] = INT_MAX;
		for(int j=i-1;j>=(i-k);j--) {
			dp[i] = min(dp[i],(dp[j]+abs(h[i]-h[j])));
		}
	}
	
	cout<<dp[n-1];
	
	return 0;
}


Measured memory_bytes: 4352
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
/*#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
#define ll long long
#define ull unsigned long long
//#define int ll
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) {cout << a; exit(0);}

using namespace std;

mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

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

const int N = 2000 + 123;
int n , k ;
vector < int > gr[N];
int par[N] , dp[N] , ans , cnt[N] , x;
void solve(int s){

	for(int i = 1 ; i <= n; i++)
		par[i] = cnt[i] = dp[i] = 0;
	deque < int > dq;
	dp[s] = -1;
	for(auto to : gr[s])
		par[to] = to , dq.pb(to) , dp[to] = 1;

	int res = 1 , mx = 0;
	while(sz(dq) != 0){
		int u = dq.front();
		dq.pop_front();
		if(dp[u] == x + 1)
			cnt[par[u]]++ , mx = max(mx , cnt[par[u]]);
		else{
			res++;
			for(auto to : gr[u])
				if(dp[to] == 0)
					par[to] = par[u] , dq.pb(to) , dp[to] = dp[u] + 1;			
		}
	}
	if(x + x == k){
		ans = max(ans , res);
	}else ans = max(ans , res + mx);
	
}
main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	x = k / 2;
	for(int i = 1 ; i < n; i++){
		int u , v;
		cin >> u >> v;
		gr[u].pb(v);
		gr[v].pb(u);
	}          
	for(int i = 1; i <= n; i++){
		solve(i);
	}
	cout << n - ans;

}     

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;


template<typename T> struct Matrix {
    vector<vector<T>> A;

    Matrix(int n, int m, T x) : A(n, vector<T> (n, x)) {}
    Matrix(vector<vector<T>> a) {
        A.resize(a.size());
        for (int i = 0; i < a.size(); i++) {
            A[i].resize(a[i].size());
            for (int j = 0; j < a[i].size(); j++)
                A[i][j] = a[i][j];
        }
    }
    
    size_t size() const {return A.size();}
    vector<T>& operator [] (int i) {return A[i];}
    const vector<T>& operator [] (int i) const {return A[i];}

    Matrix operator * (const Matrix &B) {
        Matrix<T> R(A.size(), B[0].size(), 0);
        for (int i = 0; i < A.size(); i++)
            for (int j = 0; j < B[0].size(); j++)
                for (int k = 0; k < B.size(); k++)
                    R[i][j] += A[i][k] * B[k][j];
        return R;
    }
};

template<typename T> Matrix<T> identity(int n) {
    Matrix<T> R(n, n, 0);
    for (int i = 0; i < n; i++) R[i][i] = 1;
    return R;
}

template<typename T> Matrix<T> pow(const Matrix<T> &A, long long x) {
    if (x == 0)return identity<T>(A.size());
    Matrix<T> R = pow(A, x / 2);
    return (x % 2)? R * R * A : R * R;
}


struct ModInt {
    long long v;
    //static long long MOD;
    
    ModInt (long long v) : v((v % MOD + MOD) % MOD) {}

    ModInt& operator += (const ModInt a) {v += a.v; v %= MOD; return *this;}
    ModInt& operator *= (const ModInt a) {v *= a.v; v %= MOD; return *this;}

    ModInt operator + (const ModInt a) const {return ModInt(*this) += a;}
    ModInt operator * (const ModInt a) const {return ModInt(*this) *= a;}

    //ostream
};


int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    ll n, k; cin >> n >> k;
    Matrix<ModInt> a(n, n, 0);
    zep(i, 0, n){
        zep(j, 0, n){
            ll buf; cin >> buf;
            a[i][j] = buf;
        }
    }

    auto res = pow(a, k);
    ModInt ans = 0;
    zep(i, 0, n){
        zep(j, 0, n){
            ans += res[i][j];
        }
    }
    print(ans.v)
    return 0;
}

Measured memory_bytes: 384
# get line input split by space
def getLnInput():
    return input().split()


# ceil(a / b) for a > b
def ceilDivision(a, b):
    return (a - 1) // b + 1


def main():
    getLnInput()
    nums = list(map(int, getLnInput()))
    print(min(nums), max(nums), sum(nums))
    return


main()

Measured memory_bytes: 8708
#include<iostream>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    int arr[n+1][4];
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=3;j++)
        cin>>arr[i][j];
    }
    if(n==1)
    cout<<max(arr[1][1],max(arr[1][2],arr[1][3]))<<endl;
    else
    {
     for(int i=2;i<=n;i++)
    {
        for(int j=1;j<=3;j++)
        {   if(j==1)
            arr[i][j]+=max(arr[i-1][3],arr[i-1][2]);
            if(j==2)
             arr[i][j]+=max(arr[i-1][1],arr[i-1][3]);
             if(j==3)
              arr[i][j]+=max(arr[i-1][1],arr[i-1][2]);
        }
    }
    cout<<max(arr[n][1],max(arr[n][2],arr[n][3]))<<endl;
    }
    return 0;
}

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

int main(void) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    char prev = s.at(0);
    for (int i = 1; i < (int)s.size(); i++) {
        if (s.at(i) == prev) {
            cout << "no" << endl;
            return 0;
        }
        prev=s.at(i);
    }
    cout << "yes" << endl;
    return 0;
}

Measured memory_bytes: 3580
def f(x)
   [10,100,1000,10000,100000,1000000].map{|k|
    x%k/(k/10)
  }.inject(:+)
end
n=gets.to_i
p n.times.map{|m|
  a=f(n-m)
  b=f(m)
  if (a < 1 || b < 1)
    a * 10 + b * 10
  else
    a + b
  end
}.min

Measured memory_bytes: 2812
#include<cstdio>

int H, W;

void print_frame(){
	for( int i = 1 ; i <= H ; i++ ){
		for( int j = 1 ; j <= W ; j++ ){
			if( i == 1 || i == H || j == 1 || j == W) printf("#");
			else printf(".");
		}
		printf("\n");
	}
	printf("\n");
}

int main(void){
	while(1){
		scanf("%d %d", &H, &W);
		if( H == 0 && W == 0) break;

		print_frame();
	}

	return 0;
}

Measured memory_bytes: 2556
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.Comparator;
import java.util.Collections;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author HBonsai
 */
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);
        LIS solver = new LIS();
        solver.solve(1, in, out);
        out.close();
    }

    static class LIS {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = Integer.parseInt(in.next());
            int[] a = new int[n];
            Arrays.setAll(a, i -> Integer.parseInt(in.next()));
            Integer[] dp = new Integer[n + 1];
            final int INF = Integer.MAX_VALUE;
            Arrays.fill(dp, INF);
            List<Integer> dpList = Arrays.asList(dp);
            Comparator<Integer> lowerBound = (x, y) -> x.compareTo(y) >= 0 ? 1 : -1;
            for (int i = 0; i < n; i++) {
                int replaced = ~Collections.binarySearch(dpList, a[i], lowerBound);
                if (replaced >= 0) {
                    dp[replaced] = a[i];
                }
            }
            int ans = -1;
            for (int i = n; i >= 0; i--) {
                if (dp[i] < INF) {
                    ans = i + 1;
                    break;
                }
            }
            out.println(ans);
        }

    }
}




Measured memory_bytes: 73184
import sys
A=str(input())
B=str(input())
C=str(input())

alt="a"
while True:
  if alt == "a":
    if A=="":
      print("A")
      sys.exit()
    alt = A[0]
    A=A[1:]
  if alt == "b":
    if B=="":
      print("B")
      sys.exit()
    alt = B[0]
    B=B[1:]
  if alt == "c":
    if C=="":
      print("C")
      sys.exit()
    alt = C[0]
    C=C[1:]

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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int32 sum = 0;
  REP(i,s.size())sum += s[i] - '0';
  Yes(sum % 9 == 0);
  return 0;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define FOR(i,b,e) for (common_type_t<decltype(b),decltype(e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define rep(i,n)   FOR (i, size_t{}, n)
#define ALL(x)     begin (x), end (x)
using namespace std;
using ll = int64_t;
constexpr ll inf = 2e18;

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  size_t n;
  cin >> n;

  vector <size_t> a (n);
  using P = pair <size_t, bool>;
  vector <vector <P>> shougen (n, vector <P> ());

  rep (i, n)
  {
    cin >> a [i];
    rep (j, a [i])
    {
      size_t s;
      int b;
      cin >> s >> b;
      -- s;
      shougen [i].emplace_back (s, b == 1);
    }
  }

  size_t ans = 0;
  bitset <16> t;

  rep (x, 1ull << n)
  {
    t = x;
    auto cnt = t.count ();

    rep (i, n) rep (j, a [i])
    {
      size_t s;
      bool b;
      tie (s, b) = shougen [i] [j];
      if (t [i])
      {
        if (t [s] != b)
        {
          goto failure;
        }
      }
    }
    ans = max (ans, cnt);
failure:
    ;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

N, x = map(int, input().split())
As = list(map(int, input().split()))
As.sort()

ans = 0
for i, a in enumerate(As):
    if i != N - 1:
        if x >= a:
            ans += 1
            x -= a
    else:
        if x == a:
            ans += 1
            
print(ans)



Measured memory_bytes: 8008
/* ****revpro**** */
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl     '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii      map<ll,ll>
using namespace std;

#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define N  100005
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;  
#define ordered_set tree<double, null_type,less<double>, rb_tree_tag,tree_order_statistics_node_update> 
void solve()
{
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  while((a>0)&&(c>0))
  {
    c-=b;
    if(c<=0){
      cout<<"Yes";
      return;
    }
    a-=d;
    if(a<=0){
      cout<<"No";
      return;
    }
  }
}
signed main()
{
  
    /***********************************/
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    mt19937_64 generator (seed);
    /***********************************/

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS=1;
//  cin>>TESTS;
  while(TESTS--)
  {
    solve();
    
  }
  TIME
  return 0;
}

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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(),x.end()
auto& errStream=cerr;
#ifdef LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

ll read(){
	ll i;
	scanf("%"  SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

signed main(){
	int n=read();
	vi a(n);
	REP(i,n)
		a[i]=read();
	sort(ALL(a),greater<int>());
	int f=-1;
	REP(i,n){
		int t=1+i;
		if(t<=a[i])
			f=i;
	}
	int t=1+f;
	bool win=false;
	if((a[f]-t)%2==1)
		win=true;
	{
		int g=-1;
		REP(i,n)
			if(t<=a[i])
				g=i;
		if((g-f)%2==1)
			win=true;
	}
	if(win)
		cout<<"First"<<endl;
	else
		cout<<"Second"<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	int N, M;
	bool check[100001] = { 1 };
	long long  total[100010] = { 0 };
	cin >> N >> M;
	int a;
	for (int r = 0; r <= N; r++) {
		check[r] = 1;
	}
	for (int i = 0; i < M; i++) {
		cin >> a;
		check[a] = 0;
	}

	if (check[1]) {
		total[1] = 1;
	}
	else {
		total[1] = 0;
	}

	if (check[2]) {
		total[2] = 1 + total[1];
	}
	else {
		total[2] = 0;
	}

	for (int n = 3; n <= N; n++) {
		if (check[n]) {
			total[n] = (total[n - 2] + total[n - 1])% 1000000007;
		}
		else {
			total[n] = 0;
		}
		
	}
	cout << total[N];
	return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N,M;
  cin>>N>>M;
  vector<int> C[N];
  REP(i,M){
    int A,B;
    cin>>A>>B;
    A--;B--;
    C[A].push_back(B);
    C[B].push_back(A);
  }
  queue<int> q;
  vector<int> ans(N,-1);
  q.push(0);
  ans[0]=0;
  while(!q.empty()){
    int p=q.front();
    q.pop();
    for(auto e:C[p])if(ans[e]<0){
      ans[e]=p+1;
      q.push(e);
    }
  }
  cout<<"Yes"<<endl;
  FOR(i,1,N){
    cout<<ans[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 10332
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		for(int i=1;i<=9;i++) {
			for(int j=1;j<=9;j++) {
				System.out.println(i+"x"+j+"="+(i*j));
			}
		}
	}
}



Measured memory_bytes: 26096
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 300000

int n;
char s[MAXN+1];
int l[MAXN], r[MAXN];

int input() {
	if (scanf("%d", &n) < 0) return 0;
	scanf("%s", s);
	return 1;
}

void init() {
}

long solve() {
	int ct=0;
	for (int i=0; i<n; i++) {
		l[i] = ct;
		if (s[i]=='W') ct++;
	}
	ct = 0;
	for (int i=n-1; i>=0; i--) {
		r[i] = ct;
		if (s[i]=='E') ct++;
	}
	int ret = INT_MAX;
	for (int i=0; i<n; i++)
		ret = min(ret, l[i] + r[i]);
	return ret;
}

void output(long ans) {
	printf("%ld\n", ans);
}

void cleanup() {
}

int main() {
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





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

#define ran 202202

struct modular_arithmetic{
	int mod;

	modular_arithmetic(){
		mod = 998244353;
	}
	//No specific settings.
	int add(int x,int y){return (x+=y)<mod?x:x-mod;}
	int sub(int x,int y){return (x-=y)>=0?x:x+mod;}
	int mul(int x,int y){return (int)((long long int)x*y%mod);}
	int pw(int base, int p) {
		int res = 1, mu = base%mod;
		for(;p>0;p/=2) {
			if (p&1) res = mul(res, mu);
			mu = mul(mu, mu);
		}
		return res;
	}
	int rev(int x) {return pw(x, mod-2);}
};
modular_arithmetic ma;

int n, m, k;
int fac[ran], _fac[ran];

int c(int n, int m) {
	return ma.mul(fac[n], ma.mul(_fac[m], _fac[n-m]));
}

int main() {
	scanf("%d%d%d", &n, &m, &k);
	
	fac[0] = fac[1] = 1;
	for(int i=2;i<=n;i++)
		fac[i] = ma.mul(fac[i-1], i);
	_fac[n] = ma.rev(fac[n]);
	for(int i=n-1;i>=0;i--)
		_fac[i] = ma.mul(_fac[i+1], i+1);
	
	int ans = 0;
	int x = ma.mul(m, ma.pw(m-1, n-k-1));
	for(int i=k;i>=0;i--) {
		ans = ma.add(ans, ma.mul(x, c(n-1, i)));
		x = ma.mul(x, m-1);
	}
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

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

    ll ans = 0;
    FOR(i, 1, N+1) {
        int sum = 0;
        int temp = i;
        while (temp > 0) {
            sum += temp % 10;
            temp /= 10;
        }
        if (A <= sum && sum <= B) {
            ans += i;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
print(readInts().firstIndex(where:) { $0 == 0 }! + 1)
//let (x, y) = readInts().mapToTuple()
//print(((4 * x - y) / 2) <= x)


// MARK: -----------------------------------------------------------------------


func readInts() -> [Int] {
    readLine()!.split(separator: " ").map { Int($0)! }
}

extension Collection {
    func mapToTuple() -> (Element, Element) {
        var i = makeIterator()
        return (i.next()!, i.next()!)
    }
    func mapToTuple() -> (Element, Element, Element) {
        var i = makeIterator()
        return (i.next()!, i.next()!, i.next()!)
    }
    func mapToTuple() -> (Element, Element, Element, Element) {
        var i = makeIterator()
        return (i.next()!, i.next()!, i.next()!, i.next()!)
    }
}

struct DP<Argument: Hashable, Element> {
    var dictionary = [Argument: Element]()
    
    var expression: (Argument, (Argument) -> Element) -> Element
    
    init(expression: @escaping (_ argument: Argument, _ note: (Argument) -> Element) -> Element) {
        self.expression = expression
    }
    
    subscript(_ argument: Argument) -> Element {
        mutating get {
            if let note = dictionary[argument] {
                return note
            } else {
                let result = expression(argument) { self[$0] }
                dictionary[argument] = result
                return result
            }
        }
    }
}


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int n , k , x;

int main()
{
    _FastIO;
    cin >> n >> k;
    int ans = 0;
    for(int i = 0; i < n; i++){
        cin >> x;
        if(x >= k)
            ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif 


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

    int N, K; cin >> N >> K;
    vi T(N), D(N); 
    REP(i, N) {
        cin >> T[i] >> D[i];
        T[i]--;
    }
    
    vvl a(N);
    REP(i,N) {
        a[T[i]].push_back(D[i]);
    }    
    REP(i,N) {
        if (a[i].size() > 1){
            sort(a[i].begin(), a[i].end(), greater<ll>());
        }
    }

    priority_queue<ll> best, rest;
    REP(i, N) {
        if (a[i].size() > 0) best.push(a[i][0]);

        if (a[i].size() > 1) {
            for (int j = 1; j < a[i].size(); j++) {
                rest.push(a[i][j]);
            }
        }        
    }
    
    priority_queue<ll> tb = best;
    vl bsum(tb.size());
    if (bsum.size()>0) {
        bsum[0] = tb.top();
        tb.pop();
    }
    FOR(i,1,bsum.size()) {
        bsum[i] = bsum[i - 1] + tb.top();
        tb.pop();
        if (tb.size() == 0) break;
    }

    priority_queue<ll> tr = rest;
    vl rsum(tr.size());
    if (rsum.size()>0) {
        rsum[0] = tr.top();
        tr.pop();
    }
    FOR(i,1,rsum.size()) {
        rsum[i] = rsum[i - 1] + tr.top();
        tr.pop();
        if (tr.size() == 0) break;
    }

    ll ans = 0;
    for(ll x=1; x<=best.size(); x++) {
        ll sum = x*x;

        sum += bsum[x - 1];

        if (K - x > rest.size()) continue;

        if (K-x-1>=0) sum += rsum[K - x - 1];
       
        ans = max(ans, sum);
    }


    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8948