akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  string s;
  cin >> s;
  ll n = s.size();

  ll ans = 0;
  ll c = 0;
  if (n%2 == 1) c++;
  rep(i, n/2) {
    if (s[i] != s[n-1-i]) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
#define mod 1000000007
using namespace std;

int main(){
	int q;
	cin >> q;
	string X[q],Y[q];
	rep(i,0,q){
		cin >> X[i];
		cin >> Y[i];
	}

	rep(i,0,q){
		int m = X[i].length();
		int n = Y[i].length();
		int dp[m+1][n+1] = {};
		int maxl=0;
		rep(j,0,m){
			rep(k,0,n){
				if(X[i][j] == Y[i][k]) dp[j+1][k+1] = dp[j][k]+1;
				else dp[j+1][k+1] = max(dp[j][k+1],dp[j+1][k]);
			}
		}
		cout << dp[m][n] << endl;
	}
	return 0;
}



Measured memory_bytes: 7092
//==========================Head files==========================
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<iostream>
#include<map>
#define LL long long
#define db double
#define mp make_pair
#define pr pair<int, int>
#define fir first
#define sec second
#define pb push_back
#define ms(i, j) memset(i, j, sizeof i)
using namespace std;
//==========================Templates==========================
inline int read() {
    int x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
inline LL readl() {
    LL x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
int power(int a, int b) {
	int ans = 1;
	while (b) {
		if(b & 1) ans = ans * a;
		b >>= 1; a = a * a;
	}
	return ans;
}
int power_mod(int a, int b, int mod) {
	a %= mod;
	int ans = 1;
	while (b) {
		if(b & 1) ans = (ans * a) % mod;
		b >>= 1, a = (a * a) % mod;
	}
	return ans;
}
LL powerl(LL a, LL b) {
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = ans * a;
		b >>= 1ll;a = a * a;
	}
	return ans;
}
LL power_modl(LL a, LL b, LL mod) {
	a %= mod;
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = (ans * a) % mod;
		b >>= 1ll, a = (a * a) % mod;
	}
	return ans;
}
LL gcdl(LL a, LL b) {return b == 0 ? a : gcdl(b, a % b);}
LL abssl(LL a) {return a > 0 ? a : -a;}
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
int abss(int a) {return a > 0 ? a : -a;}
//==========================Main body==========================
#define LD "%I64d"
#define D "%d"
#define pt printf
#define sn scanf
#define pty printf("Yes\n")
#define ptn printf("No\n")
//==========================Code here==========================
LL n, a[100000 + 5];
int main() {
	cin >> n;
	for (LL i = 1; i <= n; ++i) scanf("%lld", &a[i]);
	a[1]--;
	for (LL i = 2; i <= n; ++i) if (a[i] > a[i - 1]) --a[i];
	for (LL i = 2; i <= n; ++i) if (a[i] < a[i - 1]) return ptn, 0;
	pty;
	return 0;
	
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#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, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'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'};
char moji2[26]={'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'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e18 + 3)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int x,y;
    cin >> x >> y;
    int syouhin[4];
    syouhin[1] = 300000;
    syouhin[2] = 200000;
    syouhin[3] = 100000;
    int ans = 0;
    if(x < 4) ans += syouhin[x];
    if(y < 4) ans += syouhin[y];
    if(x == 1 and y == 1){
        ans += 400000;
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int cnt=0;
  int MAX=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='A'||s[i]=='T'||s[i]=='G'||s[i]=='C'){
      cnt++;
      MAX=max(cnt,MAX);
    }else{
      cnt=0;
    }
  }
  cout<<MAX<<endl;
}

Measured memory_bytes: 256
# Graph I - Depth First Search
def dfs(idx,A):
    global time,d,f
    d[idx] = time
    time += 1
    for i,v in enumerate(A[idx]):
        if v == 1 and d[i] == 0:
            dfs(i,A)
    f[idx] = time
    time += 1

n = int(input())
A = []
for _ in range(n):
    ss = list(map(int, input().split()))
    u = ss[0] - 1
    row = [0 for _ in range(n)]
    for i in range(ss[1]):
        idx = 2 + i
        row[ss[idx]-1] = 1
    A.append(row)

time = 1
d = [0 for _ in range(n)]
f = [0 for _ in range(n)]
for i in range(n):
    if d[i] == 0:
        dfs(i,A)

for i,t in enumerate(zip(d,f)):
    print(i+1,t[0],t[1])


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

typedef signed long long ll;
const int MX = 1e5 + 5;
const int INF = 1e9 + 5;
int n, k, A[MX], dp[MX];

int solve(int pos) {
    if(pos >= n) return INF;
    if(pos == (n - 1)) return 0;
    if(dp[pos] != -1) return dp[pos];
    int ans = INF;
    for(int i = 1; i <= k; i++) {
        if(pos + i < n) {
            ans = min(ans, abs(A[pos] - A[pos + i]) + solve(pos + i));
        }
    }

    return dp[pos] = ans;
}

