akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = list(int(input()) for i in range(n))
ans = 0
for i in range(n-1):
    m = a[i]//2
    ans += m
    a[i] -= m*2
    if a[i] == 1 and a[i+1] != 0:
        ans += 1
        a[i] -= 1
        a[i+1] -= 1
print(ans + a[-1]//2)

Measured memory_bytes: 13032
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <map>
#include <functional>
#include <cstring>
#include <queue>
#include <cmath>
#include <deque>
#include <list>
#include <iomanip>
#include <fstream>
#include <string>
#include <iterator>
#include <set>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
#define mp make_pair
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, N) FOR(i, 0, N)
#define SZ(x) ((int)(x).size())

const int MAXN = 507, MAXK = 12, MOD = 100000000;

int main()
{
	int n;
	cin >> n;
	if (n / 100 == n % 10) cout << "Yes";
	else cout << "No";
	//cout << endl; system("pause");//please
	return 0;
}

Measured memory_bytes: 256
object Main {
	val s = new java.util.Scanner(System.in)
	def main(args: Array[String]) {
		val h, w = s.nextInt();

		outHR(w + 2);
		for (_ <- 1 to h)
			println("#" + s.next + "#")
		outHR(w + 2);
	}
	def outHR(n: Int) {
		var r = "";
		for (_ <- 1 to n)
			r += "#";
		println(r);
	}
}


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

int main() {
  int a;
  cin>>a;
  
 vector<int> vec(a);
  
  for(int i=0;i<a;i++){
    cin>>vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  
  int answer=10000000;
  int p;
    
  for(int i=vec.at(0);i<=vec.at(a-1);i++){
    p=0;
    for(int j=0;j<a;j++){
      p+=(vec.at(j)-i)*(vec.at(j)-i);
    }
    if(p<answer){
      answer=p;
    }
  }
    
    cout<<answer<<endl;
}

Measured memory_bytes: 256
N,L = map(int,input().split())

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

imp = 0
for i in range(N-1):
    if a[i]+a[i+1]>=L:
        break
else:
    print("Impossible")
    imp = 1

#possible
if imp==0:
    print("Possible")
    for j in range(i):
        print(j+1)
    for j in range(N-1,i+1,-1):
        print(j)
    print(i+1)

Measured memory_bytes: 14052
import java.util.Scanner;
public class Main{
    public static void print(int num[]){
        for(int i = 0 ; i < num.length-1 ; i++)
            System.out.print(num[i] + " ");
        System.out.println(num[num.length-1]);
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int num[] = new int[n];
        for(int i = 0 ; i < n ; i++)
            num[i] = sc.nextInt();
        print(num);
        for(int i = 1 ; i < n ; i++)
        {
            int j = i-1;
            int tmp = num[i];
            while(j >= 0)
            {
                if(num[j] > tmp)
                {
                    num[j+1] = num[j--];
                    num[j+1] = tmp;
                }
                else
                {
                    num[j+1] = tmp;
                    break;
                }
            }
            print(num);
        }
    }
}


Measured memory_bytes: 31268
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef char chr;
typedef double  dbl;
typedef long long int lld;
#define FastIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
lld lowerIndex(lld arr[], lld n, lld x) 
{ 
    lld l = 0 , h = n - 1;
    while (l <= h) { 
        lld mid = (l+h)/2;
        if (arr[mid] >= x) 
            h = mid - 1; 
        else
            l = mid + 1; 
    } 
    return l; 
}
lld upperIndex(lld arr[], lld n, lld y)
{ 
    lld l = 0 , h = n - 1; 
    while (l <= h) { 
        lld mid = (l+h)/2; 
        if (arr[mid] <= y) 
            l = mid + 1; 
        else
            h = mid - 1; 
    } 
    return h; 
}
lld countInRange(lld arr[], lld n, lld x, lld y) 
{
    lld count = 0; 
    count = upperIndex(arr, n, y) - lowerIndex(arr, n, x) + 1; 
    return count; 
}
int main () {
    FastIO
    lld n, i;
    cin >> n;
    string s;
    cin >> s;
    lld j, k;
    lld R[n];
    lld G[n];
    lld B[n];
    lld a, b;
    lld c;
    a = 0;
    b = 0;
    c = 0;
    for(i = 0; i < n-0; i+=1){
    	if (s[i] == 'R'){
    		R[a] = i;
    		a++;
    	}
    	if (s[i] == 'G'){
    		G[b] = i;
    		b++;
    	}
    	if (s[i] == 'B'){
    		B[c] = i;
    		c++;
    	}
    }
    lld sum = 0;
    for(i = 0; i < n-2; i+=1){
    	for(k = i+2;k<n;k+=1){
    		if (s[i] != s[k]){
    			if (s[i] == 'R' && s[k] == 'G'){
    				sum+= countInRange(B,c,i,k);
    				if ((i+k) % 2 == 0 && s[(i+k)/2] == 'B'){
    					sum--;
    				}
    			}
    			if (s[i] == 'R' && s[k] == 'B'){
    				sum+= countInRange(G,b,i,k);
    				if ((i+k) % 2 == 0 && s[(i+k)/2] == 'G'){
    					sum--;
    				}
    			}
    			if (s[i] == 'G' && s[k] == 'R'){
    				sum+= countInRange(B,c,i,k);
    				if ((i+k) % 2 == 0 && s[(i+k)/2] == 'B'){
    					sum--;
    				}
    			}
    			if (s[i] == 'G' && s[k] == 'B'){
    				sum+= countInRange(R,a,i,k);
    				if ((i+k) % 2 == 0 && s[(i+k)/2] == 'R'){
    					sum--;
    				}
    			}
    			if (s[i] == 'B' && s[k] == 'G'){
    				sum+= countInRange(R,a,i,k);
    				if ((i+k) % 2 == 0 && s[(i+k)/2] == 'R'){
    					sum--;
    				}
    			}
    			if (s[i] == 'B' && s[k] == 'R'){
    				sum+= countInRange(G,b,i,k);
    				if ((i+k) % 2 == 0 && s[(i+k)/2] == 'G'){
    					sum--;
    				}
    			}
    		}
    	}
    }
    cout << sum << "\n";
    return 0;
}

Measured memory_bytes: 3700
import java.util.Scanner;

public class Main {
    private static int N;
    private static int A;
    private static int B;
    private static int C;
    private static int[] l;
    private static int INF = 1000000;

    static {
        Scanner sc = new Scanner(System.in);
        N = Integer.parseInt(sc.next());
        A = Integer.parseInt(sc.next());
        B = Integer.parseInt(sc.next());
        C = Integer.parseInt(sc.next());
        l = new int[N];

        for (int i = 0; i < N; i++) {
            l[i] = Integer.parseInt(sc.next());
        }
    }

    public static void main(String[] args) {
        System.out.println(dfs(0, 0, 0, 0));
    }

    private static int dfs(int cursor, int a, int b, int c) {
        if (cursor == N) {
            // 足りない分とはみ出た分を調整しているコストを計算している。
            // -30 は初回に合成しているとみなしている分を減算している。
            return min(a, b, c) > 0 ? Math.abs(a - A) + Math.abs(b - B) + Math.abs(c - C) - 30 : INF;
        }

        // cursor が当たっている竹をa or b or c に合成する or どこにも合成しないのパターンを計算している。
        int noCompoundPattern = dfs(cursor + 1, a, b, c);
        int aCompoundPattern = dfs(cursor + 1, a + l[cursor], b, c) + 10;
        int bCompoundPattern = dfs(cursor + 1, a, b + l[cursor], c) + 10;
        int cCompoundPattern = dfs(cursor + 1, a, b, c + l[cursor]) + 10;
        return min(noCompoundPattern, aCompoundPattern, bCompoundPattern, cCompoundPattern);
    }

    private static int min(int a, int b, int... c) {
        int min = Math.min(a, b);
        for (int i : c) {
            min = Math.min(min, i);
        }

        return min;
    }
}


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

#define ll long long



main()
{
  ll a,b,c,k;
  cin>>a>>b>>c>>k;
  if(k<=a) cout<<k<<endl;
  else if(k<=(a+b)&&k>a) cout<<a<<endl;
  else cout<<a+((k-a-b)*-1)<<endl;





}

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)

