akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
const ll mod = 1000000007;
const ll INF = 10010010010010010;

int main() {
    int n,k; cin >> n >> k;
    string s; cin >> s;
    int cnt = 0;
    rep(i,n) {
        if (s[i] == 'L') {
            if (i > 0 && s[i-1] == 'L') cnt++;
        } else {
            if (i < n-1 && s[i+1] == 'R') cnt++;
        }
    }
    int cnt2 = 0;
    rep(i,n-1) {
        if (s[i] != s[i+1]) cnt2++;
    }
    int ans = cnt + min(2*k,cnt2);
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 312345;
int a[MAX_N];
int b[MAX_N];

int main2() {
  int N = nextInt();
  string s; cin >> s;

  a[0] = 0;
  for (int i = 0; i < N; i++) {
    a[i+1] = a[i] + (s[i] == 'W');
  }
  b[N] = 0;
  for (int i = N-1; i >= 0; i--) {
    b[i] = b[i+1] + (s[i] == 'E');
  }
  ll ans = N;
  for (int i = 0; i < N; i++) {
    ll cur = a[i] + b[i+1];
    chmin(ans, cur);
  }
  cout << ans << endl;

  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

int n, m;
vector<int> v[100010];
int w[100010];
int ans[100010];
queue<int> q;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for(int i=0; i<n-1+m; ++i){
		int a, b;
		cin >> a >> b;
		v[a].push_back(b);
		++w[b];
	}
	memset(ans, -1, sizeof(ans));
	for(int i=1; i<=n; ++i)
		if(w[i] == 0){
			ans[i] = 0;
			q.push(i);
		}
	while(!q.empty()){
		int p = q.front();
		q.pop();
		for(int i=0; i<v[p].size(); ++i){
			if(w[v[p][i]] >= 2) --w[v[p][i]];
			else{
				ans[v[p][i]] = p;
				q.push(v[p][i]);
			}
		}
	}
	for(int i=1; i<=n; ++i)
		cout << ans[i] << "\n";
}

Measured memory_bytes: 7040
#include<stdio.h>

int main(){
	
	float x,max=0,min=10000;
	
	while( scanf("%f",&x) != EOF ){
		if(max<x){
			max=x;
		}
		else if(min>x){
			min=x;
		}
	}
	
	printf("%f\n",max-min);

return 0;
}

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

int N;
int A[200010];

bool judge(int mid)
{
    bool k[200020] = {0},f[200020] = {0},F = false;
    if(A[0] >= mid)k[0] = true;
    else k[0] = false;

    for(int i = 1; i < N * 2 - 1; i++)
    {
        if(A[i] >= mid)k[i] = true;
        else k[i] = false;
        if(k[i] == k[i - 1])
        {
            f[i] = f[i - 1] = true;
            F = true;
        }
    }

    if(!F)return k[N - 1] ^ (N % 2 == 0);

    for(int i = 0; i < N; i++)
    {
        if(f[N - 1 + i])return k[N - 1 + i];
        if(f[N - 1 - i])return k[N - 1 - i];
    }
    return false;
}

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N * 2 - 1; i++)scanf("%d",&A[i]);

    int l = 1,r = N * 2;
    while(r - l > 1)
    {
        int mid = (l + r) / 2;
        if(judge(mid))l = mid;
        else r = mid;
    }
    printf("%d\n",l);
    return 0;
}


Measured memory_bytes: 1408
n,m = map(int,input().split())
ab = [0]*n
cd = [0]*m

for i in range(n):
  ab[i] = input().split()
  
for i in range(m):
  cd[i] = input().split()
  
for i in range(n):
  tmp = []
  for j in range(m):
    tmp.append(abs (int(ab[i][0]) - int(cd[j][0])) + abs(int(ab[i][1]) - int(cd[j][1])))
  x = min(tmp) 
  ans = tmp.index(x)
  print(ans+1)

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

int n;
int ans = 1;
int maxh;

