akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=5010;
int n,m,b[maxn][maxn],s[maxn],l[maxn][maxn],r[maxn][maxn],w[maxn];
ll a[maxn],A[maxn][maxn];
int main(){
    scanf("%d%d",&n,&m);
    for(int i=2;i<=n;i++)scanf("%lld",&a[i]),a[i]+=a[i-1];
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)scanf("%d",&b[j][i]);
    for(int i=1;i<=m;i++){
        int top=0;
        for(int j=1;j<=n;j++){
            while(top&&b[i][j]>b[i][s[top]])top--;
            if(top)l[i][j]=s[top]+1;else l[i][j]=1;
            s[++top]=j;
        }
        top=0;
        for(int j=n;j>=1;j--){
            while(top&&b[i][j]>b[i][s[top]])top--;
            if(top)r[i][j]=s[top]-1;else r[i][j]=n;
            s[++top]=j;
        }
        for(int j=1;j<=n;j++){
            A[l[i][j]][j]+=b[i][j];
            A[l[i][j]][r[i][j]+1]-=b[i][j];
            A[j+1][j]-=b[i][j];
            A[j+1][r[i][j]+1]+=b[i][j];
        }
    }
    ll ans=-1ll<<60;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
			A[i][j]+=A[i-1][j]+A[i][j-1]-A[i-1][j-1];
			if(i<=j)
				ans=max(ans,A[i][j]-a[j]+a[i]);
		}
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 213760
S = input()
T = input()

if T in S:
    print(0)
else:
    matched = 0
    for i in range(len(S)-len(T)+1):
        matched_work = 0
        for j in range(len(T)):
            if T[j] == S[i+j]:
                matched_work += 1
        if matched_work > matched:
            matched = matched_work
    print(len(T)-matched)

Measured memory_bytes: 9060
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int l,r,d;
  cin>>l>>r>>d;
  int ans=0;
  for(int i=l;i<=r;i++)
  {
      if(i%d==0)
      ans++;
  }
  cout<<ans;
   return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>
int main()
{
	int n;
	char s;
 
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf(" %c",&s);
		if(s=='Y'){
			printf("Four");
			return 0;
		}
	}
	printf("Three");
	return 0;
}

Measured memory_bytes: 128
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math") 
///#pragma GCC target("avx2")
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <functional>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <climits>
#include <numeric>

using namespace std;
#define open_streams ifstream fin("olympiad.in");ofstream fout("olympiad.out")
#define close_streams fin.close();fout.close()
#define speed cout.tie(0);cin.tie(0);ios_base::sync_with_stdio(0)
#define ll long long
#define ull unsigned long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define UNIQ(a) a.resize(unique(all(a)) - a.begin())
#define eps 1e-6
//const double PI = M_PI;
const int INF = INT_MAX;
const ll limit = 1LL * 4e18;
const int MOD = 1e9 + 711;
const int MOD2 = 1e9 + 933;
//---------------------------------------------------------------------------
const int mod = 1e9 + 7;
const int maxn = 2e5 + 100;


ll p_w(int a, int n) {
	if (n == 0) {
		return 1;
	}
	if (n & 1) {
		return (p_w(a, n - 1)*a) % mod;
	}
	ll x = p_w(a, n / 2);
	return (x*x) % mod;
}
ll inv(int x) {
	return p_w(x, mod - 2);
}
vector<ll> f(maxn);
ll C(int n, int k) {
	if (k < n - k) {
		k = n - k;
	}
	ll d = inv(f[n - k]);
	ll u = 1;
	for (int x = k + 1; x <= n; ++x) {
		u = (u*x) % mod;
	}
	return (u * d) % mod;
}
signed main() {
	speed;
	int n, a, b;
	cin >> n >> a >> b;
	f[0] = 1;
	for (int i = 1; i < maxn; ++i) {
		f[i] = (f[i - 1] * i) % mod;
	}
	cout << (p_w(2, n) + 2 * mod - C(n, a) - C(n, b) - 1) % mod;
	return 0;
}

Measured memory_bytes: 1792
N = int(input())

def find(x, U, r):
  p = []
  while not x == U[x]:
    p.append(x)
    x = U[x]
  for x_ in p:
    U[x_] == x
  return x
  
def merge(x, y, U, r):
  x = find(x, U, r)
  y = find(y, U, r)
  
  if x == y:
    return False
  #print(x,y, U)
  if r[x] < r[y]:
    x, y = y, x
  U[y] = x
  r[x] = max(r[y]+1, r[x])
  #print(x,y, U)
  return True
  
U = [i for i in range(N)]
r = [0 for _ in range(N)]

B = []
C = []
for i in range(N):
  u, v = map(int, input().split())
  B.append((u, v, i))
  C.append((v, u, i))
B.sort()
C.sort()

#辺の作成
R = []
for i in range(1,N):
  c = B[i][0] - B[i-1][0]
  p1 = B[i][2]
  p2 = B[i-1][2]
  R.append((c, p1, p2))
  
  c = C[i][0] - C[i-1][0]
  p1 = C[i][2]
  p2 = C[i-1][2]
  R.append((c, p1, p2))
R.sort()

#Union Find:
U = [i for i in range(N)]
r = [0 for _ in range(N)]
#print(U)  
ans = 0
for road in R:
  c = road[0]
  x = road[1]
  y = road[2]
  if merge(x, y, U, r):
    #print(U)  
    ans += c
