akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main ()
{
  int N = 0;
  cin >> N;
  std::map<string,int> mymap;
  for (int i = 0; i < N; i++) {
    string S = "";
    cin >> S;
    if ( mymap.find(S) == mymap.end() ) {
    	mymap[S] = 1;
    } else {
      mymap[S]++;
    }
  }
  using pair_type = decltype(mymap)::value_type;
  auto max = max_element
  (
    begin(mymap), end(mymap),
    [] (const pair_type & p1, const pair_type & p2) {
      return p1.second < p2.second;
    }
  );
  for (auto &i : mymap) {
    if (i.second == max->second) {
    	cout << i.first << endl;
    }
  }
}

Measured memory_bytes: 25216
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;

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

int main() {
  long long n, sum = 0;
  cin >> n;
  for(int i = 1; i <= n; ++i)
     for(int j = 1; j <= n; ++j)
        for(int x = 1; x <= n; ++x){
          long long g = gcd(i, gcd(j, x));
          sum += g;
        }
  cout << sum;
}

Measured memory_bytes: 3596
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   
#include <bitset>
//#include <boost/math/common_factor_rt.hpp>

#define ll long long
int L = 1000000007;
using namespace std;
ll num[100050];

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

	for (int i = 0; i < n; i++)
	{
		int a, b;
		cin >> a >> b;
		num[a] += b;
	}

	for (int i = 1; i <= 100000; ++i)
	{
		if (k <= num[i]) {
			cout << i << endl;
			return 0;
		}
		k -= num[i];
	}
}

int dsum(ll a) {
	int ans = 0;
	while (a != 0) {
		ans += a % 10;
		a /= 10;
	}
	return ans;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int n = scanner.nextInt();
        int t = scanner.nextInt();
        int cst = 0;
        int tmp1=0;
        int tmp2=0;
        for (int i = 0;i<n;i++) {

        	tmp1 = scanner.nextInt();
        	tmp2 = scanner.nextInt();
        	if(tmp2<=t) {
        		if(cst==0) {
        			cst=tmp1;
        		}else {
        			if(tmp1<=cst) {
        				cst=tmp1;
        			}
        		}
        	}
        }
        if(cst!=0) {
        	System.out.println(cst);
        }else {
        	System.out.println("TLE");
        }

    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

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

  int result=0;
  rep(i,n){
    if((i+1)%2==0)continue;

    int count=0;
    rep(j,i+1){
      if((i+1)%(j+1)==0)count++;
    }
    if(count==8)result++;
//    if(count==8)cout<<i+1<<endl;
  }

  cout<<result;
  return 0;
}

Measured memory_bytes: 256
N = gets.to_i
ab = N.times.map { gets.split.map(&:to_i) }
cd = N.times.map { gets.split.map(&:to_i) }.sort { |a, b| a[0] == b[0] ? a[1] <=> b[1] : a[0] <=> b[0] }
ans = 0
cd.each do |s|
  xx = ab.select { 
      |v| v[0] < s[0] && v[1] < s[1] 
    }.sort{|a, b|
        a[1] == b[1] ? a[0] <=> b[0] : a[1] <=> b[1]
    }.reverse
  next if xx.length == 0
  ans += 1
  ab.delete(xx[0])
end
puts ans


Measured memory_bytes: 1916
#include <iostream>
#include <math.h>
#include <string>    // useful for reading and writing
#include <fstream>   // ifstream, ofstream
#include <sstream>   // istringstream

using namespace std;

int main()
{
    double r;
    cin >> r;
    printf("%.6f %.6f \n",M_PI*r*r,2*M_PI*r);
    return 0;
}


Measured memory_bytes: 3208
import collections

n = int(input())
v = [int(i) for i in input().split()]

ans = 0
gu = v[::2]
ki = v[1::2]

gudic = collections.Counter(gu)
kidic = collections.Counter(ki)

gumax = gudic.most_common()
kimax = kidic.most_common()



if gumax[0][0] != kimax[0][0]:
    print(n - gumax[0][1] - kimax[0][1])
