akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#define MAX 1000000000000000000
using namespace std;

int main() {
	unsigned long long int a,ans,b;
	string s;
	cin >> a>>s;
	b = s[0] - '0';
	b *= 10;
	b += s[2] - '0';
	b *= 10;
	b += s[3] - '0';
	ans = (a*b) / 100;
	cout << ans;
	return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define PP pop_back()
#define ALL(x) x.begin(),x.end()
#define st first
#define nd second
#define sz(x) (int) x.size()
#define pii pair<int,int>
#define ii int,int
#define ll long long
#define lf double
#define llu long long unsigned
#define INPUT freopen("inp.in","r",stdin);
#define OUTPUT freopen("oup.out","w",stdout);
#define sag(x) 2*x+1
#define sol(x) 2*x
#define orta ((bas+son)/2)
#define set(x,y) memset(x,y,sizeof(x))
#define MIN3(x,y,z) min(min(x,y),z)
#define MAX3(x,y,z) max(max(x,y),z)
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define ROF(i,j,k) for(int i=j;i>=k;i--)
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define MOD 1000000007
#define inf 20000000000000
#define N 100005
using namespace std;
int n,m,dp[N],x,y,s[N],ans;
int main() {
    cin>>n>>m;
    dp[1]=1;
    FOR(i,1,n) s[i]=1;
    FOR(i,1,m) {
        cin>>x>>y;
        if(dp[x] && !dp[y]) {
            dp[y]=1;
        }
        s[y]++;
        s[x]--;
        if(s[x]<=0) s[x]=0,dp[x]=0;
    }
    FOR(i,1,n) ans+=dp[i];
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n,a[200010];
bool f[200010];
int read(){
	int x = 0,c = getchar();
	while(!isdigit(c)) c = getchar();
	while(isdigit(c)){
		x = (x << 1) + (x << 3) + (c ^ '0');
		c = getchar();
	}
	return x; 
}
int main(){
	int i,j;
	n = read();
	for(i = 1;i <= n;++i) a[i] = read();
	for(i = 1;i <= n;++i){
		if(a[i] > i - 1){
			puts("-1");
			return 0;
		}
	}
	long long ans = 0,mn = n;
	for(i = n;i > 1;--i){
		if(!f[i - a[i]]){
			f[i - a[i]] = 1;
			ans += a[i];
		}
		if(i - a[i] > mn){
			puts("-1");
			return 0;
		}
		mn = i - a[i];
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1280
use std::fmt::Debug;
use std::io;
use std::io::{Read, Stdin};
use std::str;
use std::str::FromStr;
use std::usize;
use std::cmp;
use std::collections::vec_deque::VecDeque;
use std::i64::MAX;
use std::collections::HashSet;

fn main() {
    let mut sc = Scanner::new();
    let n = sc.parse::<usize>();
    let s = sc.parse::<String>().chars().collect::<Vec<char>>();

    let mut count = 0;
    let mut left = 0;
    for c in &s {
        match c {
            &'(' => count += 1,
            &')' => {
                if count == 0 {
                    left += 1;
                } else {
                    count -= 1;
                }
            }
            _ => (),
        }
    }

    for _ in (0..left) {
        print!("(");
    }
    for c in &s {
        print!("{}", c);
    }
    for _ in (0..count) {
        print!(")");
    }
    println!("");
}

struct Scanner {
    stdin: Stdin,
    buf: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            buf: Vec::with_capacity(256),
        }
    }

    fn parse<T: FromStr>(&mut self) -> T
        where <T as FromStr>::Err: Debug
    {
        self.buf.clear();
        let mut it = self.stdin.lock().bytes();
        let mut c = it.next().unwrap().unwrap();
        while c == ' ' as u8 || c == '\n' as u8 {
            c = it.next().unwrap().unwrap();
        }
        while !(c == ' ' as u8 || c == '\n' as u8) {
            self.buf.push(c);
            c = it.next().unwrap().unwrap();
        }
        str::from_utf8(&self.buf).unwrap().parse::<T>().unwrap()
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
const int N = 103;
const int M = 10003;
const int C = 22;
const int Q = 20005;
int Dist[C][N][N] = {INF};
int graph[N][N] = {INF};
int cost[C][Q] = {0};
int n,m,c,s,g;

int main(){
    while(1){
        cin >> n >> m >> c >> s >> g;
        if(n==0&&m==0) break;
        --s;--g;

        rep(i,c)rep(j,n)rep(k,n) Dist[i][j][k] = INF;
        rep(i,n)rep(j,n) graph[i][j] = INF;
        rep(i,c)rep(j,Q) cost[i][j] = 0;

        rep(i,m){
            int x,y,d,cc;
            cin >> x >> y >> d >> cc;
            --x;--y;--cc;
            Dist[cc][x][y] = min(d,Dist[cc][x][y]);
            Dist[cc][y][x] = min(d,Dist[cc][y][x]);
        }

        vector<int> p(c);
        rep(i,c) cin >> p[i];

        rep(i,c){
            vector<int> q(p[i],-1),r(p[i]);
            rep(j,p[i]-1) cin >> q[j];
            rep(j,p[i]) cin >> r[j];
            int id = 0;
            for(int di=1;di<Q;di++){
                if(q[id]+1==di) ++id;
                cost[i][di] = cost[i][di-1] + r[id];
            }
        }

        rep(i,c)rep(j,n) Dist[i][j][j] = 0;
        rep(i,n) graph[i][i] = 0;

        rep(kinds,c)rep(k,n)rep(i,n)rep(j,n) Dist[kinds][i][j] = min(Dist[kinds][i][j],Dist[kinds][i][k] + Dist[kinds][k][j]);
        rep(kinds,c)rep(i,n)rep(j,n){
            if(Dist[kinds][i][j]>=INF) continue;
            //if(Dist[kinds][i][j]>=Q) Dist[kinds][i][j] = Q - 1;
            Dist[kinds][i][j] = cost[kinds][Dist[kinds][i][j]];
        }

        rep(kinds,c)rep(i,n)rep(j,n) graph[i][j] = min(graph[i][j],Dist[kinds][i][j]);

        rep(k,n)rep(i,n)rep(j,n) graph[i][j] = min(graph[i][j],graph[i][k] + graph[k][j]);

        if(graph[s][g]==INF) cout << -1 << endl;
        else cout << graph[s][g] << endl;
    }

    return 0;
}


Measured memory_bytes: 5532
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef pair<int,int> pii;
typedef long long int ll; 
typedef tree<pii,null_type,less<pii>,rb_tree_tag, \
tree_order_statistics_node_update> ordered_set;

#define int ll   
#define long int
#define pb push_back
#define all int i=0; i<n; i++
#define INF 10000000000000000

#define Nirvana ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define mod 1000000007
#define pii pair<int, int> 
long expo(long base, long exp, int m) 
{ 
    long t = 1L; 
    while (exp > 0)  
    { 
        if (exp % 2 != 0)  t = (t * base)%m ; 
        base = (base * base)%m ; 
        exp /= 2; 
    } 
    return t%m; 
} 
#define pow expo
#define pi acos(-1.00)

int dp[20001];
int h,n;
int a[20001];
int b[20001];

int32_t main(){
	cin>>h>>n;
	for(all){
		cin>>a[i]>>b[i];
	}
	fill(dp, dp+20001, INF);
	dp[0] = 0;

	for(int i=1; i<=20000; i++){
		for(int j=0; j<n; j++){
			if(a[j]>i)continue;
			if(dp[i - a[j]]==INF)continue;
			
			dp[i] = min(dp[i], dp[i - a[j]] + b[j]);
		}
	}
	int ans = INF;
	
	for(int i=h; i<=20000; i++){
		ans = min(ans, dp[i]);
		//cout<<dp[i]<<endl;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(){
  int W, H, x, y;
  long double max = 0;
  int ans = 0;

  scanf("%d%d%d%d", &W, &H, &x, &y);

  if(W == (x+x) && H == (y+y)){
    ans = 1;
  }
  /*
  if((x == 0 && y == 0) || (x == 0 && y == H) || (x == W && y == 0) || (x == W && y == H)){
    //    max = (W * H) / 2;
    ans = 0;
  }
  */
  max = (W * (double)H) / 2;

  printf("%Lf %d", max, ans);
  printf("\n");

}


Measured memory_bytes: 128
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,ssse3,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
//using arr = array;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using vpi = vector<pi>;
using ld = long double;
const int maxn = 1<<12, mod = 1e9 + 7 , lg = 19;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll L, R;
ll dp[66][2][2][2];
#define get(x, y) (((x)>>(y))&1)
ll rec(ll i, ll a, ll b, ll c) {
	if(i>=60) return a+b==0&&c;
	if(dp[i][a][b][c]>-1) return dp[i][a][b][c];
	ll &ans = dp[i][a][b][c];
	ans = 0;
	for(int r = 0; r < 2; r++)
		for(int l = 0; l < 2; l++) {
			if(l>r) continue;
			ans += rec(i+1, get(R, i)!=r?r>get(R, i):a, get(L, i)!=l?l<get(L, i):b, r+l==0?c:(r&&l));
			ans %= mod;
		}
	return ans;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	memset(dp, -0x3f, sizeof dp);
	cin >> L >> R;
	cout << rec(0, 0, 0, 0);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int dp[11][2010];
int amount[10][2010];
int main(){
	int n,k;	cin>>n>>k;
	vector<int> a[10];
	for(int i=0;i<n;i++){
		int c,g;	cin>>c>>g;
		a[g-1].push_back(c);
	}
	for(int i=0;i<10;i++){
		sort(a[i].begin(),a[i].end());	reverse(a[i].begin(),a[i].end());
		int t=a[i].size();
		if(t==0)	continue;
		amount[i][0]=a[i][0];
		for(int j=1;j<t;j++)	amount[i][j]=a[i][j]+amount[i][j-1];
		for(int j=1;j<t;j++)	amount[i][j]+=j*(j+1);
	}
	int ans=0;
	for(int i=0;i<10;i++){
		for(int j=0;j<k;j++){
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
			for(int l=0;l<(int)a[i].size();l++){
				if(j+1>k)	break;
				dp[i+1][j+l+1]=max(dp[i+1][j+l+1],dp[i][j]+amount[i][l]);
				ans=max(ans,dp[i+1][j+1]);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1352
import java.util.*;
public class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
  int a=sc.nextInt();int b=sc.nextInt();int k=sc.nextInt();
  int ans=0;
  for(int i=100;i>0;i--){
  	if(a%i==0&&b%i==0){
    ans++;
    }
    if(ans==k){System.out.println(i);
              break;
              }
  }
}
}


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int a, b, q;
  cin >> a >> b >> q;
  
  vector<ll> s(a + 2), t(b + 2);
  s.at(0) = t.at(0) = -1e18;
  s.at(a + 1) = t.at(b + 1) = 1e18;
  for(int i = 1; i <= a; i++) cin >> s.at(i);
  for(int i = 1; i <= b; i++) cin >> t.at(i);
  
  ll x;
  for(int i = 0; i < q; i++){
    cin >> x;
    
    auto s_up = upper_bound(s.begin(), s.end(), x);
    ll s2 = distance(s.begin(), s_up);
    auto t_up = upper_bound(t.begin(), t.end(), x);
    ll t2 = distance(t.begin(), t_up);
    
    ll ans;
    ans = min({abs(x - s.at(s2)) + abs(s.at(s2) - t.at(t2)), 
    abs(x - s.at(s2 - 1)) + abs(s.at(s2 - 1) - t.at(t2)), abs(x - s.at(s2)) + abs(s.at(s2) - t.at(t2 - 1)), 
    abs(x - s.at(s2 - 1)) + abs(s.at(s2 - 1) - t.at(t2 - 1)), abs(x - t.at(t2)) + abs(t.at(t2) - s.at(s2)), 
    abs(x - t.at(t2 - 1)) + abs(t.at(t2 - 1) - s.at(s2)), abs(x - t.at(t2)) + abs(t.at(t2) - s.at(s2 - 1)), 
    abs(x - t.at(t2 - 1)) + abs(t.at(t2 - 1) - s.at(s2 - 1))});
    
    cout << ans << "\n";
  }
}

Measured memory_bytes: 2944
//ACGT;
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[5]={0},ma=0,h=0;
	string s;
	cin>>s;
	for(int t=0;t<s.size();t++)
	{
		if(s[t]=='A'||s[t]=='C'||s[t]=='G'||s[t]=='T')
		{
			a[h]++;
		}
		else
		{
			if(s[t-1]=='A'||s[t-1]=='C'||s[t-1]=='G'||s[t-1]=='T')
			{
				h++;
			}
			continue;
		}
	}
	for(int t=0;t<5;t++)
	{
		if(a[t]>ma)
		{
			ma=a[t];
		}
	}
	cout<<ma;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
//using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;
const double PI = acos(-1.0);

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

const int MOD = 2019;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S;
  cin >> S;
  int n = S.size();
  reverse(S.begin(), S.end());
  int x = 1, tot = 0;
  vector<int> cnt(MOD);
  ll ans = 0;
  for (int i = 0; i < n; i++)
  {
    cnt[tot]++;
    tot += (S[i] - '0') * x;
    tot %= MOD;
    ans += cnt[tot];
    x = x * 10 % MOD;
  }
  cout << ans << endl;
  return 0;
}

// 10と2019は互いに素であるため例としてa2～a5の和はa2～a5/10^2で求められる．mod2019 == 0であるものを求めたいからa2～a5/10^2 == 0を求めるが10と2019は互いに素であるためa2～a5 == 0であるものを求めればよい．これは累積和の問題に帰着できる．a2～a5 == 0よりS5 - S1 == 0，S5 == S1したがってmod2019の世界において累積和が等しいものの個数を数えていけばよい．したがって現れた累積和を保存していく配列をサイズ2019で作っておいて累積和を数えていけばよい．ある桁を考えるときにその桁までの累積和のmod2019が今までに何回出たかを足し続けていけばよい．


Measured memory_bytes: 3668
S = input()
N = len(S)


def isP(s):
    l, r = 0, len(s)-1
    while l < r:
        if s[l] != s[r]:
            return False
        l += 1
        r -= 1
    return True


if isP(S) and isP(S[:(N-1)//2]) and isP(S[(N+3)//2-1:]):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38256
def main():
    s = input()
    t = input()
    ans = 100000
    for i in range(len(s) - len(t) + 1):
        sub = s[i:i+len(t)]
        tmp = 0
        for j in range(len(sub)):
            if sub[j] != t[j]:
                tmp += 1
        ans = min([ans, tmp])
    print(ans)


if __name__ == '__main__':
    main()


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

using ll = long long;
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

#define INF 1e9

int solve(string X, string Y){
  int dp[X.size()+1][Y.size()+1] = {0};
  REP(i, X.size()+1){
    REP(j, Y.size()+1){
      dp[i][j] = 0;
    }
  }
  REP(i, X.size()){
    REP(j, Y.size()){
      if(X[i] == Y[j]){
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1);
      }
      dp[i+1][j+1] = max({dp[i+1][j+1], dp[i][j], dp[i][j+1], dp[i+1][j]});
    }
  }
  return dp[X.size()][Y.size()];
}
int main(){
  int q;
  cin >> q;
  while(q--){
    string X, Y;
    cin >> X >> Y;
    cout << solve(X, Y) << endl;
  }
  return 0;
}



Measured memory_bytes: 7088
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

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

	int ans = 0;
	if(A>=13)ans = B;
	if(6<=A&&A<=12)ans = B/2;
	if(A<=5)ans = 0;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	double a,min,max;
	scanf("%lf",&a);
	min=a;max=a;
	while((scanf("%lf",&a))!=EOF){
		if(a>max)max=a;
		if(a<min)min=a;
	}
	printf("%.1lf\n",max-min);
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <fstream>
#include <bitset>
#include <time.h>
#include <assert.h>
#include <random>

#define LL long long
#define VI vector<int>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14


using namespace std;


struct Edge {
    int from;
    int to;
    int cost;
    Edge(int from, int to, int cost) : from(from), to(to), cost(cost) {}
    bool operator<(const Edge& edge) const {
        return this->cost < edge.cost;
    }
    bool operator>(const Edge& edge) const {
        return this->cost > edge.cost;
    }
};

class UnionFind {
public:
    vector<int> parent;
    vector<int> setSize;

    UnionFind(unsigned int size) {
        parent.resize(size + 1);
        iota(parent.begin(), parent.end(), 0);
        setSize.resize(size + 1, 1);
    }

    // x??¨y???????????????????±??????????
    bool isSameSet(int x, int y) {
        return findRoot(x) == findRoot(y);
    }

    // x??¨y????±??????????????????????
    void unionSet(int x, int y) {
        x = findRoot(x);
        y = findRoot(y);
        if (x == y) { return; }

        parent[x] = y;
        setSize[y] += setSize[x];
    }

private:
    // ??¨??????????±???????
    int findRoot(int x) {
        if (parent[x] == x) {
            return x;
        }
        else {
            return parent[x] = findRoot(parent[x]);
        }
    }
};

/**
 * ??°?????????????°???¨?????¨????±??????????O(|E| log|V|)
 * @param num_of_node ???????????°
 * @param edges?????¨?????????????????°????????????u -> v??¨v -> u??????????????\??????
 * @return
 */
long long kruskal(unsigned int num_of_node, vector<Edge> edges) {
    sort(edges.begin(), edges.end());

    UnionFind uf(num_of_node);

    long long ans = 0;
    for (Edge e : edges) {
        if (!uf.isSameSet(e.from, e.to)) {
            uf.unionSet(e.from, e.to);
            ans += e.cost;
        }
    }
    return ans;
}

int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int V, E;
    cin >> V >> E;

    vector<Edge> edges;
    FOR(i, 0, E) {
        int s, t, w;
        cin >> s >> t >> w;
        edges.emplace_back(Edge(s, t, w));
        edges.emplace_back(Edge(t, s, w));
    }

    cout << kruskal(V, edges) << endl;

    return 0;
}

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


int main()
{
    string n;
    cin>>n;
    int cnt=0;
    rep(i,3){
        if(n[i]==n[i+1])cnt++;
        else cnt=0;
        if(cnt>=2){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;

}


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

#define ll long long
#define mst(a) memset(a, 0, sizeof a)

const int mod = 1e9+7;
const int maxn = 1e5+50;
const int inf = 1e9;

/*int bs(int n, int i)
{
    int l = 0, r = 1e6;
    while (l < r)
    {
        int m = (l + r) / 2;
        if ()
    }
}*/

int main()
{
   // freopen("in", "r", stdin);
    int n, k;
    ll ans = 0;
    cin >> n >> k;
    if (!k) ans = (ll)n*n;
    else for (int i = k+1; i <= n; ++i)
    {
        ll t = (n + 1) / i;
        ans += t * (i - k);
        if (n % i >= k && n % i != i-1) ans += n - (t*i + k) + 1;
        //printf("%lld %lld\n", t, ans);
    }
    printf("%lld\n", ans);
    return 0;
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>n>>m;
      if(abs(n-m)>1)ans=0;
      else{
        if(abs(n-m)==1){
          ans=1;
          rrep(i,1,n+1){
            ans*=i;
            ans%=MOD;
          }
          rrep(i,1,m+1){
            ans*=i;
            ans%=MOD;
          }
        }
        else{
          ans=n+m;
          ans%=MOD;
          n--;
           rrep(i,1,n+1){
            ans*=i;
            ans%=MOD;
          }
          rrep(i,1,m+1){
            ans*=i;
            ans%=MOD;
          }
        }
      }
      Cout(ans);
     

       
return 0;
}


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

int main(){
    int n; string s;
    cin >> n >> s;
    int e=0;
    for(int i=0; i<n; ++i)
        if(s[i]=='E') e++;
    
    int ans =1000000;
    for(int i=0; i<n; ++i){
        if(s[i]=='E') e--;
        ans = min(ans, e);
        if(s[i]=='W') e++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    int d;
    cin >> d;
    const int n = 26;
    vector<int> c(n,0);
    rep(i,n)cin >> c[i];
    vector<vector<int>> s(365,vector<int>(n,0));
    rep(i,d)rep(j,n)cin >> s[i][j];
    vector<int> recent(n,0);

    rep(i,d)cout << (i+2)%26 + 1 << endl;
    return 0;
}


Measured memory_bytes: 3652
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

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; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;
  vector<int> as(N);
  F0R(i, N) {
    cin >> as[i];
  }

  // 長さv以下にするには最小何回切る必要があるか
  auto fc = [&](int v) {
    i64 r = 0;
    F0R(i, N) {
      r += (as[i] + v-1) / v - 1;
    }
    return r;
  };

  int ok = 1e9, ng = 0;
  while (abs(ok - ng) > 1) {
    auto mp = (ok + ng) / 2;
    if (fc(mp) <= K) {
      ok = mp;
    }
    else {
      ng = mp;
    }
  }
  cout << ok;
}
#endif


Measured memory_bytes: 3984
import sys
input = sys.stdin.readline
N, A, B = map(int, input().split())
if N < A or N < B:
  print(-1)
  exit(0)
res = [x for x in range(N - A + 1, N + 1)]
k = N - A
if k < B - 1:
  print(-1)
  exit(0)
b = [0] * (B - 1)
for i in range(k):
  b[i % (B - 1)] += 1
if len(b):
  if max(b) > A:
    print(-1)
    exit(0)
for i in b:
  t = [x for x in range(k - i + 1, k + 1)]
  res += t
  k -= i
print(*res)

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


int main() {
  int N ;
  cin >> N ;
  vector<ll> A(N) ;
  rep(i,N) cin >> A.at(i) ;
  map<ll,int> mp ;
  priority_queue<ll> pq ;
  rep(i,N) mp[A.at(i)] = mp[A.at(i)]+1 ;
  for( auto p : mp ){
    auto m = p.first  ;
    auto n = p.second ;
    if( n>=2 ) pq.push(m) ;
    if( n>=4 ) pq.push(m) ;
  }
  if(pq.empty()){
	cout << 0 <<endl ;
    return 0 ;
  }
  ll p = pq.top() ;
  pq.pop() ;
  if(pq.empty()){
	cout << 0 <<endl ;
    return 0 ;
  }
  ll q = pq.top() ;
  cout << p*q << endl ;
}

Measured memory_bytes: 7296
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;

int n, ans = 0;
pair <int, int> b[1000010];

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; i ++) {
		int x, l;
		cin >> x >> l;
		b[i] = make_pair(x + l, x - l);
	}
	sort(b + 1, b + n + 1);
	int last = -2000000001;
	for (int i = 1; i <= n; i ++) {
		if (b[i].second >= last) {
			last = b[i].first;
			ans ++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fore(x,a,b) for(int x=a, qwerty=b; x<qwerty; x++)
#define ALL(a) (a).begin(),(a).end()
#define SZ(a) ((int)(a).size())
#define pb push_back
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fst first
#define snd second
#define mset(a,v) memset((a),(v),sizeof(a))
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
using namespace std;
typedef long long ll;
const int MAXN=200500;
int n;
int a[32][32];
int dp[21][1<<21];
const int mod=1e9+7;
int sum(int a, int b){
	a+=b;
	if(a>=mod)a-=mod;
	return a;
}
int f(int i, int m){
	if(i==n)return 1;
	int &r=dp[i][m];
	if(r!=-1)return r;
	r=0;
	fore(j,0,n)if(a[i][j]&&(m&(1<<j))==0)r=sum(r,f(i+1,m|(1<<j)));
	return r;
}
int main(){FIN;
	cin>>n;
	fore(i,0,n)fore(j,0,n)cin>>a[i][j];
	memset(dp,-1,sizeof dp);
	cout<<f(0,0)<<"\n";
}

Measured memory_bytes: 172416
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main()
{
	int n;cin>>n;
	int s=0;
	for(int i=0;;i++)
	{
		s+=pow(3,i);
		int x=n+s;
		vector<int> a;
		for(;;)
		{
			a.push_back(x%3);
			x/=3;
			if(x==0)break;
		}
		if(a.size()==i+1)
		{
			for(vector<int>::iterator it=a.end();it!=a.begin();)
			{
				it--;
				if(*it==0)cout<<'-';
				else if(*it==2)cout<<'+';
				else cout<<'0';
			}
			break;
		}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3252
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		while(n-- != 0)
		{
			int a = stdIn.nextInt();
			int aa = a * a;
			int b = stdIn.nextInt();
			int bb = b * b;
			int c = stdIn.nextInt();
			int cc = c * c;
			if(aa + bb == cc || aa + cc == bb || bb + cc == aa)
			{
				System.out.println("YES");
			}
			else
			{
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 23376
/*ex4_3
  TKC001*/
 
#include<stdio.h>
//プロトタイプ宣言
int snow(int west, int east);
 
int main(void){
     /*west:a
       east:b*/
    int west, east;
 
    //入力
    scanf("%d%d", &west, &east);
 
    //出力
    printf("%d", snow(west, east));
 
    return 0;
}
 
//関数の定義、積雪を求める関数
int snow(int west, int east){
     /*diff:b-a,eastの塔が西から何番目か
east_height:東側の塔の高さ*/
    int diff, east_height;
 
    diff = east - west;
    east_height = diff*(diff+1) / 2;
 
    return east_height - east;
}

Measured memory_bytes: 128
// D - Caracal vs Monster
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
ll H;

ll solve(){
	ll ans=0;
	for(ll count=1; H; count<<=1, H>>=1) ans += count;
	return ans;
}

int main(){
	cin>>H;
	cout<< solve() <<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder A = new StringBuilder();
        StringBuilder B = new StringBuilder();
        int n = sc.nextInt();
        for(int i=0;i<n;i++) A.append(sc.nextInt());
        int m =sc.nextInt();
        for(int i=0;i<m;i++) B.append(sc.nextInt());
        String a = new String(A);
        String b = new String(B);
        if(a.compareTo(b)<0) System.out.println(1);
        else System.out.println(0);
    }
}


Measured memory_bytes: 32120
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <tuple>
#include <stack>

using namespace std;

//#define ZTDebug
#ifdef ZTDebug
#define In scanf_s
#else
#define In scanf
#endif // ZTDebug

#define Ind(d) In("%d", &d)
#define Ind2(a, b) In("%d%d", &a, &b)
#define InD(d) int d; In("%d", &d);
#define InD2(a, b) int a, b; In("%d%d", &a, &b);
#define InDN(n, v) for (auto _i = 0; _i < n; ++_i) In("%d", &v[_i]);
#define OutDNLine(n, v) for (auto _i = 0; _i < n; ++_i) printf("%d%c", *(v + _i), _i + 1 == n ? '\n' : ' ');

typedef double db;
typedef long long LL;
typedef pair<int, int> pii;

const int Max = 100010;

int r, c, rd;

int toP(int x, int y) {
    if (y == 0) return x;
    if (x == r) return r + y;
    if (y == c) return r + c + r - x;
    if (x == 0) return rd - y;
    return -1;
}
int getP() { int x, y; cin >> x >> y; return toP(x, y); }

vector<pii> ps;
int turnP(int d, int x) {
    auto nx = x - d;
    if (nx < 0) return rd + nx;
}
bool test(int d) {
    vector<pii> cur;
    auto cnt = 0;
    for (auto p : ps) {
        auto q1 = turnP(d, p.first), q2 = turnP(d, p.second);
        if (q1 > q2) swap(q1, q2);
        ++cnt;
        cur.push_back(make_pair(q1, cnt));
        cur.push_back(make_pair(q2, -cnt));
    }
    sort(cur.begin(), cur.end());

#ifdef ZTDebug
    cout << "test " << d << endl;
    for (auto p : cur) cout << p.first << "," << p.second << " "; cout << endl;
#endif // ZTDebug

    stack<int> st;
    for (auto p : cur) {
        auto i = p.second;
        if (i < 0) {
            if (st.top() != -i) return false;
            st.pop();
        }
        else {
            st.push(i);
        }
    }
    return true;
}

int main() {
#ifdef ZTDebug
    while (true) {
#endif // ZTDebug
        int n;
        cin >> r >> c >> n;
        rd = r + c + r + c;

        ps.clear();
        for (auto i = 0; i < n; ++i) {
            auto p1 = getP(), p2 = getP();
            if (p1 != -1 && p2 != -1) ps.push_back(make_pair(p1, p2));
        }

#ifdef ZTDebug
        for (auto p : ps) cout << p.first << "," << p.second << " "; cout << endl;
#endif // ZTDebug

        int x[] = { 0, r, r + c, r + c + r };
        auto succ = false;
        for (auto d : x) if (test(d)) { succ = true; break; }
        cout << (succ ? "YES" : "NO") << endl;
#ifdef ZTDebug
    }
#endif // ZTDebug
    return 0;
}


Measured memory_bytes: 5056
#include<iostream>

using namespace std;

int main(){
  int n,sum[50]={0},i=0;
  while(cin >> n){
    if(n >= 37){
      sum[i] = 0;
      i++;
    }
    else{
      for(int a = 0; a <= 9; a++){
	for(int b = 0; b <= 9; b++){
	  for(int c = 0; c <= 9; c++){
	    for(int d = 0; d <= 9; d++){
	      if(a+b+c+d == n) sum[i]++;
	    }	    
	  }
	}
      }
      i++;
    }
    cout << sum[i-1] << endl;
  }
  int j;
  // for(j = 0; j <= i; j++) cout << sum[j] << endl;
}

Measured memory_bytes: 3056
// Made by Luis Miguel Baez
// es.luismiguelbaez@gmail.com

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

#define endl '\n'
#define precise(n,k) fixed << setprecision(k) << n
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define uint  unsigned int
#define ll    long long
#define ull   unsigned long long
#define ld    long double

#define pii   pair<int, int>
#define piii  tuple<int, int, int>
#define pll   pair<ll, ll>
#define plll  tuple<ll, ll, ll>

#define X  first
#define Y  second

#define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(bool b) {
    return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(const pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

// add templates here

template <typename T>
string to_string(const vector<T> &v) {
    bool first = true;
    string res = "{";
    for (const T &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string((T)x);
    }
    res += "}";
    return res;
}

template<class T>
void println(const T &data) {
#ifndef ONLINE_JUDGE
    cout << to_string((T)data) << endl;
#endif
}

const int MOD = int(1e9+7);
const ll oo  = (ll)(1e9+20);
const ll lloo  = (ll)(1e18)+40;

class Task {
public:
    ll A, B;
    
    ll solve(std::istream &in, std::ostream &out) {
        in >> A >> B;
        return max(0LL, A - 2*B);
    }
    void run(std::istream &in, std::ostream &out) {
        int t;
        in >> t;
        while(t--) {
            out << solve(in, out) << endl;
        }
    }
    
    void run_void(std::istream &in, std::ostream &out) {
        int t;
        in >> t;
        while(t--) {
            solve(in, out);
        }
    }
};
    
auto main() -> int {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    Task solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    cout << solver.solve(in, out) << endl;
    // solver.run(in, out);
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> s(n);
  rep(i, m) {
    int k;
    cin >> k;
    rep(j, k) {
      int idx;
      cin >> idx;
      --idx;
      s[idx] |= 1<<i;
    }
  }
  int p = 0;
  rep(i, m) {
    int par;
    cin >> par;
    p |= par<<i;
  }
  int ans = 0;
  rep(i, 1<<n) {
    int res = 0;
    rep(j, n) {
      if (i>>j & 1)
        res ^= s[j];
    }
    if (res == p)
      ++ans;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3584
import collections
from collections import Counter
n=int(input())
s=[input() for i in range(n)]
s=Counter(s)
p=[]
k=s.most_common()
p.append(k[0][0])
for i in range(len(collections.Counter(s))-1):
    if k[i][1]==k[i+1][1]:
        p.append(k[i+1][0])
    else:
        break
p=sorted(p)
for i in range(len(p)):
    print(p[i])



Measured memory_bytes: 120656
#include <cstdio>
#include <vector>
using namespace std;
vector<int>v[200005];
bool vis[200005];
int n,m,x,y;
int maxx=0;
int dfs(int x){
	vis[x]=true;
	int res=1;
	int si=(int)v[x].size();
	for(int i=0;i<si;++i){
		if(!vis[v[x][i]])res+=dfs(v[x][i]);
	}
	return res;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;++i){
		scanf("%d%d",&x,&y);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	for(int i=1;i<=n;++i){
		if(!vis[i]){
			int res=dfs(i);
			if(maxx<res)maxx=res;
		}
	}
	printf("%d\n",maxx);
	return 0;
}


Measured memory_bytes: 23748
import java.util.*;

public class Main {
    public static int operate(int[] a) {
        int n = a.length, cnt = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] == 1) cnt++;
        }
        int ret = 0;
        for (int i = 0; i < cnt; i++) {
            if (a[i] == 1) ret++;
        }
        ret = cnt - ret;
        return ret;
    }

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

        while (sc.hasNext()) {
            N = sc.nextInt();
            s = sc.next();
            int[] a = new int[s.length()];
            for(int i=0;i<s.length();i++){
                if(s.charAt(i)=='W') a[i] = 0;
                else a[i] = 1;
            }
            System.out.println(operate(a));
        }
        sc.close();

    }
}

Measured memory_bytes: 41504
#include <iostream>
using namespace std;
long long int r0,w,c,r,sum,ans;
int main(){
	while(1){
		cin >>r0 >>w >>c >>r;
		if(!(r0||w||c||r))break;
		sum=w*c-r0;
		if(sum<0)sum=0;
		if(sum%r==0){
			ans=sum/r;
		}else{
			ans=sum/r+1;
		}
		cout << ans<<endl;
	}
}

Measured memory_bytes: 3084
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n = int(input())
A = list(map(int, input().split()))

inc = None
c = 0
 
for i in range(n-1):
    if inc == None:
        if A[i] == A[i+1]:
            pass
        elif A[i] < A[i+1]:
            inc = True
        else:
            inc = False
    elif inc:
        if A[i] > A[i+1]:
            c += 1
            inc = None
    else:
        if A[i] < A[i+1]:
            c += 1
            inc = None

print(c+1)


Measured memory_bytes: 14252
n, m = map(int, input().split())
ab = []
import numpy as np
par = [[] for i in range(n)]
for i in range(m):
  a, b = map(int, input().split())
  par[a-1].append(b-1)
  par[b-1].append(a-1)
d = [-1 for i in range(n)]
d[0] = 0

import queue
q = queue.Queue()
q.put(0)
while not q.empty():
  current = q.get()
  
  for p in par[current]:
    if d[p] == -1:
      q.put(p)
      d[p] = current
if -1 in d:
  print("No")
else:
  print("Yes")
  for p in d[1:]:
    print(p+1)

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



int main(){
    string s,s2;
    cin>>s;
    s2=s;
    reverse(s2.begin(), s2.end());
    
    int i=0;
    while (s[i]!='A') {
        i++;
    }
    
    int k=0;
    while (s2[k]!='Z') {
        k++;
    }
    
    int ans=(int)s.length()-i-k;
    
    cout<<ans;
    
    return 0;
    
}


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

int main() {

	int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans = 0;
	int index = 0;
	int cnt = 1;
	while (true) {
		if (index == n) {
			break;
		}

		if (a[index] == cnt) {
			cnt++;
		}
		else { 
			ans++;			
		}
		index++;
	}

	if (cnt != 1) cout << ans << endl;
	else cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

int main() {
    string S; ll K;
    cin>>S>>K;

    vector<int> renzoku;

    int cnt=1;

    for (int i = 1; i < S.length(); ++i) {
        if(S[i]==S[i-1]) cnt++;
        else{
            renzoku.push_back(cnt);
            cnt=1;
        }
    }
    renzoku.push_back(cnt);
    /*
    for(auto i:renzoku){
        cout<<i<<endl;
    }
    */
    ll ans=0ll;

    if(renzoku.size()==1){
        ans=(K*renzoku[0])/2;
    }else if(S[0]==S[S.length()-1]){
        for(int i=1;i<renzoku.size()-1;i++){
            ans+=(ll)renzoku[i]/2;
        }
        ans*=K;
        ans+=(((ll)renzoku[0]+renzoku[renzoku.size()-1])/2)*(K-1);
        ans+=(ll)renzoku[0]/2;
        ans+=(ll)renzoku[renzoku.size()-1]/2;
    }else{
        for (auto i:renzoku) {
            ans+=(ll)i/2;
        }
        ans*=K;
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
//#include <random>
//#include <unordered_set>
#include <complex>
using namespace std;
int main()
{
    int a,b,c,x,sum=0,i,j,k;
    cin>>a>>b>>c>>x;
    for(i=0;i<=a;i++) 
    {
        for(j=0;j<=b;j++) 
        {
            for(k=0;k<=c;k++) if(((i*500)+(j*100)+(k*50))==x) sum++;
        }
    }
    cout<<sum;
    system ("pause"); 
    return 0;
}

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

int M=100000;

int main(){
while(1){
	int w,h;
	int dp[102][102][2][2]={0};

	scanf("%d%d",&w,&h); if(w==0)break;
	dp[2][1][0][0]=1; dp[1][2][1][0]=1;
	for(int i=1;i<=w;i++){
		for(int j=1;j<=h;j++){
			dp[i][j][0][0]%=M;
			dp[i][j][0][1]%=M;
			dp[i][j][1][0]%=M;
			dp[i][j][1][1]%=M;

			dp[i+1][j][0][0]+=dp[i][j][0][0];
			dp[i][j+1][1][1]+=dp[i][j][0][0];
			dp[i+1][j][0][0]+=dp[i][j][0][1];
			dp[i+1][j][0][1]+=dp[i][j][1][0];
			dp[i][j+1][1][0]+=dp[i][j][1][0];
			dp[i][j+1][1][0]+=dp[i][j][1][1];
		}
	}

	printf("%d\n",(dp[w][h][0][0]+dp[w][h][0][1]+dp[w][h][1][0]+dp[w][h][1][1])%M);
}
}

Measured memory_bytes: 1340
#include <stdio.h>
 
int main(int argc,const char * argv[]){
int a,b,c,tmp;
scanf("%d %d %d",&a,&b,&c);
if(a>b){
tmp=a;
a=b;
b=tmp;
}
if(a>c){
tmp=a;
a=c;
c=tmp;
}
if(b>c){
tmp=b;
b=c;
c=tmp;
}
printf("%d %d %d\n",a,b,c);
return 0;
}

Measured memory_bytes: 596
n = int(input())

eq = 0
mx = 0
prev = False
for i in range(n):
    d = [int(s) for s in input().split(' ')]
    if d[0] == d[1]:
        if prev:
            eq += 1
        prev = True
        mx = max(eq, mx)
    else:
        prev = False
        eq = 0

if mx >= 2:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9192
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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

int adj[10][10];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    REP(i,M){
        int a, b;
        cin >> a >> b;
        --a, --b;
        adj[a][b] = 1;
        adj[b][a] = 1;
    }

    vector<int> p(N);
    iota(p.begin(), p.end(), 0);
    int ans = 0;
    do{
        if(p[0] != 0) continue;
        bool ok = true;
        for(int i=1;i<N;i++){
            if(!adj[p[i]][p[i-1]]) ok = false;
        }
        if(ok) ans++;
    }while(next_permutation(p.begin(), p.end()));

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>

using namespace std;

int main()
{
	char a[20];

	scanf("%s", a);

	for (int i = 0; i <= 4; i++) {
		printf("%c", a[i]);
	}
	printf(" ");
	for (int i = 6; i <=12; i++) {
		printf("%c", a[i]);
	}
	printf(" ");
	for (int i = 14; i <= 18; i++) {
		printf("%c", a[i]);
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int i,j,n = sc.nextInt();
        double ptx[] = new double [n];
        double pty[] = new double [n];
        double dt=0.0;
 
        for(i=0;i<n;i++){
            ptx[i] = sc.nextDouble();
        }
        for(i=0;i<n;i++){
            pty[i] = sc.nextDouble();
        }
        for(i=0;i<4;i++){
            dt = 0.0;
            if(i == 0){
                for(j=0;j<n;j++){
                    dt += Math.abs((ptx[j]-pty[j]));
                }
                System.out.printf("%.6f\n", dt);
            }
            else if(i == 1){
                for(j=0;j<n;j++){
                    dt += Math.pow(Math.abs((ptx[j]-pty[j])),2.0);
                }
                dt = Math.sqrt(dt);
                System.out.printf("%.6f\n", dt);
            }
            else if(i == 2){
                for(j=0;j<n;j++){
                    dt += Math.pow(Math.abs((ptx[j]-pty[j])),3.0);
                }
                dt = Math.cbrt(dt);
                System.out.printf("%.6f\n", dt);
            }
            else{
                for(j=0;j<n;j++){
                    if(dt < Math.abs((ptx[j]-pty[j]))){
                        dt = Math.abs((ptx[j]-pty[j]));
                    }
 
                }
                System.out.printf("%.6f\n", dt);
            }
        }
 
        sc.close();
    }
}



Measured memory_bytes: 29200
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, start, end) for(int i = start; i < (int)(end); ++i)

int main(){
    long long a, b, k;
    cin >> a >> b >> k;
    if(a <= k){
        k -= a;
        a = 0;
        b = max(0ll, b-k);
    }else{
        a -= k;
    }
    cout << a << " " << b << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

const int M = 1e9 + 7;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    vector<pair<ll, ll>> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }

    auto comp = [&](pair<ll, ll>& a, pair<ll, ll>& b) {
        return a.first + a.second < b.first + b.second;
    };

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

    vector<vector<ll>> dp(2, vector<ll>(n + 1, 1e14));

    dp[0][0] = 0;

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {

            dp[i%2][j] = dp[(i - 1)%2][j];


            if (A[i - 1].first >= dp[(i - 1)%2][j - 1]) {
                dp[i%2][j] = min(dp[i%2][j], A[i - 1].second + dp[(i - 1)%2][j - 1]);
            }
        }
    }

    // cout <<"dp array :: "<< "\n";

    // for(int i = 1 ; i <= n ;++i){
    //     for(int j = 1 ; j <= n ;++j){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << "\n";
    // }
    for (int j = n; j >= 0; --j) {
        if (dp[n%2][j] != 1e14) {
            cout << j << "\n";
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 512
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;

int main(){
	long long n, a, b;
	cin >> n >> a >> b;
	vector<long long> x(n);
	for(long long i = 0; i < n; i++){
		cin >> x.at(i);
	}
	long long ans = 0;
	for(long long i = 1; i < n; i++){
		ans += min((x.at(i) - x.at(i - 1)) * a, b);	
	}
	cout << ans<< endl;

	return 0;
}



Measured memory_bytes: 1024