akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
	int cnt=0,cnt1=0,c=0;
	string s;
	cin>>s;
	if (s.size()&1) cout<<"No"<<endl;
	else {
		for(int i=0;i<s.length()-1;i+=2){
			if(s[i]!='h' || s[i+1]!='i') {
				cout<<"No"<<endl;
				return 0;
			}
		}
		cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int stnum;
		double weight, height, BMI;
		String data, datap[];
		while( scan.hasNext()) {
			data = scan.next();
			datap = data.split(",",3);
			stnum = Integer.valueOf(datap[0]);
			weight = Double.valueOf(datap[1]);
			height = Double.valueOf(datap[2]);
			BMI = (weight)/(height*height);
			if(BMI>=25.0) System.out.println(stnum);
		}
	}

}

Measured memory_bytes: 12000
n,m=map(int,input().split())
if abs(n-m)>=2:
    print(0)
    exit()
elif n==m:
    ans=2
    for i in range(1,n+1):
        ans*=i**2
        ans%=(10**9 +7)
    
    #ans=2*(math.factorial(n)**2)
    print(ans)
elif abs(n-m)==1:
    ans=1
    t=max(n,m)
    for i in range(2,t+1):
        ans*=i*(i-1)
        ans%=(10**9 +7)
    print(ans)

Measured memory_bytes: 9152
#include <iostream>
using namespace std;
int main()
{
	//int x1, x2, x3, x4, x5 = 0;
	//int a = 0;
	//cin >> x1 >> x2 >> x3 >> x4 >> x5;
	//if (x1 == 0)a = x2 - 1;
	//if (x2 == 0)a = x1 + 1;
	//if (x3 == 0)a = x2 + 1;
	//if (x4 == 0)a = x3 + 1;
	//if (x5 == 0)a = x4 + 1;
	//cout << a;
	int x, y = 0;
	int ans = 0;
	cin >> x >> y;
	for (int i = 0; i <= x; i++)
	{
		if (y == 2 * i + 4 * (x - i))
		{
			ans = 1;
		}
	}
	if (ans == 1)
		cout << "Yes";
	else
		cout << "No";

    return 0;
}



Measured memory_bytes: 3644
// Sky's the limit :)
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int N = 2e5 + 5;

vector<int> dp(N), p0(N), p1(N);

int solve(int n) {
    int cnt = 0;
    while (n) {
        int x = __builtin_popcount(n);
        n %= x;
        cnt++;
        if (dp[n])
            return (dp[n] + cnt);
    }
    return cnt;
}

void pre() {
    for(int i = 0; i < N; i++) {
        dp[i] = solve(i);
        // if(i < 10)
        //     cout << i << ": " << dp[i] << '\n';
    }
}

int findMod(string s, int k, vector<int> pot) {
    int n = s.size();

    int res = 0;  
    int i = 0, j = n - 1;  
    while (i < n) {    
        if (s[j] == '1') 
            res = (res + pot[i]) % k;  
        i++;  
        j--;  
    }  
    return res;  
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    pre();

    int T = 1; 
    // cin >> T; 
    while (T--) {
        int n;
        string s;
        cin >> n >> s;

        int k = 0, v0, v1;
        for (auto c : s)
            k += (c == '1');
        
        p0[0] = 1 % (k + 1);
        for(int i = 1; i < N; i++)
            p0[i] = 2 * p0[i - 1] % (k + 1);
        v0 = findMod(s, k + 1, p0);

        if(k > 1) {
            p1[0] = 1 % (k - 1);
            for(int i = 1; i < N; i++)
                p1[i] = 2 * p1[i - 1] % (k - 1);
            v1 = findMod(s, k - 1, p1);
        }

        for (int i = 0; i < n; i++) {
            int ans = 0;
            if (s[i] == '0') {
                int val = v0;
                val = (val + p0[n - 1 - i]) % (k + 1);
                ans = 1 + dp[val];
            }
            else if (s[i] == '1' && k > 1) {
                int val = v1;
                val = (val - p1[n - 1 - i] % (k - 1) + (k - 1)) % (k - 1);
                // cout << i << ": " <<     val << ' ';
                ans = 1 + dp[val];
            }
            cout << ans << '\n';
        }
    }
    
    return 0;
}



Measured memory_bytes: 9940
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	vector<vector<int>>vec(3, vector<int>(3));
	rep(i, 3)rep(j, 3)cin >> vec[i][j];

	int N; cin >> N;
	rep(i, N) {
		int a; cin >> a;
		rep(j, 3) {
			rep(k, 3) {
				if (vec[j][k] == a)vec[j][k] = 0;
			}
		}
	}

	bool is = false;
	rep(i, 3) {
		int cnt = 0;
		rep(j, 3) {
			if (vec[i][j] == 0)++cnt;
		}
		if (cnt == 3)is = true;
	}
	rep(i, 3) {
		int cnt = 0;
		rep(j, 3) {
			if (vec[j][i] == 0)++cnt;
		}
		if (cnt == 3)is = true;
	}
	int cnt = 0;
	rep(i, 3) {
		if (vec[i][i] == 0)++cnt;
	}
	if (cnt == 3)is = true;

	cnt = 0;
	rep(i, 3) {
		if (vec[2-i][i] == 0)++cnt;
	}
	if (cnt == 3)is = true;

	cout << (is ? "Yes" : "No") << "\n";
	

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
long long power(long long m, long long n) {
    if(n == 1)
    return m;
    else if(n%2 == 0)
    return power(m*m%1000000007, n/2);
    else
    return power(m*m%1000000007, n/2)*m%1000000007;
}
  
