akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

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


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

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

 if( C == "a"){
  cout << "vowel" << endl;
 } 
 else if( C == "i"){
  cout << "vowel" << endl;
 } 
 else if( C == "u"){
  cout << "vowel" << endl;
 } 
 else if( C == "e"){
  cout << "vowel" << endl;
 } 
 else if( C == "o"){
  cout << "vowel" << endl;
 } 

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

Measured memory_bytes: 256
n = int(input())    # total card number
cards = []
for i in range(n):
    cards.append(input().split())

S_list = [s for s in range(1, 14)]
H_list = [h for h in range(1, 14)]
C_list = [c for c in range(1, 14)]
D_list = [d for d in range(1, 14)]

for card in cards:
    if card[0] == 'S':
        S_list.remove(int(card[1]))
    elif card[0] == 'H':
        H_list.remove(int(card[1]))
    elif card[0] == 'C':
        C_list.remove(int(card[1]))
    elif card[0] == 'D':
        D_list.remove(int(card[1]))

for ss in S_list:
    print('S {}'.format(ss))
for hh in H_list:
    print('H {}'.format(hh))
for cc in C_list:
    print('C {}'.format(cc))
for dd in D_list:
    print('D {}'.format(dd))



Measured memory_bytes: 5612
N,W = map(int,input().split())
w = [0]*(N+1)
v = [0]*(N+1)
for i in range(1,N+1): w[i],v[i] = map(int,input().split())

dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(1,N+1):
    for j in range(1,W+1):
        if j < w[i]: dp[i][j] = dp[i-1][j]
        else: dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i]]+v[i])
print(dp[N][W])

Measured memory_bytes: 120428
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#include <cstdlib>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

using namespace std;
using ll = long long;
typedef pair<int, int> P;

int main(){
    string a, b; cin >> a >> b;
    int a_i, b_i;
    a_i = stoi(a);
    b_i = stoi(b);

    string s_a, s_b;
    rep(i, b_i) s_a += a;
    rep(i, a_i) s_b += b;
    
    if(s_a<s_b) out(s_a);
    else out(s_b);
}

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

int main() {
    int n; cin >> n;
    vector<int> a = {64, 32, 16, 8, 4, 2, 1};
    for(int ai : a){
        if(ai <= n){
            cout << ai << endl;
            break;
        }
    }
}


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

#define MOD 1000000007
#define MOD_DEFAULT MOD
ll _mpow(ll b, ll x, ll m)
{
    if (x == 0)
        return 1;
    if (x & 1)
        return _mpow(b * b % m, x / 2, m) * b % m;
    return _mpow(b * b % m, x / 2, m);
}
inline ll mpow(ll b, ll x, ll m = MOD_DEFAULT) { return _mpow(b % m, x, m); }

int main()
{
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;

    vector<ll> fact(r2 + 1 + c2 + 1 + 1);
    vector<ll> finv(fact.size());
    vector<ll> inv(fact.size());

    fact[0] = fact[1] = 1;
    finv[0] = finv[1] = 1;
    inv[0] = 0;
    inv[1] = 1;
    for (int i = 2; i < fact.size(); i++)
    {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

    auto f = [&](int r, int c) {
        return fact[r + c] * finv[r] % MOD * finv[c] % MOD;
    };
    auto g = [&](int r, int c) {
        return f(r + 1, c + 1) - 1;
    };

    ll ans = g(r2, c2) + MOD - g(r2, c1 - 1) + MOD - g(r1 - 1, c2) + g(r1 - 1, c1 - 1);
    ans %= MOD;

    cout << ans << endl;
}

Measured memory_bytes: 47104
#include<iostream>
using namespace std;
main()
{
	int n,A,x[50],i=0;
	long dp[51][5001]={};
	for(cin>>n>>A;i<n;x[i++]-=A)cin>>x[i];
	dp[0][n*A]=1;
	for(i=0;i<n;i++)for(int j=0;j<=2*n*A;j++)
	{
		dp[i+1][j]=dp[i][j];
		if(j-x[i]>=0&&j-x[i]<=2*n*A)dp[i+1][j]+=dp[i][j-x[i]];
	}
	cout<<dp[n][n*A]-1<<endl;
}


Measured memory_bytes: 2176
macro_rules! get_tuple {
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };

    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get_tuple!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (x1, x2, x3, x4, x5) = get_tuple!(usize, usize, usize, usize, usize);

    if x1 == 0 {
        println!("1");
    }

    if x2 == 0 {
        println!("2");
    }

    if x3 == 0 {
        println!("3");
    }

    if x4 == 0 {
        println!("4");
    }

    if x5 == 0 {
        println!("5");
    }

}