#print(U)    
print(ans)

Measured memory_bytes: 149356
def valid?(a, b, c)
  a <= b + c && b <= c + a + 1 && c <= a + b + 1
end
 
def calc(rear, front, west, east, north, south, buffer, best)
  buffer.size.times do |i|
    a = rear + front
    b = west + east
    c = north + south
 
    if east > 0 && valid?(b - 1, c, a)
      rear, front, west, east = east - 1, west, rear, front
      y = 69
    elsif north > 0 && valid?(c - 1, a, b)
      rear, front, north, south = north - 1, south, front, rear
      y = 78
    elsif south > 0 && valid?(c - 1, a, b)
      rear, front, north, south = south - 1, north, rear, front
      y = 83
    #elsif west > 0 && valid?(b - 1, c, a)
    else
      rear, front, west, east = west - 1, east, front, rear
      y = 87
    end
     
    if best
      x = best[i]
      return best if x < y
      best = nil if x > y
    end
    buffer[i] = y  
  end
  buffer.dup.freeze
end
 
def find(target, limit)
  buffer = [0] * limit
  best = nil
  target.permutation(6).to_a.uniq.each do |rear, front, west, east, north, south|
    a = rear + front
    b = west + east
    c = north + south
    if valid?(a, b, c)
      best = calc(rear, front, west, east, north, south, buffer, best)
    end
  end
  best
end
 
loop do
  target = gets.split.map!(&:to_i)
  break if target.all?(&:zero?)
  p, q = gets.split.map!(&:to_i)
  result = find(target, q)
  puts result ? result[p-1...q].pack('C*') : 'impossible'
end

Measured memory_bytes: 30096
n = int(input())
x = list(map(int, input().split()))

wa = 0
wawa = 0
ava = int(sum(x) / n)
aa = ava+1
for i in x:
    wa += (i-ava)**2
    wawa += (i - aa)**2

if wa > wawa:
    print(wawa)
else:
    print(wa)

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

int main(void){
   int N;
   cin>>N;
   vector<long long> a(N);
   for(int i=0;i<N;i++){
      cin>>a[i];
   }
   int count=0;
   int temp=0;
   for(int i=0;i<N;i++){
      if(a[i]%4==0) count+=2;
      else if(a[i]%2==0) temp++;
   }
   int count2=0;
   if(temp>=2){
      count2=temp-1;
   }
   int ans=count+count2;
   if(ans>=N-1){
      cout<<"Yes"<<endl;
   }else{
      cout<<"No"<<endl;
   }
   return 0;
}

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

using namespace std;
#define ll long long
#define sz(a) (int)(a).size()
#define rep(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define frep(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;

const int inf = 1e9 + 9;
const ll linf  = 1ll * inf * inf;
const int N = 500000 + 7;
const int M = 30;
const int multipleTest = 0;
const double pi = acos(-1);

int n; ll C;
ll x[N], val[N];
ll sum[N];

ll mx[N];

void solve() {
	cin >> n >> C;
	rep(i, 1, n + 1) {
		cin >> x[i] >> val[i];
		sum[i] = sum[i - 1] + val[i];
	}
	
	ll res = 0;
	
	mx[n + 1] = -linf;
	for (int i = n; i > 0; --i) {
		mx[i] = max(mx[i + 1], sum[n] - sum[i - 1] - (C - x[i]));
	}
	
	rep(i, 1, n + 1) {
		res = max(res, sum[i] - x[i]);
		res = max(res, sum[i] - 2 * x[i] + mx[i + 1]);
	}
	
	mx[0] = -linf;
	for (int i = 1; i <= n; ++i) {
		mx[i] = max(mx[i - 1], sum[i] - x[i]);
	}
	
	for (int i = n; i > 0; --i) {
		res = max(res, sum[n] - sum[i - 1] - (C - x[i]));
		res = max(res, sum[n] - sum[i - 1] - 2 * (C - x[i]) + mx[i - 1]);
	}
	
	cout << res;
	
	
	
	
}

int main() {
#ifdef _LOCAL_
	freopen("in.txt", "r", stdin);
	//    freopen("out.txt", "w", stdout);
#endif
	int Test = 1;
	if (multipleTest) {
		cin >> Test;
	}
	for(int i = 0; i < Test; ++i) {
		//		printf("Case #%d: ", i + 1);
		solve();
	}
#ifdef _LOCAL_
	cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
#endif
}



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


int main() {
	long long a ,b, x,ans;
	scanf("%lld%lld%lld",&a,&b,&x);
	  if(a==0){
	  	ans=(b/x)+1;
	  	 printf("%lld",ans);
	  	 
	  }
	  else{
	  
	long long ans=b/x-(a-1)/x;
	
     printf("%lld",ans);}
 return 0;
 }
 
 


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>
#include <set>
#include <deque>

#define mod 1000000007
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOREACH(i, v) for(auto i = v.begin(); i != v.end(); i++)

using namespace std;
using ll = long long;

int X[] = {-1, 0, 1, 1, 1, 0, -1, -1};
int Y[] = {1, 1, 1, 0, -1, -1, -1, 0};

int gcd(int a, int b) {
    int x = max(a, b);
    int y = min(a, b);
    int z = x % y;
    if(z == 0){
        return y;
    }else{
        return gcd(y, z);
    }
}

int lcm(int a, int b) {
    return (a*b)/gcd(a, b);
}

