akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


signed main(){
	string s; cin>>s;
	if(s[0]==s[2]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>     // [PRIMES]               1777 ~2^10.80  
using namespace std;                     //                       10333 ~2^13.33
using ll=long long;                      // seq 1 128 | factor   100333 ~2^16.61
using vl=vector<ll>;                     //   | grep -v ' .* '  1300111 ~2^20.31
using vvl=vector<vl>;                    //                    10300777 ~2^23.30
using vb=vector<bool>;                   //                   100400999 ~2^26.58
using vs=vector<string>;                 //                  1300400999 ~2^30.28
using pll=pair<ll,ll>;                   //                 10200500333 ~2^33.25
const ll oo =0x3f3f3f3f3f3f3f3fLL;       //                100200400777 ~2^36.54
const double eps=1e-9;                   //               1200300700111 ~2^40.13
#define sz(c) ll((c).size())             //              10200300500777 ~2^43.21
#define all(c) begin(c),end(c)           //             100200300400777 ~2^46.51
#define mp make_pair                     //            1200300400600999 ~2^50.09
#define mt make_tuple                    //           10200300400600111 ~2^53.18
#define pb push_back                     //          100200300400600333 ~2^56.48
#define eb emplace_back                  //         1200300400500800999 ~2^60.06
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(ll)(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

string a,b;
vvl dp;

ll f(ll ia, ll ib){
    if(ia < 0 || ib < 0) return 0;
    if(dp[ia][ib] != -1) return dp[ia][ib];
    ll res = 0;
    if(a[ia] == b[ib]){
        res = 1;
        res += f(ia-1, ib-1);
    }
    res = max(res, f(ia-1, ib));
    res = max(res, f(ia, ib-1));
    dp[ia][ib] = res;
    return res;
}


int main(){
    cin >> a >> b;
    dp.resize(sz(a), vl(sz(b) ,-1));
    ll x = sz(a)-1;
    ll y = sz(b)-1;
    f(x,y);
    string res;
    while(x >= 0 && y >= 0){
        if(f(x,y) == f(x-1,y-1) +1 && a[x] == b[y]){
            res = res + a[x];
            x--;
            y--;
        } else if(f(x,y) == f(x-1,y)){
            x--;
        } else {
            y--;
        }
    }
    reverse(all(res));
    cout << res << endl;
} //cin.tie(0) bei schnellem Wechseln




Measured memory_bytes: 71040
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int func(){
    int y = in();
    int m = in();
    int d = in();
    method(last_day,int){
        if(y%3==0)return 20;
        if(m%2)return 20;
        return  19;
    };
    method(last_month,int){
        return 10;
    };
    int res = 0;
    while(y<1000){
        ++res;
        if(last_day()==d){
            if(last_month()==m){
                ++y;
                m = 1;
            }else{
                ++m;
            }
            d = 1;
        }else{
            ++d;
        }
    }
    return res;
}

int main(){
    int n = in();
    rep(i,n){
        cout << func() << endl;
    }
  return 0;
}



Measured memory_bytes: 3144
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;
int main() {
	string s;
	cin >> s;
	long long t=0;
	int i=0;
	while (s[i]) {
		t++;
		i++;
	}
	cout << s[0] << t-2 << s[t - 1];

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    int one = 0;
    int two = 0;
    int four = 0;
    rep(i, N) {
        if (a[i] % 4 == 0) four += 1;
        else if (a[i] % 2 == 0) two += 1;
        else one += 1;
    }
    if (two == 0) {
        if (four + 1 >= one && (1 <= four || one == 0)) cout << "Yes" << endl;
        else cout << "No" << endl;
    } else {
        if (four >= one) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 768
import sys
input = sys.stdin.readline

s = input().split()[0]
q = int(input())

left, right = [], []
state = 1
for _ in range(q):
    q_i = input().split()
    if len(q_i) == 1:
        state = (state)%2 + 1
    else:
        _, f, c = q_i
        f = int(f)
        if (f+state)%2 == 0:
            left += [c]
        else:
            right += [c]
if state == 1:
    print(''.join(left[::-1]) + s + ''.join(right))
else:
    print(''.join(right[::-1]) + s[::-1] + ''.join(left))

Measured memory_bytes: 63324
import numpy as np
N, x = map(int, input().split())
a = np.array(list(map(int, input().split())))
b = np.copy(a)
ans = float('inf') 
for i in range(N):
    c = np.roll(a,i)
    b = np.minimum(b,c)
    ans = min(ans, sum(b)+i*x)
print(ans)


Measured memory_bytes: 12508
#include<stdio.h>
#define N 100001

int n,A[N];

int Patition(int , int);

main(){

  int i,index;

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }

  index = Partition(0, n-1);
  
 for(i = 0; i < n; i++){
   if(i == index){
     printf("[%d] ",A[i]);
   } else if(i == n-1){
     printf("%d\n",A[i]);
   } else {
     printf("%d ",A[i]);
   }
 }
   return 0;
  
}

int Partition(int p, int num){

  int x,i,j,temp;

   x = A[num];
   i = p - 1;
 
  for(j = 0; j < num; j++){

     if(A[j] <= x){
       i = i + 1;
       temp = A[j];
       A[j] = A[i];
       A[i] = temp;
     }
 
  }

  temp =  A[num];
  A[num] =  A[i+1];
  A[i+1] =  temp;

  //  printf("%d\n",i+1);

  return i+1;

}

Measured memory_bytes: 796
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<queue>
#include<functional>
#include<numeric>
#include<unordered_map>

using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	unordered_map<int, int> cnt;
	cnt[0]++;
	int a, preva = 0;	
	long long ans = 0;
	for(int i=1;i<=n;i++){
		cin >> a;
		a += preva;
		a %= m;
		ans += cnt[a];
		cnt[a] ++;
		preva = a;
	}

	cout << ans << endl;
	return 0;
}

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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
const ll INF = LLONG_MAX / 2;
const ll MOD = 1e9 + 7;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int H, W;
    cin >> H >> W;
    int A[H][W], B[H][W];
    for(int i = 0; i < H; i++)
        for(int j = 0; j < W; j++)
            cin >> A[i][j];
    for(int i = 0; i < H; i++)
        for(int j = 0; j < W; j++)
            cin >> B[i][j];
    const int MAX_SUM = 80 * (80 + 80) + 10;
    bitset<MAX_SUM> dp[H + 1][W + 1];
    dp[0][1][0] = true;
    dp[1][0][0] = true;
    for(int i = 1; i <= H; i++) {
        for(int j = 1; j <= W; j++) {
            int dif = abs(A[i - 1][j - 1] - B[i - 1][j - 1]);
            for(int k = 0; k < MAX_SUM; k++) {
                if(k + dif < MAX_SUM) {
                    dp[i][j][k] = dp[i][j][k] | dp[i - 1][j][k + dif]
                                  | dp[i][j - 1][k + dif];
                }
                dp[i][j][k] = dp[i][j][k] | dp[i - 1][j][abs(k - dif)]
                              | dp[i][j - 1][abs(k - dif)];
            }
        }
    }
    int ans = -1;
    for(int k = 0; k < MAX_SUM; k++) {
        if(dp[H][W][k]) {
            ans = k;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10624
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int i;
	int[] ini = new int[30];
	
	for(i=0; i<28; i++)
	    ini[sc.nextInt()-1] = 1;
	for(i=0; i<30; i++)
	    if(ini[i]==0)
		System.out.println(i+1);
    }
}

Measured memory_bytes: 11000
N = int(input())
D = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
conti = False
for d in D:
    if d[0] == d[1]:
        cnt += 1
        conti = True
    else:
        cnt = 0
        conti = False
    if cnt == 3:
        break
if cnt == 3:
    print('Yes')
else:
    print('No')
    

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

#define rep(i,x) for(int i = 0 ; i < x ; i ++)
#define rep1(i,x) for(int i = 1 ; i <= x ; i ++)

typedef long double ld;
const ld PI = 3.141592653589793238462643383279;

struct po{
	ld x;
	ld y;
	po(ld a){ x = a; y = 0; }
	po(ld a,ld b){ x = a; y = b; }
	po(){}
	inline ld operator()(const po& rhs) const {
		return x*rhs.x+y*rhs.y;
	}
	inline ld norm() {
		return sqrt((*this)(*this));
	}
	inline po& operator+=(const po& rhs){
		x += rhs.x;
		y += rhs.y;
		return *this;
	}
	inline po& operator-=(const po& rhs){
		x -= rhs.x;
		y -= rhs.y;
		return *this;
	}
	inline po& operator*=(const po& rhs){
		ld x_ = x*rhs.x-y*rhs.y;
		y = x*rhs.y+y*rhs.x;
		x = x_;
		return *this;
	}
	inline po& operator/=(const po& rhs){
		ld x_ = x*rhs.x+y*rhs.y;
		y = -x*rhs.y+y*rhs.x;
		x = x_;
		ld nor = rhs(rhs);
		x /= nor;
		y /= nor;
		return *this;
	}
	inline void in(){
		scanf("%Lf%Lf",&x,&y);
	}
};
inline po operator+(const po& a, const po& b){ return po(a) += b; }
inline po operator-(const po& a, const po& b){ return po(a) -= b; }
inline po operator*(const po& a, const po& b){ return po(a) *= b; }
inline po operator/(const po& a, const po& b){ return po(a) /= b; }

inline po similar(const po& a,const po& b,const po& c,const po& p,const po& q){
	return p+(q-p)*(c-a)/(b-a);
}

typedef pair<po,po> se;
#define fr first
#define sc second

struct li{
	ld a;
	ld b;
	ld c;
	li(po p,po q){
		a = q.y-p.y;
		b = p.x-q.x;
		c = p.y*q.x-p.x*q.y;
	}
	/*explicit li(se s){
		a = s.sc.y-s.fr.y;
		b = s.fr.x-s.sc.x;
		c = s.fr.y*s.sc.x-s.fr.x*s.sc.y;
		li(s.fr,s.sc);
	}*/
	li(){}
	inline ld operator()(const po& p) const {
		return a*p.x+b*p.y+c;
	}
};

void intersect(const li &l,const li &m,po* &ret){
	if(abs(l.a*m.b-m.a*l.b) <= 1e-18){
		ret = nullptr;
		return;
	}
	ret = new po;
	ret->x = -(l.c*m.b-m.c*l.b)/(l.a*m.b-m.a*l.b);
	ret->y = -(l.a*m.c-m.a*l.c)/(l.a*m.b-m.a*l.b);
}
inline bool on(const po &p,const se &s){
	return (s.fr-p)(s.sc-p) <= 1e-9;
}
void intersect(const se &s,const se &t,po* &ret){
	li l = li(s.fr,s.sc);
	li m = li(t.fr,t.sc);
	po *p;
	intersect(l,m,p);
	if(p == nullptr || (on(*p,s)&&on(*p,t)))ret = p;
	else{
		delete p;
		ret = nullptr;
	}
}
inline ld dist(const po &p,const po &q){
	return sqrt((p-q)(p-q));
}

int main(){
	int n;
	while(1){
		scanf("%d",&n);
		if(n == 0)break;
		po p[102],q[102];
		rep1(i,n){
			p[i].in();
			q[i].in();
		}
		int ret = 1;
		rep1(i,n){
			vector<po> vec;
			rep1(j,i-1){
				po *_p;
				intersect(se(p[i],q[i]),se(p[j],q[j]),_p);
				if(_p != nullptr){
					if(max(abs(_p->x),abs(_p->y))-100.0 < -1e-12){
						vec.push_back(*_p);
					}
					delete _p;
				}
			}
			rep(i,vec.size()){
				bool b = true;
				rep(j,i){
					if(dist(vec[i],vec[j]) <= 1e-12)b = false;
				}
				if(b)ret ++;
			}
			ret ++;
		}
		printf("%d\n",ret);
	}
}




Measured memory_bytes: 3232
package main

import (
	"fmt"
	"sort"
)

func main() {
	abc := make([]int, 3)
	for i := range abc {
		fmt.Scan(&abc[i])
	}
	sort.Ints(abc)

	var k int
	fmt.Scan(&k)

	for i := 0; i < k; i++ {
		abc[2] *= 2
	}

	fmt.Println(abc[0] + abc[1] + abc[2])
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
signed main(){
        int a,b;
        double x=0,y=0;
        double d=90;
        while( scanf("%d,%d", &a, &b) != EOF ){
                if(a==0&&b==0) break;
                x+=a*cos(d*M_PI/180);
                y+=a*sin(d*M_PI/180);
                d-=b;
        }
        printf("%d\n%d\n",(int)x,(int)y);
        return 0;
}

Measured memory_bytes: 3432
/*
___ is a raging sadist.
*/

//Destroy all WA at test 2

#include <bits/stdc++.h>
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define pb push_back
#define show(x) cout << (#x) << " : " << x << endl;
#define ll long long
#define ld long double
#define pow power
#define mp make_pair
#define ff first
#define ss second
#define pii pair<ll, ll>
#define sq(x) ((x) * (x))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define endl "\n"
#define PI 3.14159265
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll MOD1 = 998244353;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7; 
using namespace std;

ll power(ll x, ll y) 
{ 
   ll res = 1;      
  
   
    while (y > 0) 
    { 
       
        if (y & 1) 
            res = (long long)(res*x); 
  

        y = y>>1; 

        if (x<=100000000)
        x = (long long)(x*x);

        //cout<<x<<'\n'; 
    } 
    return res; 
} 






int main()
{

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

fastio();

ll k;
string s;

cin>>k>>s;

if (k>=s.length())
cout<<s;
else{

cout<<s.substr(0,k)<<"...";
}

return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
namespace my_header {
#define pb push_back
#define mp make_pair
#define pir pair<int, int>
#define vec vector<int>
#define pc putchar
#define clr(t) memset(t, 0, sizeof t)
#define pse(t, v) memset(t, v, sizeof t)
#define bl puts("")
#define wn(x) wr(x), bl
#define ws(x) wr(x), pc(' ')
	const int INF = 0x3f3f3f3f;
	typedef long long LL;
	typedef double DB;
	inline char gchar() {
		char ret = getchar();
		for(; (ret == '\n' || ret == '\r' || ret == ' ') && ret != EOF; ret = getchar());
		return ret; }
	template<class T> inline void fr(T &ret, char c = ' ', int flg = 1) {
		for(c = getchar(); (c < '0' || '9' < c) && c != '-'; c = getchar());
		if (c == '-') { flg = -1; c = getchar(); }
		for(ret = 0; '0' <= c && c <= '9'; c = getchar())
			ret = ret * 10 + c - '0';
		ret = ret * flg; }
	inline int fr() { int t; fr(t); return t; }
	template<class T> inline void fr(T&a, T&b) { fr(a), fr(b); }
	template<class T> inline void fr(T&a, T&b, T&c) { fr(a), fr(b), fr(c); }
	template<class T> inline char wr(T a, int b = 10, bool p = 1) {
		return a < 0 ? pc('-'), wr(-a, b, 0) : (a == 0 ? (p ? pc('0') : p) : 
			(wr(a/b, b, 0), pc('0' + a % b)));
	}
	template<class T> inline void wt(T a) { wn(a); }
	template<class T> inline void wt(T a, T b) { ws(a), wn(b); }
	template<class T> inline void wt(T a, T b, T c) { ws(a), ws(b), wn(c); }
	template<class T> inline void wt(T a, T b, T c, T d) { ws(a), ws(b), ws(c), wn(d); }
	template<class T> inline T gcd(T a, T b) {
		return b == 0 ? a : gcd(b, a % b); }
	template<class T> inline T fpw(T b, T i, T _m, T r = 1) {
		for(; i; i >>= 1, b = b * b % _m)
			if(i & 1) r = r * b % _m;
		return r; }
};
using namespace my_header;

char S[111111], T[111111];

int s1[111111], s2[111111];

int main() {
#ifdef lol
	freopen("E.in", "r", stdin);
	freopen("E.out", "w", stdout);
#endif
	int s, t, q;
	scanf("%s\n%s\n", S + 1, T + 1);
	s = strlen(S + 1);
	t = strlen(T + 1);
	for (int i = 1; i <= s; ++i) {
		s1[i] = s1[i - 1] + S[i] - 'A' + 1;
	}
	for (int i = 1; i <= t; ++i) {
		s2[i] = s2[i - 1] + T[i] - 'A' + 1;
	}
	fr(q);
	while (q--) {
		int a, b, c, d;
		fr(a, b), fr(c, d);
		if ((s1[b] - s1[a - 1]) % 3 != (s2[d] - s2[c - 1]) % 3) {
			puts("NO");
		} else {
			puts("YES");
		}
	}

	return 0;
}

Measured memory_bytes: 1536
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    X = list(map(int, input().split()))

    if X[0] >= 0:
        print(X[k - 1])
        exit()
    elif X[-1] < 0:
        print(abs(X[n - k]))
        exit()
    else:
        for i in range(n):
            if X[i] >= 0:
                ori = i
                break

    res = f_inf
    left = max(ori - k, 0)
    right = min(ori + k, n)
    for i in range(left, right - k + 1):
        RL = abs(X[i + k - 1] - X[i]) + abs(X[i + k - 1])
        LR = abs(X[i]) + abs(X[i + k - 1] - X[i])
        res = min(res, min(RL, LR))
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 19832
N = int(input())
t0, a0 = 1, 1
for _ in range(N):
  t, a = map(int,input().split())
  vote = max((t0+t-1) // t, (a0+a-1) // a)
  t0 = vote * t
  a0 = vote * a
print(t0+a0)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005

long long k,p;

int32_t main(){
    ios_base :: sync_with_stdio(0);
    cin >> k;
    cout << 50 << '\n';
    for(int i=0;i<k%50;i++){
        cout << 100+k/50-k%50 << ' ';
    }
    for(int i=k%50;i<50;i++){
        cout << 49+k/50-k%50 << ' ';
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n;
    cin >>n;
    vector<int> arr(n, 0);
    for(int& val: arr)
        cin >> val;
    ll ans = INT_MAX;
    for(int i = 1; i <= 100; i++) {
        ll tmp = 0;
        for(int num: arr) {
            tmp += (num-i)*(num-i);
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
s = list(input())

res = 0
flg = False
flg2 = False

for i in range(len(s)):
    if flg:
        res += 1
        flg = False
    elif i == 0 or s[i] != s[i-1] or flg2:
        res += 1
        flg2 = False
    elif s[i] == s[i-1]:
        flg = True
        flg2 = True

print(res)

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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define PB push_back
#define MP make_pair
#define ALL(x) (x).begin(),(x).end()
typedef long long ll;

string S;

ll rec(ll pos,ll sum,ll cur)
{
	if(pos == S.size()){
		return sum + cur;
	}
	ll d = S [pos] - '0';

	ll res = rec(pos + 1,sum + cur,d);
	if(pos){
		res += rec(pos + 1,sum,cur * 10 + d);
	}

	return res;
}

int main()
{
	cin >> S;
	cout << rec(0,0,0) << endl;

	return 0;
}


Measured memory_bytes: 256
/**OOO**/
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define mems(x,y) memset(x,y,sizeof(x))
#define pf printf
#define sc scanf
using namespace std;


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

    ll n,y,a,b,c;
    cin>>n>>y;

    if(y%10000==0 && y/10000==n)cout<<y/10000<<" "<<0<<" "<<0<<endl;
    else if(y%5000==0 && y/5000==n)cout<<0<<" "<<y/5000<<" "<<0<<endl;
    else if(y%1000==0 && y/1000==n)cout<<0<<" "<<0<<" "<<y/1000<<endl;
    else{

        for(int i=0;i<=n;i++){
            a=10000*i;
            for(int j=0;j<=n-i;j++){
                b=5000*j;
                for(int k=0;k<=n-i-j;k++){
                    c=1000*k;
                    if(a+b+c==y && i+j+k==n){
                        cout<<i<<" "<<j<<" "<<k<<endl;
                        return 0;
                    }
                }
            }
        }
        cout<<-1<<" "<<-1<<" "<<-1<<endl;
    }

return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define all(v)    ((v.begin()),(v.end()))
#define sz(v)     ((int)(v.size()))
#define forv(i, v) for(int i = 0; i < sz(v); ++i)
#define forn(i,n)   for(int i = 0; i < (int)(n); i++)
using namespace std;

typedef long long       ll;
typedef long double     ld;
typedef vector<int>     vi;
typedef vector<double>  vd;
typedef vector< vi >    vii;
typedef vector< vd >    vdd;
typedef vector<string>  vs;


int main()
{
	fast;
	int a, b;
	cin >> a >> b;
	int n;
	bool flag = true;
	for (n = 1; n < 1255; n++) {
		int p, q;
		p = 0.08 * n;
		q = 0.1 * n;
		if (p == a && q == b) {
			cout << n << endl;
			return 0;
		}
	}
	cout << "-1\n";
	return 0;
}


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

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


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

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



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

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

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

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


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

break;
}
*/

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

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

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


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



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

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

//}else{
System.out.println(Math.max(A*B,C*D));

//}




	}
}

Measured memory_bytes: 21716
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;

typedef long long ll;

int MOD=1000000007;


int main(){
    ll A[3][3]={},B[3][3]={};
    for(ll i=0; i<3; i++){
      for(ll j=0; j<3; j++){
        cin >> A[i][j];
      }
    }
    ll N;
    cin >> N;
    ll b[N+10];
    for(int i=0; i<N; i++) cin >> b[i];
    for(ll i=0; i<3; i++){
      for(ll j=0; j<3; j++){
        for(ll k=0; k<N; k++){
          if(A[i][j]==b[k]) B[i][j]=1;
        }
      }
    }
    if(B[0][0]==B[0][1] && B[0][1]==B[0][2] && B[0][2]==1){ cout << "Yes" << endl; return 0;}
    if(B[1][0]==B[1][1] && B[1][1]==B[1][2] && B[1][2]==1){ cout << "Yes" << endl; return 0;}
    if(B[2][0]==B[2][1] && B[2][1]==B[2][2] && B[2][2]==1){ cout << "Yes" << endl; return 0;}
    if(B[0][0]==B[1][0] && B[1][0]==B[2][0] && B[2][0]==1){ cout << "Yes" << endl; return 0;}
    if(B[0][1]==B[1][1] && B[1][1]==B[2][1] && B[2][1]==1){ cout << "Yes" << endl; return 0;}
    if(B[0][2]==B[1][2] && B[1][2]==B[2][2] && B[2][2]==1){ cout << "Yes" << endl; return 0;}
    if(B[0][0]==B[1][1] && B[1][1]==B[2][2] && B[2][2]==1){ cout << "Yes" << endl; return 0;}
    if(B[2][0]==B[1][1] && B[1][1]==B[0][2] && B[0][2]==1){ cout << "Yes" << endl; return 0;} 
    cout << "No" << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int min = Integer.MAX_VALUE;
		for(int i = 0; i < n; i++) {
			int m = sc.nextInt();
			min = Math.min(min, m);
			x -= m;
		}
		System.out.println(n+x/min);
	}
}


Measured memory_bytes: 21716
#include <stdio.h>

int main(void){

  int n,m,c;
  scanf("%d %d %d", &n, &m, &c);
  int b[m];
  for (int i = 0; i < m; i++) {
    scanf("%d", &b[i]);
  }
  int a[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%d", &a[i][j]);
    }
  }

  int value;
  int count = 0;
  for (int i = 0; i < n; i++) {
    value = c;
    for (int j = 0; j < m; j++) {
      value += a[i][j]*b[j];
    }
    if (value > 0) {
      count++;
    }
  }

  printf("%d\n", count);

  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    int A,B,C;
    scanf("%d%d%d",&A,&B,&C);
    if(~A&1||~B&1||~C&1){puts("0");return 0;}
    cout<<min(min(1LL*A*B,1LL*B*C),1LL*A*C)<<endl;
}

Measured memory_bytes: 3768
import itertools
a = []
while True:
    n = map(int, raw_input().split())
    if n == [0, 0]:
        break
    a.append(n)

for n in range(len(a)):
    x = 0
    b = []
    for m in range(a[n][0]):
        if m == range(a[n][0]): break
        b.append(m+1)

    c = list(itertools.combinations(b, 3))
    for l in range(len(c)):
        sum = c[l][0] + c[l][1] + c[l][2]
        if sum == a[n][1]: x += 1
    print x

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

int main(){
    int n;
    cin>>n;
    int i = 0;
    while(++i<=n){
        int x = i;
        if ( x % 3 == 0 ){
            cout << " " << i;
            continue;
        }
        while(x){
            if ( x % 10 == 3 ){
                cout << " " << i;
                break;
            }
            x /= 10;
        }
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 3104
////////////////////////////////////
//          ,.                    //
//         (_|,.                  //
//        ,' /, )_______   _      //
//     __j o``-'        `.'-)'    //
//    (")                 \'      //
//     `-j                |       //
//        `-._(           /       //
//           |_\  |--^.  /        //
//          /_]'|_| /_)_/         //
//             /_]'  /_]'         //
//                                //
//           PIGMEISTER™          //
//                                //
////////////////////////////////////

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

#define ll long long
#define ull unsigned long long
#define mod (ll)1000000007
#define sidha(i, x, n) for(ll i=(ll)(x);i<(ll)(n);i++)
#define ulta(i, x, n) for(ll i=(ll)(x);i>=(ll)(n);i--)
#define mii map<ll, ll>
#define vi vector<ll>
#define pii pair<ll, ll>
#define pb push_back
#define mp make_pair
#define modInv(x) powah(x, mod-2)
#define test ll t;cin>>t;while(t--)
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
ll powah(ll, ll);

int main()
{
    jaldi;
    
    ll h;
    cin >> h;
    ll i = 1, j = 0;
    while (h) {
        h /= 2;
        j += i;
        i *= 2;
    }
    cout << j << endl;
    
    return 0;
}

ll powah(ll x, ll y) { 
    ll res = 1;
    x = x % mod;
    while (y > 0) { 
        if (y & 1) 
            res = (res*x) % mod; 
        y = y>>1;
        x = (x*x) % mod; 
    } 
    return res; 
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <chrono>
#include <random>

using namespace std;

typedef long long ll;

void solve() {
	int n;
	cin >> n;
	int ans = 0;
	int sq = sqrt(n) + 1;

	for (int i = 1; i <= sq; i++) {
		for (int j = i; j <= n / i; j++) {
			if (i * j < n) {
				ans++;
				if (i != j)
					ans++;
			}
		}
	}

	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		//cout << endl;
	}
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <map>
using namespace std;
const int MAXN = 200005;
const int inf = 0x3f3f3f3f;
typedef long long LL;
int vis[MAXN];
char str[MAXN];
map<int, int>mp;

int main()
{
    int n, m;
    int sum=0;
    int id;
    scanf("%d %d", &n, &m);
    int AC=0, WA=0;
    int ac=0, wa=0;
    for(int i=0;i<m;++i)
    {
        scanf("%d %s", &id, str);
        if(strcmp(str, "AC")==0)
        {
            if(vis[id] == 0)
            {
                AC++;
                WA = WA + mp[id];
                vis[id]=1;
            }
            else
            {
                continue;
            }
        }
        else
        {
            if(!vis[id])
                mp[id]++;
        }
    }
    printf("%d %d\n", AC, WA);
    return 0;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1000000000;
int main(){
  int a,b; cin >> a >> b;
  a += b;
  if( a >= 10){ cout << "error" << endl; return 0;}
  cout << a << endl; return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using static System.Math;


struct Rest : IComparer<Rest>
{
    public int n;
    public string s;
    public int p;

    int IComparer<Rest>.Compare(Rest x, Rest y)
    {
        int f = String.Compare(x.s, y.s);
        if (f == 0)
            f = y.p - x.p;
        return f;
    }
}

class Program
{
    static int n;
    static Rest[] res;

    static void Main()
    {
        n = int.Parse(Console.ReadLine());
        res = new Rest[n];
        for (int i = 0; i < n; i++)
        {
            string[] inp = Console.ReadLine().Split();
            res[i].n = i + 1;
            res[i].s = inp[0];
            res[i].p = int.Parse(inp[1]);
        }
        Array.Sort(res,res[0]);
        foreach (var r in res)
            Console.WriteLine(r.n);
    }
}

Measured memory_bytes: 13408
import java.util.Scanner

import scala.io.StdIn._
object Main extends App {

  val n = scala.io.StdIn.readInt()

  def solve(): Long = {
    val divisorCntArr = Array.fill(n + 1)(0L)
    for(i <- 1 to n) {
      for(j <- i to n by i) divisorCntArr(j) += 1
    }

    (1 to n).foldLeft(0L) { (acc, num) =>
      acc + (num * divisorCntArr(num))
    }
  }


  println(solve())

}



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

using namespace std;

int main()
{
    long long n,m;
    cin>>n>>m;
    vector<vector<long long>>dp(n+1,vector<long long>(m+1,-10010010000001));
    vector<pair<int,int>>theval;
    for(long long i=0;i<n;i++){
        long long a,b;
        cin>>a>>b;
        theval.push_back({a,b});
    }
    long long output=0;
    for(long long i=0;i<n;i++){
        if(i==0){dp[i][theval[i].first]=theval[i].second;
        output=max(output,dp[i][theval[i].first]);
        dp[0][0]=0;continue;}
        for(long long j=0;j<=m;j++){
            if(j-theval[i].first<0){dp[i][j]=dp[i-1][j];}
            else{dp[i][j]=max(dp[i-1][j-theval[i].first]+theval[i].second,dp[i-1][j]);}
            output=max(output,dp[i][j]);
            //cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
        }
    }
    cout<<output<<endl;
}

Measured memory_bytes: 80256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//最大公約数
long long mygcd(long long a, long long b) {
  if (a < b) std::swap(a, b);
  long long r = a % b;
  while (r) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

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

	ll k;
	cin >> k;
	ll ans = 0;
	for (ll a = 1; a <= k; a++) {
		for (ll b = 1; b <= k; b++) {
			ll x = mygcd(a, b);
			for (ll c = 1; c <= k; c++) {
				ans += mygcd(x, c);
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x <<": "<<x<<"\n"
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template <class T> using vec = std::vector<T>;
template <class T = int> T in(){T x; cin>>x;return(x);}
template <class T > void print(T& x){cout<<x<<"\n";}
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A=in<int>();
  int B=in<int>();
  int C=in<int>();
	cout <<(A+B+C+9*max({A,B,C}))<<"\n";
}

Measured memory_bytes: 256
import Control.Monad (unless, forM_)
import Data.Vector.Unboxed.Mutable (IOVector)
import qualified Data.Vector.Unboxed.Mutable as VM

main :: IO ()
main = do
  tbl <- kannondou
  solve tbl

solve :: IOVector Int -> IO ()
solve tbl = do
  n <- readLn
  unless (n == 0) $ do
    VM.read tbl n >>= \x -> print $ (x + 3649) `div` 3650
    solve tbl

kannondou :: IO (IOVector Int)
kannondou = do
  tbl <- VM.replicate 33 0
  VM.write tbl 0 1
  forM_ [0 .. 29] $ \i -> do
    x <- VM.read tbl i
    modify tbl (+ x) (i+1)
    modify tbl (+ x) (i+2)
    modify tbl (+ x) (i+3)
  return tbl

modify :: IOVector Int -> (Int -> Int) -> Int -> IO ()
modify v f i = do
  x <- VM.read v i
  VM.write v i (f x)



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

unordered_map<string, int> userToWordCountMap;


int main()
{
    int x;
    cin >> x;
    int val = x/500;
    x = x%500;
    val *= 1000;
    int val1 = x/5;
    val1 *= 5;
    cout << val+val1;
    
}


Measured memory_bytes: 256
from sys import stdin
readline = stdin.readline
def i_input(): return int(readline().rstrip())
def i_map(): return map(int, readline().rstrip().split())
def i_list(): return list(i_map())
class UnionFind:
    def __init__(self, n):
        self.parents = [-1] * (n + 1)
        self.rank = [0] * (n + 1)

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

    def unite(self, x, y) -> bool:
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.rank[x] > self.rank[y]:
            self.parents[x] += self.parents[y]
            self.parents[y] = x
        else:
            self.parents[y] += self.parents[x]
            self.parents[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1
        return True

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

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

    def is_same(self, x, y) -> bool:
        return self.root(x) == self.root(y)

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

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

def main():
    N, M = i_map()
    u = UnionFind(N)
    for _ in range(M):
        A, B = i_map()
        u.unite(A, B)
    ans = len(u.roots()) - 1
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 74584
#define s(X,Y,Z) (t=X,X=Y,Y=t,f(Z?&X:&Y))
f(int*a){*a=(*a&7)<<4|*a>>4;}k,m,a,b,c,t,r;main(n){while(scanf("%d",&n),n){r=1,a=97,b=82,c=67;while(n--){scanf(" %c%*s",&k);m=k-76;t=m%6==0?s(c,b,m):1<m&&m<8?s(b,a,m^7):s(c,a,m>0);r+=a&7;}printf("%d\n",r);}}

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

int main() {
  string s;
  int m, h;
  while (cin >> s, s != "-") {
    cin >> m;
    while (m--) {
      cin >> h;
      s = s.substr(h) + s.substr(0, h);
    }
    cout << s << "\n";
  }
}


Measured memory_bytes: 3076
import std.stdio, std.array, std.conv, std.typecons, std.algorithm;

T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; }

void main() {
    immutable ip = readln.split.to!(ulong[]);
    immutable n = ip[0], m = ip[1];

    auto as = sort(readln.split.to!(ulong[]));
    auto ops = new Tuple!(ulong, "b", ulong, "c")[m];

    for(ulong i = 0; i < m; i++) {
        immutable ip1 = readln.split.to!(ulong[]);
        immutable b = ip1[0], c = ip1[1];
        ops[i] = tuple!("b", "c")(b, c);
    }

    ops.sort!((x, y) {
        if (x.c == y.c) return (x.b > y.b);
        return (x.c > y.c);
    });

    ulong idx = 0;
    ulong sum = 0;

    foreach(op ; ops) {
        if (idx >= n) break;
        if (op.c <= as[idx]) break;
        for(ulong i = 0; i < op.b && op.c > as[idx] && idx < n; i++) {
            sum += op.c;
            idx++;
        }
    }

    while (idx < n) {
        sum += as[idx++];
    }

    writeln(sum);

}


Measured memory_bytes: 5468
N, K=map(int,input().split())
S = str(input())

# count sequence man and memo the cnt in group
man_groups = []
same_cnt = 0
last_man = ""
for i in range(N):
    cur_man = S[i]
    if cur_man != last_man:
        if same_cnt > 0:
            if last_man == "0":
                same_cnt *= -1
            man_groups.append(same_cnt)
        same_cnt = 1
    else:
        same_cnt += 1
    last_man = cur_man
if same_cnt > 0:
    if last_man == "0":
        same_cnt *= -1
    man_groups.append(same_cnt)

# count max sequence man from evey pos
sum_list = []
end_pos = 2 * K if man_groups[0] > 0 else 2 * K - 1
max_man_groups_idx = len(man_groups) - 1
end_pos = min(end_pos, max_man_groups_idx)
last_max = sum(map(abs, man_groups[0: end_pos + 1]))
sum_list.append(last_max)

start_pos = 2 if man_groups[0] > 0 else 1
for i in range(start_pos, len(man_groups), 2):
    if end_pos >= max_man_groups_idx:
        break
    for j in range(2):
        idx = i - j - 1
        if idx >= 0:
            last_max -= abs(man_groups[idx])
    for j in range(2):
        end_pos += 1
        if end_pos <= max_man_groups_idx:
            last_max += abs(man_groups[end_pos])
    sum_list.append(last_max)

#print(man_groups)
#print(sum_list)
print(max(sum_list))







Measured memory_bytes: 11292
#include <cstdio>
#include <algorithm>
using namespace std;
#define INF 2000000000

int n,m,d[1001],c[1001],dp[1001][1001];

int main()
{
  scanf("%d%d", &n, &m);
  for (int i=0; i<n; i++) {
      scanf("%d", &d[i]);
  }

  for (int i=0; i<m; i++) {
      scanf("%d", &c[i]);
  }

  for (int i=0; i<=n; i++) {
      for (int j=0; j<=m; j++) {
          dp[i][j] = INF;
      }
  }

  for(int i=0; i<=m; i++) dp[0][i]=0;
  for (int i=1; i<=n; i++) {
      for (int j=1; j<=m; j++) {
        dp[i][j]=min(dp[i][j], dp[i][j-1]);
        if(i>0){
          dp[i][j]=min(dp[i][j], dp[i-1][j-1]+d[i-1]*c[j-1]);
        }
      }
  }

  printf("%d\n", dp[n][m]);
}

Measured memory_bytes: 5788
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d; cin >> a >> b >> c >> d;
    bool ans = false;
    for(int i = 0; i < 100; i++){
       c -= b;
        if(c<=0){
            ans = true;
            break;
        }
        a -= d;
        if(a<=0) break;
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
typedef long long ll;


int main(){
  int n;
  cin >> n;
  FOR(i,n,1000){
    if(i/100 == (i/10)%10 && i/100 == i %10){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
n,a,b=map(int,input().split())
s=input()
c=0;d=0
for i in range(n):
  if s[i]=='a':
    if c+d<a+b:
      print('Yes')
      c+=1
    else:print('No')
  elif s[i]=='b':
    if c+d<a+b and d<b:
      print('Yes')
      d+=1
    else:print('No')
  else:print('No')

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

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int cnt=0;
  for(int i=0; i<N-2; i++){
    if(S.substr(i,3)=="ABC") cnt++;
  }
  cout << cnt;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
L = len(str(N))

if L == 1 :
    print(N)
elif L == 2:
    print(9)
elif L == 3:
    print(9 + (N-10**2+1))
elif L == 4:
    print(909)
elif L == 5:
    print(9 + 900 + (N-10**4+1))
else:
    print(90909)

Measured memory_bytes: 3060
from collections import deque
n = int(input())
tree = [[] for _ in range(n)]
for _ in range(n-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    tree[u].append((v, w % 2))
    tree[v].append((u, w % 2))

q = deque()
q.append(0)
color = [-1] * n
color[0] = 0

while q:
    v = q.popleft()
    for child, w in tree[v]:
        if color[child] < 0:
            color[child] = (color[v] + w) % 2
            q.append(child)

for i in color:
    print(i)
    

Measured memory_bytes: 95776
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
from fractions import gcd

class SegmentTree:
    def __init__(self, N, func, I):
        self.sz = N
        self.func = func
        self.I = I
        self.seg = [I] * (N * 2)
 
    def assign(self, k, x):
        self.seg[k + self.sz] = x
 
    def build(self):
        for i in range(self.sz - 1, 0, -1):
            self.seg[i] = self.func(self.seg[2 * i], self.seg[2 * i + 1])
 
    def update(self, k, x):
        k += self.sz
        self.seg[k] = x
        while k > 1:
            k >>= 1
            self.seg[k] = self.func(self.seg[2 * k], self.seg[2 * k + 1])

    def query(self, a, b):
        L = self.I
        R = self.I
        a += self.sz
        b += self.sz
        while a < b:
            if a & 1:
                L = self.func(L, self.seg[a])
                a += 1
            if b & 1:
                b -= 1
                R = self.func(self.seg[b], R)
            a >>= 1
            b >>= 1
        return self.func(L, R)

def main():
    N = int(readline())
    m = map(int,read().split())
    seg = SegmentTree(N , gcd , 0)
    for i in range(N):
        seg.assign(i , next(m))
    seg.build()
    ans = 1
    for i in range(N):
        ans = max(ans,gcd(seg.query(0,i) , seg.query(i+1,N)))
    print(ans)

main()

Measured memory_bytes: 81340
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val aList = mutableListOf<List<Int>>()
    aList.add(readLine()!!.split(' ').map(String::toInt))
    aList.add(readLine()!!.split(' ').map(String::toInt))

    var max = 0
    for (i in 0 until n) {
        val temp = aList[0].filterIndexed { index, it -> index <= i }.sum() + aList[1].filterIndexed { index, it -> index >= i }.sum()
        max = Math.max(max, temp)
    }
    println(max)
}

Measured memory_bytes: 38308
use petgraph::unionfind::UnionFind;
use proconio::fastout;
use proconio::input;
use proconio::marker::Usize1;
use std::collections::HashMap;

#[fastout]
fn main() {
    input! {
        n: usize, m: usize,
        abs: [(Usize1, Usize1); m],
    }
    let mut uf: UnionFind<_> = UnionFind::new(n);
    for &(a, b) in &abs {
        uf.union(a, b);
    }
    let mut counts = HashMap::new();
    for i in 0..n {
        let x = uf.find(i);
        *counts.entry(x).or_insert(0) += 1;
    }
    println!("{}", counts.values().max().unwrap());
}


Measured memory_bytes: 10672
def main():
    n = int(input())
    
    alpha = "abcdefghijklmnopqrstuvwxyz"

    ans = []
    while n!= 0:
        n-=1
        i = n%26
        ans.append(alpha[i])
        n//=26

    print("".join(ans[::-1]))
if __name__ == "__main__":
    main()

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

int main() {
    int n, k;
    cin>>n>>k;
    vector<int> h(n), dp(n, 0);
    for(auto &e: h) cin>>e;
    for(int i = 1; i<n; i++) {
        dp[i] = dp[i-1] + abs(h[i] - h[i-1]);
        for(int j = 2; j<=k && (i-j) >= 0; j++) {
            dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
        }
    }
    cout<<dp[n-1]<<"\n";
}


Measured memory_bytes: 3956
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
  int n, i, a, b[100000], ct=0, flag, j, ans=1;
  for(i=0; i<100000; i++)
    b[i]=0;
  
  cin >> n;
  int x[n+1];
  for(i=0; i<n+1; i++)
    cin >> x[i];
  sort(x, x+n+1);
  for(i=0; i<n; i++)
    x[i]=x[i+1]-x[i];
  a=x[0];
  for(i=1; i*i<=a; i++){
    if(a%i==0){
      b[ct]=i;
      b[ct+1]=a/i;
      ct+=2;
    }
  }
  for(i=0; b[i]>0; i++){
    flag=0;
    for(j=1; j<n; j++)
      if(x[j]%b[i]!=0)
	flag++;
    if(flag==0&&ans<b[i])
      ans=b[i];
    flag=0;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 1024
//#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=2e6+5;
const int mod=1e9+7;
ll n,s;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(ll i=1;i<=n;i++){
        if(i%3!=0 && i%5!=0) s+=i;
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 3644
n,k = map(int,input().split())
p = list(map(int,input().split()))
u = sum(p[0:k])
maxsum = u
for i in range(1, n-k+1):
	u = u + p[i+k-1] - p[i-1]
	if u >= maxsum:
		maxsum = u
print((maxsum+k)/2)

Measured memory_bytes: 25060