Measured memory_bytes: 2064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;++i)
#define REP(i,n) for (int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define read(x) scanf("%d",&x)
typedef bitset<1000005> bs;
int n,k;
string s[2005];
char S[1000005];
int Len=0;
bool can[2005][10005];
int len[2005],idx[2005];
bs segtree[64];
bs state;
inline int getBest(){
	int u=1;
	while(u<32){
		if ((state&segtree[u*2]).none()) u=u*2+1;
		else u*=2;
	}
	return (char)(u-32+'a');
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>k;
	for (int i=1;i<=n;++i) cin>>s[i];
	for (int i=1;i<=n;++i) len[i]=s[i].size();
	can[n][k]=1;
	for (int i=n;i>=1;--i){
		for (int j=k;j>=len[i];--j) if (can[i][j]) can[i-1][j]=can[i-1][j-len[i]]=1;
	}
	for (int i=1;i<=n;++i){
		for (int j=0;j<len[i];++j){
			S[Len+j]=s[i][j];
		}
		idx[i]=Len;//beginning pos
		Len+=len[i];
	}
	for (int i=0;i<64;++i) segtree[i].reset();
	for (int i=0;i<Len;++i) segtree[S[i]-'a'+32].set(i);
	for (int i=31;i>0;--i) segtree[i]=segtree[i<<1]|segtree[i<<1|1];
	state.reset();
	state.set(0);
	for (int i=0;i<k;++i){// alrady got i chars
		for (int j=1;j<n;++j) if (state[idx[j]]) state.set(idx[j+1]);
		for (int j=1;j<=n;++j) if (i+len[j]>k||!can[j][i+len[j]]) state.reset(idx[j]);
		char nxt=getBest();
		cout<<nxt;
		state&=segtree[nxt-'a'+32];
		state<<=1;// move on
	}
	cout<<endl;
	return 0; 
}

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

int main(){
  int N;  //餅の枚数
  cin >> N;
  
  vector <int> d(N,0); //餅iの直径
  for (int i=0; i<N; i++){
    cin >> d.at(i);
  }

  sort(d.begin(), d.end());
  reverse(d.begin(),d.end());

  int maisu = 1;
  for (int i=1; i<d.size(); i++){
    if ( d.at(i-1) > d.at(i) ){
      maisu +=1;
    }
  }

  cout << maisu << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	char c,c1,c2,c3,c4,c5,c6,c7,c8;
	scanf("%c %c %c %c %c %c %c %c %c",&c,&c1,&c2,&c3,&c4,&c5,&c6,&c7,&c8);
	printf("%c%c%c\n",c,c4,c8);
	return 0;
}

Measured memory_bytes: 1724
#include <iostream>

using namespace std;

int main(){
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;

    if (x + r <= W && x - r >= 0 && y + r <= H && y - r >= 0)
        cout << "Yes\n";
    else cout << "No\n"; 

    return 0;
}


Measured memory_bytes: 3096
#include<stdio.h>
int main()
{
      int n,k;
      scanf("%d%d",&n,&k);
      int a[n],i;
      for(i=0;i<n;i++)
            scanf("%d",&a[i]);
      int j,temp;
      for(i=0;i<n;i++)
      {
            for(j=i+1;j<n;j++)
            {
                  if(a[j]<a[i])
                  {
                        temp=a[j];
                        a[j]=a[i];
                        a[i]=temp;
                  }
            }
      }
      int sum=0;
      for(i=0;i<k;i++)
      {
            sum+=a[i];
      }
      printf("%d",sum);

      return 0;
}


Measured memory_bytes: 1712
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  int N; // 品物
  int M; // 割引券数
  long long temp;
  cin >> N >> M;

  priority_queue<int> A;
  for (int i = 0; i < N; i++) { cin >> temp; A.push(temp); }
  for (int i = 0; i < M; i++) {
    temp = A.top();
    A.pop();
    A.push(temp / 2);
  }
  temp = 0;
  for (int i = 0; i < N; i++) {
    temp += A.top(); A.pop();
  }
  cout << temp << endl;
}

Measured memory_bytes: 892
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    sc.close();

    int ans = 0;
    if (N == 1 && M == 1) {
      System.out.println(ans);
      return;
    }

    if (1 < N) ans += combination(N, 2);
    if (1 < M) ans += combination(M, 2);

    System.out.println(ans);
  }

  private static int combination(int n, int k) {
    int closer = Math.min(n - k, k);
    int result = 1;
    for (int i = 1; i <= closer; i++)
      result = result * (n - closer + i) / i;
    return result;
  }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>

#define llong long long
#define rep(i,l,n) for(int (i)=(l);(i)<(n);(i++))
#define _min(a,b) ((a)<(b)?(a):(b))

using namespace std;