void solve() {
	int a, b, c, x;
	int res = 0;
	cin >> a >> b >> c >> x;
	for(int i = 0; i <= a; i++){
		for(int j = 0; j <= b; j++){
			for(int k = 0; k <= c; k++){
				if(500*i+100*j+50*k == x){
					res++;
				}
			}
		}
	}
	cout << res << endl;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

using LL = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int n, k, sc = 0, sk = 0, h, ans = 0;
vector<pair<int, int>> g;
string s;

int main() {
    cin >> n >> k;
    cin >> s;
    int last = -1;
    REP(i, n) if (i == n - 1 || s[i] != s[i + 1]) {
        g.push_back({ i - last, s[i] });
        sk += s[i] == '0';
        sc += i - last;
        last = i;
        while (sk > k) {
            sc -= g[h].first;
            sk -= g[h].second == '0';
            h++;
        }
        ans = max(ans, sc);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
bool isPrime(int x){
    if(x<=1){
        return false;
    }
    for(int i=2 ;i*i<=x ;i++){
        if(x%i==0){
            return false;
        }
    }
    return true;
}
int main(){
    int q;
    cin >>q;
    vector<int> l(q),r(q);
    rep(i,q){
        cin >> l[i]>>r[i];
    }
    //累積和?
    int max=0;
    rep(i,q){
        if(r[i]>=max){
            max=r[i];
        }
    }
    vector<int> s(max+1,0);
    for(int i=1;i<=max;i++){
        if(isPrime(i)&&isPrime((i+1)/2)){
        s[i]=s[i-1]+1;
        }
        else{
            s[i]=s[i-1];
        }
        //cout << s[i] <<" ";
    }   
    rep(i,q){
        cout << s[r[i]]-s[l[i]-1]<<endl;
    }
}

Measured memory_bytes: 1792
// acdart
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <string>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <cstdlib>
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second
#define F first
#define S second
#define MOD9 1000000009ll
#define MOD7 1000000007ll
#define MOD
#define INF  1023456789ll
#define INF16 10000000000000000ll
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define SZ(x) ((int)(x).size())
#define MAXN 10010
#define MAXM
#define ALL(x) ((x).begin()),((x).end())
#define RESET(a,b) memset(a,b, sizeof a)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define LEN(X) strlen(X)
#define FI(a,b,c) for(int a=b; a<c; a++)
#define FD(a,b,c) for(int a=b; a>c; a--)
using namespace std;
typedef long long ll;
typedef long long LL;
typedef double db;
typedef double D;
typedef long double ld;
typedef long double LD;
/*********default*********/

int main()
{
	int x;
	
	scanf("%d", &x);
	printf("%d\n", x * (x + 1) / 2);
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>

#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>

#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;

template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

struct __scanner__{ bool e; operator bool(){ return e; } } IN = { false };
inline __scanner__& operator>>(__scanner__& in,int &n)
{ in.e = scanf("%d",&n)==1; return in; }
inline __scanner__& operator>>(__scanner__& in,ll &n)
{ in.e = scanf("%lld",&n)==1; return in; }
inline __scanner__& operator>>(__scanner__& in,double &n)
{ in.e = scanf("%lf",&n)==1; return in; }
inline __scanner__& operator>>(__scanner__& in,char &n)
{ in.e = scanf(" %c",&n)==1; return in; }
inline __scanner__& operator>>(__scanner__& in,string &n) // BUFFER SIZE!
{ static char buf[1000000]; in.e = scanf(" %s",buf)==1; n = buf; return in; } 

int main(){
  string s;
  while (cin >> s) {
    if (count(ALL(s), '9')) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 256
h, w = gets.chop.split.map(&:to_i)
s = []

h.times do
  ws = gets.chop.chars
  s << ws
end

max = 0
h.times do |i_h|
  w.times do |i_w|
    next if s[i_h][i_w] == '#'

    cost = Array.new(h) { Array.new(w, nil) }
    cost[i_h][i_w] = 0
    adds = [[i_h, i_w]]
    loop do
      break if adds.empty?

      new_adds = []
      adds.each do |a|
        p = cost[a[0]][a[1]]
        if a[0] > 0 && s[a[0]-1][a[1]] == '.' && cost[a[0]-1][a[1]].nil?
          cost[a[0]-1][a[1]] = p + 1
          new_adds << [a[0]-1, a[1]]
        end
        if a[0] < h-1 && s[a[0]+1][a[1]] == '.' && cost[a[0]+1][a[1]].nil?
          cost[a[0]+1][a[1]] = p + 1
          new_adds << [a[0]+1, a[1]]
        end
        if a[1] > 0 && s[a[0]][a[1]-1] == '.' && cost[a[0]][a[1]-1].nil?
          cost[a[0]][a[1]-1] = p + 1
          new_adds << [a[0], a[1]-1]
        end
        if a[1] < w-1 && s[a[0]][a[1]+1] == '.' && cost[a[0]][a[1]+1].nil?
          cost[a[0]][a[1]+1] = p + 1
          new_adds << [a[0], a[1]+1]
        end
      end
      adds = new_adds
    end
    max = [max, cost.flatten.compact.max].max
  end
end

puts max

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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000001)
#define MOD (1000000007)
#define PI (acos(-1))

int main(){
  string s;
  cin >> s;
  if(s=="KIHBR"||
     s=="AKIHBR"||
     s=="KIHABR"||
     s=="KIHBAR"||
     s=="KIHBRA"||
     s=="AKIHABR"||
     s=="AKIHBAR"||
     s=="AKIHBRA"||
     s=="KIHABAR"||
     s=="KIHABRA"||
     s=="KIHBARA"||
     s=="AKIHABAR"||
     s=="AKIHABRA"||
     s=="AKIHBARA"||
     s=="KIHABARA"||
     s=="AKIHABARA"){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}



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

using namespace std;

int main(){
	vector<int> a(10);
	vector<int> b(10);
	for(int i=0;i<10;i++){
		cin >> a[i];
	}
	for(int i=0;i<10;i++){
		cin >> b[i];
	}
	sort(a.rbegin(),a.rend());
	cout << a[0] + a[1] + a[2] << " ";
	sort(b.rbegin(),b.rend());
	cout << b[0] + b[1] + b[2] << endl;
	
	return 0;
}

Measured memory_bytes: 3076
n, k = list(map(int, input().split()))
n_map = {}
for _ in range(n):
    a, b = list(map(int, input().split()))
    if not a in n_map.keys():
        n_map[a] = b
    else:
        n_map[a] += b

num = 0
for n in sorted(n_map.keys()):
    num += n_map[n]
    if num >= k:
        print(n)
        break

Measured memory_bytes: 10604
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(),(u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

const int MR = 5e5 + 10;

char s[MR];

int dp[MR][2];

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

	int ile = 0, first = -1, last = -2, prev0 = -2;
	REP(i, n)
	{
		if (s[i] == '1')
		{
			if (first == -1)
				first = i;
			last = i;
		}
		else
		{
			if (prev0 == i - 1)
			{
				// policz dla wyznaczonej czesci tekstu
				last++;
				int ile1 = 0, ile0 = 0;
				FOR(j, first, last)
					if (s[j] == '0')
					{
						ile0++;
						dp[ile0][0] = (ile0 == 1 ? ile1 : max(ile1 + max(dp[ile0 - 2][0], dp[ile0 - 2][1]), max(dp[ile0 - 1][0] + ile1 - 1, dp[ile0 - 1][1])));
						int k = j + 1;
						while (k < last && s[k] == '1')
							k++;
						int ilen = k - j - 1;
						dp[ile0][1] = (ile0 == 1 ? ilen : max(ilen + max(dp[ile0 - 2][0], dp[ile0 - 2][1]), max(dp[ile0 - 1][0] + (ile1 > 1 ? ilen : 0), dp[ile0 - 1][1] - 1 + ilen)));
						ile1 = 0;
					}
					else
						ile1++;
				ile += max(dp[ile0][0], dp[ile0][1]);
				first = -1;
				last = -2;
			}

			prev0 = i;
		}
	}

	// na koncu rowniez policz dla wyznaczonej czesci tekstu
	last++;
	int ile1 = 0, ile0 = 0;
	FOR(j, first, last)
		if (s[j] == '0')
		{
			ile0++;
			dp[ile0][0] = (ile0 == 1 ? ile1 : max(ile1 + max(dp[ile0 - 2][0], dp[ile0 - 2][1]), max(dp[ile0 - 1][0] + ile1 - 1, dp[ile0 - 1][1])));
			int k = j + 1;
			while (k < last && s[k] == '1')
				k++;
			int ilen = k - j - 1;
			dp[ile0][1] = (ile0 == 1 ? ilen : max(ilen + max(dp[ile0 - 2][0], dp[ile0 - 2][1]), max(dp[ile0 - 1][0] + (ile1 > 1 ? ilen : 0), dp[ile0 - 1][1] - 1 + ilen)));
			ile1 = 0;
		}
		else
			ile1++;
	ile += max(dp[ile0][0], dp[ile0][1]);

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

Measured memory_bytes: 2560
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>

using namespace std;

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

int gcd(int a, int b)
{
    if(a < b) swap(a, b);

    if(b == 0) return a;

    int r = a % b;
    return gcd(b, r);
}

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

    printf("%d\n", gcd(a, b));

    return 0;
}

Measured memory_bytes: 2684
#include <bits/stdc++.h>
#define N 300050
#define ll long long
#define x first
#define y second
#define all(v) v.begin(),v.end()
using namespace std;
ll n,d,a;
vector< pair< ll , ll > > ar;
ll pr[N];

int main() {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
            cout.tie(NULL);
            ll inf = 1e18;
            cin>>n>>d>>a;
            ar.resize(n);
            for(int i=0;i<n;i++)
                cin>>ar[i].x>>ar[i].y;
            sort(ar.begin(),ar.end());
            ll ans = 0 ;
            for(int i=0;i<n;i++){
                if(i)pr[i]+=pr[i-1];
                ll cu = ar[i].y - pr[i];
                if(cu<=0)continue;
                int in = upper_bound(all(ar),make_pair(ar[i].x + d + d, inf ))- ar.begin();
                ll dec = cu/a;
                if(cu%a)dec++;
                ans+=dec;
                dec*=a;
                pr[i]+=dec;
                pr[in]-=dec;
            }
            cout<<ans;

            return 0;
}


Measured memory_bytes: 4992
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func fSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	m := iScan()
	k := iScan()
	if k == 0 {
		ans := make([]int, 0)
		for i := 0; i < (1 << uint(m)); i++ {
			ans = append(ans, i)
			ans = append(ans, i)
		}
		fmt.Println(strings.Trim(fmt.Sprint(ans), "[]"))
	} else if k < (1 << uint(m)) {
		x := 0
		for i := 0; i < (1 << uint(m)); i++ {
			if i != k {
				x ^= i
			}
		}
		if x == k {
			ans := make([]int, 0)
			for i := 0; i < (1 << uint(m)); i++ {
				if i != k {
					ans = append(ans, i)
				}
			}
			ans = append(ans, k)
			for i := (1 << uint(m)) - 1; i >= 0; i-- {
				if i != k {
					ans = append(ans, i)
				}
			}
			ans = append(ans, k)
			fmt.Println(strings.Trim(fmt.Sprint(ans), "[]"))
		} else {
			fmt.Println(-1)
		}
	} else {
		fmt.Println(-1)
	}
}


Measured memory_bytes: 13524
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0; i<N; i++)

using namespace std;

int main(){
  int n; cin >> n;
  string s;
  cin >> s;
  int ans = 1;

  for(int i = 0; i < n - 1; i++) {
    if(s.substr(i,1) != s.substr(i+1,1)) {
      ans++;
    }
  }

  cout << ans << endl;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void anss(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=0,res2=INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0;
  bool judge = true;
  ll n,m;cin>>n>>m;
  buf=1;buf2=1;
  for(i=1;i<=n;i++)qmod(buf,i);
  for(i=1;i<=m;i++)qmod(buf2,i);
  qmod(buf,buf2);

  if(abs(n-m)==1){
    
  }
  else if(n==m){
    qmod(buf,2);

  }
  else buf=0;
  cout<<buf<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();

        int res = (x-z)/(y+z);
        System.out.println(res);

        sc.close();
    }
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x;
    cin >> x;
    int tmp = x / 500;
    x -= tmp * 500;
    int ans = tmp * 1000;
    tmp = x / 5;
    ans += tmp * 5;
    cout << ans << endl;
    return 0;
}



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

int main() {
  int a, b, c, d;

  cin >> a >> b >> c >> d;
    
  if((a+b) > (c+d)){
  	cout << "Left";
  }
  else if((a+b) == (c+d)){
  	cout << "Balanced";
  }
  else{
  	cout << "Right";
  }

}

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

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

    string s, t;
    cin >> s >> t;
    ll n = s.size();
    ll m = t.size();
    vector<vector<int>> a(26);
    ll ans = 0;
    ll r = 0, c = -1;
    rep(i, 0, n) {
        a[s[i] - 'a'].push_back(i);
        a[s[i] - 'a'].push_back(i + n);
    }
    rep(i, 0, 26) sort(a[i].begin(), a[i].end());
    rep(i, 0, m) {
        if (a[t[i] - 'a'].size() == 0) {
            cout << -1 << endl;
            return 0;
        }
        c = *upper_bound(a[t[i] - 'a'].begin(), a[t[i] - 'a'].end(), c);
        if (c >= n) {
            r += (c / n);
            c %= n;
        }
    }
    ans = c + 1 + n * r;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
int main(void){
  
  double N;  
  cin >> N;
  
  int nuki = N / 1.08;
  double komi = nuki * 1.08;
  
  int kotae = komi;
  
  if(kotae == N)
  {
    cout << nuki;		//正解の場合
  }
  else if(kotae < N)	//Nより小さかった場合
  {
    kotae = (nuki + 1) * 1.08;
    
    if(kotae == N)
    {
      cout << nuki + 1;
    }
    else
    {
      cout << ":(";
    }      
  }
  else if(kotae > N)	//Nより大きかった場合
  {
    kotae = (nuki - 1) * 1.08;
    
    if(kotae == N)
    {
      cout << nuki - 1;
    }
    else
    {
      cout << ":(";
    }
  }
  
    
  return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Data.Bool (bool)

main :: IO ()
main = solve <$> f >>= putStrLn
  where
    f = map read <$> words <$> getLine

solve :: [Int] -> String
solve [a, b, c] = bool "No" "Yes" $ (==1) $ length $ filter (==0) $ [a-b, b-c, c-a]


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  string s,t;
  cin >> s >> t;
  ll f=0;
  ll n=s.size();
  while(n--) {
    if(s==t) f=1;
    s=(s.substr(1,s.size()-1)+s[0]);
  }
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<unordered_map>
using namespace std;
using ll = long long;
int main(){
    ll N;
    cin >> N;
    ll a[100010];
    unordered_map<ll , ll> b;
    for(ll i = 1;i <= N;i++){
        cin >> a[i];
        b[a[i]]++;
    }
    ll ans = 0;
    unordered_map<long long, bool> z;
    for(ll i = 1;i <= N;i++){
        if(z[a[i]] == false){
        if(b[a[i]] > 0 && b[a[i]] < a[i])ans += b[a[i]];
        else if(b[a[i]] > a[i])ans += b[a[i]] - a[i];
        }
        z[a[i]] = true;
    }
    cout << ans;
}


Measured memory_bytes: 8996
#include<stdio.h>
int qu[100100],n,k,s;
int main()
{
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++)
		scanf("%d",&qu[i]);
	n--;
	k--;
	s=(n%k==0?0:1);
	s+=n/k;
	printf("%d\n",s);
	return 0;
}

Measured memory_bytes: 512
K, N = map(int, input().split())
A = list(map(int, input().split()))

a = A[0]
A = [x - a for x in A]

cur = 0
res = float('inf')
l = len(A)
for i in range(len(A)):
    x = A[i]

    if i == l - 1:
        d = abs(K - x)
    else:
        y = A[i + 1]
        d = y - x

    if d > cur:
        res = min(K - d, res)
        cur = d

print(res)


Measured memory_bytes: 26444
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

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

		List<String> sList = Arrays.asList(S.split(""));

		int zeroCount = 0;
		int oneCount= 0;
		int ans = 0;
		for(String s : sList){
			if(s.equals("0")){
				zeroCount++;
			}else{
				oneCount++;
			}
		}

		if(zeroCount>oneCount){
			ans = oneCount*2;
		}else{
			ans = zeroCount*2;
		}

		System.out.println(ans);

	}
}


Measured memory_bytes: 34036
#include"iostream"
#include"cstring"
#include"string"
#include"algorithm"
#include"cmath"
#include"cstdio"
#include"cstdlib"
#include"vector"
#include"bitset"
#include"set"
#include"map"
#include"iomanip"
#include"queue"
#include"stack"
using namespace std;
typedef long long ll;
int arr[105];
int cheq[105];
int main() {
	int num; scanf("%d", &num);
	memset(cheq, 0, sizeof(cheq));
	memset(arr, 0, sizeof(cheq));
	int bp = 2, tot = 0;
	for (int i = 1; i <= num; ++i)
		scanf("%d", &arr[i]);
	for (int fp = 1; fp <= num; ++fp, ++bp) {
		if (arr[fp] == arr[bp] && !cheq[fp] && !cheq[bp]) {
			cheq[bp] = 1;
			tot++;
		}
	}
	cout << tot << endl;
	return 0;
}

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

#define debug(...) fprintf(stderr,__VA_ARGS__)
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long LL;
const int MAXN=150 + 10;

char inis[MAXN*2], s[MAXN], t[MAXN];
int n,m , f[MAXN][MAXN][MAXN],mdf, g[MAXN*2][MAXN*2][MAXN];

int main(){
	
	scanf("%s", s+1);scanf("%d", &mdf);
	mdf=min(mdf, 150);
	for (int i=1,j=n; i<=n; i++,j--) t[j]=s[i];
	int n= strlen(s+1);
	memset(g, 0 ,sizeof(g));
	for (int i=1; i<=n; i++) g[i][i][0] = 1;
	for (int L=2; L<=n; L++)
		for (int i=1; i<=n; i++){
			int j=i+L-1;
			for (int k=0; k<=mdf; k++){
				int &cur= g[i][j][k];
				cur= max(g[i+1][j][k], g[i][j-1][k]);
				if ( s[i]==s[j]) cur= max(cur, g[i+1][j-1][k]+2);
					else
				if ( k) cur= max(cur, g[i+1][j-1][k-1]+2);
			}
		}
	int ans=0;
	for (int i=0; i<=mdf; i++) ans= max(ans , g[1][n][i]);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 65920
import heapq
import copy
N=int(input())
A=list(map(int,input().split()))
ca=copy.deepcopy(A)
fsl=[0 for i in range(N+1)]
f=ca[:N]
heapq.heapify(f)
fs=sum(f)
fsl[0]=fs
for i in range(N,2*N):
    heapq.heappush(f,A[i])
    fs=fs+A[i]-heapq.heappop(f)
    fsl[i-N+1]=fs
lsl=[0 for i in range(N+1)]
l=list(map(lambda x:-x,ca[2*N:]))
heapq.heapify(l)
ls=sum(l)
lsl[-1]=ls
for i in range(N,2*N):
    heapq.heappush(l,-A[3*N-i-1])
    ls=ls-A[3*N-i-1]-heapq.heappop(l)
    lsl[2*N-i-1]=ls
ans=-10**20
for i in range(N+1):
  ans=max(ans,fsl[i]+lsl[i])
print(ans)


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

using namespace std;

int dp[4005][32000];

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

	string s;
	int x, y;
	cin >> s >> x >> y;
	int len = s.length();
	vector<int> dx, dy;
	bool direct = true;
	int cnt = 0;
	for(int i = 0; i <= len + 1; i++)
	{
		if(i >= len || s[i] == 'T')
		{
			if(direct)dx.push_back(cnt);
			else dy.push_back(cnt);
			cnt = 0;
			direct = (direct ? false : true);
		}
		else cnt++;
	}
	int x_size = dx.size(), y_size = dy.size();
	dp[0][16000 + dx[0]] = true;
	bool ok = false;
	for(int i = 1; i < x_size; i++)
		for(int j = 8000; j <= 24000; j++)
		{
			if(dp[i - 1][j - dx[i]] || dp[i - 1][j + dx[i]])dp[i][j] = true;
		}
	if(dp[x_size - 1][16000 + x])ok = true;
  	for(int i=0;i<y_size;i++)
      	for(int j=0;j<32000;j++)
        {
          dp[i][j]=false;
        }
	dp[0][16000 + dy[0]] = true;
	dp[0][16000 - dy[0]] = true;
	for(int i = 1; i < y_size; i++)
		for(int j = 8000; j <= 24000; j++)
		{
			if(dp[i - 1][j - dy[i]] || dp[i - 1][j + dy[i]])dp[i][j] = true;
		}
	if(ok&&dp[y_size - 1][16000 + y])cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


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


bool solve(long long X, long long Y, bool me){
	if(X <= 1 && Y <= 1){
		return !me;
	}
	for(long long i = 1; 2 * i <= X; i++){
		if(solve(X - 2 * i, Y + i, !me) == me){
			return me;
		}
	}

	for(long long i = 1; 2 * i <= Y; i++){
		if(solve(X + i, Y - 2 * i, !me) == me){
			return me;
		}
	}
	return !me;
}

int main(){
	long long X, Y;
	cin >> X >> Y;
	if(abs(X - Y) <= 1){
		cout << "Brown" << endl;
	}else{
		cout << "Alice" << endl;
	}
	/*
	for(X = 0; X < 10; X++){
		for(Y = 0; Y < 10; Y++){
			cout << X << ", " << Y << endl;
			if(solve(X, Y, true)){
				cout << "Alice" << endl;
			}else{
				cout << "Brown" << endl;
			}
		}
	}
	*/
}



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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int a, b, k; cin >> a >> b >> k;
  int tmp = a;
  vector<int> v;
  if(a >= b) a = b, b = tmp;
  for(int i = 1; i <= 100; ++i) {
    if(a % i == 0 && b % i == 0){
      v.push_back(i);
    }
  }
  sort(v.begin(), v.end(), greater<int>());
  int cnt = 1;
  for(auto itr = v.begin(); itr != v.end(); itr++) {
    if(cnt == k) {
      cout << *itr << endl;
      return 0;
    }
    cnt++;
  }


  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        int S = sc.nextInt();
        int h = S / 3600;
        int m = S % 3600 / 60;
        int s = S % 3600 % 60;
        
        System.out.printf("%d:%d:%d\n", h, m, s);
        
    }
}


Measured memory_bytes: 26388
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <cassert>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

void solve()
{
    int a; ll b, n;
    scanf("%d%lld%lld", &a, &b, &n);

    ll r = MIN(b - 1, n);
    ll ans=a*r / b;

    printf("%lld\n", ans);


    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 1736
N = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
A.insert(N + 1, 0)
ALL = 0
for i in range(N + 1):
    ALL += abs(A[i] - A[i + 1])

for i in range(1, N + 1):
    abc = abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1])
    ac = abs(A[i - 1] - A[i + 1])
    print(ALL - abc + ac)


