akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

template<long long mod>
class modint{
private:
  long long a;
public:
  constexpr modint(const long long x = 0) noexcept : a(x%mod) {}
  constexpr long long& value() noexcept { return a; }
  constexpr const long long& value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint& operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if(a >= mod) a -= mod;
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if(a < rhs.a) a += mod;
    a -= rhs.a;
    return *this;
  }
  constexpr modint& operator*=(const modint rhs) noexcept {
    a = a*rhs.a%mod;
    return *this;
  }
  constexpr modint& operator/=(modint rhs) noexcept {
    long long k = mod-2;
    while(k > 0){
      if(k&1){
        *this *= rhs;
      }
      rhs *= rhs;
      k /= 2;
    }
    return *this;
  }
  friend ostream& operator<<(ostream &os, const modint &X){
    return os << X.a;
  }
  friend istream& operator>>(istream &is, modint &X){
    is >> X.a;
    X.a %= mod;
    if(X.a < 0) X.a += mod;
    return is;
  }
};

using mint = modint<998244353>;

int main(){
  int N, S;
  cin >> N >> S;
  vector<int> A(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  vector<mint> dp(S+1);
  dp[0] = 1;
  for(int i = 0; i < N; ++i){
    vector<mint> dp_(S+1);
    for(int j = 0; j <= S; ++j)
      dp_[j] = dp[j]*2;
    for(int j = S; j >= 0; --j){
      if(j+A[i] > S) continue;
      dp_[j+A[i]] += dp[j];
    }
    swap(dp,dp_);
  }
  cout << dp[S] << endl;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  int64_t A[N];
  for(int i=0;i<N;i++) cin >> A[i];
  int64_t ans = INF;
  for(int i = 0;i<N-K+1;i++){
    if(A[i]*A[i+K-1]<0){
      if(abs(A[i])<A[i+K-1]) {
        int64_t ans1 = abs(A[i])*2 + A[i+K-1];
        ans = min(ans, ans1);
      }
      else{ 
        int64_t ans1 = abs(A[i]) + A[i+K-1]*2;
        ans = min(ans, ans1);
      }
    }
    else if(A[i] <= 0 && A[i+K-1] <=0){
      ans = min(ans, abs(A[i]));
    }
    else{
      ans = min(ans,A[i+K-1]);
    }
  }
  cout << ans << endl;
}

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

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

    int q;
    vector<long long> A;
    priority_queue<long long, vector<long long>, greater<long long>> upper;
    priority_queue<long long> lower;
    priority_queue<long long> tmp;
    long long a, b;
    long long sum_a = 0;
    long long sum_b = 0;
    for (int i = 0; i < Q; i++)
    {
        cin >> q;
        if (q == 1)
        {
            cin >> a >> b;
            sum_b += b;
            A.push_back(a);
            if (upper.size() < lower.size())
            {
                sum_a += abs(a - lower.top());
                tmp.push(lower.top());
                lower.pop();
                tmp.push(a);

                upper.push(tmp.top());
                tmp.pop();
                lower.push(tmp.top());
                tmp.pop();
            }
            else
            {
                if (upper.empty() && lower.empty())
                {
                    lower.push(a);
                }
                else
                {
                    if (lower.top() > a || upper.top() < a)
                    {
                        sum_a += min(
                            abs(a - lower.top()), abs(a - upper.top()));
                    }
                    tmp.push(upper.top());
                    upper.pop();
                    tmp.push(lower.top());
                    lower.pop();
                    tmp.push(a);

                    upper.push(tmp.top());
                    tmp.pop();
                    lower.push(tmp.top());
                    tmp.pop();
                    lower.push(tmp.top());
                    tmp.pop();
                }
            }
        }
        if (q == 2)
        {
            long long x = lower.top();
            cout << x << " " << sum_a + sum_b << endl;
        }
    }
}


Measured memory_bytes: 4856
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    int N;
    cin >> N;
    vector<int> A(N), Sorted(N);
    map<int, int> m;
    rep(i,N) {
        int t;
        scanf("%d", &t);
        A[i] = t;
        Sorted[i] = A[i];
    }
    sort(Sorted.begin(), Sorted.end());
    rep(i,N) {
        m.insert(make_pair(Sorted[i], i));
    }
    int ans = 0;
    rep(i,N) {
        if (i % 2 != m.at(A[i]) % 2) ans++;
    }
    ans /= 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int n,a[3003],s;
const int MOD=998244353;
LL dp[3003][3003];
int main(){
	fastio;
	cin>>n>>s;
	LL res=0;
	rb(i,1,n){
		cin>>a[i];
		rb(j,0,s){
			dp[i][j]+=dp[i-1][j];
			if(j+a[i]<s){
				if(j==0){;
					dp[i][j+a[i]]+=i;
					dp[i][j+a[i]]%=MOD;
				}
				else{
					dp[i][j+a[i]]+=dp[i-1][j];
					dp[i][j+a[i]]%=MOD;
				}
			}
			else{
				if(j+a[i]==s){
					if(j==0){
						res+=(LL)(i)*(n-i+1);
						res%=MOD;
					}	
					else{
						res+=dp[i-1][j]*(n-i+1);
						res%=MOD;
					}
				}
			}
		}
	} 
	cout<<res<<endl;
	return 0;
}


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


ll a[55], p[55]; // a: 層数,p: パティ数

