akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;//typo用
using uintl = unsigned long long;
using itn = int;//typo用
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a) - 1; i >= (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl//1次元配列の出力
#define rrdebug(i, j, x) rep(i, alength(x))rep(j, alength(x[i]))cout << #x << "[" << i << "][" << j << "]:" << x[i][j] << endl//二次元配列の出力
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return true;} return false; }
intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); }
intl lcm(intl a,intl b){ return a / gcd(a, b) * b; }
intl kai(intl k){//k!を求める関数,
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl digit10(intl a){//aを10進数で表したときの桁数を求める関数
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}

//--------------入力受け取る場所----------------------------------------------------
intl n,q;
intl a[200000],b[200000],p[200000],x[200000];
vector<vector<intl> > v;
intl ans[200001];
bool f[200001];
void input_var(){
    cin >> n >> q;
    rep(i,n - 1)cin >> a[i] >> b[i];
    rep(i,q)cin >> p[i] >> x[i];
    v.resize(n + 1);
}
//-------------------------------------------------------------------------------

void dfs(intl node, intl sum){
    //debug(node);
    if(f[node])return;
    f[node] = true;
    ans[node] += sum;
    if(v[node].empty())return;
    for(auto i: v[node]){
        dfs(i, ans[node]);
    }
}

signed main(){
    cout << fixed << setprecision(10);
    input_var();
    m0(ans);
    m0(f);
    rep(i,n){
        v[a[i]].pb(b[i]);
        v[b[i]].pb(a[i]);
    }
    rep(i,q){
        ans[p[i]] += x[i];
    }
    dfs(1,0);
    repi(i,1,n + 1)cout << ans[i] << " ";
    return 0;
}


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

int main()
{
    cin >> n;
    vector<ll> lu(n+1);
    lu[0] = 2;
    lu[1] = 1;

    for(ll i = 2; i <= n; ++i)
    {
        lu[i] = lu[i-1] + lu[i-2];
    } 
    cout << lu[n];
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int N,M;cin>>N>>M;
	int A[N];int sum=0; int cnt=0;
	rep(i,0,N){ cin>>A[i]; sum+=A[i]; }
	rep(i,0,N){
		if(A[i]*4*M >= sum) cnt++;
	}
	if(cnt >= M) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

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

int main()
{
	int n;
	cin >> n;
	int A[n], all = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> A[i];
		all ^= A[i];
	}

	for(int i = 0; i < n; i++)
		cout << (all ^ A[i]) << " ";
	cout << endl;
	return 0;
}


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

using namespace std;

string s;
int a[555];
int n;
int K;
int at;


int main() {
    cin >> n >> K;
    int tot = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        tot+=a[i];
    }

    vector<int> divs;
    for(int i = 1; i*i <= tot; i++) {
        if(tot % i == 0) {
            divs.push_back(i);
            divs.push_back(tot/i);
        }
    }
    sort(divs.begin(), divs.end());
    int sz = divs.size();
    sort(a, a+n);
  
    for(int p = 0; p < divs.size(); p++) {

        int j = divs[sz-1-p];
        
        if(tot % j != 0) continue;

        at = j;

        long long tot_extra = 0;
        vector<int> extras;
        for(int i = 0; i < n; i++) {
            tot_extra += (at - (a[i] % at));
            extras.push_back((at - (a[i] % at)));
        }   
        
        sort(extras.begin(), extras.end());
        
        int x = tot_extra/at; // these many subtractions of 'at' needed to make it zero
        
        long long neg = 0;
        
        for(int i = 0; i < x ; i++) {
            // convert from addition to subtraction from largest additions, 
            // that ensures less chance of exceeding K
            neg += (at - extras[n-1-i]);
            tot_extra -= extras[n-1-i];
        }
        if(neg <= K) {cout << at; return 0;}
        
    

        
    }


}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;

int partion(vector<int>& a, int p, int r) {
  int x = a[r], i = p - 1;
  FOR(j, p, r) {
    if (a[j] <= x) {
      swap(a[++i], a[j]);
    }
  }
  swap(a[i + 1], a[r]);
  return i + 1;
}

int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  q = partion(a, 0, n - 1);

  rep(i, q) {
    if (i) cout << " ";
    cout << a[i];
  }
  cout << " " << "[" << a[q] << "]";
  FOR(i, q + 1, n) {
    cout << " " << a[i];
  }
  cout << endl;

  
  return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
vector<pair<string,pair<int,int>>> v;
int main()
{
    int n;
    cin >> n;
    for(int i=1;i<=n;i++) {
        string s;
        int p;
        cin >> s >> p;
        v.emplace_back(s,make_pair(-p,i));
    }

    sort(v.begin(),v.end());

    for(auto j : v) cout << j.second.second << endl;
}


Measured memory_bytes: 256
def findnxt(x):
	i=len(x)-1
	if x[i]==9:
		while True:
			if i==0 :
				break
			if(x[i]<=x[i-1] and x[i]!=9):
				break
			i-=1
		if x[i]==9:
			x.insert(0,1)
			for j in range(1,len(x)):
				x[j]=0
		else:
			x[i]+=1
			i+=1
			while i<len(x):
				if x[i-1]:
					x[i]=x[i-1]-1
				else:
					x[i]=0
				i+=1
	else:
		while i:
			if x[i]<=x[i-1]:
				break
			i-=1
		x[i]+=1
		i+=1
		while i<len(x):
			if x[i-1]:
				x[i]=x[i-1]-1
			else:
				x[i]=0
			i+=1
	return x
	
x=[1]
k=int(input())
for l in range(2,k+1):
	x=findnxt(x)
for l in x:
	print(l,end='')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;
 
ll N, K;
 
