akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <bits/extc++.h>
#define calc(a,b,c,d) max(a, max(b, max(c, d))) - min(a, min(b, min(c, d)))
using namespace std;

int n, a[200010], p[200010], s[200010];
long long ps[200010], ss[200010];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	for (int i = 1; i <= n; ++i)
		ps[i] = ps[i - 1] + a[i];
	for (int i = n; i >= 1; --i)
		ss[i] = ss[i + 1] + a[i];
	for (int i = 2, j = 1; i <= n - 2; ++i) {
		while (ps[j + 1] << 1 <= ps[i]) ++j;
		p[i] = ps[i] - (ps[j] << 1) < (ps[j + 1] << 1) - ps[i] ? j : j + 1;
	}
	for (int i = n - 1, j = n; i >= 3; --i) {
		while (ss[j - 1] << 1 <= ss[i]) --j;
		s[i] = ss[i] - (ss[j] << 1) < (ss[j - 1] << 1) - ss[i] ? j : j - 1;
	}
	
	long long ans = 200000000000000;
	for (int i = 2; i <= n; ++i)
		ans = min(ans, calc(ps[p[i]], ps[i] - ps[p[i]],
					ss[i + 1] - ss[s[i + 1]], ss[s[i + 1]]));
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 9292
N=int(input())
first=0
second=0
d=[0]
for i in range(N):
  a=int(input())
  if first<a:
    first=a
    d=i
  elif second<a:
    second=a
if first==second:
  for _ in range(N):
    print(first)
else:
  for j in range(N):
    if j==d:
      print(second)
    else:
      print(first)

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

#define all(s) s.begin(), s.end()
#define vi vector<int>
#define pb push_back
#define ii pair<int, int>
#define x first
#define y second
#define int long long

int res, sum[200005], k;
map<int, int> cnt;

main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cnt[0] = 1;
    int n;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        int u;
        cin >> u;
        sum[i] = sum[i - 1] + u - 1;
        sum[i] %= k;
        if (i >= k) cnt[sum[i - k]]--;
        res += cnt[sum[i]];
        cnt[sum[i]]++;
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 14336
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		Dice dice = new Dice();
		for(int i = 0 ; i < 6 ; i ++){
			dice.d[i]=scan.nextInt();
		}
		String str = scan.next();
		for(int i = 0 ; i < str.length() ; i ++){
			char operation = str.charAt(i);
			switch(operation){
				case 'N':
					dice.N();
					break;
				case 'S':
					dice.S();
					break;
				case 'W':
					dice.W();
					break;
				case 'E':
					dice.E();
					break;
			}
		}
		System.out.println(dice.d[0]);
	}
}
class Dice{
	public int[] d = new int[6];
	private int temp=0;	
	void N(){
		temp=d[0];
		d[0]=d[1];
		d[1]=d[5];
		d[5]=d[4];
		d[4]=temp;
	}
	void S(){
		temp=d[0];
		d[0]=d[4];
		d[4]=d[5];
		d[5]=d[1];
		d[1]=temp;
	}
	void E(){
		temp=d[0];
		d[0]=d[3];
		d[3]=d[5];
		d[5]=d[2];
		d[2]=temp;
	}
	void W(){
		temp=d[0];
		d[0]=d[2];
		d[2]=d[5];
		d[5]=d[3];
		d[3]=temp;
	}
}

Measured memory_bytes: 17176
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define For(i,n) for(int i=0;i<n;i++)
#define Fre(i,a,b) for(int i = a; i < b; i++)
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pfn(n) printf("%d\n", n)
#define pfs(n) printf("%d ", n)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define READ freopen("in.txt", "r", stdin)
#define WRITE freopen("out.txt", "w", stdout)
#define sz size()
#define number_of_digit(n) __builtin_ffs(n);
#define ll long long
#define T int
#define ld long double
inline void print(T n)
{
	if (n == 0)
	{
		putchar('0');
		putchar('\n');
	}
	else if (n == -1)
	{
		putchar('-');
		putchar('1');
		putchar('\n');
	}
	else
	{
		char buf[11];
		buf[10] = '\n';
		int i = 9;
		while (n)
		{
			buf[i--] = n % 10 + '0';
			n /= 10;
		}
		while (buf[i] != '\n')
			putchar(buf[++i]);
	}
}
int read()
{
       int cc = getc(stdin);
       for (;cc < '0' || cc > '9';)  cc = getc(stdin);
       int ret = 0;
       for (;cc >= '0' && cc <= '9';)
       {
          ret = ret * 10 + cc - '0';
          cc = getc(stdin);
       }
      return ret;
}
ll power(ll num,ll g)
{
	if(g==0)return 1;

	if(g%2==1)return (num*power((num*num)%mod,g/2))%mod;
	return power((num*num)%mod,g/2);
}
bool visit[1000005];
string s,t,r;
int l,l1;
int a[3005][3005];
int main()
{
	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
  	cout.tie(NULL);

  	cin>>s>>t;
  	int n=s.size();
  	int m=t.size();
  	r="";
  	For(i,3005)For(j,3005)a[i][j]=0;
  	for(int i=1;i<=n;i++)
  	{
  		for(int j=1;j<=m;j++)
  		{
  			if(s[i-1]==t[j-1])
  			{
  				a[i][j]=a[i-1][j-1]+1;
  			}
  			else a[i][j]=max(a[i-1][j],a[i][j-1]);
  		}
  	}
  	if(a[n][m]==0)
  	{
  		cout<<endl;
  		return 0;
  	}
  	int i=n,j=m;
  	while(a[i][j]>0)
  	{
  		if(a[i][j]==a[i-1][j])i--;
  		else if(a[i][j]==a[i][j-1])j--;
  		else
  		{
  			r+=s[i-1];
  			i--;
  			j--;
  		}
  	}
  	reverse(r.begin(),r.end());
  	cout<<r<<endl;
	return 0;
}

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