ll f(ll s, ll t) {
  if(t<=1) {
    if(s==0) return 1;
    return 0;
  }
  if(t<=1+a[s-1]) return f(s-1,t-1);
  if(t==1+a[s-1]+1) return p[s-1]+1;
  if(t==2*a[s-1]+3) return p[s];
  return p[s-1] + 1 + f(s-1,t-2-a[s-1]);
}
int main() {
  ll n, x;
  cin >> n >> x;
  a[0] = p[0] = 1;
  rep(i,n) {
    a[i+1] = 2*a[i]+3;
    p[i+1] = 2*p[i]+1;
  }
  cout << f(n,x) << endl;
  return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

// #define int long long
using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }
template<class T>
ostream &operator<<(ostream &os,const vector<T> &v){
  for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i];
  os << "]";
  return os;
}

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

//const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
  int n,m;
  cin >> n >> m;
  
  vector<map<int,int>> mp(n, map<int,int> {} );
  vector<int> vv(n,-1);
  
  for(int i=0;i<m;i++){
    int aa,bb;
    cin >> aa >> bb;
    aa--; bb--;
    mp[aa][bb] = 1;
    mp[bb][aa] = 1;
  }
  
  deque<int> Q;
  for(int i=0;i<n;i++){
    if( vv[i]==-1 ){
      Q.clear();
      Q.push_front(i);
      vv[i] = i;
      while( !Q.empty() ){
        int c = Q.front();
        Q.pop_front();
        for (const auto& pp : mp[c]){
          if( vv[pp.first]==-1 ){
            Q.push_back(pp.first);
            vv[pp.first] = i;
          }
        }
      }
    }
  }
  
  vector<int> cnt(n,0);
  int mx = -1;
  for(int i=0;i<n;i++){
    cnt[vv[i]]++;
    if( cnt[vv[i]] > mx ){ mx = cnt[vv[i]]; }
  }
  
  cout << mx << endl;
  
  return 0;
}



Measured memory_bytes: 33280
def enq(a,x)
  b = a[i=-1]
  until b.frozen?
    return a << x  if x >= (a=b)[-1]
    return a.unshift x  if x <= a[0]
    i = a.bsearch_index {|y| x <= (y.frozen? ? y: y[0])}
    b = a[i-=1]  if (b=a[i]).frozen? ? x<b: x<b[0]
  end  if b && b=a
  return a.insert(i+1, x)  if a.size-i < 9
  i > 9 ? a[i] = [a[i],x] : a.unshift(*a.shift(i+1),x)
end
def deq(a); r = a.shift; a.unshift *a.shift if !a[0].frozen?; r end
def popq(a); r = a.pop; a.push *a.pop if !a[-1].frozen?; r end
N,M,*A = $<.read.split.map{|x| x.to_i}
A.sort!
M.times { break if A[-1]==0; enq A, (popq A)/2 }
p A.flatten.inject(0,:+)

Measured memory_bytes: 87620
N = int(input())
L = list(map(int, input().split()))

def main():
    L_sum = 0
    L_max = 0
    for l in L:
        if l > L_max:
            L_max = l
        L_sum += l
    if L_max < L_sum - L_max:
        return 'Yes'
    else:
        return 'No'

if __name__ == '__main__':
    print(main())


Measured memory_bytes: 2940
#include<stdio.h>
int main(){
  int A,B,C;
  scanf("%d %d %d",&A,&B,&C);
  if(A<C&&C<B){
    printf("Yes");
  }
  else if(B<C&&C<A){
    printf("Yes");
  }
  else{
    printf("No");
  }
  return 0;
}











Measured memory_bytes: 128
#!/usr/bin/env python3

MOD = 10**9
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

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

s = sum(A)
k = s/float(4*M)
cnt = 0
for a in A:
    if a >= k:
        cnt += 1

if cnt >= M: print('Yes')
else: print('No')




Measured memory_bytes: 3064
n,m=map(int,input().split())
a = set(int(input()) for i in range(m))
#for i in range(m):
#  a.append(int(input()))
b=[0 for x in range(n+1)]
b[0]=1
for i in range(1,n+1):
  if i in a:
    continue
  x=b[i-1]
  if i>1:x+=b[i-2]
  b[i]=x
print(b[n]%(10**9+7))

Measured memory_bytes: 460056
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<vector<ll>> dp(n+1, vector<ll>(n+1, 0));
    function<ll(int, int, int)> rec = [&](int l, int r, int first)
    {
        if(dp[l][r]) return dp[l][r];
        if(l == r) return first * a[l];
        if(first == 1)
        {
            ll tmp = -1e14;
            tmp = max(tmp, rec(l+1, r, -first) + first * a[l]);
            tmp = max(tmp, rec(l, r-1, -first) + first * a[r]);
            return dp[l][r] = tmp;
        }
        else
        {
            ll tmp = 1e14;
            tmp = min(tmp, rec(l+1, r, -first) + first * a[l]);
            tmp = min(tmp, rec(l, r-1, -first) + first * a[r]);
            return dp[l][r] = tmp;
        }
    };
    cout << rec(0, n-1, 1) << endl;
}


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

int main(){
    int N,K;
    cin >> N >> K;
    int A[N];
    int d,e,ans=0;
    for (int i=0;i<N;i++) A[i]=0;
    for (int i=0;i<K;i++){
        cin >> d;
        for(int j=0;j<d;j++){
            cin >> e;
            A[e-1]++;
        }
    }
    for(int i=0;i<N;i++){
        if(A[i]==0) ans++;
    }
    cout <<ans;
}

