akhauriyash/Code-Regression huggingface dataset:
// Problem : B - 01 Unbalanced
// Contest : AtCoder - AtCoder Grand Contest 045
// URL : https://atcoder.jp/contests/agc045/tasks/agc045_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<int,ll > pil;
typedef pair<ll ,int> pli;
typedef pair<ll ,ll > pll;
typedef vector<int> vi;
typedef vector<ll > vl;
#define pque priority_queue
#define rep(i,l,r) for(i=(l);i<=(r);++i)
#define per(i,l,r) for(i=(l);i>=(r);--i)
#define REP(i,l,r) for(i=(l);i< (r);++i)
#define PER(i,l,r) for(i=(l);i> (r);--i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define fi first
#define se second
#define bugs(x) cerr<<"    "<<(x);
#define bugx(x) cerr<<"    "<<(#x)<<" = "<<(x);
#define bugl cerr<<"\n";
#define bugt bugx(clock());bugl;
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
template<class IT>inline bool bmax(IT &a,IT b){if(a<b){a=b;return true;}else return false;}
template<class IT>inline bool bmin(IT &a,IT b){if(a>b){a=b;return true;}else return false;}
const int N=1000005;
char C[N];int X[N];
inline int sol(int n,int b){
	//bugs("SOL") bugx(n) bugx(b) bugl
	int i,s=0,t=0;
	per(i,n,1){
		if(C[i]=='1')++s;
		else --s;
		cmax(s,0);
		X[i]=s;
	}
	//rep(i,1,n)bugx(X[i]) bugl
	s=t=0;
	rep(i,1,n){
		if(C[i]=='?'){
			if(t+1+X[i+1]<=b)++t;
			else --t;
		}else{
			if(C[i]=='1')++t;
			else --t;
		}
		cmin(s,t);
	}
	//bugx(s) bugl
	return b-s;
}
inline void ac(){
	int n,i,s=0,t=0;
	scanf("%s",C+1);
	n=strlen(C+1);
	rep(i,1,n){
		if(C[i]=='1')cmax(t,++s);
		else --s;
	}
	printf("%d",min(sol(n,t),sol(n,t+1)));
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	
	ac();
	return 0;
}
#undef pque
#undef rep
#undef per
#undef REP
#undef PER
#undef mp
#undef pb
#undef pf
#undef pob
#undef pof
#undef fi
#undef se
#undef bugs
#undef bugx
#undef bugl

Measured memory_bytes: 8712
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 1e-9;