using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb emplace_back
#define ll long long
#define ld long double

const int INF = 2e9 + 1;
const ll INFLL = 1e18 + 1;
const int mod = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    for (auto &c : a) {
        cin >> c;
        sum += c;
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        cnt += (a[i] * 4 * m >= sum);
    }
    cout << (cnt >= m ? "Yes" : "No");
    return 0;
}


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

#define ll long long
#define pb push_back
#define mp make_pair
#define um unordered_map
#define us unordered_set
#define mod 1000000007
#define all(x) x.begin(),x.end()

using namespace std;

int solve(vector<int> a,int n){
	return 0;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int cnt=0;
	while(n--){
		int a,b;
		cin>>a>>b;
		if(a==b){
			cnt++;
		}
		else{
			cnt=0;
		}
		if(cnt==3){
			cout<<"Yes";
			exit(0);
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
    ll a,b,c;cin>>a>>b>>c;
    vector<ll> v={a,b,c};
    sort(all(v));
    cout << (v[0]+v[1]==v[2]?"Yes":"No")<< ednl;
}



Measured memory_bytes: 256
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <string>
using namespace std;
#define LL long long
const int N=100005;
LL a[N],x[N];
int main()
{
  //  freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    int i,n;LL sum=0,t;
    scanf("%d",&n);
    for (i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        sum+=a[i],t+=((LL)i);
    }
    if (sum%t!=0) {puts("NO");return 0;}
    if (n==1) {puts("YES");return 0;}
    if (n==2)
    {
        LL x,y=(a[1]*2-a[2])/3;x=a[1]-2*y;
        if (x>=0&&y>=0) puts("YES"); else puts("NO");
        return 0;
    } 
    t=sum/t;
    for (i=3;i<=n;i++) 
     if ((t+a[i-1]-a[i])%n!=0) break; 
      else x[n-i+2]=(t+a[i-1]-a[i])/n;
    if (i<=n) {puts("NO");return 0;}
    x[n]=2*t-a[2];
    for (i=2;i<=n-1;i++) x[n]+=((LL)(i-1))*x[i];
    x[1]=t;
    for (i=2;i<=n;i++) x[1]-=x[i];
    for (i=1;i<=n;i++) if (x[i]<0) break;
    if (i<=n) puts("NO"); else puts("YES");
    
    return 0;
}


Measured memory_bytes: 1792
function Main(input) {
	var array = input.split(' ');
	var mul = parseInt(array[0], 10);
  	var b = parseInt(array[1], 10);
    var time = parseInt(array[2], 10);
  	var biscuits = 0;
  	for(var i = 1; i <= time; i++) {
		if(!(i%mul)) {
          biscuits = biscuits + b;
        }
    }
  	//出力
	console.log(biscuits);
}

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

Measured memory_bytes: 7372
#include<stdio.h>
typedef struct{
  char name[25];
  int point;
  int no;
}P;
main(){
  int a,b,c,n,i,j,flag=0;
  while(1){

    scanf("%d",&n);
    if(n==0)break;
    if(flag!=0)printf("\n");
    flag=1;
    P temp[n];
    for(i=0;i<n;i++)temp[i].no=i;
    P flg;
    for(i=0;i<n;i++){
      scanf("%s %d %d %d",temp[i].name,&a,&b,&c);
      temp[i].point=a*3+c;
    }

    for(i=0;i<n-1;i++){
      for(j=n-1;j>i;j--){
	if(temp[j].point>temp[j-1].point){
	  flg=temp[j];
	  temp[j]=temp[j-1];
	  temp[j-1]=flg;
	}
      }
    }
  loop:
    for(j=0;j<n-1;j++){
      if(temp[j].point==temp[j+1].point){
	if(temp[j].no>temp[j+1].no){
	  flg=temp[j];
	  temp[j]=temp[j+1];
	  temp[j+1]=flg;
	  goto loop;
	}
      }
    }
    for(i=0;i<n;i++){
      printf("%s,%d\n",temp[i].name,temp[i].point);
    }
  }
    
  return 0;
}

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

int main(){

  int n, y, b, r, t; //銀行の数,年数,銀行番号,年利率,金利の種類

  while(cin >> n, n){
    cin >> y;

    int ans = 0;
    double  res = 0;
    for(int i=0;i<n;i++){
      cin >> b >> r >> t;

      double k = (1+y*((double)r/(double)100));
      double l = pow((1+((double)r/(double)100)), y);

      if(t == 1 && res < k){
	ans = b;
	res = k;
      }

      if(t == 2 && res < l){
	ans = b;
	res = l;
      }

    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
int main(){
    bool bools = true;
    while(bools){
        int a,b;
        char op;
        cin >> a >> op >> b;
        if(op == '?'){
            bools = false;
        }
        if(op == '+'){
            cout << a+b << endl;
        }
        else if(op == '-'){
            cout << a-b << endl;
        }
        else if(op == '*'){
            cout << a*b << endl;
        }
        else if(op == '/'){
            cout << a/b << endl;
        }
    }
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) { cin >> h[i]; }
  
  int ans = 0;
  int max_h = h[0];
  rep(i, n) {
    if (max_h <= h[i]) ans++;
    max_h = max(max_h, h[i]);
  }
  cout << ans << endl;
  return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int n, m, x;
    cin >> n >> m >> x;
    int masu[n + 1] = {};
    rep(i, m) {
        int a;
        cin >> a;
        masu[a] = 1;
    }
    int r = 0, l = 0;
    repl(i, x, n + 1) r += masu[i];
    repr(i, x, 0) l += masu[i];
    cout << min(r, l) << endl;
    return 0;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

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

	string S; cin >> S;
	int X, Y; cin >> X >> Y;

	bitset<16001> pxs;
	bitset<16001> pys;
	pxs[0+8000] = true;
	pys[0+8000] = true;


	bool isX = true;
	F0R(k, S.size()) {
		if (S[k] == 'T') {isX = !isX; continue;}
		int j = k;
		while (j < S.size() && S[j] == 'F') ++j;

		bitset<16001> newpxs;
		bitset<16001> newpys;
		int dist = j - k;
		F0R(i, 16001) {
			if (isX) {
				if (pxs[i] && i + dist < 16001) newpxs[i+dist] = true;
				if (k > 0 && pxs[i] && i - dist >= 0)   newpxs[i-dist] = true;	
			} else {
				if (pys[i] && i + dist < 16001) newpys[i+dist] = true;
				if (pys[i] && i - dist >= 0)   newpys[i-dist] = true;
			}
		}

		if (isX) pxs = newpxs;
		else pys = newpys;
		
		k = j - 1;
	}

	print((pxs[X + 8000] && pys[Y + 8000]) ? "Yes" : "No");
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;

int main()
{
    int n,t;
    vector<int> l,r;
    cin>>n;
    rep(i,n){
        cin>>t;
        l.pb(t);
        r.pb(t);
    }
    sort(all(l));
    int count=0;

    rep(i,n){
        if(l.at(i)!=r.at(i)){
            count++;
        }
    }

    if(count>=3){
        cout<<"NO";
    }
    else{
        cout<<"YES";
    }
}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            String originalSequence = "";
            while (originalSequence.length() == 0) {
                originalSequence = scanner.nextLine();
            }
            if (originalSequence.equals("-")) {
                break;
            }
            ArrayDeque<Character> chars = new ArrayDeque<Character>();
            for (int i = 0; i < originalSequence.length(); i++) {
                chars.add(originalSequence.charAt(i));
            }
            int n = scanner.nextInt();
            for (int i = 0; i < n; i++) {
                int h = scanner.nextInt();
                for (int j = 0; j < h; j++) {
                    chars.add(chars.removeFirst());
                }
            }
            while (chars.size() > 0) {
                System.out.print(chars.removeFirst());
            }
            System.out.println("");
        }
    }
}



Measured memory_bytes: 26476
import math
from collections import deque
from collections import defaultdict
import itertools as it
 
#自作関数群
def readInt():
 return int(input())
def readInts():
 return list(map(int, input().split()))
def readChar():
 return input()
def readChars():
 return input().split()
def factorization(n):
 res = []
 if n%2==0:
  res.append(2)
 for i in range(3,math.floor(n//2)+1,2):
  if n%i==0:
   c = 0
   for j in res:
    if i%j==0:
     c=1
   if c==0:
    res.append(i)
 return res
def fact2(n):
 p = factorization(n)
 res = []
 for i in p:
  c=0
  z=n
  while 1:
   if z%i==0:
    c+=1
    z/=i
   else:
    break
  res.append([i,c])
 return res
def fact(n):#階乗
 ans = 1
 m=n
 for _i in range(n-1):
  ans*=m
  m-=1
 return ans
def comb(n,r):#コンビネーション
 if n<r:
  return 0
 l = min(r,n-r)
 m=n
 u=1
 for _i in range(l):
  u*=m
  m-=1
 return u//fact(l)
def combmod(n,r,mod):
 return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
 r=copyQueue(q)
 ans=[0]*r.qsize()
 for i in range(r.qsize()-1,-1,-1):
  ans[i] = r.get()
 print(ans)
class UnionFind():
 def __init__(self, n):
  self.n = n
  self.parents = [-1]*n
 
 def find(self, x): # root
  if self.parents[x]<0:
   return x
  else:
   self.parents[x] = self.find(self.parents[x])
   return self.parents[x]
 
 def union(self,x,y):
  x = self.find(x)
  y = self.find(y)
 
  if x==y:
   return
 
  if self.parents[x]>self.parents[y]:
   x,y = y,x
 
  self.parents[x]+=self.parents[y]
  self.parents[y]=x
 
 def size(self,x):
  return -1*self.parents[self.find(x)]
 
 def same(self,x,y):
  return self.find(x)==self.find(y)
 
 def members(self,x): # much time
  root = self.find(x)
  return [i for i in range(self.n) if self.find(i)==root]
 
 def roots(self):
  return [i for i,x in enumerate(self.parents) if x<0]
 
 def group_count(self):
  return len(self.roots())
 
 def all_group_members(self):
  return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
 x = 1
 zero = "0"*n
 ans = []
 ans.append([0]*n)
 for i in range(2**n-1):
  ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
  x+=1
 return ans;
def arrsSum(a1,a2):
 for i in range(len(a1)):
  a1[i]+=a2[i]
 return a1
def maxValue(a,b,v):
 v2 = v
 for i in range(v2,-1,-1):
  for j in range(v2//a+1): #j:aの個数
   k = i-a*j
   if k%b==0:
    return i
 return -1
def copyQueue(q):
 nq = queue.Queue()
 n = q.qsize()
 for i in range(n):
  x = q.get()
  q.put(x)
  nq.put(x)
 return nq
def get_sieve_of_eratosthenes(n):
 #data = [2]
 data = [0,0,0]
 for i in range(3,n+1,2):
  data.append(i)
  data.append(0)
 for i in range(len(data)):
  interval = data[i]
  if interval!=0:
   for j in range(i+interval,n-1,interval):
    data[j] = 0
 #ans = [x for x in data if x!=0]
 ans = data[:]
 return ans
 
x = readInts()
 
for i in range(1,6):
 if x[i-1]!=i:
  print(i)

Measured memory_bytes: 9516
import numpy as np
N, K = map(int, input().split())
S = input()
len0 = [len(i) for i in S.split('1') if (len(i)) != 0]
len1 = [len(i) for i in S.split('0') if (len(i)) != 0]

lens = np.zeros(len(len0)+len(len1), dtype=np.int)
if(int(S[0])==0):
    lens[::2] = len0
    lens[1::2] = len1
else:
    lens[::2] = len1
    lens[1::2] = len0
lens = np.cumsum(lens)
    
if(S[0] == "0"):
    lens = np.insert(lens, 0, 0)
lens = np.append(lens, [lens[-1]]*(K*2))

if(K >= len(len0)):
    print(len(S))
else:
    ans = []
    max_num = 0
    for first, i in enumerate(range(K*2, len(lens), 2)):
        if(first == 0):
            ans = lens[i]
        else:
            ans = lens[i] - lens[i-(K*2)-1]
        if(ans > max_num):
            max_num = ans
    
    print(max_num)


Measured memory_bytes: 17620
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> A;
    A.reserve(n); //要素数を予約
    for (int i = 0; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        A.push_back(make_pair(x, y));
    }
    sort(A.begin(), A.end());

    for (auto it = A.begin(); it != A.end(); it++)
    {
        // pair<int, int> P = *it;
        cout << it->first << ' ' << it->second << endl;
    }
}


Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<set>
#include<regex>
#include<ctype.h>
using namespace std;

int main(void) {
	
	int n, h[20];
	cin >> n;
	for (int i = 0; i < n; i++) cin >> h[i];

	int ans = 0;
	for (int i = 0; i < n; i++) {
		int flag = 0;
		for (int j = 0; j < i; j++) {
			if (i == j) continue;
			if (h[i] < h[j]) {
				flag = 1;
				break;
			}
		}
		if (flag == 0) ans++;
	}

	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  int b = 0;  
  cin>>a; 
  for(int i=0;i<3;i++){
    if(a%2 == 1){
      b= b+1;
    }
    a=a/10;    
  }
  cout<< b << endl;
}

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


 
int main(){
	long long x;
	cin>>x;
	long long ans=0;
	long long dep=100;
	while(true){
		if(x<=dep)break;
		ans++;
		dep=dep*1.01;
	}
	cout<<ans<<endl;	
}

Measured memory_bytes: 3640
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int n;

  cin >> n;

  cout << (n == 0);

  return 0;
}
/*

*/


Measured memory_bytes: 3660
n=int(input())
c0=0
c1=0
c2=0
c3=0
while(n>0):
    s=input()
    if(s=="AC"):
        c0+=1
    elif(s=="WA"):
        c1+=1
    elif(s=="TLE"):
        c2+=1
    elif(s=="RE"):
        c3+=1
    n=n-1
print("AC x",c0)
print("WA x",c1)
print("TLE x",c2)
print("RE x",c3)
    

Measured memory_bytes: 9164
using System;

class Program
{
    static void Main()
    {
        string[] sp = Console.ReadLine().Split(' ');
        int x = int.Parse(sp[0]);
        int y = int.Parse(sp[1]);
        int z = int.Parse(sp[2]);
        if (x < y && y<z) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}

Measured memory_bytes: 19608
#include <bits/stdc++.h>
#include <map> // pair
using namespace std;
int main(){

    string S;
    cin>>S;
    string cor="CODEFESTIVAL2016";
    int count=0;
    for(int i=0;i<16;i++){
      if(S.at(i)!=cor.at(i))count++;
    }
    cout<<count<<endl;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fo(i,m,n) for(int i = m; i <= n; i++)
#define fod(i,m,n) for(int i = m; i >= n; i--)
#define fov(i,x) for(auto &i : x)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> _ii;
int H,W,m;
vector <int> hang,cot;
vector <int> a,b;
map <_ii,int> A;
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
    cin >> H >> W >> m;
    hang.resize(H+1,0);
    cot.resize(W+1,0);
    fo(i,1,m)
    {
        int _x,_y;
        cin >> _x >> _y;
        hang[_x]++;
        cot[_y]++;
        A[_ii(_x,_y)]++;
    }
    int p = *max_element(hang.begin(),hang.end());
    fo(i,1,H) if(hang[i] == p) a.push_back(i);
    p = *max_element(cot.begin(),cot.end());
    fo(i,1,W) if(cot[i] == p) b.push_back(i);
    int sum = hang[a[0]] + cot[b[0]];
    fov(i,a)
    {
        fov(j,b)
        {
            if(A.find(_ii(i,j)) == A.end())
            {
                cout << sum << '\n';
                return 0;
            }
        }
    }
    cout << sum-1 << '\n';
    return 0;
}


Measured memory_bytes: 28508
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            // input
            int H = Integer.parseInt(sc.next());
            int W = Integer.parseInt(sc.next());
            int K = Integer.parseInt(sc.next());
            char[][] c = new char[H][W];
            int total = 0;
            for (int i = 0; i < H; i++) {
                c[i] = sc.next().toCharArray();
                for (char ch : c[i]) {
                    if (ch == '#') total++;
                }
            }

            // calc
            int ans = 0;
            for (int hi = 0; hi < Math.pow(2, H); hi++) {
                for (int wi = 0; wi < Math.pow(2, W); wi++) {
                    char[][] tmp = new char[H][W];
                    // H
                    for (int i = 0; i < H; i++) {
                        if ((1&hi >>> i) == 1) {
                            tmp[i] = c[i];
                        }
                    }
                    // W
                    for (int j = 0; j < W; j++){
                        if ((1&wi >>> j) == 1) {
                            for (int i = 0; i < H; i++) {
                                tmp[i][j] = c[i][j];
                            }
                        }
                    }
                    // calc
                    int cnt = 0;
                    for (int i = 0; i < H; i++) {
                        for (int j = 0; j < W; j++) {
                            if (tmp[i][j] == '#') cnt++;
                        }
                    }
                    if ((total - K) == cnt) ans++;
                }
            }
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 37920
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define LL long long
using namespace std;
int main(void)
{
	LL i,j,L,R,ans=2020;
	scanf("%lld%lld",&L,&R);
	if((R-L)>2019){printf("0\n");return 0;}
	for(i=L;i<=R;++i)
	{
		for(j=i+1;j<=R;++j)ans=min(ans,i*j%2019);
	}
	printf("%lld\n",ans);
	return 0;
}


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

a,b,c,d =map(int,input().split())

m = a +b -c-d

if m>0:
    print("Left")
elif m ==0:
    print("Balanced")
else:
    print("Right")

Measured memory_bytes: 2940
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Falling Asleep
 */

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

using namespace std;

/* constant */

const int MAX_N = 50;

/* typedef */

/* global variables */

char ms[MAX_N][128];
int ts[MAX_N];

/* subroutines */

/* main */

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

  for (int i = 0; i < n; i++) scanf("%s%d", ms[i], ts + i);

  char s[128];
  scanf("%s", s);

  int k = 0;
  while (k < n && strcmp(ms[k], s) != 0) k++;

  int tsum = 0;
  for (int i = k + 1; i < n; i++) tsum += ts[i];

  printf("%d\n", tsum);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
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; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  cin>>n;
  vll a(0);
  a.pb(1);
  ll cu=6;
  for(int i=1;cu<=n;i++){
    a.pb(cu);
    cu*=6;
  }
  cu=9;
  for(int i=1;cu<=n;i++){
    a.pb(cu);
    cu*=9;
  }
  sort(all(a));
  vll dp(n+1,INF);
  dp[0]=0;
  rep(i,n){
    rep(j,sz(a)){
      if(a[j]+i<=n){
        chmin(dp[i+a[j]],dp[i]+1);
      }
    }
  }
  COUT(dp[n]);
}


Measured memory_bytes: 4052
import java.util.Scanner;
import java.util.Locale;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Main {
  public static void main(String[] args ){

    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
    int oddNum = ( K + 1 ) / 2;
    int evenNum = K / 2;

    System.out.println(oddNum * evenNum);
  }
}


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

if n < 10:
    print(n)

elif n < 100:
    print(9)
elif n < 1000:
    print(9 + n-100+1)
elif n < 10000:
    print(9+999-100+1)
elif n < 100000:
    print(9+999-100+1 +n-10000+1)
elif n == 100000:
    print(90909)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bs binary_search
#define pb push_back
#define pp pair<int,int>
#define F first 
#define S second 
#define lc "\n"
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;} 
ll MAX=1e18 , MIN=-1e18 , MOD=1000000007;
int main()
{
    fastio
    map<ll,ll>mp;
    ll n,i,j,q,b,c,s=0; cin>>n; ll a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        s+=a[i]; mp[a[i]]++;
    }
    cin>>q;
    while(q--)
    {
        cin>>b>>c;
        if(mp[b]>0)
        {
            j=mp[b];
            s=s-j*b; mp[b]=0;
            mp[c]+=j; s=s+j*c;
        }
        cout<<s<<lc;
    }
    return 0;
}

Measured memory_bytes: 10108
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const int MOD = 998244353;

int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0; i<n; ++i)
        cin >> v[i];
    int sum = accumulate(v.begin(), v.end(), 0);

    vector<long long> dp(sum+1, 0), dp2(sum+1, 0);
    dp[0] = 1;
    dp2[0] = 1;
    for(int i=0; i<n; ++i){
        for(int j=sum; j>=0; --j){
            dp[j] *= 2;
            dp[j] %= MOD;
            if(j >= v[i]){
                dp[j] += dp[j-v[i]];
                dp[j] %= MOD;
                dp2[j] += dp2[j-v[i]];
                dp2[j] %= MOD;
            }
        }
    }

    long long ans = 1;
    for(int i=0; i<n; ++i){
        ans *= 3;
        ans %= MOD;
    }
    for(int i=(sum+1)/2; i<=sum; ++i){
        ans -= dp[i] * 3;
        ans %= MOD;
        ans += MOD;
        ans %= MOD;
    }
    if(sum % 2 == 0){
        ans += dp2[sum/2] * 3;
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1664
//     自己选择的路，跪着也要走完。朋友们，虽然这个世界日益浮躁起来，只
// 要能够为了当时纯粹的梦想和感动坚持努力下去，不管其它人怎么样，我们也
// 能够保持自己的本色走下去。                               ——陈立杰
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

typedef signed char          int8;
typedef unsigned char       uint8;
typedef short                int16;
typedef unsigned short      uint16;
typedef int                  int32;
typedef unsigned            uint32;
typedef long long            int64;
typedef unsigned long long  uint64;

template <typename Int>
inline Int read()       
{
    Int flag = 1;
    char c = getchar();
    while ((!isdigit(c)) && c != '-') c = getchar();
    if (c == '-') flag = -1, c = getchar();
    Int init = c & 15;
    while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}

template <typename Int>
inline Int read(char &c)       
{
    Int flag = 1;
    c = getchar();
    while ((!isdigit(c)) && c != '-') c = getchar();
    if (c == '-') flag = -1, c = getchar();
    Int init = c & 15;
    while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}

template <typename Int>
inline void write(Int x)
{
    if (x < 0) putchar('-'), x = ~x + 1;
    if (x > 9) write(x / 10);
    putchar((x % 10) | 48);
}  

template <typename Int>
inline void write(Int x, char nextch)
{
    write(x);
    putchar(nextch);
}

int n;
int P;

#define min4(a, b, c, d) min(min(a, b), min(c, d))
bool status[507][507];
int ans[507][507], tot;

void Upd(int x, int y, int v) {
    if (x < 1 || x > n || y < 1 || y > n) return;
    if (v < ans[x][y]) {
        ans[x][y] = v;
        v += status[x][y];
        Upd(x - 1, y, v);
        Upd(x + 1, y, v);
        Upd(x, y - 1, v);
        Upd(x, y + 1, v);
    }
}

int main()
{
    n = read<int>();
    for (int i = 1; i <= n; i++) 
        for (int j = 1; j <= n; j++) {
            status[i][j] = 1;
            ans[i][j] = min4(i - 1, j - 1, n - i, n - j);
        }
    for (int i = 1, t, x, y; i <= n * n; i++) {
        P = read<int>();
        x = (P + n - 1) / n; 
        y = (P - 1) % n + 1;
        tot += ans[x][y];
        // if (ans[x][y]) printf("(%d, %d) cost %d\n", x, y, ans[x][y]);
        t = min4(ans[x - 1][y] + status[x - 1][y], ans[x + 1][y] + status[x + 1][y], 
                 ans[x][y - 1] + status[x][y - 1], ans[x][y + 1] + status[x][y + 1]);
        // printf("t = %d\n", t);
        status[x][y] = 0;
        Upd(x - 1, y, t);
        Upd(x + 1, y, t);
        Upd(x, y - 1, t);
        Upd(x, y + 1, t);
        // printf("After del (%d, %d) :\n", x, y);
        // for (int j = 1; j <= n; j++) {
        //     for (int k = 1; k <= n; k++) {
        //         write(ans[j][k], k == n ? 10 : 32);
        //     }
        // }
    }
    write(tot, 10);
    return 0;
}

Measured memory_bytes: 19968
#include  <stdio.h>

int main(){
    char a,b,c,d,e,f;
    scanf ("%c%c%c%c%c%c",&a,&b,&c,&d,&e,&f);
    if (c==d&&e==f){
       printf ("Yes\n");
    }
    else{
       printf ("No\n");
    }
    return 0;
}

Measured memory_bytes: 1572
#include <stdio.h>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

int abs(int x){
  return x > 0 ? x : -x;
}

int length(char c[]){
  int cnt=0;
  for(cnt=0;c[cnt]!='\0';cnt++){
  }
  return cnt;
}

int n,k;
int a;
vector<int> vec(200001);

int main(){
  scanf("%d %d",&n,&k);
  REP(i,200001){
    vec[i]=0;
  }
  REP(i,n){
    scanf("%d",&a);
    vec[a]++;
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(),vec.end());
  int sum = 0;
  REP(i,k){
    sum += vec[i];
  }
  printf("%d\n",n-sum);
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define pob pop_back
#define ff first
#define ss second
#define endl "\n"
#define all(a) a.begin(),a.end()
#define int long long
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
/* 	1) order_of_key (k) : Number of items strictly smaller than k .
	2) find_by_order(k) : K-th element in a set (counting from zero).
*/
using namespace __gnu_pbds;
using namespace std;
using LD = long double;

const int maxs = 1e6+1;
const int mod = 1e9+7;
const int INF = 1e18;
int row[8] = {1,1,0,-1,-1,-1,0,1};
int col[8] = {0,-1,-1,-1,0,1,1,1};

using pii = pair<int, int>;

void solve() {
	int n;
	cin >> n;
	vector<int> A(n), B(n), freq_A(n + 1,0), freq_B(n + 1,0);
	for(int i = 0; i < n; i++) {
		cin >> A[i];
		freq_A[A[i]]++;
	}
	for(int i = 0; i < n; i++) {
		cin >> B[i];
		freq_B[B[i]]++;
	}
	for(int i = 1; i <= n; i++) {
		if(freq_A[i] + freq_B[i] > n) {
			cout << "No\n";
			return;
		}
	}
	cout << "Yes\n";
	vector<int> ind(n);
	for(int i = 0; i < n; i++) {
		ind[i] = upper_bound(all(B), A[i]) - B.begin();
		if(i)
			ind[i] = max(ind[i], ind[i - 1] + 1);
	}
	for(int i = n - 2; i >= 0; i--)
		ind[i] = max(ind[i], ind[i + 1] - 1);
	for(int i = 0; i < n; i++)
		cout << B[ind[i]%n] << " ";
}
 
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t = 1,i = 1;
    //cin >> t;
    while(t--) {
        //cout << "Case #" << i << ": ";
        solve();
        //i++;
    }
    return 0;
}


Measured memory_bytes: 11180
#include<cstdio>
#include<vector>
using namespace std;

typedef long long ll;

const int MAXN = 100010;

int seq[MAXN], num[MAXN], cnt;
vector<int> cir[MAXN];
ll a[MAXN], dif[MAXN];
int ans[MAXN];

inline void Swap(int& a, int& b){a ^= b ^= a ^= b;}

int main(){
	int N, M; ll K;
	scanf("%d", &N);
	for (int i = 1, tmp; i <= N; ++i)
		scanf("%lld", &a[i]), dif[i] = a[i] - a[i - 1], seq[i] = i;
	scanf("%d %lld", &M, &K);
	for (int i = 1, tmp; i <= M; ++i)
		scanf("%d", &tmp), Swap(seq[tmp], seq[tmp + 1]);
	for (int i = 1, j; i <= N; ++i)
		if (!num[i]){
			num[i] = ++cnt, j = seq[i];
			cir[cnt].push_back(i);
			while (j != i){
				num[j] = cnt, cir[cnt].push_back(j);
				j = seq[j];
			}
		}
	for (int i = 1, st, j, k; i <= cnt; ++i){
		st = cir[i][K % (ll) cir[i].size()];
		ans[cir[i][0]] = st;
		j = seq[st], k = 1;
		while (j != st){
			ans[cir[i][k]] = j;
			j = seq[j], ++k;
		}
	}
	ll sum = 0; 
	for (int i = 1; i <= N; ++i)
		sum += dif[ans[i]], printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 11340
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

int main(){
  int n,k; cin >> n >> k;
  string s; cin >> s;
  s.erase(unique(all(s)), s.end());

  int unhappy = s.size();
  int happy = n - unhappy;
  std::cout << min(happy + 2*k , n-1) << '\n';
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S, ans, end;
  cin >> S;
  
  end = S.back();
  if(end == "3"){
    ans = "bon";
  }else if(end == "0" || end == "1" || end == "6" || end == "8"){
    ans = "pon";
  }else{
    ans = "hon";
  }
  
  cout << ans << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	ll n, m;
	cin>>n>>m;
	if(n > m)swap(n, m);
	if(n == 1){
		if(m == 1)cout<<1<<endl;
		else cout<<m - 2<<endl;
		exit(0);
	}
	if(n == 2){
		cout<<0<<endl;
		exit(0);
	}
	cout<<(n - 2)*(m - 2)<<endl;

	return 0;
}

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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

void solve() {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    REP(i,N) cin >> A[i];
    REP(i,N) cin >> B[i];
    vector<int> yoyu(N);
    REP(i,N) yoyu[i] = A[i] - B[i];

    sort(ALL(yoyu));
    reverse(ALL(yoyu));

    vector<int> yoyup;
    ll ans = 0;
    ll minus_sum = 0;
    REP(i,N) {
        if (yoyu[i] > 0) yoyup.push_back(yoyu[i]);
        else if (yoyu[i] < 0) {
            ans++;
            minus_sum += abs(yoyu[i]);
        }
    }

    while(!yoyup.empty()) {
        if (minus_sum <= 0) {
            cout << ans << endl;
            exit(0);
        }
        minus_sum -= yoyup.front(); yoyup.erase(yoyup.begin());
        ans++;
    }

    if (minus_sum >= 0) cout << -1 << endl;
    else cout << ans << endl;



}

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


Measured memory_bytes: 1792
#include<iostream>
#include<stack>
#include<cstdio>
#include<map>
#include<set>
#include<queue>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
#define me(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
const int N=1111122;
const int M=200005;
int main()
{
	ll n,i,j,a,b,sum=0,q;
	cin>>n>>a>>b;
	if(a==0)cout<<0<<endl;
	else 
	{
		q=n/(a+b);
		sum+=q*a;
		ll p=n%(a+b);
		if(p>=a)sum+=a;
		else sum+=p;
		cout<<sum<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		String N =in.next();
		if((N.charAt(1)==N.charAt(2))&&(N.charAt(1)==N.charAt(0)||N.charAt(1)==N.charAt(3)))System.out.println("Yes");
		else System.out.println("No");
	}
}

Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};


int main(){
  string s;
  string p;
  cin >> s;
  int ans = 0;
  int idxs = 1;
  int idxg = 2;
  int cnt = 1;
  p = s.substr(0,1);
  while(idxg <= s.size()){
    if(s.substr(idxs,cnt) != p){
      p = s.substr(idxs,cnt);
      idxs = idxg;
      idxg+=1;
      ans++;
      cnt = 1;
    }
    else{
      cnt++;
      idxg++;
    }
  }
  cout << ans + 1 << endl;
  return 0;
}



Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;

public class Main {
	static int v = 0;
	static List<List<Integer>> ansList = null;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		char[] s = br.readLine().toCharArray();
		br.close();

		int ans = 0;
		int l = 0;
		int r = s.length - 1;
		while (l < r) {
			if (s[l] == s[r]) {
				l++;
				r--;
			} else if (s[l] == 'x') {
				ans++;
				l++;
			} else if (s[r] == 'x') {
				ans++;
				r--;
			} else {
				System.out.println(-1);
				return;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22996
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10**7)

ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

class Combination:
    def __init__(self, max_n=100007, mod=mod):
        self.mod = mod
        self.fac = [0] * max_n
        self.finv = [0] * max_n
        self.inv = [0] * max_n

        self.fac[0] = 1
        self.fac[1] = 1
        self.finv[0] = 1
        self.finv[1] = 1
        self.inv[1] = 1
        for i in range(2, max_n):
            self.fac[i] = self.fac[i - 1] * i % self.mod
            self.inv[i] = self.mod - self.inv[self.mod % i] * (self.mod //
                                                               i) % self.mod
            self.finv[i] = self.finv[i - 1] * self.inv[i] % self.mod

    def choose(self, n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        return self.fac[n] * (self.finv[k] * self.finv[n - k] %
                              self.mod) % self.mod

n, k = na()
com = Combination(2007)

prev = 0
for i in range(1, k + 1):
    res = com.choose(n - k + 1, i)
    res *= com.choose(k - 1, i - 1)
    res %= mod
    print(res)



Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100005;
struct node
{
	int to;
	ll v;
	node(int a=0,int b=0){to=a;v=b;}
};
vector<node> path[N];
bool vis[N],use[N];
ll d[N];
bool dfs(int o)
{
	//if(vis[o]) return false;
	vis[o]=true;
	use[o]=true;
	for(int i=0;i<path[o].size();i++)
	{
		node e=path[o][i];
		if(d[e.to]>d[o]+e.v)
		{
			if(use[e.to]) return true;
			d[e.to]=d[o]+e.v;
			if(dfs(e.to)) return true;
		}
	}
	use[o]=false;
	return false;
}
int main()
{
	int n,m,a,b;
	ll dd;
	scanf("%d%d",&n,&m);
	while(m--)
	{
		scanf("%d%d%lld",&a,&b,&dd);
		path[a].push_back(node(b,dd));
		path[b].push_back(node(a,-dd));
	}
	for(int i=1;i<=n;i++) d[i]=LLONG_MAX;
	
	bool bo=false;
	for(int i=1;i<=n;i++)
	{
		if(vis[i]) continue;
		d[i]=0;
		if(dfs(i)) {bo=true;break;}
	}
	if(bo) puts("No");
	else puts("Yes");
	return 0;
}

Measured memory_bytes: 15744
# https://atcoder.jp/contests/abc120/tasks/abc120_c

input = gets.strip
stack = []
i = 0
rem = 0

stack.push input[i]
while i < input.size - 1
  i += 1
  if (input[i] == '0' && stack[-1] == '1') || (input[i] == '1' && stack[-1] == '0')
    stack.pop
    rem += 2
  else
    stack.push input[i]
  end
end

puts rem


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  map<string, int> m;

  int cmd, val;
  string lhd, rhd;
  string key;
  for (int i = 0; i < n; i++) {
    cin >> cmd;

    switch (cmd) {
      case 0:
        cin >> key >> val;
        m[key] = val;
        break;

      case 1:
        cin >> key;
        try {
          cout << m.at(key) << endl;
        } catch (out_of_range&) {
          cout << 0 << endl;
        }
        break;

      case 2:
        cin >> key;
        m.erase(key);
        break;

      case 3:
        cin >> lhd >> rhd;

        for (auto itr = m.lower_bound(lhd); itr != m.end() && itr->first <= rhd; itr++) {
          cout << itr->first << " " << itr->second << endl;
        }
    }
  }
}




Measured memory_bytes: 25896