Measured memory_bytes: 3636
/*input
5 1 4
*/
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define watch(x) cout << (#x) << " is " << (x) << endl
#define N 100002

using namespace std;
int main()
{
	fastio
	ll T=1,n,m;string str;
	// cin>>T;
	// cin.ignore(); put after cin, just b4 a getline(cin, s) to avoid getline() directly getting \n
	while(T--)
	{
		ll p=0,q=0,tmp=0,sum=0,count=0; //tmp variable
		int flag=0;
		
		cin>>n>>p>>q;
		// n=;
		// for (int i = 1; i < n; ++i)
		// {
			
		// }
		// ll a[n];
		ll diff = abs(p-q);
		ll a=p;
		ll b = q;
		p= min(a,b);
		q = max(a,b);

		if(diff%2==0)
		{
			cout << diff/2 << endl;
			return 0;
		}
		else
		{
			tmp = min(p-1,n-q);
			tmp++;
			tmp+= (q-p)/2;
			cout << tmp << endl;
			return 0;
		}
		// cout << abs(p-q)/2+(abs(p-q)%2)*2 << endl;
		
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n, x, y;
vector<int> et[2000];
int ans[2000];

signed main() {
	int i, j;
	
	cin >> n >> x >> y;
	x--; y--;
	
	for (i = 0; i < n - 1; i++) {
		et[i].push_back(i + 1);
		et[i + 1].push_back(i);
	}
	et[x].push_back(y);
	et[y].push_back(x);
	
	rep(i, n) {
		int dist[2000];
		rep(j, n) dist[j] = -1;
		dist[i] = 0;
		queue<int> que;
		que.push(i);
		while (!que.empty()) {
			int v = que.front(); que.pop();
			rep(j, et[v].size()) {
				int nv = et[v][j];
				if (dist[nv] == -1) {
					dist[nv] = dist[v] + 1;
					que.push(nv);
				}
			}
		}
		rep(j, n) if (dist[j] >= 1) ans[dist[j]]++;
	}
	
	for (i = 1; i < n; i++) {
		cout << ans[i] / 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iterator>

using namespace std;

int main(){
	
	int n;
	
	float x[4], y[4];
	
	cin >> n;
	
	for(int loop = 0; loop < n; loop++){
		for(int i = 0; i < 4; i++){
			cin >> x[i] >> y[i];
		}
		x[1] -= x[0];
		y[1] -= y[0];
		x[3] -= x[2];
		y[3] -= y[2];
		if(x[3] * y[1] == y[3] * x[1]){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
	
	return 0;
}

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

int main() {
  int a;
  cin>>a;
  
  if(a==7)
    cout<<"YES"<<endl;
  
  else if (a==5)
    cout<<"YES"<<endl;
  
  else if (a==3)
    cout<<"YES"<<endl;
  
  else
    cout<<"NO"<<endl;
  
  
}

Measured memory_bytes: 256
// author-Shivam gupta

#include <bits/stdc++.h>


using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))

#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define IN(A, B, C) assert( B <= A && A <= C)

#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)

#define FOR1(i,j,a) for(int i=j;i<a;i++)

#define EB emplace_back

#define INF (int)1e9

#define EPS 1e-9

#define PI 3.1415926535897932384626433832795

#define MOD 1000000007

#define read(type) readInt<type>()
#define max1 1000008
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
typedef long int li;

typedef unsigned long int uli;

typedef long long int ll;

typedef unsigned long long int  ull;


void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}


int main() {
int n;
cin>>n;
cout<<(n*(n+1))/2;
}



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

int main(void){
    int h = 0, a = 0; 

    scanf("%d%d", &h, &a);

    if(h % a == 0){
        printf("%d\n", h / a);
    }else{
        printf("%d\n", h / a + 1);
    }
    return 0;

} 


Measured memory_bytes: 256
using System;
class ProgramA
    {
        static void Main(string[] args)
        {
            //日付を入力する
            string[] input_1 = Console.ReadLine().Split();
            int a1 = int.Parse(input_1[0]);
            int a2 = int.Parse(input_1[1]);
            int a3 = int.Parse(input_1[2]);

            //月が同じなら月末、それ以外は別
            if(a1+a2+a3 >= 22)
                Console.WriteLine("bust");
            else
            {
                Console.WriteLine("win");
            }
                
        }
    }

Measured memory_bytes: 11092
n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
ex = []
lack = 0
ans = 0
n.times do |i|
  t = a[i] - b[i]
  ex << t if t > 0
  if t < 0
    lack += -t 
    ans += 1
  end
end
ex.sort!.reverse!
ex.each do |v|
  if lack > 0
    lack -= v
    ans += 1
  end
end
p lack <= 0 ? ans : -1


Measured memory_bytes: 16144
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
using namespace std;
int main () { 
	long long x;
	cin >> x;
	if (x <= 6){
		x = 1;
	}else if(x % 11 == 0){
		x = x / 11 * 2;	
	}else if(x % 11 <= 6){
		x = x / 11 * 2 + 1;
	}else if(x % 11 > 6){
		x = x / 11 * 2 + 2;
	}
	
	cout << x << endl;
		
} 			


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

int main(){
	int a, b;
	cin >> a >> b;
	
	cout << a/b << " " << a%b << " " << flush;
	cout << fixed << setprecision(6) << (double)a/(double)b << endl;

	return 0;
}



Measured memory_bytes: 3288
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    if(a>b){
      System.out.print(a+(a-1));
    }else if(a<b){
      System.out.print(b+(b-1));
    }else if(a==b){
      System.out.print(a*2);
    }
  }
}

Measured memory_bytes: 21972
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        l: u64,
        r: u64
    };

    let base_i = l % 2019;
    let mut flag_i = false;
    let mut flag_j = false;
    let mut result = 2019;

    for i in l..r {
        if i % 2019 == base_i && flag_i {
            break;
        }

        flag_j = false;
        let base_j = (i + 1) % 2019;

        for j in i + 1..=r {
            if j % 2019 == base_j && flag_j {
                break;
            }
            result = std::cmp::min(result, (i * j) % 2019);
            flag_j = true;
        }

        flag_i = true;
    }

    println!("{}", result);
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; 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--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  char c;
  cin >> c;
  char p[5] = {'a', 'i', 'u', 'e', 'o'};
  int f = 0;
  REP(i, 5){
    if(c == p[i]) f = 1;
  }
  if(f) cout << "vowel";
  else cout << "consonant";
  return 0;
}


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