int main(void){
    long long m, n; 
    scanf("%lld %lld\n", &m, &n);
    printf("%lld\n", power(m,n));
    return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef vector<int> vi;
const int INF = 1LL << 60; //10e18+10e17ちょっとくらい
const int MOD = 1000000007;
const int MAX_N = 200100;

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;

    return 0;
}

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = sc.nextInt();
		int ans = 1;
		int max = 0;
		for (int i = 2; i <= n; i++) {
			int tmp = i;
			int tmpCount = 0;
			while (tmp % 2 == 0) {
				tmp /= 2;
				tmpCount++;
			}
			if(max < tmpCount){
				max = tmpCount;
				ans = i;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
n=input().split("/")

a=int(n[0])
b=int(n[1])
c=int(n[2])

if a<2019:
    print("Heisei")
elif a==2019:
    if b<=4:
        if c<=30:
            print("Heisei")
        else:
            print("TBD")
    else:
        print("TBD")
else:
    print("TBD")

Measured memory_bytes: 3060
N = gets.to_i
I = 2**N - 1
alist=[]
xlist=[]
ylist=[]
for i in 0..N-1
  A = gets.to_i
  X,Y = A.times.map{gets.split.map(&:to_i)}.transpose
  alist.push(A)
  xlist.push(X)
  ylist.push(Y)
end
result = 0
Slist = [0,1].repeated_permutation(N).to_a
for S in Slist
  breakflag = false
  for n in 0..N-1
    if S[n] == 1
      for a in 0..alist[n]-1
        if S[xlist[n][a]-1] != ylist[n][a]
          breakflag = true
          break
        end
      end
    end
    break if breakflag
  end
  if breakflag == false
    if result < S.count(1)
      result = S.count(1)
    end
  end
end
p result


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

int main() {
  int N_500,N_100,N_50,X;
  cin >> N_500;// >> endl;
  cin >> N_100;// >> endl;
  cin >> N_50;//  >> endl;
  cin >> X;// >> endl;
  
  int y;
  int ans;
  for(int i=0; i<N_500+1; i++) {
    for(int j=0; j<N_100+1; j++) {
      for(int k=0; k<N_50+1; k++) {
        y = 500*i + 100*j + 50*k;
        if (y == X) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}

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

int main(){
  int X;
  cin >> X;
  
  if(X < 1200){
    cout << "ABC" << endl;
  }
  else if(X < 2800){
    cout << "ARC" << endl;
  }
  else{
    cout << "AGC" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
  int a,b;
  cin >> a >> b;
  
  double min_a = 12.5*a;
  double max_a = min_a + 12.5;
  int min_a_int = min_a + 0.5;
  int max_a_int = max_a - 0.5;
  
  int min_b_int = 10*b;
  int max_b_int = min_b_int + 9;
  
  int ans;
  
  if(max_a_int < min_b_int || max_b_int < min_a_int)
  {
    ans = -1;
  }
  else
  {
    ans = min_a_int < min_b_int ? min_b_int: min_a_int;
  }
  
  cout << ans << endl;
  
  return 0;
}

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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef tuple<int,int,int> ti;
typedef vector<ti> vti;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int T = 1e5 + 2;

vii xs;
vii ys;
priority_queue<ti,vti, greater<ti>>pq;
int n;
int pai[T];
int peso[T];

void init() {
    for(int i = 0; i <= n; i++) {
        pai[i] = i;
        peso[i] = 1;
    }
}

int find(int x) {
    return (x == pai[x]? x : pai[x] = find(pai[x]));
}

void join(int x, int y) {
    x = find(x);
    y = find(y);
    if(peso[x] < peso[y]) swap(x,y);
    pai[y] = x;
    peso[x] += peso[y];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n;
    init();

    for(int i = 0; i < n; i++) {
        int a,b; cin >> a >> b;
        xs.eb(a,i);
        ys.eb(b,i);
    }

    sort(xs.begin(), xs.end());
    sort(ys.begin(), ys.end());

    for(int i = 1; i < n; i++) {
        pq.emplace(xs[i].fi - xs[i-1].fi, xs[i-1].se, xs[i].se);
        pq.emplace(ys[i].fi - ys[i-1].fi, ys[i-1].se, ys[i].se);
    }

    ll ans = 0;

    while(!pq.empty()) {
        ti at = pq.top();
        pq.pop();
        ll d,a,b;
        tie(d,a,b) = at;
        if(find(a) != find(b)) {
            ans += d;
            join(a,b);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8040
#include<iostream>
#include<algorithm>
using namespace std;
long long n,a[111111],b[111111],c[111111],d[111111],ans=0;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)cin>>b[i];
	for(int i=0;i<n;i++)cin>>c[i];
	sort(a,a+n);
	sort(b,b+n);
	sort(c,c+n);
	for(int i=n-1;i>=0;i--)d[i]=d[i+1]+n-(upper_bound(c,c+n,b[i])-c);
	for(int i=0;i<n;i++)ans+=d[upper_bound(b,b+n,a[i])-b];
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


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

    ll ans = 0;
    rep1(i, n){
        if (i%3!=0 && i%5!=0){
            ans += i;
        }
    }

    cout << ans << endl;
}



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

int main() {
	int i, j, a, b;
	string c;
	stack<int> s;
	while (cin >> c) {
		if (c[0] == '+') {
			b = s.top();
			s.pop();
			a = s.top();
			s.pop();
			s.push(a + b);
		} else if (c[0] == '-') {
			b = s.top();
			s.pop();
			a = s.top();
			s.pop();
			s.push(a - b);
		} else if (c[0] == '*') {
			b = s.top();
			s.pop();
			a = s.top();
			s.pop();
			s.push(a * b);
		} else {
			s.push(atoi(c.c_str()));
		}
	}
	cout << s.top() << endl;
	return 0;
}

Measured memory_bytes: 3180
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<cstring>
#include<climits>
#include<algorithm>
#define ll long long int
using namespace std;
int main(){
	ll n,sum=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		if(i%3!=0 && i%5!=0){
			sum+=i;
		}
	}
	cout<<sum<<endl;
	}

Measured memory_bytes: 3624
#include <stdio.h>
#define MAX_N (100000)
#define rep(i, n) for(int i = 1; i <= n; i++)

int main(void) {
  int N;
  scanf("%d", &N);

  int ANS = 0;
  rep(i, N) {
    if(i <= 9)
      ANS++;
    else if(100 <= i && i <= 999)
      ANS++;
    else if(10000 <= i && i <= 99999)
      ANS++;
  }
  printf("%d\n", ANS);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;

long long f(int n, long long x){
    vector <long long> a(51); // 層の厚さ
    vector <long long> p(51); // パテの枚数
    a[0] = 1;
    p[0] = 1;
    for(int i = 0; i < 50; i++){
        a[i + 1] = 2 * a[i] + 3;
        p[i + 1] = 2 * p[i] + 1;
    }

    if (n == 0) {
        if (x <= 0) {
            return 0;
        }else{
            return 1;
        }
    }else{
        if (x == 1) {
            return 0;
        }else if(x <= 1 + a[n - 1]){
            return f(n-1, x-1);
        }else{
            return p[n - 1] + 1 + f(n-1, x-2-a[n-1]);
        }
        
    }
}

int main(){
    long long n, x;
    cin >> n >> x;

    cout << f(n, x) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
ll ans=1;ll n;ll a[100008];
ll mod=998244353;
int main()
{
	scanf("%lld",&n);for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++) ans=ans*__gcd(a[i],(ll)i-1)%mod;
	printf("%lld\n",ans);
	
	return 0;
}

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

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

    vector<int> p(N);
    rep(i,N) cin >> p[i];

    vector<int> ascending_p(N);
    ascending_p = p;
    sort(ascending_p.begin(), ascending_p.end());

    int cnt = 0;
    rep(i,N){
        if(p[i] != ascending_p[i]) cnt++;
    }
    if(cnt == 0 || cnt == 2) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


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

  vi h(n);
  rep(i, n) cin >> h[i];

  vector<vi> v(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }

  int ans = 0;
  rep(i, n){
    bool flag = true;
    rep(j, v[i].size()){
      if (h[v[i][j]] >= h[i]) flag = false;
    }
    if (flag) {
      ans++;
    }
  }

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

Measured memory_bytes: 8804
def main():
    H, W, M = map(int, input().split())
    bombs = [list(map(int, input().split())) for i in range(M)]
    
    if M == 1:
        return 1
    
    hw = [0] * H
    wh = [0] * W
    
    for i in range(len(bombs)):
        [h, w] = bombs[i]
        hw[h-1] += 1
        wh[w-1] += 1
    
    hw_tuple_list = []
    for i in range(len(hw)):
        hw_tuple_list.append((hw[i], i+1))
    
    wh_tuple_list = []
    for i in range(len(wh)):
        wh_tuple_list.append((wh[i], i+1))

    h_list = sorted(hw_tuple_list, reverse = True)
    w_list = sorted(wh_tuple_list, reverse = True)

    h_max = h_list[0][0]
    h_idx_list = []
    check_h = [0] * H
    for i in range(len(h_list)):
        if h_max > h_list[i][0]:
            break
        h_idx_list.append(h_list[i][1])
        check_h[h_list[i][1]-1] = 1

    w_max = w_list[0][0]
    w_idx_list = []
    check_w = [0] * W
    for i in range(len(w_list)):
        if w_max > w_list[i][0]:
            break
        w_idx_list.append(w_list[i][1])
        check_w[w_list[i][1]-1] = 1
    
    cnt = 0
    for [h, w] in bombs:
        if check_h[h-1] == 1 and check_w[w-1] == 1:
            cnt += 1
    return h_max + w_max if cnt != len(h_idx_list) * len(w_idx_list) else h_max + w_max - 1

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

Measured memory_bytes: 176460
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n]={};
  int b[100001]={};
  int i;
  for(i=0;i<n;i++){
    cin >> a[i];
    b[a[i]]++;
    if(a[i]>=1)b[a[i]-1]++;
    b[a[i]+1]++;
  }
  int max = 0;
  for(i=0;i<=100000;i++){
    if(b[i]>max)max = b[i];
  }
  cout << max;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <vector>
using std::vector;

int main()
{
    int k; scanf("%d", &k);
    vector<bool> checked(k);

    int surplus = 0;
    int ans=1;
    while(1){
        surplus = ((surplus * 10) + 7) % k;
//printf("[%d] surplus = %d\n",ans, surplus);
        if (checked[surplus]){puts("-1"); return 0;}
        if (!surplus) break;
        checked[surplus] = true;
        ans++;
    }

    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 3336
s = list(input())
ans = []
for i in range(len(s)):
    if s[i] == "1":
        ans.append("1")
    elif s[i] == "0":
        ans.append("0")
    elif len(ans) > 0:
        ans.pop(-1)
for i in range(len(ans)):
    if i != len(ans)-1:
        print(ans[i],end="")
    else:
        print(ans[i])

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

#define ll long long
#define pii pair<int,int>

using namespace std;

const ll N = 300010;
const ll inf = 2e9;

inline ll read()
{
  ll p=0; ll f=1; char ch=getchar();
  while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();}
  while(ch>='0' && ch<='9'){p=p*10+ch-'0'; ch=getchar();}
  return p*f;
}

struct node
{
  ll x,y;
  node(){}
  node(ll _x,ll _y){x=_x; y=_y;}
}q[N],a[N],b[N]; ll sta,stb;

ll w,h,n;

ll rt,lc[N<<2],rc[N<<2],c[N<<2],lazy[N<<2],tot = 0;
void link(ll &u,ll L,ll R,ll k,ll cc)
{
  if(!u) u=++tot,lazy[u] = 0;
  if(L==R){c[u] = cc ; return ;}
  ll mid = (L+R)>>1;
  if(k<=mid) link(lc[u],L,mid,k,cc);
  else link(rc[u],mid+1,R,k,cc);
  c[u] = max(c[lc[u]] , c[rc[u]]);
}

ll ans = 0;

void push_down(ll u)
{
  if(lazy[u])
  {
    c[lc[u]]+=lazy[u];
    c[rc[u]]+=lazy[u];
    lazy[lc[u]] += lazy[u]; lazy[rc[u]] += lazy[u];
    lazy[u] = 0;
  }
}

void chg(ll u,ll L,ll R,ll l,ll r,ll cc)
{
  if(l>r) return ;
  if(L==l && R==r)
  {
    c[u] += cc; lazy[u]+=cc;
    return ;
  }
  ll mid=(L+R)>>1;
  push_down(u);
  if(r<=mid) chg(lc[u],L,mid,l,r,cc);
  else if(l>mid) chg(rc[u],mid+1,R,l,r,cc);
  else
  {
    chg(lc[u],L,mid,l,mid,cc);
    chg(rc[u],mid+1,R,mid+1,r,cc);
  }
  c[u] = max(c[lc[u]] , c[rc[u]]);
}

bool cmpy(const node &x,const node &y){return x.y < y.y;}

void solve()
{
  sort(q+1,q+n+1,cmpy);
  rt=tot=0; memset(c,0,sizeof(c)); memset(lazy,0,sizeof(lazy));
  memset(lc,0,sizeof(lc)); memset(rc,0,sizeof(rc));
  for(ll i=1;i<=n;i++) link(rt,1,n,i,-inf);
  sta = stb = 0; ll mid = w/2;
  for(ll i=1;i<n;i++)
  {
    if(q[i].x<=mid)
    {
      ll nx = i-1;
      while(sta && a[sta].x <= q[i].x)
      {
        chg(rt,1,n,a[sta].y,nx,a[sta].x - q[i].x);
        nx = a[sta].y-1; sta--;
      }
      a[++sta] = node(q[i].x , nx+1);
    }
    else
    {
      ll nx = i-1;
      while(stb && b[stb].x >= q[i].x)
      {
        chg(rt,1,n,b[stb].y,nx,q[i].x - b[stb].x);
        nx = b[stb].y-1; stb--;
      }
      b[++stb] = node(q[i].x , nx+1);
    }
    a[++sta] = node(0,i);
    b[++stb] = node(w,i);
    chg(rt,1,n,i,i,inf - q[i].y + w);
    ans = max(ans , c[rt] + q[i+1].y);
  }
}

int main()
{

  w = read(); h = read(); n = read();
  for(ll i=1;i<=n;i++) q[i].x = read() ,  q[i].y = read();
  q[++n] = node(0,0); q[++n] = node(w,h);
 
  solve();
  swap(w,h); for(ll i=1;i<=n;i++) swap(q[i].x,q[i].y);
  solve();

  return printf("%lld\n",ans<<1),0;
}


Measured memory_bytes: 51840
#include <iostream>
using namespace std;
int main(void){
    // Your code here
    int a,b;
    cin>>a>>b;
    if(a<=5){
        cout<<0;
    }else if(a<=12){
        cout<<b/2;
    }else if(12<a){
        cout<<b;
    }
    return 0;
    
}


Measured memory_bytes: 256
a = gets.chomp.split('')

b = ['+', '-']
b = b.product(b).product(b).map(&:flatten)

b.each do |c|
  s = ''
  3.times{ |i| s += a[i] + c[i] }
  s += a[3]
  
  if eval(s) == 7 then
    puts (s + '=7')
    break
  end
end

Measured memory_bytes: 1788
#!/usr/bin/env python

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
INF = float("inf")

def main():
    L,R,d = map(int,input().split())

    ans = 0
    for i in range(L,R+1):
        if i%d == 0:
            ans += 1
    
    print(ans)

if __name__ == "__main__":
    main()

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

#define mod 1000000007
#define maxn 2005
#define ll long long

using namespace std;

ll silnia[maxn*maxn];
ll dp[maxn][maxn];


void licz(int zosia)
{
	silnia[0]=1;
	for(int i=1; i<=zosia; ++i)
	{
		ll a=i;
		silnia[i]=(silnia[i-1]*a)%mod;
	}
}

ll qpow(ll zosia, int n)
{
	ll wynik=1;
	while(n!=0)
	{
		if(n%2==1)
			wynik=(wynik*zosia)%mod;
		zosia=(zosia*zosia)%mod;
		n/=2;
	}
	return wynik;
}

ll dwumian(int slonko, int misiu)
{
	ll c=(silnia[slonko-misiu]*silnia[misiu])%mod;
	//cout << c << endl;
	//cout << slonko << endl;
	//cout << silnia[slonko] << endl;
	return (silnia[slonko]*qpow(c,mod-2))%mod;
}

int main()
{
	//cout << dwumian(2,0) << endl;
	ll n,k;
	scanf("%lld%lld", &n, &k);
	
	if(k==1)
	{
		puts("1");
		return 0;
	}
	licz(n+n*k);
	//cout << dwumian(2,0) << endl;
	
	dp[0][0]=1;
	for(int i=0; i<=n; ++i)
	{
		for(int j=max(i,1); j<=n; ++j)
		{
			if(i!=0)
			dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
			//cout << i+j*(k-1) << " " << k-2 << endl;
			//cout << dwumian(i+j*(k-1),k-2) << endl;
			if(j!=0)
				dp[i][j]=(dp[i][j]+(dwumian(i+j*(k-1)-1,k-2)*dp[i][j-1])%mod)%mod;
			//cout << i << " " << j << dp[i][j] << endl;
		}
	}
	printf("%lld", (dp[n][n]*silnia[n])%mod);
	return 0;
}



Measured memory_bytes: 62976
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
inline ll lin() { ll x; scanf("%lld",&x); return x;}
inline char chin() { char x; scanf("%c",&x); return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; scanf("%lf",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (dup(c,b) <= dup(a,d)) yn;
  return 0;
}

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

int main()
{
	int A, B;
	cin >> A >> B;

	int n1 = A + B;
	int n2 = A - B;
	int n3 = A * B;

	int out = max(n1, n2);
	out = max(out, n3);

	cout << out << endl;

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
int i, j, k = 0, l, m, n;
using namespace std;
char S[100055], T[100055];
using namespace std;
int main() {
	scanf("%s", S);
	n = strlen(S);
	for(i = 1; i < n; i++) {
		if(S[i] != S[i-1]) ++l;
	}
	printf("%d\n", l);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,K,S;
  cin>>N>>K>>S;
  vector<int>A(N);
  for(int i=0;i<K;i++)
    A.at(i)=S;
  for(int i=K;i<N;i++){
  if(S==1000000000){
  A.at(i)=3;
  }else{A.at(i)=1+S;}
  
  }for(int i=0;i<N;i++)
    cout<<A.at(i)<<endl;
   return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep0(i,n) for (int i = 0; i < (n); ++i)  //0index
#define rep1(i,n) for (int i = 1; i < (n); ++i)  //1index
#define REP(i,a,b) for (int i = a; i < (b); ++i)  //aからb - 1まで
#define mREP(i,a,b) for (int i = a; i > (b); --i)  //逆
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;  //最大値兼MOD
typedef long long ll;
using namespace std;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }  //GCD
int dp[100010][3];
int a[100010][3];
int main(){
    int n;
    cin >> n;
    long double temp;
    vector<long double>A(n);
    rep0(i,n){
        cin >> temp;
        A[i] = temp + ((long double)i / 100000);
    }
    sort(all(A));
    rep0(i,n){
        cout << ((A[i] - (int)A[i])) * 100000 + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 2432
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

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

	VI k(n);
	vector<VI> a(50, VI(50));
	rep(i, n) {
		cin >> k[i];
		rep(j, k[i])cin >> a[i][j];
	}

	int cnt = 0;
	rep(i, m) {
		bool flag = true;
		rep(j, n) {
			auto f = find(all(a[j]), i + 1);
			if (f == a[j].end())flag = false;
		}
		if (flag)cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
N, P = map(int,input().split())
S = str(input())
L = len(S)
ans = 0
dic = {0:1} #一番右端は0なのでこれは常に必要
now = 0
if P == 2 or P == 5:
  kotae = 0
  for i in range(L):
    if int(S[L-1-i])%P == 0:
      kotae += L-i
  print(kotae)
  exit(0)
else:
  for i in range(L):
    now += int(S[L-1-i])*pow(10,i,P)
    temp = now%P
    if temp not in dic:
      dic[temp] = 1
    else:
      dic[temp] += 1
#print(dic)
ans = 0  
for i in dic.values():
  if i != 1:
    ans += i*(i-1)//2
print(ans)

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

int main()
{
    char n,m;
    cin>>n>>m;
    string s,t;
    for(int i=0;i<n-'0';i++)s+=m;
    for(int i=0;i<m-'0';i++)t+=n;
    //cout<<s<<" "<<t;
      cout<<(t<=s?t:s);  
    
    

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>

#include <bitset>

#include <tuple>

#include <cstdint>

#include <cstdio>

#include <cctype>

#include <assert.h>

#include <stdlib.h>

#include <stdio.h>

#include <cassert>

#include <cfloat>

#include <climits>

#include <cmath>

#include <complex>

#include <ctime>

#include <deque>

#include <fstream>

#include <functional>

#include <iomanip>

#include <iostream>

#include <iterator>

#include <list>

#include <limits>

#include <map>

#include <memory>

#include <queue>

#include <random>

#include <set>

#include <stack>

#include <string>

#include <unordered_map>

#include <unordered_set>

#include <utility>

#include <vector>

#include <math.h>
using namespace std;
int main() {
    int N, i;
    cin >> N >> i;
    cout << N - i + 1 << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!


void solve(){

    string str;
    cin>>str;
    

    int n=str.l();
    int a=n,z=-1;
    for(int i=0;i<n;i++){
        if(str[i]=='A'){
            a=min(a,i);
        }
        if(str[i]=='Z'){
            z=max(z,i);
        }
    }
    cout<<z-a+1;
}





int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int(i)=int (a);i<=int (b);i++)
#define ff(i,a,b) for(int(i)=int (a);i<int (b);i++)
#define F(i,a,b) for(int(i)=int (a);i>=int (b);i--)
#define foreach(i,x) for(typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vt vector
#define ll long long
#define lower(p,x) lower_bound(all(p),x)
#define upper(p,x) upper_bound(all(p),x)
#define ms(a,x) memset(a,x,sizeof a)
#define minn(a,b,c,d) min(a,min(b,min(c,d))) 
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
const double pi=acos(-1.0);//NOTE:PI
const double eps=1e-5;
const int INF=1e9,mod=1e9+7,N=1e6+6;
int a[N];
int main(){
	string s;
	cin>>s;
	vt<int> v;
	ff(i,0,s.size()){
		if(s[i]=='0'){
			v.pb(0);
		}
		else if(s[i]=='B'&&v.size()!=0){
			v.pop_back();
		}
		else if(s[i]=='1'){
			v.pb(1);
		}
	}
	for(auto u:v) cout<<u;
	
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int r = sc.nextInt();
    int D = sc.nextInt();
    int x = sc.nextInt();
    for(int i = 0; i < 10; i++) {
      x = r * x - D;
      System.out.println(x);
    }
  }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define Endl endl
typedef long long ll;
const int MAXN = (int)1e1 + 5;
int n, d;
double a[MAXN][MAXN];
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	while (cin >> n >> d)
	{
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= d; ++j)
				cin >> a[i][j];
		int ans = 0;
		for (int i = 1; i < n; ++i)
			for (int j = i + 1; j <= n; ++j)
			{
				double sum = 0;
				for (int k = 1; k <= d; ++k)
					sum += abs(a[i][k] - a[j][k])*abs(a[i][k] - a[j][k]);
				if (sqrt(sum) == (int)sqrt(sum))
					ans++;
			}
		cout << ans << endl;
	}
}
/*
3 2
1 2
5 5
-2 8

3 4
-3 7 8 2
-12 1 10 2
-2 8 9 3

5 1
1
2
3
4
5
*/

Measured memory_bytes: 256
// Author : Mohamed Sameh
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
typedef long long ll ;
using namespace std ;
int n;
const int N = 4e2+9;
int a[N];
ll dp[N][N];
ll pre[N];
ll solve(int l = 0, int r = n-1)
{
  if (l >= r)return 0;
  if (l == r-1)return a[l] + a[r];
  ll &ret = dp[l][r];
  if (~ret)return ret;
  ret = 1e18;
  for (int i = l; i < r; i++)
  {
    ret = min(ret, solve(l, i) + solve(i+1, r) + a[l] + pre[r] - pre[l]);
  }
  return ret;
}
void test ()
{
  memset(dp, -1, sizeof dp);
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  pre[0] = a[0];
  for (int i = 1; i < n; i++)
    pre[i] = pre[i-1] + a[i];
  cout << solve() <<"\n";
}
int main()
{
  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  test();
}


Measured memory_bytes: 1664
N = int(input())
S = input()
left = 0
right = S.count("E")
ans = False
for i in range(N):
    if i > 0 and S[i - 1] == "W":
        left += 1
    if S[i] == "E":
        right -= 1
    if ans is not False:
        ans = min(ans, left + right)
    else:
        ans = left + right
print(ans)
    

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename Iter, typename T> int gt(Iter L, Iter R, T v) { return upper_bound(L, R, v) - L; }
template <typename Iter, typename T> int ge(Iter L, Iter R, T v) { return lower_bound(L, R, v) - L; }
template <typename Iter, typename T> int lt(Iter L, Iter R, T v) { return lower_bound(L, R, v) - L - 1; }
template <typename Iter, typename T> int le(Iter L, Iter R, T v) { return upper_bound(L, R, v) - L - 1; }
template <typename Bst, typename T> typename Bst::const_iterator gt(const Bst& bst, T v) { return bst.upper_bound(v); }
template <typename Bst, typename T> typename Bst::const_iterator ge(const Bst& bst, T v) { return bst.lower_bound(v); }
template <typename Bst, typename T> typename Bst::const_iterator lt(const Bst& bst, T v) { return bst.lower_bound(v) == bst.begin() ? bst.end() : --bst.lower_bound(v); }
template <typename Bst, typename T> typename Bst::const_iterator le(const Bst& bst, T v) { return bst.upper_bound(v) == bst.begin() ? bst.end() : --bst.upper_bound(v); }
// maintain an upper/lower hull L of lines y = mx + b
// query for y(x) such that y(x) is minimum/maximum over all lines y in L
// assumes lines are inserted in non-increasing/non-decreasing order of m
// minimization by default, call constructor with greater<ll>() for maximization
struct cht {
    struct line {
        ll m, b, intersection;
        ll eval(ll x) const { return m * x + b; }
        ll cross(const line& l) const { return (l.b - b) / (m - l.m); }
        bool operator<(const line& l) const { return m > l.m; }
        bool operator<(const ll x) const { return intersection < x; }
        friend bool operator<(const ll x, const line& l) { return x < l.intersection; }
    };
    multiset<line, less<>> h;
    const function<bool(ll, ll)> cmp;
    cht(const function<bool(ll, ll)>& cmp = less<ll>()) : cmp(cmp) {}
    const line& l1() { return *h.rbegin(); }
    const line& l2() { return *++h.rbegin(); }
    void pop() { h.erase(--h.end()); }
    void add(ll m, ll b) {
        if(h.empty()) {
            h.insert({m, b, numeric_limits<ll>::min()});
        } else if(m != l1().m or cmp(b, l1().b)) {
            if(m == l1().m) pop();
            while(h.size() >= 2 and l1().cross({m, b}) <= l1().cross(l2())) pop();
            h.insert({m, b, l1().cross({m, b})});
        }
    }
    ll opt(ll x) {
        assert(!h.empty());
        ll y1 = lt(h, x)->eval(x), y2 = le(h, x)->eval(x);
        return cmp(y1, y2) ? y1 : y2;
    }
};
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    ll c;
    cin >> n >> c;
    vector<ll> h(n);
    cin >> h;
    cht cht;
    auto opt = [&](int j) { return j ? h[j] * h[j] + cht.opt(h[j]) : 0; };
    for(int j = 0; j < n; j++) {
        cht.add(-2 * h[j], h[j] * h[j] + c + opt(j));
    }
    cout << opt(n - 1) << endl;
    return 0;
}

Measured memory_bytes: 14336
import 'dart:io';

main(List<String> args) {
  var N = int.parse(stdin.readLineSync());

  while (N > 0) {
    if (N % 10 == 7) {
      print("Yes");
      return;
    } else {
      N ~/= 10;
    }
  }
  print("No");
}


Measured memory_bytes: 13132
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define F first
#define S second
#define en "\n"
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
const int loose = 0;
const int tight = 1;



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;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

ll digit_DP(string s,ll k) {
	ll n = s.size();
	vector<Matrix> dp(k+1, Matrix(n + 1, Array(2, 0)));
	dp[0][0][tight] = 1;
	REP(i, n) {
		ll d = s[i] - '0';
		ll ni = i + 1;
		REP(t, 2) {
			REP(kk, k+1) {
				rep(j, 0, 10) {
					if (t == tight && d < j) break;
					ll nt = ((t == tight) && (j == d)) ? tight : loose;
					if (j == 0) {
						dp[kk][ni][nt] += dp[kk][i][t];
					}
					else {
						if (kk + 1 <= k) dp[kk+1][ni][nt] += dp[kk][i][t];
					}
				}
			}
		}
	}

	return  dp[k][n][loose] + dp[k][n][tight];
}


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

	string s;
	cin >> s;
	ll k;
	cin >> k;
	cout << digit_DP(s, k) << endl;

	return 0;
}


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

int main()
{
    char S[100];
    cin >> S;
    int ans = 0;
    int len = strlen(S);
    for (int i = 0; i < len / 2; i++)
    {
        if (S[i] != S[len - i - 1])
        {
            ans++;
        }
    }
    cout << ans;
    return 0;
}

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

int main() {
    int N; cin >> N;
    vector<int> P(N), Q(N), R(N);
    for (int i = 0; i < N; ++i) cin >> P[i];
    for (int i = 0; i < N; ++i) {
        cin >> Q[i];
        R[i] = i + 1;
    }

    int p, q;
    int id = 1;
    do {
        bool fp = true, fq = true;
        for (int i = 0; i < N; ++i) {
            if (!fp && !fq) break;
            if (R[i] != P[i]) fp = false;
            if (R[i] != Q[i]) fq = false;
        }

        if (fp) p = id;
        if (fq) q = id;
        ++id;
    } while (next_permutation(R.begin(), R.end()));

    if (p < q) swap(p, q);
    cout << p - q << endl;

    return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc = initScanner(os.Stdin)
	n := scanInt(sc)
	fmt.Println(resolve(n))
}

func resolve(n int) int {
	var ln int
	l0, l1 := 2, 1

	if n == 1 {
		return l1
	}

	for i:=2; i<=n; i++ {
		ln = l0 + l1
		l0, l1 = l1, ln
	}
	return ln
}

// --------------- BASE DEFINITIONS ---------------

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	return sc
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanIntSlice(sc *bufio.Scanner, n int) []int {
	is := make([]int, n)
	for i := 0; i < n; i++ {
		is[i] = scanInt(sc)
	}

	return is
}

func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanStringSlice(sc *bufio.Scanner, n int) []string {
	ss := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		ss[i] = sc.Text()
	}

	return ss
}


Measured memory_bytes: 1780
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  map<int, int> mp;
  vector<int> v(n);
  for(int i = 0; i < n; ++i) cin >> v[i];
  for(int i = 0; i < n; ++i) mp[i + v[i]]++;
  long long ans = 0;
  for(int i = 0; i < n; ++i) ans += mp[i - v[i]];
  cout << ans << endl;
}

Measured memory_bytes: 20992
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <cmath>
#include <numeric>
#include <sstream>
#include <iomanip>
using ll = long long;
using namespace std;
#define INF 999999999

int main()
{
    int N, M, C;
    cin >> N >> M >> C;
    vector<int> B(M);
    for (int i = 0; i < M; i++)
        cin >> B[i];
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        int x = 0;
        int a;
        for (int j = 0; j < M; j++)
        {
            cin >> a;
            x += a * B[j];
        }
        if (x + C > 0)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, H, ans=0, temp=0, count=0;
  cin >> N >> H;
  for(int i=1; i<N; i++){
    temp=H;
    cin >> H;
    if(temp>=H){
      count++;
      ans=max(ans, count);
   }
   else count=0;
  }
  cout << ans << endl;
} 

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N;
    string S;
    cin >> N >> S;

    int cnt[N + 1];
    // i文字目までにWがいくつあるか(1-indexed)

    // 累積和テーブルを埋めていく
    cnt[0] = 0;
    for (int i = 0; i < N; ++i) {
        cnt[i + 1] = cnt[i];
        if (S[i] == 'W') ++cnt[i + 1];
    }

    int ans = N;
    for (int i = 1; i <= N; ++i) {
        // 自分より西にいて西を向いている人が
        //  cnt[i-1]人
        // 自分より東にいて東を向いている人が
        //  (N-i)-(cnt[N]-cnt[i])人
        ans = min(ans, cnt[i - 1] + (N - i) - (cnt[N] - cnt[i]));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1796
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  long long n, k; cin >> n >> k;
  vector<long long> a(n), b(n), c(n);
  REP(i, n) {
    if (i % 2 == 0) {
      a[i] = k + i / 2;
      b[i] = k + n + n / 2 + i / 2;
    } else {
      a[i] = k + (n + 1) / 2 + i / 2;
      b[i] = k + n + i / 2;
    }
    c[i] = k + n + n + i;
  }
  REP(i, n) {
    if (a[i] + b[i] > c[i]) {
      cout << -1 << '\n';
      return 0;
    }
  }
  REP(i, n) cout << a[i] << ' ' << b[i] << ' ' << c[i] << '\n';
  return 0;
}


Measured memory_bytes: 4608
H, W = map(int, input().split())

S = []
for _ in range(H):
	S.append([0 if x == '.' else x for x in list(input())])

dx = [-1, -1, 0, 1, 1, 1, 0, -1]
dy = [0, 1, 1, 1, 0, -1, -1, -1]

for i in range(H):
	for j in range(W):
		if S[i][j] == '#':
			for k in range(8):
				x = i + dx[k]
				y = j + dy[k]
				if x >= 0 and y >= 0 and x < H and y < W:
					if S[x][y] != '#':
						S[x][y] += 1

for i in range(H):
	for j in range(W):
		print(S[i][j],end='')
	print()

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

// using namespace std;

using map_t = std::vector<std::vector<bool>>;

void fill(const map_t& map, int w, int h, int x, int y, map_t& visited) {
  if (x < 0 || w <= x || y < 0 || h <= y) {
    return;
  }
  if (!map[y][x] || visited[y][x]) {
    return;
  }
  visited[y][x] = true;
  fill(map, w, h, x - 1, y - 1, visited);
  fill(map, w, h, x + 0, y - 1, visited);
  fill(map, w, h, x + 1, y - 1, visited);
  fill(map, w, h, x - 1, y + 0, visited);
  fill(map, w, h, x + 1, y + 0, visited);
  fill(map, w, h, x - 1, y + 1, visited);
  fill(map, w, h, x + 0, y + 1, visited);
  fill(map, w, h, x + 1, y + 1, visited);
}

int solve(const map_t& map, int w, int h) {
  map_t visited(h, std::vector<bool>(w, false));
  int ret = 0;
  for (int y = 0; y < h; ++y) {
    for (int x = 0; x < w; x++) {
      if (map[y][x] && !visited[y][x]) {
        ret++;
        fill(map, w, h, x, y, visited);
      }
    }
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  while (true) {
    int w, h;
    std::cin >> w >> h;
    if (w == 0 || h == 0) {
      break;
    }
    map_t map(h, std::vector<bool>(w));
    for (int y = 0; y < h; ++y) {
      for (int x = 0; x < w; x++) {
        int a;
        std::cin >> a;
        map[y][x] = a != 0;
      }
    }
    std::cout << solve(map, w, h) << std::endl;
  }
  return 0;
}



Measured memory_bytes: 3364
from collections import Counter
 
N = int(input())
S = [input() for _ in range(N)]

# 方針：各文字列の出現回数を数え、出現回数が最大なる文字列を昇順に出力する
# Counter(リスト) は辞書型のサブクラスであり、キーに要素・値に出現回数という形式
# Counter(リスト).most_common() は(要素, 出現回数)というタプルを出現回数順に並べたリスト
S = Counter(S).most_common()

max_count = S[0][1] # 最大の出現回数

# 出現回数が最も多い単語を集計する
l = [s[0] for s in S if s[1] == max_count]

# 昇順にソートして出力
for i in sorted(l):
  print(i)

Measured memory_bytes: 49628
import sys


def main():
    a_and_b = sys.stdin.readline().strip().split(' ')
    a = a_and_b[0]
    b = a_and_b[1]
    ai = int(a_and_b[0])
    bi = int(a_and_b[1])

    if a == b:
        print(a * bi)
        return

    if a > b:
        print(b * ai)
    else:
        print(a * bi)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<pair<int,int>>>;
#define INF 1000000000000000000
#define MOD 1000000007

int main(){
  string S;
  cin>>S;

  if(S.size()<4){
    cout<<"No"<<endl;
  }else{
    if(S.at(0)=='Y'&&S.at(1)=='A'&&S.at(2)=='K'&&S.at(3)=='I'){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }
}


Measured memory_bytes: 256
from collections import Counter

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

a = list(Counter(A).items())
b = []

for i in range(len(a)):
    if a[i][1] >= 4:
        b.append(a[i][0])
        b.append(a[i][0])
    elif a[i][1] >= 2:
        b.append(a[i][0])

if len(b) < 2:
    print(0)
else:
    b.sort()
    print(b[-2] * b[-1])

Measured memory_bytes: 21412