int main(void) {
  cin >> N >> K;
 
  ll ans = (1LL << 60);
  ll s = 1;
  REP(i, 0, N + 1) {
    ans = min(ans, s + (N - i) * K);
    s *= 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//============================================================================
// 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

//============================================================================
#define PI 3.14159265359
#define succ(x) ((x)+1)
#define pred(x) ((x)-1)
//============================================================================
void enter()
{
    int n,i,x;

    scanf("%d", &n);
    for (i=1; i<=n; i++){
        if (i % 3 ==0){
            printf(" %d", i);
            continue;
        }
        for (x=i; x; x/=10)
            if (x % 10 ==3){
                printf(" %d", i);
                break;
            }
    }
    printf("\n");
}
/*void call(int n)
{
    int i = 1;

    CHECK_NUM:
    int x = i;
    if ( x % 3 == 0 ){
        cout << " " << i;
        goto END_CHECK_NUM;
    }

    INCLUDE3:
    if ( x % 10 == 3 ){
        cout << " " << i;
        goto END_CHECK_NUM;
    }
    x /= 10;
    if ( x ) goto INCLUDE3;

    END_CHECK_NUM:
    if ( ++i <= n ) goto CHECK_NUM;

    cout << endl;
}*/
//============================================================================
int main(void)
{
    enter();
    return 0;
}
//============================================================================

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

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

int main() 
{
    int n;
    cin >> n;
    int a[n];
    rep(i,n) cin >> a[i];

    int lg[n];
    lg[0] = a[0];
    for(int i=1; i<n; i++) lg[i] = gcd(lg[i-1], a[i]);
    int rg[n];
    rg[n-1] = a[n-1];
    for(int i=n-2; i>=0; i--) rg[i] = gcd(rg[i+1], a[i]);

    int ans = 0;
    rep(i,n) {
        if (i==0) {
            ans = max(ans, rg[1]);
        } else if (i==n-1) {
            ans = max(ans, lg[n-2]);
        } else {
            ans = max(ans, gcd(lg[i-1], rg[i+1]));
        }        
    }

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


Measured memory_bytes: 1408
from collections import deque
N,M = map(int,input().split())
edge = [[] for i in range(N)]
for i in range(M):
	A,B = map(int,input().split())
	A -= 1
	B -= 1
	edge[A].append(B)
	edge[B].append(A)

q = deque([(0, None)])
searched = [False for i in range(N)]
ans = [-1 for i in range(N)]
while len(q) > 0:
	after, before = q.popleft()
	if searched[after]:
		continue
	searched[after] = True
	ans[after] = before
	for n in edge[after]:
		if searched[n]:
			continue
		q.append((n, after))

flag = True
for i in range(1, N):
	if ans[i] == -1:
		flag = False
		break

if flag:
	print("Yes")
	for i in range(1, N):
		print(ans[i] + 1)
else:
	print("No")

Measured memory_bytes: 40720
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define vvvel vector<vvel>
void mmin(int &a, int b) {
	a = min(a, b);
}
void mmax(int &a, int b) {
	a = max(a, b);
}
void sor(vel &v) {
	sort(v.begin(), v.end());
}
int ser(vel &v, int tan) {
	int si = v.size() - 1;
	if (tan == v[si]) {
		return si;
	}
	int lo = 0;
	int up = si;
	while (up - lo > 1) {
		int mi = (lo + up) / 2;
		if (v[mi] <= tan) {
			lo = mi;
		}
		else {
			up = mi;
		}
	}
	return lo;
}
signed main() {
	int n;
	cin >> n;
	vel c(n);
	vel po(n, 1000000000);
	int ko = 0;
	int sum = 0;
	vel a(n);
	vel b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < n; i++) {
		c[i] = a[i] - b[i];
		sum += c[i];
		if (c[i] >= 0) {
			po[ko] = c[i];
			ko++;
		}
	}
	sort(po.begin(), po.end());
	if (sum >= 0) {
		int i = 0;
		while (sum >= 0) {
			if (i < n) {
				sum -= po[i];
				i++;
			}
			else {
				sum = -1;
				i++;
			}
		}
		cout << n-i+1 << endl;
	}
	else {
		cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <map>
#include <functional>

using namespace std;


int main() {
	int a, b;
	cin >> a >> b;;
	if ((a * b)%2 == 0) {
		cout << "Even" << endl;
	} else {
		cout << "Odd" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int> a(3);cin>>a[0]>>a[1]>>a[2];
  sort(a.begin(),a.end());
  int k;cin>>k;
  for(int i=0;i<k;i++)a[2]*=2;
  cout<<a[0]+a[1]+a[2]<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
long long a=0,b=0,x=0,c=0;
cin>>a>>b>>x;
if(a>0){
	a-=1;
	c=(b/x)-(a/x);
}
else{
	c=b/x;
	c++;
}
cout<<c;
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod ((int)1e9+7)
using namespace std;
typedef pair<int,int> pi;
typedef long long int ll;

const int N = (int)2e5+5;
vector<int> v[N];
ll power(ll a,ll b) {
    if (b==0) return 1;
    ll c = power(a,b>>1);
    c = (c*c)%mod;
    if (b&1) return (c*a)%mod;
    return c;
}
ll f[N], inv[N], dp[N], ans[N];
ll comb(int n,int r) {
    return (f[n]*((inv[r]*inv[n-r])%mod))%mod;
}
int cnt[N];
void dfs(int i,int p) {
    cnt[i] = 1;
    for(auto it:v[i]) {
        if(it!=p) {
            dfs(it,i);
            cnt[i] += cnt[it];
        }
    }
    int n = cnt[i]-1;
    dp[i] = 1;
    for(auto it:v[i]) {
        if(it!=p) {
            dp[i] *= (comb(n,cnt[it])*dp[it])%mod;
            dp[i] %= mod;
            n -= cnt[it];
        }
    }
}
int n;
void run(int i,int p) {
    ans[i] = dp[i];
    for(auto it:v[i]) {
        if(it!=p) {
            int t = (comb(n-1,cnt[it])*dp[it])%mod;
            dp[i] = (dp[i]*power(t,mod-2))%mod;
            int s = (comb(n-1,n-cnt[it])*dp[i])%mod;
            dp[it] = (dp[it]*s)%mod;
            run(it,i);
            dp[it] = (dp[it]*power(s,mod-2))%mod;
            dp[i] = (dp[i]*t)%mod;
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    f[0] = 1;
    for(int i=1;i<N;i++) {
        f[i] = (f[i-1]*i)%mod;
    }
    inv[N-1] = power(f[N-1],mod-2);
    for(int i=N-2;i>=0;i--) {
        inv[i] = (inv[i+1]*(i+1))%mod;
    }
    cin>>n;
    for(int i=1,x,y;i<n;i++) {
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(1,1);
    run(1,1);
    for(int i=1;i<=n;i++) {
        cout<<ans[i]<<"\n";
    }
}


Measured memory_bytes: 20980
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[100002],b[100002],c[100002],i,j,k,v[300001],l;
long long nr12,nr,nr1;
int main()
{
    cin>>n;
    for(i=1;i<=n;i++) cin>>a[i];
    for(i=1;i<=n;i++) cin>>b[i];
    for(i=1;i<=n;i++) cin>>c[i];
    k=0;
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    sort(c+1,c+n+1);
    a[n+1]=1<<30;
    b[n+1]=1<<30;
    c[n+1]=1<<30;
    i=j=l=1;
    while(k<3*n)
    {
        if(c[l]<=b[j]&&c[l]<=a[i]) {v[++k]=3;l++;}
        else if(b[j]<=c[l]&&b[j]<=a[i]) {v[++k]=2;j++;}
        else if(a[i]<=b[j]&&a[i]<=c[l]) {v[++k]=1;i++;}
    }
    for(i=1;i<=3*n;i++)
    {
        switch(v[i])
        {
            case 1:nr1++; break;
            case 2:nr12+=nr1; break;
            case 3:nr+=nr12; break;
        }
    }
    cout<<nr;
    return 0;
}


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

#define MAXN (100010)
#define mod (1000000007)

int n;
int x[MAXN];

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; ++ i){
		scanf("%d", x + i);
	}
	int ans = 1;
	for(int i = 1, j = 1; i <= n; ++ i){
		while(j < n && x[j] >= 2 * (j - (i - 1)) - 1) 
		    ++ j;
		ans = (1ll) * ans * (j - i + 1) % mod;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 768
def main():
  n = int(input())
  num_set = list(map(int, input().split()))
  if n < 3:
    print(0)
    exit()
  cnt = 0
  for i in range(len(num_set)):
    for j in range(i+1, len(num_set)):
      for k in range(j+1, len(num_set)):
        if num_set[i]==num_set[j] or num_set[i]==num_set[k] or num_set[j]==num_set[k]:
          continue
        if num_set[i]+num_set[j] > num_set[k] and num_set[k]+num_set[j] > num_set[i] and num_set[i]+num_set[k] > num_set[j]:
          cnt += 1
  print(cnt)
if (__name__=='__main__'):
  main()

Measured memory_bytes: 9168
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,b,c,=INTM()
    if a<=c and c<=a+b:
        print('YES')
    else:
        print('NO')
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
    int n,ma,mb;
    cin >> n >> ma >> mb;
    int a[n],b[n],c[n];
    for(int i = 0;i<n;i++) cin >> a[i] >> b[i] >> c[i];
    int dp[450][450];
    for(int i = 0;i<450;i++) for(int j = 0;j<450;j++) dp[i][j] = 1e5;
    dp[0][0] = 0;
    for(int i = 0;i<n;i++){
        for(int j = 400;j>=0;j--){
            for(int k = 400;k>=0;k--){
                dp[j+a[i]][k+b[i]] = min(dp[j+a[i]][k+b[i]],dp[j][k]+c[i]);
                //dp[j][k] = min(dp[j][k],dp[j][k]);
            }
        }
    }
    int ans = 5000;
    int mma = ma;
    int mmb = mb;
    while(ma<=410 && mb<=410){
        ans = min(ans,dp[ma][mb]);
        ma+=mma;
        mb+=mmb;
    }
    if(ans == 5000) cout << -1 << endl;
    else cout << ans << endl;

    /*for(int i = 0;i<=6;i++){
        for(int j = 0;j<=6;j++){
            cout << dp[i][j] << " "; 
        }
        cout << endl;
    }*/
}

Measured memory_bytes: 1024
A,B,N=map(int,input().split())
max_L=0
x=0
if B>N:
	x=N
	max_L=int(A*x/B)-A*int(x/B)
else:
	x=B-1
	max_L=int(A*x/B)-A*int(x/B)

print(max_L)

Measured memory_bytes: 9144
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc045/tasks/abc045_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(a, b, h):
    return (a + b) * h // 2


def main(args):
    a = int(input())
    b = int(input())
    h = int(input())
    ans = solve(a, b, h)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    long long int a[n];
    for(int i=0;i<n;i++)cin >> a[i];
    sort(a,a+n);
    long long int mod=1e9+7;
    long long int ans=1;
    vector<long long int> plus;
    vector<long long int> minus;
    for(int i=0;i<n;i++){
        if(a[i]<0)minus.push_back(a[i]);
        else plus.push_back(a[i]);
    }
    if(n==k){
        int t=0;
        for(int i=0;i<k;i++){
            ans *= abs(a[i]);
            ans %= mod;
            if(a[i]<0)t++;
        }
        if(t%2==1 && ans!=0)cout << mod - ans;
        else cout << ans;
    }
    else if(a[n-1]<0 && k%2==1){
        for(int i=0;i<k;i++){
            ans *= abs(a[n-1-i]);
            ans %= mod;
        }
        cout << mod - ans;
    }
    else{
        int p;
        long unsigned int m;
        int count=0;
        p=plus.size()-1; m=0;
        while(count<k){
            while((m+1<minus.size() && p-1>=0) && count+2<=k){
                if(minus[m]*minus[m+1]>=plus[p]*plus[p-1]){
                ans *= ((minus[m]*minus[m+1])%mod);
                ans %= mod;
                m+=2;
                count+=2;
                }
                else break;
            }
            while(p<0 && count+1<=k){
                ans *= abs(minus[m]);
                ans %= mod;
                m++;
                count++;     
            }
            if(p==0 && (count<k && (k-count)%2==0)){
                while(count+1<=k){
                    ans *= abs(minus[m]);
                    ans %= mod;
                    m++;
                    count++;     
                }                
            }
            if(count+1<=k && p>=0){
                ans *= plus[p];
                ans %= mod;
                p--;
                count++;                
            }
        }
        cout << ans;
    }
}

Measured memory_bytes: 6996
#include<math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long int
#define ull unsigned long long
#define py printf("Yes\n")
#define pn printf("No\n")
#define in cin>>
using namespace std;
int INF = 1001001001;
const int MOD=1e9+7;

int main()
{
  int n ,k,ans=0;
  in n>>k;
  vector<int>p(n);
  rep(i,n)
  {
    in p[i];
  }
  sort(p.begin(), p.end());
  rep(i,k)
  {
    ans+=p[i];
  }
  cout<<ans<<endl;
}


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

int n, k, x, y, ans;
char c;
int b[1010][1010][2];

inline int get_num()
{
	int now = 0;
	char ch = getchar();
	while(!isdigit(ch)) ch = getchar();
	while(isdigit(ch)){
		now = (now << 1) + (now << 3) + ch - '0';
		ch = getchar();
	}
	return now;
}

inline char get_char()
{
	char ch = getchar();
	while(ch != 'B' && ch != 'W') ch = getchar();
	return ch;
}

int main()
{
	n = get_num(), k = get_num();
	for(int i = 1; i <= n; ++i){
		x = get_num(), y = get_num(), c = get_char();
		int sx = x, sy = y;
		x = x % k, y = y % k;
		if(x == 0) x = k;
		if(y == 0) y = k;
		if((abs(sx - x) + abs(sy - y)) / k % 2 == 1){
			if(c == 'W') c = 'B';
			else c = 'W';
		}
		if(c == 'W') b[x][y][0]++;
		else if(c == 'B') b[x][y][1]++;
	}
	for(int i = 1; i <= k; ++i){
		for(int j = 1; j <= k; ++j){
			b[i][j][0] += b[i - 1][j][0] + b[i][j - 1][0] - b[i - 1][j - 1][0];
			b[i][j][1] += b[i - 1][j][1] + b[i][j - 1][1] - b[i - 1][j - 1][1];
		}
	}
	for(int i = 0; i <= k; ++i){
		for(int j = 0; j <= k; ++j){
			ans = max(ans, b[k][k][0] - b[i][k][0] - b[k][j][0] + 2 * b[i][j][0]
					 + b[i][k][1] + b[k][j][1] - 2 * b[i][j][1]);
			ans = max(ans, b[k][k][1] - b[i][k][1] - b[k][j][1] + 2 * b[i][j][1]
					 + b[i][k][0] + b[k][j][0] - 2 * b[i][j][0]);
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 8192
#include<iostream>
#include<vector>
#include<queue>

using namespace std;



int main(){
	while(1){
		int n,a,b,c,x; cin >> n >> a >> b >> c >> x;
		if (n + a + b + c + x == 0)break;
		vector<int> rand(n);
		for (int i = 0; i < n; i++){	
			cin >> rand[i];
		}
		int look = 0;
		int ans = 0;
		for (int i = 0; i <= 10000; i++){
			ans = i;
			if (rand[look] == x) look++;
			x = (a * x + b) % c;
			if (look == rand.size()) break;
		}
		if (look < rand.size()){
			cout << -1 << endl;
		}else{
			cout << ans << endl;
		}
	}


return 0;
}

Measured memory_bytes: 3120
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long M = sc.nextLong();
        long c = 0;

        if (M >= 2 * N) {
            c = N;
            M -= 2 * N;
            N = 0;
        } else {
            c = M / 2;
            M = M % 2;
        }
        c += M / 4;

        System.out.println(c);
    }
}


Measured memory_bytes: 23892
import sys
sys.setrecursionlimit(100000)

from collections import defaultdict



class Graph:

    def __init__(self, N):
        self.graph = defaultdict(list)
        self.N = N
        self.memo = [-1] * (N+1)
        self.tovisit = set(range(1, N+1))

    def add_edge(self, x, y):
        self.graph[x].append(y)

    def _longest_path(self, node):
        if self.memo[node] == -1:
            res = 0
            for y in self.graph[node]:
                res = max(res, 1 + self._longest_path(y))

            self.memo[node] = res
            self.tovisit.discard(node)

        return self.memo[node]

    def longest_path(self):
        while self.tovisit:
            self._longest_path(self.tovisit.pop())

        res = 0
        for i in range(1, self.N+1):
            res = max(res, self.memo[i])

        return res


def main():

    N, M = map(int, input().split())
    graph = Graph(N)
    for _ in range(M):
        x, y = map(int, input().split())
        graph.add_edge(x, y)

    ans = graph.longest_path()
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 124704
import sys
input = sys.stdin.readline
# int(input()) # 入力が1つ
n, k = map(int, input().split()) # 入力が複数
# [int(i) for i in input().split()] # 配列で数字

ans = 0

while n:
    ans += 1
    n //= k
print(ans)

Measured memory_bytes: 38256
n = int(input())
p = [int(x) for x in input().split()]

# 最初はカウントされるから1
ans = 1
base = p[0]

for i in range(1, n):
    if p[i] < base:
        ans += 1
        # pi番目がbaseより小さかったら更新
        base = p[i]

print(ans)

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

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int r = Integer.parseInt(reader.readLine());

            System.out.println(3 * r * r);
        }
    }

}


Measured memory_bytes: 21204
mod = 10 ** 9 + 7

N, *A = map(int, open(0).read().split())

B = [0] * 62
for a in A:
    for i in range(62):
        if a >> i & 1:
            B[i] += 1

ans = 0
for i, b in enumerate(B):
    ans += ((N - b) * b % mod) * pow(2, i, mod)
    ans %= mod

print(ans)


Measured memory_bytes: 156172
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  map<string,int> m;
  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    int t,x;
    string s;
    cin>>t>>s;
    if(t==0) cin>>x;
    if(t==0) m[s]=x;
    if(t==1) cout<<m[s]<<endl;
    if(t==2) m.erase(s);
  }
  return 0;
}



Measured memory_bytes: 27796
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
  int H, W;
  cin >> H >> W;
  char c;
  vector<vector<int>> A(H, vector<int>(W));
  queue<pair<int,int>> q;
  for (int i = 0; i != H; ++i) {
    for (int j = 0; j != W; ++j) {
      cin >> c;
      if (c == '#') {
        ++A[i][j];
        q.emplace(i,j);
      }
    }
  }

  int ans{-1};
  while (!q.empty()) {
    ++ans;
    int n = q.size();
    for (int i = 0; i != n; ++i) {
      auto [h,w] = q.front();
      q.pop();
      if (h-1 >= 0 && !A[h-1][w]) ++A[h-1][w], q.emplace(h-1,w);
      if (h+1 < H && !A[h+1][w]) ++A[h+1][w], q.emplace(h+1,w);
      if (w-1 >= 0 && !A[h][w-1]) ++A[h][w-1], q.emplace(h,w-1);
      if (w+1 < W && !A[h][w+1]) ++A[h][w+1], q.emplace(h,w+1);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 15272
#include<iostream>
#include<vector>
typedef long long ll;
typedef long double ld;
using namespace std;
int main() {
	ll N;
	cin >> N;
	vector<ll>a(N);
	for (ll i = 0; i < N; i++) {
		cin >> a[i];
	}
	ll dp[10001];
	for (ll i = 0; i <=10000; i++) {
		dp[i] = 0;
	}
  	dp[0]=1;
	for (ll i = 0; i < N; i++) {
		for (ll j = 10000; j >= 0; j--) {
			if (a[i] + j <= 10000) {
				if (dp[j])  dp[j + a[i]] =1;
			}
		}
	}
	for (ll i = 10; i <= 10000; i += 10) 
		dp[i] = 0;
    ll x=0;
	for (ll i = 0; i <=10000; i++) {
		if (dp[i])x=i;
    }
       cout<<x<<endl;
}













Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef long long ll;
#define loop(i,n) for(int i=0;i<n;i++)
#define inf 10000000000 //10^10
#define pi 3.141592

int main(){
    int n,m;
    for(cin >> n >> m ; n!=0 ;cin >> n >> m){
        vint d(n);
        vector<pair<int,int> > p(n);

        loop(i,n){
            int d_i,p_i;
            cin >> d_i >> p_i;
            d[i]=d_i;
            p[i]=make_pair(p_i,i); //インデックスを管理
        }
        
        int hazard=0;
        loop(i,n) hazard+=d[i]*p[i].first;

        sort(p.begin(),p.end(), [](pair<int,int> x,pair<int,int> y)->int {return x.first>y.first;});
        
        loop(i,n){
            int rest=d[p[i].second];
            if(m<rest){
                hazard-=m*p[i].first;
                break;
            }else{
                m-=rest;
                hazard-=rest*p[i].first;
            }
        }
        cout << hazard << endl;
    }
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  srand((unsigned)time(NULL));
  ll X;
  cin >> X;
  ll ans = INF;
  if(X<=599) ans = 8;
  else if(X<=799) ans = 7;
  else if(X<=999) ans = 6;
  else if(X<=1199) ans = 5;
  else if(X<= 1399) ans = 4;
  else if(X<=1599) ans = 3;
  else if(X<=1799) ans = 2;
  else ans = 1;
  cout << ans << endl;

}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 h, w, a, b;
int main() {
  cin >> h >> w >> a >> b;
  for (i64 i = 0; i < h; ++i) {
    for (i64 j = 0; j < w; ++j) {
      char c = '0';
      if ((i < b && j < a) || (i >= b && j >= a)) c = '1';
      cout << c;
    }
    cout << '\n';
  }
  return 0;
}



Measured memory_bytes: 1280
#include<stdio.h>
int main(void){
    char bx,fx,comx;
    int i;
    int fg;
    int sgg;
    i=0;
    fg=0;
    sgg=0;
    while(1){
        scanf("%c",&fx);
        if(fx==' '){
            comx=bx;
            sgg=1;
        }else if(sgg==1){
            if(comx==fx){
                sgg=0;
            }else{
                fg=99;
            }
        }
        if(fx=='\n'){
            break;
        }
        bx=fx;
    }
    if(fg!=0){
        printf("NO\n");
    }else{
        printf("YES\n");
    }
    return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int n; cin >>n;
  vector<char> a(n);
  rep(i,n)cin>>a[i];
  bool p=false;
  bool w=false;
  bool y=false;
  bool g=false;
  rep(i,n){
    if(a[i]=='P')p=true;
    else if(a[i]=='W')w=true;
    else if(a[i]=='Y')y=true;
    else if(a[i]=='G')g=true;
  }
  if(p+w+y+g==3)cout<<"Three"<<endl;
  else cout<<"Four"<<endl;
  return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn.readLine
import Math.sqrt

object Main {

  def main(args: Array[String]) = {
      val n = readLine.split(" ").map(_.toInt)
      var cnt = 0
      for(i <- n(0) to n(1))
          if(n(2) % i == 0)
              cnt += 1
      println(cnt)
  }
}

Measured memory_bytes: 43972
(N,),r,*L=$<.map{_1.split.map &:to_i}
l=(n=*0..N).map{[1e9]*$.}
L.map{l[_1][_2]=l[_2][_1]=_3}
n.map{|k|n.map{|i|n.map{|j|(l[i][j]>t=l[i][k]+l[k][j])&&l[i][j]=t}}}
p r.permutation.map{|b,*a|a.sum{l[b][b=_1]}}.min

Measured memory_bytes: 145908
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  char c;
  int n = 0;
  for (int i =0; i < N; i++){
    cin >> c;
    if (c == 'Y'){
      n = 1;
      break;
    }
  }
  if (n == 1){
    cout << "Four"<<endl;
  }
  else{
    cout << "Three"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  if (a >= k)
  {
    cout << k << endl;
  }
  else if (a < k && a + b >= k)
  {
    cout << a << endl;
  }
  else if (a + b + c >= k)
  {
    cout << a - (k-b-a) << endl;
  }
}

Measured memory_bytes: 3620
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		Integer[] l = new Integer[N];
		for(int i = 0; i < N; i++){
			l[i] = sc.nextInt();
		}
		sc.close();

		Arrays.sort(l, Comparator.reverseOrder());
		int snake = 0;
		for(int i = 0; i < K; i++){
			snake += l[i];
		}
		System.out.println(snake);

	}

}


Measured memory_bytes: 24788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  string s;
  cin >> s;
 
  if (s.back() == 'F') s += 'T';
  int x, y;
  cin >> x >> y;
  x += 8000, y += 8000;
  vector<int> dx, dy;
  int cnt = 0;
  int f = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'T') {
      if (f % 2 == 0) dx.emplace_back(cnt);
      else dy.emplace_back(cnt);
      cnt = 0;
      f++;
    } else cnt++;
  } 
  int n = dx.size(), m = dy.size();
  vector<bool> dp1(16010, false), dp2(16010, false);
  dp1[8000] = true;
  for (int i = 0; i < n; i++) {
    vector<bool> next(16010, false);
    for (int j = 0; j < 16010; j++) {
      if (!dp1[j]) continue;
      next[j + dx[i]] = true;
      if (i > 0 && j >= dx[i]) next[j - dx[i]] = true;
    }
    dp1 = next;
  }
  dp2[8000] = true;
  for (int i = 0; i < m; i++) {
    vector<bool> next(16010, false);
    for (int j = 0; j < 16010; j++) {
      if (!dp2[j]) continue;
      if (j + dy[i] < 16010) next[j + dy[i]] = true;
      if (j >= dy[i]) next[j - dy[i]] = true;
    }
    dp2 = next;
  }
  if (dp1[x] && dp2[y]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int main() {
	int a, b, k;
	cin >> a >> b >> k;
	vector<bool> ans(b + 1);
	for (int i = a; i <= b; i++) {
		if (i < a + k || i > b - k)
			ans[i] = true;
	}
	for (int i = a; i <= b; i++) 
		if (ans[i])	cout << i << endl;
	
	return 0;
}

Measured memory_bytes: 122368
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

map<ll, ll> prime_factorization(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while(n >= a*a){
    if(n % a == 0){
      ans[a]++;
      n /= a;
    }else{
      a++;
    }
  }
  ans[n]++;

  return ans;
}

int main(){
  ll n, p;
  cin >> n >> p;
  auto mp = prime_factorization(p);
  ll ans = 1;
  for(auto p : mp){
    ll add = p.second/n;
    ans *= pow(p.first,add);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
struct edge{int from,to,cost;};
signed main(){
  string a;
  int b;
  cin>>a>>b;
  int c[1000000][5];
  vector<char> d(1000000);
  int m=0;
  rep(i,b){
    cin>>c[i][0];
    if(c[i][0]==2)
      cin>>c[i][1]>>d[i];
    else
      m++;
  }
  int n=0;
  rep(i,b){
  if(c[b-i-1][0]==1)
    n++;
    else{
      if(n%2==1){
        if(c[b-i-1][1]==2)
    c[b-i-1][1]=1;
        else if(c[b-i-1][1]==1)
          c[b-i-1][1]=2;
      }
    }
  }
  rep(i,b){
    if(c[b-i-1][1]==1)
      cout<<d[b-i-1];
    }
  if(m%2==0)
  cout<<a;
  else{
  reverse(all(a));
    cout<<a;
  }
    
  rep(i,b){
  if(c[i][1]==2)
    cout<<d[i];
  }
}

Measured memory_bytes: 11264
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        final int A = scan.nextInt();
        final int B = scan.nextInt();
        scan.close();

        if ((A + B) % 2 == 0) {
            System.out.println((A + B) / 2);
        } else {
            System.out.println("IMPOSSIBLE");
        }
    }
}

Measured memory_bytes: 22612
#include<iostream>
using namespace std;
int main(){
  int kinds, buy;
  cin>>kinds;
  int arr[kinds];
  cin >> buy;
  for (int i=0; i<kinds; i++){
    cin >> arr[i];
  }
  sort(arr,arr+kinds);
  int sum = 0;
  for(int i=0; i<buy; i++){
    sum+=arr[i];
  }
  cout << sum << endl;
}



Measured memory_bytes: 3144
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=200005;
int n;
long long A[N];
int b[N];
long long c[N];
long long a[N];
struct Point
{
	int x;
	long long y;
};
double slope(Point a,Point b)
{
	return (double)(b.y-a.y)/(b.x-a.x);
}
Point p[N];
Point s[N];
int top;
int pos[N];
bool book[N];
long long ans[N];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&A[i]);
	for(int i=1;i<=n;i++)
		scanf("%d",&b[i]);
	int Max=max_element(A+1,A+n+1)-A;
	rotate(A+1,A+Max,A+n+1);
	rotate(b+1,b+Max,b+n+1);
	n++;
	A[n]=A[1],b[n]=b[1];
	c[1]=c[2]=0;
	for(int i=2;i<=n;i++)
		c[i+1]=2*b[i]+2*c[i]-c[i-1];
	for(int i=1;i<=n;i++)
		a[i]=A[i]-c[i];
	for(int i=1;i<=n;i++)
	{
		p[i]=(Point){i,a[i]};
		while(top>=2&&slope(s[top-1],s[top])<=slope(s[top-1],p[i])) top--;
		s[++top]=p[i];
	}
	for(int i=1;i<=top;i++)
		pos[i]=s[i].x,book[pos[i]]=true;
	long double ans=0;
	for(int i=2;i<=n;i++)
		ans+=c[i];
	for(int i=2;i<=n;i++)
		if(book[i]) ans+=p[i].y;
		else
		{
			int a=lower_bound(pos+1,pos+top+1,i)-pos-1,b=upper_bound(pos+1,pos+top+1,i)-pos;
			a=pos[a],b=pos[b];
			ans+=(long double)(p[a].y*(b-i)+p[b].y*(i-a))/(b-a);
		}
	printf("%.12Lf",ans/(n-1));
	return 0;
}

Measured memory_bytes: 15972
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn = 1e5 + 20;
ll x[maxn] , a[maxn];
int main()
{
	ll k , n = 50;
	cin >> k;
	for(int i = 0; i < n; i++)
	{
		x[i] = k / n;
		if(i < k % n)
			x[i]++;
		a[i] = k - x[i];
	}
	cout << n << endl;
	for(int i = 0; i < n; i++)
	{
		a[i] = (n + 1) * x[i] - k;
		while(x[i] != (k - x[i] + a[i]) / n)
			a[i]++; //, cout << a[i] << endl;
		while(x[i] == (k - x[i] + a[i]) / n)
			a[i]++;
		a[i]--;
		cout << a[i] << " ";
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define gsort(arr) sort(arr, arr+n, greater<ll>()); 
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sync2 cout<<fixed<<setprecision(10)
const ll inf=1e9+7;
const ll inf2=inf*inf;
#define pi 3.14159265358979323846
#define for0(i,n) for (int i = 0; i <(int)n; i++)
#define for1(i,n) for (int i = 1; i<=(int)n; i++)
#define all(vv) vv.begin(),vv.end()
priority_queue <ll, vector<ll>, greater<ll>> mnheap;
priority_queue <ll> mxheap;
#define vc(vv) vector<ll> vv;
ll gcd(ll x,ll y){if (x == 0)return y;return gcd(y%x, x);}
int is_prime(ll x) {if(x<2)return 0;for(ll i=2;i*i<=x;i++){if(x%i==0)return 0;}return 1;}
inline ll modpw(ll x, ll y, ll z) {ll res=1;x=x%z;while(y){if(y&1) res=(res*x)%z;x=(x*x)%z;y/=2;}return res;}
inline ll modinv(ll x,ll z){return modpw(x,z-2,z);}
ll lcm(ll x,ll y){return (x*y)/gcd(x,y);}
#define pYES cout<<"YES"<<endl
#define pNO cout<<"NO"<<endl

ll dp[100005][3];
int main()
{
     sync;
     int t;
     //cin>>t;
     t=1;
     while(t--)
     {
          int n;
          cin>>n;
          ll a[n][3];
          for0(i,n)cin>>a[i][0]>>a[i][1]>>a[i][2];
          for0(i,n)
          {
               if(i==0)
               {
                    dp[i][0]=a[i][0];
                    dp[i][1]=a[i][1];
                    dp[i][2]=a[i][2];
                    continue;
               }
               dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
               dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i][1];
               dp[i][2]=max(dp[i-1][1],dp[i-1][0])+a[i][2];
          }
          cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
     }
}

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

c = 1
rem = len(A) - K
while True:
  if rem > K - 1:
    c += 1
    rem -= K - 1
  else:
    break
if rem == 0:
  print(c)
else:
  print(c + 1)

Measured memory_bytes: 13812
eval"N,C,*H="+`dd`.split*?,;g,*q=->i{x,y=q[i,2];1.0*($*[x]-$*[y])/(H[y]-H[x])-H[x]-H[y]};N.times{|i|q.shift while q.size>1&&g[0]>-2*H[i];$*<<(i>0?$*[q[0]]+C+(H[q[0]]-H[i])**2:0);q.pop 2while(q<<i).size>2&&g[-2]>g[-3]};p$*[-1]

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

int main() {
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5])
		cout << "Yes";
	else
		cout << "No";


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
template <typename T> 
using lim = numeric_limits<T>;
template <typename T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using indexed_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = 2e5;
ll n, k;
int A[N+1];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++){
        cin >> A[i];
    }

    int a, b;
    a = A[1];
    b = A[A[1]];
    while(a != b){
        a = A[a];
        b = A[A[b]];
    }

    int cnt = 0;
    a = 1;
    while(a != b){
        a = A[a];
        b = A[b];
        cnt++;
    }

    if (k <= cnt){
        a = 1;
        while(k--){
            a = A[a];
        }
        cout << a << "\n";
        return 0;
    }

    k -= cnt;
    int cycle = 1;
    b = A[a];
    while(a != b){
        b = A[b];
        cycle++;
    }

    k %= cycle;

    while(k--){
        a = A[a];
    }
    cout << a << "\n";
}