long long int N, M, K, H, W, L, R;

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

	cin >> N >> M;
	vector<long long int>a(N);
	vector<long long int>b(N);
	vector<long long int>c(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	long long int ans = 0;
	for (int i = 0; i < 8; i++) {
		vector<long long int>aa;
		vector<long long int>bb;
		vector<long long int>cc;
		aa = a;
		bb = b;
		cc = c;
		if (i & 1) {
			for (int j = 0; j < N; j++) {
				aa[j] *= -1;
			}
		}
		if ((i >> 1) & 1) {
			for (int j = 0; j < N; j++) {
				bb[j] *= -1;
			}
		}
		if ((i >> 2) & 1) {
			for (int j = 0; j < N; j++) {
				cc[j] *= -1;
			}
		}
		vector<long long int>box(N);
		for (int j = 0; j < N; j++) {
			box[j] = aa[j] + bb[j] + cc[j];
		}
		sort(box.begin(), box.end());
		reverse(box.begin(), box.end());
		long long int ret = 0;
		for (int j = 0; j < M; j++) {
			ret += box[j];
		}
		ans = max(ans, ret);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include<cstdio>
using namespace std;
int main(){
	unsigned int n;
	unsigned long long int a,pre,ans=0;
	bool now=false,def=false;//true now means increasing
	scanf("%u",&n);
	scanf("%llu",&a);
	--n;
	while(n-->0){
		pre=a;
		scanf("%llu",&a);
		if(def){
			if(now)
			if(a<pre){
				def=false;
				if(n>0){
					pre=a;
					scanf("%llu",&a);
					--n;
				}
				++ans;
			}
			if(!now)
			if(a>pre){
				def=false;
				if(n>0){
					pre=a;
					scanf("%llu",&a);
					--n;
				}
				++ans;
			}
		}
		if(n)
		if(!def){
			if(a>pre){
				now=true;
				def=true;
			}
			if(a<pre){
				now=false;
				def=true;
			}
		}
	}
	printf("%llu",ans+1);
	return 0;
}

Measured memory_bytes: 128
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real()*a.real() + a.imag()*a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
#include <bits/stdc++.h>
using namespace std;


void solve(long long N, long long M, std::vector<long long> P, std::vector<long long> Y){
	vector<pair<int, int>> ans;
	ans.reserve(M);
	vector<tuple<long long, long long, long long>> gogo;
	long long cnt[200000] = {};
	REP(i, M) {
		gogo.push_back(make_tuple(Y[i], P[i], i));
	}
	sort(gogo.begin(), gogo.end());
	for (int i = 0; i < M; ++i) {
		cnt[get<1>(gogo[i])]++;
		ans[get<2>(gogo[i])] = make_pair(get<1>(gogo[i]), cnt[get<1>(gogo[i])]);
	}
	REP(i, M) {
		cout << setfill('0') << right << setw(6) << ans[i].first;
		cout << setfill('0') << right << setw(6) << ans[i].second << endl;
	}
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> P(M);
    std::vector<long long> Y(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&P[i]);
        scanf("%lld",&Y[i]);
    }
    solve(N, M, std::move(P), std::move(Y));
    return 0;
}


Measured memory_bytes: 8560
#include <stdio.h>
#include <math.h>

int main() {

  double a,b,c;
  double S,L2, L, h;

  scanf("%lf %lf %lf",&a,&b,&c);

  S = 0.5*a*b*sin(c*3.14159265359/180);
  L2 = a*a+b*b-2*a*b*cos(c*3.1415926359/180);
  L = sqrt(L2)+a+b;
  h = 2*S/a;

  printf("%.11lf\n%.11lf\n%.11lf\n",S ,L,h); 

  return 0;
}



Measured memory_bytes: 2120
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        TreeMap<Integer,Integer> oddmap = new TreeMap<Integer,Integer>(Comparator.reverseOrder());
        TreeMap<Integer,Integer> evenmap = new TreeMap<Integer,Integer>(Comparator.reverseOrder());
        for(int i = 0; i < n; i++){
            int a = sc.nextInt();
            if(i % 2 == 0){
                if(evenmap.containsKey(a)){
                    evenmap.put(a,evenmap.get(a)+1);
                }else{
                    evenmap.put(a,1);
                }
            }else{
                if(oddmap.containsKey(a)){
                    oddmap.put(a,oddmap.get(a)+1);
                }else{
                    oddmap.put(a,1);
                }
            }
        }
        PriorityQueue<Point> odd = new PriorityQueue<>();
        PriorityQueue<Point> even = new PriorityQueue<>();
        for(Map.Entry<Integer,Integer> e : oddmap.entrySet()){
            odd.add(new Point(e.getKey(), e.getValue()));
        }
        for(Map.Entry<Integer,Integer> e : evenmap.entrySet()){
            even.add(new Point(e.getKey(), e.getValue()));
        }
        Point odd1 = odd.poll();
        Point even1 = even.poll();
        if(odd1.key != even1.key){
            System.out.println(n - odd1.value - even1.value);
        }else{
            int odd2 = odd.size() != 0 ? odd.poll().value : 0;
            int even2 = even.size() != 0 ? even.poll().value : 0;
            System.out.println(Math.min(n - odd1.value - even2 , n - odd2 - even1.value));
        }
    }
}

class Point implements Comparable<Point>{
    int key,value;
    public Point(int k, int v){
        this.key = k;
        this.value = v;
    }
    
    public int compareTo(Point p){
        if(this.value > p.value){
            return -1;
        }else if(this.value < p.value){
            return 1;
        }
        return 0;
    }
}


Measured memory_bytes: 56980
#include <stdio.h>
#include <iostream>
int s[1000];
using namespace std;
int main()
{
    int n;
    cin>>n;
    for (int i=0; i<n; i++)
    {
        cin>>s[i];
    }
    int m,p;

    m=0;
    p=n-1;
    int sum1=s[m];
    int sum2=s[p];
    while ((p-m)!=1)
    {
        if (sum1<sum2)
            sum1+=s[++m];
        else
            sum2+=s[--p];
    }
    if (sum1>sum2)
        cout<<sum1-sum2<<endl;
    else
        cout <<sum2-sum1<<endl;


    return 0;
}


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

#define ll long long
#define fast_io ios::sync_with_stdio(0); cin.tie(0)
#define infl 1e18+9
#define sz(a) ((int)a.size())

const int nax=3005; 
ll maxx[nax][nax];  
ll minn[nax][nax];  
void solve(){
  int n;
  cin>>n; 
  vector<int> a(n); 
  for(int i=0;i<n;i++){
    cin>>a[i]; 
  }
  for(int l=1;l<=n;l++){
    for(int i=0;i+l-1<n;i++){
      int j=i+l-1; 
      if(l==1){
        maxx[i][j]=a[i]; 
        minn[i][j]=-a[i]; 
      }
      else {
        maxx[i][j]=max(minn[i][j-1]+a[j],minn[i+1][j]+a[i]); 
        minn[i][j]=min(maxx[i][j-1]-a[j],maxx[i+1][j]-a[i]); 
      }
    }
  }
  cout<<maxx[0][n-1]<<endl; 
}

int main()
{
	fast_io;
	clock_t beg=clock(); 
	solve(); 
	clock_t end=clock(); 
	fprintf(stderr,"%.2lf sec\n",(double)(end-beg)/CLOCKS_PER_SEC); 
	return 0;
}

Measured memory_bytes: 139904
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

const int MAX_N = 200000 * 2;

