akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef unsigned long long ull;
#define forinc(a,b,c) for(int a=b, _c=c; a<=_c; ++a)
#define fordec(a,b,c) for(int a=b, _c=c; a>=_c; --a)
#define forv(a,b) for(auto &a:b)
#define ii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define all(a) begin(a), end(a)
#define reset(f, x) memset(f, x, sizeof(f))
#define sz(x) (int)(x.size())
#define bit(x, i) (x>>(i-1)&1ll)
#define onbit(x, i) (x|(1ll<<(i-1)))
#define offbit(x, i) (x&~(1ll<<(i-1)))
template<class T> void Max(T &x, T y){ return x = (x > y) ? x : y;}
template<class T> void Min(T &x, T y){ return x = (x < y) ? x : y;}

const int N=1e5+5;
int n, f[N][4][4][4],x,y,z;
tuple<int,int,int> trace[N][4][4][4];
string s[N];
char c[N][4][4][4];

main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);

  cin>>n>>x>>y>>z;
  forinc(i,1,n) cin>>s[i];

  x=min(x,3); y=min(y,3); z=min(z,3);

  auto u=[&](int x){return min(x+1,3);};
  auto v=[&](int x){return x-1;};
  f[0][x][y][z]=1;
  forinc(t,0,n-1){
    forinc(i,0,3){
      forinc(j,0,3){
        forinc(k,0,3){
          if(!f[t][i][j][k]) continue;
          tuple<int,int,int> now=mt(i,j,k);

          if(s[t+1]=="AB") {
            if(i){
              f[t+1][v(i)][u(j)][k]=1;
              trace[t+1][v(i)][u(j)][k]=now;
              c[t+1][v(i)][u(j)][k]='B';
            }
            if(j){
              f[t+1][u(i)][v(j)][k]=1;
              trace[t+1][u(i)][v(j)][k]=now;
              c[t+1][u(i)][v(j)][k]='A';
            }
          }
          else if(s[t+1]=="BC"){
            if(k){
              f[t+1][i][u(j)][v(k)]=1;
              trace[t+1][i][u(j)][v(k)]=now;
              c[t+1][i][u(j)][v(k)]='B';
            }
            if(j){
              f[t+1][i][v(j)][u(k)]=1;
              trace[t+1][(i)][v(j)][u(k)]=now;
              c[t+1][(i)][v(j)][u(k)]='C';
            }
          }
          else{
            if(k){
              f[t+1][u(i)][j][v(k)]=1;
              trace[t+1][u(i)][(j)][v(k)]=now;
              c[t+1][u(i)][j][v(k)]='A';
            }
            if(i){
              f[t+1][v(i)][j][u(k)]=1;
              trace[t+1][v(i)][(j)][u(k)]=now;
              c[t+1][v(i)][j][u(k)]='C';
            }
          }
        }
      }
    }
  }
  tuple<int,int,int> t=mt(-1,-1,-1);
  bool ok=0;
  forinc(i,0,3) forinc(j,0,3) forinc(k,0,3){
    if(f[n][i][j][k]){
      t=mt(i,j,k);
      ok=1;
      break;
    }
  }
  if(!ok) return cout<<"No\n",0;
  vector<char> ans;
  int now=n,i,j,k; tie(i,j,k)=t;
  while(now){
    ans.pb(c[now][i][j][k]);
    int _i,_j,_k;
    tie(_i,_j,_k)=trace[now][i][j][k];
    i=_i, j=_j, k=_k;
    now--;
  }
  reverse(all(ans));
  cout<<"Yes\n";
  forv(v,ans) cout<<v<<'\n';
}


Measured memory_bytes: 113088
def sp(n):
  a = n // 3
  b = (n - a) // 2
  c = n -a -b
  return a,b,c

def ceil(x, y):
  return (x -1) // y + 1

def tatedake_diff(h, w):
  a,b,c = sp(h)
  s1 = (c-a) * w
  a,b,c = sp(w)
  s2 = (c-a) * h
  return min(s1, s2)