Measured memory_bytes: 4388
#include <bits/stdc++.h>
using namespace std;
int a[3005], cnt[3005];
long long dp[3005][3005];
const long long MOD=998244353;
long long modpow(long long x,long long e){
	if(x==1||e==0) return 1;
	long long c=modpow(x,e/2);
	long long c1=(c*c)%MOD;
	if(e%2==0) return c1;
	else return (c1*x)%MOD;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, s;
	cin>>n>>s;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	memset(dp, 0, sizeof dp);
	for(int i=0;i<=n;i++){
		dp[i][0]=modpow(2, n);
	}
	long long INV=modpow(2, MOD-2);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=s;j++){
			dp[i][j]=dp[i-1][j];
			if(j>=a[i]){
				dp[i][j]+=(dp[i-1][j-a[i]]*INV)%MOD;
				dp[i][j]%=MOD;
			}
		}
	}
	cout<<dp[n][s];
}


Measured memory_bytes: 74212
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int dp[90];
int32_t main(){
	int n;cin>>n;
	dp[0]=2;
	dp[1]=1;
	for(int i=2;i<=n;i++){
		dp[i]=dp[i-1]+dp[i-2];
	}
	cout<<dp[n];
}


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

int main() {
   string S;
   cin >> S;
   int count=0;
   int total=0;
   for (int i=0; i<S.size(); i++) {
       if (S.at(i)=='A'||S.at(i)=='C'||S.at(i)=='G'||S.at(i)=='T') {
           count++;
           if (count>total) total=count;
       }
       else count=0;
   }
   cout << total << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a, b;
    scanf("%d %d", &a, &b);
    if(a == 1){
        printf("1\n");
    }else if(b < 5){
        printf("%d\n", a-1);
    }else{
        printf("%d\n", a);
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  string s;
  cin >> s;
  for(char c: s)
    if(c == ',') cout << ' ';
    else cout << c;
  cout << endl;
  return 0;
}



Measured memory_bytes: 256
from copy import deepcopy
s = list(input())
K = int(input())
dummy = "A"
S = deepcopy(s)
if len(set(S)) == 1:
    print(len(S)*K//2)
else:
    replace_cnt = 0
    for i in range(1, len(S)):
        if S[i] == S[i-1]:
            S[i] = dummy
            replace_cnt += 1
    if S[0] != S[-1]:
        print(replace_cnt*K)
    else:
        S = s+s
        replace_cnt_two = 0
        for i in range(1, len(S)):
            if S[i] == S[i-1]:
                S[i] = dummy
                replace_cnt_two += 1
        diff = replace_cnt_two - replace_cnt
        print(diff*(K-1)+replace_cnt)


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

int ans;

void solve(void){
	int n;
	cin >> n;
	pair<int, int> p[n];
	for(int i = 0; i < n; i++){
		cin >> p[i].first >> p[i].second;
	}
	for(int i = 0; i + 2 < n; i++){
		if(p[i].first == p[i].second && p[i+1].first == p[i+1].second &&
			p[i+2].first == p[i+2].second){
				cout << "Yes\n";
				return;
			}
	}
	
	cout << "No\n";
	
}

signed main() {
int t = 1;
// cin >> t;    
	while(t--)
    solve();

    return 0;
}


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

const int inf = 1e8;
int main(){
  int h,w;
  string g[55];
  int dp[55][55];

  cin >> h >> w;
  for(int i=0;i<h;i++)cin >> g[i];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++)dp[i][j] = inf;
  }
  dp[0][0] = 0;

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(i)dp[i][j] = min(dp[i][j], dp[i-1][j] + g[i][j]-'0');
      if(j)dp[i][j] = min(dp[i][j], dp[i][j-1] + g[i][j]-'0');
    }
  }
  cout << dp[h-1][w-1] << endl;
}