map<ll, vector<ll>> powers;

ll f(ll mod, int bit, bool to_one, const string &original_S) {
    // printf("mod: %lld, bit: %d, to_one: %d, %s\n", mod, bit, to_one, original_S.c_str());
    static map<ll, ll> memo;
    if (powers.find(mod) == powers.end()) {
        // power[i] is 2 ^ i % mod
        vector<ll> power(MAX_N + 10);
        power[0] = 1 % mod;

        for (int i = 1; i <= MAX_N; i++) {
            power[i] = (power[i - 1] * 2) % mod;
            // printf("power[%d]: %lld\n", i, power[i]);
        }
        powers[mod] = power;
    }

    vector<ll> &power = powers[mod];

    if (memo.find(mod) == memo.end()) {
        ll v = 0;
        string T = original_S;
        reverse(T.begin(), T.end());
        for (int i = 0; i < (int) T.size(); i++) {
            if (T[i] == '1') {
                v = (v + power[i]) % mod;
            }
        }
        memo[mod] = v;
    }

    ll ans = memo[mod];
    // printf("memo: %lld\n", ans);

    if (to_one) {
        ans = (ans + power[bit]) % mod;
    } else {
        // if ((x += MOD-a.x) >= MOD) x -= MOD;
        if ((ans += mod - power[bit]) >= mod) ans -= mod;
        // ans = (ans - power[bit]) % mod;
        // while (ans < 0) {
        //     ans += mod;
        // }
    }

    // string T = S;
    // reverse(T.begin(), T.end());
    // for (int i = 0; i < (int) T.size(); i++) {
    //     if (T[i] == '1') {
    //         ans = (ans + (*power)[i]) % mod;
    //     }
    // }

    return ans;
}

int count_bit(const string &S) {
    int ans = 0;

    for (int i = 0; i < (int) S.size(); i++) {
        if (S[i] == '1') {
            ans++;
        }
    }

    return ans;
}

int main(void) {
    int N;
    cin >> N;
    string S;
    cin >> S;

    const int bit_count = count_bit(S);
    // printf("bit_count: %d\n", bit_count);

    for (int i = 0; i < N; i++) {
        string T = S;
        ll mod;
        if (T[i] == '1') {
            T[i] = '0';
            mod = bit_count - 1;
        } else {
            T[i] = '1';
            mod = bit_count + 1;
        }
        // printf("%s, %lld\n", T.c_str(), mod);
        // printf("%d: %lld\n", i, f(mod, T));

        if (mod == 0) {
            printf("%d\n", 0);
            continue;
        }
        ll x = f(mod, N - i - 1, T[i] == '1', S);

        int cnt = 1;
        // printf("x: %lld\n", x);
        while (x > 0) {
            int bit_count = __builtin_popcountll(x);
            // printf("x: %lld, bit_count: %d\n", x, bit_count);
            x = x % bit_count; // f(bit_count, to_string(x));
            cnt++;
        }

        printf("%d\n", cnt);
    }

    return 0;
}


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

int main(){
int L, R, d;
cin  >> L >> R >> d;

int count = 0;
for (int num = L; num <= R; num++){
	int i = 0 ;
	
	if ( num % d == 0 ) {
		count++;
	}
/*
	int id = 0;
	while ( id <= R ){
		id = i * d ;
		//cout << id ;
		if ( id > L ) {
			if ( num % id == 0){
				cout << id << endl ;
				count++;
			}
		}	
		i++;
	}
*/
}

cout << count << endl;
return 0;
}


Measured memory_bytes: 3564
#include <stdio.h>
#include <stdlib.h>
#include<string.h>

int main() {
  int n,m,i,j;
  scanf("%d",&n);
  char s[n][10];
  for(i=0;i<n;i++) {
    scanf("%s",s[i]);
  }
  scanf("%d",&m);
  char t[m][10];
  for(i=0;i<m;i++) {
    scanf("%s",t[i]);
  }
  int pts[n];
  for(i=0;i<n;i++) {
    pts[i]=0;
  }
  for(i=0;i<n;i++) {
    for(j=0;j<n;j++) {
      if(strcmp(s[i],s[j])==0) {
        pts[i]++;
      }
    }
    for(j=0;j<m;j++) {
      if(strcmp(s[i],t[j])==0) {
        pts[i]--;
      }
    }
  }
  int ptsmax = 0;
  for(i=0;i<n;i++) {
    if(ptsmax < pts[i]) {
      ptsmax = pts[i];
    }
  }
  printf("%d\n",ptsmax);
  return 0;
}


Measured memory_bytes: 888
// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
    std.range, std.container, std.bigint, std.ascii, std.typecons;
import std.numeric;

// }}}
// nep.scanner {{{
class Scanner
{
    import std.stdio : File, stdin;
    import std.conv : to;
    import std.array : split;
    import std.string;
    import std.traits : isSomeString;

    private File file;
    private char[][] str;
    private size_t idx;

    this(File file = stdin)
    {
        this.file = file;
        this.idx = 0;
    }