int main(){
	int L,R,d;
	cin >> L >> R >> d;
	int count = 0;
	rep(i,L,R+1){
		if(i%d==0) count++;
	}
	cout << count;
	
	return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(){
  int k;
  int a[5];
  for(int i=0;i<5;i++){
    cin >> a[i];
  }
  cin >> k;
  
  if(a[4]-a[0]<=k){
    cout << "Yay!" <<endl;
  }else{
    cout << ":(" <<endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;
//const ll mod=998244353;
bool isPrime[1000001];
void init(int mx) {
  isPrime[0] = isPrime[1] = false;
  for(int i=2;i<1000001;i++) isPrime[i]=true;
  for (int i = 2; i <= mx; i++) {
    if (isPrime[i]) {
      for (int j = 2; i * j <= mx; j++) isPrime[i * j] = false;
    }
  }
}
int main(void){
    ll n;
    cin>>n;
    init(100000);
    vector<ll> v;
    for(int i=2;i<=55555;i++) if(i%5==1&&isPrime[i]) v.push_back(i);
    for(int i=0;i<n;i++){
        cout<<v[i];
        if(i!=n-1) cout<<" ";
        else cout<<endl;
    }
}

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

struct Point{double x,y;};

void koch(int n,Point a,Point b){
	if(n==0) return;
	
	Point s,t,u;
	double th=M_PI*60.0/180.0;
	
	s.x=(2.0*a.x+1.0*b.x)/3.0;
	s.y=(2.0*a.y+1.0*b.y)/3.0;
	t.x=(1.0*a.x+2.0*b.x)/3.0;
	t.y=(1.0*a.y+2.0*b.y)/3.0;
	u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
	u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;
	
	n--;
	
	koch(n,a,s);
	printf("%.8f %.8f\n",s.x,s.y);
	koch(n,s,u);
	printf("%.8f %.8f\n",u.x,u.y);
	koch(n,u,t);
	printf("%.8f %.8f\n",t.x,t.y);
	koch(n,t,b);
}

int main(){
	Point a,b;
	int n;
	
	scanf("%d",&n);
	
	a.x=0;
	a.y=0;
	b.x=100;
	b.y=0;
	
	printf("%.8f %.8f\n",a.x,a.y);
	koch(n,a,b);
	printf("%.8f %.8f\n",b.x,b.y);
	
	return 0;
}



Measured memory_bytes: 2672
#include <cmath>
#include <iostream>

using namespace std;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

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

  int ans = log(n) / log(k) + 1;

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 512
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        x: usize,
        y: usize,
        z: usize
    }
    println!("{} {} {}", z, x, y);
}


Measured memory_bytes: 4352
# import numpy as np
# import scipy as sp
# import sys
# input = sys.stdin.readline
# print(a,b,c,sep="") # 半角スペースなしで出力(abc)
# n=int(input())  #数値入力 「N」だけの入力のとき
# a,b=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
# a=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
# a=[int(input()) for _ in range (n)]  #リスト入力  改行でa1 ... anのとき
# s=[list(map(str,list(input()))) for i in range(h)]  # 文字列の二次元配列入力
# s = [list(map(int, input().split())) for i in range(n)] # 数値の二次元配列入力
# a = b[:], a = [x[:] for x in b] # deepcopy
# chr(ord('a') + 1) # chrのインクリメント
# s.sort(key=lambda x: x[1], reverse=False) # 2番目の要素で昇順にソート（Trueなら降順）
#　

n, r = map(int, input().split())
if n >= 10:
    print(r)
else:
    print(r+100*(10-n))


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >>D;
if(A+B>C+D){
cout << "Left";
}else if(A+B==C+D){
  cout << "Balanced";
}else{
  cout << "Right";
}

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

using namespace std;
using ll = long long;
typedef pair<int, int> P;

int main(){
    ll x; cin >> x;
    ll a = 100;
    for(ll i=1;;i++){
        a *= 1.01;
        if(a>=x) {out(i); return 0;}
    }

}

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

int main()
{
int n;
  cin>>n;
  int arr[n];
  vector<int>ans(n+1);
  map<int,int>m;
  for(int i=1;i<=n-1;i++)
  {
     cin>>arr[i];
   
  }
  for(int i=1;i<=n-1;i++)
  {
    ans[arr[i]]++;
  }
    for(int i=1;i<=n;i++)
  {
    cout<<ans[i]<<endl;
     
    
  }
 
}


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

using namespace std;

#define INF 1000000000
#define pb(a) push_back(a)
#define vi vector<int>
#define vvi vector<vi>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())
#define ll long long
#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x;
#define bit(n) (1<<(n))

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;i++)
#define FORVEC(i, v) for(int i = 0;i < sz(v);i++)