int main(){
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h.at(i);
  maxh = h.at(0);
  for(int i = 1; i < n; i++){
    if(maxh <= h.at(i)){
      ans++;
      maxh = h.at(i);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int m, f, r;

	while(scanf("%d %d %d\n",&m, &f, &r) && !((m == -1) && (f == -1) && (r == -1))){
		if((m == -1) || (f == -1))
			printf("F\n");
		else if(m + f >= 80)
			printf("A\n");
		else if(m + f >= 65)
			printf("B\n");
		else if(m + f >= 50)
			printf("C\n");
		else if(m + f >= 30 && r >= 50)
			printf("C\n");
		else if(m + f >= 30)
			printf("D\n");
		else
			printf("F\n");
	}

	return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

using ull = unsigned long long;


constexpr ll initVal = (1LL<<31)-1;     //TODO: fix type and value
constexpr ll initLazy = (1LL<<60)-1;    //TODO: fix type and value
template <typename T>
struct Node {
    T val;
    T lazy;
    ull l, r;
    Node<T>* l_node = nullptr;
    Node<T>* r_node = nullptr;
    Node(ull l, ull r, const T& val = initVal) : l(l), r(r), val(val), lazy(initLazy) {}
    T getVal() {
        return (lazy != initLazy ? lazy : val); //TODO: fix
    }
    T f1(const T& a, const T& b) {
        return min(a, b);               //TODO: fix
    }
    T f2(const T& a, const T& b) {
        return b;                       //TODO: fix
    }
    void push() {
        if(r - l > 1) {
            auto m = (l+r)/2;
            {
                if(l_node == nullptr) l_node = new Node(l, m);
                if(lazy != initLazy) l_node->lazy = f2(l_node->lazy, this->lazy);
            }
            {
                if(r_node == nullptr) r_node = new Node(m, r);
                if(lazy != initLazy) r_node->lazy = f2(r_node->lazy, this->lazy); 
            }
        }
        val = getVal();
        lazy = initLazy;
    }
    void fix() {
        if(r - l == 1) return;
        val = f1(l_node->getVal(), r_node->getVal());
    }
    T query(ull qL, ull qR) {
        if(qR <= l || r <= qL) return initVal;
        if(qL <= l && r <= qR) return getVal();
        if(r - l == 1)  return getVal();

        push();
        T l_val = l_node->query(qL, qR), r_val = r_node->query(qL, qR);
        return f1(l_val, r_val);
    }
    void update(ull uL, ull uR, const T& uVal) {
        if(uR <= l || r <= uL) return;
        if(uL <= l && r <= uR) lazy = f2(lazy, uVal);
        else {
            push();
            l_node->update(uL, uR, uVal);
            r_node->update(uL, uR, uVal);
            fix();
        }
    }
};

template <typename T>
struct DynamicLazySegTree {
    Node<T> root;
    DynamicLazySegTree(ull l, ull r, const T& val) : root(l, r, val) {}
    T query(ull l, ull r) {
        return root.query(l, r);
    }
    void update(ull l, ull r, const T& val) {
        root.update(l, r, val);
    }
};


int main(){
    int n, q;
    cin >> n >> q;
    DynamicLazySegTree<ll> st(0, n, initVal);
    rep(i, q) {
        int query;
        cin >> query;
        if(query == 0) {
            int s, t, x;
            cin >> s >> t >> x;
            ++t;
            st.update(s, t, x);
        }
        else {
            int s, t;
            cin >> s >> t;
            ++t;
            cout << st.query(s, t) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 15000
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#define maxn 100005
#define BASE 100000
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,bit[maxn << 1],a[maxn],b[maxn];
ll m;
inline void add(int pos,int x){
	for(int i=pos;i<=200000;i += i & -i){
		bit[i] += x;
	}
}
inline int query(int pos){
	int res = 0;
	for(int i=pos;i>0;i -= i & -i){
		res += bit[i];
	}
	return res;
}
bool check(int x){
	ll lim = (m + 1) >> 1;
	int sum = 0;
	memset(bit,0,sizeof(bit));
	add(BASE,1);
	ll cnt = 0;
	for(int i=1;i<=n;i++){
		if(a[i] >= x) sum++;
		else sum--;
		cnt += query(sum + BASE);
		add(sum + BASE,1);
	}
	return cnt >= lim;
}
int main(){
	scanf("%d",&n);
	m = (ll)n * (n - 1) / 2 + n;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		b[i] = a[i];
	}
	sort(b + 1,b + n + 1);
	int lb = 1,rb = n;
	while(lb < rb){
		int mid = (lb + rb + 1) >> 1;
		if(check(b[mid])) lb = mid;
		else rb = mid - 1;
	}
	printf("%d\n",b[lb]);
	return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
int main(){
	int n,a,b;
	cin>>n>>a>>b;
	int ans=0;
	int count=0;
	for(int i=1;i<=n;i++){
		count++;
	//	cout<<"count="<<count<<endl;
		if(i%10000==0){
			count-=36;
		}
		else if(i%1000==0){
			count-=27;
		}
		else if(i%100==0){
			count-=18;
		}
		else if(i%10==0){
			count-=9;
		}
	//	cout<<"i="<<i<<endl;
		if(count>=a&&count<=b){
			ans+=i;
	//		cout<<"ans="<<ans<<endl;
		}
	}
	cout<<ans<<endl;
	
}


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

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif

static void D_task();

int main()
{
	D_task();
	
	fflush(stdout);
	return 0;
}

class TmEdge
{
protected:
	TmEdge() {}

public:
	int _to = -1;
	int _cost = -1;

	TmEdge(int to, int cost) {
		_to = to;
		_cost = cost;
	}

};

static void getNodeDist(std::map<int, std::vector<TmEdge>>& tree, int nodeId, int fromId, LLONG nowDist, int* color)
{
	LLONG dist = nowDist;
	for (auto edgeIt = tree[nodeId].begin(); edgeIt != tree[nodeId].end(); edgeIt++) {
		if (edgeIt->_to != fromId) {
			dist += edgeIt->_cost;
			if ((dist % 2) == 0) {
				color[edgeIt->_to] = 1;
			}
			getNodeDist(tree, edgeIt->_to, nodeId, dist, color);
			dist -= edgeIt->_cost;
		}
	}
}

static void D_task()
{
	int N;
	int from, to, dist;

	std::map<int, std::vector<TmEdge>> tree;

	scanf(" %d", &N);
	for (int i = 0; i < N - 1; i++) {
		scanf(" %d %d %d", &from, &to, &dist);
		//	0-origin
		from--; to--;
		TmEdge edge(to, dist);
		tree[from].push_back(edge);
		edge._to = from;
		tree[to].push_back(edge);
	}

	static int color[100001] = { 0 };
	color[0] = 1;

	getNodeDist(tree, 0, -1, 0, color);

	for (int i = 0; i < N; i++) {
		printf("%d\n", color[i]);
	}
}


Measured memory_bytes: 16384
using System;
using System.IO;

class Program
{
    static void Main(string[] args) {
        var scan = new Scanner();
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(Solve(scan));
        Console.Out.Flush();
    }
    static object Solve(Scanner scan) {
        var N = scan.NextInt();
        var H = scan.ArrayInt(N);
        var temp = 0;
        for (int i = 0; i < N; i++) {
            if (H[i] - temp <= -2) return "No";
            temp = Math.Max(temp, H[i]);
        }
        return "Yes";
    }
}

class Scanner
{
    string[] s;
    int i;
    public Scanner() {
        s = new string[0];
        i = 0;
    }
    public string Next() {
        if (i < s.Length) return s[i++];
        string str = Console.ReadLine();
        while (str == "") str = Console.ReadLine();
        s = str.Split(' ', StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }
    public int NextInt() => int.Parse(Next());
    public int[] ArrayInt(int len, int add = 0) {
        var array = new int[len];
        for (int i = 0; i < len; i++) array[i] = NextInt() + add;
        return array;
    }
}

Measured memory_bytes: 36956
def solve(s):
    try:
        i = int(s)
    except ValueError as e:
        return "error"
    return i * 2

def main():
    n = input()
    a = int(n[-1])
    if (a in [2, 4, 5, 7, 9]):
        print('hon')
    elif (a in [0, 1, 6, 8]):
        print('pon')
    else:
        print('bon')


if __name__ == "__main__":
    main()

Measured memory_bytes: 9196
#include<stdio.h>
int main(void)
{
	int n,a,b,c,i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d",&a,&b,&c);
		if(a>b&&a>c){
			if(a*a==b*b+c*c){
				printf("YES\n");
			}
			else{
				printf("NO\n");
			}
		}
		else if(b>a&&b>c){
			if(b*b==a*a+c*c){
				printf("YES\n");
			}
			else{
				printf("NO\n");
			}
		}
		else if(c>a&&c>b){
			if(c*c==a*a+b*b){
				printf("YES\n");
			}
			else{
				printf("NO\n");
			}
		}
		else{
			printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 576
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
 //    String[] nyu=sc.nextLine().split(" ");

     String nyu=sc.nextLine();
//int A=Integer.parseInt(nyu[0]);
//int B=Integer.parseInt(nyu[1]);
//int C=Integer.parseInt(nyu[2]);
int D=Integer.parseInt(nyu);


//StringBuffer sb = new StringBuffer(nyu);
//		String dst = sb.reverse().toString();

//     String nyu2=sc.nextLine();
//int E=Integer.parseInt(nyu2);



//double A=Double.parseDouble(nyu[0]);
//double B=Double.parseDouble(nyu[1]);
/*
switch(nyu){
case "H H":
System.out.println("H") ;
break;

case "D D":
System.out.println("H") ;
break;

case "H D":
System.out.println("D") ;
break;

case "D H":
System.out.println("D") ;
break;


default:
System.out.println("NO") ;

break;
}
*/

//int res=Math.min((A*B),C);

//for(String tem:nyu){
//if(tem.equals("1"))res++;
//}
//int res=0;
//for(int i=0;i<300;i++){
//if(num[i]==1)res=i;
//}

//char[] c = nyu.toCharArray();


//System.out.println(nyu+"-"+line_r_2+"-"+nyu2+"-"+line_r_1);



if(D<1200){
//double res=Math.ceil((AB)/2);

System.out.println("ABC");
//}else if(B<A){
//System.out.println("Alice");

}else{
System.out.println("ARC");

}




	}
}

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

// #define fi first
// #define se second
#define rep(i, n) for (ll i=0;i<(n); i++)
#define ALL(v) (v).begin(), (v).end()
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
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 (a>b) { a=b; return 1; } return 0; }

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;

const ll M=1000000007ll;
const ll MOD=1000000007ll;
const ll MAX=100000001ll;
//const ll M = 1000000000+7;

ll cnt = 0; 

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

mint f(ll n){
  if(n==0) return 1;
  mint ans = f(n/2);
  ans *= ans;
  if(n%2==1) ans*= 2;
  return ans;
}

mint choose(ll n, ll k){
  mint x=1, y=1;
  rep(i,k){
    x *= (n-i);
    y *= (i+1);
  }
  return x / y;
}

struct BIT {
  private:
   vector<ll> bit;
   ll N;
 
  public:
   BIT(ll size) {
     N = size;
     bit.resize(N + 1);
   }
 
   // 一点更新です
   void add(ll a, ll w) {
     for (ll x = a; x <= N; x += x & -x) bit[x] += w;
   }
 
   // 1~Nまでの和を求める。
   int sum(ll a) {
     ll ret = 0;
     for (ll x = a; x > 0; x -= x & -x) ret += bit[x];
     return ret;
   }
 };
 

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

  map<ll, ll> m;
  ll tmp;
  rep(i,n-1){
    cin >> tmp;
    m[tmp]++;
  }

  rep(i, n-1){
    cout << m[i+1] <<endl;
  }

  cout << 0<<endl;
  
  //cout<<ans<<endl;
}


Measured memory_bytes: 16104
#include <cstdio>
#include <algorithm>
#include <vector>

const int MN = 100005;

int N, M;
std::vector<int> G[MN];
int vis[MN], A[MN], B[MN], C, D;

int main() {
	scanf("%d%d", &N, &M);
	for (int i = 1, x, y; i <= M; ++i) 
	{
		scanf("%d%d", &x, &y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	A[C = 1] = 1;
	B[D = 1] = 1;
	vis[1] = 1;
	while (1) {
		int u = A[C], w = 0;
		for (int v : G[u]) if (!vis[v]) w = v;
		if (!w) break;
		vis[w] = 1, A[++C] = w;
	}
	while (1) {
		int u = B[D], w = 0;
		for (int v : G[u]) if (!vis[v]) w = v;
		if (!w) break;
		vis[w] = 1, B[++D] = w;
	}
	printf("%d\n", C + D - 1);
	for (int i = C; i >= 2; --i) printf("%d ", A[i]);
	for (int i = 1; i <= D; ++i) printf("%d%c", B[i], " \n"[i == D]);
	return 0;
}

Measured memory_bytes: 9428
import std.stdio;
import std.conv;
import std.string;
import std.algorithm;

void main(){
  int n;
  while(n=to!int(chomp(readln())),n){
    auto arr=new int[n];
    for(int i=0;i<n;++i)arr[i]=to!int(chomp(readln()));
    auto dp=new int[n+1];
    for(int i=0;i<n;++i) dp[i+1]=max(dp[i]+arr[i],arr[i]);
    writeln(reduce!(max)(dp[1..n+1]));
  }
}

Measured memory_bytes: 1128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main() {

    ll m = 1e9+7;
    ll X, Y;
    cin >> X >> Y;

    if ((X + Y)%3 != 0) {
        cout << 0 << endl;
        return 0;
    }

    if (1.0 * Y / X > 2 || 1.0 * Y / X < 0.5) {
        cout << 0 << endl;
        return 0;
    }

    ll N = (X+Y) / 3;
    ll a, b;
    a = Y - N;
    b = X - N;

    vector<ll> modinv(1e7);
    modinv[1] = 1;
    for (int i = 2; i <= N; i++) {
        modinv[i] = modinv[m%i] * (m-m/i) % m;
    }


    ll ans = 1;
    for (int i = 1; i <= N; i++) {
        ans *= i;
        ans %= m;
    }

    for (int i = 1; i <= N-a; i++) {
        ans *= modinv[i];
        ans %= m;
    }

    for (int i = 1; i <= a; i++) {
        ans *= modinv[i];
        ans %= m;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 78336
#include <bits/stdc++.h>
#define INF 1e+9
#define MOD (int)1e9+7
#define debug(x) cerr << #x << ": " << x << "\n";
using namespace std;
using ll = long long;
using P = pair<int, int>;

int t[200001];

int main(void){
    int N, T; cin >> N >> T;
    for(int i = 0; i < N; i++){
        cin >> t[i];
    }
    t[N] = (int) 2e9 + 1;

    int res = 0;

    for(int i = 0; i < N; i++){
        if(t[i] + T <= t[i + 1]){
            res += T;
        }else{
            res += t[i + 1] - t[i];
        }
        // debug(res);
    }

    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 1024
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST         ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll           long long
#define ld           long double
#define pb           push_back
#define mp           make_pair
#define pii          pair<int,int>
#define mii          map<int,int>
#define vi           vector<int>
#define vll          vector<long long>
#define all(a)       (a).begin(),(a).end()
#define clz(a)       __builtin_clz(a) // count leading zeroes
#define ctz(a)       __builtin_ctz(a) // count trailing zeroes
#define popc(a)      __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul          1000000007
#define rep(i,a,b)   for(int i=a;i<b;i++)
#define rfor(i,a,b)  for(int i=a; i>=b; i--)
#define SIZE         1000005
#define F            first
#define S            second
#define mod          998244353

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define endl         '\n'
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;


void solve()
{
    int n,k; cin>>n>>k;
    vector<int> a(n);
    vector<ll> sum(n+1,0);
    rep(i,0,n)
    {
        cin>>a[i];
        sum[i+1] = sum[i]+a[i];
    }
    vector<ll> store;
    rep(i,0,n+1)
    {
        rep(j,i+1,n+1)
        {
            store.pb(sum[j]-sum[i]);
        }
    }
    ll ans = 0;
    vector<ll> temp;
    rfor(i,50,0)
    {
        ll bin = 1LL<<i;
        for(ll j:store)
        {
            if(j&bin) temp.pb(j);
        }
        if((int)temp.size()>=k)
        {
            store.clear();
            store = temp;
            ans+=bin;
        }
        temp.clear();
    }
    cout<<ans;
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    while(t--){
       solve();
    }
    return 0;
}

Measured memory_bytes: 6128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
const int MAX = 510000;
const int MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    ll s = 0;
    map<ll,ll> mp;
    mp[0] = 1;
    rep(i,N) {
        cin >> A[i];
        s += A[i];
        mp[s]++;
    }
    ll ans = 0;
    for(auto itr = mp.begin();itr!=mp.end();itr++){
        //cout << itr->first << ":" << itr->second << endl;
        if(itr->second>1){
            ans += itr->second*(itr->second-1)/2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 14336
#include <stdio.h>
#include <string.h>

int main(){
  int n, i, j, min;
  char c1[36][3], c2[36][3];
  char mark[3];

  scanf("%d", &n);

  for(i=0; i<n; i++){
    scanf("%s", c1[i]);
    strcpy(c2[i], c1[i]);
  }

  for(i=0; i<n-1; i++)
    for(j=n-1; j>i; j--)
      if(c1[j][1] < c1[j-1][1]){
	strcpy(mark, c1[j]);
	strcpy(c1[j], c1[j-1]);
	strcpy(c1[j-1], mark);
      }

  for(i=0; i<n-1; i++) printf("%s ", c1[i]);
  printf("%s\nStable\n", c1[i]);

  for(i=0; i<n; i++){
    min = i;
    for(j=i; j<n; j++){
      if(c2[j][1] < c2[min][1]) min = j;
    }
    if(i != min){
      strcpy(mark, c2[i]);
      strcpy(c2[i], c2[min]);
      strcpy(c2[min], mark);
    }
  }

  for(i=0; i<n-1; i++) printf("%s ", c2[i]);
  printf("%s\n", c2[i]);

  for(i=0; i<n; i++)
    if(strcmp(c1[i], c2[i]) != 0) break;
  if(i==n) printf("Stable\n");
  else printf("Not stable\n");

  return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <math.h>
#include <string>

using namespace std;

int main(){
    string a, b;
    cin >> a >> b;

    a += b;
    int n = stoi(a);
    int m = sqrt(n);
    if(m * m == n) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))

void update(int64 *bit,int index,int64 v){
  int n=bit[0];
  for(int i=index;i<=n;i+=i&-i) bit[i]=MAX(bit[i],v);
}

int64 getMax(int64 *bit,int index){
  int64 res=0;
  for(int i=index;i>0;i-=i&-i) res=MAX(res,bit[i]);
  return res;
}

void run(void){
  int n;
  scanf("%d",&n);
  int *h=(int *)calloc(n,sizeof(int));
  int i;
  for(i=0;i<n;i++) scanf("%d",h+i);
  int64 *bit=(int64 *)calloc(n+1,sizeof(int64));
  bit[0]=n;
  for(i=0;i<n;i++){
    int a;
    scanf("%d",&a);
    int64 v=getMax(bit,h[i])+a;
    update(bit,h[i],v);
  }
  printf("%lld\n",getMax(bit,n));
}

int main(void){
  run();
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  int sum = 0;
  int counter = 0;
  for (int i = 0; i < N; i++) {
    int a; cin >> a;
    sum += a;
    counter++;
  }
  cout << sum - counter << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <map>
#define for1(x,y) for(long long x = 1; x<ll(y); x++)
#define forn(x,y,z) for(long long x = y; x< ll(z); x++)
#define for0(x,y,z) for(long long x = y; x< ll(z); x++)
# define PII pair<int,int>
# define FF first
# define SS second
# define PB push_back

#define forn(x,y,z) for(long long x = y; x< ll(z); x++)
#define for0(x,y,z) for(long long x = y; x< ll(z); x++)
using namespace std;
typedef long long ll;
typedef long double ld;	

#define maxn 1000015
const double EPS = (1e-7), EPSm= (1e7);
const ll linf = (ll)1e17 + 5;
long double PI = 3.14159265359;
int dir[8][2]={{1,0},{-1,0},{0,1},{0,-1},{-1,-1},{1,1},{-1,1},{1,-1}};
	
const int MAXN = 1e5 + 10;
const int NINF = -1e5;
const int INF = 2000000000;

void solve()
{
	int n;
	cin>>n;
	cout<<(((n+1000)/1000)*1000-n)%1000<<endl;
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	setprecision(20);
	int test;
	//cin >> test;
	//while(test--)
		solve();
	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
using pii = pair<int, int>;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int H, W;
vector<string> S, T;
bool check() {
  map<string, int> mp;
  rep(j, 0, W) {
    string s;
    rep(i, 0, H) {
      if (T[i][j] == '#')
        s += T[H - 1 - i][j];
      else
        s += T[i][j];
    }
    string t = s;
    reverse(all(t));
    if (s <= t)
      mp[s]++;
    else
      mp[t]--;
  }
  int c = 0;
  for (auto p : mp) {
    dump(p);
    if (p.second == 0)
      continue;
    string s = p.first;
    string t = s;
    reverse(all(t));

    if (s != t)
      return false;
    else {
      if (p.second & 1){
        c++;
      }
      if(c==2)return false;
    }
  }
  return true;
}
bool dfs(int s, int k) {
  dump(s, k);
  if (s == 0) {
    return check();
  }

  int c = 0;
  while (~s >> c & 1)
    c++;
  T[k] = S[c];
  rep(i, c + 1, H) {
    if (s >> i & 1) {
      T[H - 1 - k] = S[i];
      if (dfs(s ^ (1 << c) ^ (1 << i), k + 1))
        return true;
    }
  }
  return false;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  cin >> H >> W;
  S.resize(H);
  T.resize(H);
  rep(i, 0, H) { cin >> S[i]; }
  if (H & 1) {
    S.push_back(string(W, '#'));
    H++;
    T.push_back(string());
  }
  cout << (dfs((1 << H) - 1, 0) ? "YES" : "NO") << endl;

  return 0;
}


Measured memory_bytes: 892
#include<cstdio>
#include<cstring> 
#include<climits>
#include<algorithm>
using namespace std;
#define MAXN 10
int D,G;
struct node
{
	int p,c;
}text[MAXN+5];
int read()
{
	int f=1,x=0;
	char c=getchar();
	while(c<'0'||'9'<c) {if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
int cmp(int x,int y)
{
	return (x+y-1)/y;
}
int main()
{
	D=read(),G=read();
	for(int i=1;i<=D;i++)
		text[i].p=read(),text[i].c=read();
	int ans,count=G;
	int minn=INT_MAX;
	for(int i=0;i<(1<<D);i++)
	{
		count=G;
		ans=0;
		for(int j=1;j<=D;j++)
		{
			if((1<<(j-1))&i)
			{
				count-=(100*j*text[j].p+text[j].c);
				ans+=text[j].p;
			}
		}
		//if(ans==0) continue;
		if(count>0) 
		{
			int t=ans;
			for(int j=1;j<=D;j++)
			if(!(1<<(j-1)&i))
			{
				ans=t;
				if(count-(100*j*text[j].p+text[j].c)<=0)
				{
					if(count-100*j*text[j].p<=0)
						ans+=cmp(count,100*j);
					else ans+=text[j].p;
					if(ans<minn)
					{
						minn=ans;
					}
				}
			}
		}
		else minn=min(ans,minn);
	}
	printf("%d",minn);
 } 


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'
typedef pair<int, int> P;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    ll r = 1e9;
    ll l = 0;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }

    rep(tmp, 200)
    {
        ll mid = (l + r) / 2;
        if (mid == 0)
        {
            cout << 1 << endl;
            return 0;
        }
        int cnt = 0;
        for (auto j : a)
        {
            cnt += (j + mid - 1) / mid - 1;
        }
        if (cnt <= k)
        {
            r = mid;
        }
        else
        {
            l = mid;
        }
    }
    cout << r << endl;
}

Measured memory_bytes: 3988
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
int main(void)
{
	int N=0,ans=0;
	int B[1000];
	cin>>N;
	for(int i=0;i<N-1;i++){
		cin>>B[i];
	}
	ans+=B[0];
	for(int i=0;i<N-2;i++){
		ans+=min(B[i],B[i+1]);
	}
	ans+=B[N-2];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>
#include <map>
#include <time.h>
#include <iomanip>
#include <bitset>

using namespace std;

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int a[200005];

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

    rep(i, 0, n - 1) {
        int b;
        cin >> b;
        a[b - 1]++;
    }

    rep(i, 0, n) {
        cout << a[i] << endl;
    }
}


Measured memory_bytes: 5100
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cfloat>
using namespace std;
int mod = 1e9+7;

int main() {
  long long int n, a, b;
  cin >> n >> a >> b;

  long long int ans = ((n-1) * b + a) - ((n-1) * a + b) + 1;
  long long int mn = 0;
  cout << max(ans, mn) << endl;

  return 0;
}

//


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<ll, ll>P;
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
ll basic[33333];
signed main(){
	ll n,memo=0,ans=0;
	cin>>n;
	for(int i=1;i<=33333;i++){
		if(i%2==0||i%3==0){
			basic[memo]=i;
			memo++;
		}
	}
	rep(i,n-1){
		cout<<basic[i]<<" ";
		ans+=basic[i];
	}
	ll p=0;
	for(int i=2;i<=30000;i++){
		if((i%3==(3-(ans%3))%3)&&(i%2==(2-(ans%2))%2)&&(gcd(i,ans)!=1)){
			for(int j=0;j<n-1;j++){
				if(i==basic[j])p++;
			}
			if(p==0){
				cout<<i;
				return 0;
			}
		}
		p=0;
	}
}


Measured memory_bytes: 512
/**
 *      ABC 60 C
 *      author  : kyomukyomupurin
 *      created : 2018-09-08 04:01:44
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, T; cin >> N >> T;
    int t[N];
    for (int i = 0; i < N; ++i) {
        cin >> t[i];
    }

    long long dp[N + 10] = {};      // N番目の人が押したときのシャワーが出る時間
    dp[0] = T;
    for (int i = 0; i < N; ++i) {
        if (t[i + 1] - t[i] >= T){
            dp[i + 1] = dp[i] + T;
        }
        else if (t[i + 1] - t[i] < T){
            dp[i + 1] = dp[i] + t[i + 1] - t[i];
        }
    }
    cout << dp[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 2560
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U>
inline void cmax(T& a, U b) { if (a < b) a = b; }
template<class T, class U>
inline void cmin(T& a, U b) { if (a > b) a = b; }

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} io_setup;

constexpr char el = '\n';
#line 2 "c.cpp"

int main() {
  double n;
  cin >> n;
  double t = n/3;
  cout << t * t * t << endl;
  cout << flush;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)

{

   int a,b,d,r;
double f;

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

   d=a/b;

   r=a%b;

   f=(double)a/b;

   printf("%d %d %lf\n",d,r,f);

return 0;

}

Measured memory_bytes: 1064
import java.io.*;
import java.util.*;
public class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        String s=br.readLine();
        int max=0;
        int x=0;
        for(int i=0;i<n;i++){
            if(s.charAt(i)=='I'){ x++; }
            else{ x--; }
            if(max<x){ max=x; }
        }System.out.println(max);
    }
    
}

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

int main(){
    int n;
    cin >> n;
    long long ans = 0;
    vector<int> d(n);
    for (int i = 0; i < n; i++) cin >> d[i];
    for (int i = 0; i < n; i++){
        for (int j = i + 1; j < n; j++) ans += d[i] * d[j];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

N,Q = map(int,input().split())
BIT = [0]*(N+1)

def BIT_query(idx):
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

def BIT_update(idx,x):
    while idx <= N:
        BIT[idx] += x
        idx += idx&(-idx)
    return

c = [0]+list(map(int,input().split()))
lastAppeared = [-1]*(N+1)
ans = [0]*Q
queries = []
for q in range(Q):
    l,r = map(int,input().split())
    queries.append(r*10**12+l*10**6+q)
queries.sort()

curR = 0
for i in range(Q):
    query = queries[i]
    r = query//10**12
    l = (query//10**6)%(10**6)
    q = query % 10**6
    while curR < r:
        curR += 1
        color = c[curR]
        last = lastAppeared[color]
        if last != -1:
            BIT_update(last,-1)
        lastAppeared[color] = curR
        BIT_update(curR,1)
    ans[q] = BIT_query(r)-BIT_query(l-1)
for i in range(Q):
    print(ans[i])


Measured memory_bytes: 159816
import java.util.*;

/**
 * @author yamato
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scanner = new Scanner(System.in);
		String S = scanner.next();
		String T = scanner.next();
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		String U = scanner.next();
		
		if(S.equals(U)) {
			A = A-1;
		}else if(T.equals(U)){
			B = B-1;
		}
		System.out.print(A+" "+B);
		
	}

}

Measured memory_bytes: 23892
function Main(input) {
  input = input.split("\n");
  var S = input[0].split("");
  var c=0;
  for(var i=0;i<S.length;i++){
    if(S[i]=="x"){
      c++;
    }
  }
  var ans="NO";
  if(c<=7){
    ans="YES";
  }

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
	vector<char> s(3);
  rep(i, 3) cin >> s[i];
	if (s[1] == 'B') cout << "ARC" << endl;
	if (s[1] == 'R') cout << "ABC" << endl;
}


Measured memory_bytes: 3628
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define in inline
#define reg register
//#define int long long
#define MAX 200308
using namespace std;
namespace qwq{
	in void read(int &o) {
		o=0;
		int w=1;
		char c=getchar();
		while(c<'0'||c>'9') {
			if(c=='-')w*=-1;
			c=getchar();
		}
		while(c>='0'&&c<='9') {
			o=(o<<3)+(o<<1)+(c^48);c=getchar();
		}
		o*=w;
	}
	void write(int x){
	   	if(x<0)putchar('-'),x=-x;
    	if(x>9)write(x/10);
		putchar(x%10+48);
	}
	void Write(int x) {
		write(x);putchar('\n');
	}
	in int max(int x,int y){return x>y?x:y;}
	in int min(int x,int y){return x<y?x:y;}
}
using namespace qwq;
int N,M;
signed main()
{
	read(N);
	for(reg int i=9;i>=1;--i)
	{
		if(N%i==0 && N/i>0&&N/i<=9){
			puts("Yes");return 0;
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std; 
int main()
{
	int N,R;
	cin>>N>>R;
	if(N<10)
	{
		int rat=100*(10-N);
		cout<<(R+rat)<<endl;
	}
	else
	{
		
		cout<<R<<endl;
		}
		return 0;
	}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
char ch;
while(1)
{ch=0;
scanf("%c",&ch);
if(ch=='\n') break;
if('a'<=ch && ch<= 'z') ch-=32;
else if('A'<=ch && ch<= 'Z') ch+=32;
printf("%c",ch);
}
cout<<endl;
return 0;
}


Measured memory_bytes: 3248
import sys

S = input()

N = len(S)-1
sum = 0

for i in range(2**N):

    op = [""]*(N)
    for j in range(N):
        if (i>>j)&1:
            op[j] = "+"
    s = ""
    for j in range(N):
        s = s + S[j] + op[j]
    s = s + S[len(S)-1]
    sum = sum + eval(s)
print(sum)

Measured memory_bytes: 3064
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
    n: usize,
    h: [usize; n]
    }
    let mut m = 0;
    let mut ans = 0;
    for i in 0..n {
        if m <= h[i] {
            ans += 1;
            m = h[i]
        }
    }
    println!("{}", ans);
}



Measured memory_bytes: 4352
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<string>
#include<vector>
#include<climits>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define	mp	make_pair
#define	pb	push_back
#define	pf	push_front

using namespace std;

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

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

int main()
{
	int t[181];
	for(int i=1;i<=180;i++)	t[i]=i*(i+1)*(i+2)/6;	// T_181==1004731

	static int memo[1000000],memo_odd[1000000];
	memo[0]=memo_odd[0]=0;
	for(int i=1;i<1000000;i++)	memo[i]=memo_odd[i]=200;
	for(int i=1;i<1000000;i++){
		for(int j=1;j<=180;j++){
			if(t[j]>i)	break;
			memo[i]=min(memo[i],memo[i-t[j]]+1);

			if((j-1)%4==0)
				memo_odd[i]=min(memo_odd[i],memo_odd[i-t[j]]+1);
		}
	}

	for(int n;cin>>n,n;)	cout<<memo[n]<<' '<<memo_odd[n]<<endl;

	return 0;
}

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

using namespace std;

int main(){

	while(1){
		char c[3][3];
		for(int i = 0; i < 3; i++){
			for(int j = 0; j < 3; j++){
				cin>>c[i][j];
			}
		}
		if(cin.eof())
			break;
		int r=-1;
		for(int i = 0; i < 3; i++){
			if(c[i][0]==c[i][1]&&c[i][0]==c[i][2]&&c[i][0]!='s'){
				if(c[i][0]=='o'){
					r=0;
					break;
				}
				else{
					r=1;
					break;
				}
			}
			if(c[0][i]==c[1][i]&&c[0][i]==c[2][i]&&c[0][i]!='s'){
				if(c[0][i]=='o'){
					r=0;
					break;
				}
				else{
					r=1;
					break;
				}
			}
		}
		if(r!=-1){
			if(r==0)
				cout<<'o'<<endl;
			else
				cout<<'x'<<endl;
		}
		else{
			if(c[0][0]==c[1][1]&&c[0][0]==c[2][2]&&c[0][0]!='s'){
				cout<<c[0][0]<<endl;
			}
			else if(c[0][2]==c[1][1]&&c[0][2]==c[2][0]&&c[1][1]!='s'){
				cout<<c[1][1]<<endl;
			}
			else
				cout<<'d'<<endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>
#include <sstream>
#include <stdio.h>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> PSI;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define REP(i,n)  for(int i=0; i<(n); i++)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

//int Counter(int x)
/*int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}*/
/*bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.second > secondElof.second;
}*/


/*long nCr(int n, int r)
{
       if(n==r) return dp[n][r] = 1;
       if(r==0) return dp[n][r] = 1;
       if(r==1) return dp[n][r] = n;
       if(dp[n][r]) return dp[n][r];
       return dp[n][r] = nCr(n-1,r) + nCr(n-1,r-1);
}*/
/*int stoi(std::string str){
int ret;
std::stringstream ss;
ss << str;
ss >> ret;
return ret;
}*/
//LL a[200000];
//LL mis=-1, maf=-1;
/*bool under(int i, int j, LL t){
    if()
}*/
int main(){
    string s;
    int k;
    cin >> k >> s;
    int n = s.size();
    if(n<=k) cout << s << endl;
    else{
        s=s.substr(0,k);
        s+="...";
        cout << s << endl;
    }
    
}
/*int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(0);
	Main();
}*/


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

const int mod = 1e9+7;
const int maxn = 1e6+5;
void tlfclwx(){ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
int k[maxn];
int main()
{
    tlfclwx();
    int n, q;
    cin >> n >> q;
    ll sum = 0;
    for(int i = 1; i <= q; i++)
    {
        cin >> k[i];
        sum += k[i];
    }
    if(sum >= n) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 640
from collections import Counter

n = int(input())
s = input().rstrip()

c = Counter(list(s))

num_r = c['R']
num_g = c['G']
num_b = c['B']

bad = 0
for i in range(n-2):
    for j in range(i+1, n):
        k = j + (j - i)
        if k >= n:
            break

        if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
            bad += 1

print(num_r * num_g * num_b - bad)

Measured memory_bytes: 68888
#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(){
    int n, m;
    map<int,int> mp;
    while(scanf("%d,%d", &n, &m), n || m){
        mp[n] += m;
    }
 
    vector<int> r;
    for(map<int,int>::iterator it = mp.begin(); it != mp.end(); ++it){
        r.push_back(-it->second);
    }
    sort(r.begin(), r.end());
    r.erase(unique(r.begin(), r.end()), r.end());
 
    while(scanf("%d", &n) != EOF){
        printf("%d\n", upper_bound(r.begin(), r.end(), -mp[n]) - r.begin());
    }
}

Measured memory_bytes: 1056