    this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType))
    {
        this.file = file;
        this.idx = 0;
        fromString(s);
    }

    private char[] next()
    {
        if (idx < str.length)
        {
            return str[idx++];
        }

        char[] s;
        while (s.length == 0)
        {
            s = file.readln.strip.to!(char[]);
        }

        str = s.split;
        idx = 0;

        return str[idx++];
    }

    T next(T)()
    {
        return next.to!(T);
    }

    T[] nextArray(T)(size_t len)
    {
        T[] ret = new T[len];

        foreach (ref c; ret)
        {
            c = next!(T);
        }

        return ret;
    }

    void scan()()
    {
    }

    void scan(T, S...)(ref T x, ref S args)
    {
        x = next!(T);
        scan(args);
    }

    void fromString(StrType)(StrType s) if (isSomeString!(StrType))
    {
        str ~= s.to!(char[]).strip.split;
    }
}
// }}}


ulong lcm(ulong a, ulong b)
{
    return a / gcd(a, b) * b;
}
    
void main()
{
    auto cin = new Scanner;

    int n;
    cin.scan(n);
    auto a = cin.nextArray!ulong(n);
    ulong res;
    foreach (e; a)
    {
        res += e - 1;
    }
    res.writeln;
}


Measured memory_bytes: 380
from collections import Counter

def list2str(l):
    s = ""
    for c in l:
        s += c
    return s

n = int(input())

s = []
for _ in range(n):
    s.append(list2str(sorted(input())))

"""
# TLE
cnt = 0
for i in range(1, n):
    for j in range(i):
        if s[j] == s[i]:
            cnt += 1
print(cnt)
"""

"""
# AC
print(sum([x * (x - 1) // 2 for x in Counter(sorted(s)).values()]))
"""

cnt = 0
a = Counter()
for b in s:
    if b in a:
        cnt += a[b]
    a[b] += 1
print(cnt)

Measured memory_bytes: 19764
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}

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


/////////////////////////////////////////////////////////////////////////////////////

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 1;i < n;i++){
        int A;
        cin >> A;
        A--;
        a[A]++;
    }

    for (int i = 0;i < n;i++){
        cout << a[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3972
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


class UnionFind:
    # Reference: https://note.nkmk.me/python-union-find/
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())


def main():
    N, M, *AB = map(int, read().split())

    AB = list(reversed(AB[2:]))
    count = N * (N - 1) // 2
    ans = [count]
    uf = UnionFind(N)

    for a, b in zip(AB[::2], AB[1::2]):
        a -= 1
        b -= 1
        if not uf.same(a, b):
            count -= uf.size(a) * uf.size(b)
            uf.union(a, b)
        ans.append(count)

    print('\n'.join(map(str, reversed(ans))), sep='\n')
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 27996
import java.util.*;
// cin=sc.nextInt();
// List<Integer> a = new ArrayList<Integer>(n);
 
public class Main {
    public static void main(String args[]){
		    Scanner sc = new Scanner(System.in);
            String s = sc.next();
            if(s.charAt(1) == 'O'){
                System.out.println(6);
            }
            else if(s.charAt(1) == 'E'){
                System.out.println(4);
            }
            else if(s.charAt(1) == 'H'){
                System.out.println(3);
            }
            else if(s.charAt(1) == 'R'){
                System.out.println(2);
            }
            else if(s.charAt(1) == 'A'){
                System.out.println(1);
            }
            else if(s.charAt(0) == 'S'){
                System.out.println(7);
            }
            else if(s.charAt(0) == 'T'){
                System.out.println(5);
            }
	}
}


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

int g(int n) {
  if (n == 2) return 3;
  else if (n == 4 || n == 6 || n == 9 || n == 11 ) return 2;
  else return 1;
}

int main() {
  int x, y;
  cin >> x >> y;
  cout << (g(x) == g(y) ? "Yes" : "No") << endl;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string ss = Console.ReadLine();
            int a = (int)(ss.Length / 5 + 1);

            for(int i = 1; i<= a; i++)
            {
                if (ss.EndsWith("dream"))
                {
                    ss = ss.Substring(0, ss.Length - 5);
                }
                else if (ss.EndsWith("dreamer"))
                {
                    ss = ss.Substring(0, ss.Length - 7);
                }
                else if (ss.EndsWith("erase"))
                {
                    ss = ss.Substring(0, ss.Length - 5);
                }
                else if (ss.EndsWith("eraser"))
                {
                    ss = ss.Substring(0, ss.Length - 6);
                }
                else
                {
                    break;
                }
            }

            if (ss.Length == 0)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }
    }

 }



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

using namespace std;
typedef long long Int;