int main(){
	int a,b;
	string s;
	bool f=true;
	cin>>a>>b>>s;
	REP(i,a){
		if('0'>s[i]||s[i]>'9'){
			f=false;break;
		}
	}
	if(s[a]!='-')f=false;
	REP(i,b){
		if('0'>s[i+a+1]||s[i+a+1]>'9'){
			f=false;break;
		}
	}
	cout<<(f?"Yes":"No")<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define MAX 1e6
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

int main() 
{
	double n;
	cin>>n;
	// ll val1 = n/3;
	// ll val2 = n/3;
	// ll val3 = n/3;
	// if(n % 3 == 1) val2 += 1;
	// else if(n % 3 == 2){
	// 	if(val1*(val2+2)*val3 > val1*(val2+1)*(val3+1)){
	// 		val2 += 2;
	// 	} 
	// 	else {
	// 		val2++; val3++;
	// 	}
	// } ;
	cout<<fixed<<setprecision(12)<<(double)((n*n*n)/27)<<endl;
	return 0;
}  


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

int main() {
    int N; cin >> N;
    map<string, int> ma;
    int n = 0;
    rep(i, N) {
        string s; cin >> s;
        ma[s]++;
        n = max(n, ma[s]);
    }
    for(auto &u : ma) {
        if(u.second == n) cout << u.first << '\n';
    }
    cout << '\n';
    return 0;
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 998244353
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
int dp[1000009][2]; // 0: def, 1:rev
int num[1000009];
signed main(){
	string st;
	cin>>st;
	int n = st.size();
	for(int i=0;i<n;i++){
		num[i] = st[n-i-1] - '0';
	}
	if( n == 1 ){
		cout<<min( num[0], 11-num[0] )<<endl;
		return 0;
	}
	dp[0][0] = num[0];
	dp[0][1] = 10-num[0];
	for(int i=1;i<n;i++){
		// rev
		dp[i][1] = min( (9-num[i])+1+dp[i-1][0], (9-num[i])+dp[i-1][1] );
		// jun
		dp[i][0] = min( 1 + dp[i][1], min(num[i]+1+dp[i-1][1], num[i]+dp[i-1][0] ) );
		//cout<<i<<" "<<dp[i][0]<<" "<<dp[i][1]<<endl;
	}
	cout<<dp[n-1][0]<<endl;
	return 0;
}

Measured memory_bytes: 24836
n = int(input())
lst = list(map(int, input().split()))
for i in range(n - 1):
  a, b = min(lst[i], lst[i + 1]), max(lst[i], lst[i + 1]) # a < b
  while a != 0:
    a, b = b % a, a
  lst[i + 1] = b
print(lst[n - 1])

Measured memory_bytes: 20108
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;

class Program
{
    const long mod = 1000000007;

    static void Main(string[] args)
    {
        // 入力
        long[] nm = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var n = nm[0];
        var m = nm[1];

        long ans = 1;
        if (Math.Abs(n - m) > 1)
        {
            ans = 0;
        }
        else if (Math.Abs(n - m) == 1)
        {
            for (int i = 0; i < n; i++)
            {
                ans *= (n - i);
                ans %= mod;
            }
            for (int i = 0; i < m; i++)
            {
                ans *= (m - i);
                ans %= mod;
            }
        }
        else
        {
            for (int i = 0; i < n; i++)
            {
                ans *= (n - i);
                ans %= mod;
            }
            for (int i = 0; i < m; i++)
            {
                ans *= (m - i);
                ans %= mod;
            }

            ans *= 2;
            ans %= mod;
        }

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 2 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
// fflush(stdout)
// cout << flush
vi G[N],Ginv[N], vis(N, -1), tp, dis(N, 0);
void dfs(int u){
    vis[u] = 1;
    for(int v : G[u])
        if(vis[v] == -1)
            dfs(v);
    tp.pb(u);
}
int main(){
    //freopen("in","r",stdin);
    //freopen("out","w",stdout);
    fin;
    int n, m;
    cin >> n >> m;
    w(m){
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        G[u].pb(v);
        Ginv[v].pb(u);
    }
    fore(i, 0, n){
        if(vis[i] == -1)
            dfs(i);
    }
    //reverse(all(tp));
    int mx = 0;
    for(int i : tp){
        //cout << i << endl;
        for(int u : Ginv[i]){
            dis[u] = max(dis[u], dis[i] + 1);
            mx = max(mx, dis[u]);
        }
    }
    cout << mx << "\n";
    return 0;
}   

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


int main(){
  string s; cin >> s;
  if(s=="SAT") cout << 1 << endl;
  else if(s=="SUN") cout << 7 << endl;
  else if(s=="MON") cout << 6 << endl;
  else if(s=="TUE") cout << 5 << endl;
  else if(s=="WED") cout << 4 << endl;
  else if(s=="THU") cout << 3 << endl;
  else cout << 2 << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n, MOD = map(int,input().split())
    if n == 1:
        print(1)
        return

    E = [[] for _ in range(n)]
    nv_to_idx = [{} for _ in range(n)]
    for _ in range(n - 1):
        u, v = map(int,input().split())
        u -= 1; v -= 1
        nv_to_idx[u][v] = len(E[u])
        nv_to_idx[v][u] = len(E[v])
        E[u].append(v)
        E[v].append(u)

    # topological sort
    topological_sort = []
    parent = [None] * n
    stack = [(0, -1)]
    while stack:
        v, p = stack.pop()
        parent[v] = p
        topological_sort.append(v)
        for nv in E[v]:
            if nv == p:
                continue
            stack.append((nv, v))
    topological_sort.reverse()

    # tree DP
    dp = [None] * n
    for v in topological_sort:
        res = 1
        for nv in E[v]:
            if nv == parent[v]:
                continue
            res = res * (dp[nv] + 1) % MOD
        dp[v] = res

    # rerooting
    def rerooting(v, p):
        # rerooting を先に済ませる
        if p != -1 and v != -1:
            idx = nv_to_idx[p][v]
            p_res = 1
            if idx > 0:
                p_res *= cum_left[p][idx - 1]
            if idx < len(E[p]) - 1:
                p_res *= cum_right[p][idx + 1]
            dp[p] = p_res % MOD

        # monoid に対する cumulative sum を計算
        if cum_left[v] is None:
            left = [(dp[nv] + 1) % MOD for nv in E[v]]
            right = [(dp[nv] + 1) % MOD for nv in E[v]]
            k = len(E[v])
            for i in range(k - 1):
                left[i + 1] *= left[i]
                left[i + 1] %= MOD
            for i in range(k - 1, 0, -1):
                right[i - 1] *= right[i]
                right[i - 1] %= MOD
            cum_left[v] = left
            cum_right[v] = right
        dp[v] = cum_left[v][-1]

    ans = [None] * n
    stack = [(~0, -1), (0, -1)]
    cum_left = [None] * n
    cum_right = [None] * n
    while stack:
        v, p = stack.pop()
        if v >= 0:
            rerooting(v, p)
            ans[v] = dp[v]
            for nv in E[v]:
                if nv == p:
                    continue
                stack.append((~nv, v))
                stack.append((nv, v))
        else:
            rerooting(p, ~v)

    print(*ans, sep = '\n')
resolve()

Measured memory_bytes: 132784
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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 namespace std;

//ここから

void solve(){
  ll n,a,b,c,d;
  cin>>n>>a>>b>>c>>d;
  b-=a;
  bool ok=false;
  for(ll i=0;i<=n-1;++i){
    ll l=n-1-i;
    if(i*c-l*d<=b&&b<=i*d-l*c)ok=true;
  }
  if(ok)cout<<"YES";
  else cout<<"NO";
}

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

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

const int N=500,mod=1000000007;
typedef long long ll;
int ksm(ll a,int b,int c=1){
	for(;b;b/=2,a=a*a%mod)
		if(b&1)c=c*a%mod;
	return c;
}
int f[N][N],n,K,g[N],h[N],L[N],R[N];
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>K;
	for(int i=0;i<=K;++i)
		for(int j=1;j<N;++j)f[i][j]=(f[i][j-1]+ksm(j,i))%mod;
	g[0]=1;
	for(int i=1;i<=n;++i)cin>>L[i];
	for(int i=1;i<=n;++i)cin>>R[i];
	for(int i=1;i<=n;++i){
		int l=L[i],r=R[i];
		for(int j=0;j<=K;++j)h[j]=(f[j][r]-f[j][l-1]+mod)%mod;
		for(int j=K;j>=0;--j){
			int res=0;
			for(int k=0;k<=j;++k)
				res=(res+(ll)g[k]*h[j-k])%mod;
			g[j]=res;
		}
	}
	cout<<g[K]<<'\n';
	return 0;
}


Measured memory_bytes: 1152
s = input().strip()

flg = True
for i in range(len(s)):
    if (i % 2 == 0):
        if (s[i] == 'L'):
            flg = False
    else:
        if (s[i] == 'R'):
            flg = False

if flg:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 38384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node{
  struct node *p;
  struct node *left;
  struct node *right;
  int key;
} ;

int flag = 0;
typedef struct node Node;
Node *root, *NIL;

void Insert(int);
void Inorder(Node *);
void Preorder(Node *);
void Find(Node *, int);

int main(){
  int n,i,m;
  char in[7],insert[7] = "insert",find[5] = "find",print[6] = "print";
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%s",in);
    (void)getchar();
    if(strcmp(in, insert) == 0) {
      scanf(" %d",&m);
      Insert(m);
    }
    else if(strcmp(find, in) == 0) {
      scanf("%d",&m);
      Find(root,m);
      if(flag == 1){
        printf("yes\n");
      }
      else{
        printf("no\n");
      }
      flag = 0;
    }
    else {
      Inorder(root);
      printf("\n");
      Preorder(root);
      printf("\n");
    }
  }
  return 0;
}
void Insert(int Ins) {
  Node *x = NIL;
  Node *y = root;
  Node *z;

  z = malloc(sizeof(Node));
  z -> key = Ins;
  z -> left = NIL;
  z -> right = NIL;
  while(y != NIL) {
    x = y;
    if(z -> key < y -> key){
      y = y -> left;
    }
    else{
      y = y -> right;
    }
  }

  z -> p = x;
  if(x == NIL){
    root = z;
  }
  else {
    if(z -> key < x -> key){
      x -> left = z;
    }
    else{
      x -> right = z;
    }
  }
}

void Inorder(Node *n) {
  if(n == NIL){
    return;
  }
  else {
    Inorder(n -> left);
    printf(" %d", n->key);
    Inorder(n -> right);
  }
}

void Preorder(Node *n) {
  if(n == NIL){
    return 0;
  }
  else {
    printf(" %d", n->key);
    Preorder(n -> left);
    Preorder(n -> right);
  }
}
void Find(Node *n, int k) {
    if(n == NIL){
      return;
    }
  else {
    if(n -> key == k) {
      flag = 1;
      return 0;
    }
  }
    if(n -> key > k) {
      Find(n -> left, k);
      return;
    }
    else {
      Find(n -> right, k);
      return 0;
    }
}



Measured memory_bytes: 20548
#include<iostream>
#include<vector>
#include<queue>
using namespace std;

typedef pair<int, int> P;
const int INF = 1e9;

int main()
{
	int N; cin >> N;
	vector<vector<int>>G(N);
	for (int i = 0, a, b; i < N - 1; i++) {
		cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int K; cin >> K;
	vector<int> num(N, -1);
	for (int i = 0, v, p; i < K; i++) {
		cin >> v >> p;
		num[v - 1] = p;
	}

	vector<int> dist(N, INF);
	priority_queue<P, vector<P>, greater<P>> Q;
	for (int i = 0; i < N; i++) if (num[i] >= 0) {
		dist[i] = num[i];
		Q.push({ dist[i],i });
	}
	while (!Q.empty()) {
		int v = Q.top().second; Q.pop();
		for (int u : G[v]) if (dist[u] > dist[v] + 1) {
			dist[u] = dist[v] + 1;
			Q.push({ dist[u],u });
		}
	}

	bool ok = true;
	for (int i = 0; i < N; i++) {
		if (num[i] >= 0 && dist[i] != num[i]) ok = false;
		for (int j : G[i]) if (dist[i] == dist[j]) ok = false;
	}
	cout << (ok ? "Yes" : "No") << endl;
	if (ok) for (int i = 0; i < N; i++) cout << dist[i] << endl;
	
	return 0;
}


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

const int maxn = 1e5 + 10;
int a[maxn];
unordered_map<int, int> s;

int main() {
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  #endif
  ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i) {
		int cur;
		cin >> cur;
		++s[cur];
	}
	if(s.size() == 1) {
		if(s.begin() -> first == 0) cout << "Yes";
		else cout << "No";
	} else if(s.size() == 2) {
		if(s.count(0) && s[0] == n / 3) cout << "Yes";
		else cout << "No";
	} else if(s.size() == 3) {
		int tot = 0;
		for(auto e : s) a[tot++] = e.first;
		if(s[a[0]] == s[a[1]] && s[a[0]] == s[a[2]] && (a[0] ^ a[1]) == a[2]
				&& (a[1] ^ a[2]) == a[0] && (a[0] ^ a[2]) == a[1])
			cout << "Yes";
		else cout << "No";
	} else cout << "No";
  return 0;
}


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

using namespace std;

int sgn(long long x) {
  return (x >= 0 ? 1 : -1);
}

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

  long long x, k, d;
  cin >> x >> k >> d;
  if (abs(x) / d > k) {
    cout << abs(x - sgn(x) * k * d);
  } else {
    k -= abs(x) / d;
    cout << (k % 2 ? abs(abs(x) % d * sgn(x) - sgn(x) * d) : abs(abs(x) % d * sgn(x)));
  }

  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c, x; cin >> a >> b >> c >> x;
  int rsl=0;
  for(int i =0; i<=a; i++){
    for(int j =0; j<=b; j++){
      for(int k=0; k<=c; k++){
        int tmp = i*500 + j*100 + k*50;
        if(tmp==x) rsl++;
      }
    }
  }
  cout << rsl << endl;
 }

Measured memory_bytes: 256
//CODING ME ACCHHA KARNEKA HAI TERKO TO BAS PRACTICE KARTE REH
#include <bits/stdc++.h>
#define pragma
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define aisort sort(a,a+n)
#define adsort sort(a,a+n,greater<ll>())
#define PI 2 * acos(0)

typedef pair<ll, ll> pii;
typedef pair<ll, pii> piii;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef set<ll> Set;

const ll maxs = 1e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;

//MODULO OPEARTIONS
    inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
    inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
    inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }

//POWER
    ll fastpow(ll x,ll y)
    {ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}

//MODULAR INVERSE
    ll inv(ll x){ return fastpow(x , mod - 2);}
    
//PRIME
    bool isPrime(ll n) { if (n <= 1)  return false; if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return true; } 




int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   string s,r;
   cin>>s>>r;
   string res=r.substr(0,r.size()-1);
   if(res==s)
  cout<<"Yes";
  else
  cout<<"No";
}




