akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

import sys, re

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S=input()
N=len(S)

ans=0
# 0文字以上でACGTのいずれかのみ
pattern = re.compile(r'^[ACGT]*$')
for i in range(N):
    for j in range(i+1, N+1):
        if pattern.match(S[i:j]):
            ans=max(ans, j-i)
print(ans)


Measured memory_bytes: 3188
//33
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(;;){
    char g[8][8];
    for(int y=0;y<8;y++){
      for(int x=0;x<8;x++){
	if(!(cin>>g[y][x]))return 0;
      }
    }
    for(int y=0;y<8;y++){
      for(int x=0;x<8;x++){
	if(g[y][x]=='1'){
	  int a=0;
	  for(int i=0;i<4;i++){
	    for(int j=0;j<4;j++){
	      a=(a<<1)+(y+i<8&&x+j<8&&g[y+i][x+j]=='1');
	    }
	  }
	  static const int f[]={0xcc00,0x8888,0xf000,0x8800,0xc600,0x8c40,0xc800};
	  cout<<char(find(f,f+7,a)-f+'A')<<endl;
	  goto next;
	}
      }
    }
  next:
    ;
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#define INF 1<<21;
using namespace std;
main(){
  int mokuhyou;
  int r[4]={0,2,3,5};
  double dp[4][51];
  double nn[4]={0,0.8,0.85,0.88};
  double n[4]={0,380,550,850};
  int rr[4]={0,5,4,3};
  double inf=INF;
  while(1){
    cin>>mokuhyou;
    if(mokuhyou==0)break;
    for(int i=0;i<4;i++){
      for(int j=0;j<=50;j++){
	dp[i][j]=INF;
      }
    }
    for(int i=1;i<4;i++){
      int aa=1;
      for(int j=0;j<=mokuhyou/100;j++){
	dp[i][j]=min(dp[i-1][j],dp[i][j]);
      }
      for(int j=r[i];j<=mokuhyou/100;j+=r[i]){
	double as=(aa/rr[i])*rr[i];
	dp[i][j]=min(dp[i][j],(n[i]*(aa-as))+((n[i]*as)*nn[i]));
	aa++;
      }
      for(int j=r[i];j<=mokuhyou/100;j++){
	int aaa=1;
	for(int k=j;k<=mokuhyou/100;k+=r[i]){
	  double aas=(aaa/rr[i])*rr[i];
	  dp[i][k]=min(dp[i][k],dp[i-1][j-r[i]]+(n[i]*(aaa-aas))+((n[i]*aas)*nn[i]));
	  aaa++;
	}
      }
      /*
      for(int j=0;j<4;j++){
	for(int k=0;k<=mokuhyou/100;k++){
	  if(dp[j][k]==inf){
	    cout<<" -1"<<" ";
	  }
	  else{
	    cout<<dp[j][k]<<" ";
	  }
	}
	cout<<endl;
      }
      cout<<endl;
      */
    }
    cout<<dp[3][mokuhyou/100]<<endl;
  }
}

Measured memory_bytes: 1228
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int N, E, T;
vector<int> W;
vector<int> G;
vector<int> S[1000];
int memo[300];
int dfs(int K, vector<bool> used){
  if(memo[K] != -1 && memo[K] < INF) return memo[K];
  if(W[K]) return 1;
  int res = INF;
  used[K] = true;
  REP(i, E) if(G[i] == K){
    vector<int> need;
    REP(j, S[i].size()) {
      if(used[S[i][j]]) need.push_back(INF);
      else need.push_back(dfs(S[i][j], used));
    }
    sort(need.begin(), need.end());
    reverse(need.begin(), need.end());
    int ans = 0;
    REP(i, need.size()) ans = max(ans, need[i] + i);
    res = min(res, ans);
  }
  return memo[K] = res;
}
int main(){
  while(cin >> N >> E >> T){
    T--;
    W.assign(N, 0);
    REP(i, N) cin >> W[i];
    G.assign(E, 0);
    REP(i, E){
      cin >> G[i]; G[i]--;
      int C; cin >> C;
      S[i].assign(C, 0);
      REP(j, C) cin >> S[i][j];
      REP(j, C) S[i][j] --;
    }
    /*
    vector<bool> used(N, false);
    memset(memo, -1, sizeof memo);
    int ans = dfs(T, used);
    if(ans == INF) ans = -1;
    cout << ans << endl;
    */
    bool update;
    vector<int> dist(N, INF);
    REP(i, N) if(W[i]) dist[i] = 1;
    while(true){
      update = false;
      REP(i, E){
        vector<int> need;
        REP(j, S[i].size()){
          need.push_back(dist[S[i][j]]);
        }
        sort(need.begin(), need.end());
        reverse(need.begin(), need.end());
        int res = 0;
        REP(j, need.size()) res = max(res, need[j] + j);
        if(dist[G[i]] > res){
          update = true;
          dist[G[i]] = res;
        }
      }
      if(!update) break;
    }
    if(dist[T] == INF) dist[T] = -1;
    cout << dist[T] << endl;
  }
  return 0;
}

Measured memory_bytes: 1284
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <algorithm>

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
inline int gcd(int a,int b){return b?gcd(b,a%b):a;}
inline int lcm(int a,int b){return a*b/gcd(a,b);}
typedef long long ll;
typedef std::vector<int> VI;
typedef std::pair<int, int> PII;

using namespace std;

int main()
{
  string S;
  cin >> S;
  int N = S.length();
  vector<int> H(N,1);
  REP(i,N)
  {
    if (S[i] == 'L' || S[i+1] == 'L') continue;
    if (i+2<N) {
      H[i+2] += H[i];
      H[i] = 0;
    }
  }
  for (int i=N-1;i>=0;i--)
  {
    if (S[i-1] == 'R' || S[i] == 'R') continue;
    if (i-2>=0) {
      H[i-2] += H[i];
      H[i] = 0;
    }
  }
  REP(i,N-1)
  {
    printf("%d ", H[i]);
  }
  printf("%d\n", H[N-1]);
  return 0;
}


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

using namespace std;
typedef long long LL;
const LL INF=1e15;

int main(){
	int n;
	cin >> n;
	vector<LL> a(n);
	rep(i,n) cin >> a[i];
	LL sum=0, sign=1;
	LL res1=0, res2=0;
	rep(i,n){
		sum+=a[i];
		if(sum*sign<=0){
			res1+=abs(sum)+1;
			sum=sign;
		}
		sign*=-1;
	}
	sum=0, sign=-1;
	rep(i,n){
		sum+=a[i];
		if(sum*sign<=0){
			res2+=abs(sum)+1;
			sum=sign;
		}
		sign*=-1;
	}
	cout << min(res1,res2) << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define repin(a,n) vector<ll> a(n);rep(i,n){cin>>a[i];}
#define repins(a,n) vector<string> a(n);rep(i,n){cin>>a[i];}
#define repind(a,n) vector<double> a(n);rep(i,n){cin>>a[i];}
#define in(a) ll a;cin>>a;
#define ins(a) string a;cin>>a;
#define ind(a) double a;cin>>a;
template<class T>
inline void out(T a){cout<<a<<endl; }
inline void out(double a){ printf("%.10f\n", a);} 
#define all(x) (x).begin(),(x).end()
#define rep2(i,a,b) for(ll i=(a);i<(b);++i)
#define range(i,s,c) for(ll i=(s);i<(s+c);++i)
using vell = vector<ll>;
using ves = vector<string>;
using ved = vector<double>;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main()
{
	in(n);
	in(k);
	repin(a,n);
	double ans = 0;
	double sum = 0;
	rep(i,k){
		sum += (a[i]+1)/2.0;
	}
	ans = max(ans,sum);
	rep(i,n-k){
		sum -= (a[i]+1)/2.0;
		sum += (a[k+i]+1)/2.0;
		ans = max(ans,sum);
	}
	out(ans);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, k;
	string s;
	cin>>n>>k>>s;
	int i = 0;
	int j = 0;
	int ans = 0;
	while(j < n){
		while(j < n && s[j] == '1')j++;
		ans = max(ans, j - i);
		while(j < n && s[j] == '0')j++;
		k--;
		if(k < 0){
			while(i < n && s[i] == '1')i++;
			while(i < n && s[i] == '0')i++;
		}
		ans = max(ans, j - i);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 512
n=int(input())
people=[None]*n
for i in range(n):
  a=int(input())
  people[i]=[tuple(map(int,input().split())) for k in range(a)]
ans=0
for i in range(2**n):
  shoujiki=[]
  div=i
  flg=0
  for j in range(n)[::-1]:
    s=div//(2**j)
    div%=2**j
    if s:shoujiki.append(j)
  for k in shoujiki:
    for lk in people[k]:
      if (lk[0]-1 in shoujiki and lk[1]==0) or (lk[0]-1 not in shoujiki and lk[1]==1):flg=1
  if not flg:
    if len(shoujiki)>ans:ans=len(shoujiki)
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
int main() {
	vector<int>Alpha(26, 0);
	string S;
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		Alpha.at(S.at(i) - 97)++;
	}
	for (int i = 0; i < 26; i++) {
		if (Alpha.at(i) % 2 != 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
    int x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
    return x*f;
}
inline ll readll(){
    ll x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
    return x*f;
}
const int maxn=(1<<18),mod=998244353,inv2=(mod+1)/2;
inline int ksm(int x,int y){
	int res=1;
	while(y){
		if(y&1) res=(ll)res*x%mod;
		x=(ll)x*x%mod;
		y>>=1;
	}
	return res;
}
int n,a[maxn],N,b[maxn];
inline void fwt(int *y,int flag){
	for(int k=2;k<=N+1;k<<=1)
		for(int i=0;i<=N;i+=k)
			for(int j=0;j<(k>>1);++j){
				int y1=y[i+j],y2=y[i+j+(k>>1)];
				if(flag) y[i+j]=(y1+y2)%mod,y[i+j+(k>>1)]=(y1-y2+mod)%mod;
				else y[i+j]=(ll)(y1+y2)*inv2%mod,y[i+j+(k>>1)]=(ll)(y1-y2+mod)*inv2%mod;
			}
}
int main(){
	n=read();
	N=(1<<n)-1;
	int sum=0;
	REP(i,0,N) a[i]=read(),sum+=a[i];
	sum=ksm(sum,mod-2);
	REP(i,0,N) a[i]=(ll)a[i]*sum%mod,b[i]=(i==0?N:mod-1);
	a[0]=(a[0]+mod-1)%mod;
	fwt(a,1),fwt(b,1);
	REP(i,0,N) a[i]=(ll)ksm(a[i],mod-2)*b[i]%mod;  
	fwt(a,0);
	REP(i,0,N) printf("%d\n",(a[i]+mod-a[0])%mod);
    return 0;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = int(1e5 + 5);
#define REP(i, n) for (int i = 0; i < n; i++)

int main() {
    int n, a[MAX_N][3], dp[MAX_N][3]{}; // dp[i][j] i番目までみて最後にjを使ったときの最大値
    cin >> n;
    REP(i,n)REP(j,3) cin >> a[i][j];
    REP(i,n){
        REP(j,3){
            dp[i+1][j] = max(dp[i][(j+1)%3],dp[i][(j+2)%3])+a[i][j];
        }
    }
    cout << max(dp[n][0],max(dp[n][1],dp[n][2])) << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define cinf(n,x) for(int i=0;i<(n);I++) cin >> x[i];

int main(){
  int a,b,c ;
  cin >> a >> b >> c;
  int sum ;
  sum = a+b+c-max({a,b,c}) ;
  if(sum == max({a,b,c}))
    cout <<"Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
const int INF = 1001001001;
const ll LINF = 1e18;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const P p1, const P p2){ return p1.first < p2.first;};
bool p_comp_fg(const P p1, const P p2){ return p1.first > p2.first;};
bool p_comp_ss(const P p1, const P p2){ return p1.second < p2.second;};
bool p_comp_sg(const P p1, const P p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

const ll mod = 1e9 + 7;
vl pow_t(1e5+100, 0);
ll pow_mod(ll p){
    ll ans = 1;
    for(ll i=p; i >= 1; i--){
        if(pow_t[i] > 0){
            ans *= pow_t[i] % mod; break;
        }
        ans *= 3; ans %= mod; pow_t[p-i+1] = ans;
    }
    pow_t[p] = ans % mod;
    return pow_t[p];
}

int main(){
    string S; cin >> S; ll N = S.size();
    vl as(N, 0), aqs(N, 0), cs(N, 0), cqs(N,0);
    ll a_count = 0, aq_count = 0, c_count = 0, cq_count = 0;
    FOR(i, 0, N){
        as[i] = a_count; aqs[i] = aq_count;
        if(S[i] == 'A') a_count++;
        if(S[i] == '?') aq_count++;
    }
    string Sr = S; reverse(Sr.begin(), Sr.end());
    FOR(i, 0, N){
        cs[N-i-1] = c_count; cqs[N-i-1] = cq_count;
        if(Sr[i] == 'C') c_count++;
        if(Sr[i] == '?') cq_count++;
    }
    ll ret = 0;
    
    vl pow_mod3(1e5+10,1); ll tp = 1;
    for (ll i=1; i<=1e5+10; i++) {
        tp = (tp * 3) % mod; pow_mod3[i] = tp;
    }
    
    FOR(i, 1, N-1){
        if(S[i] == 'B' || S[i] == '?'){
            ll a_case = (as[i] * pow_mod3[aqs[i]] + aqs[i] * pow_mod3[max(aqs[i]-1,0ll)]) % mod;
            ll c_case = (cs[i] * pow_mod3[cqs[i]] + cqs[i] * pow_mod3[max(cqs[i]-1,0ll)]) % mod;
            ret = (ret + (a_case * c_case) % mod ) % mod;
        }
    }
    cout << ret << endstr;
    return 0;
}


Measured memory_bytes: 5120
q = int(input())
for i in range(q):
  x,y = map(int,input().split())
  if x == y:
    print(2*(x-1))
    continue
  z = int((x*y)**0.5)
  if z**2 == x*y:
    z -= 1
  ans = 2*z-2
  if z*(z+1)<x*y:
    ans += 1
  print(ans)

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

class UnionFind {
public:
    vector<LL> parent;
    vector<LL> dis;

    UnionFind(LL N) {
        parent.resize(N);
        REP(i, N) {
            parent[i] = i;
        }
        dis.resize(N);
        fill(ALL(dis), 0);
    }

    pair<LL, LL> root(LL x) {
        if(x == parent[x]) {
            return make_pair(x, dis[x]);
        }
        auto p = root(parent[x]);
        parent[x] = p.first;
        dis[x] += p.second;
        auto r = make_pair(parent[x], dis[x]);
        return r;
    }

    bool same(LL x, LL y) {
        return root(x).first == root(y).first;
    }

    bool unite(LL l, LL r, LL d) {
        if(same(l, r)) {
            LL dl = root(l).second;
            LL dr = root(r).second;
            return dr - dl == d;
        }
        LL R = root(r).first;
        parent[R] = l;
        LL x = d - dis[r];
        dis[R] = d - dis[r];
        return true;
    }
};

int main() {
    LL N, M;
    cin >> N >> M;
    UnionFind uf(N + 1);
    bool p = true;
    REP(i, M) {
        LL l, r, d;
        cin >> l >> r >> d;
        p = p && uf.unite(l, r, d);
    }

    if(p) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define u128 __int128
#define ss second
#define pb push_back

#define N 200010
#define MOD 1000000007

ll n, m, k;

ll bexp(ll a, ll b)
{
	ll res = 1;
	while(b)
	{
		if(b & 1)
			res = res * a;
		a *= a;
		b >>= 1;
	}
	return res;
}

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

// 	int n, m, k;
// 	cin >> n >> m >> k;
// 	if(n <= m && k <= m)
// 		cout << "Yes\n";
// 	else
// 		cout << "No\n";
// 	return 0;
// }
// int main()
// {
// 	ios::sync_with_stdio(false);
// 	cin.tie(NULL);

// 	ll n, m;
// 	cin >> n >> m;
// 	ll k1 = (n + 1) / 3, k2 = (m + 1)/ 2, k3 = (n + 1)/ 2, k4 = (m + 1) / 3;
// 	ll m1 = k1 * k2, m2 = k3 * k4;
	
// 	if(n % 3 == 1)
// 	{
// 		m1 += (m + 1)/3;
// 	}
// 	if(m % 3 == 1)
// 		m2 += (n + 1)/3;
// 	cout << max(m1, m2);
// 	return 0;
// }

int main()
{
	
	string s;
	cin >> s;
	int n = s.size();
	int ans = 0;
	int k0 = 0, k1 = 0;
	for (int i = 0; i < n; ++i)
	{
		if(s[i] == '0')
			k0++;
		else
			k1++;
	}
	ans = min(k1, k0) * 2;
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a;i<n;i++)
#define ve vector
#define ss second 
#define ff first
#define pf pop_front
#define pob pop_back
#define psf push_front
#define res(x) cout<<x<<'\n'
#define read(t) ll t;cin>>t

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    string a,b;
    cin>>a>>b;
    int x,y;
    cin>>x>>y;
    string inp;
    cin>>inp;
    if(inp==a) x--;
    else y--;

    cout<<x<<" "<<y<<endl;
    
    
    


   

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
using namespace std;

class union_find{
private:
	vector<int> parents;
	vector<int> weight;
public:
	union_find(int n){
		for(int i=0;i<n;i++){
			parents.push_back(i);
			weight.push_back(0);
		}
	}
	int find(int x){
		if(parents[x]==x){
			return x;
		}else{
			int tmp=find(parents[x]);
			weight[x]=weight[x]+weight[parents[x]];
			return parents[x]=tmp;
		}
	}
	void unite(int x,int y,int w){
		int tmpx=find(x);
		int tmpy=find(y);
		if(tmpx==tmpy)return;
		weight[tmpx]=w-weight[x]+weight[y];
		parents[tmpx]=tmpy;
	}
	int get_weight(int x,int y){
		if(find(x)==find(y)){
			return weight[x]-weight[y];
		}else{
			return -2000000;
		}
	}
};
int main(){
	char c;
	int a,b,w;
	int n,m;
	while(cin>>n>>m,n!=0||m!=0){
		union_find uf(n+1);
		for(int i=0;i<m;i++){
			cin>>c;
			if(c=='!'){
				cin>>a>>b>>w;
				uf.unite(a,b,w);
			}else if(c=='?'){
				cin>>a>>b;
				int tmp=uf.get_weight(a,b);
				if(tmp!=-2000000){
					cout<<tmp<<endl;
				}else{
					cout<<"UNKNOWN"<<endl;
				}
			}
		}
	}
}

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

int main(){
    int n;
    cin >> n;
    string S, T;
    cin >> S >> T;

    for(int i=0;i<2*n;i++){
        if(i%2 == 0)
            cout << S[i/2];
        if(i%2 == 1)
            cout << T[i/2];
    }
}

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 1e18 * 4;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
  int n, i, j;
  cin >> n;
  vl a(n), t(n);
  for (i = 0; i < n; i++) {
    cin >> t[i];
  }
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<pll> a2(n), t2(n);
  ll M = -1;
  for (i = 0; i < n; i++) {
    if (t[i] > M) {
      M = t[i];
      t2[i] = pll(M, M);
    } else {
      t2[i] = pll(1, M);
    }
  }
  M = -1;
  for (i = n-1; i >= 0; i--) {
    if (a[i] > M) {
      M = a[i];
      a2[i] = pll(M, M);
    } else {
      a2[i] = pll(1, M);
    }
  }
  ll ans = 1;
  for (i = 0; i < n; i++) {
    if (a2[i].second < t2[i].first || t2[i].second < a2[i].first) {
      ans *= 0;
    }
    else {
      ans = ans * (min(a2[i].second, t2[i].second) - max(a2[i].first, t2[i].first) + 1) % MOD;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
 
const int N = 0;
 
typedef long long int ll;
 
using namespace std;
 
int main(){

    ll n,m;cin>>n>>m;
    
    ll a = n%m;
    ll b = abs(a-m);
    cout<<(min(a,b));
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N=0;
    int Acount=0;
    cin>>N;
    vector<string> S(N);

    for(auto &&x:S){
        cin>>x;
    }

    for(int i=0;i<N;i++){
        if(S[i]=="A"){
            Acount++;
        }else{
            Acount--;
        }

        if(Acount<0){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    if(Acount==0){ 
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }


}



Measured memory_bytes: 3164
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var ABQ = Sarray();
            var A = ABQ[0];
            var B = ABQ[1];
            var Q = ABQ[2];
            var si = new List<long>();
            var ti = new List<long>();

            for (var i = 0; i < A; ++i)
                si.Add(Sarray()[0]);
            for (var i = 0; i < B; ++i)
                ti.Add(Sarray()[0]);
            si.Sort();
            ti.Sort();
            for (var i = 0; i < Q; ++i)
            {
                var x = Sarray()[0];
                var xs = ~si.BinarySearch(x, new ub<long>());
                var xt = ~ti.BinarySearch(x, new ub<long>());
                var rs = 0L;
                var ls = 0L;
                var rt = 0L;
                var lt = 0L;
                if (A <= xs)
                    rs = ls = si[(int)A - 1];
                else if (xs <= 0)
                    rs = ls = si[0];
                else
                {
                    rs = si[xs];
                    ls = si[xs - 1];
                }
                if (B <= xt)
                    rt = lt = ti[(int)B - 1];
                else if (xt <= 0)
                    rt = lt = ti[0];
                else
                {
                    rt = ti[xt];
                    lt = ti[xt - 1];
                }
                var ans = Abs(x - rs) + Min(Abs(rs - rt), Abs(rs - lt));
                ans = Min(ans, Abs(x - ls) + Min(Abs(ls - rt), Abs(ls - lt)));
                //t→s
                ans = Min(ans, Abs(x - rt) + Min(Abs(rt - rs), Abs(rt - ls)));
                ans = Min(ans, Abs(x - lt) + Min(Abs(lt - rs), Abs(lt - ls)));

                WriteLine(ans);
            }
            Out.Flush();
        }
        public class ub<T> : IComparer<T> where T : IComparable<T>
        {
            public int Compare(T x, T y) => 0 < x.CompareTo(y) ? 1 : -1;
        }
    }
}

Measured memory_bytes: 22140
h, w = [int(m) for m in input().split(" ")]
s = [input() for i in range(h)]

s = [[{".": 0, "#": 10}[c] for c in line] for line in s]

for h_i in range(h):
    for w_i in range(w):
        if 10 <= s[h_i][w_i]:
            for y in range(h_i-1, h_i+2):
                for x in range(w_i-1, w_i+2):
                    if 0 <= y < h and 0 <= x < w:
                        s[y][x] += 1

print("\n".join(["".join(["#" if 10 <= c else str(c) for c in line]) for line in s]))

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	a := nextInt()
	b := nextInt()
	ans := -1
	if a >= 13 {
		ans = b
	} else if a >= 6 && a <= 12 {
		ans = b / 2
	} else {
		ans = 0
	}
	fmt.Println(ans)
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


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

int main()
{
	int n,flag=1;
	vector<int>v;
	cin>>n;
	for (int i=1;i<=9;i++) if (n%i==0){v.push_back(i);}
	int s=v.size();
	for(int i=0;i<s;i++)
    {
        for(int j=0;j<s;j++)
        {


                if(v[i]*v[j]==n){flag=0;cout<<"Yes"<<endl;break;}

        }
        if(flag==0)break;
    }
    if(flag==1)cout<<"No"<<endl;
	return 0;
}


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

#define trav(a, A) for (auto & a : A)
#define f first
#define s second

typedef long long ll;

const ll MOD = 1e+9+7;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MAXN = 1e+5+7;

int main ()
{
	ios_base::sync_with_stdio (0);
	cin.tie (0);
	ll i, j, n;
	cin >> n;
	vector <ll> inp (n);
	trav (a, inp) cin >> a;
	sort (inp.rbegin (), inp.rend ());
	ll ans = 0;
	for (i = 1; i < n; ++i)
		ans += inp[i/2];
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 4796
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>
#include<functional>

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< int,  int> P;



int main(void) {
	long long int n;
	long long int count = 0;
	long long int m = 0, a = 0, r = 0, c = 0, h = 0;


	cin >> n;
	vector<string>s(n);
	FOR(i, 0, n - 1) {
		cin >> s[i];
	}

	FOR(i, 0, n - 1) {
		switch (s[i][0]) {
		case 'M':
			m++;
			break;
		case 'A':
			a++;
			break;
		case 'R':
			r++;
			break;
		case 'C':
			c++;
			break;
		case 'H':
			h++;
			break;
		}
	}
	count += m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h;
	cout << count << endl;

	return 0;
}

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

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  string s, t;
  cin >> s >> t;
  int n = sz(s);
  int m = sz(t);
  const int SIGMA = 26;
  string w = s + s;
  vector <vector <int>> nxt(2 * n, vector <int> (SIGMA, -1));
  vector <int> cur(SIGMA, -1);
  for (int i = sz(w) - 1; i >= 0; i--) {
    nxt[i] = cur;
    cur[w[i] - 'a'] = i;
  }
  ll ans = 0;
  int pos = -1;
  for (int i = 0; i < n; i++) if (s[i] == t[0]) { pos = ans = i; break; }
  if (pos == -1) {
    cout << -1 << '\n';
    return (0);
  }
  for (int i = 1; i < m; i++) {
    int go = nxt[pos][t[i] - 'a'];
    if (go == -1) {
      cout << -1 << '\n';
      return (0);
    }
    ans += go - pos;
    pos = go % n;
  }
  cout << 1 + ans << '\n';
  return (0);
}


Measured memory_bytes: 29264
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#define ll long long
#define N 2000010
using namespace std;
inline int read()
{
	int neg=1,num=0;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-')neg=-1;
	for(;isdigit(c);c=getchar())num=(num<<1)+(num<<3)+c-'0';
	return neg*num;
}
int n,cnt,tot,pri[N];
bool vis[N];
int d[N],num[N];
void d_sieve()
{
	vis[1]=d[1]=1;
	for(int i=2;i<=n;i++)
	{
		if(!vis[i])pri[++tot]=i,d[i]=2,num[i]=1;
		for(int j=1;j<=tot && i*pri[j]<=n;j++)
		{
			vis[pri[j]*i]=1;
			if(i%pri[j]==0){d[i*pri[j]]=d[i]/(num[i]+1)*(num[i]+2);num[i*pri[j]]=num[i]+1;break;}
			d[i*pri[j]]=d[i]*2;num[i*pri[j]]=1;	
		} 
	}
}
int main()
{
	n=1e6;d_sieve();
	int C=read();
	ll ans=0;
	for(int i=1;i<C;i++)ans+=d[C-i];
	cout<<ans;
	return 0;
}



Measured memory_bytes: 12740
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
A=[0,0,0,0,0,0,0,0,0,0]
B=0
A[0]=a-b
A[1]=a-c
A[2]=a-d
A[3]=a-e
A[4]=b-c
A[5]=b-d
A[6]=b-e
A[7]=c-d
A[8]=c-e
A[9]=d-e
for i in range(10):
  if A[i]<=k and A[i]>=(k*(-1)):
    B=B+1
if B==10:
  print("Yay!")
else:
  print(":(")

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

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

  cin >> a >> b >> c;
  int arr[] = {a, b, c};

  for(unsigned char i = 0; i < 3; ++i){
    for(unsigned char j = i; j < 3; ++j){
      if(arr[i] > arr[j]) {
        int tmp = 0;
        tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
      }
    }
  }

  cout << arr[0] << ' ' << arr[1] << ' ' << arr[2] << endl; 
}


Measured memory_bytes: 3108
s = str(input())
lst = []

for i in range(len(s)):
    if s[i]=='B':
        if len(lst)!=0:
            del lst[-1]
        else:
            continue
    else:
        for j in range(2):
            if int(s[i])==j:
                lst.append(str(j))

print(''.join(lst))

Measured memory_bytes: 3060
# vim: fileencoding=utf-8


def main():
    a, b = map(int, input().split())
    c = 0
    for i in range(a, b + 1):
        #     s = str(i)
        #     r = "".join(reversed(list(s)))
        #     if s == r:
        #         c += 1
        if (i % 10) == (i // 10000) and (i % 100 // 10) == (i % 10000 // 1000):
            c += 1
    print(c)


if __name__ == "__main__":
    main()


Measured memory_bytes: 64392
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    int n,k; cin>>n>>k;
    string s;
    vector <int> a;
    cin>>s;
    int r=0, l=0;
    rep(i,n){
       if(s[i] == 'L') {l++; if(r) a.push_back(r); r=0;}
       if(s[i] == 'R') {r++; if(l) a.push_back(-l); l=0;}
    }
    if(r) a.push_back(r); r=0;
    if(l) a.push_back(-l); l=0;
    n = a.size();
    int ans = 0;
    rep(i,n){
        ans += abs(a[i])-1;
    }
    int naka = n-2;
    if(a.size()==1) {cout<<ans<<endl; return 0;}
    if(a.size()==2){
        ans += 1;
        cout<<ans<<endl; return 0;
    }
    if(a[0]*a[n-1] >0){
        int x = naka/2;
        ans += min(k , x)*2;
        k-=x;
        if(k>0) ans += 2;
        cout<<ans<<endl;
        return 0;
    }else{
        naka--;
        int x = naka/2;
        ans += min(k , x)*2;
        k-=x;
        if(k>0) ans += 2;
        k--;
        if(k>0) ans++;
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 1528
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val v = (1..n).map { sc.nextInt() }
    val c = (1..n).map { sc.nextInt() }
    var ans = 0
    for (bit in 1 until (1 shl n)) {
        var sum = 0
        for (i in 0 until n) {
            if (bit and (1 shl i) > 0) {
                sum += v[i]
                sum -= c[i]
            }
        }
        ans = Math.max(ans, sum)
    }
    println(ans)
}

Measured memory_bytes: 42392
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace __gnu_pbds;
using namespace std;
/*
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
*/
#define ull unsigned long long int
#define ll long long int
#define ld long double
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST int testcase;cin>>testcase;while(testcase--)
#define FTEST int testcase;fin>>testcase;while(testcase--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));
#define endl "\n"
#define plll pair<ll,pll>
#define plii pair<ll,pii>
#define no {cout<<"no"<<endl;return;}
#define yes {cout<<"yes"<<endl;}
#define rep(i,N) for(int i=0;i<N;i++)
const int maxn=1e6;
const int mod=998244353;
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int arr[maxn+1];
ll dp[maxn+1];
int n;
int Max=1;
bool isprime[maxn+1];
int cnt[maxn+1]={0};
vector<int> prime;
int lpf[maxn+1]={0};
void sieve(){
    lpf[1]=1;
    for(int p=2;p<=Max;p++){
        if(lpf[p]==0){
            lpf[p]=p;
            for(int q=p+p;q<=Max;q+=p){
                if(!lpf[q]) lpf[q]=p;

            }
        }
    }
    /*
    for(int p=2;p<=Max;p++){
        cout<<p<<" "<<lpf[p]<<endl;
    }
    */
    return;
}
bool p(){

    sieve();
    int l,a;
    for(int i=1;i<=n;i++){
        a=arr[i];
        while(a!=1){
            l=lpf[a];
            while(a%l==0) a/=l;
            if(cnt[l] && l!=1) return(false);
            cnt[l]++;

        }
    }

    return(true);

}
bool s(){
    int g=arr[1];
    for(int i=1;i<=n;i++){
        g=__gcd(g,arr[i]);
        if(g==1) return(true);
    }
    return(false);
}
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++) {cin>>arr[i];Max=max(Max,arr[i]);}
    if(p()){
        cout<<"pairwise coprime";

    }
    else if(s()){
        cout<<"setwise coprime";
    }
    else{
        cout<<"not coprime";
    }
    return;
}
int main(){
    IO
    //TEST
    solve();
    return(0);
}
/*
2
3 3
2500 2500 2520
10 -5 -20
10 15 20
-15 17 13
2 3
2125 2098
-20 10 -10
10 10 -20
*/
/*
1
3 3
2500 2500 2520
10 -5 -20
10 15 20
-15 17 13

*/


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



const int inf = 2e9;

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

    int n, m, k;
    cin>>n>>m>>k;
    vector<ll> a(n+1), b(m+1);
    for (int i=0; i<n; i++) {
	cin>>a[i+1];
	a[i+1]+=a[i];
    }
    for (int i=0; i<m; i++) {
	cin>>b[i+1];
	b[i+1]+=b[i];
    }

    int res = 0;
    for (int i=0; i<=n && a[i]<=k; i++) {
	int j = prev(upper_bound(b.begin(),b.end(),k-a[i]))-b.begin();
	//cout<<i<<": "<<j<<endl;
	res=max(res,i+j);
    }

    cout<<res<<endl;
  
    return 0;
}


Measured memory_bytes: 6368
#include<cstdio>
#include<iostream>
#include<cmath>
#include<string>
#include<vector>
using namespace std;

char flip(char i) {
  if (i == 'S') return 'W';
  else return 'S';
}

char s_next(char op, char prev) {
  if (op == 'o') return prev;
  if (op == 'x') return flip(prev);
}

char w_next(char op, char prev) {
  if (op == 'o') return flip(prev);
  if (op == 'x') return prev;
}

int main() {
  int n;
  string input;
  cin >> n >> input;
  auto x = vector<string>({"SS", "SW", "WS", "WW"});
  
  string shin = "-1";
  for (auto start : x) {
    auto ans = start;
    int ansIdx = 1;    
    for(int i = 0; i < n; i++) {
      if (ans[ansIdx] == 'S') {
        ans += s_next(input[i], ans[ansIdx - 1]);
      } else {
        ans += w_next(input[i], ans[ansIdx - 1]);
      }
      ansIdx++;
    }
    if (ans[0] == ans[ans.length() - 2] &&
        ans[1] == ans[ans.length() - 1]) {
      shin = ans.substr(1, n);
    }
  }
  cout << shin << endl;
}


Measured memory_bytes: 736
N, C, K = map(int, input().split())
T = sorted(map(int, (input() for _ in range(N))))
ans = 0
count = 0
bus = None
for t in T:
    tk = t + K
    if bus is None or bus < t or count + 1 > C:
        bus = tk
        count = 0
        ans += 1
    count += 1
print(ans)


Measured memory_bytes: 7396
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)
const ll INF = 1LL << 60;


int main(){
    int n;
    string s;
    cin >> s;
    if (s[0] == s[1] && s[1] == s[2]) cout << "Yes" << endl;
    else if (s[1] == s[2] && s[2] == s[3]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> ord(N);
  vector<int> sat(N);
  vector<int> addsat(N - 1);
  int sum = 0;
  rep(i, N) cin >> ord.at(i);
  rep(i, N) {
    int x;
    cin >> x;
    sum += x;
  }
  rep(i, N - 1) cin >> addsat.at(i);

  rep(i, N - 1) {
    if (ord.at(i + 1) - ord.at(i) == 1)
      sum += addsat.at(ord.at(i) - 1);
  }
  cout << sum << endl;
}


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

class Main implements Runnable {

	public Main() {}
	static class Node 
	{
		int u,v,w;
		Node(int a, int b, int c)
		{
			u = a;
			v = b;
			w = c;
		}
		
	}
	static LinkedList<Node>[] adj ;
	static int n;
	static int[] color;
	public static void main(String[] args) {
		new Thread(null, new Main(),"Pratham", 1<<27).start();
	}
	public void run() {
		FastScanner s = new FastScanner();
		n = s.nextInt();
		adj = new LinkedList[n];
		for(int i = 0; i<n;i++) adj[i] = new LinkedList<>();
		
		for(int i = 0 ;i < n-1 ; i++)
		{
			int u = s.nextInt() - 1;
			int v = s.nextInt() - 1;
			int w = s.nextInt() ;
			adj[u].add(new Node(u,v,w));
			adj[v].add(new Node(v,u,w));
		}
		color = new int[n];
		dfs(0,-1);
		StringBuilder sb = new StringBuilder();
		for(int i  = 0;i<n;i++)
			sb.append(color[i]+"\n");
		System.out.print(sb+"");
	}
	
	static void dfs(int u , int p)
	{
		for(Node V : adj[u])
		{
			int v = V.v;
			if(v != p)
			{
				int w = V.w;
				if(w % 2 == 0)
				{
					color[v] = color[u];
				}
				else
				{
					color[v] = 1 - color[u];
				}
				dfs(v, u);
			}
		}
	}
	
	
	
static   class FastScanner {
		
	    private InputStream mIs;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner() {
			this(System.in);
		}

		public FastScanner(InputStream is) {
			mIs = is;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = mIs.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		
		}	

	}

}


Measured memory_bytes: 68956
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N,x;
int a[MAXN];
vector<int> l,r;
deque<int> q;
void Solve() {
    read(N);read(x);
    if(x == 1 || x == 2 * N - 1) {puts("No");return;}
    puts("Yes");
    for(int i = 1 ; i < x ; ++i) l.pb(i);
    for(int i = x + 1 ; i <= 2 * N - 1 ; ++i) r.pb(i);
    q.pb(x);
    bool f = 0;
    while(l.size() && r.size()) {
        if(f) {
            q.push_back(l.back());
            q.push_front(r.back());
        }
        else {
            q.push_back(r.back());
            q.push_front(l.back());
        }
        l.pop_back();r.pop_back();
        f ^= 1;
    }
    if(r.size() > l.size()) swap(l,r);
    while(l.size()) {
        q.push_back(l.back());
        l.pop_back();
        q.push_front(l.back());
        l.pop_back();
    }
    for(int i = 0 ; i < 2 * N - 1 ; ++i) {out(q[i]);space;}
    enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N,K;
int x[100100];
int main(){
	cin >> N >> K;
	for(int i=0;i<N;i++)cin >> x[i];
	int ans = INF;
	for(int i=0;i<=N-K;i++){
		int base = x[i+K-1]-x[i];
		if(x[i]>0)base += x[i];
		else if(x[i+K-1]<0)base -= x[i+K-1];
		else{
			base += min(-x[i],x[i+K-1]);
		}
		ans = min(ans,base);
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
using namespace std;
int main()
{

  ll n,T;
  ll t[200010];
  cin>>n>>T;
  rep(i,n)cin>>t[i];

  ll ans=0;


  reps(i,n){
    if(t[i]-t[i-1]>=T){
      ans+=T;
    }else{
      ans+=t[i]-t[i-1];
    }
  }
  ans+=T;
  cout<<ans<<endl;
  return 0;
}


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

int main() {
  int n,k,x,y;
  cin >>n >>k >>x >>y;
  if(n>k){
    cout <<(x*k+(n-k)*y) <<endl;
  }
  else{
    cout <<n*x <<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
using namespace std;
using ll = long long;


struct Edge {
	int to, ort, rev;
};

vector<vector<Edge>> edg;
vector<int> cntout;
vector<pair<int, int>> par;

int main() {
	int n, m; cin >> n >> m;
	if (m & 1) {
		cout << -1 << endl;
		return 0;
	}
	edg = decltype(edg)(n);
	cntout = decltype(cntout)(n);
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		a--; b--;
		edg[a].push_back({ b, 1, (int)edg[b].size() });
		edg[b].push_back({ a, -1, (int)edg[a].size() - 1 });
		cntout[a]++;
	}

	deque<int> que;
	par = decltype(par)(n, { -1, -1 });
	{
		bool vis[100003] = {};
		deque<int> q;
		q.push_back(0);
		while (!q.empty()) {
			int pos = q.front();
			q.pop_front();
			vis[pos] = true;
			bool flag = true;
			for (int i = 0; i < (int)edg[pos].size(); i++) {
				auto e = edg[pos][i];
				if (vis[e.to]) continue;
				flag = false;
				vis[e.to] = true;
				par[e.to] = { pos, i };
				q.push_back(e.to);
			}
			if (flag) que.push_back(pos);
		}
	}
	while (!que.empty()) {
		int pos = que.front();
		que.pop_front();
		if ((cntout[pos]&1) && par[pos].first != -1) {
			auto &e = edg[par[pos].first][par[pos].second];
			e.ort *= -1;
			edg[e.to][e.rev].ort *= -1;
			cntout[pos]--;
			cntout[par[pos].first]++;
		}
		if (par[pos].first != -1) que.push_back(par[pos].first);
	}


	bool check = true;
	for (int i = 0; i < n; i++) {
		check &= cntout[i] % 2 == 0;
	}
	if (!check) {
		cout << "-1" << endl;
		return 0;
	}
	for (int i = 0; i < n; i++) {
		for (const auto &e : edg[i]) {
			if (e.ort == 1) {
				cout << i + 1 << " " << e.to + 1 << endl;
			}
		}
	}
	return 0;
}



Measured memory_bytes: 9344