akhauriyash/Code-Regression huggingface dataset:
n,k=list(map(int,input().split()))
s=input()

if s[0]=='0':
    seq=[0]
else:
    seq=[]

i=0
while i<n:
    j=i
    while j<n and s[j]==s[i]:
        j+=1
    seq.append(j-i)
    i=j

if s[-1]=='0':
    seq.append(0)

bleft=0
bright=min(2*k,len(seq)-1)

cursum=sum(seq[bleft:bright+1])
ret=cursum

for i in range(2,len(seq),2):
    left=i
    right=min(i+2*k,len(seq)-1)

    if bleft!=left:
        cursum-=seq[bleft]+seq[bleft+1]
        bleft=left
    if bright!=right:
        cursum+=seq[right-1]+seq[right]
        bright=right
    
    ret=max(ret,cursum)
    
print(ret)


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

int main(){
	string s1,s2;
	cin>>s1>>s2;
	if(s1[0]==s2[2]&&
		s1[1]==s2[1]&&
	s1[2]==s2[0]){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	
	return 0;
}
	

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

int main() {
  int N; string S; cin >> N >> S;
  char prev = S[0]; int num = 1;
  for (int i = 1; i < N; i++) {
    if (S[i] != prev) {
      num++;
      prev = S[i];
    }
  }
  cout << num << endl;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int e,v;

struct edge{int from,to,cost;};
vector<edge> edges;

class UF{
private:
	vector<int> par;
public:
	int groups;
	
	UF(int __size):par(__size){
		for(int i=0;i<__size;i++)par[i]=i;
	}
	
	int find(int x){
		if(par[x]==x) {
			return x;
		}else{
			return par[x]=find(par[x]);
		}
	}
	
	void unite(int x,int y){
		x=find(x);
		y=find(y);
		par[y] = x;
	}
};

int MSA(int r){
	int ret = 0;
	UF uf(v);
	vector<priority_queue<pii,vector<pii>,greater<pii>>> vpq(v);
	vector<int> lazy(v,0);
	vector<int> state(v,0);
	
	for(auto e:edges){
		vpq[e.to].push(pii(e.cost,e.from));
	}
	state[r] = 2;
	
	rep(start,v){
		int cur = uf.find(start);
		if(state[cur]!=0)continue;
		
		vector<int> processing;
		vector<int> from(v,-1);
		vector<int> from_cost(v,0);
		
		while(state[cur]!=2){
			processing.pb(cur);
			state[cur]=1;
			if( vpq[cur].empty() )return INF;
			
			pii e = vpq[cur].top(); vpq[cur].pop();
			from[cur] = e.second;
			from_cost[cur] = e.first+lazy[cur];
			if(cur==from[cur])continue;
			
			ret+=from_cost[cur];
			
			if(state[ from[cur] ]==1){
				int p=cur;
				do{
					lazy[p] -= from_cost[p];
					
					if(p!=cur){
						uf.unite(cur,p);
						while(vpq[p].size()){
							pii t = vpq[p].top();vpq[p].pop();
							t.first+=lazy[p]-lazy[cur];
							t.second = uf.find(t.second);
							vpq[cur].push(t);
						}
					}
					p = uf.find(from[p]);
				}while(p!=cur);
			}else{
				cur = from[cur];
			}
		}
		for(auto elm:processing)state[elm]=2;
	}
	return ret;
}

int main(){
	int r;
	cin>>v>>e>>r;
	rep(i,e){
		int s,t,w;
		cin>>s>>t>>w;
		edges.pb(edge{s,t,w});
	}
	cout<<MSA(r)<<endl;
}

Measured memory_bytes: 3280
t[]={10,50,100,500,5e9};e[4];i,z;main(n){for(;scanf("%d%d%d%d%d",&n,e,e+1,e+2,e+3),n;){for(i&&puts(""),i=4;i--;n-=e[i]*t[i]);for(;++i-4;z>0&&printf("%d %d\n",t[i],z))z=e[i]+n%t[i+1]/t[i];}}

Measured memory_bytes: 0
#include<stdio.h>
#define WHITE 2
#define GRAY 1
#define BLACK 0

int d[101],mat[101][101],m,color[101],Q[101],head=0,tail=0;

void bfs(int s){
  int i,u;
  for(i = 1; i <= m; i++){
    color[i] = WHITE;
    d[i] = -1;
  }
  color[s] = GRAY;
  d[s] = 0;
  Q[tail] = s;
  tail++;
  while(tail != head){
    u = Q[head];
    head++;
    for(i = 1; i <= m; i++){
      if(mat[u][i] == 1 && color[i] == WHITE){
	color[i] = GRAY;
	d[i] = d[u]+1;
	Q[tail] = i;
	tail++;
      }
    }
    color[u] = BLACK;
  }
}


int main(){
  int next[100][100];
  int k,num,i,j;

  scanf("%d",&m);

  for(i = 1; i <= m; i++){
    scanf("%d %d",&num,&k);
    for(j = 1 ; j <= k; j++){
      scanf(" %d",&next[i][j]);
      mat[i][next[i][j]] = 1;
    }
  }

  bfs(1);
  for(i = 1; i <= m; i++){
    printf("%d %d\n",i,d[i]);
    }
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
int main(){
    int D;
    cin>>D;
    if(D==25){cout<<"Christmas"<<endl;}
    if(D==24){cout<<"Christmas Eve"<<endl;}
    if(D==23){cout<<"Christmas Eve Eve"<<endl;}
    if(D==22){cout<<"Christmas Eve Eve Eve"<<endl;}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define lli long long int
#include <limits.h>
#include <fstream>
#define F first
#define S second
#define PI 3.141592653589793238
#define pb push_back

using namespace std;

//doesn't work for arrays
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

const lli mod=1000000007;

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

lli binpow(lli x,lli y,lli m)
{
    if (y==0)
        return 1;
    lli p=binpow(x,y/2,m)%m;
    p=(p*p)%m;
    if(y%2)
        return (x*p)%m;
    else
        return p;
}

lli modi(lli a,lli m)
{
    return binpow(a,m-2,m);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli i,j,tt=1;
    //cin>>tt;
    while(tt--)
    {
        int n,m,u,v;
        cin>>n>>m;
        vector<vector<int>> g(n,vector<int>());
        for(i=0;i<m;i++)
        {
            cin>>u>>v;
            u--;
            v--;
            g[u].push_back(v);
            g[v].push_back(u);
        }
        int ans=1;
        bool vis[n]={0};
        for(i=0;i<n;i++)
        {
            int ct=0;
            if(vis[i]==0)
            {
                queue<int> q;
                q.push(i);
                vis[i]=1;
                while(!q.empty())
                {
                    int temp=q.front();
                    q.pop();
                    ct++;
                    for(j=0;j<g[temp].size();j++)
                    {
                        if(vis[g[temp][j]]==0)
                        {
                            q.push(g[temp][j]);
                            vis[g[temp][j]]=1;
                        }
                    }
                }
            }
            ans=max(ans,ct);
        }
        cout<<ans<<"\n";
    }
    return 0;
}


Measured memory_bytes: 15056
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define MAXN 100001
int N;
int par[MAXN];

struct node{
    int x,y,name;
};
node N1[MAXN];
node N2[MAXN];
struct edge{
    int from,to,cost;
};
bool comp(const node& a,const node& b){
    if(a.x==b.x)return a.y<b.y;
    return a.x<b.x;
}
bool comp2(const node& a,const node& b){
    if(a.y==b.y)return a.x<b.x;
    return a.y<b.y;
}
void init(int a){
    rep(i,N)par[i] = -1;
}
int find(int s){
    if(par[s]<0)return s;
    return par[s] = find(par[s]);
}
void unite(int s,int t){
    s = find(s),t = find(t);
    if(s==t)return;
    if(par[s]>par[t])swap(s,t);
    par[s] += par[t];
    par[t] = s;
}
bool issame(int s,int t){
    return find(s) == find(t);
}
bool sor(const edge& a,const edge& b){
    return a.cost<b.cost;
}
int main(){
    cin >> N;
    rep(i,N){
        int xx,yy;cin >> xx >> yy;
        N1[i] = (node){xx,yy,i};
        N2[i] = (node){xx,yy,i};
    }
    ll cost = 0;
    sort(N1,N1+N,comp);
    
    edge cos[MAXN*2];
    rep(i,N-1){
        cos[i] = (edge){N1[i].name,N1[i+1].name,abs(N1[i].x-N1[i+1].x)};
    }   
    sort(N2,N2+N,comp2);
    rep(i,N-1){
        cos[i+N-1] = (edge){N2[i].name,N2[i+1].name,abs(N2[i].y-N2[i+1].y)};
    }
    
    sort(cos,cos+2*N-2,sor);
    init(N);
    rep(i,2*N-2){
        if(!issame(cos[i].from,cos[i].to)){
            cost += cos[i].cost;
            //cout << cos[i].from <<' '<< cos[i].to << ' '  << cos[i].cost << endl;
            unite(cos[i].from,cos[i].to);
        }
    }
    cout << cost << endl;
    return 0;

}

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

int main() {
    int X, N;
    cin >> X >> N;
    vector<bool> used(300, false);
    int offset = 100;
    for (int i = 0; i < N; ++i) {
        int p;
        cin >> p;
        used[p + offset] = true;
    }
    int res = 100000;
    for (int i = used.size() - 1; i >= 0; --i) {
        if (used[i]) continue;
        int tmp = i - offset;
        if (abs(X - res) >= abs(X - tmp)) res = tmp;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#define ll long long
using namespace std;

ll sumup(vector<pair<ll, int>> &v, vector<int> &u){
    ll res=v[0].first;
    u.push_back(v[0].second);
    for(int i=1; i<v.size(); ++i){
        if(v[i].first<=0) break;
        res += v[i].first;
        u.push_back(v[i].second);
    }
    return res;
}

int main() {
	int N;
	cin >> N;
	vector<ll> v(N);
	vector<pair<ll, int>> ev, od;
	for(int i=0; i<N; ++i){
	    cin >> v[i];
	    if(i%2==0) ev.push_back(make_pair(v[i], i));
	    else od.push_back(make_pair(v[i], i));
	}
	sort(ev.begin(), ev.end(), greater<pair<ll, int>>());
	sort(od.begin(), od.end(), greater<pair<ll, int>>());
	vector<int> e_ans, o_ans, ans, sol;
	ll e_sum=sumup(ev, e_ans), o_sum=sumup(od, o_ans);
	if(e_sum>o_sum){
	    cout << e_sum << endl;
	    ans.swap(e_ans);
	}
	else{
	    cout << o_sum << endl;
	    ans.swap(o_ans);
	}
	sort(ans.begin(), ans.end(), greater<int>());
	int now=0, num=N-1;
	while(num>=0){
	    if(num>ans[now]){
	        sol.push_back(num);
	        --num;
	    }
	    else if(now+1==ans.size()){
	        for(int i=0; i<num; ++i){
	            sol.push_back(0);
	        }
	        num=-1;
	    }
	    else if(ans[now+1]+2==num){
	        sol.push_back(num-1);
	        ++now;
	        num -= 2;
	    }
	    else{
	        sol.push_back(num-2);
	        ans[now] -= 2;
	        num -= 2;
	    }
	}
	cout << sol.size() << endl;
	for(int i=0; i<sol.size(); ++i) cout << sol[i]+1 << endl;
	return 0;
}


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

int main() {
  
  int A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;
  
  int total=0;
  int ans=1000000000;
  for(int i=0; i<=100000; i++){
    total = i*C*2 + max(0,X-i)*A + max(0,Y-i)*B;
    ans = min(ans,total);
  }
  
  cout << ans << endl;
  
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;

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

int main() {
    long long n, a, b; cin >> n >> a >> b;
    long long ans = (modpow(2, n) - 1 + MOD) % MOD;
    long long xa = 1, xb = 1, ya = 1, yb = 1;
    for (int i = 0; i < a; i++)
    {
        xa = xa * (n - i) % MOD;
        ya = ya * (i+1) % MOD;
    }
    for (int i = 0; i < b; i++)
    {
        xb = xb * (n - i) % MOD;
        yb = yb * (i+1) % MOD;
    }

    long long suba = xa * modpow(ya, MOD - 2) % MOD;
    long long subb = xb * modpow(yb, MOD - 2) % MOD;
    ans = (ans - suba - subb + 2 * MOD) % MOD;

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


Measured memory_bytes: 256
use std::io;


fn main() {
    let n = read::<usize>();
    if n.contains(&1) && n.contains(&9) && n.contains(&7) && n.contains(&4) {
        println!("YES");
    } else {
        println!("NO");
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

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

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

        if(a[i] > max){
            max = a[i];
            k = b[i];
        }
    }

    cout << max + k << endl;
}

Measured memory_bytes: 5192
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}
		
		long[][] dp = new long[n][3];
		dp[0][0] = a[0];
		dp[0][1] = b[0];
		dp[0][2] = c[0];
		
		for (int i = 1; i < n; i++) {
			dp[i][0] = a[i] + Math.max(dp[i - 1][1], dp[i - 1][2]);
			dp[i][1] = b[i] + Math.max(dp[i - 1][2], dp[i - 1][0]);
			dp[i][2] = c[i] + Math.max(dp[i - 1][0], dp[i - 1][1]);
		}
		
		long max = 0;
		for (int i = 0; i < 3; i++)
			max = Math.max(max, dp[n - 1][i]);
		
		System.out.println(max);
				
		sc.close();
	}
}



Measured memory_bytes: 51572
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class E
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		long N = GetLong();
		var A = GetLongs(N);
		var L = new Dictionary<long, long>();
		var R = new Dictionary<long, long>();
		var X = new HashSet<long>();
		for(int i = 0; i < N; i++)
		{
			long l = i + A[i];
			L.TryGetValue(l, out long lc);
			L[l] = lc + 1;

			long r = i - A[i];
			R.TryGetValue(r, out long rc);
			R[r] = rc + 1;

			X.Add(l);
			X.Add(r);
		}

		long cnt = 0;
		foreach(var x in X)
		{
			L.TryGetValue(x, out long lc);
			R.TryGetValue(x, out long rc);
			cnt += lc * rc;
		}
		WriteLine(cnt);
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 87036
def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split(sep)))

def main():
    s = input()
    a = []
    for c in s:
        if c == 'B':
            if a:
                a.pop()
        else:
            a.append(c)
    print(''.join(a))

main()


Measured memory_bytes: 3192
n = int(input())
r = 10**9 + 7

ten = 1
for i in range(n):
    ten *= 10
    ten %= r

nine = 1
for i in range(n):
    nine *= 9
    nine %= r

eight = 1
for i in range(n):
    eight *= 8
    eight %= r

print((ten - 2 * nine + eight) % r)

Measured memory_bytes: 9184
from itertools import product
a=['7','5','3']
n=int(input())
c=0
for j in range(1,10):
    for i in (product(a,repeat=j)):
        check=i.count('7')*i.count('3')*i.count('5')
        if int(''.join(i))<=n and check:c+=1
print(c)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    string S,T;cin>>S>>T;
    vector<int> R(26,-1),r(26,-1);
    bool check=0;
    rep(i,S.size()){
        if(R[S[i]-'a']==-1)R[S[i]-'a']=T[i]-'a';
        else{
            if(R[S[i]-'a']!=T[i]-'a'){
                check=1;
                break;
            }
        }
    }
    rep(i,T.size()){
        if(r[T[i]-'a']==-1)r[T[i]-'a']=S[i]-'a';
        else{
            if(r[T[i]-'a']!=S[i]-'a'){
                check=1;
                break;
            }
        }
    }
    if(check)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
using namespace std;
 
int main() {
    fast();
    /*ll t;
    cin>>t;
    while(t--)
    {
       
    }*/
    ll n,m;
    cin>>n>>m;
    ll a[n];
     multiset <ll, greater <ll> > s;
     multiset <ll, greater <ll> > :: iterator itr; 
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        s.insert(a[i]);
    }
    itr=s.begin();
    while(m>0)
    {
        itr=s.begin();
        ll x=*itr;
        s.erase(itr);
        s.insert(x/2);
        m--;
    }
    ll sum=0;
    for(itr=s.begin();itr!=s.end();itr++)
    {
        sum+=*itr;
    }
    cout<<sum<<endl;
    
}


Measured memory_bytes: 5760
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e8
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
}

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func main() {
	x := nextInt()
	fmt.Println(1 - x)
}


Measured memory_bytes: 1772
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i< (n);i++)
using namespace std;
typedef long long ll;
const ll INF = 1e+18;

