akhauriyash/Code-Regression huggingface dataset:
import java.util.*


data class Point(var d: Int, var y: Int, var x: Int) : Comparable<Point> {

    override operator fun compareTo(other: Point) : Int {
        return compareValues(d, other.d)
    }

}


fun main() {
    val reader = System.`in`.bufferedReader()
    val INF = 1000000
    var (H, W) = reader.readLine()!!.split(" ").map(String::toInt)
    var (CH, CW) = reader.readLine()!!.split(" ").map{it.toInt()-1}
    var (DH, DW) = reader.readLine()!!.split(" ").map{it.toInt()-1}
    var S = Array(H) {IntArray(W) {-1}}
    (0 .. H-1).forEach{ i ->
        var s = reader.readLine()!!
        (0 .. W-1).forEach{ j ->
            if (s[j] == '.') {
                S[i][j] = INF
            }
        }
    }

    // スタートノードから各ノードへの距離。ただし未訪問(初期状態)なら-1
    S[CH][CW] = 0
    
    // スタートノードをキューに入れる
    var q = PriorityQueue<Point>()
    q.offer(Point(0, CH, CW))
    // 幅優先探索で、未訪問のマスをスタートマスから近い順に巡る
    var DIR1 = arrayOf(Pair(0, 1), Pair(1, 0), Pair(0, -1), Pair(-1, 0))
    var DIR2 = arrayOf(
        Pair(-2, -2), Pair(-2, -1), Pair(-2, 0), Pair(-2, 1), Pair(-2, 2),
        Pair(-1, -2), Pair(-1, -1), Pair(-1, 1), Pair(-1, 2),
        Pair(0, -2), Pair(0, 2),
        Pair(1, -2), Pair(1, -1), Pair(1, 1), Pair(1, 2),
        Pair(2, -2), Pair(2, -1), Pair(2, 0), Pair(2, 1), Pair(2, 2)
        )
    while (!q.isEmpty()) {
        var (d, y, x) = q.poll()
        DIR1.forEach { (dy, dx) -> 
            var ny = y + dy
            var nx = x + dx
            if (0 <= ny && ny < H && 0 <= nx && nx < W && S[ny][nx] > d) {
                S[ny][nx] = d
                q.offer(Point(d, ny, nx))
            }
        }
        DIR2.forEach { (dy, dx) -> 
            var ny = y + dy
            var nx = x + dx
            if (0 <= ny && ny < H && 0 <= nx && nx < W && S[ny][nx] > d+1) {
                S[ny][nx] = d + 1
                q.offer(Point(d+1, ny, nx))
            }
        }
    }
    println(if (S[DH][DW] == INF) -1 else S[DH][DW])
}


Measured memory_bytes: 65540
''' Hey stalker :) '''
INF = 10**10
def main():
    #print = out.append
    ''' Cook your dish here! '''
    h, n = get_list()
    wepons = dict()
    for _ in range(n):
        a,b = get_list()
        if a in wepons:
            wepons[a] = min(b, wepons[a])
        else: wepons[a] = b
    dp = [0]*(h+1)
    for i in range(1, h+1):
        ans = INF
        for wp in wepons:
            if wp>i: ans = min(ans, wepons[wp])
            else: ans = min(ans, wepons[wp] + dp[i-wp])
        dp[i] = ans
    print(dp[-1])

''' Pythonista fLite 1.1 '''
import sys
#from collections import defaultdict, Counter
#from bisect import bisect_left, bisect_right
#from functools import reduce
#import math
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()
#[main() for _ in range(int(input()))]
print(*out, sep='\n')


Measured memory_bytes: 42444
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dup(x,y) (((x)+(y)-1)/(y))
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


signed main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int ans = max({ a * c,a * d,b * c,b * d });
	cout << ans;
}

Measured memory_bytes: 3632
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
z = 0
for i in range(n-1,-1,-1):
    if a[i+1] < b[i]:
        b[i] -= a[i+1]
        z += a[i+1]
        if a[i] < b[i]:
            z += a[i]
            a[i] = 0 
        else:
            z += b[i]
            a[i] -= b[i]
    else:
        z += b[i]
print(z)

Measured memory_bytes: 18624
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const ll MOD = 1000000007;