Int ans = 0;
Int gobackr[108000];
Int gobackl[108000];
Int gor[108000];
Int gol[108000];
Int x[108000];
Int v[108000];
Int n, c;
int main(){
	cin >> n >> c;
	ans -= c;
	for(Int i = 0;i < n;i++){
		cin >> x[i]>> v[i];
		ans += v[i];
	}

	ans = max(ans, 0LL);
	Int sum = 0;
	for(Int i = 0;i < n;i++){
		sum += v[i];
		gobackr[i+1] = max(gobackr[i], sum - 2 * x[i]);
		gor[i+1] = max(gor[i], sum - x[i]);
	}
	sum = 0;
	for(Int i = n-1;i >= 0;i--){
		sum += v[i];
		gobackl[i] = max(gobackl[i+1], sum - 2 * (c-x[i]));
		gol[i] = max(gol[i+1], sum - (c-x[i]));
	}

	for(Int i = 0;i <= n;i++){
		ans = max(ans, gobackr[i] +gol[i]);
		ans = max(ans, gobackl[i] +gor[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5120
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	X := ReadInt()
	for {
		isPrime := true
		for i := 2; i*i <= X; i++ {
			if X%i == 0 {
				isPrime = false
				break
			}
		}
		if isPrime {
			fmt.Println(X)
			return
		}
		X++
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

using namespace std;

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

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

    cout << max(a,b)*min(a,b)/gcd(max(a,b),min(a,b)) << endl;
    

    return 0;
}

Measured memory_bytes: 256
using System;

namespace ABC096_A_Day_of_Takahashi
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			string[] input = Console.ReadLine().Split(' ');
			int a = int.Parse(input[0]);
			int b = int.Parse(input[1]);

			if (a <= b)
			{
				Console.WriteLine(a);
			}
			else
			{
				Console.WriteLine(a - 1);
			}
		}
	}
}

Measured memory_bytes: 13140
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

class bipartite_matching{
private:
  int V;
  vector< vector< int > > info;
  vector< int > match;
  vector< bool > used;
public:
  bipartite_matching(int V_size):V(V_size){
    info.resize(V_size);
    used.resize(V_size);
    match.resize(V_size);
  };
  void add_edge( int u, int v){
    info[u].push_back(v);
    info[v].push_back(u);
  }
  bool dfs( int v){
    used[v] = true;
    for(int i = 0; i < info[v].size(); i++){
      int u = info[v][i], w = match[u];
      if(w < 0 || !used[w] && dfs(w)){
        match[v] = u, match[u] = v;
        return true;
      }
    }
    return false;
  }
  int run(){
    match.assign(V,-1);
    int ret = 0;
    for(int i = 0; i < V; i++){
      if(match[i] < 0){
        used.assign(V,false);
        if(dfs(i)) ret++;
      }
    }
    return ret;
  }
};

int main(){
  int m, n, b[500], r[500];
  while(cin >> m >> n , m){
    bipartite_matching bm(n + m);
    for(int i = 0; i < m; i++){
      cin >> b[i];
    }
    for(int i = 0; i < n; i++){
      cin >> r[i];
    }
    for(int i = 0; i < m; i++){
      for(int j = 0; j < n; j++){
        if(__gcd(b[i],r[j]) > 1) bm.add_edge( i, m + j);
      }
    }
    cout << bm.run() << endl;
  }
}

Measured memory_bytes: 2712
#include<iostream>
#include<cmath>


using namespace std;


int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    if(ceil((double)C/B)<=ceil((double)A/D)) cout <<"Yes"<<endl;
    else cout << "No" << endl;
    return 0;

}

Measured memory_bytes: 3620
/*
 * ARC082_D.cpp
 *
 *  Created on: Jun 5, 2018
 *      Author: 13743
 */
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}

int p[100001];
vector<int> con;

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

	int N;
	cin >> N;
	FOR(i, 1, N) {
		cin >> p[i];
	}

	bool start = true;
	FOR(i, 1, N) {
		if(start && p[i]==i) {
			con.pb(0);
			start = false;
		}
		if(p[i] == i) con[con.size()-1]++;
		else start = true;
	}

	int ans = 0;
	REP(i, SZ(con)) {
		ans += con[i]/2;
		if(con[i]%2 == 1) {
			ans++;
		}
	}

	cout << ans << endl;
}






Measured memory_bytes: 1024
N, M, X = list(map(int, input().split()))
A = set(map(int, input().split()))
min_cost = 1000

cost = 0
for i in range(X, 0, -1):            
    if i in A:
        cost += 1
min_cost = min(cost, min_cost)

cost = 0
for i in range(X, N):
    if i in A:
        cost += 1
min_cost = min(cost, min_cost)
print(min_cost)

Measured memory_bytes: 3064
N, K = map(int, input().split())
V = [int(a) for a in input().split()]
INF = 1<<50
ma = 0
for i in range(min(K, N)+1):
    for j in range(i+1):
        S = sorted(V[:j] + ([] if i==j else V[-(i-j):]))
        ma = max(ma, sum([max(S[t], (0 if t < K-i else -INF)) for t in range(len(S))]))
print(ma)