int main(){
    //xに関して二分探索
    //x未満になるものがK個未満の時、trueなので、
    //-INFは常にtrue,INFは常にfalseとなる。
    ll N,K;cin>>N>>K;
    vector<ll> lst(N);
    rep(i,N)cin>>lst[i];
    sort(lst.begin(),lst.end());

    ll min = -INF;
    ll max = INF;

    auto judge=[&](ll x){
        //個数がK未満ならtrueを返すようなjudge関数
        ll tot = 0;
        //totはx以下になるペアの個数.
        rep(i,N){
            if(lst[i]<0){
                ll l = i;
                ll r = N;
                while(l+1<r){
                    ll m = (l+r)/2;
                    if(lst[i]*lst[m]<x) r = m;else l = m;
                }
                tot += N-r;
            }else{
                ll l = i;
                ll r = N;
                while(l+1<r){
                    ll m = (l+r)/2;
                    if(lst[i]*lst[m]<x) l = m;else r = m;
                }
                tot += l-i;
            }
        }
        return tot < K;
    };
    while(min+1<max){
        ll mid = (min+max)/2;
        if(judge(mid)){
            min = mid;
        }else{
            max = mid;
        }
    }
    cout<<min<<endl;
    return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ld eps = (ld)1 / 1e9;
ll inf = LLONG_MAX, mod1 = 1e9 + 7, mod2 = 998244353;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main()
{
    fast_io;
    ll n, x, t;
    cin >> n >> x >> t;
    if (n % x == 0) cout << t * (n / x);
    else cout << t * (n / x + 1);
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <string>
#include <math.h>
#include <numeric>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int, int> P;
#define PB push_back
#define INF 100000000000000000

int main()
{
  ll N, ans, i;
  char slime;
  string S;
  cin >> N >> S;
  ans = 1;
  slime = S.at(0);
  for (i = 1; i < N; i++)
  {
    if (slime != S.at(i))
    {
      slime = S.at(i);
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int d,g;
  cin >> d >> g;
  vector<int> num(d);
  vector<int> comp(d);
  rep(i,d){
      cin >> num[i] >> comp[i];
  }
  int score,question,ans = INT_MAX ;
  rep(bit,1<<d){
    score = 0;question = 0;
    rep(i,d){
      if(bit&(1<<i)){
        question += num[i];
        score += comp[i]+num[i]*100*(i+1);
      }
    }
    
    
    if(score < g){
      rep(i,d){
        if(!(bit&(1<<(d-i-1)))){
          double haiten = 100*(d-i);
          if(g-score <= haiten*num[d-i-1]){
            question += ceil((g-score) / haiten);
            break;
          }else{
            question += num[d-i-1];
            score += haiten * num[d-i-1];
          }
        }
      }
    }
    ans = min(ans,question);

  }
  cout<< ans << endl;
}



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

int main() {
  string S,T;
  cin>>S;
  cin>>T;
  int X;
  X=S.size();
  bool ans=true;
  for(int i=0;i<X;i++){
    if(S.at(i)!=T.at(i)){
      ans=false;
      break;
    }
  }
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <climits>
#include <iomanip>
using namespace std;
#define MAXSIZE 100005
#define MAXL 100
#define MOD 998244353
typedef long long int lli;

int main(){
    lli N, T;
    cin >> N >> T;
    vector<lli> t(N);
    for(lli i = 0; i < N; ++i){
        cin >> t[i];
    }

    lli ans = 0;
    for(lli i = 0; i < N; ++i){
        if(i == N - 1){
            ans += T;
        }else{
            ans += min(t[i + 1] - t[i], T);
        }
    }

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

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

int main(){
  int k, s;
  cin >> k >> s;
  long long ans = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      if (s - i - j >= 0 && s - i - j <= k) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>

using namespace std;

int main() {
    cout.setf(ios::fixed, ios::floatfield);
    cout.setf(ios::showpoint);
    cout.precision(12);
    ios::sync_with_stdio(false);

    int A, B, X;
    cin >> A >> B >> X;

    if(A > X || (A + B) < X) {
        cout << "NO" << endl;
        return 0;
    }

    cout << "YES" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
long long p = 1000000007;
long long k, n, q, a;
char s[1000001];
long long inv[2000001];
long long rui(long long rui_a, long long rui_b) {
	if (rui_b == 0)return 1;
	if (rui_b == 1)return rui_a % p;
	long long rui_c;
	rui_c = rui(rui_a, rui_b / 2);
	rui_c = rui_c * rui_c % p;
	if (rui_b % 2) {
		return rui_c * rui_a % p;
	}
	return rui_c;
}
void makeinv(void) {
	long long arraynumber = sizeof inv / sizeof inv[0];
	inv[1] = 1;
	for (int invcount = 2; invcount < arraynumber; invcount++) {
		inv[invcount] = p - inv[p % invcount] * (p / invcount) % p;
	}
}
int main() {
	scanf("%lld", &k);
	scanf(" %s", s);
	makeinv();
	while (s[n] != NULL)n++;
	q = 1;
	for (int i = 0; i < n + k; i++) {
		q *= 25;
		q %= p;
	}
	for (long long i = 1; i <= k + n; i++) {
		q *= inv[25];
		q %= p;
		q *= (n + k + 1 - i);
		q %= p;
		q *= inv[i];
		q %= p;
		if (i >= n)a += q;
		a %= p;
	}
	printf("%lld\n", a);
}

Measured memory_bytes: 18332
#include <stdio.h>
#include <stdlib.h>
#define LEN 100005


struct process 
{
	char name[100];
	int time;
};

int main(void)
{
	int n, q;
	// printf("define n, q\n");
	struct process pro[LEN];
	scanf("%d %d", &n, &q);
	int i;
	// printf("n and p get\n");
	for (i = 0; i < n; i++)
		scanf("%s %d", pro[i].name, &pro[i].time);
	// printf("%s %d", pro[1].name, pro[1].time);
	int timecount = 0;
	int head = 0;
	int tail = n;
	while (head != tail)
	{
		if (pro[head].time <= q)
		{
			timecount += pro[head].time;
			printf("%s %d\n", pro[head].name, timecount);
			if (head + 1 < LEN)
			{
				head++;
				continue;
			}
			else
			{
				head = 0;
				continue;
			}
			continue;
		}
		timecount += q;
		pro[head].time -= q;
		// pro[tail].name = pro[head].name;
		for (i = 0; i < 100; i++)
		{
			if (pro[head].name[i] == '\0')
			{
				pro[tail].name[i] = '\0';
				break;
			}
			else
				pro[tail].name[i] = pro[head].name[i];
		}
		pro[tail].time = pro[head].time;
		if (head + 1 < LEN)
		{
			head++;
		}
		else
		{
			head = 0;
		}
		if (tail + 1 < LEN)
		{
			tail++;
		}
		else
		{
			tail = 0;
		}
	}
}



Measured memory_bytes: 11840
import java.util.*;
import java.io.*;
import java.math.*;

public class Main{

    public static void main (String args[]) {
        
		double x,y = 0.000;
		
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String line = "";
			
			while ((line = br.readLine()) != null) {
				String[] str = line.split(" ");
				
				if (str.length == 6) {
					double a = Double.parseDouble(str[0]);
					double b = Double.parseDouble(str[1]);
					double c = Double.parseDouble(str[2]);
					double d = Double.parseDouble(str[3]);
					double e = Double.parseDouble(str[4]);
					double f = Double.parseDouble(str[5]);
										
					x = (b*f - c*e)/(b*d - a*e);
					y = (c*d - a*f)/(b*d - a*e);
					
					BigDecimal bx = new BigDecimal(x);
					BigDecimal by = new BigDecimal(y);
					
					bx = bx.setScale(3, BigDecimal.ROUND_HALF_UP);
					by = by.setScale(3, BigDecimal.ROUND_HALF_UP);
					
					System.out.println(bx + " " + by);
					
				}else {
					System.exit(0);
				}
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			System.exit(0);
		}
		finally {
			System.exit(0);
		}
    }
}

Measured memory_bytes: 17000
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    long long a,b,c;
    cin >> a >> b >> c;
    
    if(a % 2 == 0||b % 2 == 0||c % 2 == 0) cout << 0 << endl;
    else cout << min({a*b,b*c,c*a}) << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

num_of_minus = sum([a < 0 for a in A])
abs_A = [abs(a) for a in A]

ans = sum(abs_A)

if num_of_minus % 2 == 0:
    print(ans)
else:
    print(ans - 2 * min(abs_A))


Measured memory_bytes: 66464
class comb():
  F = [1, 1]
  Fi = [1, 1]
  I = [0, 1]
  def __init__(self, num, mod):
    self.MOD = mod
    for i in range(2, num + 1):
      self.F.append((self.F[-1] * i) % mod)
      self.I.append(mod - self.I[mod % i] * (mod // i) % mod)
      self.Fi.append(self.Fi[-1] * self.I[i] % mod)
  def com(self, n, k):
    if n < k: return 0
    if n < 0 or k < 0: return 0
    return self.F[n] * (self.Fi[k] * self.Fi[n - k] % self.MOD) % self.MOD


N, M, K = list(map(int, input().split()))
MOD = 998244353

ans = 0

P = [M] * (N)

for i in range(N - 1):
  P[i + 1] = P[i] * (M - 1) % MOD

com = comb(N, MOD)
for i in range(K + 1):
  t = P[-1 -i] * com.com(N - 1, i) % MOD
  ans = (ans + t) % MOD

print(ans)

Measured memory_bytes: 114060
import java.util.Scanner;

public class Main {	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int x = Math.max(a+b,a-b);
		x = Math.max(x, a*b);
		System.out.println(x);
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;
using namespace std;

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  for (int i = min(a, b);; i--) {
    if (a % i == 0 && b % i == 0) k--;
    if (k == 0) {
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define se second
#define fi first
#define rep(i, l, r) for (ll i = (ll)(l); i < (ll)(r); i++)
#define print(v) for (const auto itr : v){cout << itr << ' ';} cout << endl;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 998244353
#define endl "\n"
#define inf 1e18
using namespace std;
const ll INF = 1e18L + 5;
const ll maxn = 1e6+5, maxn1=2e5+3;
#define MAXN 200005
ll ceel(ll a, ll b)
{
   if (a % b == 0)
       return a / b;
   return a / b + 1;
}
ll modneg(ll a,ll m)
{
    a = a % m;
    if(a<0)
        a=a+m;
    return a;
}
ll powermod(ll x, unsigned ll y, ll p){ ll res = 1; x = x % p; while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;} return res;}
ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); };



int main()
{

ll n,i,j,k,a,b,c,d,test,cnt=0,s;
cin>>n>>s;
ll arr[n+5];
rep(i,0,n)
    cin>>arr[i];
ll dp[3005][3005];
memset(dp,0,sizeof dp);
for(i=0;i<n;i++)
{
    dp[i][0]=powermod(2,i,mod);
    for(j=0;j<=s;j++)
    {
        dp[i+1][j]+=dp[i][j]*2; dp[i+1][j]%=mod;
        if(j+arr[i]<=s)
        {
            dp[i+1][j+arr[i]]+=dp[i][j];
            dp[i + 1][j + arr[i]]%=mod;
        }
    }
}
// rep(i,0,n)
// {
//     rep(j,0,s)
//         cout<<dp[i][j]<<" ";
//     cout<<endl;
// }
cout<<dp[n][s];
return 0;
}

Measured memory_bytes: 74200
fun main(args: Array<String>) {
    agc037a()
}

fun agc037a() {
    val s = readLine()!!

    // dp[i文字目まで使用][前の文字を使う？(0/1)] = 答えの最大値
    val dp = Array(s.length) { LongArray(2) { 0 } }
    dp[0][0] = 1

    for (i in 1..s.lastIndex) {
        dp[i][0] = 1 + if (s[i] == s[i - 1]) dp[i - 1][1] else Math.max(dp[i - 1][0], dp[i - 1][1])
        dp[i][1] = if (i <= s.lastIndex && i - 2 >= 0 &&
            s[i - 1].toString() + s[i].toString() == s[i - 2].toString() + s[i - 1].toString()
        ) {
            1 + dp[i - 2][0]
        } else {
            1 + if (i >= 2) Math.max(dp[i - 2][0], dp[i - 2][1]) else 0
        }
    }

    val answer = dp.last().max()

    println(answer)
}


Measured memory_bytes: 61040
n,k = map(int,input().split())
a = list(map(int,input().split()))

a.sort(reverse=True)
mask = (1<<k)-1
dp = 1
min_n = 10**10
for i in a:
    if(i >= k):
        min_n = i
        continue
    dp |= (dp<<i)
    if(dp > mask):
        min_n = i
        dp &= mask
         
ans = 0
for i in a:
    ans += (i < min_n)

print(ans)

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

using namespace std;

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

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

  int cnt[100010] = {};
  for (int i = 0; i < n; i++) {
    cnt[a[i] - 1]++;
    cnt[a[i]]++;
    cnt[a[i] + 1]++;
  }

  int maxa = 0;
  for (int i = 0; i <= 100001; i++) {
    if (cnt[i] > maxa) {
      maxa = cnt[i];
    }
  }

  cout << maxa << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <set>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007


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

    // input
    int N, M;
    
    cin >> N;
    vector<int> sec(N);
    REP(i, N) cin >> sec[i];
    
    cin >> M;
    vector<int> drink(M), aft_drink_sec(M);
    REP(i, M) {
        cin >> drink[i] >> aft_drink_sec[i];
    }
    
    // calculation
    REP(i, M) {
        vector<int> cp_sec;
        COPY(sec, cp_sec);
        int idx = drink[i] - 1;
        cp_sec[idx] = aft_drink_sec[i];
        cout << SUM(cp_sec) << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream> // 「標準的な入出力に関して必要な情報を取って来い」という程度の意味
#include <string> // 文字列を扱う際にインクルードするもの
#include <math.h>
using namespace std; //cout cin など stdを必要とする機能を記述する際に簡易的に書くために定義

int main() {


    // B問題
    int N, K;
    int i = 0;
    cin >> N >> K;
    while (N >= pow(K,i)){
        i++;
    }
    cout << i << endl;
}

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

using namespace std;

unsigned long sums[5000050];

void solve()
{
	int N, K;
	cin >> N >> K;
	vector<unsigned long> imos(N+1);
	for (int i = 0; i < N; i++)
	{
		long a;
		cin >> a;
		imos[i+1] = a+imos[i];
	}

	unsigned long ans = 0;

	for (int l = 0; l < N; l++) for (int r = l+1; r <= N; r++)
	{
		sums[N*l+r-l] = imos[r] - imos[l];
	}

	unsigned long b = 1ULL<<60;

	while(b>0)
	{
		int cnt = 0;
		for (auto s : sums)
		{
			cnt += ((ans+b)&s) == ans+b;
		}
		if (cnt >= K) ans += b;
		b >>= 1;
	}

	cout << ans << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 8448
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		long n = sc.nextLong(), k = sc.nextLong(), q = sc.nextLong();
		long[] a = new long[(int)n];
		Arrays.fill(a, 0);
		for(int i = 0; i < q; i++) {
			a[sc.nextInt()-1] += 1;
		}
		for(int i = 0; i < n; i++) {
			if(k - q + a[i] <= 0 ) {
				System.out.println("No");
			}else {
				System.out.println("Yes");
			}
		}
	}
	
	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 55260
def main():
    N = int(input())
    S = list(map(int, input().split()))
    INF = float('inf')
    n = 2 ** N + 1

    S.sort()

    parents = [S[-1]]
    S[-1] = INF

    for _ in range(N):
        checking = 2
        parents.sort()
        tmp = parents[::-1]
        for i in tmp:
            while True:
                if S[-checking] < i:
                    parents.append(S[-checking])
                    S[-checking] = INF
                    break
                else:
                    checking += 1
                if checking == n:
                    print('No')
                    exit()
    else:
        print('Yes')


if __name__ == '__main__':
    main()

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

#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;

string s;
int x, y;

// 0 = horiz, 1 = vert
int dir = 0;
set<int> hdp[8005], vdp[8005];

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin >> s >> x >> y;
	vector<int> moves[2];
	
	int len = 0;
	bool turned = false, fw = false;
	for (int i = 0; i < sz(s); ++i) {
		if (s[i] == 'T') {
			if (len) {
				moves[dir].push_back(len);
				if (!dir && !turned) fw = true;
			}
			turned = true;
			len = 0;
			dir = !dir;
		} else ++len;
		
		if (i == sz(s) - 1 && len) {
			moves[dir].push_back(len);
			if (!dir && !turned) fw = true;
		}
	}

	if (sz(moves[0])) {
		hdp[0].insert(moves[0][0]);
		if (!fw) hdp[0].insert(-moves[0][0]);
	} else hdp[0].insert(0);
	
	for (int i = 1; i < sz(moves[0]); ++i) {
		for (auto j : hdp[i - 1]) {
			hdp[i].insert(j + moves[0][i]);
			hdp[i].insert(j - moves[0][i]);
		}
	}
	
	if (sz(moves[1])) {
		vdp[0].insert(moves[1][0]);
		vdp[0].insert(-moves[1][0]);
	} else vdp[0].insert(0);
	
	for (int i = 1; i < sz(moves[1]); ++i) {
		for (auto j : vdp[i - 1]) {
			vdp[i].insert(j + moves[1][i]);
			vdp[i].insert(j - moves[1][i]);
		}
	}
	
	if (hdp[max(sz(moves[0]) - 1, 0)].count(x) && vdp[max(sz(moves[1]) - 1, 0)].count(y)) cout << "Yes";
	else cout << "No";
}


Measured memory_bytes: 192112
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair 
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = n - 1; i>= 0; i--)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<ll> vll;

const int MAXN = 100005;
ll mod=1000000007;
ll ans = 0;
int n,m,q;
vi a,b,c,d;
void solve(vi v){
	if(v.size() == n){
		ll sum = 0;
		rep(i,q){
			if(v[b[i]] - v[a[i]] == c[i]){
				sum+=d[i];
			}
		}	
		ans = max(ans,sum);
	}
	else{
		int st = 1;
		if(v.size()) st = v.back();
		for(int i = st; i <= m; i++){
			v.pb(i);
			solve(v);
			v.pop_back();
		}	
	}	
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>q;
	a.resize(q);
	b.resize(q);
	c.resize(q);
	d.resize(q);
	rep(i,q){
		cin>>a[i]>>b[i]>>c[i]>>d[i];
		a[i]--;
		b[i]--;
	}
	solve(vi());
	cout<<ans<<nl;
	return 0;
}



Measured memory_bytes: 3656
def multiply(x, y):
    return (x * y) % mod


def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x
    elif x == 1:
        return 1
    elif x == 0:
        return 0
    else:
        # print(mod)
        tmp = power(x, y // 2)
        return (multiply(tmp, tmp) * [1, x][y % 2]) % mod


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

mod = 10 ** 9 + 7

plist = [0]
nfact = 1
N
tmp = 0
for i in range(1, N):
    tmp = (tmp + power(i + 1, mod - 2)) % mod
    nfact = (nfact * (i + 1)) % mod
    plist.append(tmp)

ans = 0
# print(plist)
# print(nfact)
for i, a in enumerate(A):
    # print(i, N - i - 1, N)
    tmp = (1 + plist[i] + plist[N - i - 1]) % mod
    ans = (ans + multiply(multiply(a, tmp), nfact)) % mod

print(ans)

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

int main()
{
  int A, B;
  cin >> A >> B;
  vector<int> ans;
  ans.push_back(A + A -1);
  ans.push_back(A + B);
  ans.push_back(B + B -1);

  sort(ans.begin(), ans.end());
  cout << ans[2] << endl;

  return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
import sys
import math
import string
import collections
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

ABC = list(map(int, input().split()))
if len(set(ABC)) == 2:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 67308
#include <cstdint>
#include <iostream>

using namespace std;

int32_t main()
{
  int32_t a, b, c;

  cin >> a >> b >> c;
  if ((a <= c) && (c <= b)) {
    cout << "Yes" << endl;

  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int d;
	scanf("%d", &d);
	if (d == 25)
		printf("Christmas\n");
	else if (d == 24)
		printf("Christmas Eve\n");
	else if (d == 23) 
		printf("Christmas Eve Eve\n");
	else if (d == 22)
		printf("Christmas Eve Eve Eve\n");

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
int main() {
    ull X, Y;
    cin >> X >> Y;
    ull x = X;
    size_t length = 1;
    while (x <= Y) { x *= 2; length++; }
    cout << length - 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<utility>
#include<tuple>
#include<set>
#include<list>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<cmath>

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FUNCTION__ << endl;
#define int long long

const long long MAXN = 1e6;
const long long MOD = 1e9+7;
const long long INF = __LONG_LONG_MAX__ / 2;

using namespace std;

int hoge[MAXN];

signed main(){
    int N, K;
    cin >> N >> K;
    int minv = INF;
    for (int a = 0; a <= N; a++){
      minv = min( minv, (int)(pow(2, a)+ 0.1) + (N - a) * K);
    }
    cout << minv << endl;
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, string> P;
typedef tuple<int, string, string> T;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int k, a, b;

bool solve() {
    for (int i = 1; i*k <= b; i++) {
        if (a <= i*k && i*k <= b)
            return true;
    }
    return false;
}

void input() {
    cin >> k >> a >> b;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << (solve()?"OK":"NG") << endl;
}


Measured memory_bytes: 3040
#include <map>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, d[109], a[109], dp[109][40320]; map<vector<int>, int> dperm;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> d[i];
	for (int i = 0; i < n; i++) cin >> a[i];
	vector<int> pr = { 0,1,2,3,4,5,6 }; int cntr = 0;
	do {
		dperm[pr] = cntr++;
	} while (next_permutation(pr.begin(), pr.end()));
	for (int i = 1; i < n; i++) {
		vector<int> p = { 0,1,2,3,4,5,6,7 };
		int cnt = 0;
		do {
			vector<int> p2(p.begin(), p.begin() + 7);
			for (int j = 0; j < 7; j++) {
				if (p2[j] > p[7]) p2[j]--;
			}
			int e = dperm[p2];
			int res = 0;
			for (int j = 1; i - j >= 0 && j <= d[i]; j++) {
				if (p[7 - j] > p[7]) res += a[i];
			}
			for (int j = 1; i - j >= 0 && j <= 7; j++) {
				if (p[7 - j] < p[7] && d[i - j] >= j) res += a[i - j];
			}
			for (int j = 0; j < 8; j++) {
				dp[i][cnt] = max(dp[i][cnt], dp[i - 1][j * 5040 + e] + res);
			}
			cnt++;
		} while (next_permutation(p.begin(), p.end()));
	}
	int ret = 0;
	for (int i = 0; i < 40320; i++) ret = max(ret, dp[n - 1][i]);
	cout << ret << endl;
	return 0;
}

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

#define ll long long
#define rep(i,n) for(ll i=(ll)(0); i<(ll)(n); ++i)
#define irep(i,m,n) for(ll i=(ll)(m); i<(ll)(n); ++i)
#define vi vector<int>

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

const long long MOD = 1e9 + 7;

signed main()
{
  int c[3][3];
  rep(i,3) rep(j,3) cin>>c[i][j];
  rep(i,101){
    int b1=c[0][0]-i;
    int b2=c[0][1]-i;
    int b3=c[0][2]-i;
    bool ok=true;
    irep(j,1,3){
      if(!((c[j][0]-b1)==(c[j][1]-b2)&&(c[j][1]-b2)==(c[j][2]-b3))){
        ok=false;
      }
    }
    if(ok){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 256