int main() {
    int n, t;
    cin >> n >> t;
    VI a(n);
    REP(i,n) scanf("%d", &a[i]);
    sort(a.begin(), a.end());
    ll ans = 1;
    int r = 0;
    REP(l,n){
        while (r < n-1 && a[r+1] <= a[l]+t) r++;
        ans = (ans * (r-l+1)) % MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3456
n, m = gets.split.map(&:to_i)
a = m.times.map { gets.split.map(&:to_i) }

if m == 1
  a.each do |l,r|
    puts r - l + 1
  end
else
  rp = 100000
  lp = 0
  arrs = []
  a.each do |l, r|
    if rp >= r
      rp = r
    end
    if lp <= l
      lp = l
    end
  end
  if rp - lp + 1 <= 0
    puts 0
  else
    puts rp - lp + 1
  end
end

Measured memory_bytes: 9596
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
long long n,a,b,c,d;
int main(){
	//freopen("main.in","r",stdin);
	cin >> n >> a >> b >> c >> d;
	n--; if(a > b) swap(a,b);
	long long del = b-a;

	for(int i = 0; i <= n; i++){
		long long x = i * c - (n-i) * c;
		long long l = x - (n-i) * (d-c);
		long long r = x + i*(d-c);
		if(l <= del && del <= r){
			cout << "YES" << endl;
			return 0;
		}
	}
	
	cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
n=int(input())
h=list(map(int,input().split()))
cnt=0
c=0
for i in range(max(h)):
    for j in range(n):
        if h[j]>=1:
            c=1
            h[j]-=1
        else:
            if c==1:
                cnt+=1
            c=0
    if c==1:
        cnt+=1
        c=0
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()

const int mod = 1000000007;
int binpow(int a, int b, int mod)
{
    int ans = 1;
    a = a % mod;
    b = b % mod;
    if (b == 0)
        return 1;
    while (b)
    {
        if (b & 1)
            ans = ((ans % mod) * (a % mod)) % mod;
        a = ((a % mod) * (a % mod)) % mod;
        b >>= 1;
    }
    return ans % mod;
}

//read question carefully!

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        int n = s.size();
        if (s[n - 1] != 's')
        {
            cout << s << "s"
                 << "\n";
        }
        else
        {
            cout << s << "es"
                 << "\n";
        }
    }
}


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

#if ((_WIN32 || __WIN32__) && __cplusplus < 201103L)
#define lld I64d
#else
#define lld lld
#endif

//{{{
using namespace std;
typedef long long LL;
typedef vector<int> VI;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
// clang-format off
#define debug(args...) {vector<string> _v = split(#args, ','); err(_v.begin(), args); cerr<<endl;}
vector<string> split(const string& s, char c) {vector<string> v; stringstream ss(s); string x; while
(getline(ss, x, c)) v.push_back(x); return v;} void err(vector<string>::iterator) {}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args)
{cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; err(++it, args...);}
// clang-format on
//}}}

const int N = 3000 + 10;
int n;
LL a[N], s[N];
LL dp[2][N][N];

LL calc(int l, int r) { return s[r] - s[l - 1]; }

LL dfs(int l, int r, int fg)
{
    if (dp[fg][l][r] != -1) return dp[fg][l][r];

    if (l > r) return 0;
    if (l == r) return dp[fg][l][r] = a[l];

    LL ret = 0;
    LL v1 = dfs(l + 1, r, fg ^ 1);
    LL v2 = dfs(l, r - 1, fg ^ 1);

    ret = max(calc(l + 1, r) - v1 + a[l], calc(l, r - 1) - v2 + a[r]);
    // debug(l, r, v1, v2, fg, ret);

    return dp[fg][l][r] = ret;
}

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
// freopen("out", "w", stdout);
#endif

    while (cin >> n)
    {
        for (int i = 1; i <= n; i++) cin >> a[i];
        s[0] = 0;
        for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];

        clr(dp, -1);
        LL ans = dfs(1, n, 0);

        cout << ans * 2 - s[n] << endl;
    }

    return 0;
}


Measured memory_bytes: 145436
#include <iostream>

using namespace std;

int main()
{
  string s;
  cin >> s;
  s=s+"0";
  for(int i=0; i<s.size()-1; ++i)
  {
    if (s[i]==s[i+1])
    {
      cout << i+1  << ' ' << i+2;
      return 0;
    } else
    if (s[i]==s[i+2])
    {
      cout << i+1 << ' ' << i+3;
      return 0;
    }
  }
  cout << -1 << ' ' << -1;
  return 0;
}

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