Measured memory_bytes: 3636
s=[int(input()) for _ in range(4)]
g=min(s[3]//500,s[0])
h=min(s[3]//100,s[1])
j=s[2]
c=0
for a in range(g+1):
	for b in range(h+1):
		x=s[3]-500*a
		x-=100*b
		if x>=0 and x//50<=s[2]:
			c+=1
print(c)

Measured memory_bytes: 38768
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)                  cerr<<#x<<": "<<x<<endl
#define trace2(x, y)              cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)              cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)          cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)     cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}



int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin >> n;
	ll a[n+1]={0},b[n+1]={0},c[n+1]={0};
	rep(i,1,n+1) cin >> a[i];
	rep(i,1,n+1) cin >> b[i];
	rep(i,1,n) cin >> c[i];
	ll ans=0;
	for(ll i=1; i<=n; i++){
		ans+=b[a[i]];
		if(a[i]-a[i-1]==1 && i>1) ans+=c[a[i-1]];
	}
	cout << ans;
    return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


Measured memory_bytes: 256
N = gets.chomp.to_i
T, A = gets.chomp.split(" ").map{|s| s.to_i }
H_ARR = gets.chomp.split(" ").map{|s| s.to_i }

index = nil
min_diff = nil

H_ARR.each_with_index do |h, i|
  temp = T - 0.006*h
  diff = (A-temp).abs
  if index.nil? || diff < min_diff
    index = i
    min_diff = diff
  end
end

puts index + 1

Measured memory_bytes: 1916
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
  double n;

  while(cin >> n , n >= 0){
    string ans = "",tmp = "";
    int integer = n;

    n -= integer;

    while(integer){
      tmp += (integer % 2) + '0';
      integer /= 2;
    }

    int len = (int)tmp.size();
    for(int i = len ; i < 8 ; i++){
      tmp += "0";
    } 

    reverse(tmp.begin(),tmp.end());
    ans += tmp + ".";

    tmp = "";

    for(int i = 0 ; i < 4 ; i++){
      double b = pow(2.0,-(i+1));

      if(n == b){  
	tmp += "1";
	n -= b;
	break;
      }

      if((int)(n / b) == 0){
	tmp += "0";
      }
      else{
	tmp += "1";
	n -= b;
      }
    }

    len = (int)tmp.size();
    for(int i = len ; i < 4 ; i++){
      tmp += "0";
    }  

    if(!n) cout << ans + tmp << endl;
    else cout << "NA" << endl;
  }

  return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,i,temp;
    cin>>n;
    vector<ll> arr;
    for(i=0;i<n;i++){
        cin>>temp;
        arr.push_back(temp);
    }
    reverse(arr.begin(),arr.end());
    ll max=1,len=1,maxindex=0;
    for(i=1;i<n;i++){
        if(arr[i]>=arr[i-1])
            len+=1;
        else{
            if(max<len){
                max=len;
                maxindex=i-max;
            }
            len=1;
        }
    }
    if(max<len){
        max=len;
        maxindex=n-max;
    }
    cout<<max-1<<endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

ll pow_mod(ll x,int k,int mod) {
  ll ans=1;
  while (k) {
  	if (k&1) ans=ans*x%mod;
  	x=x*x%mod;
  	k>>=1;
  }
  return ans;
}

int MOD;

ll C[3005][3005],strl[3005][3005];

void pre(int n) {
  for(int i=0;i<=n;i++) C[i][0]=1;
  for(int i=1;i<=n;i++)
    for(int j=1;j<=i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;
  strl[0][0]=1;
  for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++) strl[i][j]=(strl[i-1][j-1]+strl[i-1][j]*j)%MOD;
}

int main() {
  int n;
  scanf("%d%d",&n,&MOD);
  pre(n+1);
  ll ans=0;
  for(int i=0;i<=n;i++) {
  	ll s=0,v=1,t=pow_mod(2,n-i,MOD);
  	for(int j=0;j<=i;j++) {
  		s=(s+v*strl[i+1][j+1])%MOD;
  		v=v*t%MOD;
	  }
	ans=(ans+C[n][i]*pow_mod(2,pow_mod(2,n-i,MOD-1),MOD)%MOD*((i&1)?MOD-1:1)%MOD*s)%MOD;
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 141312
import sys
input = sys.stdin.readline
h, w = map(lambda x: int(x)+2, input().split())
MAZE = ['#'*w]
for _ in range(h-2):
    MAZE.append('#'+input()+'#')
else:
    MAZE.append('#'*w)

L = [[0]*w for _ in range(h)]
R = [[0]*w for _ in range(h)]
U = [[0]*w for _ in range(h)]
D = [[0]*w for _ in range(h)]

LAMP = [[0]*w for _ in range(h)]

for i in range(1, h-1):
    for j in range(1, w-1):
        if MAZE[i][j] == '.':
            L[i][j+1] = L[i][j]+1
            U[i+1][j] = U[i][j]+1
        if MAZE[i][w-j] == '.':
            R[i][w-j-1] = R[i][w-j]+1
        if MAZE[h-i][j] == '.':
            D[h-i-1][j] = D[h-i][j]+1

ans = 0
for i in range(1, h-1):
    for j in range(1, w-1):
        if MAZE[i][j] == '#':
            continue
        LAMP[i][j] = L[i][j]+R[i][j]+U[i][j]+D[i][j]+1
        ans = max(ans, LAMP[i][j])

print(ans)


Measured memory_bytes: 210056
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [a, b] <- getIntList
    print $ solve a b

solve a b | a < 10 && b < 10 = a * b
          | otherwise = -1

Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
// define #Asukaminato ha kawaii
#define ll long long
#define rep(i, m) for (int i = 0; i < (int)(m); i++)
const int inf = 1000000000; // 10^9 Ten to the power of nine.


int main() {
    int A,B;
    cin>>A>>B;
	  int res = 0;
	  int now = 1;
	  while (now < B)
  {
		now += A- 1;
		res++;
	}
	  
    cout << res << endl;
	  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repc(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ll long long
#define vec vector
#define pb push_back
#define ft first
#define sd second
#define all(vec) vec.begin(), vec.end()

typedef pair<int, int> P;

const int MOD = 1e9 + 7;
const int INF = 1001001001;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};

//------------------------------------------------------//

int main(){
  string n;
  cin >> n;
  int sum = 0;
  rep(i, n.size()){
    sum += n[i] - '0';
    sum %= 9;
  }
  if(sum % 9 == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;




int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, K;
  cin >> N >> K;
  string S;
  cin >> S;

  //幸福度変化するのは両サイドのみ -> 増加するように取れば最適
  vector<ll> vorder(0);
  REP(i,N-1){
      if (S[i] != S[i+1]){
          vorder.push_back(i);
      }
  }


  ll ans = 0;
  REP(i,N){
      if (i>0 && S[i]=='L' && S[i-1]=='L'){
          ans++;
      } else if (i<N-1 && S[i]=='R' && S[i+1]=='R'){
          ans++;
      }
  }
  if ((vorder.size()+1)/2 <= K){
      ans += vorder.size();
  } else {
      ans += K*2;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 1480
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ll x,a,b;
	cin >> x >> a >> b;
	if(x < b-a){
		cout << "dangerous" << endl;
	}else if(b <= a){
		cout << "delicious" << endl;
	}else if(b-a <= x && b-a>0){
		cout << "safe" << endl;
	}
	return 0;
}

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

int main() {
  int N;
  int cnt = 1;
  cin >> N;
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    if (S == "P") {
      cnt *= 2;
    }
    else if (S == "W") {
      cnt *= 3;
    }
    else if (S == "G") {
      cnt *= 5;
    }
    else {
      cnt *= 7;
    }
    cnt %= 2 * 3 * 5 * 7;
  }
  if (cnt) {
    cout << "Three" << endl;
  }
  else {
    cout << "Four" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define s second
#define f first
int dx[]={1,0,1,-1};
int dy[]={0,1,1,1};
int main(){
  int n;
  while(cin>>n,n){
    string s[n];
    for(int i=0;i<n;i++)cin>>s[i];
    pair<pair<int,int>,pair<int,int> > a[n][n];
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
    a[i][j].f.f=a[i][j].f.s=a[i][j].s.f=a[i][j].s.s=s[i][j]-'0';    
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
    for(int k=0;k<4;k++){
      int x=j+dx[k],y=i+dy[k];
      if(x>=0&&y>=0&&y<n&&x<n){
        if(k==0&&a[y][x].f.f)a[y][x].f.f+=a[i][j].f.f;
        if(k==1&&a[y][x].f.s)a[y][x].f.s+=a[i][j].f.s;
        if(k==2&&a[y][x].s.f)a[y][x].s.f+=a[i][j].s.f;
        if(k==3&&a[y][x].s.s)a[y][x].s.s+=a[i][j].s.s;
      }
    }
    int res=0;
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++){
    res=max(res,a[i][j].f.f);
    res=max(res,a[i][j].f.s);
    res=max(res,a[i][j].s.f);
    res=max(res,a[i][j].s.s);
      }
    cout<<res<<endl;
  }
}

Measured memory_bytes: 4060
#include <stdio.h>

int main(void){
  char input[101] = {0};
  scanf("%s",input);
  printf("%c",input[0]);
  for (int i=1;i<101;i++){
    if (input[i] == 0){
      printf("%d",i-2);
      printf("%c\n",input[i-1]);
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
  #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl "\n"
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(){
  int n;
  cin>>n;
  if(n<1200)cout<<"ABC"<<endl;
  else if(n>=1200 and n<2800)cout<<"ARC"<<endl;
  else cout<<"AGC"<<endl; 
}
int32_t main(){
   IOS;
   solve();
   //debug();
  #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
  #endif	
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{	
	static boolean move(String s, int a, int b)
	{
		return !s.substring(a, b + 1).contains("##");
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner e = new Scanner(System.in);
		
		int n = e.nextInt();
		int s1 = e.nextInt() - 1;
		int s2 = e.nextInt() - 1;
		int t1 = e.nextInt() - 1;
		int t2 = e.nextInt() - 1;
		String s = e.next();
		
		if(t1 == t2)
		{
			System.out.println("No");
			return;
		}
		
		if(!move(s, s1, t1) || !move(s, s2, t2) )
		{
			System.out.println("No");
			return;
		}
		
		if(t1 > t2)
		{
			if(!s.substring(s2 - 1, t2 + 2).contains("..."))
			{
				System.out.println("No");
				return;
			}
		}
		
		System.out.println("Yes");
	}
}

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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define F first
#define S second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

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

const int N = 100500;

bool n, s, e, w;

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//srand(time(NULL));

	//cin.tie(NULL);
	//cout.tie(NULL);
	//ios_base::sync_with_stdio(false);

	//cout << setprecision(10) << fixed;
	
	string st;
	cin >> st;

	for (int i = 0; i < sz(st); i++) {
		n |= st[i] == 'N';
		s |= st[i] == 'S';
		e |= st[i] == 'E';
		w |= st[i] == 'W';
	}

	cout << ((n ^ s) || (e ^ w) ? "No" : "Yes");
	
	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}


Measured memory_bytes: 384