/* memo
int no[tate][yoko]
*/

int main() {
    char S[11] = {};
    char T[12] = {};
    cin >> S;
    cin >> T;
    REP(i, strlen(S)) {
        if (S[i] != T[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}



Measured memory_bytes: 3636
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(long long n){
    vector<vector<int>> cnt(10, vector<int>(10, 0));
    i64 ans = 0;
    for(int i = 1; i <= n; ++i){
        vector<int> s;
        int j = i;
        while(j){
            s.emplace_back(j % 10);
            j /= 10;
        }
        ++cnt[s.front()][s.back()];
    }
    for(int i = 1; i <= n; ++i){
        vector<int> s;
        int j = i;
        while(j){
            s.emplace_back(j % 10);
            j /= 10;
        }
        ans += cnt[s.back()][s.front()];
    }
    cout << ans << endl;
}


signed main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Fast() ios_base::sync_with_stdio(false);cin.tie(NULL);
double arr[200009];
int main()
{
    Fast();
    ll n,t,x,y,i,j,k,mini=LONG_LONG_MAX,ma=LONG_LONG_MIN,flag =0,mul=1;
    vector<double>vi;
    string s,s1="";
    double sum =0;
    cin>>n>>k;
    for(i = 1; i<=20000; i++)
    {
        sum+=i;
        arr[i]=sum;
    }
    for(i = 0; i<n; i++)
    {
        cin>>x;
        vi.push_back(x);
    }
   double  maxi=-29999999;
   sum=0;
    for( j=0,i=0; i<n ; j++,i++)
    {
        vi[i]=arr[(int)vi[i]]/vi[i];

        //cout<<sum<<endl;
        //cout<<vi[i]<<endl;
    }

    for(i = 0 ;i<k ;i++)
    {
        sum+=vi[i];
    }
    maxi =max(sum,maxi);
    for(j=0;i<n;i++,j++)
    {
        sum+=vi[i]-vi[j];
        maxi=max(sum,maxi);
    }
    //cout<<maxi<<endl;
    //sum=0;
    cout<<fixed<<setprecision(8)<<maxi<<endl;


}


Measured memory_bytes: 2548
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

// 繰り返し二乗法
// n^p(mod mod) を高速で求める 再帰よりforが速い？
ll RepeatSquaring(ll N, ll P, ll mod)
{
    if (P == 0)
        return 1;
    if (P % 2 == 0)
    {
        ll t = RepeatSquaring(N, P / 2, mod);
        return t * t % mod;
    }
    return N * RepeatSquaring(N, P - 1, mod);
}

/* nCr mod pを求めるセット */
ll modPow(ll a, ll x, ll p)
{
    //calculates a^x mod p in logarithmic time.
    ll res = 1;
    while (x > 0)
    {
        if (x % 2 != 0)
        {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}

ll modInverse(ll a, ll p)
{
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p - 2, p);
}

ll modBinomial(ll n, ll k, ll p)
{
    // calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i = 0; i < k; i++)
    {
        numerator = (numerator * (n - i)) % p;
    }

    ll denominator = 1; // k!
    for (ll i = 1; i <= k; i++)
    {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return (numerator * modInverse(denominator, p)) % p;
}

int main(int argc, char const *argv[])
{
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = RepeatSquaring(2, n, 1000000007) - 1;
    ans += 1000000007;
    ans -= modBinomial(n, a, 1000000007);
    ans %= 1000000007;
    ans += 1000000007;
    ans -= modBinomial(n, b, 1000000007);
    ans %= 1000000007;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)

using ll = long long;
using ull = unsigned long long;
constexpr ll mod = 1e9 + 7;
using namespace std;

int main() {

	int N; cin >> N;
	vector<int> A(N), B(N), C(N - 1);
	rep(i, N)cin >> A[i];
	rep(i, N)cin >> B[i];
	rep(i, N - 1)cin >> C[i];

	int ans = 0;
	int before = 0;
	rep(i, N) {
		ans += B[A[i] - 1];
		if (i != 0 && A[i] == before + 1)ans += C[before - 1];
		before = A[i];
	}

	cout << ans;

	return 0;

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sun Jul  5 21:07:34 2020

@author: NEC-PCuser
"""
import copy

H, W, K = map(int, input().split())

c = []
c_count = 0
for i in range(H):
    c_li = list(input())
    c_count += c_li.count("#")
    c.append(c_li)
N = H + W
ans = 0
for i in range(2 ** N):
    count = c_count
    c_tmp = copy.deepcopy(c)
    for j in range(N):
        if ( j <  W and (i >> j) & 1):
            for k in range(H):
                if (c_tmp[k][j] == "#"):
                    count -= 1
                c_tmp[k][j] = "!"
        elif ((i >> j) & 1):
            for k in range(W):
                if (c_tmp[j - W][k] == "#"):
                    count -= 1
    if count == K:
        ans += 1

print(ans)

Measured memory_bytes: 9356
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip	;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
string f(string a,string b){
	if(a.size()==b.size()){
		return a>b?a:b;
	}else return a.size()>b.size()?a:b;
}
int main(){
	int n,m;
	while(cin>>m>>n,n+m){
		vector<string>in(n+1);
		rep(i,m)in[0]+="A";
		rep(i,n)cin>>in[i+1];
		rep(i,n+1)in[i]="A"+in[i];
		string dp[100][100]={""};
		loop(i,1,n+1)loop(j,1,m+1)if(isdigit(in[i][j])){
			string s="";
			if(dp[i-1][j]!=""){
				s=dp[i-1][j];
			}
			if(dp[i][j-1]!=""){
				s=f(s,dp[i][j-1]);
			}
			s+=in[i][j];
			if(s=="0")s="";
			dp[i][j]=s;
		}
		string out="";
		rep(i,n)rep(j,m)out=f(out,dp[i+1][j+1]);
		cout<<out<<endl;
	}
}

Measured memory_bytes: 1424
from collections import defaultdict

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

buka = defaultdict(int)

for a in A:
    buka[a] += 1

for i in range(1, N + 1):
    if i in buka.keys():
        print(buka[i])
    else:
        print(0)


Measured memory_bytes: 34044
#include<iostream>

int main(){
int n,m,c;
  std::cin >> n >> m >> c;
  int b[m];
  int a[n][m];
  for(int i=0;i<m;i++){
    std::cin >> b[i];
  }
  int t=0;
  for(int i=0;i<n;i++){
    int res=0;
    for(int j=0;j<m;j++){
         std::cin >> a[i][j];
         res+=(a[i][j]*b[j]);
   }
    if(res+c>0) t++;
 }
 std::cout << t << std::endl;
 return 0;
}


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

int main(){
    int n;
    int Wm[4]={0};
    int Km[4]={0};
    int i, j;
    int W=0, K=0;
    for(i=0;i<10;i++){
        cin >> Wm[0];
        for(j=0;j<3;j++){
            if(Wm[j] > Wm[j+1]){
                swap(Wm[j], Wm[j+1]);
            }else{
                break;
            }
        }
    }
    for(j=1;j<4;j++){
        W += Wm[j];
    }
    for(i=10;i<20;i++){
        cin >> Km[0];
        for(j=0;j<3;j++){
            if(Km[j] > Km[j+1]){
                swap(Km[j], Km[j+1]);
            }else{
                break;
            }
        }
    }
    for(j=1;j<4;j++){
        K += Km[j];
    }
    cout << W << ' ' << K << endl;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <queue>
#include <string>
#include <stack>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll          = long long;
using db          = double;
using ld          = long double;
using uint        = unsigned int;
using ull         = unsigned long long;

using pii         = pair<int, int>;
using pll         = pair<ll, ll>;
using tiii        = tuple<int, int, int>;

#define mod7        1000000007
#define mod9        1000000009

#define forall(v)   v.begin(), v.end()
#define prec(x)     setprecision(x) << fixed

/* [💭] [💡] [🎈] */

int main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    vector<bool> eat(n);
    priority_queue<tiii> t, a;

    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;

        t.emplace(tiii(x + y, x, i));
        a.emplace(tiii(x + y, y, i));
    }

    ll x = 0;
    for (int i = 0; i < n; i++) {
        if (i & 1) { // a
            tiii r = a.top();
            a.pop();
            while (eat[get<2>(r)]) {
                r = a.top();
                a.pop();
            }

            eat[get<2>(r)] = true;
            x -= get<1>(r);
        } else { // t
            tiii r = t.top();
            t.pop();
            while (eat[get<2>(r)]) {
                r = t.top();
                t.pop();
            }

            eat[get<2>(r)] = true;
            x += get<1>(r);
        }
    }

    cout << x;

    return 0;
}

Measured memory_bytes: 2988
#include<bits/stdc++.h>
using namespace std;
#define int 		long long
#define ull 		unsigned long long
#define vi 			vector<int>
#define vvi			vector<vi>
#define pb			push_back
#define mii  		map<int, int>
#define pii 		pair<int, int>
#define pq 			priority_queue<int>
#define pqs 		priority_queue<int, vi, greater<int>>
#define mod 		1000000007
#define inf 		1e18
#define ps(x, y) 	fixed<<setprecision(y)<<x
#define w(t)		int t; cin>>t; while(t--)
#define rep(i,a,b)	for(int i = a; i < b; i++)
#define repd(i,a,b)	for(int i = a; i>= b; i--)
int32_t main()
{
	int n, ans = 0;
    cin>>n;
    vector<int> dp(n, 0);
    for(int i = 1; i < n; i++)
        for(int j = i; j < n; j = j+i)
            dp[j]++;
    for(int i = 1; i < n; i++)
        ans += dp[i];
    cout<<ans;
	return 0;
}


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

#define fast_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define show(x) cout << #x << " = " << x << '\n'
#define ll long long
#define ull unsigned long long
#define PI 3.1415926535897932384626433832795
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("-ffloat-store")


int main()
{
    fast_IO
    ll n, ans = 0, x = 1; cin >> n;
    while (n >= x * x + 1)
    {
        ans += 1 + 2 * ((n - (x * x + 1)) / x);
        x++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,k;
    int sum=0;
    cin>>a>>b>>c>>k;
    for(int i=0;i<a;i++){
        if(k==0)
            goto End;
        sum++;
        k--;     
    }
    for(int i=0;i<b;i++){
        if(k==0)
            goto End;
        k--;
    }
    for(int i=0;i<c;i++){
        if(k==0)
            goto End;
        sum--;
        k--;
    }
    End:cout<<sum<<endl;
}

Measured memory_bytes: 3608
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  int N, M;
  cin >> N >> M;
  priority_queue<Pi, vector<Pi>, greater<Pi>> list;
  FOR(i, N) {
    Pi p;
    cin >> p.first >> p.second;
    list.push(p);
  }
  int ans = 0;
  priority_queue<int> can;
  for (int i = 1; i <= M; ++i) {
    while (!list.empty() && list.top().first <= i) {
      can.push(list.top().second);
      list.pop();
    }
    if (!can.empty()) {
      ans += can.top();
      can.pop();
    }
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 1908
# -*- coding: utf-8 -*-
"""
Created on Sat May 26 21:19:35 2018

@author: maezawa
"""

n = int(input())
s = input()

dp = [None for _ in range(n)]

cnt = 0
for i in range(1,n):
    if s[i]=='E':
        cnt += 1
dp[0] = cnt
#print(dp[0])

for i in range(1,n):
    if s[i-1] == 'E':
        if s[i] == 'E':
            dp[i] = dp[i-1] - 1
        else:
            dp[i] = dp[i-1]
    elif s[i-1] == 'W':
        if s[i] == 'W':
            dp[i] = dp[i-1] + 1
        else:
            dp[i] = dp[i-1]

ans = min(dp)
print(ans)
        

Measured memory_bytes: 15520
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;

int main() {
  string s;
  cin >> s;
  int start, end;
  rep(i, s.length()) {
    if (s[i] == 'A') {
      start = i;
      break;
    }
  }
  for (int i = s.length() - 1; i >= 0; i--) {
    if (s[i] == 'Z') {
      end = i;
      break;
    }
  }
  cout << end - start + 1 << endl;
}


Measured memory_bytes: 640
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

class BIT(object):
    def __init__(self, size: int):
        self.bitree = [0]*(size+1)
        
    def setval(self, idx:int, val:int):
        tree = self.bitree
        nex_idx = idx+1
        
        while nex_idx < len(tree):
            tree[nex_idx] += val
            nex_idx += nex_idx & -nex_idx
            
    def getsum(self, idx: int):
        tree, result = self.bitree, 0
        nex_idx = idx+1
        
        while nex_idx:
            result += tree[nex_idx]
            nex_idx -= nex_idx & -nex_idx
            
        return result
    
n,q = li()
bitree = BIT(n)

for _ in range(q):
    com, x, y = li()
    if com == 0:
        bitree.setval(x-1, y)
    else:
        print(bitree.getsum(y-1) - bitree.getsum(x-2))
        


Measured memory_bytes: 8148
import sys
input = sys.stdin.readline
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def solve():
  n,m,k = (int(i) for i in input().split())
  uff = UnionFind(n)
  ufb = UnionFind(n)
  query = [0]*n
  query2 = [[] for _ in range(n)]
  for i in range(m):
    a,b = (int(i)-1 for i in input().split())
    uff.union(a,b)
    query[a] += 1
    query[b] += 1
    query2[a].append(b)
    query2[b].append(a)
  for i in range(k):
    a,b = (int(i)-1 for i in input().split())
    if uff.same(a,b):
      ufb.union(a,b)
      query2[a].append(b)
      query2[b].append(a)
  for i in range(n):
    print(uff.size(i)-1-len(query2[i]), end=" ")
solve()

Measured memory_bytes: 32856
#include <iostream>
#include <algorithm>
#include <cmath>
#define rep(i, N) for(int i = 0; i < N; ++i)
#define MOD 1000000007ULL
using namespace std;

typedef long long ll;

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll counter[100001] = {};
int main()
{
    ll n, k;
    cin >> n >> k;

    ll ans = 0;
    for(ll i = k; i > 0; i--)
    {
        ll divCount = k / i;
        counter[i] = modpow(divCount, n, MOD);
        for (ll j = 2; j * i <= k; j++)
        {
            counter[i] += (MOD - counter[j*i]);
            counter[i] %= MOD;
        }
        // cout << i << ":" << counter[i] << endl;
        ans += (counter[i] * i) % MOD;
    }
    cout << ans % MOD << endl;
    return 0;
}


Measured memory_bytes: 4412
#include <iostream>
#include <stack>
#include <string>
using ll = long long;

int main() {
  std::string S;
  std::cin >> S;
  std::stack<int> K;
  int res{0};
  for (auto&& c : S) {
    K.push(c - '0');
    if (K.size() >= 2) {
      int a, b;
      a = K.top();
      K.pop();
      b = K.top();
      K.pop();
      if (a + b == 1)
        res += 2;
      else {
        K.push(b);
        K.push(a);
      }
    }
  }
  std::cout << res << std::endl;
  return 0;
}

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

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

    int a = stoi(s.substr(0,2));
    int b = stoi(s.substr(2,2));

    bool x = false, y = false;

    if(a > 0 && a <= 12) x = true;
    if(b > 0 && b <= 12) y = true;
    if(x && y) cout << "AMBIGUOUS" << endl;
    else if(x) cout << "MMYY" << endl;
    else if(y) cout << "YYMM" << endl;
    else cout << "NA" << endl;

    return 0;


}



Measured memory_bytes: 3596
/*input
5
3 2 2 4 1
1 2 2 2 1
*/

#include <iostream>

typedef long long ll;

ll a[2][101];

int main() {
	int n;
	std::cin >> n;
	for(int i = 0; i < 2; i++) {
		for(int j = 1; j <= n; j++) {
			std::cin >> a[i][j];
			a[i][j] += a[i][j - 1];
		}
	}
	ll ans = 0;
	for(int j = 1; j <= n; j++) {
		ans = std::max(ans, a[0][j] + a[1][n] - a[1][j - 1]);
	}
	std::cout << ans << '\n';
}

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

using namespace std;

#define ll long long
#define MoD 1e9 + 7
#define clear(a) memset(a, 0, sizeof(a))
#define fo(i, a, b) for(int i = a; i < b; i++)
//#define re(i, a, b) for(int i = b; i > a; i--)
#define pb(a) push_back(a)

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

double n, x, t;
void solve(){
	cin >> n>> x>> t;

	int ans= ceil(n/x)*t;
	cout << ans << '\n';
}

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

	int t=1;
	for(int i=1; i<=t; ++i) {
		solve();
	}

}


Measured memory_bytes: 3720
#include<iostream>
using namespace std;
int main(){
int n,a[100001]={0},vis[100001]={0},current=1,times=0,panda=0;
cin>>n;
for(int i=1;i<=n;i++){
	cin>>a[i];
}
while(current!=2){
	vis[current]=1;
	current=a[current];
	if(vis[current]==1){
		panda=1;
		cout<<-1;
		break;
	}
	times++;
}
if(panda==0)
cout<<times;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        System.out.println(c + " " + a + " " + b );

     }
}


Measured memory_bytes: 21716
N, Q = gets.chomp.split(' ').map(&:to_i)
S = gets.chomp
count_list = Array.new(N) { -1 }
count = 0
count_list[0] = count
(1..N).each do |i|
  prev = S[i - 1]
  ch = S[i]
  if prev == 'A' && ch == 'C'
    count += 1
  end
  count_list[i] = count
end

Q.times do
  l, r = gets.chomp.split(' ').map(&:to_i)
  # 1 to 0-origin
  l -= 1
  r -= 1
  puts count_list[r] - count_list[l]
end


Measured memory_bytes: 3324
#include<cstdio>
using namespace std;
typedef long long LL;
const int N=200005,p=1000000007;
int f[N],d[N],d2[N],i,j,k,n,m,K,g,an;
char c;

inline char getc()
{
	#define VV 10000000
	static char s[VV],*l=s,*r=s;
	if (l==r)
		l=s,r=s+fread(s,1,VV,stdin);
	return l==r?0:*l++;
}

int read(){ int z=0; do c=getc(); while (c<'0'||c>'9'); while (c>='0'&&c<='9') z*=10,z+=c-'0',c=getc(); return z; }

void minus(int &a,int b){ a-=b,a+=a<0?p:0; }

int power(int z,int k)
{
	int d=1;
	for (;k;z=(LL)z*z%p,k>>=1) if (k&1) d=(LL)d*z%p;
	return d;
}

int main()
{
	n=read(),K=read();
	for (i=1;i*i<n;++i)
		if (!(n%i))
			d[++g]=i,d2[++d2[0]]=n/i;
	if (i*i==n) d[++g]=i;
	for (i=d2[0];i;--i) d[++g]=d2[i];
	for (i=1;i<=g;++i)
	{
		f[i]=power(K,d[i]+1>>1);
		for (j=1;j<i;++j)
			if (!(d[i]%d[j]))
				minus(f[i],f[j]);
		an=(an+(d[i]&1?(LL)f[i]*d[i]:(LL)f[i]*d[i]>>1))%p;
	}
	printf("%d\n",an);
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int l = a + b, r = c + d;
    if (l > r)
        cout << "Left" << endl;
    else if (l == r)
        cout << "Balanced" << endl;
    else
        cout << "Right" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>

using namespace std;

const int MAXN = 105;

int n,ans;
int a[MAXN]; 

int main()
{
	cin >> n;
	for (int i = 1;i <= n;i++)
		cin >> a[i];
	int cnt = 1;
	for (int i = 2;i <= n;i++)
		if (a[i] != a[i - 1])
			ans += cnt / 2,cnt = 1;
		else
			cnt++;
	ans += cnt / 2;
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define debug int debug = 0;
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<int, Pi> V;
typedef vector<int> VE;
const ll mod = 1000000007; //10^9+7

int n,v,ox,oy;
int h, w;
int cost[210][210];//cost[i][j],(i,j)へのコスト
int d[210][210];//d[i][j],(i,j)までにかかる最小コスト
bool used[210];//used[i],iを使ったかどうか
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


//2次元ダイクストラ
int diskstra(int y,int x){
    REP(i,h)REP(j,w)d[i][j]=mod;
    priority_queue<V,vector<V>,greater<V> >que;
    que.push(make_pair(0,make_pair(y,x)));
    d[y][x]=0;
    while(!que.empty()){
        auto c=que.top().first;
        auto now=que.top().second;
        que.pop();

        REP(i,4){
            int ny=now.first+dy[i];
            int nx=now.second+dx[i];
            if(ny<0||ny>=h||nx<0||nx>=w)continue;
            if(d[ny][nx]<=c+cost[ny][nx])continue;
            d[ny][nx]=c+cost[ny][nx];
            que.push(make_pair(d[ny][nx],make_pair(ny,nx)));
        }
    }
}

int main() {
    string s[52];
    int white = 0;
    int black = 0;
    cin >> h >> w;
    REP(y, h){
        cin >> s[y];
        REP(x, w){
            if(s[y][x] == '.'){
                white++;
                cost[y][x] = 1;
            }else{
                black++;
                cost[y][x] = mod;
            }
        }
    }
    diskstra(0, 0);
    if(d[h - 1][w - 1] == mod){
        print(-1);
    }else{
        print(white - d[h - 1][w - 1] - 1);
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#define eps 0.0000000001
#define maxn 1000009
#define inf 0x3f3f3f3f
#define mod 1000000007
#define ll long long
using namespace std;
//int T,cas=1;
ll dp[maxn*3];
ll n;
int main()
{
    //freopen("d:\\in.txt","r",stdin);
    //scanf("%d",&T);
    //while(cas<=T)
    //{
    //    cas++;
    //}
    scanf("%lld",&n);
    for(int i=n+1;i<=2*n+1;i++)
        dp[i]=1;
    dp[n]=n;
    ll sum=n+n;
    for(int i=n-1;i>=1;i--)
    {
        dp[i]=(sum-dp[i+2]+(n-1)*(n-1)%mod+mod)%mod;
        sum=(sum+dp[i])%mod;
        sum=(sum-dp[i+n+1])%mod;
    }
    printf("%lld\n",dp[1]);
    return 0;
}


Measured memory_bytes: 16640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    static int N;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();

        if( N == 1 ) {
            System.out.println("Hello World");
        } else {
            int a = sc.nextInt();
            int b = sc.nextInt();
            System.out.println( a + b );
        }
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

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

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

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

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

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 21972
import java.util.Scanner;

public class Main {

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

		String str, str2;
		while (true) {
			str = sc.next();
			if (str.equals("-"))
				break;
			str2 = "";
			int shuffulNum = sc.nextInt();
			for (int i = 0; i < shuffulNum; i++) {
				int n = sc.nextInt();
				for (int j = n; j < str.length(); j++) {
					str2 += str.charAt(j);
				}
				for (int j = 0; j < n; j++) {
					str2 += str.charAt(j);
				}
				str = str2;
				str2 = "";
			}
			System.out.println(str);
		}
	}
}

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

int n;
string arr[100005],x,pre;

int main(){
	scanf("%d",&n);
	for(int i =0;i<n;i++){
		cin>>x;
		sort(x.begin(),x.end());
		arr[i] = x;
	}
	sort(arr,arr+n);
	pre = arr[0];
	long long c= 0, ans = 0;
	for(int i =0;i<n;i++){
		if(pre==arr[i]){
			c++;
		} else {
			ans += (c*(c-1)/2);
			c = 1;
		}
		pre = arr[i];
	}
	ans += (c*(c-1)/2);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

const int mod = 1000000007;
class mint {
  long long x;

 public:
  mint(long long n = 0) : x((n % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint& a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint& a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint& a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint& a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint& a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint& a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint& a) { return (*this) *= a.inv(); }
  mint operator/(const mint& a) const {
    mint res(*this);
    return res /= a;
  }

  friend ostream& operator<<(ostream& os, const mint& m) {
    os << m.x;
    return os;
  }
};

mint pow(mint a, long long b) { return a.pow(b); }
mint pow(mint a, int b) { return a.pow((long long)b); }

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

  mint tenn = ((mint)10).pow(n);
  mint ninen = ((mint)9).pow(n);
  mint eightn = ((mint)8).pow(n);

  mint ret = tenn - ninen * 2 + eightn;
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 3604
#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)
int main(){
    int n;cin>>n;
    int a[3][n];
    REP(i,3)REP(j,n)cin>>a[i][j];
    REP(i,3) sort(a[i],a[i]+n);
    long int s=0;
    REP(i,n)s+=(lower_bound(a[0],a[0]+n,a[1][i])-a[0])*(a[2]+n-upper_bound(a[2],a[2]+n,a[1][i]));
    cout<<s<<endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 305
//#define INF 1000000005LL
#define INF 1e18
#define MOD 1000000007

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

ll d[SIZE][SIZE];
int V;

void warshall_floyd_init(){
  fill(d[0],d[SIZE],INF);
  rep(i,0,SIZE) d[i][i] = 0;
}

//trueなら負の閉路が存在,0_indexed
bool warshall_floyd(){
  rep(k,0,V) rep(i,0,V){
    if(d[i][k]==INF)continue;
    rep(j,0,V){
      if(d[k][j]==INF)continue;
      d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
    }
  }
  rep(i,0,V) if(d[i][i] < 0) return true;
  return false;
}

void add_edge(int a,int b,ll c){
  d[a][b] = c;
  d[b][a] = c;
}

int n;
ll a[SIZE][SIZE];

int main(){

  cin >> n;
  V=n;
  warshall_floyd_init();
  rep(i,0,n) rep(j,0,n){
    cin >> a[i][j];
    if(i>j)add_edge(i,j,a[i][j]);
  }
  warshall_floyd();
  rep(i,0,n) rep(j,0,n){
    if(d[i][j] != a[i][j]){
      cout << -1 << endl;
      return 0;
    }
  }

  ll ans=0;
  rep(i,0,n) rep(j,i+1,n) {
    bool t = true;
    rep(k,0,n){
      if(k==i || k==j)continue;
      if(d[i][k] + d[k][j] == d[i][j])t=false;
    }
    if(t)ans += d[i][j];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1664
A, B, H, M = map(int,input().split())

M2 = 12 * M / 60
H2 = H + M/60
theta = abs(H2-M2) / 12 * 360
#if theta >= 180:
#  theta = 360 - theta
#print(theta)

import math
c = A**2 + B**2 - 2*A*B*math.cos(theta*math.pi/180)
print(c**0.5)

Measured memory_bytes: 9516
function Main(input) {
  var a = 0;
  var n = parseInt(input);
  if(n%2 === 1) {
    a = 2 * n;
  }
  else if(n%2 == 0) {
    a = n;
  }
  console.log(a)
  return 0;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"))

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

using namespace std;

#ifdef KACTL
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
#endif
#define all(x) begin(x), end(x)

using ll = int64_t;
using ld = long double;
using pii = pair<int32_t, int32_t>;
using vi = vector<int32_t>;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    string s;
    cin >> s;

    vi has(26, 0);
    for (char c : s) 
        has[c - 'a'] = true;

    int nxt = 0;
    while (nxt < 26 and has[nxt])
        ++nxt;

    if (nxt < 26) {
        s += (char)('a' + nxt);
        cout << s << '\n';
        return 0;
    }

    // we are at exactly 26 letters.

    if (s == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1 << '\n';
        return 0;
    }

    while (true) {
        int v = s.back() - 'a';
        has[v] = false;
        s.pop_back();

        int u = v + 1;
        while (u < 26 and has[u]) {
            ++u;
        }

        if (u < 26) {
            s += (char)('a' + u);
            cout << s << '\n';
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <sstream>
using namespace std;

typedef long long LL;
#define lowbit(x) ((x)&(-x))
#define INF 0x3f3f3f3f
#define memset(a,b) memset(a,b,sizeof(a))
#define	GE() printf(">----------\n")
#define	IN() freopen("in.txt","r",stdin)
#define	OUT() freopen("out.txt","w",stdout)
const int mod=1000000007;
const int inf=0x3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-8;
const int maxn=100005;

int n, data[maxn], vis[maxn];

int main()
{
    while(~scanf("%d", &n)){
        for(int i=1;i<=n;i++){
            scanf("%d", &data[i]);
        }
        memset(vis, 0);
        int ans=0, now=1;
        while(now!=2){
            ans++;
            if(vis[data[now]]){
                ans=0;
                break;
            }
            vis[data[now]]++;
            if(now==data[now])ans=1;
            now=data[now];
        }
        printf("%d\n", ans?ans:-1);
    }
    return 0;
}



Measured memory_bytes: 1024
using System;
using System.Linq;

namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
      int A=int.Parse(Console.ReadLine());
      int B=int.Parse(Console.ReadLine());
      int C=int.Parse(Console.ReadLine());
      int X=int.Parse(Console.ReadLine());
      int ans=0;
      for(int i=0;i<=A;i++){
        for(int j=0;j<=B;j++){
          for(int k=0;k<=C;k++){
            if((i*500+j*100+k*50)==X){
              ans++;
            }
          }
        }
      }
      Console.WriteLine(ans);
    }
    
  }

}



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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int N, Q; cin >> N >> Q;
  vector<vector<int>> G(N);
  rep(i, N-1) {
    int a, b; cin >> a >> b; a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<ll> val(N);
  rep(i, Q) {
    int p, x; cin >> p >> x; p--;
    val[p] += x;
  }
  auto dfs = [&](auto dfs, int u, int p) -> void {
    for (int v : G[u]) if (v != p) {
      val[v] += val[u];
      dfs(dfs, v, u);
    }
  };
  dfs(dfs, 0, -1);
  rep(i, N) cout << val[i] << (i == N - 1 ? '\n' : ' ');
}

Measured memory_bytes: 21888
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
    int A,B,C;
    cin >>A>>B>>C;
    int m=max(A,max(B,C));
    cout << 9*m+A+B+C;
}

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

int main(){
    string n;

    cin >> n;
  
  int i;
  
  for(i=0;i<n.length();i++){
    if(n[i]=='?') n[i]='D';
  }
  
  cout << n << endl;
}

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

using namespace std;

#define endl '\n'

typedef long long int64;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
const int maxn = 100000 + 10;

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

    int n; cin >> n;

    int64 answer = 0, last = -1;

    for (int i = 0; i < n; ++i){
        int64 v; cin >> v;

        if (v > last + 1){
            cout << -1 << endl;
            return 0;
        }

        if (v != last + 1)
            answer += last;

        last = v;
    }

    cout << answer + last << endl;

    return 0;
}

Measured memory_bytes: 256
n, m = [int(_) for _ in input().split()]
A = [[int(_) for _ in input().split()] for _ in range(n)]
B = [int(input()) for _ in range(m)]

for Ai in A:
    ans = 0
    for a, b in zip(Ai, B):
        ans += a * b
    print(ans)



Measured memory_bytes: 6012
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using P = pair<int,int>;
using ll = long long;
using namespace std;
int main(void){
    int n, k;
    cin >> n >> k;
    int a[n];
    rep(i, n) cin >> a[i];
    sort(a, a + n);
    int sum = 0;
    rep(i, k) sum += a[i];
    
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3616
#include "bits/stdc++.h"

using namespace std;


#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 rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define int long long

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

template <typename T>
void print(T x)
{
	std::cout << x <<" " ;
}


template <typename T>
void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int N;
	cin >> N;
	string s;
	cin >> s;
	
	if (N >= 3200) {
		cout << s << endl;
	}
	else {
		cout << "red" << endl;
	}

}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from bisect import bisect_left
import sys,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
tmp = n-1 if n%2 else n
m = (n**2 - (n+tmp))//2
print(m)
for i in range(1,n+1):
    for j in range(1,n+1):
        if i == j or i>j : continue
        if i+j == tmp+1: continue
        print(i,j)

Measured memory_bytes: 68076
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>=n;i--)
#define INF 999999999
#define INF_M 2147483647
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
 
int main() {
 	int a,b,c;
 	while(cin >> a >> b >> c) {
 		int cnt = 0;
 		rep(i,1,11) {
 			if(i == a || i == b || i == c) continue;
 			if(a + b + i <= 20) cnt++;
 		}
 		if(cnt / 7.0 >= 0.5) cout << "YES" << endl;
 		else cout << "NO" << endl;
 	}
    return 0;
}

Measured memory_bytes: 1148