Measured memory_bytes: 42096
#include <stdlib.h>
#include <stdio.h>
typedef struct{
    int head;
    int tail;
}war;
int compare(const void*a,const void *b){
    war tmp1=*(war*)a,tmp2=*(war*)b;
    int x=tmp1.tail,y=tmp2.tail;
    if(x>y)return 1;
    return -1;
}
int main()
{   int n,m;
    scanf("%d%d",&n,&m);
    war a[m];
    for(int i=0;i<m;i++){
        scanf("%d%d",&a[i].head,&a[i].tail);
    }
    qsort(a,m,sizeof(war),compare);
    int ans=1,cut=a[0].tail;
    for(int i=0;i<m;i++){
        if(a[i].head<cut){
            
        }else{
            ans++;
            cut=a[i].tail;
        }
    }
    printf("%d",ans);
    return 0;
}


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

int main()
{
	int n;
	std::cin >> n;
	long long res = 0;
	for (int i = 1; i <= n; i++)
		for (int j = i; j <= n; j += i)
			res += j;

	std::cout << res << std::endl;
}

Measured memory_bytes: 3616
#include <stdio.h>
int findSumofDigits(int n){
  int sum = 0;
  while (n>0){
    sum+= n%10;
    n/=10;

  }
      return sum;
}

int main(void){
  int N,A,B,total,sum,i;
  sum=0;
  total=0;

  scanf("%d",&N);
  scanf("%d",&A);
  scanf("%d",&B);

  for(i=1;i<=N;i++){
    sum=findSumofDigits(i);

    if(A<=sum&&sum<=B){
      total+=i;
    }
  }
  printf("%d\n",total);

  return 0;
}

Measured memory_bytes: 1708
def resolve():
  n = int(input())
  aa = list(map(int, input().split()))
  s = set()
  num = 0
  for a in aa:
    if a >= 3200:
      num += 1
    else:
      s.add(a // 400)
  print(max(len(s), 1), len(s) + num)
  return

if __name__ == "__main__":
  resolve()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<double> v(N);
  double average = 0.0;
  rep(i,N){
    cin >> v[i];
    average += v[i];
  }
  average /= N;
  int id = 0;
  double mini = DBL_MAX;
  rep(i,N){
    double x = abs(v[i] - average);
    if(x<mini){
      id = i;
      mini = x;
    }
  }
  cout << id << endl;
  return 0;
}


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

int main(){
     int a;
     int b;
     int c;
     cin >> a >> b >> c;
     if(a>b){
         int t = b;
         b = a;
         a = t;
     }
     if(b>c){
         int t = c;
         c = b;
         b = t;
     }
    if(a>b){
         int t = b;
         b = a;
         a = t;
     }
     cout << a <<" "<< b <<" "<< c <<endl;
}



Measured memory_bytes: 3072
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <set>
#include <tuple>

using namespace std;
typedef vector<int>VI;
typedef long long LL;

#define IOSWORK ios::sync_with_stdio(0); cin.tie(0)
#define FOR(x, b, e) for(int x = b; x<= (e); x++)
#define FORD(x, b, e) for(int x = b; x>= (e); x--)
#define REP(x, n) for(int x = 0; x<(n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define VAR(v, n) typeof(n) v = (n)
#define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define SCAN_INT(n) scanf("%i",&n)
#define SCAN_P_INT(n,m) scanf("%i %i",&n,&m)
#define PRINT_P_INT(n,m) printf("%i %i\n",n,m);
#define PRINT_INT(n) printf("%i\n",n)

#define PB push_back
#define ST first
#define ND second
#define INF 1000000000


#define MAXSIZE

int n,k;
int suma;

int main(){
   SCAN_P_INT(n,k);
   REP(i,n){
        int temp;
        SCAN_INT(temp);
        int zmienna;
        suma+=2*min(temp,(k-temp)>0?k-temp:temp-k);
   }
   PRINT_INT(suma);
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
#include<tuple>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
#define rrep(i,n)for(int i=n-1;i>=0;i--)
#define REP(i,n) for (int i = 1; i <= (int)n; i++)//i=1からi=nまで
#define RREP(i,n)for(int i=n;i>=1;i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const double pi = 3.14159265358979323846;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int a; cin >> a;
    cout << a * a + a * a * a + a << endl;
   
}


    





















Measured memory_bytes: 3628
def main():
    import sys
    input = sys.stdin.readline

    N = list(map(int, list(input()[:-1])))
    K = int(input())
    L = len(N)

    # dp[i][j][k]
    # i 桁目まで決めて
    # j 個の非0を使って
    # k = 0 : そこまでの桁はNと一致
    # k = 1 : そこまでの桁でN未満であることが確定
    dp = [[[0] * 2 for _ in range(K + 2)] for _ in range(L + 1)]
    dp[0][0][0] = 1

    for i, x in enumerate(N):
        for k in range(K + 1):
            # 桁ごと数え上げ
            if x == 0:
                # x == 0
                dp[i + 1][k][0] += dp[i][k][0]
            else:
                # x == 0
                dp[i + 1][k][1] += dp[i][k][0]
                # 0 < n < x
                dp[i + 1][k + 1][1] += dp[i][k][0] * (x - 1)
                # n == x
                dp[i + 1][k + 1][0] += dp[i][k][0]
            # N未満で次の桁に1~9を入れる
            dp[i + 1][k + 1][1] += dp[i][k][1] * 9
            # N未満で次の桁に0を入れる
            dp[i + 1][k][1] += dp[i][k][1]

    print(sum(dp[L][K]))  

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 100005;
 
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
     ll a,b;
     cin >> a >> b;
     if(a<b)
     {
         for(ll i=0;i<b;i++)    cout<<a;
     }
     else
     {
         for(ll i=0;i<a;i++)    cout<<b;
     }
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
public class Hello
{