def tateyoko_diff(h, w):
  a,b,c = sp(h)
  s1 = (c * w)
  s2 = (h - c) * (w // 2)
  s3 = (h - c) * ceil(w, 2)
  r1 = max(s1,s2,s3) - min(s1,s2,s3)
  s1 = (a * w)
  s2 = (h - a) * (w // 2)
  s3 = (h - a) * ceil(w, 2)
  r2 = max(s1,s2,s3) - min(s1,s2,s3)
  return min(r1,r2)
  
H, W = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
  ans = 0
else:
  ans = min(tatedake_diff(H, W), tateyoko_diff(H, W), tateyoko_diff(W, H))
print(ans)

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



int main()
{
    // 整数の入力
 //   int a, b;
    // 文字列の入力
    std::string s;
    //char i;
 

    cin >> s ;

   // t= s;
    int a;
    a=s.length();
    
   s.replace(s.begin(),s.end() ,a, 'x');
    
    // 出力
    cout << s << endl;

    return 0;
}

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

#define x first
#define y second

int n, l[300055], r[300055], ans;
char s[300055];

int main () {
	
	scanf("%d%s", &n, s + 1);
	
//	printf("[%s]\n", s + 1);
	
	for (int i = 1; i <= n; i++)
		l[i] = l[i - 1] + (s[i] == 'W');
	
	for (int i = n; i >= 1; i--) {
		r[i] = r[i + 1] + (s[i] == 'E');
	}
	
	ans = r[2];
	
	for (int i = 1; i <= n; i++)
		ans = min(ans, l[i - 1] + r[i + 1]);
	
	printf("%d\n", ans);
	
	return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

bool check(vector<deque<pair<int, char>>> const& cards) {
  rep(i, 3) {
    assert(cards[i].size() == 3);
    char col = cards[i][0].second;
    vector<int> is;
    for(auto p: cards[i]) {
      if(col != p.second) return false;
      is.push_back(p.first);
    }
    sort(is.begin(), is.end());
    if(!((is[0] + 1 == is[1] && is[1] + 1 == is[2])
      || (is[0] == is[2]))) return false;
  }
  return true;
}

bool dfs(vector<pair<int, char>> const& vs, vector<deque<pair<int, char>>>& cards, int idx) {
  if(idx == vs.size()) {
    if(check(cards)) return true;
    return false;
  }
  rep(i, 3) {
    if(cards[i].size() < 3) {
      cards[i].push_back(vs[idx]);
      if(dfs(vs, cards, idx + 1)) return true;
      cards[i].pop_back();
    }
  }
  return false;
}

int main() {

  int Tc; cin >> Tc;
  while(Tc--) {
    vector<pair<int, char>> vs;
    vector<int> a(9); vector<char> b(9);
    rep(i, 9) cin >> a[i];
    rep(i, 9) cin >> b[i];
    rep(i, 9) {
      vs.emplace_back(a[i], b[i]);
    }
    vector<deque<pair<int, char>>> cards(3);
    cout << dfs(vs, cards, 0) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3136
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    int n; char c; string abo;
    int A = 0, B = 0, AB = 0, O = 0;
    while (cin >> n >> c >> abo) {
        if (abo == "A") A ++;
        else if (abo == "B") B ++;
        else if (abo == "AB") AB ++;
        else if (abo == "O") O ++;
    }
    cout << A << endl;
    cout << B << endl;
    cout << AB << endl;
    cout << O << endl;
    return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main(){
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e-a<=k) cout << "Yay!" << endl;
    else cout << ":(" << endl;
}

Measured memory_bytes: 256
def square(n):
    mp = [[0 for _ in range(n)] for _ in range(n)]

    x, y = n // 2, n // 2 + 1
    mp[y][x] = 1

    for i in range(2, n ** 2 + 1):
        x = (x + 1) % n
        y = (y + 1) % n

        while mp[y][x]:
            y = (y + 1) % n
            x = (x - 1) % n

        mp[y][x] = i

    for line in mp:
        s = ""
        for i in line:
            si = str(i)
            s += si.rjust(4)
        print(s)


while True:
    n = int(input())
    if not n:
        break
    square(n)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> p(n);

  for (int i = 0; i < n; i++) {
    cin >> p.at(i);
  }
  
  int count = 0;
  for (int i = 1; i < n - 1; i++) {
    if ((p.at(i-1) < p.at(i)) && (p.at(i) < p.at(i+1)) ||
        (p.at(i+1) < p.at(i)) && (p.at(i) < p.at(i-1))) {
      count++;
    }
  }
  
  cout << count << endl;
}

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

using namespace std;

#define ll long long
#define re register
#define gc getchar()
int read()
{
	re int x(0),f(1);re char ch(gc);
	while(ch>'9'||ch<'0') {if(ch=='-')f=-1;ch=gc;}
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=gc;
	return x*f;
}

const int N=2e5+10;

int n,q,m;

struct line {int u,v,w;}e[N<<1];
bool operator < (line a,line b){return a.w<b.w;}
int f[N],v[N];
int find(int x){return x==f[x]?x:f[x]=find(f[x]);}
ll ans;

int main()
{
    n=read(),q=read();
    memset(v,127,sizeof(v));
    while(q--)
    {
        int a=read()+1,b=read()+1,c=read();
        e[++m]=(line){a,b,c};
        v[a%n+1]=min(v[a%n+1],c+1);
        v[b%n+1]=min(v[b%n+1],c+2);
    }
    int pos(1);
    for(int i=2;i<=n;++i)
        if(v[i]<v[pos])
            pos=i;
    for(int i=pos%n+1,j=pos;i!=pos;j=i,i=i%n+1)
        v[i]=min(v[i],v[j]+2);
    for(int i=2;i<=n;++i)
        e[++m]=(line){i-1,i,v[i]};
    e[++m]=(line){1,n,v[1]};
    sort(e+1,e+1+m);
    for(int i=1;i<=n;++i)
        f[i]=i;
    for(int i=1;i<=m;++i)
    {
        int u=find(e[i].u),v=find(e[i].v);
        if(u==v) continue;
        ans+=e[i].w;f[u]=v;
    }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 9600
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N = II()
	if(N % 2 == 0):
		print((N//2)/N)
	else:
		print(((N//2)+1)/N)

main()

Measured memory_bytes: 38512
#include <iostream>
#include <string>
#include <vector>
using namespace std;

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

    int cnt = 0;

    auto pos = S.find("ABC");
    while (pos != string::npos) {
        ++cnt;
        S = S.substr(pos+3);
        pos = S.find("ABC");
        bool check = true;
    }
    cout << cnt << endl;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<ll, ll>P;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void SAY(bool YES){cout<<(YES?"YES":"NO")<<endl;};
void Say(bool Yes){cout<<(Yes?"Yes":"No")<<endl;};

const ll MOD = 1000000007;

ll dp[10101];

int main(){

    ll N;
    cin >> N;
    dp[0] = 1;
    for(ll i = 0; i < N; i++){
        ll s;
        cin >> s;
        for(ll j = 10100; j >= 0; j--){
            ll pre = j - s;
            if(pre < 0)continue;
            if(dp[pre])dp[j] = 1;
        }
    }
    ll ans = 0;
    for(ll i = 1; i <= 10000; i++)if(dp[i] && i % 10)chmax(ans, i);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; ++i)
#define rep1(i,h) for(int i = 0; i <= h; ++i)
#define rep2(i,k,h) for(int i = k; i < h; ++i)
#define rep3(l,k,h) for(int l = k; l <= h; ++l)
#define INF LLong_MAX // long long INF
#define inf INT_MAX // int inf

typedef pair<int,int> int_pair;
typedef pair<string,string> string_pair;


int main() {
    int n,k = 0;
    cin >> n;
    vector<int>  a(n+1), b(n);
    rep(i,n+1) cin >> a.at(i);
    rep(i,n) cin >> b.at(i);
    ll ans = 0;
    rep(i,n) {
        ans += min(a.at(i), b.at(i));
        b.at(i) -= min(a.at(i), b.at(i));
        ans += min(a.at(i+1), b.at(i));
        a.at(i+1) -= min(a.at(i+1), b.at(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
llfor;ll ans=0;////////////////////////////////////////////////////////////
int main(){
 string s;
 cin>>s;
 ll n=s.length(),t[n+10]={0},ans=n;
 rrp(i,n,0){
  if(i<n-1)t[i]=t[i+1];
  if(s[i]=='T')t[i]++;
  if(s[i]=='S'&&t[i]!=0){
   ans-=2;
   t[i]--;
  }
 }
 pr(ans);
 return 0;}

Measured memory_bytes: 5252
import java.util.ArrayList;
import java.util.Scanner;

/**
 * Created by kosuke abe on 2014/10/29.
 */
public class Main {
    static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
        int N, Q;
        int[] date_info = new int[101];
        while(true){
            int result = 0;
            Fill(date_info, 0);

            N = scan.nextInt();
            Q = scan.nextInt();
            if(N == 0 && Q == 0){
                break;
            }
            Count(date_info, N);
            System.out.println(Result(date_info, result, Q));
        }
    }

    static void Fill(int[] list, int number){
        for(int i=0;i<101; i++){
            list[i] = number;
        }
    }

    static void Count(int[] list, int member){
        for(int i=0;i < member;i++){
            int day = scan.nextInt();
            for(int j=0; j<day;j++){
                list[scan.nextInt()] += 1;
            }
        }
    }

    static int Result(int[] list,int result,int min){
        for(int i=1;i<101;i++){
            if(list[i] >= min && list[i] > list[result]){
                result = i;
            }
        }
        return result;
    }
}

Measured memory_bytes: 61980
# https://atcoder.jp/contests/abc155/tasks/abc155_e
# DPで解き直してみる
# アイデアとしては以下
# F(n)をn円使ったときに使う紙幣の最小と定義
# 例えばF(36)→8,(サンプルの通り)、F(4)→4、F(6)→5
# F(23456)を考える
# F(23456)=min(F(2345)+6, F(2346)+4) となる
# ∵6をそのまま払うなら、桁上りは必要ないので2345を払う最小F(2345)を足せば良い。
# お釣り狙いならばとりあえず、10 - 6のお釣りの分をカウント。そして上位桁で多く払う分2346の最小F(2346)を足せば良い。

# ナイーブな実装

'''
def F(n: int):
    if n < 5:
        # 終了条件
        return n
    a, b = divmod(n, 10)
    ret = min(F(a) + b, F(a + 1) + (10 - b))
    # print(n, ret)
    return ret


print(F(int(input())))
'''
# しかしこれには不適切な実装が含まれている
# 1、再帰の深さが最大100000になる。再帰メモ化でもハッシュの衝突が起きたりして遅くなる可能性がある
# 2、int型を前提にした実装なので、10^100000の大きさの数字を扱おうとするとかなり遅くなる。
# よって上記の再帰関数をdpの形で書き直し、且つ文字列で扱える処理に変更する必要がある。


N = input()
# Nの先頭に0がついているとみたてて
dp0 = 0  # 桁上がりしない
dp1 = 1  # 桁上りするときに必要な紙幣の枚数

for n in N:
    n = int(n)
    dp0_new = min(dp0 + n, dp1 + (10 - n))
    n = n + 1
    dp1_new = min(dp0 + n, dp1 + (10 - n))
    dp0, dp1 = dp0_new, dp1_new

print(dp0)

Measured memory_bytes: 53028
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define F first
#define S second
#define mset(x,v) memset(x, v, sizeof(x))
#define left(x) 2*x
#define right(x) (2*x) + 1
#define ALL(t) (t).begin(),(t).end() 
#define ret return 0
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define rev(s) reverse(s.begin(),s.end())
#define WL(t) while(t --)
int main()
{
               boost;
               cout<<fixed;
               cout<<setprecision(5);
               
               int n;string s;
               cin>>n;
               
               long double ans=0.0;
               long double x;
               for(int i=0;i<n;i++)
               {
                     cin>>x>>s;
                     //cout<<(double)x<<" "<<s<<endl;
                     
                     if(s=="JPY")
                     ans=(ans+(x*1.0));
                     else if(s=="BTC")
                     {
                           ans=(ans+(x*380000*1.0));
                     }
               }
               cout<<(double)ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

ll N;
int cnt = 0;

void dfs(ll cur) {
    if (cur > N) return;

    vector<bool> use(3, false);
    string num = to_string(cur);
    int n = num.size();
    for (int i = 0; i < n; i++) {
        if (num[i] == '3') use[0] = true;
        if (num[i] == '5') use[1] = true;
        if (num[i] == '7') use[2] = true;
    }
    if (use[0] && use[1] && use[2]) cnt++;

    dfs(cur * 10 + 3);
    dfs(cur * 10 + 5);
    dfs(cur * 10 + 7);
}

int main() {
    cin >> N;
    dfs(0);
    cout << cnt << endl;
    return 0;
}

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

ll gcd(ll a, ll b){

  if(b>a){swap(a,b);}
  if(b==0){return a;}
  gcd(b,a%b);
}
int main(){
  int k;
  ll ans=0;
  cin>>k;
  rep(i,k){
    rep(j,k){
      ll tmp=gcd(i+1,j+1);
      rep(t,k){
        ans+=gcd(tmp,t+1);
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n, m, s, t;
    cin >> n >> m >> s >> t;
    s--, t--;
    vector<vector<ll>> g(n);
    REP(i, m) {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<vector<ll>> dist(n, vector<ll>(2, INF));
    dist[s][0] = 0;
    using P = pair<ll,PII>;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, {s, 0}});
    while(que.size()) {
        auto p = que.top(); que.pop();
        ll v = p.second.first, f = p.second.second;
        for(auto to: g[v]) {
            if(dist[to][1-f] > dist[v][f] + 1) {
                dist[to][1-f] = dist[v][f] + 1;
                que.push({dist[to][1-f], {to, 1-f}});
            }
        }
    }

    if(dist[t][0] == 2) cout << 2 << endl;
    else if(dist[t][1] == INF) cout << -1 << endl;
    else {
        // dist[t][1] 以上で最小の素数
        vector<bool> isprime(200001, true);
        isprime[0] = isprime[1] = false;
        for(ll i=2; i<=200000; ++i) {
            if(!isprime[i]) continue;
            for(ll j=2*i; j<=200000; j+=i) {
                isprime[j] = false;
            }
        }

        for(ll i=dist[t][1]; i<=200000; i+=2) {
            if(isprime[i]) {
                cout << i << endl;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 14344
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <assert.h>
     
using namespace std;
     
typedef long long ll;
     
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
     
#define MOD 1000000007

int main(){
  ll n;
  cin>>n;
  vector<ll> v;
  rep(i,0,n){
    ll a;
    cin>>a;
    v.pb(a);
  }
  ll e = 1000;
  rep(i,0,n-1){
    if(v[i]<v[i+1]){
      ll a = e/v[i];
      e -= a*v[i];
      e += a*v[i+1];
    }
  }
  cout << e << endl;
  return 0;
}

Measured memory_bytes: 3628
/*---------------------------------------------
				Author:TanYz
---------------------------------------------*/
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <string>
#include <cmath>
#include <map>
#include <stack>
#include <ctime>
#include <set>
#include <vector>
#include <cstdlib>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define mpii(a,b) make_pair(a,b)
const int INF=1<<30;
const int maxn=2333333;
const int mod=1000000007;

int x;

int main()
{
	//freopen("tan_in.txt","r",stdin);
	//freopen("tan_out.txt","w",stdout);
	cin>>x;
	if(x<1200)puts("ABC");
	else puts("ARC");
	return 0;
}





Measured memory_bytes: 256
import java.util.Scanner;

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

		int sum1 = 0, sum2 = 0;
		for (int i = 0; i < M; i++) {
			A[i] = sc.nextInt();
			if (A[i] > X) {
				sum1++;
			} else if (A[i] < X) {
				sum2++;
			}
		}
		sc.close();
		System.out.println(Math.min(sum1, sum2));
	}
}


Measured memory_bytes: 23636
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();
        int ans = 0;
        ans += n*(n-1)/2;
        ans += m*(m-1)/2;
        System.out.println(ans);
     }
}

Measured memory_bytes: 22996
N, C = map(int, input().split())
d = [list(map(int, input().split())) for _ in range(C)]
c = [list(map(int, input().split())) for _ in range(N)]

init_colors = [[], [], []]
for i in range(N):
    for j in range(N):
        init_colors[(i + 1 + j + 1) % 3].append(c[i][j])

iwakan_all = []
for i in range(3):
    _init_colors = init_colors[i]
    _iwakan = []

    for target in range(C):

        iwakan = 0
        for j in range(len(_init_colors)):
            iwakan += d[_init_colors[j] - 1][target - 1]

        _iwakan.append(iwakan)

    iwakan_all.append(_iwakan)


res = float('inf')
for i in range(C):
    tmp1 = iwakan_all[0][i]
    for j in range(C):
        if j != i:
            tmp2 = iwakan_all[1][j]
            for k in range(C):
                if k != i and k != j:
                    tmp3 = iwakan_all[2][k]
                    res = min(res, tmp1 + tmp2 + tmp3)

print(res)


Measured memory_bytes: 56028
#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;

struct bar{
	int bar1;
	int bar2;
};

int main(){
	int n, m, a;
	while (1){
		cin >> n >> m >> a;
		if (n == 0 && m == 0 && a == 0) break;
		map<int, vector<bar>> mp;
		for (int i = 0; i < m; i++){
			int h, p, q;
			cin >> h >> p >> q;
			bar barx = { p, q };
			mp[h].push_back(barx);
		}
		int nowbar = a;
		for (map<int, vector<bar>>::reverse_iterator i = mp.rbegin(); i != mp.rend(); i++){
			for (auto j: i->second){
				if (j.bar1 == nowbar){
					nowbar = j.bar2;
				}
				else if (j.bar2 == nowbar){
					nowbar = j.bar1;
				}
			}
		}
		cout << nowbar << endl;
	}

	return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
  ll n;cin>>n;
  vector<ll>sum(n+1,0);
  for(int i=1;i <= n;i++)
  {
    sum[i]=sum[i-1]+i;
  }

  ll itr=lower_bound(all(sum),n)-sum.begin();

  for(int i=1;i <=itr ;i++)
  {
    if(i==sum[itr]-n)continue;
    else cout<<i<<endl;
  }
}

Measured memory_bytes: 78336
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

static const ll MAX = 200002;
ll pos[MAX] = {};

int main() {
    
    ll n;
    cin >> n;
    vector <ll> v;
    for (ll i=0;i<n;i++){
        ll p;
        cin >> p;
        v.push_back(p);
        pos[p] = i;
    }
    ll tmp = 0;
    ll maxv = 0;
    for (ll i=1;i<=n;i++){
        if(pos[i-1] < pos[i]){
            tmp++;
        }else{
            tmp = 1;
        }
        if(maxv < tmp){
            maxv = tmp;
        }
    }
    cout << n - maxv << endl;
}




Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
const int N = 1e3 + 5;
typedef long long int ll;

int main() {
    IOS ;
    // int t ; cin >> t ; while(t--) {}
    int x ; cin >> x ; 
    if(x < 30) cout << "No" ;
    else cout << "Yes" ;
    return 0 ;
}


Measured memory_bytes: 3648
import Data.List

main :: IO ()
main = do
    s <- getLine
    print $ solve s

solve :: String -> Int
solve l = fst $ foldr plus (0, 0) $ map ( roundup . mul2q . divMod3 . length ) $ group l
    where
        divMod3 = flip divMod 3     -- 3で除して商と剰余を求める
        mul2q   (q, r) = (2 * q, r) -- 商を2倍する
        roundup (q, 0) = (q,     0) -- 剰余が0以外のとき商に1加算する
        roundup (q, r) = (q + 1, r)
        plus (q1, 2) (q2, 2) = (q1 + q2 + 1, 0) -- 隣接する要素の剰余がいずれも2のとき商の合計に1加算する
        plus (q1, 2) (q2, 0) = (q1 + q2,     2) -- 隣接する要素の剰余が2と0のとき剰余2を返す
        plus (q1, 0) (q2, 2) = (q1 + q2,     2) -- 隣接する要素の剰余が0と2のとき剰余2を返す
        plus (q1, _) (q2, _) = (q1 + q2,     0)


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

typedef pair<long long, long long> P;
int INF = 2'000'000'000;

int main(){
    int n, w;
    cin >> n >> w;
    vector<long long> ans(100'001, INF);
    ans[0] = 0;
    int x, y;
    queue<P> que;
    for (int i = 0; i < n; i++){
        cin >> x >> y;
        for (int j = 0; j <= 100'001; j++){
            if (j + y > 100'001) break;
            if (ans[j] + x <= w) que.push({y + j, min(ans[y + j], ans[j] + x)});
        }
        while (que.size()){
            ans[que.front().first] = que.front().second;
            que.pop();
        }
    }
    for (int i = 100'000; i >= 0; i--){
        if (ans[i] <= w){
            cout << i << endl;
            exit(0);
        }
    }
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,ans=0;
	long long d,x,y;
	cin>>n>>d;
	for(int i=1;i<=n;i++){
	    cin>>x>>y;
	    if(x*x+y*y<=d*d)ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3620
from heapq import heapify,heappop,heappush
import sys
input=sys.stdin.readline
N,M=map(int,input().split())
S,T=map(int,input().split())
Graph=[set() for i in range(N)]
Edge=[]
mod=10**9+7
inf=float("inf")
for i in range(M):
  a,b,c=map(int,input().split())
  Graph[a-1].add((c,b-1))
  Graph[b-1].add((c,a-1))
  Edge.append((a-1,b-1,c))
  Edge.append((b-1,a-1,c))
def dijkstra(s,n,links):
  Visited=[False]*n
  cost=[inf]*n
  P=[0]*n
  P[s]=1
  cost[s]=0
  heap=[(0,s)]
  heapify(heap)
  while heap:
    hc,hp=heappop(heap)
    if Visited[hp]:
      continue
    Visited[hp]=True
    for c,p in links[hp]:
      if Visited[p]:
        continue
      if c+hc<cost[p]:
        cost[p]=c+hc
        P[p]=P[hp]
        heappush(heap,(cost[p],p))
      elif c+hc==cost[p]:
        P[p]=(P[p]+P[hp])%mod
  return cost,P

def dp(s,n,links,d):
  Visited=[False]*n
  cost=[inf]*n
  P=[0]*n
  P[s]=1
  cost[s]=0
  heap=[(0,s)]
  heapify(heap)
  while heap:
    hc,hp=heappop(heap)
    if 2*hc>d:
      break
    if Visited[hp]:
      continue
    Visited[hp]=True
    for c,p in links[hp]:
      if Visited[p]:
        continue
      if c+hc<cost[p]:
        cost[p]=c+hc
        P[p]=P[hp]
        heappush(heap,(cost[p],p))
      elif c+hc==cost[p]:
        P[p]=(P[p]+P[hp])%mod
  return cost,P

cost_S,P_S=dijkstra(S-1,N,Graph)
D=cost_S[T-1]
cost_T,P_T=dp(T-1,N,Graph,D)
Pat=P_S[T-1]
ans=(Pat**2)%mod
for a,b,c in Edge:
  if cost_S[a]+cost_T[b]+c==D:
    if 2*cost_S[a]<D and 2*cost_T[b]<D:
      ans-=((P_S[a]*P_T[b])**2)%mod
for i in range(N):
  if 2*cost_S[i]==2*cost_T[i]==D:
    ans-=((P_S[i]*P_T[i])**2)%mod
print(ans%mod)



      
  
  
  
  


Measured memory_bytes: 143472
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 200005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

typedef pair<ll,int> LP;
struct TreeMST {
  int n;
  vi S;
  vvi to, co;
  TreeMST(int n):n(n),to(n),co(n) {}
  void add(int a, int b, int c) {
    to[a].pb(b); co[a].pb(c);
    to[b].pb(a); co[b].pb(c);
  }
  void addS(int v) { S.pb(v);}
  ll solve() {
    ll res = 0;
    PQ(LP) q;
    vl dist(n,LINF);
    vi cnt(n);
    for (int v : S) {
      dist[v] = 0; cnt[v] = 1;
      q.push(LP(0,v));
    }
    while (sz(q)) {
      ll d = q.top().fi;
      int v = q.top().se; q.pop();
      if (dist[v] != d) continue;
      res += dist[v]*(cnt[v]-2);
      cnt[v] = -1;
      rep(i,sz(to[v])) {
        int u = to[v][i];
        if (cnt[u] == -1) continue;
        ll nd = d+co[v][i];
        cnt[u]++; res += nd;
        if (dist[u] <= nd) continue;
        dist[u] = nd;
        q.push(LP(nd,u));
      }
    }
    return res;
  }
};

int main() {
  int n;
  scanf("%d",&n);
  TreeMST g(n*2);
  rep(i,n) g.addS(i+n);
  rep(i,n) {
    int x;
    scanf("%d",&x);
    g.add(i,i+n,x);
  }
  rep(i,n-1) {
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    --a; --b;
    g.add(a,b,c);
  }
  cout<<g.solve()<<endl;
  return 0;
}






















Measured memory_bytes: 61804
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>


using std::cout;
using std::cin;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


ll gcd(ll a, ll b) {
    while (b != 0) {
        auto tmp = a;
        a = b;
        b = tmp % a;
    }
    return a;
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

int isPrime(int a) {
    for (int i = 2; i * i <= a; ++i) {
        if (a % i == 0) {
            return 0;
        }
    }
    return 1;
}




void oneCase () {
    ll n, m;
    cin >> n >> m;
    ll res = min(n, m / 2);
    n -= res;
    m -= res * 2;
    res += m / 4;

    cout << res << "\n";
}





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

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            B.GoldenApple();
        }
    }

    class B
    {
        public static void GoldenApple()
        {
            int[] num = Input.getIntArray();
            decimal n = num[0];
            decimal d = num[1];
            int human = 0;

            // ++ * ++ ++ * ++ ++ * ++
            
            human = decimal.ToInt32(Math.Ceiling(n / (d + d + 1)));
            Output.writeInt(human);
        }

    }
  
    class Input
    {
        public static int getInt()
        {
            int i = int.Parse(Console.ReadLine());
            return i;
        }

        public static string getString()
        {
            string s = Console.ReadLine();
            return s;
        }
        public static int[] getIntArray()
        {
            string[] s = Console.ReadLine().Split(' ');
            int[] num = s.Select(x=>int.Parse(x)).ToArray();
            return num;
        }
    }

    class Output
    {
        public static void writeInt(int i)
        {
            Console.WriteLine(i);
        }
    }
}


Measured memory_bytes: 13396
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <cstdio>
#define INF 1000000000000
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;
using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  ll a[n];
  REP(i, n) cin >> a[i];
  vector<int> g[n];
  REP(i, m){
    int s, t;
    cin >> s >> t;
    g[s].pb(t);
    g[t].pb(s);
  }
  int b[n] = { };
  int c = 1;
  REP(i, n){
    if(b[i] == 0){
      queue<int> q;
      b[i] = c;
      q.push(i);
      while(q.size()){
        int f = q.front();
        q.pop();
        for(int e: g[f]){
          if(b[e] == 0){
            b[e] = c;
            q.push(e);
          }
        }
      }
      c++;
    }
  }
  priority_queue<ll, vector<ll>, greater<ll>> cost[n-m];
  REP(i, n){
    cost[b[i]-1].push(a[i]);
  }
  if((n-m-1) > (n/2)) cout << "Impossible" << endl;
  else if((n-m) == 1) cout << 0 << endl;
  else{
    ll ans = 0;
        REP(i, n-m){
          if(cost[i].size()){
          ans += cost[i].top();
          cost[i].pop();
          }
        }
    priority_queue<ll, vector<ll>, greater<ll>> last;
    REP(i, n-m){
      while(cost[i].size()){
        last.push(cost[i].top());
        cost[i].pop();
      }
    }
    REP(i, n-m-2){
      ans += last.top();
      last.pop();
    }
    cout << ans << endl;
  }
  return 0;
}


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

using namespace std;

int main(void)
{
    long long a,b,c;
    cin>>a>>b>>c;
    if(c-a-b<=0) cout<<"No\n";
    else if(4*a*b < (c-a-b)*(c-a-b)) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int now,sum;
	while(cin>>now,now!=-1){
		sum=1150;
		now-=10;
		if(now>0){
			sum+=(now*125);
			now-=10;
		}
		if(now>0){
			sum+=(now*15);
			now-=10;
		}
		if(now>0){
			sum+=(now*20);
		}
		cout<<4280-sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
# python template for atcoder1
import sys

N, A, B, C, D = map(lambda x: int(x)-1, input().split())
L = input()

reachable = True
if "##" in L[A:C+1] or "##" in L[B:D+1]:
    reachable = False

if not reachable:
    print("No")
elif C < D:
    print("Yes")
else:
    if "..." in L[B-1:D+2]:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<long long>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
int MOD=1e9+7;
int INF=1e9+7;
//
int main(){
  string S;
  cin>>S;
  int N=0,W=0,E=0,s=0;
  FOR(i,0,(int)S.size()){
    if(S[i]=='N'){
      N++;
    }else if(S[i]=='E'){
      E++;
    }else if(S[i]=='W'){
      W++;
    }else if(S[i]=='S'){
      s++;
    }
  }
  if((N&&s==0)||(s&&N==0)||(E&&W==0)||(W&&E==0)){
    Yes(0);
  }else{
    Yes(1);
  }
  return 0;
}


Measured memory_bytes: 256
P=[1,10,9,12,3,4]
m=10**9+7
def f(A,p,N):
    if p==0:return [1&(i in N) for i in range(13)]
    p%=6
    B=[0]*13
    for n in N:
        for i in range(13):
            c=(i+(n*P[p]))%13
            B[c]=(B[c]+A[i])%m
    return B

S=reversed(input())
A=[0]
for p,s in enumerate(S):
    if s=="?":A=f(A,p,range(10))
    else:A=f(A,p,[int(s)])
print(A[5])

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


def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))

    cb = [None]*m
    for i in range(m):
        b, c = map(int, input().split())
        cb[i] = (c, b)

    cb.sort(reverse=True)
    add = []
    count = 0

    for c, b in cb:
        add += [c]*b
        count += b
        if count >= n:
            break

    a += add
    a.sort(reverse=True)
    print(sum(a[:n]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 23828
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;


int main(){
    fast_io
    
    int n,k;
    cin>>n>>k;
    vector<int> d(k);
    vector<int> snuke(n, 0);
    rep(i,k){
        cin>>d[i];
        vector<int> A(d[i]);
        rep(j,d[i]) {
            cin>>A[j];
            snuke[A[j]-1]++;
        }
    }
    int ans=0;
    rep(i,n){
        if(snuke[i]==0) ans++;
    }
    cout<<ans<<endl;

    
    return 0;
}

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

int main() {
    int s = 1000001;
    int l = -1000001;
    int n; cin >> n;
    long int sum = 0;
    
    for(int i=0; i<n; i++) {
        int a=0; cin >> a;
        s = min(a, s);
        l = max(a, l);
        sum += a;
    }
    cout << s << " " << l << " " << sum << endl;
    
    return 0;
}


Measured memory_bytes: 3132
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define LL long long
using namespace std;
const LL Maxn = 100010;
LL a[Maxn], val[Maxn], sum1[Maxn], sum2[Maxn];
LL n, C;
LL seg1[Maxn<<2], seg2[Maxn<<2];
LL _max(LL x, LL y) { return x > y ? x : y; }
void build_tree(LL now, LL L, LL R) {
	if(L < R){
		LL mid = L+R>>1, lc = now<<1, rc = now<<1|1;
		build_tree(lc, L, mid);
		build_tree(rc, mid+1, R);
		seg1[now] = _max(seg1[lc], seg1[rc]);
		seg2[now] = _max(seg2[lc], seg2[rc]);
	} else { seg1[now] = sum1[L], seg2[now] = sum2[L]; }
}
LL qry1(LL now, LL L, LL R, LL l, LL r) {
	if(l > r) return 0;
	if(L == l && R == r) return seg1[now];
	LL mid = L+R>>1, lc = now<<1, rc = now<<1|1;
	if(r <= mid) return qry1(lc, L, mid, l, r);
	else if(l > mid) return qry1(rc, mid+1, R, l, r);
	else return _max(qry1(lc, L, mid, l, mid), qry1(rc, mid+1, R, mid+1, r));
}
LL qry2(LL now, LL L, LL R, LL l, LL r) {
	if(l > r) return 0;
	if(L == l && R == r) return seg2[now];
	LL mid = L+R>>1, lc = now<<1, rc = now<<1|1;
	if(r <= mid) return qry2(lc, L, mid, l, r);
	else if(l > mid) return qry2(rc, mid+1, R, l, r);
	else return _max(qry2(lc, L, mid, l, mid), qry2(rc, mid+1, R, mid+1, r));
}
int main() {
	LL i, j, k;
	scanf("%lld%lld", &n, &C);
	for(i = 1; i <= n; i++) scanf("%lld%lld", &a[i], &val[i]);
	a[n+1] = C;
	for(i = n; i >= 1; i--) sum1[i] = sum1[i+1]+val[i]-(a[i+1]-a[i]), sum2[i] = sum2[i+1]+val[i]-2*(a[i+1]-a[i]);
	build_tree(1, 1, n);
	LL ans = _max(qry1(1, 1, n, 1, n), 0), sv = 0;
	for(i = 1; i <= n; i++){
		LL x = lower_bound(a+1, a+n+1, C-a[i]) - a;
		x = _max(x, i+1);
		sv += val[i];
		ans = _max(ans, _max(sv-2*a[i]+qry1(1, 1, n, i+1, x-1), sv-a[i]+_max(qry2(1, 1, n, x, n), 0)));
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define dbug(x) cout<<#x<<"="<<x<<endl
#define m0(x) memset(x,0,sizeof(x))
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef long long ll;
typedef pair<ll, ll> pl;

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  return is;
}

int main(){

  string S;
  cin >> S;
  bool ans=false;
  if(S[0]==S[1]){
    if(S[2]==S[3]&&S[1]!=S[2]){
      ans=true;
    }
  }
  else{
    if((S[0]==S[2]&&S[1]==S[3])||(S[0]==S[3]&&S[1]==S[2]))ans= true;
  }

  cout << ( ans==true ? "Yes" : "No") <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int h, w;
    cin >> h >> w;
    vs grid(h);
    rep(i, h) cin >> grid[i];
    
    vvi ans(h, vi(w, 0));
    rep(i, h) rep(j, w) {
        if (grid[i][j] == '#') {
            ans[i][j] = -1;
            continue;
        }
        rep(k, 8) {
            int ni = i + dy[k];
            int nj = j + dx[k];
            if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
            if (grid[ni][nj] == '#') ans[i][j]++;
        }
    }
    rep(i, h) {
        rep(j, w) {
            if (ans[i][j] == -1) cout << '#';
            else cout << ans[i][j];
        }
        cout << endl;
    }
}

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

int main() {

  int N,Ali = 0,Bob = 0;
  cin >> N;

  vector<int> a(N);

  for (int i=0 ; i < N ; i++)
    cin >> a.at(i);
  
  sort(a.begin(),a.end());
  
  for (int i = 0 ; i < N ; i++){
    
    if (i % 2 == 0)
      Ali += a.at(N - 1 - i);
    else
      Bob += a.at(N - 1 - i);

  }
  
  
  cout << Ali - Bob << endl;
  
}


Measured memory_bytes: 256
#include<cstdio>
#include <iostream>
#include<algorithm>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const static int MOD = 1000000007;
ull dp[105][4][2];

int main(){
	string S;
	cin >> S;
	int K;
	scanf("%d", &K);
	for (int i = 0; i <= K; ++i)
	{
		dp[0][i][0] = dp[0][i][1] = 0;
	}
	dp[0][0][0] = 1;
	for (int i = 1; i <= S.length(); ++i){
		for (int j = 0; j <= K; ++j){
			if(S[i - 1] == '0'){
				dp[i][j][0] = dp[i - 1][j][0];
				dp[i][j][1] = dp[i - 1][j][1];
				if(j > 0){
					dp[i][j][1] += 9*dp[i - 1][j - 1][1];
				}
			}else if(j > 0){
				dp[i][j][0] = dp[i - 1][j - 1][0];
				dp[i][j][1] = 9*dp[i - 1][j - 1][1] + dp[i - 1][j][0] + dp[i - 1][j][1] + (S[i - 1] - '1')*dp[i - 1][j - 1][0];
			}else{
				dp[i][j][0] = 0;
				dp[i][j][1] = dp[i - 1][j][0] + dp[i - 1][j][1];
			}
		}
	}
	printf("%llu\n", dp[S.length()][K][0] + dp[S.length()][K][1]);
	return 0;
}

Measured memory_bytes: 256