akhauriyash/Code-Regression huggingface dataset:
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(V) sort((V).begin(),(V).end())
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) for(int i = 0; i < (V).size(); i++) {cout << (V).at(i) << endl;}

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

// デフォルト変数定義
int n,m,a,b,c=1,x,y,z;
string s,t;
//

signed main() {
  RAPID;
  IN(n);
  Vi p(n);
  Vi q(n);
  VIN(p)
  VIN(q)
  Vi nums;
  FOR(i, 1, n+1) {
    nums.pb(i);
  }
  while(next_permutation(nums.begin(), nums.end())) {
    if(p == nums) {
      a = c;
    }
    if(q == nums) {
      b = c;
    }
    c++;
  }
  OUT(abs(a-b));
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

const ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
int main() {
	ll n, i, m, c[111111], dp[111111],a;
	cin >> n >> m;
	for (i = 0; i < n; i++)
		c[i] = 0;
	for (i = 0; i < m; i++) {
		cin >> a;
		c[a]++;
	}
	dp[0] = 1;
	if (c[1] == 0)
		dp[1] = 1;
	else
		dp[1] = 0;
	for (i = 2; i <= n; i++) {
		if (c[i] == 0)
			dp[i] = (dp[i - 1] + dp[i - 2]) % M;
		else
			dp[i] = 0;
	}
	cout << dp[n] << endl;
}

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

int main(){
int a,b,c,e;
  cin>>a>>b>>c;
 bool d=true;
  for(int i=1;i<=3000;i++){
    e=a*i;
    if(e%b==c){
      cout<<"YES"<<endl;
      d=false;
      break;
    }
  }
  if(d)
    cout<<"NO"<<endl;
}


Measured memory_bytes: 256
package main

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

func main() {
        var s = bufio.NewScanner(os.Stdin)
        var in string
        if s.Scan() {
                in = s.Text()
        }
        sl := strings.SplitN(in, " ", 2)
        if len(sl) != 2 {
                panic("invalid input")
        }
        t, err := strconv.ParseFloat(sl[0], 64)
        if err != nil {
                panic(err)
        }
        x, err := strconv.ParseFloat(sl[1], 64)
        if err != nil {
                panic(err)
        }
        result := strconv.FormatFloat(t/x, byte('f'), 13, 64)
        fmt.Println(result)
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
using ll = long long;
using P = pair<int, int>;
const double pi = 3.14159265358979323846;

int main(){
    int a, b, h, m;
    cin >> a >> b >> h >> m;

    double argh = 0.5 * (60 * h + m);
    int argm = 6 * m;

    double arg;
    if (argm - argh <= 180) arg = argm - argh;
    else arg = argh - argm;

    double ans = sqrt(a * a + b * b - 2 * a * b * cos(2 * pi * arg / 360));

    cout << fixed << setprecision(15) << ans << endl;

    return 0;
}

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

int main() {
 int n,k;
 cin >> n >> k;
 int x = 1;
 for(int i = 0;i < n;i++){
   if(x < k){
     x *= 2;
   }else{
     x += k;
   }
 }
 cout << x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    ll x;
    cin >> x;

    for(ll i = 1; i <= x; i++) {
        if (i*(i+1)/2 >= x) {
            cout << i << endl;
            break;
        }
    }

    return 0;
}

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

const string YES = "Yes";
const string NO = "No";
int main(){
  int X, Y; cin >> X >> Y;
  bool ans = false;
  for (int i = X; i <= X * 2; i++) {
    if (i * 2 == Y) ans = true;
  }
  if (ans) cout << YES << endl;
  else cout << NO << endl;
}


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

int main(){
	int n;
	cin >> n;
	int a[n + 1];
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	int sum = 0;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			sum+=a[i] * a[j];
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
//QWsin
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

inline void print(string name,int *arr,int len){
	rep(i,1,len) printf("%s[%d]=%d\n",name.c_str(),i,arr[i]);puts("");
}
inline void print(string name,int a){
	printf("%s=%d\n",name.c_str(),a);puts("");
}

typedef long long ll;
const int INF=1<<30;

const int maxn=10+10;

int P[maxn],Q[maxn],id[maxn];

int n;
int same(int *a,int *b){
	rep(i,1,n) if(a[i]!=b[i]) return 0;
	return 1;
}

int Greater(int *a,int *b){
	rep(i,1,n) 	
		if(a[i]>b[i]) return 1;	
		else if(a[i]<b[i]) return 0;
	return 0;
}

int main()
{
	cin>>n;
	rep(i,1,n) cin>>P[i];
	rep(i,1,n) cin>>Q[i];
	//P<Q
	if(Greater(P,Q)){
		rep(i,1,n)	swap(P[i],Q[i]);
	}
	rep(i,1,n) id[i]=i;
	int tmp=0,in=0;
	do{
		if(!in && same(P,id)){
			in=1;	
		}
		if(in){
			if(same(Q,id)) break;
			else ++tmp;	
		}
	}while(next_permutation(id+1,id+n+1));
	cout<<tmp<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
long long k,s,yz,ans,t,p;
using namespace std;
int main()
{
	cin>>k>>s;
	for(int x=0;x<=k;x++)
	{
		if(x>s) break;
		yz=s-x;
		p=yz+1;
		if(yz<=k) ans+=p;
		else
		{
			t=yz-k;
			if(p-t*2>=0)ans+=p-t*2;
		}
	}
	cout<<ans;
	return 0;
}

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

int main() {
  double x1, x2, y1, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  double distance = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  cout << fixed << setprecision(5);
  cout << distance << endl;

  return 0;
}


Measured memory_bytes: 3288
#include<bits/stdc++.h>
using namespace std;
int n;
long long m,a[100010],tmp[100010],num=1;
long long gcd(long long x,long long y) {
	if(y==0) return x;
	return gcd(y,x%y);
}
int main()
{
	scanf("%d%lld",&n,&m);
	for(int i=1;i<=n;++i) scanf("%lld",&a[i]),tmp[i]=a[i]/2;
	num=tmp[1];
	for(int i=2;i<=n;++i) {
		num=num*tmp[i]/gcd(num,tmp[i]);
		if(num>m) {
			printf("0");
			return 0;
		}
	}
	for(int i=1;i<=n;++i)
		if(num%a[i]!=tmp[i]) {
			printf("0");
			return 0;
		}
	printf("%lld",(m/num+1)/2);
	return 0;
}

Measured memory_bytes: 1792
n = int(input())
l = [[0]*3 for i in range(n)]

for i in range(n - 1):
    c, s, f = map(int, input().split())
    l[i][0] = c
    l[i][1] = s
    l[i][2] = f

for i in range(n - 1):
    t = 0
    for j in range(i, n - 1):
        t = max(l[j][1], t)
        mod = abs(t - l[j][1])%l[j][2]
        if mod != 0:
            t += l[j][2] - mod
        t += l[j][0]
    print(t)

print(0)

Measured memory_bytes: 9152
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
struct Edge { LL to, cost; };
LL h, w, n, m, s, t, k, ans = 0, a[100001], d[100001];
Ppll pp[200002];
vector<Edge>vec[100001];
int main() {
	cin >> n >> m >> t >> s;
	s /= 50;
	rep(i, n+1)
		rep(j, m+1)
		rep(h, t+1) {
		if (i * 10 + j * 2 + h == s)
			ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4352
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let arr:Vec<f64> = (0..n).map(|_| read()).collect();
    if arr.len() == 1 {
        println!("{}", arr[0]);
    } else {
        let mut numerator = 0.0;
        for i in 1..arr.len() {
            numerator = lcm(arr[i], arr[i-1]);
        }
        let mut denomintor = 0.0;
        for i in arr {
            denomintor += 1.0 * numerator/i;
        }
        println!("{}", numerator/denomintor);
    }
}

fn gcd(a:f64, b:f64) -> f64 {
    if b == 0.0 {
        return a;
    }
    return gcd(b, a % b);
}

fn lcm(a:f64, b:f64) -> f64 {
    return a * b / gcd(a, b);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	map<string,lli> cnt;

	lli n;
	cin>>n;
	REP(i,0,n){
		string s;
		cin>>s;
		cnt[s]++;
	}

	lli m;
	cin>>m;
	REP(i,0,m){
		string s;
		cin>>s;
		cnt[s]--;
	}

	lli ans = 0;
	for(auto e:cnt){
		ans =max(ans,e.second);
	}
	cout<<ans<<endl;



	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stddef.h>
#include <stack>
#include <queue>
#include <cctype>
#include <stdio.h>

using namespace std;


int main() {
	
	char ch;
	int a[26];
	fill(a, a + 26, 0);
	
	while (scanf("%c",&ch)!=EOF) {
		if (isalpha(ch)) {
			if (isupper(ch)) ch = tolower(ch);
			a[ch - 'a']++;
		}
	}


	for (int i = 0; i < 26; i++) {
		cout << (char)('a' + i) << " : " << a[i] << endl;
	}
	
}

Measured memory_bytes: 1160
# import itertools
# import math
# import sys
# import numpy as np

N = int(input())
# S = input()
# n, *a = map(int, open(0))
# N, K = map(int, input().split())
# A = list(map(int, input().split()))
# Q = list(map(int, input().split()))
# S = input()

# d = sorted(d.items(), key=lambda x:x[0]) # keyでsort

X = list(map(int, input().split()))

tots = []
for i in range(1, 101):
    tot = 0
    for j in X:
        tot += (j - i) ** 2
    tots.append(tot)

print(min(tots))

Measured memory_bytes: 9180
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
const int MAX = 305;
int dp[MAX][MAX];
int num[MAX];

int dfs(int l, int r){
    if(dp[l][r]!=-1)return dp[l][r];
    if(l >= r){
        dp[l][r]=0;
        return 0;
    }
    if(l+1==r){
        if(abs(num[l]-num[r])<2){
            dp[l][r] = 2;
            return 2;
        }
        else{
            dp[l][r] = 0;
            return 0;
        }
    }
    for(int p = l; p <= r; p++){
        dp[l][r] = max(dp[l][r], dfs(l, p) + dfs(p+1, r));
    }
    if(abs(num[l]-num[r])<2 && dfs(l+1, r-1)==(r-l-1)){
        dp[l][r]=r-l+1;
    }
    return dp[l][r];
}

int main(){
    for(int n;cin>>n,n;){
        for(int i = 0; i < MAX; i++){
            for(int j = 0; j<MAX;j++){
                dp[i][j]=-1;
            }
        }
        for(int i=1;i<=n;i++){
            cin>>num[i];
        }
        cout<<dfs(1, n)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3500
/*
    author: kartik8800
*/
#include<bits/stdc++.h>
#define ll long long
#define fr(a,b) for(int i = a; i < b; i++)
#define mod 1000000007
#define inf (1LL<<60)
#define triplet pair<int,pair<int,int>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

vector<int> tree[100001];
ll dp[100001][2];

ll solve(int u, bool constraint, int pr)
{
    if(dp[u][constraint] != -1)
        return dp[u][constraint];
    ll ans = 0;
    ll w1 = 1;
    for(int child : tree[u])
    {
        if(child != pr)
            w1 = (w1 * solve(child, 0, u)) % mod;
    }
    ans += w1;
    if(!constraint)
    {
     ll w2 = 1;
        for(int child : tree[u])
        {
            if(child != pr)
                w2 = (w2 * solve(child, 1, u)) % mod;
        }  
     ans = (ans + w2)%mod; 
    }
    return dp[u][constraint] = ans;
}

int main(){
    int n;
    cin>>n;
    memset(dp, -1, sizeof dp);
    for(int i=0; i < n-1; i++)
    {
        int u,v;
        cin >> u >> v;
        tree[u].push_back(v);
        tree[v].push_back(u);
    }
    cout << solve(1, 0, -1);
    return 0;
}

Measured memory_bytes: 15616
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdlib.h>
using namespace std;

int change(char x) {
	if (x == '0') {
		return 0;
	}
	if (x == '1') {
		return 1;
	}
	if (x == '2') {
		return 2;
	}
	if (x == '3') {
		return 3;
	}
	if (x == '4') {
		return 4;
	}
	if (x == '5') {
		return 5;
	}
	if (x == '6') {
		return 6;
	}
	if (x == '7') {
		return 7;
	}
	if (x == '8') {
		return 8;
	}
	if (x == '9') {
		return 9;
	}
}

int main() {
	string S;
	int ans = 0;
	cin >> S;

	char a = S.at(0);
	char b = S.at(1);
	char c = S.at(2);
	char d = S.at(3);

	int one = change(a) * 10 + change(b);
	int two = change(c) * 10 + change(d);

	if (1 <= one && one <= 12) {
		ans += 1;
	}
	if (1 <= two && two <= 12) {
		ans += 2;
	}

	switch (ans) {
		case 0:cout << "NA" << endl; break;
		case 1:cout << "MMYY" << endl; break;
		case 2:cout << "YYMM" << endl; break;
		case 3:cout << "AMBIGUOUS" << endl; break;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

typedef long long int llint;

int main()
{
    char s[101];
    llint k;
    scanf("%s",s);
    scanf("%lld",&k);

    if(s[0]=='1')
    {
        for(int i=1;i<k;i++)
        {
            if(s[i]!='1')
            {
                printf("%c\n",s[i]);
                return 0;
            }
        }
        printf("1\n");
        return 0;
    }
    else printf("%c\n",s[0]);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
#define f2(i,j,k) for(int i=j;i>k;i--)
using namespace std;
int main(){
    long long n,ans=0;
    cin>>n;
    string s;
    cin>>s;
    f(i,0,n){
        long long d=0;
        vector<long long> a(26),b(26);
        f(j,0,i){
            a[s[j]-'a']++;
        }
        f(j,i,n){
            b[s[j]-'a']++;
        }
        f(j,0,26){
            if(a[j]>0&&b[j]>0){
                d++;
            }
        }
        ans=max(ans,d);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <math.h>



struct Circle{   // 円定義構造体
	float x,y;   // x,y:中心点座標
	float r;   // r:円の半径
};


int main(){
	struct Circle C1;
	struct Circle C2;
	int check;
	int x1,x2,x3,xr,y2,y1,yr,d;
	
	scanf("%d %d %d", &x1,&x2,&xr);
	scanf("%d %d %d", &y1,&y2,&yr);
	
	C1.x = x1;
	C1.y = x2;
	C1.r = xr;	
	C2.x = y1;
	C2.y = y2;
	C2.r = yr;	


	// 円同士の当たり判定
	float r = C1.r + C2.r;   // ２円の半径の合計
	float x = C1.x - C2.x;   // X座標の差
	float y = C1.y - C2.y;   // Y座標の差

 d = sqrt(x*x+y*y);

	if(d>r)check=4;
	else if (d==r)  check=3;
	else if(fabs(C1.r - C2.r)<d && d<r)check=2;
	else if(d==fabs(C1.r - C2.r)) check=1;
	else check=0;

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

			return 0;
}




Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int T[N << 2], a[N], dp[N], n, k;

void change(int rt, int tl, int tr, int pos, int val)
{
    if(tl == tr){
        T[rt] = max(T[rt], val);
        return;
    }
    int mid = tl + tr >> 1;
    if(mid >= pos) change(2 * rt, tl, mid, pos,  val);
    else change(2 * rt + 1, mid + 1, tr, pos, val);
    T[rt] = max(T[2 * rt], T[2 * rt + 1]);
}

int query(int rt, int ql, int qr, int tl, int tr)
{
    if(tl >= ql && tr <= qr){
        return T[rt];
    }
    int mid = tl + tr >> 1;
    int res = 0;
    if(mid >= ql) res = max(res, query(2 * rt, ql, qr, tl, mid));
    if(mid + 1 <= qr) res = max(res, query(2 * rt + 1, ql ,qr, mid + 1, tr));
    return res;
}
int main()
{
    cin >> n >> k;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    dp[1] = 1;
    int ans = 0;
    change(1, 0, N, a[1], dp[1]);
    for(int i = 2; i <= n; ++i){
        dp[i] = query(1, max(0, a[i] - k), min(a[i] + k, N - 5), 0, N) + 1;
        change(1, 0, N, a[i], dp[i]);
        ans = max(ans, dp[i]);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 10092
import copy
h, w, knum = map(int, input().split())
c = [list(input()) for _ in range(h)]

ans = 0
ccopy = copy.deepcopy(c)
hbin = list(map(bin, list(range((2**h)))))
hbin = list(map(lambda x:x[2:], hbin))
for i,item in enumerate(hbin):
    item = "0"*(h-len(item)) + item
    hbin[i] = list(item)
wbin = list(map(bin, list(range((2**w)))))
wbin = list(map(lambda x:x[2:], wbin))
for i,item in enumerate(wbin):
    item = "0"*(w-len(item)) + item
    wbin[i] = list(item)

for i in hbin:
    ccopy = copy.deepcopy(c)
    for j,switch in enumerate(i):
        if int(switch) == 1:
            ccopy[j] = list("R"*w)
    for k in wbin:
        ccopy2 = copy.deepcopy(ccopy)
        for l,switch in enumerate(k):
            if int(switch) == 1:
                for m in range(h):
                    ccopy2[m][l] = "R"
        ccopy2 = list(map(lambda x:x.count("#"), ccopy2))
        if  knum == sum(ccopy2):
            ans += 1
        ccopy2 = copy.deepcopy(ccopy)
print(ans)


Measured memory_bytes: 9352
#include<iostream>
#include<cstdio>
#include<iomanip>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    string ans="No";
    if(a+b==c){
        ans="Yes";
    }else if(a+c==b){
        ans="Yes";
    }else if(b+c==a){
        ans="Yes";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a[4][13] = {{ 0 }};
    int n;
    int i, j;
    int  y;
    char x[2];
    scanf("%d", &n);
    for (i=0;i<n;i++){
        scanf("%s %d", x, &y);
        if(x[0]=='S'){
            a[0][y-1]++;
        }
        if(x[0]=='H'){
            a[1][y-1]++;
        }
        if(x[0]=='C'){
            a[2][y-1]++;
        }
        if(x[0]=='D'){
            a[3][y-1]++;
        }
    }
    for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            if(a[i][j]!=1){
                if(i==0){
                    printf("S %d\n", j+1);
                }
                if(i==1){
                    printf("H %d\n", j+1);
                }
                if(i==2){
                    printf("C %d\n", j+1);
                }
                if(i==3){
                    printf("D %d\n", j+1);
                }
            }
        }
    }
    return 0;
}


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

int main(){
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	
	int ans = 0;
	
	for(int i = 0; i < k; i++){
		if(a != 0){
			ans++;
			a--;
		} else if(b != 0){
			b--;
		} else if(c != 0){
			ans--;
			c--;
		}
	}
	
	cout << ans;
	
	return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>

long modpow(long a, long n, long mod){
	if (n == 0) {
		return 1;
	}
	long answer;
	if (n%2 == 0) {
		answer = modpow(a, n/2, mod);
		answer *= answer;
	} else {
		answer = modpow(a, n-1, mod);
		answer *= a;
	}
	answer %= mod;
	return answer;
}

int main(void) {

	long n,m,k;
  scanf("%ld %ld %ld", &n, &m, &k);
  long mod = 998244353;
  long answer = modpow(m-1,n-1,mod);
  answer *= m;
  answer %= mod;
  long plus;
	long combination = 1;
  for (long i = 1; i <= k; i++) {
		combination *= n-i;
		combination %= mod;
		combination *= modpow(i,mod-2,mod);
		combination %= mod;
		plus = combination;
    plus *= modpow(m-1,n-1-i,mod);
    plus %= mod;
    plus *= m;
    plus %= mod;
    answer += plus;
    answer %= mod;
  }
  printf("%ld\n", answer);

  return 0;
}

Measured memory_bytes: 1700
import java.util.*;
class Main
{
 public static void main(String[] args)
  {
   Scanner s = new Scanner(System.in);
   String one = s.next();
   String two = s.next();
   String three = s.next();
   
   System.out.println(one.charAt(0)+""+two.charAt(1)+""+three.charAt(2) );
   }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*

*/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  
  string S; cin>>S;
  if (S=="ABC")
    cout<<"ARC"<<endl;
  else
    cout<<"ABC"<<endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5005;
const ll inf=0x3f3f3f3f3f3f3f3fll;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,A,B,pos[N];
ll f[N],ans;
int main(){
	n=read();A=read();B=read();
	for (int i=1;i<=n;i++) pos[read()]=i-1;
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++) f[j]=min(f[j],f[j-1]);
		for (int j=0;j<=n;j++) f[j]+=(pos[i]==j) ? 0 : ((pos[i]<j) ? A : B);
	}
	ans=inf;
	for (int i=0;i<=n;i++) ans=min(ans,f[i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
def main():
    global E, F
    A, B, C, D, E, F = map(int, input().split())

    waterA, waterB = 100 * A, 100 * B
    water = set()
    i = 0
    while waterA * i <= F:
        j = 0
        while waterA * i + waterB * j <= F:
            water.add(waterA * i + waterB * j)
            j += 1
        i += 1

    sugar = set()
    i = 0
    while C * i <= F // 100 * E:
        j = 0
        while C * i + D * j <= F // 100 * E:
            sugar.add(C * i + D * j)
            j += 1
        i += 1

    ph = dict()
    for i in persent(water, sugar):
        ph[i[0]] = i[1], i[2]

    a, b = ph[max(ph)]
    print(a + b, b)

def persent(w, s):
    max_ph = 100 * E / (100 + E)
    for a in w:
        for b in s:
            if 0 < a + b <= F:
                x = 100 * b / (a + b)
                if x <= max_ph:
                    yield x, a, b

main()


Measured memory_bytes: 4284
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cstdlib>

using namespace std;

int main()
{
    int p[200];
    int i,n,m,c,x,b,a;
    cin>>n>>m>>x;
    for(i=0; i<m; i++)
    {
        cin>>p[i];
    }
    for(i=0,a=0,c=0,b=0; i<m; i++)
    {
        if(p[i]>x&&p[i]<n)
            a++;
        if(p[i]>0&&p[i]<x)
            c++;
    }
    b= a < c ? a : c;
    cout<<b<<endl;
    return 0;
}


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


int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  string s; cin >> s;
  int np = 0;
  for (int i = 0; i < (int)s.size(); i++) if (s.at(i) == 'p') np++;
  int myNp = s.size() / 2;
  cout << myNp - np << endl;

  return 0;
}



Measured memory_bytes: 512
N=int(input())
W = list(map(int,input().split()))
rui = [0 for i in range(N+1)]
for i in range(N):
    rui[i+1] = W[i] + rui[i]
sm = rui[N]
mv = float("inf")
for i in range(N):
    # print(sm-2*rui[i+1])
    mv = min(abs(sm-2*rui[i+1]),mv)
print(mv)

Measured memory_bytes: 3064
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    int n;
    scan(n);
    auto a = readln.split.to!(int[]);

    auto cnt = new int[](10^^5 + 10);
    int over;

    foreach (ai ; a) {
        if (ai > 10^^5) {
            over++;
        }
        else {
            cnt[ai]++;
        }
    }

    debug {
        writeln(cnt[0 .. 20]);
    }

    int ans = over;

    foreach (i ; 0 .. 10^^5 + 1) {
        int d = cnt[i];

        if (cnt[i] >= i && d > cnt[i] - i) {
            d = cnt[i] - i;
        }
        
        ans += d;
    }

    writeln(ans);
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

int main() {
	int N;
	cin >> N;
	map<string, ll> m;
	string s;
	ll result = 0;

	repeat(i, N) {
		cin >> s;
		int n = 0;
		sort(s.begin(), s.end());
		m[s] += 1;
	}

	for(auto& p : m) {
		ll count = p.second;
		result += count * (count-1) / 2;
  }

	cout << result << endl;
	return 0;
}


Measured memory_bytes: 11136
// Problem: Anti-Division
// Contest: Virtual Judge - AtCoder
// URL: https://vjudge.net/problem/AtCoder-abc131_c
// Memory Limit: 1048 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//
//#include <immintrin.h>
//#include <emmintrin.h>

#include <bits/stdc++.h>
//#pragma GCC optimize("O2")
#define vi vector<int>
#define pii pair<int, int >
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define LL long long
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define all(x) (x).begin(), (x).end()
#define all2(x,n) (x+1), (x+1+n)
#define sz(x) ((int)(x).size())
#define mod(x) ((x)%MOD)
#define debug(x) cerr<<#x<<" : "<<x<<endl
#define mt make_tuple
#define eb emplace_back
#define o(X) (1<<(X))
#define oL(X) (1LL<<(X))
#define contain(S,X) (((S)&o(X))!=0)
#define containL(S,X) (((S)&oL(X))!=0)
#define ppt(x) __builtin_popcount(x)
using namespace std;
const int INF=0x3f3f3f3f,N=5e6+5,MOD=1e9+7;
const LL INF_LL=0x3f3f3f3f3f3f3f3fLL;
inline int getplc(int x,int y) { return (x>>y)&1; }
template<typename T>
T square(T x) {return x*x;}
LL qpow(LL a,LL b=MOD-2,LL _MOD=MOD){
	LL res=1;
	for(;b;b>>=1,a=a*a%_MOD){
		if(b&1)res=res*a%_MOD;
	}
	return res;
}
// Smax
//int Smax() { return -INF; }
template <typename T>
T Smax(T x) { return x; }
template<typename T, typename... Args>
T Smax(T a, Args... args) { return max(a, Smax(args...)); }
// Smin
template <typename T>
T Smin(T x) { return x; }
template<typename T, typename... Args>
T Smin(T a, Args... args) { return min(a, Smin(args...)); }
template <typename T>
// erro
#define errorl(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); errl(_it, args); }

void errl(istream_iterator<string> it) {}
template<typename T, typename... Args>
void errl(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	errl(++it, args...);
}

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr<<endl;}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << "=" << a << " # ";
	err(++it, args...);
}
void Solve();
int main() {
#ifndef ONLINE_JUDGE
//	freopen("in.txt","r",stdin);
//    freopen("o1.txt","w",stdout);
#endif
	ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
	Solve();
	return 0;
}

//////////////////////////////////////////////////////////////////

LL cal(LL x,LL c,LL d){
  return x-(x/c+x/d-x/((LL)(c*d/__gcd(c,d))));
}

void Solve(){
  LL a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<cal(b,c,d)-cal(a-1,c,d)<<endl;
} 


Measured memory_bytes: 3656
n, T = map(int, input().split())
c = []
min_c = 1001
for _ in range(n):
    c, t = map(int, input().split())
    if t <= T and min_c > c:
        min_c = c

if min_c == 1001:
    print('TLE')
else:
    print(min_c)


Measured memory_bytes: 38384
#include<stdio.h>

int count;

void merge(int A[], int left, int mid, int right, int n){

int n1, n2, L[250001], R[250001], i, j, k;
n1 = mid - left;
n2 = right - mid;
for(i = 0; i < n1; i++){
L[i] = A[left + i];
}
for(i = 0; i < n2; i++){
R[i] = A[mid + i];
}
L[n1] = 2000000000;
R[n2] = 2000000000;
i = 0;
j = 0;
for(k = left; k < right; k++){
count++;
if(L[i] <= R[j]){
A[k] = L[i];
i++;
}
else{
A[k] = R[j];
j++;
}

}

}



void mergeSort(int A[], int left, int right, int n){

int mid;
if(left + 1 < right){
mid = (left + right) / 2;
mergeSort(A, left, mid, n);
mergeSort(A, mid, right, n);
merge(A, left, mid, right, n);
}

}



int main(void){

int A[500000], n, i;
count = 0;

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

mergeSort(A, 0, n, n);

for(i = 0; i < n; i++){
if(i != 0) printf(" ");
printf("%d", A[i]);
}

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

return 0;
}

Measured memory_bytes: 5640
import sys
def input():
    return sys.stdin.readline()[:-1]

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

l.sort()
pre = l[0]
for i in range(1,N):
    d = l[i]
    if pre==d:
        print('NO')
        exit()
    pre = d
print('YES')

Measured memory_bytes: 26808
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int S = 0;
    
    string N;
	
    cin>>N;
    
    for(int i = 0; i < N.size(); i++){
        S += N[i] - '0';
        S %= 9;
    }
    
    if(S%9 == 0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
	
	return 0;
}

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

int main()
{
    int K, X;
    cin >> K >> X;
    int start = X - K + 1;
    int end = X + K - 1;
    for(int i = start; i <= end; i++)
        cout << i << " ";
    cout << "\n";  
}

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

int main(void) {
  int A, B;
  cin >> A >> B;
  for (int i = 0; i <= 1250; i++) {
    if (floor(i * 0.08) == A && floor(i * 0.1) == B) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int dp[3010][3010];
signed main() {
    int N; cin >> N;
    string s; cin >> s;

    for(int i=0; i<N; i++) dp[1][i] = i+1;
    for(int i=1; i<N; i++) {
        for(int j=0; j<N-i; j++) {
            // 前より小さいのが j 個、大きいのが N-i-j 個
            if(s[i-1] == '<') {
                (dp[i+1][j] += dp[i][j]) %= MOD;
            }
            if(s[i-1] == '>') {
                (dp[i+1][j] += dp[i][N-i] - dp[i][j] + MOD) %= MOD;
            }
            if(j > 0) (dp[i+1][j] += dp[i+1][j-1]) %= MOD;
        }
    }
    cout << dp[N][0] << endl;
    return 0;
}


Measured memory_bytes: 70016
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		Reader.init(System.in);
		StringBuilder output=new StringBuilder("");
		PrintWriter out=new PrintWriter(System.out);
		String s=Reader.next();
		String t=Reader.next();
		int[][] dp=new int[s.length()+1][t.length()+1];
		//Stack<Character> stk=new Stack<Character>();
		for(int i=1;i<=s.length();i++) {
			for(int j=1;j<=t.length();j++) {
				char a=s.charAt(i-1);char b=t.charAt(j-1);
				int l1=0,l2=0,l3=0;
				if(a==b) l1= 1+dp[i-1][j-1];
				l2=dp[i-1][j];
				l3=dp[i][j-1];
				dp[i][j]=Math.max(l1, Math.max(l2, l3));
				
			}
		}
		int i=s.length(),j=t.length();
		while(i>0 && j>0) {
			if(s.charAt(i-1)==t.charAt(j-1)) {
				output.append(s.charAt(i-1));i--;j--;
			}
			else if(dp[i][j]==dp[i-1][j-1]) {
				i--;j--;
			}
			else if(dp[i][j]==dp[i-1][j]) {
				i--;
			}
			else if(dp[i][j]==dp[i][j-1]) j--;
			
		}
		output.reverse();
		out.write(output.toString());
		out.flush();
	}

}

class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
 
    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
 
    /** get next word */
    static String nextLine() throws IOException{
    	return reader.readLine();
    }
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }
    
    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}


Measured memory_bytes: 82440
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <string.h>
using namespace std;
int main(){
    int n;
    int ans;
    int tmp = 0;
    cin>>n;
    int x[n];
    for (int i = 0; i < n; i++){
        cin>>x[i];
    }
    for (int j = 0; j < n; j++){
        tmp = tmp + pow((int)(x[j] - 1), 2);
    }
    ans = tmp;
    for (int i = 2; i <= 100; i++){
        tmp = 0;
        for (int j = 0; j < n; j++){
            tmp = tmp + pow((int)(x[j] - i), 2);
        }
        if (ans > tmp){
            ans = tmp;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<map>
#include<numeric>
#include<regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9

// 2^k <= N を満たす最大のk
ll div_2(ll N) {
	ll ans = 0;
	while (N >= 2) {
		N /= 2;
		ans++;
	}
	return ans;
}

int main() {
	ll X, Y; cin >> X >> Y;

	ll Z = Y / X;

	cout << div_2(Z) + 1 << endl;

	return 0;
}

Measured memory_bytes: 256
import itertools
n = 2
inputs = [[int(i) for i in input().split()] for i in range(n)]

combinations = list(itertools.combinations(inputs[1], 2))
energy = [combinations[i][0] * combinations[i][1] for i in range (len(combinations))]
energy_sum = sum(energy)
print(energy_sum)

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
constexpr lnt INF = 2e18;
struct FIO{FIO(){std::cin.tie(0);std::ios_base::sync_with_stdio(0);}}IO;
/*-*/



constexpr lnt MOD = 998244353;
struct mint
{
    lnt v;
    mint():v(0){}
    mint(lnt v):v((v+MOD)%MOD){}
    mint operator-()const{ return mint(0) - *this; }
    mint& operator+=(const mint& a){ if((v+=a.v)>=MOD) v-=MOD; return *this; }
    mint& operator-=(const mint& a){ if((v+=MOD-a.v)>=MOD) v-=MOD; return *this; }
    mint& operator*=(const mint& a){ (v*=a.v)%=MOD; return *this; }
    mint& operator/=(const mint& a){ (*this) *= a.inv(); 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 operator/(const mint& a)const{ return mint(*this) /= a; }
    bool operator<(const mint& a)const{ return v < a.v; }
    bool operator==(const mint& a)const{ return v == a.v; }
    mint pow(lnt k)const{ mint r(1),t(v); while(k){ if(k&1) r*=t; t*=t; k>>=1; } return r; }
    mint inv()const{ return pow(MOD-2); }
    static mint comb(lnt n, lnt k) {
        if(n-k<k) k=n-k;
        mint num(1), dom(1);
        for(int i=0;i<k;i++) { num*=n-i; dom*=i+1; }
        return num/dom;
    }
    static std::vector<mint> construct_comb(int n) {
        std::vector<mint> c(n+1);
        mint a = 1; c[0] = a;
        for(int i=1;i<=n;i++) {
            a = a*mint(n+1-i)/i;
            c[i] = a;
        }
        return c;
    }
    static std::vector<mint> construct_fact(int n) {
        std::vector<mint> f(n+1,1);
        for(int i=2;i<=n;i++) f[i]=f[i-1]*i;
        return f;
    }
};
std::istream& operator>>(std::istream&i,mint&a){ lnt t; i>>t; a=mint(t); return i; }
std::ostream& operator<<(std::ostream&o,const mint&a){ o<<a.v; return o; }


int main() {
	lnt n,s;
	std::cin >> n >> s;
	std::vector<lnt> a(n);
	rep(i,n) std::cin >> a[i];
	std::vector<mint> dp(s+1,0);
	dp[0]=1;
	mint half = mint(2).inv();
	rep(i,n) {
		for(int j=s;j>=0;j--) {
			if(j-a[i]<0) break;
			dp[j]+=dp[j-a[i]]*half;
		}
	}
	print(dp[s]*mint(2).pow(n));
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define vd vector<ld>
#define vvd vector<vector<ld>>
#define ALL(a) begin(a), end(a)
#define RALL(a) rbegin(a), rend(a)
#define SORT(a) stable_sort(ALL(a))
#define RSORT(a) stable_sort(RALL(a))
#define REV(a) reverse(ALL(a))
#define UNIQUE(a) a.erase(unique(ALL(a)), end(a))
#define lambda(i) [](auto& i)
#define compare(i, j) [](auto& i, auto& j)
#define min_of(a) *min_element(ALL(a))
#define max_of(a) *max_element(ALL(a))
#define sum(a) accumulate(ALL(a), 0)
#define pb push_back
#define mp make_pair
#define SZ(a) ll((a).size())
#define REP(i, n) for (decltype(+n) i = 0; i < (n); i++)
#define RREP(i, n) for (auto i = n - 1; i != static_cast<decltype(i)>(-1); i--)
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define RFOR(i, a, b) for (auto i = b - 1; i != a; i--)
#define EACH(i, a) for (auto&& i: (a))
using namespace std;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

struct union_find {
  vector<ll> data;
  union_find(ll size) : data(size, -1) { }
  bool union_set(ll x, ll y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool find_set(ll x, ll y) {
    return root(x) == root(y);
  }
  ll root(ll x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  ll size(ll x) {
    return -data[root(x)];
  }
};

vi cum(vi V) {
  vi U(SZ(V));
  partial_sum(ALL(V), begin(U));
  return U;
}

void solve() {
  ll n, m;
  ll ans = 1;

  cin >> n >> m;
  auto uf = union_find(n);
  REP(i, m) {
    ll x, y, z;
    cin >> x >> y >> z;
    uf.union_set(x - 1, y - 1);
  }
  REP(i, n - 1) {
    if (!uf.find_set(i, i + 1)) {
      uf.union_set(i, i + 1);
      ans++;
    }
  }

  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(15);
  solve();
}


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

//#define debug
typedef long long ll;

int main(){
#ifdef debug
    freopen("test.in", "r", stdin);
#endif
    string a, b, c;
    while(cin>>a>>b>>c){
        bool flag=false;
        if(a.back()==b[0]&&b.back()==c[0])
            flag=true;
        if(flag)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
def solve():
  n,a = (int(i) for i in input().split())
  x = list(int(i) for i in input().split())
  tp = max(x)
  if tp < a:
    print(0)
    exit()
  
  dp = [[[0 for i in range(n*tp +1)] for j in range(n+1)] for k in range(n+1)]
  query = a*n
  dp[0][0][0] = 1
  for i in range(1,n+1):
    for j in range(n+1):
      for k in range(n*tp +1):
        #選ばない
        dp[i][j][k] = dp[i-1][j][k]
        if x[i-1] <= k and j > 0:
         dp[i][j][k] += dp[i-1][j-1][k-x[i-1]]
        
  ans = 0
  for j in range(1,n+1):
    ans += dp[n][j][j*a]
  #print(dp)
  print(ans)
  
  
  
  
  
  
solve()

Measured memory_bytes: 95452
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
	int n;
	cin >> n;
	vector<double> a(n),b(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i < n; ++i) {
		cin >> b[i];
	}
	double temp,md,ed,td,cd;
	md = ed = td = cd = 0;
	for (int i = 0; i < n; ++i) {
		temp = abs(a[i]-b[i]);
		md += temp;
		ed += temp*temp;
		td += temp*temp*temp;
		cd = max(temp,cd);
	}
	ed = sqrt(ed);
	td = cbrt(td);
	cout << setprecision(20) << fixed << md << endl;
	cout << setprecision(20) << fixed << ed << endl;
	cout << setprecision(20) << fixed << td << endl;
	cout << setprecision(20) << fixed << cd << endl;
	return 0;
}



Measured memory_bytes: 3484
# https://atcoder.jp/contests/abc158/tasks/abc158_b

read A ; A=($A) ; n=$((A[0])) ; a=$((A[1])) ; b=$((A[2]))
echo "$n $a $b" >&2

ans=$(( (n / (a+b)) * a ))
resi=$(( n%(a+b) ))
if [ $((resi)) -le $((a)) ] ; then
  ans=$((ans + resi))
else
  ans=$((ans + a))
fi
echo $ans


Measured memory_bytes: 628
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt(); //1行目の入力
		for(int i = 1; x != 0; i++){
			System.out.println("Case "+i+": "+x);
			x = sc.nextInt();
		}
	}
}


Measured memory_bytes: 41884
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,g,i,m=0,j=10000;
	cin>>n>>g;
	int c[n+6],t[n+6];
	for (i=1;i<=n;i++)
	{
		cin>>c[i]>>t[i];
		if (t[i]<=g&&c[i]<j)
		{
			j=c[i];
			m=i;
		}
	}
	if (m==0)
	{
		cout<<"TLE";
		return 0;
	}
	cout<<j;
}

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

N, M = map(int, input().split())
s = input()
label = [0] * (N+1)
for i in range(N):
    if s[i] == 'B':
        label[i+1] = 1
adj = [[] for _ in range(N+1)]
ab_num = [[0, 0] for _ in range(N+1)]
for _ in range(M):
    a, b = map(int, input().split())
    adj[a].append(b)
    adj[b].append(a)
    ab_num[a][label[b]] += 1
    ab_num[b][label[a]] += 1

stack = []
remain = [1] * (N+1)
for i in range(1, N+1):
    if ab_num[i][0] == 0 or ab_num[i][1] == 0:
        stack.append(i)
        remain[i] = 0

cnt = N - len(stack)
while stack:
    if cnt == 0:
        print('No')
        exit()
    v = stack.pop()
    for u in adj[v]:
        if remain[u]:
            if ab_num[u][label[v]] == 1:
                remain[u] = 0
                stack.append(u)
                cnt -= 1
            else:
                ab_num[u][label[v]] -= 1

print('Yes')


Measured memory_bytes: 92236
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    string s;cin>>s;
    cout << *s.begin() << s.size()-2 << *(s.end()-1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<math.h>
using namespace std;



int main()
{

	int  N, M ,i, t = 0;
	int a[10000];

	cin >> N >> M;

	for (auto i = 0; i < M; i++) {
		cin >> a[i];
		t = t + a[i];
	}

	if (t <= N) {
		cout << N - t;

	}
	else {
		cout << "-1";
	}



}



Measured memory_bytes: 3668