Measured memory_bytes: 1220
#include<cstdio>
#include<cstring>
#include<algorithm>
#define qmax(x,y) (x=max(x,y));
using namespace std;

typedef long long ll;
const int Maxn=110000;
const ll mod=1000000007;

int n,a[21][21];
ll f[Maxn],g[Maxn];

int main() {
	scanf("%d",&n);int end=1<<n;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++) scanf("%d",&a[i][j]);
	for(int i=0;i<end;i++)
		for(int j=1,tempp=1;j<=n;j++,tempp<<=1)
			if(i&tempp)
				for(int k=j,tempt=tempp;k<=n;k++,tempt<<=1)
					if(i&tempt) f[i]+=a[j][k];
	for(int i=0;i<end;i++) g[i]=f[i];
	for(int i=0;i<end;i++)
		for(int s=i&(i-1);s;s=i&(s-1)) qmax(g[i],g[i^s]+f[s]);
	printf("%lld",g[end-1]); 
	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define LL long long int
#define Max(x, y) (x > y ? x : y)
#define Min(x, y) (x < y ? x : y)
#define Abs(x) ( (x) > 0 ? (x) : -(x) )
#define Swap(x,y) do{x = x ^ y; y = x ^ y; x = x ^ y;}while(0)
#define IO_BOOST                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0)
#define setp(x) fixed << setprecision(x)
#define INF 0x3f3f3f3f
#define Lowbit(x) ((x) & (-x))
#define Pii pair<int, int>
#define x first
#define y second
#define MOD ((int)1e9+7)
using namespace std;

int n, m;
long double pr[3000];
long double dp[3000];
void forkdp(long double *temp, long double *dp){
    for(int i = 0 ; i <= n ; i++)
        temp[i] = dp[i];
}
void solve(){
    dp[0] = 1;
    for(int i = 1 ; i <= n ; i++){
        long double temp[3000];
        forkdp(temp, dp);
        for(int j = 1 ; j <= i ; j++){
            dp[j] = temp[j-1]*pr[i] + temp[j]*(1-pr[i]);
        }
        dp[0] *= (1-pr[i]);
    }
    long double ans = 0;
    for(int i = n/2+1 ; i <= n ; i++){
        ans += dp[i];
    }
    cout << setp(10) << ans << '\n';
}
int main(){
    IO_BOOST;
    cin >> n;
    for(int i = 1 ; i <= n ; i++)
        cin >> pr[i];
    solve();

}

Measured memory_bytes: 384