int N;

int main() {
    cin >> N;
    vector<int> D(N);
    long long sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> D[i];
        sum += D[i];
    }
    int ans = 0;
    long long neg = 0;
    for (int i = 0; i < N; i++) {
        int b;
        cin >> b;
        sum -= b;
        D[i] -= b;
        if (D[i] < 0) {
            neg += D[i];
            ans++;
        }
    }
    
    if (sum < 0) {
        cout << -1 << endl;
       return 0;
    }
    
    sort(D.begin(), D.end(), greater<int>());
    int i = 0;
    while (neg < 0) {
        neg += D[i];
        ans++;
        i++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
n,k = map(int,input().split())
x = list(map(int,input().split()))

ans = 114514191981036436433-4

for i in range(n+1-k):
    a,b = x[i],x[i+k-1]
    if a < 0 and b < 0:
        ans = min(ans,abs(a))
    elif a >= 0 and b >= 0:
        ans = min(ans,abs(b))
    else:
        ans = min(ans,min(abs(a)+abs(b)*2,abs(b)+abs(a)*2))
        
print(ans)

Measured memory_bytes: 62576
#include<bits/stdc++.h>
using namespace std;
int main(){
	int K;
	string S;
	cin >> K >> S;
	if(S.size()<=K){
		cout << S << endl;
	}else{
		cout << S.substr(0,K) << "..." << endl;
	}
	return 0;
}


Measured memory_bytes: 3628
# from sys import exit
# A, B, C = [int(n) for n in input().split()]
N = int(input())
# a = [int(input()) for _ in range(N)]
# S = str(input())
# L = len(S)
# T = str(input())
# exit()
K = [0 for _ in range(N)]
P = [0 for _ in range(N)]
for i in range(N):
    K[i], P[i] = [int(n) for n in input().split()]
    ans = K[i] % P[i]
    print(ans if ans != 0 else P[i])



Measured memory_bytes: 5600
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#define maxn 1005
#define maxm 200005
using namespace std;
inline int qread(){
	int x=0,sign=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') sign=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x*sign;
}
int n,m; 
int s[maxm],e[maxm];
vector<int>E[maxn];
void add_edge(int u,int v){
	E[u].push_back(v);
}
int used[maxn];
int route[maxn][maxn];
void dfs(int s,int x){
	int y;
	used[x]=1;
	route[s][x]++;
	int cnt=E[x].size();
	for(int i=0;i<cnt;i++){
		y=E[x][i];
		if(y==s) continue;
		if(!used[y]&&route[s][y]<2){
			dfs(s,y);
		}
	}
}

int judge(int u,int v){//1为diff,0为same 
	if(route[v][u]>0){//在一个SCC中 
		if(route[u][v]>=2) return 0;
		else return 1; 
	}else{//不在一个SCC中 
		if(route[u][v]>=2) return 1;
		else return 0;
	}
}

char a[]="same",b[]="diff";
void qprint(char *s,int len){
	for(int i=0;i<len;i++){
		putchar(s[i]);
	}
	putchar('\n');
}
int main(){
//	scanf("%d %d",&n,&m);
	n=qread();
	m=qread(); 
	int u,v;
	for(int i=1;i<=m;i++){
//		scanf("%d %d",&u,&v);
		s[i]=qread();
		e[i]=qread();
		add_edge(s[i],e[i]);
	}
	int y;
	for(int i=1;i<=n;i++){
		int cnt=E[i].size();
		for(int j=0;j<cnt;j++){
			y=E[i][j];
			if(route[i][y]<2){
				memset(used,0,sizeof(used));
				dfs(i,y);
			}
		}
	}
//	for(int i=1;i<=n;i++){
//		for(int j=1;j<=n;j++){
//			printf("%d ",route[i][j]);
//		}
//		printf("\n");
//	}
	for(int i=1;i<=m;i++){
		if(judge(s[i],e[i]) )qprint(b,4);
		else qprint(a,4);
	}
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 1000001;

int n, m, k;
vector <set <int> > row, col, trow, tcol;
vector <string> c;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int x1, y1, x2, y2;
    cin >> n >> m >> k >> x1 >> y1 >> x2 >> y2;
    c.resize(n);
    for(auto &i : c) cin >> i;
    x1--; y1--; x2--; y2--;
    row.resize(n);
    trow.resize(n);
    col.resize(m);
    tcol.resize(m);
    for(int i = 0 ; i < n ; i++){
        row[i].insert(-1e9);
        row[i].insert(1e9);
        trow[i].insert(-1e9);
        trow[i].insert(1e9);
    }
    for(int i = 0 ; i < m ; i++){
        col[i].insert(-1e9);
        col[i].insert(1e9);
        tcol[i].insert(-1e9);
        tcol[i].insert(1e9);
    }
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < m ; j++){
            if(c[i][j] == '.'){
                row[i].insert(j);
                col[j].insert(i);
            }
            else{
                trow[i].insert(j);
                tcol[j].insert(i);
            }
        }
    }
    vector <vector <int> > dist(n, vector <int>(m, (int)1e9));
    vector <pair <int, int> > bfs;
    dist[x1][y1] = 0;
    bfs.push_back(make_pair(x1, y1));
    row[x1].erase(y1);
    col[y1].erase(x1);
    for(int i = 0 ; i < (int)bfs.size() ; i++){
        int x = bfs[i].first, y = bfs[i].second;
        int limit = *trow[x].lower_bound(y);
        while(true){
            int new_y = *row[x].lower_bound(y);
            if(new_y >= limit) break;
            if(new_y - y > k) break;
            dist[x][new_y] = dist[x][y] + 1;
            row[x].erase(new_y);
            col[new_y].erase(x);
            bfs.push_back(make_pair(x, new_y));
        }
        limit = *tcol[y].lower_bound(x);
        while(true){
            int new_x = *col[y].lower_bound(x);
            if(new_x >= limit) break;
            if(new_x - x > k) break;
            dist[new_x][y] = dist[x][y] + 1;
            row[new_x].erase(y);
            col[y].erase(new_x);
            bfs.push_back(make_pair(new_x, y));
        }
        limit = *prev(trow[x].upper_bound(y));
        while(true){
            int new_y = *prev(row[x].upper_bound(y));
            if(new_y <= limit) break;
            if(y - new_y > k) break;
            dist[x][new_y] = dist[x][y] + 1;
            row[x].erase(new_y);
            col[new_y].erase(x);
            bfs.push_back(make_pair(x, new_y));
        }
        limit = *prev(tcol[y].upper_bound(x));
        while(true){
            int new_x = *prev(col[y].upper_bound(x));
            if(new_x <= limit) break;
            if(x - new_x > k) break;
            dist[new_x][y] = dist[x][y] + 1;
            row[new_x].erase(y);
            col[y].erase(new_x);
            bfs.push_back(make_pair(new_x, y));
        }
    }
    if(dist[x2][y2] == 1e9) dist[x2][y2] = -1;
    cout << dist[x2][y2] << endl;
}