Measured memory_bytes: 13920
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <stdio.h>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORa(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)

// O(|V| + |E|)

//    Edges := 重み付き辺の集合
//    WeightedGraph := 重み付きグラフ
//    UnWeightedGraph := 重み無しグラフ
//    Matrix := 距離行列
template< typename T >
struct edge {
  ll src, to;
  T cost;

  edge(ll to, T cost) : src(-1), to(to), cost(cost) {}

  edge(ll src, ll to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator ll() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;


struct SCC
{
  vector< vector< int > > gg, rg;
  vector< pair< int, int > > edges;
  vector< int > comp, order, used;

  SCC(size_t v) : gg(v), rg(v), comp(v, -1), used(v, 0) {}

  void add_edge(int x, int y)
  {
    gg[x].push_back(y);
    rg[y].push_back(x);
    edges.emplace_back(x, y);
  }

  int operator[](int k)
  {
    return (comp[k]);
  }

  void dfs(int idx)
  {
    if(used[idx]) return;
    used[idx] = true;
    for(int to : gg[idx]) dfs(to);
    order.push_back(idx);
  }

  void rdfs(int idx, int cnt)
  {
    if(comp[idx] != -1) return;
    comp[idx] = cnt;
    for(int to : rg[idx]) rdfs(to, cnt);
  }

  void build(vector< vector< int > > &t)
  {
    for(int i = 0; i < gg.size(); i++) dfs(i);
    reverse(begin(order), end(order));
    int ptr = 0;
    for(int i : order) if(comp[i] == -1) rdfs(i, ptr), ptr++;

    t.resize(ptr);
    set< pair< int, int > > connect;
    for(auto &e : edges) {
      int x = comp[e.first], y = comp[e.second];
      if(x == y) continue;
      if(connect.count({x, y})) continue;
      t[x].push_back(y);
      connect.emplace(x, y);
    }
  }
};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll v,e;
    cin>>v>>e;
    UnWeightedGraph buff;
    SCC scc(v);
    FOR(i,0,e){
      ll in1,in2;
      cin>>in1>>in2;
      scc.add_edge(in1,in2);
    }
    scc.build(buff);
    int s=0;
    FOR(i,0,v){
      s = max(s,scc[i]);
    }
    cout<<(s==v-1 ? 0 : 1 )<<endl;
}



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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int mod = 1e+9 + 7;

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