int main(){
    int n; cin>>n;
    int cnt = 0;
    bool valid = true;
    for(int i=0; i<n; i++){
        char p;
        int x;
        cin>>p>>x;
        if(p == '(') cnt += x;
        else cnt -= x;

        if(cnt < 0) valid = false;
    }

    if(!valid || cnt != 0){
        cout << "NO" << endl;
    }
    else{
        cout << "YES" << endl;
    }
}


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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll h,w; cin>>h>>w;
    vector<string> a(h);
    rep(i,h) cin>>a[i];

    vector<bool> row(h,false),col(w,false);
    rep(i,h)rep(j,w) if(a[i][j]=='#'){
        row[i]=true;
        col[j]=true;
    }

    rep(i,h){
        if(row[i]){
            rep(j,w){
                if(col[j]){
                    cout<<a[i][j];
                }
            }
            cout<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
  int h,w,n;
  cin >> h >> w;
  cin >> n;
  vector<int> a(n);
  int ans[h][w];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  int pos=0;
  int color=1;
  int c=0;
  bool flg = false;
  for(int i=0;i<h;i++){
    if(!flg){
      for(int j=0;j<w;j++){
        if(a[pos]==c){
          c=0;
          pos++;
          color++;
        }
        ans[i][j]=color;
        c++;
      }
      flg = true;
    }else{
      for(int j=w-1;j>=0;j--){
        if(a[pos]==c){
          c=0;
          pos++;
          color++;
        }
        ans[i][j]=color;
        c++;
      }
      flg=false;
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(j!=0)
        cout<<" ";
      cout<<ans[i][j];
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n, t, f, z;

int main()
{
    t = 0; f = 0; z = 0;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        int a;
        scanf("%d", &a);
        if(a % 4 == 0) f++;
        else if(a % 2 == 0) t++;
        else z++;
    }
    int tmp = f - z;
    if(tmp >= 0) printf("Yes\n");
    else if(tmp == -1 && t == 0) printf("Yes\n");
    else printf("No\n");
    return 0;
}


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

peak = []
trough = []
h = [0] + h + [0]
before = 0
for a, b in zip(h[:-1], h[1:]):
    after = b - a
    if after == 0:
        continue
    elif before > 0 > after:
        peak.append(a)
    elif before < 0 < after:
        trough.append(a)
    before = after

print(sum(peak) - sum(trough))

Measured memory_bytes: 3064
#include <iostream>
 #include <vector>
 #include <map>
 using namespace std;
 vector<int> mat[2004];
 
 int main()
 {
     int n;
     cin>>n;
     map<int, int> edg;
     for(int i = 1; i <= 2e3; ++i) {
         edg[i] = (i * (i-1))/2;
     }
     int e = -1;
     for(auto i : edg) {
         if(i.second == n) {
             e = i.first;
         }
     }
     if(e == -1) {
         printf("No\n");
         return 0;
     }
     int cnt = 1;
     for(int i = 1; i <= e; ++i) {
         for(int j = i + 1; j <= e; ++j) {
             mat[i].push_back(cnt);
             mat[j].push_back(cnt);
             cnt++;
         }
     }
     printf("Yes\n");
     printf("%d\n", e);                              
     for(int i = 1; i <= e; ++i) {
         printf("%d ", mat[i].size());
         for(auto j : mat[i])
             printf("%d ", j);
         printf("\n");
     }
     
     return 0;
 }
                                                     

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9+21;
const long long LINF = (long long) 1e18;
const long double PI = 2 * acos((long double)0);
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
#define Mahmud main()
#define endl "\n"
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define alla(arr,n) arr,arr+n
#define sz(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define pb push_back
///Debug
#define dbg1(x) std::cerr<<#x<<"="<<(x)<<endl;
#define dbg2(x,y) std::cerr<<#x<<"="<<(x)<<','<<#y<<"="<<(y)<<endl;
#define dbg3(x,y,z) std::cerr<<#x<<"="<<(x)<<','<<#y<<"="<<(y)<<','<<#z<<"="<<(z)<<endl;
#define dbgArr(arr,n) cerr<<#arr<<"=["; printArray(arr,n,0,93); cerr<<endl;
///traversing
#define rep(n) for(int i=0;i<n;++i)
#define trv(i,t) for(__typeof(t.begin()) i=t.begin();i!=t.end();++i)
///necessary functions
inline ll Int()
{
    ll _x=0,_tmp=1;
    char _tc=getchar();
    while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
    if( _tc == '-' ) _tc=getchar(), _tmp = -1;
    while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
    return _x*_tmp;
}
inline long double Double()
{
    long double d;
    scanf("%Lf",&d);
    return d;
}
ll lcm(ll a,ll b)
{
    return a/__gcd(a,b)*b;
}
int ton(string x)
{
    int y;
    std::istringstream ss(x);
    ss >> y;
    return y;
}
template<typename T>
string tostring(T x)
{
    ostringstream ss;
    ss << x ;
    return ss.str();
}

///Current Code vars
#define N 100010
long long n,k,c,d;
ll arr[N+1],brr[N+1];
///Current Code functions

string s;

void out(int x)
{
    if(x==0) puts("IMPOSSIBLE");
    else puts("POSSIBLE");
    exit(0);
}
map<long long,int>mm,ans;
void solve()
{
    n = Int(), k = Int();
    for(int i=0;i<n;++i)
    {
        long long u = Int();
        arr[i] = u;
        mm[arr[i]] = 1;
        if(u==k) out(1);
    }
    if(n==1)
    {
        if(arr[0] != k) out(0);
        else out(1);
    }
    sort(arr,arr+n);
    if(arr[n-1] <k) out(0);
    ll gcd = arr[0];
    for(int i = 1; i<n;++i) gcd = __gcd(arr[i],gcd);
    if(k%gcd==0) out(1);
    else out(0);
}

int Mahmud
{
    // ios_base::sync_with_stdio(0); //cin.tie(0);
  //#ifdef _LOCAL_
    //freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
  //while(1)
    solve();
  //#ifdef _LOCAL_
    //printf("\nTime elapsed: %dms", 1000 * clock() / CLOCKS_PER_SEC);
  //#endif
    return 0;
}


Measured memory_bytes: 7296
#include<stdio.h>


int main(){
  
  char s[100001];
  int length = 0, stpoint = 0, letmany = 1, num[100000];
  scanf("%s",s);
  while(s[length] != '\0'){
    num[length] = 0;
    length++;
  }
  
  for(int i = 1; length > i; i++){
    if(s[i] == s[i-1])
      letmany++;
    else{
      if(s[i-1] == 'R'){
        num[i-1] += (letmany/2)+(letmany%2);
      	num[i] += (letmany/2);
      }
      else{
        num[stpoint-1] += (letmany/2);
        num[stpoint] += (letmany/2)+(letmany%2);
      }
      letmany = 1;
      stpoint = i;
    }
  }
  num[stpoint-1] += (letmany/2);
  num[stpoint] += (letmany/2)+(letmany%2);
  
  for(int i = 0; length > i; i++)
    printf("%d ",num[i]);
  
  return 0;
  
  
}

Measured memory_bytes: 896
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n[2],k;
    cin>>n[0]>>n[1]>>k;
    
    int now=0, nxt=1;
    rep(i,k){
        if(n[now]%2) n[now]--;
        ll a=n[now]/2;
        n[now]-=a;
        n[nxt]+=a;
        swap(now,nxt);
    }
    
    cout2(n[0],n[1])
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
  int k;
  cin >> k;
  string s;
  cin >> s;
  int n = s.length();
  mint ans = 0;
  combination comb(n + k + 10);
  rep(i, k + 1) {
    ans += comb(n + i - 1, n - 1) * mint(25).pow(i) * mint(26).pow(k - i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 35660
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main() {
    int n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d >> s;
    a--; b--; c--; d--;

    bool ans = true;

    for (int i = b+1; i <= d-1; i++) {
        if (s[i] == '#' && s[i+1] == '#') {
            ans = false;
            break;
        }
    }

    for (int i = a+1; i <= c-1; i++) {
        if (s[i] == '#' && s[i+1] == '#') {
            ans = false;
            break;
        }
    }

    if (c > d) {
        bool flag = false;
        for (int i = b; i <= d; i++) {
            if (s[i-1] == '.' && s[i] == '.' && s[i+1] == '.') {
                flag = true;
                break;
            }
        }
        if (!flag) ans = false;
    }

    cout << (ans ? "Yes" : "No") << "\n";
    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const int MOD = 1e9+7;
int n, s, D = 1500;
long long cur[2][55][3000];
int main(){
	scanf("%d%d", &n, &s);
	if(s&1) return 0*puts("0");
	s /= 2; cur[0][0][D] = 1;
	for(int i = 1; i <= n; i++) rep(j,i+1) rep(k,3000)
		cur[i&1][j][k] = (cur[~i&1][j][k]*(2*j+1) + (j ? cur[~i&1][j-1][k+i] : 0) + cur[~i&1][j+1][k-i]*(j+1)*(j+1)) % MOD;
	printf("%lld\n", cur[n&1][0][s+D]);
}

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

int main(){
    int n;
    cin >> n;
    vector<int> e(n - 1);
    vector<vector<int>> g(n);
    rep(i, n - 1){
        int a, b;
        cin >> a >> b;
        a--; b--;
        e[i] = b;
        g[a].pb(b);
    }
    int k = 0;
    rep(i, n){
        k = max(k, (int)g[i].size());
        if (i == 0) k--;
    }
    k++;
    cout << k << endl;
    queue<int> que;
    vector<int> seen(n);
    que.push(0);
    seen[0] = -1; 
    while (!que.empty()){
        int x = que.front();
        que.pop();
        rep(i, g[x].size()){
            int nx = g[x][i];
            que.push(nx);
            seen[nx] = (seen[x] + i + 1) % k;
        }
    }
    rep(i, n - 1){
        cout << seen[e[i]]  + 1 << endl;
    }
}

Measured memory_bytes: 7844
import math
import sys

n = int(input())

words = list()

for i in range(n):
    words.append(input())


if len(words) != len(set(words)):
    print("No")
    sys.exit()

for i in range(n-1):
    if words[i][-1] != words[i+1][0]:
        print("No")
        sys.exit()

print("Yes")


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

int main() {
	int n, x, y;
	cin >> n;
	cin >> x;
	cin >> y;
	vector<int> results(n);
	for (int i = 1; i <= n-1; i++) {
		for (int j = i + 1; j <= n; j++) {
			int first = abs(j-i);
			int second = abs(x-i) + 1 + abs(j-y);
			int result = min(first, second);
			results[result-1]++;
		}
	}
	for (int i = 0; i < n-1; i++) {
		cout << results[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define ALLR(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EMP emplace
#define EMPB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define Bit(n) (1LL << (n))
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

int cnt[10];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  REP(i, 4) {
    int a;
    cin >> a;
    cnt[a]++;
  }
  cout << (cnt[1] && cnt[9] && cnt[7] && cnt[4] ? "YES" : "NO") << endl;

  return 0;
}

Measured memory_bytes: 764
#include <stdio.h>

int main(int argc, const char * argv[])
{
    int i, j, k, n, count;
    int a[999999];
    
    count = 0;
    
    while(scanf("%d",&n) != EOF){
        if (count == 0) {
            if (n > 1) {
                a[count++] = 2;
                if (n > 2) {
                    a[count++] = 3;
                    for(i=5; i<=n; i+=2){
                        k=0;
                        for(j=0; a[j]*a[j] <= i; j++){
                            if(i%a[j] == 0) {
                                k = 1;
                                break;
                            }
                        }
                        if (k == 0) {
                            a[count++] = i;
                        }
                    }
                }
            }
            printf("%d\n",count);
        } else {
            if (n <= a[count - 1]) {
                for (i=count - 1; n < a[i]; i--);
                printf("%d\n", i+1);
            } else {
                if (a[count-1] == 2) {
                    a[count++] = 3;
                    printf("%d\n",count);
                } else {
                    for(i=a[count - 1]+2; i<=n; i+=2){
                        k=0;
                        for(j=0; a[j]*a[j] <= i; j++){
                            if(i%a[j] == 0) {
                                k = 1;
                                break;
                            }
                        }
                        if (k == 0) {
                            a[count++] = i;
                        }
                    }
                    printf("%d\n", count);
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1340
#include<bits/stdc++.h>
#define INT long long int
#define oo 987654321
using namespace std;
INT H,W,h,w,a[30][30], ans;

int main()
{
    ios::sync_with_stdio(false);
    cin>>H>>W>>h>>w;
    for(int i = 0 ; i < h ; i++ )
        for(int j = 0 ; j < W ; j++ )
            a[i][j] = 1;
    for(int i = 0 ; i < w ; i++ )
        for(int j = 0 ; j < H ; j++ )
            a[j][i] = 1;
    for(int i = 0 ; i < H ; i++ )
        for(int j = 0 ; j < W ; j++ )
            if( !a[i][j] ) ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import math
import sys
from collections import defaultdict

class Graph:
    def __init__(self,vertices):
        self.graph=defaultdict(list)
        self.V=vertices

    def addEdge(self,u,v):
        self.graph[u].append(v)

def isCycle(n,graph):

    in_degree=[0]*n

    for i in range(n):
        for j in graph[i]:
            in_degree[j]+=1

    queue=[]
    for i in range(len(in_degree)):
        if in_degree[i]==0:
            queue.append(i)

    counter=0

    while(queue):

        nu=queue.pop(0)

        for v in graph[nu]:
            in_degree[v]-=1

            if in_degree[v]==0:
                queue.append(v)
        counter+=1
    if counter==n:
        return False
    else:
        return True


if __name__=='__main__':

    V, E, = (int(x) for x in input().split())
    g = Graph(V)
    for i in range(E):
        v, e = (int(x) for x in input().split())
        g.addEdge(v,e)

    if(True == isCycle(g.V,g.graph)):
        print("1")
    else:
        print("0")



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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	string s, t;
	cin >>s >>t;
	
	int n=sz(s), m=sz(t);
	int ans =MD;
	rep(i, n+1-m){
		int cnt = 0;
		rep(j, m){
			if(s[i+j] != t[j]) cnt++;
		}
		ans = min(ans, cnt);
	}
	cout <<ans <<"\n";
	return 0;
}



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

using namespace std;

int n, m, x, k, ans, a[105];

int main() {
    cin >> n >> k;
    for (int i = 1; i <= k; i++){
        cin >> m;
        for (int j = 1; j <= m; j++){
            cin >> x;
            a[x]++;
        }
    }
    ans = 0;
    for (int i = 1; i <= n; i++){
        if (a[i] == 0)
            ans++;
    }
    cout << ans;
}

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

int main() {
    uint64_t n;
    std::cin >> n;

    uint64_t answer;

    if(n % 2 == 1) {
        answer = n * ((n - 1) / 2);
    } else {
        answer = (n / 2) * (n - 1);
    }

    std::cout << answer;

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Basic Modifications - Unique
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_4_D&lang=jp

"""
_ = input()
prev = float('-inf')
res = []
for a in input().split():
    a = int(a)
    if a > prev:
        res.append(a)
        prev = a
print(*res)



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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
lr = [LI() + [i] for i in range(n)]
x = sorted(lr, reverse=1)
L_max,R_,idx1 = x[0]
x = sorted(lr, key = itemgetter(1))
L_, R_min,idx2 = x[0]
tmp = 0
for l,r,i in lr:
    if i == idx1 or i == idx2:
        continue
    tmp = max(tmp,r-l+1)
ans1 = max(0,R_min - L_max+1) + tmp
lst = [[max(0,r-L_max+1),l,i] for l,r,i in lr]
lst.sort()
tmp1 = inf
ans2 = 0
for i in range(1,n):
    tmp1 = min(tmp1, max(0,R_min - lst[i-1][1]+1))
    tmp2 = lst[i][0]
    ans2 = max(ans2,tmp1+tmp2)
print(max(ans1,ans2))

Measured memory_bytes: 78280
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // order_of_key
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = 3000000;
#define PI 3.14159265
int main()
{
    fastio;
    int n;
    cin>>n;

    int rem = n%(500);
    ll ans = 1LL*1000*(n/500);
    ans = ans + 5*(rem/5);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()
str_list = ["A", "B", "C", "D", "E", "F", "G", "H",
           "I", "J", "K", "L", "M", "N", "O", "P",
          "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
str_list2 = str_list + str_list
for iter, i in enumerate(S):
    num = str_list.index(i)
    new_str = str_list2[num+N]
    if iter == 0:
        ans = new_str
    else:
        ans += new_str
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		for(int i=0; i<s.length(); i++) {
			System.out.print("x");
		}
		System.out.println();
		sc.close();
	}
}


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

typedef long long ll;
typedef pair<int, int> pii; 
const int N = 2e5+10, mod = 1e9+7;

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

    map<string, int> mp;
    while (n--) {
        string s; cin >> s;
        ++mp[s];
    }

    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
}   

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t = 1; 
    while (t--) solve();
    return 0;
}


Measured memory_bytes: 3664
#include <stdio.h>
#include <string.h> 
int main()
{
	char a[100005],b[100005],c[100005];
	scanf("%s",&a);
	scanf("%s",&b);
	scanf("%s",&c);
	if(b[0]<=90){
		printf("A%cC\n",b[0]);
	}else{
		b[0] = b[0] - 32;
		printf("A%cC\n",b[0]);
	}
	return 0;	
} 

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll a,b,ans,sum,mi,p;
    cin>>a>>b;
    sum=a+b;
    mi=a-b;
    p=a*b;
    ll res=max(sum,mi);
    cout<<max(res,p)<<endl;
}


Measured memory_bytes: 256
(n,),a,b=$<.map{|l|l.split.map &:to_i}
c,d=[a,b].map{|z|(z<<F=z[0]).each_cons(2).map{|x,y|x^y}}
d+=m=[k=-1]
d.map{|x|k=m[k]until k<0||d[k]==x;m<<k+=1}
j=0
(2*n-1).times{|i|j=m[j]until j<0||d[j]==c[i%n];p i+=1-n,F^a[i]if n==j+=1}

Measured memory_bytes: 58468
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

int ok(ll n, ll m, ll M, ll s) {
    if(M-m>1) return 0;
    if(M==m)  return M==n-1 || M<=n/2;
    ll n1=s-m*n;
    ll n2=n-n1;
    return M>=n2+1 && M<=n2+n1/2;
}

int main() {
    ll i, n, m, M, s, t;
    scanf("%lld", &n);
    m=n; M=0; s=0;
    for(i=0; i<n; i++) {
        scanf("%lld", &t);
        m=min(m, t);
        M=max(M, t);
        s=s+t;
    }
    printf(ok(n, m, M, s)? "Yes\n" : "No\n");
    return 0;
}

Measured memory_bytes: 256
let () = Scanf.scanf "%d" @@ fun n ->
  let n = n lor (n lsr 1) in
  let n = n lor (n lsr 2) in
  let n = n lor (n lsr 4) in
  let n = n lor (n lsr 8) in
  let n = n lor (n lsr 16) in
  Printf.printf "%d\n" @@ (n + 1) lsr 1


Measured memory_bytes: 384
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}
void solve()
{
	string s;
	cin >> s;
	ll sum = 0;
	for(int i = 0; i < (1 << (sz(s) - 1)); ++i){
		ll to = 0;
		for(int j = 0; j < sz(s); ++j){
			to *= 10;
			to += s[j] - '0';
			if(i & (1 << j)){
				sum += to;
				to = 0;
			}
		}	
		sum += to;
		to = 0;
	}
	cout << sum;
}


 // a b c a b c a b c a b c
 
int main()
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
    Red;
  	int T = 1;
  //	cin >> T;
  	for(int i = 1; i <= T; ++i){
  		solve();
  	}
  	return 0;

}

Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=(1<<20)+5;
int a[N],b[N],q[N],st[N],vis[N],top,n;
void solve(){
	if(top==n)return;
	R int m=top;
//	fp(i,1,top)printf("%d%c",st[i]," \n"[i==top]);
	for(R int i=1,p=1;i<=m;++i){
		while(p<=n&&(vis[p]||a[p]>=a[st[i]]))++p;
//		printf("%d %d\n",st[i],p);
		if(p>n){puts("No");exit(0);}
		st[++top]=p++;
	}
	sort(st+1,st+1+top);
	fp(i,1,top)vis[st[i]]=1;
	solve();
}
int main(){
	scanf("%d",&n),n=1<<n;
	fp(i,1,n)scanf("%d",&a[i]);
	sort(a+1,a+1+n),reverse(a+1,a+1+n);
	st[++top]=1,vis[1]=1;
	solve();
	puts("Yes");
	return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>

using namespace std;

int main() {
    int a, b, x;

//    ifstream in("C:\\Users\\P218024\\Documents\\Cpp Projects\\abc094\\sample.txt");
//    cin.rdbuf(in.rdbuf());

    cin >> a >> b >> x;
    cout << ((a <= x)  && (x <= a + b) ? "YES" : "NO");

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
    int A, B;
    cin >> A >> B;
    if(A >= B * 2){
        cout << A - B*2<<endl;
    }
    else{
        cout << "0" <<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
    #include <string>
    using namespace std;
    int main(void){
     long long int a,b,k;
     cin >> a >> b >> k;
        if(k<=a)
            a=a-k;
      else{
             b=b-(k-a);
          a=0;
       
        
      }
      if(b<0)
         b=0;
         
        cout << a << " " << b;
    }

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << min(A, B) + min(C, D) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
char s[110];
int n,pos,maxn;
int main()
{
    scanf("%d%s",&n,s+1);
    for(int i=1;i<=n;++i)
    {
        if(s[i]=='I') ++pos;
        else --pos;
        maxn=max(maxn,pos);
    }
    cout<<maxn<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys,os,re
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate
sys.setrecursionlimit(10**6)

card=[[False for i in range(13)]for j in range(4)]
mark=["S","H","C","D"]

n=int(input())
for i in range(n):
    s,m=input().split()
    card[mark.index(s)][int(m)-1]=True

for i in range(4):
    for j in range(13):
        if not card[i][j]:
            print(mark[i],j+1)


Measured memory_bytes: 6504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef pair<double,int>Q;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
ll modpow(ll x,ll n)
{
	ll res=1;
	while(n>0)
	{
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
ll F[100005],R[100005];
void make(){
	F[0] = 1;
	for(int i=1;i<100005;i++) F[i] = F[i-1]*i%mod;
	for(int i=0;i<100005;i++) R[i] = modpow(F[i],mod-2);
}
ll C(int a,int b){
	return F[a]*R[b]%mod*R[a-b]%mod;
}
ll cc[2005][2005],rui[2005][2005],rui2[2005][2005];
int main(){
	make();
	int a,b;cin>>a>>b;
	cc[0][0]=1;
	for(int i=1;i<2005;i++) for(int j=0;j<=i;j++){
		if(j==0||j==i) cc[i][j]=1;
		else{
			cc[i][j] = cc[i-1][j-1]+cc[i-1][j];
			cc[i][j] %= mod;
		}
	}
	//cout<<cc[5][2]<<endl;
	for(int i=0;i<2005;i++){
		for(int j=0;j<=i;j++){
			if(j==0) rui[i][j] = cc[i][j];
			else rui[i][j] = (rui[i][j-1]+cc[i][j])%mod;
		}
	}
	for(int i=0;i<2005;i++){
		for(int j=0;j<=i;j++){
			if(j==0) rui2[i][j] = rui[i][j];
			else rui2[i][j] = (rui2[i][j-1]+rui[i][j])%mod;
		}
	}
	ll ans = 0;
	for(int x=0;x<=a;x++){
		for(int k=x;k<=a;k++){
		    if(b-1<k-x) continue;
			ll ret = C(b-1,k-x); //assert(b-1<k-x);
			if(x==k){
				ans=(ans+ret)%mod;
			}
			else{
				ll sum=0;
				if(a-k >= k-x-1){
					sum = (a-k) - (k-x-1);
					sum = sum*modpow(2,k-x-1)%mod;
					sum = (sum+rui2[k-x-1][k-x-1])%mod;
				}
				else{
					sum = rui2[k-x-1][a-k];
				}
				sum%=mod;
				ans += ret*sum%mod;
				ans %= mod;/*
				for(int i=0;i<=a-k;i++){
					int X = a-k-i,Y = k-x-1;
					//num is Y
					ll sum = 0;
					for(int j=Y;j>=max(0,Y-X);j--) sum += C(Y,j);
					ans+=ret*sum;
				}*/
			}
			
		}
	}
	cout<<ans%mod<<endl;
}

Measured memory_bytes: 94592
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const double pi=acos(-1);

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(){
    char c;
    cin >> c;
    if(c<'a') cout << "A" << endl;
    else cout << "a" << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define sort(a) sort(a.begin(),a.end())
#define MOD (int)(1e9+7)
#define EPS 1e-8
#define INF (int)(1e9+1e7)
#define INFL (ll)(1e18)
typedef long long ll;
using namespace std;
int main()
{
    int n;
    cin >> n;
    multiset<ll>used;
    used.insert(-1);used.insert(-1);
    used.insert(n);used.insert(n);

    vector<ll>ind(n,-1);
    rep(i,n){
        ll p;
        cin >> p;--p;
        ind[p]=i;
    }
    ll ans=0;
    for(ll i = n-1;i>=0;i--){
        ll k = ind[i];
        used.insert(k);
        auto itr =used.lower_bound(k);
        ll c =*(++itr);
        ll d =*(++itr);
        --itr;--itr;
        ll b =*(--itr);
        ll a =*(--itr);
        
        ans+=(i+1)*((b-a)*(c-k)+(d-c)*(k-b));
    }

    cout << ans << endl;
}

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

typedef long long ll;
const int N=20;
int a[N],n;
ll dfs(int L,int R,int lt,int rt){
	if(L>R)return 0;
	if(L==R)return (ll)(lt+rt)*a[L];
	ll ret=LLONG_MAX;
	for(int i=L;i<=R;++i)
		ret=min(ret,dfs(L,i-1,lt,lt+rt)+dfs(i+1,R,lt+rt,rt)+(ll)(lt+rt)*a[i]);
	return ret;
}

int main(){
#ifdef ONLINE_JUDGE
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#endif
	cin>>n;
	for(int i=1;i<=n;++i)cin>>a[i];
	cout<<dfs(2,n-1,1,1)+a[1]+a[n]<<endl;
	return 0;
}



Measured memory_bytes: 384
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  double ans = 0;
  for (int i = 1; i <= n; i++) {
    if (i >= k) {
      ans += 1;
      continue;
    }
    int cal = i;
    double tmp = 1;
    while (cal < k) {
      tmp *= 0.5;
      cal *= 2;
    }
    ans += tmp;
  }
  printf("%.10f\n", ans / (double)n);
  return 0;
}

Measured memory_bytes: 256
N=gets.to_i

h={}

c = nil
N.times do
    s=gets.chomp
    if h[s]
        puts 'No'
        exit 0
    end
    h[s] = 1
    if c.nil? || s[0] == c
        c = s[-1]
    else
        puts 'No'
        exit 0
    end

end

puts 'Yes'


Measured memory_bytes: 3836
//#include "stdc++.h"
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
typedef long long int ll;
inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0) return 1;ll p=power(a,n/2,m);p=(p*p)%m;if(n%2) return (p*a)%m;else return p; }
#define flush fflush(stdout)
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
#define int long long

int dp[100001][2],phi;vector<int> adj[100001];int m;int lft[100001];int ans[100001];

void dfs1(int u,int p,int vp)
{
    int vl=(lft[u]%m*(vp+1)%m)%m;
    ans[u]=dp[u][0];
    ans[u]=(ans[u]%m+(dp[u][0]%m*vl%m)%m)%m;
    int v;
    for(int i=0;i<adj[u].size();i++)
    {
        v=adj[u][i];
        if(v!=p)
        {
            
            dfs1(v,u,vl);
        }
    }
}
void dfs(int u,int p)
{
    int v;
    dp[u][0]=1;
    dp[u][1]=0;int z=0;vector<int>ve;
    for(int i=0;i<adj[u].size();i++)
    {
        v=adj[u][i];
        if(v!=p)
        {
            dfs(v,u);z++;ve.pb(v);
            dp[u][0]=(dp[u][0]%m*(dp[v][0]+1)%m)%m;
            dp[u][1]=(dp[u][1]%m+dp[v][0]%m)%m;
            dp[u][1]=(dp[u][1]%m+dp[v][1]%m)%m;
        }
    }
    if(z)
    {
    int lt[z+2],rt[z+2];
    lt[0]=1;
    rt[z+1]=1;
    for(int i=1;i<=z;i++)
    {
        lt[i]=(lt[i-1]%m*(dp[ve[i-1]][0]+1)%m)%m;
    }
    for(int i=z;i>=1;i--)
    {
        rt[i]=(rt[i+1]%m*(dp[ve[i-1]][0]+1)%m)%m;
    }
    for(int i=1;i<=z;i++)
    {
        lft[ve[i-1]]=(lt[i-1]%m*rt[i+1]%m)%m;
    }
    }
        
}
int32_t main()
{
    IOS;//ifstream fin("input.txt");ofstream fout("output.txt");/*
    int n;int u,v;
    cin>>n>>m;
    
    for(int i=1;i<n;i++)
    {
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(1,0);
   // for(int i=1;i<=n;i++)
     //   cout<<dp[i][0]<<" "<<dp[i][1]<<endl;
    dfs1(1,0,0);
    for(int i=1;i<=n;i++)
        cout<<ans[i]<<endl;
    return 0;
}



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

int main(){
  string s;
  cin >>s;
  bool app[26];
  rep(i,26) app[i] = false;
  rep(i,s.size()){
    app[s[i]-'a'] = true;
  }
  rep(i,26){
    if(app[i]==false){
      cout << char(i+'a') << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline
from collections import Counter



def main():
    N = int(input())
    S = input().strip()

    ans = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                x = S.find(str(i))
                if x == -1 or x == N - 1:
                    continue
                y = S[x + 1:].find(str(j))
                if y == -1 or y == N - 1:
                    continue
                z = S[x + y + 2:].find(str(k))
                if z == -1:
                    continue
                ans += 1
    print(ans)








if __name__ == '__main__':
    main()



Measured memory_bytes: 3444