Measured memory_bytes: 387068
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>s;
	int res=s.size();
	for(int i=1;i<s.size();i++){
		if(s[i]!=s[i-1]){
			res=min(res,max(i,(int)(s.size()-i)));
		}
	}
	cout<<min(res,(int)(s.size()))<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, 0, n) {
        cin >> a[i];
    }
    vector<int> lmax(n + 1, 0), rmax(n + 1, 0);
    REP(i, 0, n) {
        lmax[i + 1] = max(lmax[i], a[i]);
    }
    for (int i = n - 1; i >= 0; i--) {
        rmax[i] = max(rmax[i + 1], a[i]);
    }
    REP(i, 0, n) {
        cout << max(lmax[i], rmax[i + 1]) << endl;
    }

    return 0;
}


Measured memory_bytes: 3968
// 9132019.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
long long a[1000000] = { 0 };
int ans = 0;
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (i >= 1) a[i] += a[i - 1];
	}
	map<long long,int>fmp;
	map<long long, int>gmp;
	for (int i = 0; i <= n; i++) {
		auto it = fmp.find(a[i]);
		if (it == fmp.end()) {
			fmp.insert(make_pair(a[i], i));
		}
	}
	for (int i = n; i >= 0; i--) {
		auto it = fmp.find(a[i]);
		if (it != fmp.end()) {
			ans = max(ans, i - it->second);
		}
	}
	cout << ans << endl;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file



Measured memory_bytes: 17128
import sys
N, Y = map(int, input().split())

for x in range(N + 1):
    if 10000 * x > Y:
        break
    for y in range(N - x + 1):
        if 10000 * x + 5000 * y > Y:
            break
        z = N - x - y
        if 10000 * x + 5000 * y + 1000 * z == Y:
            print(x, y, z)
            sys.exit()

print('-1 -1 -1')

Measured memory_bytes: 40812
#include <stdio.h>

int main(void) {
	int n, i;
	long int r[200000];
	scanf("%d", &n);
	for(i = 0; n > i; i++){
		scanf("%ld", &r[i]);
	}
	int small = r[0]+1, maxp = 0;
	long int ans = r[1] - r[0];
	for(i = 0; n-1 > i; i++){
		int j;
		if(small > r[i]){
		small = r[i];
		for(j = i+1; n > j; j++){
			if(ans < r[j] - r[i]) ans = r[j] - r[i];
		}
		}
	}
	printf("%ld\n", ans);
	return 0;
}


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