else:
    if len(gumax) == 1 and len(kimax) == 1:
        print(n // 2)
    elif len(gumax) == 1 and len(kimax) >= 2:
        print(n - gumax[0][1] - kimax[1][1])
    
    elif len(gumax) >= 2 and len(kimax) == 1:
        print(n - gumax[1][1] - kimax[0][1])
    else: 
        one = n - gumax[0][1] - kimax[1][1]
        ano = n - gumax[1][1] - kimax[0][1]
        print(min(one, ano))

Measured memory_bytes: 21952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    ll A = in<ll>(),B = in<ll>();
    int amix = sqrt(A);
    int bmix = sqrt(B);
    vector<ll> As(0);
    vector<ll> Bs(0);
    for(int i = 2;i < amix+2;){
        if(i == amix+1 && A != 1)As.pb(A);
        if(A % i == 0){
            As.pb(i);
            A/=(i);
        }else{
            i++;
        }
    }
    for(int i = 2;i < bmix+2;){
        if(i == bmix+1 && B != 1)Bs.pb(B);
        if(B % i == 0){
            Bs.pb(i);
            B/=(i);
        }else{
            i++;
        }
    }
    sort(ALL(As));
    sort(ALL(Bs));
    UNIQUE(As);
    UNIQUE(Bs);
    vector<ll> list(0);
    set_intersection(ALL(As),ALL(Bs),back_inserter(list));
    cout << list.size() +1  << "\n";
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> Pi;
typedef pair<P,Pi> Pii;
int H,W;
char mas[22][22];
string pat;
int ax,ay,bx,by;
int dx[] = {0,1,-1,0,0};
int dy[] = {0,0,0,-1,1};

int solved(){
  bool used[10][20][20][20][20];
  memset(used,false,sizeof(used));
  queue<Pii> que;
  int len = pat.size();
  que.push(Pii(P(0,0),Pi(P(ax,ay),P(bx,by))));
  used[0][ax][ay][bx][by] = true;
  while(!que.empty()){
    Pii p = que.front(); que.pop();
    int cnt = p.first.first;
    int idx = p.first.second;
    int Ax = p.second.first.first;
    int Ay = p.second.first.second;
    int Bx = p.second.second.first;
    int By = p.second.second.second;
    if(Ax == Bx && Ay == By) {
      cout << cnt << " " << Ay << " " << Ax << endl;
      return 1;
    }
    int nBx = Bx;
    int nBy = By;
    if(pat[idx] == '8') nBy = max(0,nBy-1);
    else if(pat[idx] == '6') nBx = min(W-1,nBx+1);
    else if(pat[idx] == '4') nBx = max(0,nBx-1);
    else if(pat[idx] == '2') nBy = min(H-1,nBy+1);
    for(int i=0;i<5;i++){
      int nAx = Ax+dx[i];
      int nAy = Ay+dy[i];
      if(nAx >= W || nAx < 0) nAx = Ax;
      if(nAy >= H || nAy < 0) nAy = Ay;
      if(mas[nAy][nAx] != '#'){
	int next = (idx+1)%len;
	if(used[next][nAx][nAy][nBx][nBy] == false){
	  used[next][nAx][nAy][nBx][nBy] = true;
	  que.push(Pii(P(cnt+1,next),Pi(P(nAx,nAy),P(nBx,nBy))));
	}	
      }
    }
  }
  return 0;
}

int main(){
  while(1){
    cin >> H >> W;
    if(H == 0 && W == 0) break;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	cin >> mas[i][j];
	if(mas[i][j] == 'A'){
	  ax = j;
	  ay = i;
	}
	if(mas[i][j] == 'B'){
	  bx = j;
	  by = i;
	}
      }
    }
    cin >> pat;
    if(solved() == 0){
      cout << "impossible" << endl;
    }
  }
}

Measured memory_bytes: 2800
#include <bits/stdc++.h>
 
using namespace std;
 
vector<string> v;
char buf[5002];
int main(){
    scanf("%s",buf);
    string s=buf;
    for(int i=0;i<s.size();i++){
        for(int j=i;j<s.size()&&j<i+7;j++){
            v.push_back(s.substr(i,j-i+1));
        }
    }
    sort(v.begin(),v.end());
    int k;
    cin>>k;
    k--;
    v.erase(unique(v.begin(),v.end()),v.end());
    printf("%s\n",v[k].c_str());
    return 0;
}

Measured memory_bytes: 2300
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		
		
		Scanner scan = new Scanner(System.in);
		int[] array1 = new int[scan.nextInt()];
		for(int i=0; i<array1.length; i++) {
			array1[i]=scan.nextInt();
		}
		int[] array2 = new int[scan.nextInt()];
		for(int i=0; i<array2.length; i++) {
			array2[i]=scan.nextInt();
		}
		
		int output = 0;
		HashMap<Integer, Integer> a1Map = new HashMap<Integer, Integer>();
		for(int i = 0; i<array1.length; i++) {
			a1Map.put(array1[i],0);
		}
		
		for(int i = 0; i<array2.length; i++) {
			if(a1Map.containsKey(array2[i])) {
				if(a1Map.get(array2[i])==0) {
					a1Map.replace(array2[i],0);
					output++;
				}
			}
		}
		System.out.println(output);
		
		
	}
}


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

using namespace std;

const int maxn=105;

#define eps (1e-10)
struct point{
    double x,y;
    point(){}
    point(double x,double y):x(x),y(y){}
    point operator - (point p){
        return point(x-p.x,y-p.y);
    }
};

typedef vector<point>polygon;

double dot(point a,point b)
{
    return a.x*b.x+a.y*b.y;
}
double cross(point a,point b)
{
    return a.x*b.y-a.y*b.x;
}