int main() {
    scanf("%d %d", &n, &k);

    for(int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
    memset(dp, -1, sizeof(dp));
    printf("%d\n", solve(0));
    return 0;
}

Measured memory_bytes: 5760
#include <stdio.h>
int main (void){
  int a,b,c,d;
  scanf("%d %d %d %d",&a,&b,&c,&d);
  if (b <= c || d <= a)
    printf("0\n");
  else if (b > c){
    if (c > a){
      if (d > b) 
	printf("%d\n",b - c);
      else
	printf("%d\n",d - c);
    }
    else {
      if (b > d)
	printf("%d\n",d - a);
      else
	printf("%d\n",b - a);
    }
  }
  else if (d > a){
    if (b > d){
      if (a > c)
	printf("%d\n",d - a);
      else
	printf("%d\n",d - c);
    }
    else {
      if (c > a)
	printf("%d\n",b - c);
      else
	printf("%d\n",b - a);
    }
  }
  return (0);
}


Measured memory_bytes: 128
import collections
def pf(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
  
n=int(input())
r=0
for c in range(1,n):
  ab=collections.Counter(pf(n-c))
  ab_l=list(ab.values())
  x=1
  for i in ab_l:
    x*=i+1
  r+=x
print(r)

Measured memory_bytes: 70972
//In the name of Allah
// #isart
#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define pii pair<int, int>
#define MP make_pair

using namespace std;

const int MAXN = 1e5 + 10, mod = 1e9 + 7;
ll dp[2][MAXN], fen[2][MAXN], s[MAXN];
bool is[2][MAXN];

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int n, mx1 = -1, mx2 = -1;
	ll a, b;
	cin >> n >> a >> b;
	for(int i = 0; i < n; i ++) cin >> s[i];
	for(int i = 1; i < n; i ++)
		if(s[i] - s[i - 1] < a) is[0][i] = 1;
	for(int i = 1; i < n; i ++)
		if(s[i] - s[i - 1] < b) is[1][i] = 1;
	for(int i = 0; i < n; i ++){
		int ind1 = upper_bound(s, s + n, s[i] - a) - s;
		int ind2 = upper_bound(s, s + n, s[i] - b) - s;
		//cout << i << ' ' << ind1 << ' ' << ind2 << ' ' << mx1 << ' ' << mx2 << endl;
		if(ind1 == 0){
			if(mx2 <= ind1)
				dp[0][i] = 1;
		}
		else if(ind1 == i)
			dp[0][i] = (dp[0][i - 1] + dp[1][i - 1]) % mod;
		else if(mx2 <= ind1)
			dp[0][i] = dp[1][ind1];
		if(ind2 == 0){
			if(mx1 <= ind2)
				dp[1][i] = 1;
		}
		else if(ind2 == i){
			dp[1][i] = (dp[0][i - 1] + dp[1][i - 1]) % mod;
		}
		else if(mx1 <= ind2)
			dp[1][i] = dp[0][ind2];
		if(is[0][i]) mx1 = i;
		if(is[1][i]) mx2 = i;
//		cout << i << " : " << dp[0][i] << ' ' << dp[1][i] << endl;
	} 
	ll ans = (dp[0][n - 1] + dp[1][n - 1]) % mod;
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 2816
#include <stdio.h>

int main (void)
{
    int i;
    int n;
    int a[100000] = {0};
    int count = 0; 

    scanf("%d",&n);

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

    for(i=0;i<n;i++){
        if(a[i] % 2 != 0)
            count++;
    }
    
    if(count % 2 == 0)
        printf("YES\n");
    else
        printf("NO\n");

    return 0;
    
}

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

int main() {
	string S;
	cin >> S;
	int cnt = 0;
	for (int i = 0; S[i + 1] != '\0'; ++i) {
		if (S[i] != S[i + 1])
			cnt++;
	}
	cout << cnt << endl;

	return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;


const int maxn = 1e6 + 5;


int n;
string s, t;


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

    cin>>s>>t;
    n = s.size();
    vector<vector<int>> ms(26), mt(26);
    for (int i=0; i<n; i++) {
	ms[s[i]-'a'].push_back(i);
	mt[t[i]-'a'].push_back(i);
    }

    sort(ms.begin(),ms.end());
    sort(mt.begin(),mt.end());

    cout<<(ms==mt ? "Yes\n" : "No\n");
    
    return 0;
}


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

int main() {
  long long int n,t,ans;
  cin>>n>>t;
  vector<int> a(n);
  ans=t*n;
  for(int i=0;i<n;i++){
    cin>>a.at(i);  
    if(i==0) continue;
    if(a.at(i)-a.at(i-1)<t) ans-=t-(a.at(i)-a.at(i-1));
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll;
ll n, a[100005], b[100005], p[100005], pp[100005];

ll cdq(ll l, ll r)
{
	if (l == r) return 0;
	ll mid = (l + r) / 2;
	ll ret = cdq(l, mid) + cdq(mid + 1, r);
	ll i = l;
	ll now = l - 1;
	for (ll j = mid + 1; j <= r; j++)	
	{
		while (p[i] <= p[j] && i <= mid)
		{
			pp[++now] = p[i];
			i++;
		}
		pp[++now] = p[j];
		if (i > mid) 
		{
			for (ll k = j + 1; k <= r; k++) pp[++now] = p[k];
			break;
		}
		ret += (mid - i + 1);
	}
	for (ll k = i; k <= mid; k++) pp[++now] = p[k];
	for (ll i = l; i <= r; i++) p[i] = pp[i];
	return ret;
}

ll erfen(ll l, ll r)
{
	memset(p, 0, sizeof(p));
	if (l == r) return l;
	ll mid = (l + r) / 2;
	ll rel = b[mid];
	for (ll i = 1; i <= n; i++)
	{
		p[i] = p[i - 1];
		if (a[i] > rel) p[i]++;
		else p[i]--;
	}
	ll num = cdq(0, n);
	if (num >= ((n + 1) * n / 2) / 2 + 1) return erfen(l, mid);
	else return erfen(mid + 1, r);
}

int main()
{
	cin >> n;
	for (ll i = 1; i <= n; i++) cin >> a[i], b[i] = a[i];
	sort (b + 1, b + n + 1);
	cout << b[erfen(1, n)] << endl;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=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 {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;  // 階乗と階乗の逆元
  combination(int n):fact(n+1),ifact(n+1) {  // 階乗と階乗の逆元を n まで求める
    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() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n, k;
  cin >> n >> k;

  mint ans(1);
  combination comb(2 * n);

  for (ll i = 1; i <= min(n-1 , k); i++) {
    ans += comb(n, i) * comb((n - i) + i - 1, i);
  }

  cout << ans.x << endl;

  return 0;
}


Measured memory_bytes: 6528
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
int main(){
    long long a,b,ans=0,i,j,last,fb,tp1,tp2;
    cin>>a>>b;
    ans=b-a+1;
    for(i=1;(1ll<<i)<=b;i++);
    i--;
    last=i;
    fb=b&(1ll<<i);
    for(j=i-1;j>=0;j--){
        if((b&(1ll<<j))==0){
            tp1=fb-(1ll<<last)+(1ll<<j+1);
            tp2=fb-(1ll<<last)+(1ll<<j);
            ans+=max(0ll,tp1-max(a,tp2));
        }
        else last=j;
        fb+=b&(1ll<<j);
        //cout<<j<<" "<<ans<<endl;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

ans = 0
prev = -1
for i in range(N):
  ans += B[A[i]-1]
  if A[i] == prev + 1:
    ans += C[prev-1]
  prev = A[i]
print(ans)

Measured memory_bytes: 38580
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int n,A,B,C;
vector<int> l;
int rec(int i, int a, int b, int c){
    if(i==n) {
        //少なくとも1本は選んでいる
        if(!a || !b || !c){ 
            return 1e9; 
        }
        return abs(a-A)+abs(b-B)+abs(c-C);
    }

    int res = rec(i+1, a, b, c);

    res = min(res, rec(i+1, a+l[i], b, c) + (a ? 10 : 0));
    res = min(res, rec(i+1, a, b+l[i], c) + (b ? 10 : 0));
    res = min(res, rec(i+1, a, b, c+l[i]) + (c ? 10 : 0));

    return res;
}
int main(){
    cin >> n >> A >> B >> C;
    l.resize(n);
    for(int i=0; i<n; i++) cin >> l[i];
    cout << rec(0,0,0,0) << endl;
    
}

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

using namespace std;

const int md = 1000000007;

inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}

inline int mul(int a, int b) {
  return (long long) a * b % md;
}

inline int power(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline int inv(int x) {
  return power(x, md - 2);
}

const int N = 1234567;

int fact[N], invfact[N];

inline int C(int n, int k) {
  if (k < 0 || k > n) return 0;
  return mul(fact[n], mul(invfact[k], invfact[n - k]));
}

int main() {
  fact[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = mul(fact[i - 1], i);
  }
  invfact[N - 1] = inv(fact[N - 1]);
  for (int i = N - 2; i >= 0; i--) {
    invfact[i] = mul(invfact[i + 1], i + 1);
  }
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  int ans = 0;
  int rb = 0, rc = 0;
  for (int sum = 0; sum <= b + c; sum++) {
    int coeff = mul(power(3, b + c - sum), fact[a + sum - 1]);
    int what = power(2, sum);
    if (sum > b) {
      add(rb, rb);
      add(rb, C(sum - 1, b));
      add(what, md - rb);
    }
    if (sum > c) {
      add(rc, rc);
      add(rc, C(sum - 1, c));
      add(what, md - rc);
    }
    what = mul(what, invfact[sum]);
    add(ans, mul(coeff, what));
  }
  printf("%d\n", mul(ans, invfact[a - 1]));
  return 0;
}


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

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

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let x = read::<i64>();
  println!("{}", x / 3);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = (a); i < (n); i++)
#define MP make_pair
#define all(s) (s).begin(), (s).end()
#define rev(s) (s).rbegin(), (s).rend()
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> P;

void test(){freopen("test.txt", "r", stdin);}

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

	vector<set<int> > boat(k);
	rep(i, k){
		int m;
		cin >> m;
		rep(j, m){
			int b;
			cin >> b;
			boat[i].insert(b);
		}
	}
	set<int> res;
	int r;
	cin >> r;
	rep(i, r){
		int p, q;
		cin >> p >> q;
		rep(j, k){
			if(boat[j].find(p) != boat[j].end() && boat[j].find(q) != boat[j].end()){
				res.insert(p);
				res.insert(q);
			}
		}
	}

	cout << res.size() << endl;

	
	return 0;
}

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

int main() {
  bool eye = false;
  int n, a, b, res = 0;
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> a >> b;
    if(a == b) {
      res++;
      if(res == 3) {
        eye = true;
        break;
      }
    } else res = 0;
  }
  if(eye) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3632
H, W = map(int,input().split())
A = [input() for _ in range(H)]

tmp = []
for a in zip(*A):
  if(a.count("#") > 0):
    tmp.append("".join(a))
tmp2 = []
for t in zip(*tmp):
  if(t.count("#") > 0):
    tmp2.append("".join(t))
print("\n".join(tmp2))

Measured memory_bytes: 3064
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

void precalc() {
}

int n, a, b;

string s;
int read() {
  if (scanf("%d%d%d", &n, &a, &b) < 3) {
    return 0;
  }
  cin >> s;
  return 1;
}

void solve() {
  int cnta = 0, cntb = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] != 'c') {
      if (cnta + cntb < a + b) {
        if (s[i] == 'a' || cntb < b) {
          printf("Yes\n");
          ++(s[i] == 'a' ? cnta : cntb);
          continue;
        }
      }
    }
    printf("No\n");
  }
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 896
#include <stdio.h>

int main(void)
{
    while(1){
        int n, r, p, c;
        scanf("%d %d", &n, &r);
        if(n == 0 && r == 0)
            break;
        int deck[51];
        int i;
        for(i = 1; i <= n; i++)
            deck[i] = i;

        for(i = 0; i < r; i++){
            scanf("%d %d", &p, &c);
            int j;
            int temp[51];
            for(j = 1; j <= n; j++)
                temp[j] = deck[j];
            for(j = n; j > n - p + 1; j--)
                deck[j - c] = temp[j];
            for(j = n - p + 1; j > n - (p - 1 + c); j--)
                deck[j + p - 1] = temp[j];
        }

        printf("%d\n", deck[n]);
    }

    return 0;
}

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

using namespace std;

int main()
{
    int n,y;
    cin >> n >> y;
    y=y/1000;
    int flag=0,X,Y;
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=n-i;j++)
        {
            if(9*i+4*j+n==y)
            {
                flag=1;
                X=i,Y=j;
                break;
            }
        }
    }
    if(flag)
    {
        cout << X << ' ' << Y << ' ' << (n-X-Y) << endl;
    }
    else
        printf("-1 -1 -1\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define int long long
signed main() {
	int n; cin >> n;
	double ans = 0;
	for (int i = 0; i < n; i++) {
		double p; string s; cin >> p >> s;
		if (s[0] == 'B')p *= 380000;
		ans += p;
	}
	printf("%.6f\n", ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <queue>
using namespace std;

typedef pair<string, int> P;

int bfs(string worm){
	queue<P> que;
	que.push(P(worm, 0));

	map<string, int> d;
	
	while(!que.empty()){
		P p = que.front();
		que.pop();

		//重複パターンはcontinue
		if(d[p.first]) continue;

		string str = p.first;

		//全色同じかどうかのチェック
		bool flag = false;
		for(int i=0;i<str.size()-1;i++){
			if(str[i] != str[i+1]){
				flag = true;
				break;
			}
		}
		//同じならreturn
		if(!flag) return p.second;

		//重複パターン判別用
		d[p.first] = p.second;

		for(int i=0;i<str.size()-1;i++){
			//隣り合わせで色が異なるとき
			if(str[i] != str[i+1]){
				char temp;
				string next;

				//tempに含まれない一色を代入
				if(str[i] != 'b' && str[i+1] != 'b'){
					temp = 'b';
				}else if(str[i] != 'g' && str[i+1] != 'g'){
					temp = 'g';
				}else{
					temp = 'r';
				}

				//変化後の順番をnextに詰め込む
				next = str;
				next[i] = next[i+1] = temp;

				//キューにプッシュ
				que.push(P(next, p.second+1));
			}
		}
	}
	return -1;
}

int main(){
	string worm;
	while(cin >> worm && worm != "0"){
		int ret = bfs(worm);
		if(ret>=0) cout << ret << endl;
		else cout << "NA" << endl;
	}
}

Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
typedef long long ll;
using namespace std;
#define int long long

//素数判定
inline bool IsPrime(int p) {
	if (p == 1) return false;
	for (int i = 2; i <= sqrt(p); i++) {
		if (p%i == 0) return false;
	}
	return true;
}

//10進数の自然数の桁数を返す
inline int GetDigit(int num) {
	return (int)log10(num) + 1;
}

//各位の和を返す
int GetDigitsSum(int num) {
	int N = 0;
	while (num > 0) {
		N += num % 10;
		num /= 10;
	}
	return N;
}

//互除法
ll gcd(ll a, ll b) {
	if (a < b) {
		return gcd(b, a);
	}
	else if (a%b) {
		return gcd(b, a%b);
	}
	else {
		return b;
	}
}

//異なるn個からr個の整数を取り出す組合せの数を求める
int combination(int n, int r) {
	if (r == 0 || n == r) {
		return 1;
	}
	else if (r == 1) {
		return n;
	}
	else {
		return combination(n - 1, r - 1) + combination(n - 1, r);
	}

}

//Ｏ(√n)
//素因数分解
map<int, int> prime_factor(int n) {
	map<int, int> res; // map[i]:=ｎを素因数分解したときiは何乗か。
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			while (n % i == 0) {
				res[i]++;
				n /= i;
			}
		}
	}
	if (n != 1)
		res[n] = 1;
	return res;
}

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

	int N;
	bool can;
	cin >> N;

	int Asum = 0, Bsum = 0;
	vector<int> A(N), B(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
		Asum += A[i];
	}
	for (int i = 0; i < N; i++)
	{
		int tmp;
		cin >> tmp;
		Bsum += tmp;
		B[i] = A[i]-tmp;
		//cout << "i:" << B[i] << endl;
	}

	if (Bsum > Asum) {
		can = false;
	}
	else { 
		can = true;
	}

	sort(B.begin(), B.end());

	int i = 0;
	int res = 0;
	int tmp = 0;
	int j = N - 1;
	while (1) {
		if (B[i] >= 0) {
			break;
		}
		//引けない
		if (B[i] + tmp < 0) {
			res++;
			tmp += B[j];
			j--;
		}
		//引く
		tmp += B[i];
		i++;
		res++;
	}

	if (can) {
		cout << res << endl;
	}
	else {
		cout << -1 << endl;
	}
	return 0;
}


Measured memory_bytes: 1792
N = int(input())
d = {}
for i in range(N):
    s = input()
    if s in d.keys():
        d[s] += 1
    else:
        d[s] = 1
M = int(input())
for i in range(M):
    t = input()
    if t in d.keys():
        d[t] -= 1
    else:
        d[t] = -1
print(max(max(d.values()),0))


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

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

	int x = n % 2 ? min(m / 2, a) : 0;
	int y = m % 2 ? min(n / 2, b) : 0;

	if (n % 2 && m % 2 ? a - x + b - y > (n / 2) * (m / 2) * 2 : (a - x + 1) / 2 + (b - y + 1) / 2 > (n / 2) * (m / 2))
	{
		cout << "NO" << endl;
		return 0;
	}

	bool corner = n % 2 && m % 2 && a - x + b - y == (n / 2) * (m / 2) * 2 && (a - x) % 2;
	if (corner)
	{
		a -= 1;
		b -= 1;
	}

	std::string res;
	res += "YES\n";

	const char cstr[3][4] = { "<>^", "^.v", "v<>" };

	int fa[2] = { a - x, a - x };
	int fb[2] = { b - y, b - y };
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			if (corner && n - i < 4 && m - j < 4)
			{
				res += cstr[3 - (n - i)][3 - (m - j)];
				if (i == n - 1 && j == m - 1)
				{
					x -= 1;
					y -= 1;
				}
			} else
			if (n % 2 && i == n - 1)
			{
				if (x)
				{
					res += (j % 2 ? '>' : '<');
					if (j % 2)
						x -= 1;
				}
				else
					res += '.';
			} else
			if (m % 2 && j == m - 1)
			{
				if (y)
				{
					res += (i % 2 ? 'v' : '^');
					if (i % 2)
						y -= 1;
				}
				else
					res += '.';
			} else
			if (fa[i % 2] > 1)
			{
				res += (j % 2 ? '>' : '<');
				if (j % 2)
					fa[i % 2] -= 2;
			} else
			if (fa[i % 2] == 1)
			{
				res += (i % 2 ? '.' : (j % 2 ? '>' : '<'));
				if (j % 2)
					fa[i % 2] -= 1;
			} else
			if (fb[i % 2] > 1)
			{
				res += (i % 2 ? 'v' : '^');
				if (j % 2)
					fb[i % 2] -= 2;
			}
			else
			if (fb[i % 2] == 1)
			{
				res += (j % 2 ? '.' : (i % 2 ? 'v' : '^'));
				if (j % 2)
					fb[i % 2] -= 1;
			} else
				res += '.';
		}
		res += '\n';
	}

	if (!x && !y && !fa[1] && !fb[1])
		cout << res;
	else
		cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 2308
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

void process(priority_queue<int64>& x1, priority_queue<int64>& x2, int& Z,
             int64& ans) {
  if (x1.size() > 0 && x2.size() > 0) {
    if (x1.top() >= x2.top()) {
      Z--;
      ans += x1.top();
      x1.pop();
    } else {
      Z--;
      ans += x2.top();
      x2.pop();
    }
  } else if (x1.size() == 0) {
    Z--;
    ans += x2.top();
    x2.pop();
  } else if (x2.size() == 0) {
    Z--;
    ans += x1.top();
    x1.pop();
  }
}

int main() {
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  priority_queue<int64> p, q, r;
  int64 tmp;
  for (int i = 0; i < A; i++) {
    cin >> tmp;
    p.push(tmp);
  }
  for (int i = 0; i < B; i++) {
    cin >> tmp;
    q.push(tmp);
  }
  for (int i = 0; i < C; i++) {
    cin >> tmp;
    r.push(tmp);
  }
  int64 ans = 0;
  priority_queue<int64, vector<int64>, greater<int64>> a_b;
  for (int i = 0; i < X; i++) {
    ans += p.top();
    a_b.push(p.top());
    p.pop();
  }
  for (int i = 0; i < Y; i++) {
    ans += q.top();
    a_b.push(q.top());
    q.pop();
  }
  debug(ans);
  while (1) {
    if (r.size() == 0) break;
    if (r.top() < a_b.top()) break;
    ans += r.top() - a_b.top();
    r.pop();
    a_b.pop();
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7692
#include <map>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define rep(i,a) for(int i=lst[a];i;i=nxt[i])
using namespace std;

int read() {
	char ch;
	for(ch=getchar();ch<'0'||ch>'9';ch=getchar());
	int x=ch-'0';
	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

const int N=2e5+5,inf=0x7fffffff;

map<int,int> e[N];
typedef map<int,int> :: iterator it;

int t[N<<1],nxt[N<<1],f[N<<1],lst[N],l;

void add(int x,int y,int z) {
	t[++l]=y;f[l]=z;nxt[l]=lst[x];lst[x]=l;
	t[++l]=x;f[l]=0;nxt[l]=lst[y];lst[y]=l;
}

int n,p[N],q[N],a[N],b[N],id,S,T;
int d[N],dis[N];

bool bfs() {
	fo(i,S,T) dis[i]=0;dis[S]=1;
	int i=0,j=1;d[1]=S;
	while (i<j) {
		rep(k,d[++i])
			if (f[k]&&!dis[t[k]]) {
				dis[t[k]]=dis[d[i]]+1;
				d[++j]=t[k];
			}
	}
	return dis[T];
}

int dinic(int x,int y) {
	if (x==T) return y;
	int now=0;
	rep(i,x)
		if (f[i]&&dis[t[i]]==dis[x]+1) {
			int k=dinic(t[i],min(y,f[i]));
			f[i]-=k;f[i^1]+=k;
			y-=k;now+=k;
			if (!y) break;
		}
	if (!now) dis[x]=-1;
	return now;
}

int main() {
	n=read();l=1;
	fo(i,1,n) p[i]=read()+1;
	fo(i,1,n) q[i]=read()+1;
	fo(i,1,n)
		if (!a[i]) {
			++id;int x=i;
			do {a[x]=id;x=p[x];} while (x!=i);
		}
	fo(i,1,n)
		if (!b[i]) {
			++id;int x=i;
			do {b[x]=id;x=q[x];} while (x!=i);
		}
	S=0;T=id+1;
	int ans=0;
	fo(i,1,n)
		if (p[i]==q[i]) {
			if (p[i]==i) continue;ans++;
			e[a[i]][b[i]]++;e[b[i]][a[i]]++;
		} else {
			ans++;
			if (i==p[i]) e[S][b[i]]++;
			else if (i==q[i]) e[a[i]][T]++;
			else e[a[i]][b[i]]++;
		}
	fo(x,S,T)
		for(it i=e[x].begin();i!=e[x].end();i++) {
			int y=i->first,z=i->second;
			add(x,y,z);
		}
	while (bfs()) ans-=dinic(S,inf);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 26496
#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>;

ll num_layer(int lvl) {
  return (1LL<<(lvl+2)) - 3;
}

ll num_patty(int lvl) {
  return (1LL<<(lvl+1)) - 1;
}

ll num_patty_eaten(int lvl, ll eat) {
  if (eat == 0) return 0;
  ll nlay = num_layer(lvl);
  if (eat == nlay) return num_patty(lvl);
  ll mid = (nlay + 1) / 2;
  if (eat < mid) return num_patty_eaten(lvl-1, eat-1);
  return num_patty(lvl-1) + 1 + num_patty_eaten(lvl-1, eat-mid);
}

int main() {
  int n;
  ll x;
  cin >> n >> x;
  ll ans = num_patty_eaten(n, x);
  cout << ans << endl;
  return 0;
}

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

bool prime ( int x ){
    bool flag = true;
    for ( int i = 2; i <= 1e5; ++i){
        if ( x % i == 0 ){
            flag = false;
        } else if ( i * i > x ){
            break;
        }
    }
    if ( x == 2 ){
        flag = true;
    }
    return flag;
}

int main(){
    int X;
    cin >> X;
    int ans;
    for ( int i = X; i <= 1e6; ++i ){
        bool flag = false;
        flag = prime(i);
        if ( flag ){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(n) for(int i=0;i<n;i++)
#define ll long long
ll mob=1000000007;
using namespace std;
int main()
{ string h;string j;
cin>>h;
cin>>j;
int r;
int b;
cin>>r>>b;
string y;
cin>>y;
if(y==h)
cout<<r-1<<" "<<b;
else
cout<<r<<" "<<b-1;








return 0;
}


Measured memory_bytes: 256
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	bb := make([]string, n*2)
	head := 0
	for i := 1; i <= n; i++ {
		a := getNextInt(scanner)
		if i%2 == 1 {
			bb[n-i/2] = fmt.Sprintf("%d", a)
			head = n - i/2
			continue
		}
		bb[n+i/2] = fmt.Sprintf("%d", a)
	}
	if n%2 == 0 {
		for i := 0; i < n/2; i++ {
			bb[head+i], bb[head+n-1-i] = bb[head+n-1-i], bb[head+i]
		}
	}
	fmt.Fprintln(writer, strings.Join(bb[head:head+n], " "))
	writer.Flush()
}


Measured memory_bytes: 19072
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;

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

  vector<int>dp(n+1,INF);
  queue<int>que;
  dp[n]=0;
  que.push(0);
  for(int i=n-1;i>=0;i--){
    while(1){
      if(que.empty()){
        cout<<-1<<endl;
        return(0);
      }
      else if(que.front()!=INF&&que.size()<=m){
        break;
      }
      que.pop();
    }
    if(s[i]=='0')dp[i]=que.front()+1;
    que.push(dp[i]);
  }

  vector<int>ans;
  int rest=dp[0],x=0;
  while(x<n){
    rest--;
    int i=1;
    while(rest!=dp[x+i])i++;
    ans.push_back(i);
    x+=i;
  }

  rep(i,ans.size()){
    cout<<ans[i];
    if(i+1==ans.size())cout<<endl;
    else cout<<' ';
  }

  return(0);
}


Measured memory_bytes: 1528
#include <iostream>
using namespace std;
int gcd(int a,int b){
    if(a%b)return gcd(b,a%b);
    else return b;
}
int main(){
    int a,b;
    while(cin>>a>>b){
        cout << gcd(a,b) << " " << a/gcd(a,b)*b << endl;
    }
}


Measured memory_bytes: 3016
use std::str::FromStr;
use std::io;
use std::cmp;

fn main() {

    let mut line = String::new();
    io::stdin().read_line(&mut line);
    let split : Vec<&str> = line.split(' ').collect();
    let X = i32::from_str(split[0].trim()).unwrap();
    let t = i32::from_str(split[1].trim()).unwrap();

    let result = cmp::max(X - t, 0);
    println!("{}", result);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define faster_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define md 1000000007

ll strsz,D,dp[100005][3][102];
string s,ss;

ll fnc(ll pos, ll is_choto, ll sum)
{
    if(pos == strsz) return 0;
    if(dp[pos][is_choto][sum] != -1) return dp[pos][is_choto][sum];

//    cout<<pos<<" "<<is_choto<<" "<<sum<<endl;

    ll low = 0;
    ll high = 9;

    if(!is_choto)high = (s[pos] - '0');
    ll ans = 0;
    for(ll i = low; i<=high; i++){
//        if((sum + i)%D == 0)cout<<sum+i<<endl;
        ans = (ans%md + (fnc(pos + 1, (is_choto | (i<high)), (sum + i) % D) % md + ((sum + i)%D == 0 && (sum + i)>0) % md)) % md;
    }
    return dp[pos][is_choto][sum] = ans;
}

int main()
{
    faster_io;

    ll n;

    cin>>s>>D;

    memset(dp, -1, sizeof dp);

    ll x=0;

    strsz = s.size();
    cout<<fnc(0,0,0)<<endl;

//    cout<<x<<endl;
    return 0;
}


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

int main(){
  int a,b;
  cin>>a>>b;
  int ans=0;
  if(a>=b){
    ans=ans+a;
    a--;
  }
  else{
    ans=ans+b;
    b--;
  }
  if(a>=b){
    ans=ans+a;
    a--;
  }
  else{
    ans=ans+b;
    b--;
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d,x;
  cin >> x;
  a=x/1000;
  b=(x-a*1000)/100;
  c=(x-a*1000-b*100)/10;
  d=(x-a*1000-b*100-c*10);
  if(a==b){
    if(b==c){cout << "Yes" << endl;}else{cout << "No" << endl;}
  } else {
    if(b==c&&c==d){cout << "Yes" << endl;}else{cout << "No" << endl;}
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int A,B,Q;
    cin >> A >> B >> Q;
    vector<int>s(A+2);
    vector<int>t(B+2);
    for(int i = 1; i <= A; i++) {
        cin >> s[i];
    }
    for(int i = 1; i <= B; i++) {
        cin >> t[i];
    }
    s[0] = -INF;t[0] = -INF;
    s[A+1] = INF;t[B+1] = INF;
    for(int i = 0; i < Q; i++) {
        int x;
        cin >> x;
        auto it1 = lower_bound(s.begin(),s.end(),x);
        auto it2 = lower_bound(t.begin(),t.end(),x);
        auto it3 = it1-1;
        auto it4 = it2-1;
        int ans = INF;
        ans = min(ans,max(s[it1-s.begin()],t[it2-t.begin()])-x);
        ans = min(ans,x-min(s[it3-s.begin()],t[it4-t.begin()]));
        ans = min(ans,min(x-s[it3-s.begin()]+t[it2-t.begin()]-s[it3-s.begin()],t[it2-t.begin()]-x+t[it2-t.begin()]-s[it3-s.begin()]));
        ans = min(ans,min(x-t[it4-t.begin()]+s[it1-s.begin()]-t[it4-t.begin()],s[it1-s.begin()]-x+s[it1-s.begin()]-t[it4-t.begin()]));
        cout << ans << endl;
    }
}

Measured memory_bytes: 4772
N,M = map(int, input().split())
ac = [0]*N
wa = [0]*N
for i in range(M):
	p,s = input().split()
	if s == 'AC':
		if ac[int(p) - 1] != 0:
			continue
		else:	
			ac[int(p) - 1] = 1
	else:
		if ac[int(p) - 1] != 0:
			continue
		else:
			wa[int(p) - 1] += 1
AC,WA = 0,0

for i in range(N):
  AC += ac[i]
  if ac[i] >= 1:
    WA += wa[i]
print(AC,WA)

Measured memory_bytes: 4596
inputX = int(input())
maxNumber = 1
if inputX <= 3:
    maxNumber = 1
else:
    for i in range(2, 33):
        if i== 2:
            for i1 in range(2, 10):
                if i ** i1 <= inputX:
                    if i ** i1 > maxNumber:
                        maxNumber = i ** i1
        elif i == 3:
            for i1 in range(2, 7):
                if i ** i1 <= inputX:
                    if i ** i1 > maxNumber:
                        maxNumber = i ** i1
        elif i <= 5:
            for i1 in range(2, 5):
                if i ** i1 <= inputX:
                    if i ** i1 > maxNumber:
                        maxNumber = i ** i1
        elif i <= 10:
            for i1 in range(2, 4):
                if i ** i1 <= inputX:
                    if i ** i1 > maxNumber:
                        maxNumber = i ** i1
        else:
            if i ** 2 <= inputX:
                if i ** 2 > maxNumber:
                    maxNumber = i ** 2


print (maxNumber)

Measured memory_bytes: 3064
# a = int(input())
# n, *a = map(int, open(0))
N, K = map(int, input().split())
A = list(map(int, input().split()))
# S = input()
A_memo = []
for i in range(N):
    tmp = [0, 0]
    for j in range(N):
        if A[i] > A[j]:
            if j < i:
                tmp[0] += 1
            else:
                tmp[1] += 1
    A_memo.append(tmp)

cnt = 0
for i in range(N):
    cnt += A_memo[i][0] * (K-1)*(K)//2 + A_memo[i][1] * (K+1)*(K)//2

print(int(cnt % 1000000007))

Measured memory_bytes: 3316
S = input()
if len(S)<5:
    print('NO')
else:
    while True:
        if len(S) == 0:
            print('YES')
            break
        if S[-5:] == 'dream':
            S = S[:-5]
        elif S[-7:] == 'dreamer':
            S = S[:-7]
        elif S[-5:] == 'erase':
            S = S[:-5]
        elif S[-6:] == 'eraser':
            S = S[:-6]
        else:
            print('NO')
            break

Measured memory_bytes: 3188
#include <stdio.h>
int n, s, count = 0, digits[10];
void dfs(int cur, int start) {
               if(cur == n) {
                  int sum = 0;
 for(int i = 0; i < n; i++) { sum += digits[i];
 }
     if(sum == s) { count++; }
     return;
 }
 for(int i = start; i < 10; i++) {
     digits[cur] = i; 
     dfs(cur+1, i+1);
   }
}

int main(void){
   while(scanf("%d %d",&n,&s)!= EOF){
       if(n == 0 && s == 0){
           break;
       }
       count = 0;
       dfs(0, 0);
       printf("%d\n", count);
   }

}



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

int main(int argc, char const *argv[])
{
	int n,k;
	while(~scanf("%d %d",&n,&k)){
		getchar();
		char arr[n+5];
		for (int i = 0; i < n; ++i)
		{
			scanf("%c",&arr[i]);
		}
		int a=0;
		for (int i = 1; i < n; ++i)
		{
			if (arr[i]==arr[i-1])
			{
				a++;
			}
		}
		printf("%d\n",min(n-1,a+2*k) );
	}
	return 0;
}

Measured memory_bytes: 384
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        p: [f64; n]
    };

    let mut dp = vec![vec![0.0; n + 1]; n + 1];

    // i: i枚目まで考慮する
    // j: 表になっている数
    dp[0][0] = 1.0;
    for i in 1..=n {
        for j in 0..=i {
            if j > 0 {
                dp[i][j] = dp[i - 1][j] * (1.0 - p[i - 1]) + dp[i - 1][j - 1] * p[i - 1]
            } else {
                dp[i][j] = dp[i - 1][j] * (1.0 - p[i - 1])
            }
        }
    }

    let mut sum = 0.0;
    for j in n / 2 + 1..=n {
        sum += dp[n][j];
    }

    println!("{}", sum);
}


Measured memory_bytes: 72520
N = int(input())
W = [input() for _ in range(N)]

if len(set(W)) != N:
  print('No')
  exit()
  
for i in range(1,N):
  b = W[i-1]
  a = W[i]
  if b[len(b)-1] != a[0]:
    print('No')
    exit()

print('Yes')

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    double r,pi,s,l;
    cin >> r;

    pi = 3.141592653589;

    s = r*r*pi;
    l = 2*r*pi;

    printf("%.8lf %.8lf\n",s,l);

    return 0;

}


Measured memory_bytes: 3272
<?php
ini_set('error_reporting', E_ALL & ~E_NOTICE);

$arr = array();

fscanf(STDIN, "%d", $N);
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%s", $s);
    $arr[$s]++;
}
fscanf(STDIN, "%d", $M);
for ($i = 0; $i < $M; $i++) {
    fscanf(STDIN, "%s", $t);
    $arr[$t]--;
}

echo max(max($arr), 0) . "\n";


Measured memory_bytes: 4728
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
 
#if DEBUG
    #include "debug.h"
#else
    #define debug(args...)
#endif    

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;


#define M 1000000 
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = INT_MAX;
const int mod = 1e9+7;

const int N = 2e5 + 10;
inline int add(int x,int y){
  x += y;
  if(x >= mod) x -= mod;
  return x;
}
inline int mul(int x,int y){
  x = (1LL * x * y) % mod;
  return x;
}
clock_t time_p=clock();
vector<int>A[3];
vector<ll>pref[3];
  int x,y,a,b,c;

ll f(int a, int b) {
  ll ans = 0;
  if(b > 0)
    ans += pref[0][b - 1];
  if(x - b + a > 0)
    ans += pref[2][x - b + a - 1];
  if(y - a > 0)
    ans += pref[1][y - a - 1];
  debug(a, b, ans);
  return ans;
}

int32_t main(){
  fast;

  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);

  cin >> x >> y >> a >> b >> c;

  FOR(i,1,a) {
    int x;
    cin >> x;
    A[0].pb(x);
  }
  FOR(i,1,b) {
    int x;
    cin >> x;
    A[1].pb(x);
  }
  FOR(i,1,c) {
    int x;
    cin >> x;
    A[2].pb(x);
  }    

  FOR(i,0,2) {
    sort(all(A[i]));
    reverse(all(A[i]));
    debug(A[i]);
    pref[i].pb(A[i][0]);
    ll sum = A[i][0];
    for(int j = 1; j < sz(A[i]); j++) {
      sum += A[i][j];
      pref[i].pb(sum);
    }
  }
  ll ans = 0;
  FOR(i,0,x) {
    if(c >= x - i) { // c - (x - i) remains
      int lo = 0, hi = min(y, c - x + i);
      while(lo < hi) {
          int mid = (lo + hi) >> 1;
          if(f(mid, i) > f(mid+1, i)) {
              hi = mid;
          }
          else {
              lo = mid+1;
          }
      }
      ans = max(ans, f(lo, i));
    }
  }

  cout << ans << "\n";

  time_p=clock()-time_p;
  cerr<<"\nTime Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";

  return 0;
}

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



//----- 値変換関数 -----//
int f_change(int);

int main(void)
{
	//入力回数
	int n = 0;
	//入力回数
	int random = 0;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cout << "Case" << " " << i + 1 << ":" << endl;
		//入力
		cin >> random;

		for (int j = 0; j < 10; j++)
		{
			random = f_change(random * random);
			cout << random << endl;
		}
	}

	return 0;
}


//*****----- 値変換関数 -----*****//

int f_change(int n)
{
	//変換文字列
	char str_change[9] = {NULL};//文字列初期化

	//割って文字列に格納する変数
	int h_waru[7] = {10000000 , 1000000 , 100000 , 10000 , 1000 , 100 , 10};

	//4桁分格納する変数
	int h_kakeru[4] = {1000 , 100 , 10 , 1};

	//割った値を順番に格納
	for (int i = 0; i < 7; i++)
	{
		str_change[i] = n / h_waru[i];
		n %= h_waru[i];
	}
	//8番目は直接
	str_change[7] = n;

	//nを一度初期化
	n = 0;

	for (int i = 0; i < 4; i++)
	{
		n += str_change[i + 2] * h_kakeru[i];
	}

	return n;
}

Measured memory_bytes: 1160