int main() {
  vector<int> vec1(3) , vec2(3) ,vec3(3);
  int N , S;
  
  cin >> vec1.at(0) >> vec1.at(1) >> vec1.at(2);
  cin >> vec2.at(0) >> vec2.at(1) >> vec2.at(2);
  cin >> vec3.at(0) >> vec3.at(1) >> vec3.at(2);

  cin >> N;
  
   for( int i = 0; i < N; i++){
     int bi = 0;
     cin >> bi;
     if( bi == vec1.at(0)) vec1.at(0) = 0;
     if( bi == vec1.at(1)) vec1.at(1) = 0;
     if( bi == vec1.at(2)) vec1.at(2) = 0;
     if( bi == vec2.at(0)) vec2.at(0) = 0; 
     if( bi == vec2.at(1)) vec2.at(1) = 0; 
     if( bi == vec2.at(2)) vec2.at(2) = 0;
     if( bi == vec3.at(0)) vec3.at(0) = 0;  
     if( bi == vec3.at(1)) vec3.at(1) = 0; 
     if( bi == vec3.at(2)) vec3.at(2) = 0;     
   }
  if((vec1.at(0) == 0 && vec1.at(1) == 0 && vec1.at(2) == 0) || 
     (vec2.at(0) == 0 && vec2.at(1) == 0 && vec2.at(2) == 0) ||
     (vec3.at(0) == 0 && vec3.at(1) == 0 && vec3.at(2) == 0) || 
     (vec1.at(0) == 0 && vec2.at(0) == 0 && vec3.at(0) == 0) || 
     (vec1.at(1) == 0 && vec2.at(1) == 0 && vec3.at(1) == 0) || 
     (vec1.at(2) == 0 && vec2.at(2) == 0 && vec3.at(2) == 0) || 
     (vec1.at(0) == 0 && vec2.at(1) == 0 && vec3.at(2) == 0) || 
     (vec1.at(2) == 0 && vec2.at(1) == 0 && vec3.at(0) == 0) )
    cout << "Yes" ;
  else cout << "No";
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n: usize = read();
    let a: Vec<i64> = read_vec();
    let mut dp = vec![Vec::new(); 1 << n];

    for j in 0..1 << n {
        dp[j].push(a[j]);
    }
    for i in 0..n {
        for j in (0..1 << n).rev() {
            if (1 << i) & j != 0 {
                let mut dum = dp[j - (1 << i)].clone();
                dp[j].append(&mut dum);
                dp[j].sort();
                let first = dp[j][dp[j].len() - 1];
                let second = dp[j][dp[j].len() - 2];
                dp[j] = vec![second, first];
            }
        }
    }
    let mut current_max = 0;
    for j in 1..1 << n {
        let first = dp[j].pop().unwrap();
        let second = dp[j].pop().unwrap();
        current_max = max(current_max, first + second);
        println!("{}", current_max);
    }
}


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