    public static void Main()
    {
        string[] s = Console.ReadLine().Split(' ');
        //水の追加
        int A = int.Parse(s[0]) * 100;
        int B = int.Parse(s[1]) * 100;
        //砂糖追加
        int C = int.Parse(s[2]);
        int D = int.Parse(s[3]);
        //100あたり溶ける量
        double E = double.Parse(s[4]);
        //限界
        int F = int.Parse(s[5]);

        double max = -1;
        double concentration = 0;
        string ans = "";
        int water = 0;
        int sugar = 0;

        int A_count = 0;
        int B_count = 0;
        int C_count = 0;
        int D_count = 0;

        for (A_count = 0; A * A_count <= F; A_count++)
        {
            for (B_count = 0; (A * A_count + B * B_count) <= F; B_count++)
            {
                for (C_count = 0; (A * A_count + B * B_count) + (C * C_count) <= F; C_count++)
                {
                    for (D_count = 0; (A * A_count + B * B_count) + (C * C_count + D * D_count) <= F; D_count++)
                    {
                        water = (A * A_count + B * B_count);
                        sugar = (C * C_count + D * D_count);
                        //規定内
                        if (sugar <= water * E / 100)
                        {
                            //濃度計算
                            concentration = concentration_cal(water, sugar);
                            if (max < concentration) { max = concentration; ans = (water + sugar) + " " + sugar; }
                        }
                    }
                }
            }
        }

        Console.WriteLine(ans);
    }

    static int sugar_set(int A, int B, double sugar_max)
    {
        int max = -1;
        int A_count = 0;
        int B_count = 0;
        int sugar = 0;

        while (true)
        {
            sugar = A * A_count + B * B_count;
            //Console.WriteLine(A + " * " + A_count + " + " + B + " * " + B_count + " = " + sugar);
            //小さい場合
            if (sugar <= sugar_max)
            {
                if (max < sugar) max = sugar;
                B_count++;
            }
            else
            {
                if (B_count == 0) break;
                A_count++;
                B_count = 0;
            }
        }

        return max;

    }

    static double concentration_cal(int water, int sugar)
    {
        double a = 100.0 * sugar;
        double b = water + sugar + 0.0;
        return a / b;
    }


    static int[] s_to_i(string[] s)
    {
        int[] ret = Array.ConvertAll<string, int>(s, delegate (string value) { return int.Parse(value); });
        return ret;
    }
}

Measured memory_bytes: 11092
def g(A,l,m,r):
    global c
    L, R = A[l:m]+[1e9] , A[m:r]+[1e9]
    i=j=0
    for k in range(l,r):
        if L[i]<R[j]:
            A[k]=L[i]
            i+=1
            c+=j
        else:
            A[k]=R[j]
            j+=1
def s(A,l,r):
    if l+1<r:
        m=(l+r)//2
        s(A,l,m)
        s(A,m,r)
        g(A,l,m,r)
c=0
n=int(input())
A=list(map(int,input().split()))
s(A,0,n)
print(c)


Measured memory_bytes: 27484
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define ALL(x) x.begin(),x.end()





void solve(){
  int x, y, a, b, c; cin >> x >> y >> a >> b >> c;
  vector<ll> p(a), q(b), pqr(x+y+c);
  FOR(i,0,a) cin >> p[i];
  FOR(i,0,b) cin >> q[i];
  sort(ALL(p));
  sort(ALL(q));
  reverse(ALL(p));
  reverse(ALL(q));
  FOR(i,0,x) pqr[i] = p[i];
  FOR(i,0,y) pqr[x+i] = q[i];
  FOR(i,0,c) cin >> pqr[x+y+i];
  sort(ALL(pqr));
  reverse(ALL(pqr));
  ll ans = 0;
  FOR(i,0,x+y){
    ans += pqr[i];
  }
  cout << ans << endl;
}

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

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

template <class T> using V = vector<T>;

using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;


#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;


ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}


ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}


ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}


/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/


signed main() {
  ll n;
  	ci(n)
  co(n/3)
}

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

