akhauriyash/Code-Regression huggingface dataset:
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

// code
// ------------------------------------------------
int main()
{

  ll n,m;
  cin >> n >> m;

  vll l(n,0),r(n+1,0);

  rep(i,m)
  {
    ll a,b;
    cin >> a >> b;

    l[a-1]++;
    r[b]++;
  }

  ll imo = 0;
  ll cnt = 0;
  rep(i,n)
  {
    imo += l[i] - r[i];
    if(imo >=  m) cnt++;
  }

  cout << cnt << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


int d[3] = {-1,0,1};
int main(){
    int n;cin>>n;
    VEC(int,t,n);
    int m;cin>>m;
    vector<P>p;
    rep(i,m){
        int a,b;cin>>a>>b;
        a--;
        int res = 0;
        rep(i,n){
            if(i==a)res += b;
            else res += t[i];
        }
        cout<<res<<endl;
    }

}



Measured memory_bytes: 256
using System;

class _0052 {
    public static void Main() {
        int n, sum;

        while ((n = int.Parse(Console.ReadLine())) != 0) {
            sum = 0;
            for (float b = 5; b <= n; b *= 5)
                sum += (int)(n / b);
            Console.WriteLine(sum);
        }
    }
}

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

int main(){
    int N, K;
    string S;
    cin >> N;
    cin >> S;
    cin >> K;
    for(int i = 0; i < N; i++){
        if(S[i] != S[K - 1]) S[i] = '*';
    }
    cout << S << endl;
}

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

long long n;

int main() {
	cin >> n;
	long long ans = 0;
	for (int i = 1; i <= n; i++)
	{
		long long a = n / i;
		ans += a * (a + 1) / 2 * i;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3628
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int H, N;
vector<int> A, B;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> H >> N;
  A.resize(N);
  B.resize(N);
  for (int i = 0; i < N; i++) {
    int ai, bi;
    cin >> ai >> bi;
    A[i] = ai;
    B[i] = bi;
  }

  vector<int> dp(10001, INF);
  dp[0] = 0;
  for (int i = 0; i < H; i++) {
    if (dp[i] == INF) {
      continue;
    }
    for (int j = 0; j < N; j++) {
      int h = min(H, i + A[j]);
      dp[h] = min(dp[h], dp[i] + B[j]);
    }
  }

  int ans = dp[H];
  cout << ans << endl;
  return 0;
}


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

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

struct Node{
  ll x;
  vector<int> child;
  Node() : x(0), child(vector<int>(0, 0)) {}
};

vector<Node> t;

P solve(ll now){
  vector<P> ret;
  for(int c : t[now].child){
    ret.push_back(solve(c));
    if(ret.back().first == -1)
      return P(-1, -1);
  }
  vector<vector<int>> dp(t[now].child.size()+1, vector<int>(5001));
  dp[0][0] = 1;
  ll sum = 0;
  for(int i=0; i<ret.size();i++){
    ll x,y;
    tie(x, y) = ret[i];
    sum += x + y;
    for(int from=5000; from>=0; from--){
      if(from + x <= 5000)
        dp[i+1][from + x] |= dp[i][from];
      if(from + y <= 5000)
        dp[i+1][from + y] |= dp[i][from];
    }
  }
  ll use = -1;
  for(int i = t[now].x; i>=0; i--)
    if(dp.back()[i]){
      use=i;
      break;
    }
  if(use == -1)
    return P(-1, -1);
  else{
    //cout << now << ": " << t[now].x << " " << sum - use << endl << endl;
    return P(t[now].x, sum - use);
  }
}

int main(){
  ll N;
  cin >> N;
  t.resize(N);
  for(int i=1;i<N;i++){
    ll p;
    cin >> p;
    p--;
    t[p].child.push_back(i);
  }
  for(int i=0;i<N;i++){
    ll x;
    cin >> x;
    t[i].x = x;
  }
  P ans = solve(0);
  if(ans == P(-1, -1))
    cout << "IMPOSSIBLE" << endl;
  else
    cout << "POSSIBLE" << endl;
  return 0;
}


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

int n,a[100010],ans;
bool b[100010];

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	
	for(int t=0;t<10;t++)
		for(int i=1;i<=n;i++)
		{
			int cur=0;bool f=0;
			while(i<=n&&a[i]==i&&a[i+1]!=i&&a[i]!=i+1) swap(a[i],a[i+1]),i++,cur++,f=1;
			if(f) i--,ans=ans+(cur==1?1:cur-1);
		}
	
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    long a,b,k;

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

    if((a+b)%2==0)
    {
        k=(a+b)/2;
        printf("%d\n",k);
    }
    else
    {
        printf("IMPOSSIBLE\n");
    }
    return 0;
}

Measured memory_bytes: 128
def main():
    n,k=map(int,input().split())
    h=list(map(int,input().split()))
    dp=[None]*n
    temp=[1001]*n
    dp[0]=0
    dp[1]=abs(h[1]-h[0])
    for i in range(2,n):
        low=i-k-1
        if low<0:
            low=-1
        for j in range(i-1,low,-1):
            temp[j]=dp[j]+abs(h[i]-h[j])
            if j==i-1:
                mn=temp[j]
            else:
                if mn > temp[j]:
                    mn=temp[j]
        # temp2=dp[i-2]+abs(h[i]-h[i-2])
        # temp1=dp[i-1]+abs(h[i]-h[i-1])
        dp[i]=mn
        #temp=[1001]*n
    print(dp[n-1])

if __name__=='__main__':
    main()


Measured memory_bytes: 52832
while 1:
    a=list(map(int,input().split()))
    if a[0]==0:break
    b,c=0,0
    for i in a:
        if i>=10: b+=10
        else:b+=i
        if i==1:c+=1
    while c:
        if b+10<=21:b+=10
        c-=1
    print(0 if b>21 else b)

Measured memory_bytes: 7536
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll n,k,l,m;
	cin >> n >> k;
	vector<P> a(n);
	for(ll i = 0; i < n; i++) {
		cin >> l>>m;
		a[i] = mp(l,m);
	}
	sort(ALL(a));
	ll sum = 0;
	ll ans;
	for(ll i = 0; i < n; i++) {
		sum += a[i].sc;
		if (sum >= k){
			ans = a[i].fs;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
        using namespace std;
        int main()
        {
          int H,N,i,sum=0;
	cin>>H>>N;
        
          for(i=1;i<=N;i++)
          {
            int x;
		cin >> x;
            sum=sum+x;
          }
          if(sum<H)

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vi vector<int>


ll gcd(ll x, ll y){
  ll smaller=min(x,y);
  ll bigger=max(x,y);
  
  if (bigger%smaller==0){
    return smaller;
  }
  else {
    return gcd(smaller,bigger%smaller);
  }
}






int main(){


  ll a,b;
  cin>>a>>b;
  
  ll answer=(a/gcd(a,b))*b;
  
  cout<<answer<<endl;
  
  
      
    
  
  
  
  
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
  char s[4];
  scanf("%s",s);
  char wk[7][4]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
  int i=0;
  while(strcmp(s,wk[i])!=0)i++;
  printf("%d\n",7-i);
  return(0);  
}

Measured memory_bytes: 256
#include "stdio.h"

int main()
{
    int N;
    scanf("%d", &N);
    long sum = 0;
    for (long i = 1; i < N + 1; i++)
    {
        if (i % 3 == 0 || i % 5 == 0)
        {
            continue;
        }
        sum += i;
    }
    printf("%ld\n", sum);
}

Measured memory_bytes: 1736
from sys import stdin
from collections import defaultdict

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

mod = 10 ** 9 + 7
g = defaultdict(int)

for i in range(N):
    tmp = 1
    a = A[i]
    g_tmp = defaultdict(int)
    while tmp <= A[i] ** 0.5:
        while tmp > 1 and a % tmp == 0:
            a //= tmp
            if tmp not in g_tmp:
                g_tmp[tmp] = 1
            else:
                g_tmp[tmp] += 1
        tmp += 1
    if a > 1:
        if a not in g_tmp:
            g_tmp[a] = 1
        else:
            g_tmp[a] += 1
    for j in g_tmp:
        if j not in g:
            g[j] = g_tmp[j]
        else:
            g[j] = max(g[j], g_tmp[j])

l = 1
ans = 0
for i in g:
    l *= pow(i, g[i], mod)
    l %= mod
for a in A:
    ans += l * pow(a, mod - 2, mod)
    ans %= mod

print(ans)

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

using namespace std;

pair<int, pair<int, int> > edge[100000];
int N, B[1000][1000], A[1000][1000];

int main() {
  cin >> N;
  int M = 0;
  for(int i = 1; i <= N; i++) {
    for(int j = 1; j <= N; j++) {
      cin >> A[i][j];
      if (i != j) {
        edge[++M] = make_pair(A[i][j], make_pair(i, j));
      }
    }
  }
  sort(1 + edge, 1 + M + edge);
  for(int i = 1; i <= N; i++) {
    for(int j = 1; j <= N; j++) {
      B[i][j] = A[i][j];
    }
  }
  for(int k = 1; k <= N; k++) {
    for(int i = 1; i <= N; i++) {
      for(int j = 1; j <= N; j++) {
        B[i][j] = min(B[i][j], B[i][k] + B[k][j]);
      }
    }
  }
  for(int i = 1; i <= N; i++) {
    for(int j = 1; j <= N; j++) {
      if (B[i][j] != A[i][j]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for(int i = M; i >= 1; i--) {
    int u = edge[i].second.first, v = edge[i].second.second;
    for(int k = 1; k <= N; k++) {
      if (B[u][k] > 0 && B[k][v] > 0 && B[u][v] > 0 && B[u][v] == B[u][k] + B[k][v]) {
        B[u][v] = -1;
        B[v][u] = -1;
      }
    }
  }
  long long res = 0;
  for(int i = 1; i <= N; i++) {
    for(int j = 1; j <= N; j++) {
      res += max(B[i][j], 0);
    }
  }
  cout << res / 2 << endl;
  return 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    cout << (a-1)*(b-1);
    
    return 0;
}

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

namespace ABC126
{
    class C
    {
        static void Main(string[] args)
        {
            List<int> list = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            int N = list[0], K = list[1];

            double sw = 0;
            for (int i = 1; i <= N; i++)
            {
                int x = i;
                int counter = 0;
                while (x < K)
                {
                    counter++;
                    x *= 2;
                }

                sw += 1 / Math.Pow(2, counter);
            }

            double r = sw / N;
            Console.WriteLine(r);
        }

    }
}


Measured memory_bytes: 13268
def gcd(a, b):
    while b>0:
        a, b = b, a % b
    return a

n, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
dx = [abs(x[i]-x[i+1]) for i in range(n)]

for i in range(n):
    if i==0:
        tmp = dx[0]
    else:
        tmp = gcd(tmp, dx[i])
print(tmp)

Measured memory_bytes: 14252
import java.util.*;

public class Main {

    static int a,b;


    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        List<Integer> list = new ArrayList<Integer>();
        while(true){
            a=sc.nextInt();
            b=sc.nextInt();
            if(a==0&&b==0){
                break;
            }
            int sum = 0;
            for(int i=1;i<=a-2;i++){
                for(int j=i+1;j<=a-1;j++){
                    for(int k=j+1;k<=a;k++){
                        if(i+j+k==b){
                            sum++;
                        }
                    }
                }
            }
            list.add(sum);
        }
        sc.close();
        for(int i=0;i<list.size();i++){
            System.out.println(list.get(i));
        }


    }
}



Measured memory_bytes: 26588
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int h,w;
vector<vector<int>> d(400,vector<int>(400,1000));
void wf(){rep(k,h*w) rep(i,h*w) rep(j,h*w) d.at(i).at(j) = min(d.at(i).at(j), d.at(i).at(k) + d.at(k).at(j));}

int main() {
  int ans=0;
  cin >> h >> w;
  vector<char> s(h*w);
  for(int i=0;i<h*w;i++) cin >> s[i];
  for(int i=0;i<h*w;i++) d[i][i] = 0;
  for(int i=0;i<h;i++){
    for(int j=0;w>1 && j<(w-1);j++){
      if (s[i*w+j] == '.' && s[i*w+j+1] == '.'){
        d[i*w+j][i*w+j+1] = 1;
        d[i*w+j+1][i*w+j] = 1;
      }
    }
  }
  for(int i=0;i<w;i++){
    for(int j=0;h>1 && j<(h-1);j++){
      if (s[j*w+i] == '.' && s[j*w+i+w] == '.'){
        d[j*w+i][j*w+i+w] = 1;
        d[j*w+i+w][j*w+i] = 1;
      }
    }
  }
  wf();
  for(int i=0;i<h*w;i++) for(int j=0;j<h*w;j++) if(d[i][j] < 401) ans = max(ans,d[i][j]);
  cout << ans << endl;
}


Measured memory_bytes: 896
#include<iostream>
using namespace std;
int main(){
  int x;
  int a=0,c=0;
  cin>>x;
  for(int i=0;i<1000000000;i++){
    a++;
    c+=a;
    if(c>=x){
      cout<<a<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long N,Y;
    cin>>N>>Y;
    bool check=false;
    for(int i=0;i<=N;i++){
        for(int j=0;j<=N-i;j++){
            int k=N-i-j;
            if((10000*i+5000*j+1000*k)==Y){check=true; cout<<i<<' '<<j<<' '<<k; break;}
        }
        if(check){break;}
    }
    if(!check){cout<<-1<<' '<<-1<<' '<<-1;}
    return 0;
}


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

typedef long long ll;

int main() {
    ll n,count=0;
    cin >> n;
    vector<ll> A(n-1);
    map<ll,ll> cntmap;
    for(ll i=0; i<n-1; ++i)
        cin >> A.at(i);

    sort(A.begin(), A.end());

    ll last = A.at(0);

    for(ll i=0; i<n-1; ++i) {
        if (last == A.at(i)) {
            ++count;
        }
        else {
            cntmap[last] = count;
            last = A.at(i);
            count = 1;
        }

        if (i == n-2) {
            cntmap[last] = count;
        }
    }

    for (ll i=1; i<=n; ++i) {
        if (cntmap.count(i) != 0)
            cout << cntmap[i] << endl;
        else
            cout << 0 << endl;
    }
}


Measured memory_bytes: 17152
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Prime Number II
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		int N = 50000;
		int overN;
		boolean[] prims;

		// prim number of over 50000
		for (int i = N + 1; ; i++) {
			int count = 0;
			for (int j = 2; j < i; j++) {
				if (i % j == 0) {
					count++;
				}
			}
			if (count == 0) {
				overN = i;
				break;
			}
		}

		prims = new boolean[overN + 1];
		for (int i = 2; i < overN / 2 + 1; i++) {
			if (!prims[i]) {
				for (int j = 2; j < overN / i + 1; j++) {
					prims[i * j] = true;
				}
			}
		}

		int primU = 0, primL = 0;
		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = Integer.parseInt(line);
			//U
			for (int i = n + 1; ; i++) {
				if (!prims[i]) {
					primU = i;
					break;
				}
			}
			//L
			for (int i = n - 1; ; i--) {
				if (!prims[i]) {
					primL = i;
					break;
				}
			}
			System.out.println(primL + " " + primU);
		}
	}
}

Measured memory_bytes: 19480
#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(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, k, a[200008];

ll f(ll i, ll mid){
	ll res;
	if(a[i] < 0){
		if(a[i]*a[0] <= mid){return n-1;}
		if(a[i]*a[n-1] > mid){return 0;}
		
		ll yes = n-1;
		ll no = 0;
		while(yes-no > 1){
			ll m = (yes+no)/2;
			if(a[i]*a[m] <= mid){
				yes = m;
			}
			else{
				no = m;
			}
		}
		
		res = n-yes;
		if(yes <= i){res--;}
	} 
	else{
		if(a[i]*a[0] > mid){return 0;}
		if(a[i]*a[n-1] <= mid){return n-1;}
		
		ll yes = 0;
		ll no = n-1;
		while(no-yes > 1){
			ll m = (yes+no)/2;
			
			if(a[i]*a[m] <= mid){
				yes = m;
			}
			else{
				no = m;
			}
		}
		
		res = yes+1;
		if(yes >= i){
			res--;
		}
	}
	return res;
}

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

	cin >> n >> k;
	zep(i, 0, n){cin >> a[i];}
	sort(a, a+n);
	
	ll ok = 1e18;
	ll ng = -1e18-1;
	while(ok-ng > 1){
		ll mid = (ok+ng)/2;
		
		ll sm = 0;
		zep(i, 0, n){
			sm += f(i, mid);
		}
		sm /= 2;
		
		if(sm >= k){ok = mid;}
		else{ng = mid;}
	}
	print(ok)
	//print(f(3, -12))
	return 0;
}

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

int main(void){
    int a, b;
    cin >> a >> b;
    if(a<=0 && b>=0)
        cout<< "Zero" << endl;
    else if(a>0)
        cout << "Positive" << endl;
    else{
        int c = abs(a),d = abs(b);
        if((c%2 == 0 && d%2 == 0 )||(c%2 != 0 && d%2 != 0))
            cout << "Negative" << endl;
        else
            cout << "Positive" << endl;
    }  
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        char[] list=br.readLine().toCharArray();
        char a='A';
        int sum=0;
        for(int i=0;i<list.length;i++){
            if(list[i]<=a){
                sum++;
            }
            a=list[i];
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 24332
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int n;
ll k, a[100500];

int main(){

scanf("%d %lld", &n, &k);

ll g = 0;

for(int i=1;i<=n;i++){
	scanf("%lld", &a[i]);
	g = __gcd(g, a[i]);
}

if(*max_element(a + 1, a + n + 1) < k){
	cout << "IMPOSSIBLE";
}
else{
	if(g <= k && k % g == 0)cout << "POSSIBLE";
	else cout << "IMPOSSIBLE";
}
return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		char a=scan.next().charAt(0);
		char b=scan.next().charAt(0);
		if(a=='H' && b!='D') System.out.println("H");
		else if(b=='H' && a!='D') System.out.println("H");
		else if(a=='D' && b=='D') System.out.println("H");
		else System.out.println("D");
	}

}


Measured memory_bytes: 26776
package main

import (
	"fmt"
)

func main() {
	var a, b, n int
	fmt.Scan(&a, &b, &n)
	p := a / b
	q := a % b
	var c int
	if n < b {
		c = n
	} else {
		c = b - 1
	}
	r := c * q / b
	fmt.Println(p*c + r)
}


Measured memory_bytes: 1752
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mx 1000000000
#define ll long long


ll bigMod(ll n,ll p){
    if(p==0) return 1;
    if(p%2==0){
       ll ret=bigMod(n,p/2);
       return ((ret%mod)*(ret%mod))%mod;
    }
    else return ((n%mod)*(bigMod(n,p-1)%mod))%mod;
}

ll modInverse(ll n){
   return bigMod(n,mod-2);
}

ll nCr(ll n,ll r){
    if(r>n) return 0;
    ll ans=1;

    for(int i=1;i<=r;i++) (ans=ans*(n-i+1)%mod*modInverse(i)%mod)%mod;
    return ans;
}

int main(){
    ll n,a,b;
    ll c1,c2,c;
    scanf("%lld %lld %lld",&n,&a,&b);


    c=bigMod(2,n)-nCr(n,a)-nCr(n,b)-1;
    c=(c%mod+mod)%mod;
    printf("%lld\n",c);

return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N;
    cin >> N;
    vector<long long> a(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    vector<long long> b(N);//各山に降った雨の1/2
    long long ub = 1e10, lb = 0;
    vector<long long> c(N);
    for(int i = 0; i < N; i++){
        if(i % 2 == 0) c[i] = 1;
        else c[i] = -1;
    }
    while(true){
        int flag = 0;
        long long cen = (ub + lb) / 2;
        for(int i = 0; i < N; i++){
            if(i == 0) b[i] = cen;
            else b[i] = a[i - 1] - b[i - 1];
            if(b[i] < 0 && c[i] != c[0]){
                ub = cen;
                flag = 1;
                break;
            }
            else if(b[i] < 0 && c[i] == c[0]){
                lb = cen;
                flag = 1;
                break;
            }
            if(i == N - 1){
                long long t = a[i] - b[i];
                if(t < 0){
                    ub = cen;
                    flag = 1;
                }
            }
        }
        if(flag == 0){
            if(b[0] < a[N - 1] - b[N - 1]) lb = cen;
            else if(b[0] > a[N - 1] - b[N - 1]) ub = cen;
            else break;
        }
    }
    for(int i = 0; i < N; i++){
        if(i < N - 1) cout << b[i] * 2 << ' ';
        else cout << b[i] * 2 << endl;
    }
}

Measured memory_bytes: 3712
n=int(input())
d=[]
ok=False
for i in range(n):
    l=list(map(int,input().split()))
    d.append(l)
for i in range(n-2):
    if d[i][0]==d[i][1] and d[i+1][0]==d[i+1][1] and d[i+2][0]==d[i+2][1]:
        ok=True
if ok:
    print('Yes')
else:
    print('No')

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

const int N = 2022;
int n, m, u[N], v[N], col[N], ans = 0;
vector<int> G[N];
vector<pair<int, int>> E[N];

int dep[N], fa[N], has[N][N], ig[N];
vector<pair<int, int>> cov[N];
inline void dfs1(int x, int pre) {
  dep[x] = dep[pre] + 1;
  fa[x] = pre;
  for (auto y : G[x]) if (y != pre) {
    dfs1(y, x);
  }
}
inline void label(int x, int y, int id) {
  while (x != y) {
    if (dep[x] >= dep[y]) {
      has[x][id] = 1;
      cov[x].emplace_back(id, 1);
      x = fa[x];
    } else {
      has[y][id] = 1;
      cov[y].emplace_back(id, 0);
      y = fa[y];
    }
  }
}
inline void dfs2(int x) {
  for (auto y : G[x]) if (y != fa[x]) {
    dfs2(y);
  }
  if (x != 1) {
    ans += (cov[x].size() >= 1) + (cov[x].size() >= 2);
    if (ig[x] || cov[x].size() < 2) return;
    int p = cov[x][0].first, q = cov[x][1].first;
    E[p].emplace_back(q, cov[x][0].second == cov[x][1].second);
    E[q].emplace_back(p, cov[x][0].second == cov[x][1].second);
    for (int y = 2; y <= n; y++) {
      if (has[y][p] && has[y][q]) {
        ig[y] = 1;
      }
    }
  }
}
inline void dfs3(int x) {
  for (auto y : E[x]) if (!~col[y.first]) {
    col[y.first] = col[x] ^ y.second;
    dfs3(y.first);
  }
}

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, x, y; i < n; i++) {
    scanf("%d%d", &x, &y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  dfs1(1, 0);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &u[i], &v[i]);
    label(u[i], v[i], i);
  }
  dfs2(1);
  printf("%d\n", ans);
  memset(col, -1, sizeof col);
  for (int i = 1; i <= m; i++) {
    if (!~col[i]) {
      col[i] = 0;
      dfs3(i);
    }
    if (col[i]) {
      printf("%d %d\n", v[i], u[i]);
    } else {
      printf("%d %d\n", u[i], v[i]);
    }
  }
}


Measured memory_bytes: 28928
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORX(i, a, b, x) for (int i = (a); i <= (b); i+=x)
#define debug(x) cerr << #x << " is= " << x << endl; //use for debugging
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 5] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
 
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
 
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define mp(a,b) make_pair(a,b)
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long int
#define vi         vector<int>
#define vll        vector<ll>
#define vpii       vector<pair<int,int>>
#define vov        vector<vector<int>> 
#define pr         pair<int,int>
#define vpll       vector<pair<ll,ll>>
#define all(v)     v.begin(),v.end()
#define rall(v)    v.rbegin(),v.rend()  //reverse of above;
#define sz(container) int((container).size())
#define cut(x) {cout<<x<<"\n"; return;}
#define setprec(x) cout << fixed << showpoint << setprecision(8)<<x<<endl;
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define time cout << clock() / double(CLOCKS_PER_SEC) << endl;
#define endl "\n"
#define mod 1000000007
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
//*s.find_by_order() ->returns an iterator to the k-th largest element (counting from zero);
//s.order_of_key() ->number of elements strictly smaller then our item;
//st.rbegin()->second; last element in set
//st.erase(prev(st.end())); delete last element in set;
//sort(a+1,a+n+1,[](ll x,ll y){return abs(x)>abs(y);});
//sort(v.begin(), v.end(), greater<int>()); 
const int N=1e5+5;
int h,w,temp,x,y;
pr a[100][100];
bool dp[100][100][N];
void solve()
{
 // we can prove that max diff will not exceed max. value of a,b;
 //hence dp state is reach index i,j with diff k;
 dp[1][0][0]=1;
 dp[0][1][0]=1;
 
 FOR(i,1,h) FOR(j,1,w) FOR(k,0,1e5)
 if(dp[i-1][j][k] or dp[i][j-1][k])
 {
  x=abs(a[i][j].first-a[i][j].second);
  dp[i][j][x+k]=1;
  dp[i][j][abs(x-k)]=1;
 }
 FOR(k,0,1e5) if(dp[h][w][k]) cut(k);
 //cout<<"lol \n";
}
int main()
{
  fast_io;
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  cin>>h>>w;
  FOR(i,1,h)FOR(j,1,w) cin>>a[i][j].first;
  FOR(i,1,h)FOR(j,1,w) cin>>a[i][j].second;
  solve();
}

Measured memory_bytes: 69216
#include <iostream>
#include <algorithm>

using namespace std;

int main(void) {
    long long n;
    cin >> n;
    long long sum = 0;
    long m = 0;
    for (long i = 0; i < n; i++)
    {
        long long p;
        cin >> p;
        m = m < p ? p : m;
        sum += p;
    }   
    cout << sum - (m / 2) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

const int MAX_N = (int)1e5 + 5;

bool lights[MAX_N];

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

	int N; cin >> N;
	for (int i = 1; i <= N; ++i) lights[i] = false;
	lights[1] = true;
	vector<int> a(N+1, 0);

	for (int i = 1;i <= N; ++i){
		cin >> a[i];
	} // end for

	int res = -1;
	int from = 1;
	int to = a[1];
	for(int i = 1; i <= N; ++i){
		if (lights[from]){
			lights[from] = false;
			to = a[from];
			lights[to] |= true;
			from = to;
		} // end if
		if (lights[2]){
			res = i;
			break;
		} // end if
	} // end for

	cout << res << endl;	

	return 0;
}

Measured memory_bytes: 768
import sys
S = list(input())
op = ['+', '-']
for i in range(1<<len(S)-1):
    f = S[0]
    for j in range(len(S)-1):
        if i&(1<<j):
            f += '+'
        else:
            f += '-'
        f += S[j+1]
    if eval(f)==7:
        break
print(f+'=7')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
const ll INF = 1e18;
#define print(x) cout << (x) << endl;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X, Y;
    cin >> X >> Y;
    int sum = 0;
    if (X == 1 && Y == 1) {
        cout << 1000000 << endl;
    } else {
        if (X == 1) {
            sum += 300000;
        }
        else if (X == 2) {
            sum += 200000;
        }
        else if (X == 3) {
            sum += 100000;
        }
        if (Y == 1) {
            sum += 300000;
        }
        else if (Y == 2) {
            sum += 200000;
        }
        else if (Y == 3) {
            sum += 100000;
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll dp[N],a[N],sum[N];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum[i]=(i>2?sum[i-2]:0)+a[i];
    }
    for(int i=2;i<=n;i++){
        if(i&1) dp[i]=max(dp[i-1],dp[i-2]+a[i]);
        else dp[i]=max(sum[i-1],dp[i-2]+a[i]);
    }
    cout<<dp[n];
}

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

#define endl '\n'
#define int long long

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

	int h, w; cin >> h >> w;
	int ch, cw; cin >> ch >> cw;
	int dh, dw; cin >> dh >> dw;
	string s[h];
	for(string &str : s) cin >> str;
	vector< vector<int> > magic(h, vector<int>(w, -1));
	vector< vector<bool> > vis(h, vector<bool>(w, false));
	queue< pair<int, int> > q, reach;
	q.push({cw - 1, ch - 1});
	reach.push({cw - 1, ch - 1});
	magic[ch - 1][cw - 1] = 0;
	vis[ch - 1][cw - 1] = true;
	function<bool(int, int)> valid = [&] (int x, int y) {
		return (x >= 0 and x < w and y >= 0 and y < h and s[y][x] == '.');
	};
	vector< pair<int, int> > moves = {{1, 0}, {0, 1}, {0, -1}, {-1, 0}};
	int total = 0;
	bool run = true;
	while(run) {
		int n_total = total;
		while(!q.empty()) {
			auto u = q.front();
			reach.push(u);	
			q.pop();
			for(int i = 0; i < 4; i ++) {
				int vx = u.first + moves[i].first;
				int vy = u.second + moves[i].second;
				if(valid(vx, vy) and !vis[vy][vx]) {
				vis[vy][vx] = true;
				q.push({vx, vy});
				reach.push({vx, vy});
				magic[vy][vx] = magic[u.second][u.first];
				n_total ++;
				}
			}
		}
		while(!reach.empty()) {
			auto u = reach.front();
			reach.pop();
			for(int i = max(u.first - 2, 0LL); i <= min(u.first + 2, w - 1); i ++) {
				for(int j = max(u.second - 2, 0LL); j <= min(u.second + 2, h - 1); j ++) {
					if(valid(i, j) and !vis[j][i]) {
						vis[j][i] = true;
						magic[j][i] = magic[u.second][u.first] + 1;
						q.push({i, j});
						n_total ++;
					}
				}
			}
		}
		if(n_total == total) run = false;
		else total = n_total;
	}
	cout << magic[dh - 1][dw - 1] << endl;

	return 0;
}

Measured memory_bytes: 12900
#include <iostream>

template<class T> inline bool chmax(T& a, T b) {
  if ( a < b ) {
    a = b;
    return true;
  }
  return false;
}
const int MAX_N {110};
const int MAX_W {100010};
long long dp[MAX_N][MAX_W] {{0}};
int N;
long long W;
long long weight [MAX_N] {0};
long long value [MAX_N] {0};

int main()
{
  std::cin >> N >> W;
  for ( int i = 0; i < N; i++ ) {
    std::cin >> weight[i] >> value[i];
  }

  for (int n = 0; n < N; n++) {
    for (int w = 0; w <= W; w++) {
      if (w - weight[n] >= 0) {
        chmax(dp[n+1][w], dp[n][w - weight[n]] + value[n]);
      }
      chmax(dp[n+1][w], dp[n][w]);
    }
  }

  std::cout << dp[N][W] << std::endl;
  return 0;
}


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

int n, m, h[100005], u, v, ans;
bool vis[100005];

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", h + i);
    }
    for (int i = 1; i <= m; ++i) {
        scanf("%d%d", &u, &v);
        if (h[u] < h[v]) {
            vis[u] = true;
        } else if (h[u] == h[v]) {
            vis[u] = vis[v] = true;
        } else {
            vis[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (vis[i] == false) {
            ++ans;
        }
    }
    printf("%d\n", ans);
    return 0;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    int s = 0;
    if(N) 
        s += (N * (N - 1)) / 2;
    if(M)
        s += (M * (M - 1)) / 2;
    cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
/* 
	بسم الله الرحمن الرحیم
	
	(; طلا یک جهانی
*/	

#include <bits/stdc++.h>
using namespace std;

#define int long long

int32_t main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int a, b;
	cin >> a >> b;
	if (a < 6)
		cout << 0;
	else if (a < 13)
		cout << b / 2;
	else
		cout << b;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [float('inf')] * n
dp[0] = 0

for i in range(n):
    for j in range(k+1):
        num = i+j
        if num >= n: break
        else: 
            dp[num] = min(dp[num], dp[i]+abs(h[num]-h[i]))

print(dp[-1])


Measured memory_bytes: 55008
n = int(input())
t, a = map(int, input().split(" "))
h = list(map(int, input().split(" ")))
avg_list = []
res = 0
for i in range(0, n):
    avg = t - h[i] * 0.006 - a
    if avg < 0:
        avg = -avg
    avg_list.append(avg)
print(avg_list.index(min(avg_list)) + 1)

Measured memory_bytes: 9132
h,w,a,b = map(int, input().split())
if a*2>w or b*2>h:
    print('No')
else:
    ans = [[0 for i in range(w)]for j in range(h)]
    for i in range(h):
        for j in range(w):
            if j<a and i<b:
                ans[i][j]=1
            elif j>=a and i>=b:
                ans[i][j]=1
    for i in range(h):
        print(''.join(map(str,ans[i])))

Measured memory_bytes: 52700
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;

namespace mp = boost::multiprecision;

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

#define int long long

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

const int MAX_N = 1005;
const int MAX_M = 1005;

int N, M;
int A[MAX_N];
int B[MAX_M];

int myPow[MAX_N*MAX_M];

int getPow(int k)
{
  if(k == 1) {
    return 1;  
  }
  if(k <= 0) {
    return 0;
  }
  if(myPow[k] != -1) {
    return myPow[k];
  }
  return myPow[k] = (k * getPow(k-1)) % MOD;
}

signed main()
{
  memset(myPow, -1, sizeof(myPow));
  cin >> N >> M;
  REP(n,N) {
    cin >> A[n];
  }
  REP(m,M) {
    cin >> B[m];
  }

  sort(A,A+N, greater<int>());
  sort(B,B+M, greater<int>());

  // REP(n,N) {
  //   cerr << A[n] << ",";
  // }
  // cerr << endl;
  // REP(m,M) {
  //   cerr << B[m] << ",";
  // }
  // cerr << endl;

  getPow(N*M+1);

  int number = N*M;
  int ai = 0, bi = 0;
  int n = 0, m = 0;
  int ans = 1;

  while((ai < N || bi < M)) {
    // cerr << ai << " " << bi << " " << number << " " << ans << endl;
    if(ai < N && A[ai] > number) {
      cout << 0 << endl;
      return 0;
    }
    if(bi < M && B[bi] > number) {
      cout << 0 << endl;
      return 0;
    }

    if(number == A[ai] && number == B[bi]) {
      n++; m++;
      ai++; bi++;
    } else if(number == A[ai]) {
      // cerr << "A" << endl;
      ans *= m; ans %= MOD;
      n++; ai++;
    } else if(number == B[bi]) {
      // cerr << "B" << endl;
      ans *= n; ans %= MOD;
      m++; bi++;
    } else {
      ans *= (n*m - (N*M - number)); ans %= MOD;
    }
    // cerr << "ans: " << ans << endl;
    number--;
  }

  cout << (ans * getPow(number) ) % MOD << endl;

  return 0;
}

Measured memory_bytes: 23808
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

int N, M;
string S;
int dist[101010];

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

  int cnt = 0;
  int max1 = 0;
  for (auto c : S) {
    if (c == '1') {
      ++cnt;
      chmax(max1, cnt);
    } else {
      cnt = 0;
    }
  }

  if (max1 >= M) {
    cout << -1;
    return 0;
  }

  rep(i, 0, 101010) { dist[i] = inf; }
  dist[0] = 0;

  vector<int> ansrev;
  int cur = N;
  while (cur != 0) {
    for (int i = M; i >= 1; --i) {
      if (cur - i < 0) i = cur;

      if (S[cur - i] == '0') {
        cur -= i;
        ansrev.push_back(i);
        break;
      }
    }
  }

  reverse(ansrev.begin(), ansrev.end());

  for (auto e : ansrev) {
    cout << e << " ";
  }
}


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

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

int N;
vector<int> solve() {
    vector<int> X(N);
    REP(i, N) cin >> X[i];
    REP(i, N) X[i]--;

    map<int, int> event;
    REP(i, N) event[ X[i] ] = i;

    REP(i, N) if (event[ X[i] ] != i) {
        return vector<int>(); // NG
    }

    typedef pair<int, int> P;
    priority_queue<P, vector<P>, greater<P>> before;
    REP(i, N) {
        if(i != 0) {
            before.push(P(X[i], i));
        }
    }

    queue<int> after;
    vector<int> count(N);

    vector<int> answer;
    auto insert = [&](int x) {
        //cout << "insert " << x+1 << endl;
        answer.push_back(x+1);
        count[x]++;
    };

    REP(i, N * N) {
        //cout << i << endl;
        if(event.count(i)) {
            //cout << "event" << event[i] << endl;
            const int x = event[i];
            if(count[x] != x) {
                //cout << "count " << x << " " << count[x] << " is not " << x << endl;
                return vector<int>(); // NG
            }
            insert(x);
            REP(_, N - count[x]) {
                after.push(x);
            }
        } else {
            if(before.empty()) {
                if(after.empty()) {
                    //cout << "before and after" << endl;
                    return vector<int>(); // NG
                } else {
                    int x = after.front(); after.pop();
                    insert(x);
                }
            } else {
                auto p = before.top();
                int x = p.second;
                insert(x);
                if(count[x] < x) {
                    // remain
                } else {
                    before.pop();
                }
            }
        }
    }

    return answer;
}

int main(){
    iostream_init();
    while(cin >> N) {
        auto res = solve();
        if(res.size() != 0) {
            cout << "Yes" << endl;
            REP(i, res.size()) {
                cout << res[i];
                if(i+1 != res.size()) cout << " ";
                else cout << endl;
            }
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 2692
#include<iostream>
#include<vector>

int main() {
    int n, m;
    std::cin >> n >> m;
    std::vector<int> a(m);
    long long sum = 0;
    for (int i = 0; i < m; i++)
    {
        std::cin >> a[i];
        sum += a[i];
    }

    int ans;
    if (n >= sum)
    {
        ans = n - sum;
    }
    else
    {
        ans = -1;
    }

    std::cout << ans << "\n";
}

Measured memory_bytes: 3644
n = int( input() )
w = list( map( int, input().split() ) )

w_sum1 = sum(w)
w_sum2 = 0
min = w_sum1


for i in range(n):
    w_sum1 -= w[i]
    w_sum2 += w[i]
    if abs(w_sum1-w_sum2) < min:
        min = abs(w_sum1-w_sum2)

print(min)

Measured memory_bytes: 38256
#include<iostream>
#include<algorithm>

using namespace std;
int main(){

	int m;
	cin>>m;
	while(m--){
		int P;
		cin>>P;
		int y;
		cin>>y;
		int n;
		cin>>n;
		int ans = 0;
		while(n--){
			bool isH;
			double r;
			int c;
			cin>>isH>>r>>c;
			int A = P;
			int Q = 0;
			for(int i = 0;i < y;i++){
				if(isH){
					int B = A * r;
					A += B - c;
				}
				else{
					int B = A * r;
					Q += B;
					A -= c;
				}
			}
			ans = max(ans,A + Q);
		}
		cout<<ans<<endl;
	}

}

Measured memory_bytes: 1232
import java.util.*;

class Main {

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

        long currentT = sc.nextLong();
        long currentA = sc.nextLong();

        for (int i = 1; i < N; i++) {
            long t = sc.nextLong();
            long a = sc.nextLong();

            long tScale = t / currentT;
            long aScale = a / currentA;
            long scale = 1;
            if (Math.min(tScale, aScale) < 1) {
                scale = Math.max((currentT + t - 1)/ t, (currentA + a - 1)/ a);
            }
            currentT = scale * t;
            currentA = scale * a;
        }
        System.out.println(currentT + currentA);
    }
}

Measured memory_bytes: 25300
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>

using namespace std;

vector<int> to_vec(int a,int d,int N,int M){
  vector<int> v{a};
  for(int i=0;i<N-1;i++){
    a=(a*58+d)%(M+1);
    v.push_back(a);
  }
  sort(begin(v),end(v));
  return v;
}

int main(){
  int M,N,m0,md,n0,nd;
  cin>>M>>N>>m0>>md>>n0>>nd;
  auto vm=to_vec(m0,md,M,N);
  auto vn=to_vec(n0,nd,N,M);
  long long ans=1e18;
  int rx=N;
  long long l=0,r=accumulate(begin(vn),end(vn),0LL);
  for(int i=0;;i++){
    for(;rx;){
      long long c=l+r+(M-i)*1LL*(N-rx);
      long long n=l+r-vn[rx-1]+(M-i)*1LL*(N-rx+1);
      if(n>c)break;
      rx--;
      r-=vn[rx];
    }
    ans=min(ans,l+r+(M-i)*1LL*(N-rx));
    if(i==M)break;
    l+=vm[i];
  }
  cout<<ans<<endl;
}

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

using namespace std;
# define M_PI 3.14159265358979323846
# define epsi 1e-9
# define F first
# define S second
# define REP(i,a,b) for(int i=a;i<=b;i++)
# define my_sizeof(type) ((char *)(&type+1)-(char*)(&type))
using ll = long long int;
const int MOD = 1e9 + 7;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    ll W;
    cin>>n>>W;
    vector<pair<ll,ll>> weight_value_pair;
    for (int i = 0; i < n; ++i)
    {
        ll w,v;
        cin>>w>>v;
        weight_value_pair.emplace_back(w,v);
    }
    sort(weight_value_pair.begin(),weight_value_pair.end());
    //dp[i][j]=Max profit if items are chosen only from initial i items and the
    //capacity of knapsack is j
    ll dp[n+1][W+1];
    //Initializing 0th column as zero
    for(int i=0;i<=n;i++)
    {
        dp[i][0]=0;
    }
    //Initializing 0th row as zero
    for (int i = 0; i <=W ; ++i) {
        dp[0][i]=0;
    }
    for (int i = 1; i <=n ; ++i) {
        for (int j = 1; j <=W ; ++j) {
            if(j-weight_value_pair[i-1].first>=0)
            {
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-weight_value_pair[i-1].first]+weight_value_pair[i-1].second);

            } else
            {
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    cout<<dp[n][W];
}

Measured memory_bytes: 82468
def solve(N):
    ans = ""
    while N > 0:
        q,r = N // 26,N % 26
        if r == 0:
            q -= 1
            r = 26
        ans = chr(96 + r) + ans
        N = (N - r) // 26

    return ans

def main():
    N = int(input())

    print(solve(N))

if __name__ == "__main__":
    main()


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

using namespace std;

char S[120000];

int main()
{
    scanf("%s", S);
    int N=strlen(S);
    int ans=0;
    for(int i=1; i<N; i++)
        ans+=S[i-1]!=S[i];
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std; 
int N,ptr=0,res=0;
int A[100000]; 
int main (){
  cin>>N;
  for(int i=0;i<N;i++) cin>>A[i]; 
  sort(A,A+N);
  while(ptr<N){
    int cc=A[ptr],f=0;
    while(ptr<N&&A[ptr]==cc) f++,ptr++;
    res+=f%2;
  }
  cout<<res<<endl;
}

Measured memory_bytes: 640
s = input()
n = len(s)

if len(s) == 2:
    if s[0] == s[1]:
        print(1,2)
    else:
        print(-1,-1)
else:
    for i in range(n-1):
        if s[i] == s[i+1]:
            print(i+1,i+2)
            exit()
    for i in range(n-2):
        if s[i] == s[i+2]:
            print(i+1,i+3)
            exit()
    print(-1,-1)


Measured memory_bytes: 3188