int main(void){
  int a,b; cin >> a >> b;
  int ans;
  for(int i= 1; i <=3; ++i){
    if(i != a && i != b){
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<double,double> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int n;
vector<array<int,3>> v;

bool ok(array<int,3> a, array<int,3> b) {
    int need = abs(a[1]-b[1])+abs(a[2]-b[2]);
    return b[0]-a[0] >= need && (b[0]-a[0]-need) % 2 == 0;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n; v.pb({0,0,0});
    F0R(i,n) {
        int a,b,c; cin >> a >> b >> c;
        v.pb({a,b,c});
    }
    FOR(i,1,n+1) if (!ok(v[i-1],v[i])) {
        cout << "No";
        exit(0);
    }
    cout << "Yes";
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)


Measured memory_bytes: 1912
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,K = map(int, readline().split())

    if N > K:
        print(min(N % K, abs((N % K) - K)))
    else:
        print(min(abs(N-K), N))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 500020
using namespace std;
int read(){
	int nm=0,fh=1;char cw=getchar();
	for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
	return nm*fh;
}
int n,m,t[3][M],p[M],cnt,pos[M];
void fail(){puts("No");exit(0);}
void ROW(int x,int y,int z){
	if(x>z) swap(x,z);
	if(y!=x+1||y!=z-1) return fail();
	if(y%3!=2) return fail();
}
int main(){
	n=read();
	for(int j=0;j<3;j++){
		for(int i=1;i<=n;i++) t[j][i]=read();
	}
	for(int i=1;i<=n;i++){
		ROW(t[0][i],t[1][i],t[2][i]);
		p[i]=(t[1][i]+1)/3;
		if(t[0][i]>t[2][i]) p[i]=-p[i];
		if(abs(abs(p[i])-i)&1) fail();
		pos[abs(p[i])]=i;
	}
	for(int i=1;i<=n;i++){
		if(pos[i]==i) continue;
		p[i+1]=-p[i+1],swap(p[i],p[pos[i]]);
		if((abs(i-pos[i])>>1)&1) p[i]=-p[i],p[pos[i]]=-p[pos[i]];
		pos[abs(p[pos[i]])]=pos[i],pos[i]=i;
	}
	for(int i=1;i<=n;i++) if(p[i]<0) cnt++;
	if(cnt&1) fail();
	if(n<=3&&cnt>0) fail();
	if(n==4&&cnt%4>0) fail();
	for(int i=1;i<n-1;i++) if(p[i]<0) p[i]=-p[i],p[i+2]=-p[i+2];
	if(p[n-1]<0||p[n]<0) fail();
	puts("Yes");
	return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

// 正方形[i+1, i+k] * [j+1, j+k]の区間にある条件を満たすものを調べる
int calc(int i, int j, int k, vector<vi> &mp) {
  if (i >= 2 * k || j >= 2 * k)
    return 0;
  int right = min(j + k, 2 * k);
  int left = max(j, 0);

  int top = min(i + k, 2 * k);
  int bottom = max(i, 0);

  return mp[top][right] - mp[bottom][right] - mp[top][left] + mp[bottom][left];
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<vi> w(2 * k + 1, vi(2 * k + 1, 0)), b(2 * k + 1, vi(2 * k + 1, 0));

  // [1,2k]の区間に全部収める
  REP(i, n) {
    int x, y;
    char c;
    cin >> x >> y >> c;
    x %= 2 * k;
    y %= 2 * k;
    x++;
    y++;
    if (c == 'W') {
      w[y][x]++;
    } else {
      b[y][x]++;
    }
  }

  // 累積和を取る.
  FOR(i, 1, 2 * k + 1) {
    FOR(j, 1, 2 * k + 1) {
      w[i][j] += w[i - 1][j] + w[i][j - 1] - w[i - 1][j - 1];
      b[i][j] += b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1];
    }
  }

  // 2k*2kのマスの内部にある正方形のうち、それぞれの左下を指定してあげることで計算する。
  int ans = 0;
  REP(i, 2 * k + 1) {
    REP(j, 2 * k + 1) {
      int white = calc(i, j, k, w) + calc(i + k, j + k, k, w) +
                  calc(i - k, j - k, k, w) + calc(i + k, j - k, k, w) +
                  calc(i - k, j + k, k, w);
      int black = calc(i + k, j, k, b) + calc(i, j + k, k, b) +
                  calc(i - k, j, k, b) + calc(i, j - k, k, b);

      ans = max(ans, white + black);
    }
  }

  REP(i, 2 * k + 1) {
    REP(j, 2 * k + 1) {
      int white = calc(i, j, k, b) + calc(i + k, j + k, k, b) +
                  calc(i - k, j - k, k, b) + calc(i + k, j - k, k, b) +
                  calc(i - k, j + k, k, b);
      int black = calc(i + k, j, k, w) + calc(i, j + k, k, w) +
                  calc(i - k, j, k, w) + calc(i, j - k, k, w);

      ans = max(ans, white + black);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 31616
import bisect

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

A = sorted(A)
B = sorted(B)
C = sorted(C)

ans = 0

for b in B:
    aPtn = bisect.bisect_left(A, b)
    cPtn = len(C) - bisect.bisect_right(C, b)
    ans += aPtn * cPtn

print(ans)


Measured memory_bytes: 23360
void main() {
	auto ip = readAs!(int[]), H = ip[0], W = ip[1];
	auto s = readMatrix!char(H, W);
	auto dx = [-1, 0, 1, 0];
	auto dy = [0, 1, 0, -1];
	foreach(i; 0..H) foreach(j; 0..W) {
		if(s[i][j] == '#') {
			bool ok = false;
			foreach(k; 0..4) {
				if(i-dx[k] >= 0 && i-dx[k] < H &&
					j-dy[k] >= 0 && j-dy[k] < W &&
					s[i-dx[k]][j-dy[k]] == '#') {
					ok = true;
				}
			}
			if(!ok) {
				"No".writeln;
				return;
			}
		}
	}
	"Yes".writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

T[] deepcopy(T)(T[] a) {
	static if(isArray!T) {
		T[] res;
		foreach(i; a) {
			res ~= deepcopy(i);
		}
		return res;
	} else {
		return a.dup;
	}
}

Measured memory_bytes: 256
using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main(string[] args)
    {
        var str = Console.ReadLine();
        var id = Console.ReadLine();
        if ((id.Length == str.Length + 1) && (id.IndexOf(str) == 0))
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 26164
#include<iostream>
using namespace std;
const int maxn = 3e5 + 5;
const int MOD = 998244353;
#define LL long long
LL n,a,b,k;
LL fac[maxn];
LL inv[maxn];
LL C(LL x){
    return (fac[n] * inv[x]%MOD) *inv[n-x] %MOD;
}
int main()
{
    cin>>n>>a>>b>>k;
    if(k == 0){
        cout<<1<<endl;
        return 0;
    }
    fac[0]=inv[0]=inv[1]=1;
	for (int i=2;i<=n;i++)
		inv[i]=1ll*inv[MOD%i]*(MOD-MOD/i)%MOD;
	for (int i=1;i<=n;i++){
		fac[i]=1ll*fac[i-1]*i%MOD;
		inv[i]=1ll*inv[i-1]*inv[i]%MOD;
	}
	LL ans = 0;
    for(int red = 0;red<=n;red++){
        LL rest = k - red * a;
        LL blue = rest / b;
        if(rest % b == 0 && blue <= n && rest >= 0){
            ans = (ans + C(red) * C((LL)rest / b)) % MOD;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
const int N = 1e5+7;
vector<int>adj[N];
int mp[N];
int vist[N];
int dfs(int src){
	int cnt=0;
	if(vist[src]!=0){
		return vist[src];
	}
	for(auto x :adj[src]){
		cnt=max(cnt,dfs(x));
	}
	cnt++;
	vist[src]=cnt;
	return cnt;

}

int main(){
	int n,m,a,b;
	cin>>n>>m;;
	for(int i=0;i<m;i++){
		cin>>a>>b;
		mp[b]++;
		adj[a].push_back(b);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(mp[i]==0){
		
			ans=max(dfs(i),ans);
		}
	}
	cout<<ans-1;


}

Measured memory_bytes: 11136
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#undef LOCAL
#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#ifdef LOCAL
struct PrettyOS {
    ostream& os;
    bool first;
    template <class T> auto operator<<(T&& x) {
        if (!first) os << ", ";
        first = false;
        os << x;
        return *this;
    }
};
template <class... T> void dbg0(T&&... t) {
    (PrettyOS{cerr, true} << ... << t);
}
#define dbg(...)                                            \
    do {                                                    \
        cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \
        dbg0(__VA_ARGS__);                                  \
        cerr << endl;                                       \
    } while (false);
#else
#define dbg(...)
#endif

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

ll calc(string s) {
    int n = int(s.size());
    ll ans = 0;
    int l = 0;
    while (l < n) {
        int r = l;
        while (r < n && s[l] == s[r]) r++;
        ans += (r - l) / 2;
        l = r;
    }
    return ans;
}

string rep(string s, int k) {
    string t;
    for (int i = 0; i < k; i++) {
        t += s;
    }
    return t;
}

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

    string s;
    int k;
    cin >> s >> k;

    if (k < 1000) {
        cout << calc(rep(s, k)) << endl;
    } else {
        int u = (k - 900) / 2;
        k -= 2 * u;
        ll a = calc(rep(s, k));
        ll b = calc(rep(s, k + 2));
        cout << a + (b - a) * u << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int search(int N[],int n,int keyli){
  int i=0;
  N[n]=keyli;
  while(N[i]!=keyli)i++;
  return i !=n;

}

int main(){
  int i,n,N[10000+1],q,keyli,sum=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&N[i]);
}

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&keyli);
    if(search(N,n,keyli))sum++;
}
  printf("%d\n",sum);

  return 0;
}



Measured memory_bytes: 2052
#include<stdio.h>
int main (){

  int k,c,r,i,temp,x=0,y;
  int sum[100];

  for(r=0;r<101;r++)
    {sum[r]=0;}
 #include<stdio.h>
int main (){

  int k,c,r,i,temp,x=0,y;
  int sum[100];

  for(r=0;r<101;r++)
    {sum[r]=0;}
 
  
  scanf("%d",&k);

    while (k!=0){
      
     
      temp=k*(k-1)/2;

      for (i=0 ; i <temp ; i++){
	scanf("%d",&c);
	sum[x]+=c;
      }
      sum[x]=sum[x]/(k-1);
	
      scanf("%d",&k);
      x=x+1;
      
    }

    for(y=0;y<x;y++){
      printf("%d\n",sum[y]);
    }
    return 0;
}

  
  scanf("%d",&k);

    while (k!=0){
      
     
      temp=k*(k-1)/2;

      for (i=0 ; i <temp ; i++){
	scanf("%d",&c);
	sum[x]+=c;
      }
      sum[x]=sum[x]/(k-1);
	
      scanf("%d",&k);
      x=x+1;
      
    }

    for(y=0;y<x;y++){
      printf("%d\n",sum[y]);
    }
    return 0;
}

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

#define ll long long
#define fis cout << fixed; cout << setprecision(10)


int solve() {

	string s;
	cin >> s;
	char ch = s[s.length() - 1];
	string hon = "24579";
	string pon = "0168";
	string bon = "3";
	if(hon.find(ch) != string::npos) {
		cout << "hon\n";
	}
	else if(pon.find(ch) != string::npos) {
		cout << "pon\n";
	}
	else 
		cout << "bon\n";


	return 0;
}

int main() {

	ios::sync_with_stdio(false);
	cin.tie(NULL);
	solve();

	return 0;
}

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

using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int in() {int x; cin>>x; return x;}
string stin() {string s; cin>>s; return s;}
/***** MAIN *****/
signed main() {
  string s = stin();
  string sub_s = stin();
  bool restorable = false;

  // 後ろからsubstring(sub_s)が入るかどうか探索
  for(int i = s.size()-sub_s.size(); i >= 0; --i) {
    bool restorable_sub = true;
    for(int j = 0; j < sub_s.size(); ++j) {
      if(s[i+j] == '?') continue;
      if(s[i+j] == sub_s[j]) continue;
      else {
        restorable_sub = false;
        break;
      }
    }
    
    // substringが入るとき、'?'ごとsubstringに置き換え
    if(restorable_sub) {
      for(int j = 0; j < sub_s.size(); ++j) {
        s[i+j] = sub_s[j];
      }
      restorable = true;
      break;
    }
  }

  // substringがどこにも入らなかった時
  if(!restorable) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  // substringで置き換えたところ以外は'a'で埋める（辞書順で最も前の文字列を作る）
  for(int i = 0; i < s.size(); ++i) {
    if(s[i] == '?') cout << 'a';
    else cout << s[i];
  }
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 256
#include<iostream>
#include<map>
#define f0r(n,i) for(int i=1;i<=n;i++)
using namespace std;
map<string,int>coun;
int n,result=1;
char check;
string word;
int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n;
    f0r(n,i)

    {
        cin >> word;
        coun[word]++;
        if( (coun[word]>1 || check!=word[0]) && i>1) result=0;
        check=word[word.length()-1];
    }
    if( result == 0 ) cout<<"No";
    else cout<<"Yes";
}


Measured memory_bytes: 256