int main() {
    int n, m, s, c, ans = 0;
    cin >> n >> m;
    vector<int> number(n, -1);
    bool flag = true;
    rep(i, m) {
        cin >> s >> c;
        if(number.at(s - 1) == -1) number.at(s - 1) = c;
        else if(number.at(s - 1) != c) flag = false;
    }
    if(n != 1 && number.at(0) == 0) flag = false;
    if(n != 1 && number.at(0) == -1) number.at(0) = 1;
    if(flag) {
        rep(i, n) {
            if(number.at(i) == -1) number.at(i) = 0;
            ans = 10 * ans + number.at(i);
        }
    } else {
        ans = -1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>

#include<cstdio>

#include<cstring>

#include<string>

#include<stack>

#include<queue>

#include<set>

#include<map>

#include<vector>

#include<list>

#include<cmath>

#include<algorithm>

#include<bitset>

#define lson node<<1,st,mid

#define rson node<<1|1,mid+1,ed

#define mem(a,x) memset(a,x,sizeof(a))

#define me(a) memset(a,0,sizeof(a))

#define IOS ios::sync_with_stdio(false)

#define lowbit(x) x&(-x)

#define up(i,x,y) for(long long i=x;i<y;i++)

#define down(i,x,y) for(long long i=x;i>=y;i--)

#define in freopen("in.txt","r",stdin)

#define out freopen("out.txt","w",stdout)   

typedef long long ll;

typedef unsigned long long ull;

const ll mod = 1e9+7;

const ll INF = 0x3f3f3f3f;

const ll maxn = 5e5 + 5;

const ll N=1e3+5;

const double pi = acos(-1.0);

const double eps=1e-9;

using namespace std;

ll a[maxn];

ll n,k;

int check(ll x)

{

    if(x==0)    return 0;

    ll js=0;

    for(int i=0;i<n;i++)

    {

        js+=a[i]/x;

        if(a[i]%x==0)   js--;

        if(js>k) return 0;

    }

    return 1;

}

int main()

{

    

    cin>>n>>k;

    for(ll i=0;i<n;i++)

        cin>>a[i];

    

    ll l=1,r=1e9+5;

    ll ans;

    while(l<=r)

    {

        ll mid=(l+r)/2;

        if(check(mid))

        {

            ans=mid;

            r=mid-1;

        }

        else    l=mid+1;

    }

    cout<<ans<<endl;

}

 

Measured memory_bytes: 4676
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

bool check(char *field, int start, int end) {
    bool able = true;
    bool flag = false;
    for (int i=start; i<=end; i++) {
        if (field[i] == '#') {
            if (flag) {
                able = false;
                break;
            }
            else {
                flag = true;
            }
        }
        else {
            flag = false;
        }
    }
    return able;
}

int main() {
    int n = 0, a = 0, b = 0, c = 0, d = 0;
    scanf("%d %d %d %d %d\n", &n, &a, &b, &c, &d);
    a--;
    b--;
    c--;
    d--;
    char *field = (char *)malloc(sizeof(char)*n);
    for (int i=0; i<n; i++) {
        field[i] = getchar();
    }
    bool able = true;
    bool flag = false;
    int dist = (c > d) ? c : d;
    able = check(field, a, dist);
    if (!able) {
        printf("No\n");
        return 0;
    }
    if (d < c) {
        int count = 0;
        bool change = false;
        for (int i=b-1; i<=d+1; i++) {
            if (field[i] == '#') {
                count = 0;
            }
            else {
                count++;
                if (count >= 3) {
                    change = true;
                    break;
                }
            }
        }
        if (!change) able = false;
    }
    if (able) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
    free(field);
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto si : s) os << si << " "; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += (b % mod + mod)) %= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12);
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    string s;
    cin >> s;
    if (s[sz(s) - 1] == 's') s += "es";
    else s += 's';
    cout << s << endl;
}


Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
#include <functional>
#include <queue>
#include <utility>
#include <string>

using namespace std;

using field = vector<string>;
using pos = pair<int, int>;

pos move(pos &current, int direction) {
    switch (direction) {
        case 0:
            return pos(current.first, current.second + 1);
        case 1:
            return pos(current.first, current.second - 1);
        case 2:
            return pos(current.first + 1, current.second);
        case 3:
            return pos(current.first - 1, current.second);
    }
}

int solve(field &f, int H, int W) {
    int history[50][50] = {};

    queue<pos> q;
    q.push(pos(0, 0));

    while (!q.empty()) {
        pos current = q.front();
        q.pop();

        for (int dir = 0; dir < 4; dir++) {
            pos next = move(current, dir);
            int cost = history[current.first][current.second] + 1;
            int r = next.first;
            int c = next.second;
            if (r < 0 || c < 0 || r >= H || c >= W || f[r][c] == '#' || history[r][c] > 0) continue;
            else if (r == H - 1 && c == W - 1) return cost;
            else {
                history[r][c] = cost;
                q.push(next);
            }
        }
    }
    return -1;
}

int main() {
    int H, W;
    cin >> H >> W;

    field f(H);
    int init = 0;
    for (int i = 0; i < H; i++) {
        cin >> f[i];
        for (int j = 0; j < W; j++)
            if (f[i][j] == '#') init += 1;
    }

    int res = solve(f, H, W);

    if (res < 0)
        printf("-1\n");
    else
        printf("%i\n", H * W - (res + 1) - init);

    return 0;
}


Measured memory_bytes: 256