	if (a >= 13) {
		cout << b << endl;
	}
	else if (a >= 6 && a <= 12) {
		cout << b / 2 << endl;
	}
	else {
		cout << 0 << endl;
	}


	return 0;
}


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

using namespace std;
int main(){
  int n, q;
  cin >> n;
  int *s = (int* )calloc(n, sizeof(int));
  for(int i=0;i<n;i++){
    cin >> s[i];
  }
  cin >> q;
  int *t = (int *)calloc(q, sizeof(int));
  for(int i=0;i<q;i++){
    cin >> t[i];
  }

  int ans = 0;
  for(int i=0;i<q;i++){
    for(int j=0;j<n;j++){
      if(t[i]==s[j]){
        ans++;
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3124
// https://yahoo-procon2019-qual.contest.atcoder.jp/tasks/yahoo_procon2019_qual_b
// +build ignore

package main

import "fmt"

func contains(s []int, e int) bool {
	for _, v := range s {
		if e == v {
			return true
		}
	}
	return false
}

func main() {
	// var a1, a2, a3, b1, b2, b3 int
	startends := make([]int, 6)
	m := make(map[int]bool)
	dupl := []int{}
	fmt.Scanf("%d %d", &startends[0], &startends[1])
	fmt.Scanf("%d %d", &startends[2], &startends[3])
	fmt.Scanf("%d %d", &startends[4], &startends[5])

	for _, element := range startends {
		if !m[element] {
			m[element] = true
		} else {
			if !contains(dupl, element) {
				dupl = append(dupl, element)
			}
		}
	}
	if len(dupl) == 2 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

Measured memory_bytes: 512
N = input()
A = list(map(int,input().split()))
x = 1
b = 0

A.sort()

for n in A:
    x*=n
    if x > 10**18:
        print(-1)
        b = 1
        break
    if x == 0:
        print(0)
        b = 1
        break
if b == 0:
    print(x)

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    ll n,m;cin >>n>>m;
    vector<P>p(n);
    for (int i = 0; i < n; ++i) {
        ll a,b;cin >>a>>b;
        p[i]=make_pair(a,b);
    }
    sort(all(p));
    ll ans=0;
    for (int i = 0; i < n; ++i) {
//        cout <<ans <<endl;
        ans+=min(m,p[i].second)*p[i].first;
        m-=p[i].second;
        if(m<=0)break;
    }
    cout <<ans <<endl;
    return 0;
}



Measured memory_bytes: 1792
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author EDGE
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskAtcoderB solver = new TaskAtcoderB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskAtcoderB {
        public void solve(int testNumber, FastReader in, PrintWriter out) {

            int n = in.nextInt(), k = in.nextInt();

            out.println(Integer.toString(n, k).length());
        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

    }
}



Measured memory_bytes: 21332
/*
AUTHOR: Naman
*/
#include <bits/stdc++.h>

using namespace std;
#define endl "\n"
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define all(x) x.begin(),x.end()
#define pb push_back
#define Fo(i,k,n) for(ll i=k;i<=n;i+=1)
#define deb(x) cout << #x << "=" << x << endl
#define in(a,n) Fo( i,0,n-1)cin>>a[i]
#define out(a,n) Fo( i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define IOS     ios_base::sync_with_stdio(0); cin.tie(NULL);
const ll N=2*1e6+1;
const ll M=1e9+7;

int main() {
	IOS
    ll t=1;
	//cin>>t;	
	
	Fo(_,1,t)
	{
	   //cout<<"Case #"<<_<<": ";
	   ll n;
	   cin>>n;
	   ll ar[n];
	   in(ar,n);
	   ll suf[n];
	   suf[n-1]=ar[n-1];
	   
	   for(ll i=n-2;i>=0;i--)suf[i]=(suf[i+1]+ar[i]%M)%M;
	   
	   ll ans=0;
	   
	   Fo(i,0,n-2)
	   {
	       ans+=(ar[i]%M*suf[i+1]%M)%M;
	       ans%=M;
	   }
	   cout<<ans;
	   
	   


	   cout<<endl;
	   
	}
	
    
}

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

int main() 
{
	int N, X, Y;
	cin >> N >> X >> Y;
	
	int c[2000] = {};
	
	// i,j <= X,  i=1...X, j=i+1,...,X
	for(int i = 1; i <= X; i++){
		for(int j = i+1; j <= X; j++){
			c[j-i]++;
		}
	}
	// i <= X, X<j<Y
	for(int i = 1; i <= X; i++){
		for(int j = X+1; j < Y; j++){
			if(1 + Y - j < j - X){
				c[X-i + 1+ Y-j]++;
			}else{
				c[j-i]++;
			}
		}
	}

	// i <= X, Y <= j
	for(int i = 1; i <= X; i++){
		for(int j = Y; j <= N; j++){
			c[X-i+1+j-Y]++;
		}
	}

	// X<i,j<Y
	for(int i = X+1; i < Y; i++){
		for(int j = i+1; j < Y; j++){
			if(i - X + 1 + Y - j < j - i){
				c[i-X + 1 + Y-j]++;
			}else{
				c[j-i]++;
			}
		}
	}
	// X<i<Y, Y <= j
	for(int i = X+1; i < Y; i++){
		for(int j = Y; j <= N; j++){
			if(i-X + 1 + j-Y < j-i){
				c[i-X + 1 + j-Y]++;
			}else{
				c[j-i]++;
			}
		}
	}

	// Y < i,j
	for(int i = Y; i < N; i++){
		for(int j = i+1; j <= N; j++){
			c[j-i]++;
		}
	}

	for(int k = 1; k < N; k++){
		cout << c[k] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"


func main() {
  var x1, x2, x3, x4, x5 int
  fmt.Scan(&x1, &x2, &x3, &x4, &x5)
  
  a := []int {x1, x2, x3, x4, x5}
  
  for i, v := range a {
    if v == 0 {
      fmt.Println(i+1)
    }
  }
}

Measured memory_bytes: 1752
#include <bits/stdc++.h>
using namespace std;
int32_t main()
{
    int a,b,c;
    cin >> a >> b >> c;
   if((c<=b && c>=a )|| (c>=b && c<=a)){
       cout<<"Yes\n";
   }
   else{
       cout<<"No\n";
   }


}


Measured memory_bytes: 256