int contains(polygon g,point p)
{
    int n=g.size();
    bool x=false;
    for(int i=0;i<n;i++){
        point a=g[i]-p,b=g[(i+1)%n]-p;
        if(abs(cross(a,b))<eps&&dot(a,b)<eps){
            return 1;
        }
        if(a.y>b.y){
            swap(a,b);
        }
        if(a.y<eps&&b.y>eps&&cross(a,b)>eps){
            x=!x;
        }
    }
    return (x?2:0);
}

int main()
{
    int n;
    cin>>n;
    polygon s;
    point temp;
    for(int i=0;i<n;i++){
        cin>>temp.x>>temp.y;
        s.push_back(temp);
    }
    int q;
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>temp.x>>temp.y;
        int res=contains(s,temp);
        cout<<res<<endl;
    }
    return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<int> lst(N);
  for (int i = 1; i <= N; i++) {
    int A;
    cin >> A;
    lst.at(A-1) = i;
  }
  for (int i = 0; i < N-1; i++) cout << lst.at(i) << " ";
  cout << lst.at(N-1) << endl;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

	int a, b, c;
	cin >> a >> b >> c;

	if (a + b >= c) co("Yes");
	else co("No");
	Would you please return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
int main(){
  int N,a=0;
  string S;
  cin>>N;
  for(int i=1;i<=N;i++){
    cin>>S;
    if(S=="Y"){
      a++;
      break;
    }
  }
  if(a==0)cout<<"Three"<<endl;
  else cout<<"Four"<<endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

#include <climits>
#include <cmath>
#include <cstring>

#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;


int main()
{
	FAST;
	int n,m;
	cin >> n >> m;
	
	int arr[n];
	vector<pair<int,int> > a(m);
	
	for(int i=0 ; i<n ; i++)
	    cin >> arr[i];
	    
	for(int i=0 ; i<m ; i++)
	    cin >> a[i].second >> a[i].first;
	    
	sort(a.begin() , a.end());
	reverse(a.begin() , a.end());
	sort(arr , arr+n , greater<int>());
	
	ll ans = 0;
	int i=0;
	int j=0;
	int c=0;
	while(c < n)
    {
        if(a[j].first >= arr[i] && j < m)
        {
            while(a[j].second--)
            {
                ans += a[j].first;
                c++;
                if(c >= n)   break;
            }
            j++;
        }
        else
        {
            ans += arr[i];
            i++;
            c++;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1408
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

Price = list(map(int, input().split()))
Volume = [0.25, 0.5, 1, 2]
Pper = [p/v for (p, v) in zip(Price, Volume)]
N = int(input())

ans = 0
n = Pper.index(min(Pper))
if n != 3:
    ans = int(N/Volume[n]) * Price[n]
else:
    ans = N//2 * Price[3]
    m = Pper.index(min(Pper[:3]))
    nokori = N % 2
    ans += int(nokori/Volume[m]) * Price[m]

print(ans)


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

using namespace std;

int N, M;
vector<int> A, B;
vector<vector<bool>> G;

vector<bool> used;

void dfs(int u) {
  used[u] = true;
  for (int v = 0; v < N; v++) {
    if (!G[u][v]) continue;
    if (used[v]) continue;
    dfs(v);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  A.resize(M), B.resize(M), G.resize(N, vector<bool>(N, false));
  used.resize(N, false);
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
    A[i]--, B[i]--;
    G[A[i]][B[i]] = G[B[i]][A[i]] = true;
  }
  int res = 0;
  for (int i = 0; i < M; i++) {
    G[A[i]][B[i]] = G[B[i]][A[i]] = false;
    used.assign(N, false);
    dfs(0);
    for (int i = 0; i < N; i++) {
      if (!used[i]) {
        res++;
        break;
      }
    }
    G[A[i]][B[i]] = G[B[i]][A[i]] = true;
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <limits>
#include <string>
#include <bitset>
#include <functional>
#include <iomanip>

using namespace std;
using lint = long long;
using vi = vector<int>;
using vl = vector<int>;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
using pqi = priority_queue<int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
#define mp(x, y) make_pair((x), (y))
#define all(x) (x).begin(), (x).end()
#define foreach(it, x) for (auto it = (x).begin(); it != (x).end(); it++)
#define space (char)0x20

constexpr lint MOD = 1e9 + 7;
double A, B, C, D, E, F, G, H, I, J, K, L, M, N;
int O, P, Q, R, S, T, U, V, W, X, Y, Z;
// string s;

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

	cin >> N >> K;
    vector<double> dice(N);
    rep(i, N) {
        cin >> F;
        dice[i] = (double)((1 + F) / 2);
    }

    double ans = 0;
    double tmp = 0;
    rep(i, K) {
        tmp += dice[i];
    }
    ans = tmp;
    rep2(i, K, N) {
        tmp -= dice[i-K]; 
        tmp += dice[i];
        ans = max(ans, tmp);
    }

    cout << setprecision(20) << ans << endl;
	return 0;
}

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

int main(void){
	int n;
	cin>>n;
	int a;
	map<int,int> c;
	
	int b[3]={-1,-1,-1};
	for(int i=0;i<n;i++){
		cin>>a;
		c[a]++;
		if(c[a]==1){
			if(b[0]==-1){
				b[0]=a;
			}else if(b[1]==-1){
				b[1]=a;
			}else if(b[2]==-1){
				b[2]=a;
			}
		}
	}
	bool flg=true;
	if(n%3!=0){flg=false;}
		
	if(c[b[0]]!=n/3||c[b[1]]!=n/3||c[b[2]]!=n/3){
			flg=false;
	}
	
	if(c[0]==n){
		cout<<"Yes";
	}else if(c[0]==(n/3)&&b[0]^b[1]!=0&&c[b[2]]==0&&n%3==0){
		cout<<"Yes";
	}else if(((b[0]^b[1])==b[2])&&(b[0]!=b[1])&&(b[0]!=b[2])&&(b[1]!=b[2])&&flg){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
	
}

Measured memory_bytes: 3840
N,X,M = map(int,input().split())
c1 = [X]
c2 = {X}
ans = X
for i in range(N-1):
    X = pow(X,2,M)
#    print(X)
    if X not in c2:
        c1.append(X)
        c2.add(X)
        ans += X
    else:
        b = c1.index(X)
        break
else:
    print(ans)
    exit()
l = len(c1) - b
t = N-i -1
ans += (t//l) * sum(c1[b:]) + sum(c1[b:b+t%l])
print(ans)

Measured memory_bytes: 12948
//In the name of God!
#include <bits/stdc++.h>

const int maxn = 100 + 12;
using namespace std;

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int n, b, pre = 1e5 + 12;
    long long ans = 0;
    cin >> n;
    for(int i = 0; i < n - 1; i++){
        cin >> b;
        ans += min(pre, b);
        pre = b;
    }
    cout << ans + b;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define eps 1e-9
#define MOD 998244353
#define INV_10 299473306
#define INF 1000000000
#define PI 3.14159265358979323846
using namespace std;
vector<int>v[100005];
int ans[100005];
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < m; i++)
	{
		int x, y;
		cin >> x >> y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	vector<int>bfs;
	bfs.push_back(1);
	int idx=0;
	while(true)
	{
		int l = bfs.size();
		for(int i = idx; i < l; i++)
		{
			for(int j = 0; j < v[bfs[i]].size(); j++)
			{
				if(!ans[v[bfs[i]][j]])
				{
					ans[v[bfs[i]][j]]=bfs[i];
					bfs.push_back(v[bfs[i]][j]);
				}
			}
		}
		if(l==bfs.size())
		{
			cout << "Yes\n";
			for(int i = 2; i <= n; i++)
				cout << ans[i] << '\n'; 
			return 0;
		}
		idx=l;
	}

}

Measured memory_bytes: 10564
/*Rabbi Zidni Ilma*/
 
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define scl(n) scanf("%lld",&n)
#define scll(n,m) scanf("%lld %lld",&n,&m)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define mod 1000000007
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)

ll pow(ll b,ll p)
{
	ll res=1;
	for(ll i=1;i<=p;i++)
	res=((res%mod)*(b%mod))%mod;
	
	return res%mod;
}
 
int main()
{
   ll n,i,ans;
   scl(n);
   ans=pow(10ll,n)-2*pow(9ll,n)+pow(8ll,n);
   while(ans<0)
   ans=(ans+mod)%mod;
   printf("%lld\n",ans);
}

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

int main() {
    ull N;
    cin >> N;

    ull a1, a2;
    for (ull i=1; i*i<=N; i++) {
        if (N%i==0){
            a1 = i; a2 = N/i;
        }
    }

    cout << (a1 - 1) + (a2 - 1) << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>

#define nl '\n'

using namespace std;

int n, t;
string x;
char c;
bool b;

int main(){
    cin >> n;

    set<string> s;
    vector<string> v;

    for(int i = 0; i < n; i++){
        cin >> x;
        t = s.size();
        s.insert(x);
        v.push_back(x);
        if(s.size() == t){
            cout << "No";
            return 0;
        }
    }

    c = v[0][v[0].length()-1];
    for(int i = 1; i < v.size(); i++){
        if(v[i][0] == c){
            c = v[i][v[i].length()-1];
        } else{
            cout << "No";
            return 0;
        }
    }

    cout << "Yes";


}

//g++ -std=c++14 comp.cpp -o b; ./b.exe

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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 998244353;

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

  LL n;
  cin >> n;
  vector<LL> v(n);
  REP(i,n){
    cin >> v[i];
  }
  LL sum = 0;
  REP(i,n){
    LL a;
    cin>>a;
    v[i] -= a;
    if(v[i]>0){
      sum += v[i];
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var [a,b,c,k] = nexts(4);
  var cnt = 0;
  while(a >= b)b *= 2, cnt++;
  while(b >= c)c *= 2, cnt++;
  return cnt <= k ? "Yes" : "No";
}

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

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

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

	int n; cin>>n;
	vector<int> a(n + 1), b(n);
	for(auto &x : a){
		cin>>x;
	}
	for(auto &x : b){
		cin>>x;
	}
	ll ans = 0;
	for(int i = 0; i < n; i++){
		if(b[i] <= a[i]){
			ans += b[i];
		}else{
			ans += a[i]; b[i] -= a[i];
			int tmp = min(b[i], a[i + 1]);
			ans += tmp;
			a[i + 1] -= tmp;
		}
	}
	cout<<ans<<endl;

	return 0;
}

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

int gcd(long long a, long long b){
  long long M = max(a, b), m = min(a, b);
  while(m != 0){
  	long long r = M%m;
    M = m; m = r;
  }
  return M;
}

int digit_sum(long long n){
  long long ans;
  while(n != 0){
  	ans += n%10;
  	n /= 10;
  }
  return ans;
}

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

Measured memory_bytes: 256
from fractions import gcd

N, M = map(int, input().split())
A = list(map(int, input().split()))

gcd_n = A[0]
for a in A:
    gcd_n = gcd(gcd_n, a)

for a in A:
    if (a // gcd_n) % 2 == 0:
        print(0)
        exit()

lcm_n = 1
for a in A:
    lcm_n = (lcm_n * a // 2) // gcd(lcm_n, a // 2)

print(((M // lcm_n) + 1) // 2)


Measured memory_bytes: 16316
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long

signed main()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

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

    unordered_map<string,int> m;
    int t;
    cin>>t;
    std::vector<int> v(t);
    for (auto &it:v)
        cin>>it;
    sort(v.begin(),v.end(),greater<int>());
    int ans=0;
    if (t>=2)
        ans+=v[0];
    int j=1;
    int count=0;
    for (int i=2;i<t;++i)
    {
        ans+=v[j];
        ++count;
        if (count%2==0)
            j++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4724
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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,b,c;
  cin >> a >> b >> c;

  cout << max({a*10+b+c,b*10+a+c,c*10+a+b}) << endl;

}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner scan = new Scanner(System.in);

        int a = scan.nextInt();
        int b = scan.nextInt();
        int h = scan.nextInt();

        System.out.println(String.valueOf((a+b)*h/2));


    }
}


Measured memory_bytes: 20820
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

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

int main(void){
  int n;
  while(cin>>n){
    if(n==0) break;
    int c[10]={};
    REP(i,n){
      int tmp;
      cin>>tmp;
      c[tmp]++;
    }
    REP(i,10){
      if(c[i]==0){
        putchar('-');
      }else{
        REP(j,c[i])putchar('*');
      }
      putchar('\n');
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int n;cin >> n;
    vector<double> v(n);
    rep(i,n) cin >> v[i];
    sort(v.begin(),v.end());
    while (v.size()>1){
        v[1]=(v[0]+v[1])/2;
        v.erase(v.begin());
    }
    cout << v[0] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>P;
vector<P>vec;
vector<int>s;

int main(){
  int n,m;
  int a[100009];
  cin>>n>>m;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<m;i++){
    int b,c;
    cin>>b>>c;
    vec.push_back(P(c,b));
  }
  sort(a,a+n);
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  for(int i=0;i<m;i++){
    int c=vec[i].first;
    int b=vec[i].second;
    for(int j=0;j<b;j++){
      s.push_back(c);
    }
    if(s.size()>n)break;
  }
  long long ans=0;
  for(int k=0;k<n;k++){
    if(k>=s.size()){
      ans+=a[k];
    }
    else{
      ans+=max(a[k],s[k]);
    }
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 2932
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;


vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res.push_back(N/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;
}


signed main() {
    ll a, b, k;
    cin >> a >> b >> k;
    
    ll t = k;
    for(ll i=min(a, b); i > 0; i--) {
        if (a % i == 0 && b % i == 0) t--;
        if (t == 0) {
            mes(i);
            re0;
        }
    }
    
    

    
    
    
    
    
    
    
    
}

Measured memory_bytes: 3596
#include<stdio.h>
const int maxn = 100005;

int main(){
//	freopen("b.txt","r",stdin);
	int a=0,b=0,c=0,n,x;
	scanf("%d", &n);
	for(int i=0;i<n;i++){
		scanf("%d", &x);
		if(x%4==0){
			c++;
		}else if(x%2==0){
			b++;
		}else{
			a++;
		}
	}
	if(b==0){
		if(a-1>c){
			printf("No\n");
		}else{
			printf("Yes\n");
		}
	}else{
		if(a>c){
			printf("No\n");
		}else{
			printf("Yes\n");
		}
	}

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cmath>
typedef long long ll;
using namespace std;
ll p[100005];
string s[100005];
ll kai[100005];
ll kai2[100005];
int main() {
	ll n, m;
	cin >> n >> m;
	
	for (int i = 0; i < m; i++) {
		cin >> p[i] >> s[i];
	}
	ll count = 0;
	ll pena = 0;
	
	for (int i = 0; i < n; i++) {
		kai[i] = 0;
		kai2[i] = 0;
	}
	for (int i = 0; i < m; i++) {
		if (s[i] == "AC") {
			kai[p[i]-1] = 1;
			
		}
		else {
			if (kai[p[i] - 1] != 1) {
				kai2[p[i]-1] += 1;
			}
		}
	}

	for (int i = 0; i < n; i++) {
		if (kai[i] == 1) {
			count++;
		}
		if (kai[i] == 1) {
			pena += kai2[i];
		}
	}
	cout << count <<" "<<pena<< endl;
	return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>w(n); cin>>w.front();
	for(int i=1;i<n;++i){
		cin>>w.at(i);
		w.at(i)+=w.at(i-1);
	}
	int ans=1e9;
	for(int i=0;i<n;++i){
		ans=min(ans,abs(w.back()-w.at(i)*2));
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,x,y;
    cin>>n>>k>>x>>y;
    if(n<=k)
    {
        cout<<x*n;
    }
    else
    {
        cout<<(x*k)+(y*(n-k));
    }

return 0;

}


Measured memory_bytes: 3636
#include<cstdio>
const int MAXN = 100000;
int abs(int x) {
	return x < 0 ? -x : x;
}
int gcd(int x, int y) {
	return y == 0 ? x : gcd(y, x%y);
}
int main() {
	int N, X, x, ans = -1;
	scanf("%d%d", &N, &X);
	for(int i=1;i<=N;i++) {
		scanf("%d", &x);
		if( ans == -1 ) ans = abs(x-X);
		else ans = gcd(ans, abs(x-X));
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 128
#include <cstdio>
const int maxn=200005;
int n,a[maxn],b[maxn];
int check(int mid) {
    for (int i=0;i<n;++i)
        b[i]=mid>=a[i];
    for (int i=0;i<n/2;++i) {
        if (b[n/2+i]==b[n/2+i+1])
            return b[n/2+i];
        if (b[n/2-i]==b[n/2-i-1])
            return b[n/2-i];
    }
    return b[0];
}
int main()
{
    scanf("%d",&n);
    n=(n<<1)-1;
    for (int i=0;i<n;++i)
        scanf("%d",&a[i]);
    int left=0,right=0x3f3f3f3f,res=-1;
    while (left<=right) {
        int mid=(left+right)>>1;
        if (check(mid)) {
            res=mid;
            right=mid-1;
        } else
            left=mid+1;
    }
    printf("%d\n",res);
    return 0;
}

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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

const int di[]={-1,-1,-1,0,0,1,1,1};
const int dj[]={-1,0,1,-1,1,-1,0,1};

vs update(vs a)
{
	int n=a.size();
	vs b(n,string(n,'.'));
	rep(i,n) rep(j,n){
		if(a[i][j]=='@'){
			b[i][j]='@';
			continue;
		}
		int cnt=0;
		rep(k,8){
			int ni=i+di[k],nj=j+dj[k];
			if(0<=ni && ni<n && 0<=nj && nj<n && a[ni][nj]!='.')
				cnt++;
		}
		if(a[i][j]=='#' && (cnt==2 || cnt==3) || a[i][j]=='.' && cnt==3)
			b[i][j]='#';
	}
	return b;
}

int main()
{
	for(int n;cin>>n && n;){
		vs grid(n);
		rep(i,n) cin>>grid[i];
		
		set<vs> vis;
		queue<pair<vs,int>> q;
		q.emplace(grid,0);
		int res=-1;
		while(q.size()){
			vs cur; int turn;
			tie(cur,turn)=q.front(); q.pop();
			if(vis.count(cur)) continue;
			vis.insert(cur);
			
			int cnt=0;
			rep(i,n) rep(j,n) cnt+=cur[i][j]=='#';
			if(cnt==0){
				res=turn;
				break;
			}
			
			rep(i,n) rep(j,n) if(cur[i][j]=='@') rep(k,8){
				int ni=i+di[k],nj=j+dj[k];
				if(ni<0 || n<=ni || nj<0 || n<=nj || cur[ni][nj]=='#') continue;
				swap(cur[i][j],cur[ni][nj]);
				q.emplace(update(cur),turn+1);
				swap(cur[i][j],cur[ni][nj]);
			}
		}
		cout<<res<<endl;
	}
}

Measured memory_bytes: 7176
//hinagata.cpp
//作成日
//更新日
//目的
//手段
/*includes*/
#include <bits/stdc++.h>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REPi(i,a,b) for(ll i=(a);i<(b);i++)
#define REPRi(i,a,b) for(ll i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

int main(){
    int A,B,C;
    cin>>A>>B>>C;
    if((A!=B&&B==C)||(B!=A&&C==A)||(C!=B&&A==B)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
n,m = gets.split(" ").map(&:to_i)

drink_place = 0
drink_num = 0

shop = []

n.times do |n_c|

  a,b = gets.split(" ").map(&:to_i)
  shop << [a,b]
end

shop.sort!

shop.each do |shop|
  drink_place += (shop[1] * shop[0])
  t = m - (drink_num + shop[1])
  
  if t <= 0
    drink_place += (t * shop[0])
    break
  end

  drink_num += shop[1]

end

puts drink_place


Measured memory_bytes: 10488
#include<bits/stdc++.h>
#define test int t; cin>>t; while(t--)
#define fast ios::sync_with_stdio(false);
typedef long long ll;
using namespace std;
int main()
{
  fast
   int  n;
   cin>>n;
   int a[n];
   int ans=0;
   for(int i=0;i<n;i++)
   {
       cin>>a[i];
       ans^=a[i];
   }
   for(int i=0;i<n;i++)
   {
      int temp=ans^a[i];

      cout<<temp<<" ";
   }
 return 0;
}



Measured memory_bytes: 4364
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int k = s.nextInt();
        int[] a = new int[n];
        for(int i=0; i<k; i++)
        {
            int d = s.nextInt();
            for(int j=0; j<d; j++)
            {
                int x = s.nextInt();
                a[x-1]++;
            }
        }
        int c = 0;
        for(int i=0; i<a.length; i++)
        {
            if(a[i]==0)
                c++;
        }
        System.out.println(c);
    }
}


Measured memory_bytes: 46120
x=int(input())
if 360%x == 0:
    print(int(360/x)) #2 * 2 * 2 * 3 * 3 * 5
else:
    count_2 = 0
    count_3 = 0
    count_5 = 0
    while x % 2 == 0:
        count_2 += 1
        x /= 2
        if count_2 == 3:
            break
    while x % 3 == 0:
        count_3 += 1
        x /= 3
        if count_3 == 2:
            break
    while x % 5 == 0:
        count_5 += 1
        x /= 5
        if count_5 == 1:
            break
    print((2**(3-count_2))*(3**(2-count_3))*(5**(1-count_5)))
        

Measured memory_bytes: 9212
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

int keta(int x){
	int i=0;
	while (x/pow(10,i)>=1){
		i++;
	}
	if (x==0){
		return 1;
	}
	else
	return i;
	}


int main(){
string s;
cin>>s;
int x=s.size();
string a="";
for (int i=1;i<=x;i++){
	a+=s[x-i];
}
cout<<a<<endl;
}

Measured memory_bytes: 1184
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#define FOR(idx, begin, end) for(int idx = (int)(begin); idx < (int)(end); ++idx)

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

using namespace std;
typedef long long lint;

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


int main() {

	cin.tie(0);

	int N, K;
	cin >> N >> K;

	string S;
	cin >> S;

	int cnt = 1;
	vector<int> set1,set0;

	FOR(i, 1, N) {
		if (S[i] == S[i - 1]) {
			cnt++;
		}
		else {
			if (S[i] == '0')	set1.emplace_back(cnt);
			else set0.emplace_back(cnt);
			cnt = 1;
		}
	}
	if (S[N - 1] == '1')	set1.emplace_back(cnt);
	else set0.emplace_back(cnt);

	int ans = 0, tmp = 0,offset = 1;

	if (S[0] == '1') offset = 0;

	cnt = 0;
	if (set0.size() <= K) {
		FOR(i, 0, set1.size()) ans += set1[i];
		FOR(i, 0, set0.size()) ans += set0[i];
	}
	else {
		while (K + cnt <= set0.size()) {
			FOR(i, ((cnt - offset) > 0 ? (cnt - offset) : 0), K + cnt + 1 - offset > set1.size() ? set1.size() : K + cnt + 1 - offset) tmp += set1[i];
			FOR(i, cnt, K + cnt) tmp += set0[i];
			ans = ans > tmp ? ans : tmp;
			tmp = 0;
			cnt++;
		}
	}

	cout << ans;
}


Measured memory_bytes: 1020
import java.util.Scanner;
import java.awt.image.BandedSampleModel;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main{


    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        long x=sc.nextLong();
        long k=sc.nextLong();
        long d=sc.nextLong();
        long ans=0;
        if(x<0)
        {
            long dis=Math.abs(x)/d;
            if(k<=dis)
            {
                ans=Math.abs(x+k*d);
            }
            else
            {
                long moves=k-dis;
                if(moves%2==0)
                {
                    ans=Math.abs(x+dis*d);
                }
                else
                {
                    ans=Math.abs(x+dis*d+d);
                }
               // ans=Math.min(Math.abs(x+dis*d),Math.abs(x+dis*d)+d);
            }
        }
        else if(x>0)
        {
            long dis=Math.abs(x)/d;
            if(k<=dis)
            {
                ans=x-k*d;
            }
            else
            {
                long moves=k-dis;
                if(moves%2==0)
                {
                    ans=Math.abs(x-dis*d);
                }
                else
                {
                    ans=Math.abs(x-dis*d-d);
                }
                //ans=Math.min(Math.abs(x-dis*d),Math.abs(x-dis*d-d));
            }
        }
        else
        {
           // long dis=Math.abs(x)/d;
            if(k%2==0)
            {
                ans=0;
            }
            else
            {
                ans=d;
            }
        }
        System.out.println(Math.abs(ans));
    }
}


Measured memory_bytes: 35772
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int N; cin >> N;
    N++;

    vec s(0);
    while(N > 0){
        int b = N % 2;
        s.push_back(b);
        N = (N - b) / 2;
    }

    int n = s.size();
    vec ans1(n - 1), ans2(0);
    REP(i, n - 1) ans1[i] = i + 1;
    REP(i, n - 1){
        if(s[i] == 1){
            ans1.insert(ans1.begin() + n - 1 - i, 51 + i);
            ans2.push_back(51 + i);
        }
    }
    REP(i, n - 1) ans2.push_back(i + 1);

    cout << ans1.size() + ans2.size() << endl;
    REP(i, ans1.size()) cout << ans1[i] << " ";
    REP(i, ans2.size()) cout << ans2[i] << " ";

    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

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

using namespace std;
using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000007;
const static int IINF = INT_MAX;
const static llong LINF = LLONG_MAX;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

/* --------------- template start --------------- */
template <typename T> 
struct BinaryIndexTree { // [1, n]
    vector<T> array;
    int n;

    BinaryIndexTree(int _n) {
        array.resize(_n + 1, 0);
        n = _n;
    }

    T cumsum(int i) {
        T s = 0;
        while(i > 0) {
            s += array[i];
            i -= i & -i;
        }

        return s;
    }

    T sum(int i, int j) {
        T ret_i = cumsum(i - 1);
        T ret_j = cumsum(j);

        return ret_j - ret_i;
    }

    void add(int i, T x) {
        while (i <= n) {
            array[i] += x;
            i += i & -i;
        }
    }
};

template<typename T>
struct UnionFind {
    vector<int> par;
    vector<T> sz;

    UnionFind(int n) {
        par.resize(n);
        sz.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            sz[i] = 1;
        }
    }

    int find_root(int x) {
        return par[x] == x ? x : par[x] = find_root(par[x]);
    }

    bool same(int x, int y) {
        return find_root(x) == find_root(y);
    }

    void unite(int x, int y) {
        x = find_root(x);
        y = find_root(y);
        if (x == y) return;
        
        if (sz[x] < sz[y]) swap(x, y);
        sz[x] += sz[y];
        par[y] = x;
    }

    T size_of_tree(int x) {
        return sz[find_root(x)];
    }
};
/* --------------- template end --------------- */

/* --------------- function start --------------- */
llong my_gcd(llong a, llong b) {
    return (a ? my_gcd(b % a, a) : b);
}
llong my_lcm(llong a, llong b) {
    return a * b / my_gcd(a, b);    
}

llong facmod(llong n) {
    if (n == 0) return 1;

    llong res = n;
    for (int i = n - 1; i > 0; --i) {
        res = (res * i) % MOD;
    }

    return res;
}
llong powmod(llong a, llong n) {
    llong res = 1;
    while (n > 0) {
        if (n & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        n >>= 1;
    }

    return res;
}
llong modinv(llong n) {
    return powmod(n, MOD - 2);
}
llong combmod(llong n, llong k) {
    llong res = 1;
    for (int i = 0; i < k; ++i) {
        res = (res * (n - i)) % MOD;
    }
    res = (res * modinv(facmod(k))) % MOD;

    return res;
}
/* --------------- function end --------------- */

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

    llong h, w;
    cin >> h >> w;
    if (h == 1 || w == 1) {
      cout << 1 << endl;
      return 0;
    }

    llong ans = ceil((double)h * w / 2LL);
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
import sys
sys.setrecursionlimit(10**8)

def nextLine(): return next(stdin)
def nextStrList(): return nextLine().split()
def nextIntList(): return [int(_) for _ in nextStrList()]


def main():
	k=nextIntList()[0]
	if k<=9:
		print(k)
		sys.exit(0)
	num=[0,1]
	for i in range(10, k):
# 		print(num)
		if all([n==9 for n in num]):
			num=[0 for d in range(len(num))]
			num.append(1)
			continue
		
		for di in range(len(num)):
			if di==0:
				if num[di]<=num[di+1] and num[di]<9:
					num[di]+=1
					break
			elif di<len(num)-1:
				if num[di]<=num[di+1] and num[di]<9 and num[di]<=num[di-1]:
					num[di]+=1
					break
			else: #di==len(num)-1
				num[di]+=1
	
		for dii in range(di-1, -1,-1):
			if num[dii+1]==0:
				num[dii]=0
			else:
				num[dii]=num[dii+1]-1 
	
	print("".join(str(n) for n in reversed(num)))

if __name__=="__main__":
	main()


Measured memory_bytes: 3192