akhauriyash/Code-Regression huggingface dataset:
s = input()
n = len(s)
mod = 10**9+7
cnt = 0
dp = [[0 for i in range(4)] for j in range(n+1)]
dp[0][0] = 1
for i in range(1,n+1):
  if s[i-1] in "A?":
    dp[i][1] += dp[i-1][0]
  if s[i-1] in "B?":
    dp[i][2] += dp[i-1][1]
  if s[i-1] in "C?":
    dp[i][3] += dp[i-1][2]
  for j in range(4):
    if s[i-1] == "?":
      dp[i][j] += dp[i-1][j]*3
    else:
      dp[i][j] += dp[i-1][j]
    dp[i][j] %= mod
print(dp[-1][-1])

Measured memory_bytes: 55388
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")
#include"bits/stdc++.h"
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int long long
#define ends ' '
#define endl '\n'
#define pb emplace_back
#define x first
#define y second
#define pii pair<int, int>
#define sz(x) (int)(x).size()

int32_t main()
{
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif
	IOS;

	int n;
	
	cin >> n;

	int a[n+1] = {0};

	for(int i = 1; i <= n; ++i)
		cin >> a[i];

	int b[n+1] = {0};

	vector<int> ans;

	for(int i = n; i >= 1; i--)
	{
		// std::vector<int> fact;

		// for(int j = 1; j*j <= i; ++j)
		// {
		// 	if(i%j)
		// 		continue;
		// 	fact.pb(j);
		// 	if(i/j != j)
		// 		fact.pb(i/j);
		// }
		// sort(fact.begin(), fact.end(), greater<int>());

		// for(int i : fact)
		// {
		// 	if(b[])
		// }
		int temp = 0;

		for(int j = 2*i; j <= n; j += i)
			temp += b[j];

		if(temp%2 != a[i])
			b[i]++, ans.pb(i);
	}

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

	for(int i : ans)
		cout << i << ' ';

	return 0;
}

Measured memory_bytes: 5108
fun main(args: Array<String>) {
    val (N, A, B) = readLine()!!.split((" ")).map(String::toInt)

    var total = 0

    for(i in 1..N){
        var sum = i
        var ans = 0
        while(sum > 0){
            ans += sum % 10
            sum /= 10
        }

        if(ans in A..B){
            total += i
        }
    }
    println(total)

}


Measured memory_bytes: 37792
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    sorted_a = sorted(a)
    a_max = max(a)

    for ai in a:
        if ai == a_max:
            print(sorted_a[-2])
        else:
            print(sorted_a[-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 14088
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define pb push_back
const ll mod=1e9+7;
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
const ll N=1e5+8;
const ll INF=1e18;
int prime[N]={0};
ll a[300000]={0};
int main(){
  IOS;
  ll a,b,c,k;
  cin>>a>>b>>c>>k;
  while(b<=a){
    b*=2;
    k--;
  }
  if(k<0){
  cout<<"No";
  return 0;
  }
  while(c<=b){
    c*=2;
    k--;
  }
  if(k<0){
     cout<<"No";
     return 0;
  }
  else 
  {
    cout<<"Yes";
    return 0;
  }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
struct node
{
	int x,y,h;
}a[105];
bool cmp(node a,node b)
{
	return a.h>b.h;
}
int main()
{
	int n,cx,cy,i,H,tmp;
	bool flag=0;
	scanf("%d",&n);
	for(i=0;i<n;i++) scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].h);
	sort(a,a+n,cmp);
	for(cx=0;cx<=100;cx++) 
	{
		for(cy=0;cy<=100;cy++)
		{
			H=a[0].h+abs(a[0].x-cx)+abs(a[0].y-cy);
			for(i=1;i<n;i++)
			{
				tmp=max(H-abs(a[i].x-cx)-abs(a[i].y-cy),0);
				if(tmp!=a[i].h) break;
			}
			if(i==n) 
			{
				flag=1;
				break;
			}
		}
		if(flag) break;
	}
	printf("%d %d %d\n",cx,cy,H);
	return 0;
}

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

int     main()
{
    int N; cin >> N;
    char pre = ' ';
    int res = 0;
    while (N--)
    {   
        char a; cin >> a;
        if (pre != a)
        {   
            res++;
        }   
        pre = a;
    }   
    cout << res << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 27 20:57:32 2019

@author: Yamazaki Kenichi
"""

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

def eg(x,y):
    if y == 0:
        return x
    x, y = y, x%y
    return eg(x,y)

T = [[1,1,1] for i in range(N)]
T[0][0],T[0][1],T[0][2] = A[0], 0, 0
for i in range(1,N):
    T[i][0] = eg(T[i-1][0],A[i])
    T[i][1] = T[i-1][0]
    T[i][2] = max(eg(T[i-1][2],A[i]),eg(T[i-1][1],A[i]))
print(max(T[N-1]))



Measured memory_bytes: 17640
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cmath>
using namespace std;
#define I inline
#define R register
#define inf 1073742823
#define FOR(i,begin,end) for(R int i=begin;i<=end;++i)
#define ROF(i,begin,end) for(R int i=begin;i>=end;--i)
signed main(){
    int n;
    cin>>n;
    if(n&1)cout<<n/2+1;
    else cout<<n/2;
    return 0;
}

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=998244353
    A,B,C,D=MI()
    
    if A==C and B==D:
        print(1)
        exit()
    
    F=[[0]*(D+1) for _ in range(C+1)]
    
    def calc(a,b):
        temp=F[a][b-1]*a + F[a-1][b]*b - F[a-1][b-1]*(a-1)*(b-1)
        return temp%mod
    
    F[A][B]=1
    for i in range(A+1,C+1):
        F[i][B]=(F[i-1][B]*B)%mod
    for j in range(B+1,D+1):
        F[A][j]=(F[A][j-1]*A)%mod
    

    
    for i in range(A+1,C+1):
        for j in range(B+1,D+1):
            F[i][j]=calc(i,j)
            
 
    
    print(F[C][D])



    
    
 

main()


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

using namespace std;

typedef pair<int,int> ii;

#define X first
#define Y second

const int N=1e5+10;
const int inf=1e9+10;


int n;
int a[N];
vector <int> rem;

vector <int> v[N];
int h[N],q[N];

int BFS(int st){
        h[st]=1;
        int top=1,bot=1;
        q[1]=st;
        while (top<=bot){
                int x=q[top++];
                for(auto y:v[x]) if (!h[y]){
                        q[++bot]=y;
                        h[y]=1;
                }
        }
        int use=1;
        for(int i=1;i<=bot;i++) if (a[q[i]]<a[q[use]]) use=i;
        swap(q[use],q[1]);
        for(int i=2;i<=bot;i++) rem.push_back(a[q[i]]);
        return a[q[1]];
}

int main(){
        int m;
        cin>>n>>m;
        for(int i=1;i<=n;i++) cin>>a[i];
        while (m--){
                int x,y;
                cin>>x>>y;
                x++,y++;
                v[x].push_back(y);
                v[y].push_back(x);
        }
        int nc=0;
        long long ans=0;
        for(int st=1;st<=n;st++) if (!h[st]){
                ans+=BFS(st);
                nc++;
        }
        if (nc==1) ans=0;
        else {
                if (int(rem.size())<nc-2){
                        cout<<"Impossible";
                        return 0;
                }
                sort(rem.begin(),rem.end());
                for(int i=0;i<nc-2;i++) ans+=rem[i];
        }
        cout<<ans;
}


Measured memory_bytes: 7552
#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<string>
#include<unordered_map>
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,k
#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 sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/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;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
 ll a1,b1,c1,d1;
 sc(a1);sc(b1);sc(c1);sc(d1);
 ll a,b,c,d;
 if(a1<=c1){a=a1;b=b1;c=c1;d=d1;}
 else if(a1>c1){c=a1;d=b1;a=c1;b=d1;}
 if(b<=c)ans=0;
 else if(a<=c&&b<=d)ans=b-c;
 else if(c<=a&&b<=d)ans=b-a;
 else if(a<=c&&d<=b)ans=d-c;
 else if(c<=a&&d<=b)ans=d-a;
 pr(ans);
return 0;}

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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  if (a > b) {
    cout << 0 << endl;
  } else if (n == 1) {
    if (a == b) cout << 1 << endl;
    else cout << 0 << endl;
  } else if (n == 2) {
    cout << 1 << endl;
  } else {
    ll s_min = (n-1LL) * a + b;
    ll s_max = (n-1LL) * b + a;
    ll ans = s_max - s_min + 1;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>








const int N=2010;
int n,a[N],dp[4][N],mn,mx;




void solve()
{
	cin>>n>>a[1]>>a[2];
	n+=2;
	for(int i=3;i<=n;i++)cin>>a[i];
	dp[0][n]=abs(a[n]-a[n-1]);
	dp[1][n]=abs(a[n]-a[n-1]);
	mn=dp[0][n];
	mx=dp[1][n];
	for(int i=n-1;i>=3;i--)
	{
		dp[0][i]=max(mx,abs(a[n]-a[i-1]));
		dp[1][i]=min(mn,abs(a[n]-a[i-1]));
		mn=min(mn,dp[0][i]);
		mx=max(mx,dp[1][i]);
	}
	cout<<dp[0][3]<<"\n";
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = int(1e9 + 7);
int main() {
    char s[4];
    while (scanf("%s", s) != EOF)
        if (s[0] == s[1] && s[1] == s[2] || s[1] == s[2] && s[2] == s[3])
            puts("Yes");
        else puts("No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s;
	int n;
	cin >> n >> s;
	int ans = 0;
	for(int i = 0; i < n - 2; ++i) {
		if(s.substr(i, 3) == "ABC") {
			++ans;
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)

using namespace std;

int main(){
    long int a,b,n,k;
    long int i,j;
    vector<long int> v;
    map<long int,long int> map;
    cin>>n>>k;
    rep(i,0,n){
        cin>>a>>b;
        map[a]+=b;
    }
    for(auto m=map.begin();m!=map.end();m++){
        if(k>m->second){
            k-=m->second;
        }
        else{
            cout<<m->first<<endl;
            break;
        }
    }
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

ll gcd(ll a,ll b){
  if(a%b == 0){
    return b;
  }else{
    return gcd(b, a%b);
  }
}

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

int main(){

  ll n;
  cin >> n;
  ll a[n];
  for(ll i=0;i<n;i++)cin >> a[i];

  ll l=a[0];
  for(ll i=1;i<n;i++)l=gcd(l,a[i]);
  cout << l << endl;


}

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

using namespace std;

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

int main()
{
    int N;
    cin >> N;
    vector<ll> a(N), b(N), c(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> b[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> c[i];
    }

    sort(begin(a), end(a));
    sort(begin(b), end(b));
    sort(begin(c), end(c));

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ans += (lower_bound(begin(a), end(a), b[i]) - begin(a)) * (end(c) - upper_bound(begin(c), end(c), b[i]));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<sstream>
#include<queue>
#include<deque>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007
#define pb push_back

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
int main() {
	while(1) {
		string str; cin >> str;
		if (str == "#") break;
		
		vector<string> d;
		for (int i = 0; str.size() != 0; i++) {
			if (str[0] == 'n') {
				d.pb(str.substr(0,5));
				str = str.substr(5,str.size()-1);
			}else{
				d.pb(str.substr(0,4));
				str = str.substr(4,str.size()-1);
			}
		}


		int denominator; //??????
		denominator = pow(2,d.size()-1);
		int  numerator; //??????
		numerator = 90 * denominator;
		int ans_d;
		int ans_n;
		reverse(d.begin(),d.end());
		if (d[0] == "north") {
			ans_d = denominator;
			ans_n = 0;
		}else{
			ans_d = denominator;
			ans_n = numerator;
		}
		if (d.size() == 1) {
			int ans;
			if (d[0] == "north") {
				ans = 0;
			}else{
				ans = 90;
			}
			cout << ans << endl;
			continue;
		}
		for (int i = 1; i < d.size(); i++) {
			if (d[i] == "north") {
				numerator /= 2;
				ans_n -= numerator;
			}else{
				numerator /= 2;
				ans_n += numerator;
			}
		}

		while(ans_n % 2 == 0) {
			ans_n /= 2;
			ans_d /= 2;
		}
		if (ans_d == 1) {
			cout << ans_n << endl;
		}else{ 
			cout << ans_n << "/" << ans_d << endl;
		}

		
	}

	return 0;
}

Measured memory_bytes: 3124
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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 int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

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

int N, K;

int main()
{
    cin >> N >> K;
    ll m = 1;
    for (int i = 1; i <= 100; i++)
    {
        m *= K;
        // cout << m << endl;
        if (N < m)
        {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from itertools import combinations
import math

IA = lambda: [int(x) for x in input().split()]
IM = lambda N: [IA() for _ in range(N)]

N, D = IA()
X = IM(N)

ans = 0
for x, y in combinations(X, 2):
    t = sum((u - v)**2 for u,v in zip(x, y))
    ans += int(math.sqrt(t))**2 == t
print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	
	if ((a * b) % 2 == 1 || (a * b * 2) % 2 == 1 || (a * b * 3) % 2 == 1) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
from itertools import permutations
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
p_, q_ = 0, 0
for i, o in enumerate(permutations(range(1, n + 1), n)):
    if p == o:
        p_ = i + 1
    if q == o:
        q_ = i + 1
print(abs(p_ - q_))


Measured memory_bytes: 39024
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
MOD = 998244353

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

ans = 0
dp = [0]*(S+1)
for i in range(N):
    dp[0] += 1      # Lがiからを足す
    next_dp = [0]*(S+1)
    for j in range(S+1):
        next_dp[j] += dp[j]             # A[i]を選ばない
        next_dp[j] %= MOD
        if j+A[i]<=S:
            next_dp[j+A[i]] += dp[j]    # A[i]を選ぶ
            next_dp[j] %= MOD
    dp = next_dp
    ans += dp[S]    # Rがiまでを足す
    ans %= MOD

print(ans)


Measured memory_bytes: 43244
N = gets.chomp.to_i
points = []

def distance(a,b)
  dis = (a[0]-b[0])**2 + (a[1]-b[1])**2
  return Math.sqrt(dis)
end

N.times do
  point = gets.chomp.split(" ").map(&:to_i)
  points << point
end

distances = []

while points.length > 0 do
  i = points.shift
  points.each do |e|
    distances << distance(i,e)
  end
end

result = 0
distances.each do |e|
  result += e
end

result = 2 * result / N

puts result

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int a[2000005];
int main()
{
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll p = a*c;
    ll q = a*d;
    ll r = b*c;
    ll s = b*d;
    cout <<max({p,q,r,s}) << endl;
}


Measured memory_bytes: 3632
#include"bits/stdc++.h"

using namespace std; 

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

#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_LARGE = 1000000100;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

void Main()
{
    int r;
    cin >> r;
    cout << 3 * r * r << endl;

	return;
}

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

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int a[n];
  int sum=0;
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    if(a[i]>=k) sum+=1;
  }
  cout<<sum;
}

Measured memory_bytes: 640
import java.util.Scanner;

//Compile
public class Main{

	public static char[][] map;
	public static boolean[][] mark;
	public static int count;
	public static int[][] move = {{1,0}, {0,1}, {-1,0}, {0, -1}};

	public static void dfs(int i, int j, char ch){
		mark[i][j] = true;
		count++;
		for(int k=0;k<4;k++){
			int i2 = i + move[k][0];
			int j2 = j + move[k][1];
			if(0<=i2&&i2<12&&0<=j2&&j2<6&&!mark[i2][j2]&&map[i2][j2]==ch){
				dfs(i2, j2, ch);
			}
		}
	}

	public static boolean delete(int i, int j, char ch){
		if(ch=='O')return false;
		mark = new boolean[12][6];
		count = 0;
		dfs(i,j,ch);
		if(count<4)return false;
		for(int m=0;m<12;m++){
			for(int n=0;n<6;n++){
				if(mark[m][n]){
					map[m][n] = '.';
					for(int k=0;k<4;k++){
						int m2 = m + move[k][0];
						int n2 = n + move[k][1];
						if(0<=m2&&m2<12&&0<=n2&&n2<6&&map[m2][n2]=='O')
							map[m2][n2] = '.';
					}
				}
			}
		}
		return true;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t--!=0){
			map = new char[12][6];
			for(int i=0;i<12;i++)map[i]=sc.next().toCharArray();
			int chain = 0;
			while(true){
				boolean f = false;
				for(int i=0;i<12;i++){
					for(int j=0;j<6;j++){
						if(map[i][j]!='.')
							f |= delete(i,j,map[i][j]);
					}
				}
				if(!f)break;
				chain++;
				for(int j=0;j<6;j++){
					for(int i=11;i>=1;i--){
						if(map[i][j]=='.'){
							int k = i-1;
							while(k>=0&&map[k][j]=='.')k--;
							if(k<0)break;
							for(int m=k;m<i;m++){
								map[m+1][j] = map[m][j];
								map[m][j] = '.';
							}
						}
					}
				}
			}
			System.out.println(chain);
		}
	}
}

Measured memory_bytes: 12000
a, b, c = map(int, input().split())
divisors = []
i = 1
while(i * i < c):
    if(c % i == 0):
        divisors.append(i)
        divisors.append(c // i)
    i += 1
if(i * i == c):
    divisors.append(i)
ans = 0
for i in range(len(divisors)):
    if(a <= divisors[i] <= b):
        ans += 1
print(ans)


Measured memory_bytes: 5600
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)

typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;

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

int main() {
    int N; cin>>N;
    int F[N][10];
    int P[N][11];
    REP(i,N) REP(j,10) cin>>F[i][j];
    REP(i,N) REP(j,11) cin>>P[i][j];
    i64 ans = -INF;
    FOR(bit,1,1<<10) {
        i64 tmp = 0;
        REP(i,N) {
            int cnt=0;
            REP(j,10) if (bit&(1<<j)) {
                if (F[i][j]==1) cnt++;
            }
            tmp += P[i][cnt];
        }
        ans = max(tmp,ans);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char *argv[]) {
  int64_t A, B;
  std::cin >> A >> B;
  if(A <= 5) cout << 0 << endl;
  else if(A <= 12) cout << (B / 2) << endl;
  else cout << B << endl;

  return 0;
}


Measured memory_bytes: 256
from numpy import *
n,c = (int(i) for i in input().split())  
xs = []
ys = []

for j in range(n):
  x,y = (int(i) for i in input().split())  
  xs.append(x)
  ys.append(y)
left = [[0,0]]
right = [[0,0]]
lmax = [0]
rmax = [0]
for j in range(n):
  left.append([left[-1][0]+ys[j]-(xs[j]-left[-1][1]),xs[j]])
  lmax.append(max(lmax[-1],left[-1][0]))

for j in range(n)[::-1]:
  right.append([right[-1][0]+ys[j]-(right[-1][1]+c-xs[j]),xs[j]-c])
  rmax.append(max(rmax[-1],right[-1][0]))
anss = []
anss.append(max(lmax))
anss.append(max(rmax))
for i in range(1,n):
  anss.append(left[i][0]-xs[i-1]+rmax[-1-i])  
for i in range(1,n):
  anss.append(right[i][0]+right[i][1]+lmax[-1-i])
print(max(anss))

Measured memory_bytes: 61376
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
const int dm = 1 << 21;
char dn[dm], * di = dn;
inline void putkotae(int X, int Y) {
	char C[12];
	rep(i, 6) {
		*(C + i) = '0' + Y % 10;
		Y /= 10;
	}
	rep(i, 6) {
		*(C + i + 6) = '0' + X % 10;
		X /= 10;
	}
	for (int i = 11; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

void pakuri_sort(int N, ll A[]) {
	const int b = 8;
	int tmp[100001];
	rep(k, 8) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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


	int N = getint(), M = getint();
	int P[100000], PK[100001] = {};
	ll S[100000];
	rep(i, M) {
		P[i] = getint();
		S[i] = ((ll)getint() << 20) + i;
	}
	sort(S, S + M);

	int kotae[100000];
	rep(i, M) {
		int j = S[i] & 131071;
		kotae[j] = ++PK[P[j]];
	}
	rep(i, M) putkotae(P[i], kotae[i]);

	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

Measured memory_bytes: 4864
#include <stdio.h>

int main(void) {

	char b;

	scanf("%c", &b);    
    
    if(b == 'A'){
      puts("T");
    }
    else if(b == 'T'){
      puts("A");
    }
    else if(b == 'C'){
      puts("G");
    }
    else{
      puts("C");
    }

	return 0;
}



Measured memory_bytes: 128
import sys
import math
import copy
import queue
input = sys.stdin.readline
def LI(): return [int(x) for x in input().split()]
INF = 10**15
DD = ((1,0),(0,1),(-1,0),(0,-1))

S = [x for x in input().rstrip()]
n = int(input())

a = [[],[]]
d = 0
for _ in range(n):
    q = list(input().split())
    if q[0] == '1':
        d = 1-d
    else:
        if q[1] == '1':
            a[d].append(q[2])
        else:
            a[1-d].append(q[2])

if d == 1:
    a[1].reverse()
    S.reverse()
    S = ''.join(a[1]) + ''.join(S) + ''.join(a[0])
else:
    a[0].reverse()
    S = ''.join(a[0]) + ''.join(S) + ''.join(a[1])
print (S)

Measured memory_bytes: 67232
import numpy as np

num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse = True)

dp = np.zeros(N+1, dtype = np.int)
MIN = -10**9
for i in range(1, N+1):
    mx = MIN
    for a in A:
        k = i-num[a]
        if k >= 0:
            mx = max(mx, dp[k] + 1)
    dp[i] = mx

d = dp[N]
n = N
s = []
for i in range(0, d):
    for a in A:
        tmp = n-num[a]
        if tmp >= 0 and dp[tmp] == dp[n]-1:
            s.append(str(a))
            n -= num[a]
            break
print("".join(s))


Measured memory_bytes: 14520
package main

import (
	"fmt"
)

func main() {
	var (
		h, w int
	)
	fmt.Scan(&h, &w)

	if h == 1 || w == 1 {
		fmt.Println(1)
	} else {
		fmt.Println((h*w+2-1) / 2)
	}
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;

int main(){
  int K,S;
  cin>>K>>S;
  int ans=0;
  for (int X=0;X<=K;X++){
    for (int Y=0;Y<=K;Y++){
      int Z=S-X-Y;
      if (Z>=0&&Z<=K) ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cstdio>
#include<cmath>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define rep4(i,j,k) rep(i,4)rep(j,4)rep(k,4)
int MOD=1000000007;
int dp[4][4][4][110];
signed main(){
    int n;cin>>n;
    rep(i,4){
        rep(j,4){
            rep(k,110)rep(kk,4)dp[i][j][kk][k]=0;
        }
    }
    rep(i,4){
        rep(j,4)rep(kk,4)dp[i][j][kk][3]=1;
    }
    dp[0][3][2][3]=0;dp[0][2][3][3]=0;dp[3][0][2][3]=0;
    for(int i=4;i<=n;i++){
        rep4(a1,a2,a3){
            rep(cur,4){
                if(cur==2){
                    if(a2==0&&a3==3)continue;
                    if(a2==3&&a3==0)continue;
                    if(a1==0&&a2==3)continue;
                    if(a1==0&&a3==3)continue;
                }
                if(cur==3){
                    if(a2==0&&a3==2)continue;
                }
                dp[a2][a3][cur][i]+=dp[a1][a2][a3][i-1];
            }
        }
        //XAGC out done
        //XGAC out done
        //XACG out done
        //AGXC out
        //AXGC out
        rep(j,4){
            rep(k,4){
                rep(kk,4)dp[j][k][kk][i]%=MOD;
            }
        }
    }
    int res=0;
    rep(i,4){
        rep(j,4)rep(kk,4)res+=dp[i][j][kk][n];
    }
    res%=MOD;
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.chop.to_i
a = gets.chop.split.map(&:to_i)

cnt = 0
pre = 0

a.each do |i|
  if i == pre + 1
    pre = i
  else
    cnt += 1
  end
end

if cnt == 0
  puts 0
elsif cnt == n
  puts -1
else
  puts cnt
end

Measured memory_bytes: 16772
import itertools

n = int(input())
p = tuple(map(int, input().split())) # 横入力
q = tuple(map(int, input().split())) # 横入力
seq = [0]*n
for i in range(1,n+1):
    seq[i-1] = i
nnn = list(itertools.permutations(seq, n))
print(abs(nnn.index(q) - nnn.index(p)))


Measured memory_bytes: 8052
s = input()
leng = len(s)
count = 0
if leng %2!=0:
    for i in range(int((leng-1)/2)):
        if s[i] != s[leng-i-1]:
            count += 1
else:
    for i in range(int(leng/2)):
        if s[i] != s[leng-i-1]:
            count += 1
    
print(count)

Measured memory_bytes: 3060
N, K = map(int, input().split())
S1 = 0
S2 = 0
for k in range(1, N+1):
    S1 += k*N - k*(k-1) +1
    S1 %= 10**9 + 7
for k in range(1, K):
    S2 += k*N - k*(k-1) +1
    S2 %= 10**9 + 7
    
S = S1 - S2 + 1
S %= 10**9 +7

print(S)

Measured memory_bytes: 9188
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	int N;
	int cnt=0;
	
	cin>>N;
	
	vint A(N);
	
	for (int i = 0; i < N; i++) {
		cin>>A[i];
	}
	
	for (int i = N-1; i >= 0; i--) {
		if(A[i]!=i+1){
			cnt++;
		}
	}
	YN(cnt==0||cnt==2);

	return 0;
}

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

int main() {
 int a;
 int b;
 int c;
 int d;
 int e;
 cin >> a;
 cin >> b;
 cin >> c;
 if (0 == a % b){
   d = a / b;
   e = d * c;
   cout << e;
 }else{
   d = a / b;
   d = d + 1;
   e = d * c;
   cout << e;
 }
  
	return 0;
}


Measured memory_bytes: 3552
import sys
input = sys.stdin.buffer.readline

def main():
    N,K = map(int,input().split())
    a = list(map(int,input().split()))
    M = max(max(a),K).bit_length()
    l = [0 for _ in range(M)]
    for num in a:
        for i in range(M):
            l[i] += num%2
            num //= 2

    use = 0
    for i in reversed(range(M)):
        if l[i] < -(-N//2):
            if use+2**i <= K:
                use += 2**i
    
    ans = 0        
    for num in a:
        ans += (num^use)
        
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 13068
#include <cstdio>
#include <map>
#include <iostream>

using namespace std;
#define ll long long
const int MAX = 2e5 + 111;
int n;
ll h[MAX];
ll ans = 0;
map<ll, ll> p;

int main(){
    scanf("%d", &n);
    for (int i = 1; i <= n; i++){
        cin >> h[i];
        ll m = i-h[i];
        if (p.count(m)!=0) ans += p[m];
        p[i+h[i]]++;
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 17780
import java.io.*;
import java.util.*;

public class Main {
    public FastScanner in;
    public PrintWriter out;

    public class Pair {
        public int first, second;

        public Pair(int first, int second) {
            this.first = first;
            this.second = second;
        }
    }

    public void solve() {
        int n = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) arr[i] = in.nextInt();
        int max = Integer.MIN_VALUE;
        int index = 0;
        for (int i = 0; i < n; i++) {
            if (Math.abs(arr[i]) > max) {
                max = Math.abs(arr[i]);
                index = i;
            }
        }
        if (arr[index] == 0) {
            out.println(0);
        } else if (arr[index] < 0) {
            out.println(2 * n - 2);
            for (int i = 0; i < n; i++) {
                if (i == index) continue;
                out.println((index + 1) + " " + (i + 1));
            }
            for (int i = n - 1; i >= 1; i--) {
                out.println((i + 1) + " " + i);
            }
        } else {
            out.println(2 * n - 2);
            for (int i = 0; i < n; i++) {
                if (i == index) continue;
                out.println((index + 1) + " " + (i + 1));
            }
            for (int i = 1; i < n; i++) {
                out.println(i + " " + (i + 1));
            }
        }
    }

    public void runIO() {
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    public void run() {
        try {
            in = new FastScanner(new File("input.txt"));
            out = new PrintWriter(new File("output.txt"));
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }

        solve();

        out.close();
    }

    public class FastScanner {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public FastScanner(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public FastScanner(File file) {
            try {
                reader = new BufferedReader(new FileReader(file));
            } catch (FileNotFoundException e) {
                throw new RuntimeException(e);
            }
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }

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


Measured memory_bytes: 21332
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(ReadLine());

        var ans = Enumerable.Range(1, N).Where(i => i % 2 == 1).Select(i => Divisor.GetDivisors(i).Count()).Count(x => x == 8);

        WriteLine(ans);
    }
}

static class Divisor
{
    public static IEnumerable<long> GetDivisors(long x)
    {
        var oppositeDivisors = new List<long>();

        for (long i = 1; i * i <= x; i++)
        {
            if (x % i == 0)
            {
                yield return i;
                if (x / i != i)
                    oppositeDivisors.Add(x / i);
            }
        }

        for (int i = oppositeDivisors.Count - 1; i >= 0; i--)
            yield return oppositeDivisors[i];
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


Measured memory_bytes: 28460
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner io = new Scanner(System.in);
		long A = io.nextLong();
		long B = io.nextLong();
		
		System.out.println(orNum(A,B));
		
		
	}
	
	public static long orNum(long A,long B){

		long q = 1L << 59;
		
		for(;q>0;q=q>>1){
			if((A&q)==0 && (B&q)==0)
				continue;
			if((A&q)!=0 && (B&q)!=0){
				A -= q; B -= q;
				continue;
			}
			if((A&q)==0 && (B&q)!=0){
				break;
			}
			if(((A&q)!=0 && (B&q)==0)){
				return 0;
			}
		}

		if(A==B){
			return 1;
		}
		
		long ans = q-A;
		ans = ans *2+1;
		B -= q;
		ans += Math.min(A-1,orNum(1,B));
		return ans;
	}
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

void solve(string S){
	if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3]) {
		cout << "Bad" << endl;
	} else {
		cout << "Good" << endl;
	}
}

int main(){	
	string S;
	cin >> S;
	solve(S);
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_comparison.hpp>

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

inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;
using namespace boost;

int go[50][50];
int re[50][50];

int d[50];
int e[50];

bool memo[50][50];

int main(){
  while(true){
    int n = getInt();
    int m = getInt();

    if(n + m == 0) break;

    d[0] = d[n - 1] = 0;
    e[0] = 0; e[n - 1] = 1000;

    REP(i, n - 2){
      d[i + 1] = getInt();
      e[i + 1] = getInt();
    }

    REP(i,n) REP(j,n){
      memo[i][j] = false;
      go[i][j] = re[i][j] = 0;
    }

    REP(i, m){
      int a = getInt() - 1;
      int b = getInt() - 1;
      int c = getInt();

      if(e[a] >= e[b])
        re[b][a] = c;
      if(e[a] <= e[b])
        go[a][b] = c;
    }


    typedef boost::tuple<int, int, int, long long> data;
    const int COST = 0;
    const int POS_GO = 1;
    const int POS_RE = 2;
    const int FLAG   = 3;

    priority_queue<data, vector<data>, greater<data> > pq;
    bool ok = false;

    pq.push(make_tuple(0, 0, 0, 1));

    // puts("go"); REP(i,n){ REP(j,n) printf("%2d ", go[i][j]); puts("");}
    // puts("re"); REP(i,n){ REP(j,n) printf("%2d ", re[i][j]); puts("");}

    while(pq.size()){
      data dt = pq.top(); pq.pop();
      int cost  = dt.get<COST>();
      int posgo = dt.get<POS_GO>();
      int posre = dt.get<POS_RE>();
      long long flag = dt.get<FLAG>();

      if(memo[posgo][posre]) continue;
      memo[posgo][posre] = true;

      // printf("%d %d %d\n", cost, posgo, posre);

      if(posgo == n - 1 && posre == n - 1){
        ok = true;
        printf("%d\n", cost);
      }

      REP(i,n){
        bool gof = go[posgo][i] != 0;
        bool ref = re[posre][i] != 0;
        int cc = cost;
        long long ff = (flag | (1ll << i));

        if((flag & (1ll << i)) == 0){
          cc += d[i];
        }

        if(gof && !memo[i][posre])
          pq.push(make_tuple(cc + go[posgo][i], i, posre, ff));
        if(ref && !memo[posgo][i])
          pq.push(make_tuple(cc + re[posre][i], posgo, i, ff));
        if(gof && ref && !memo[i][i])
          pq.push(make_tuple(cost + d[i] + go[posgo][i] +
                             re[posre][i], i, i, ff));
      }
    }

    if(!ok) puts("-1");
  }
  return 0;
}

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

int main () {
    int A, B, C, D, E;
    cin >> A >> B >> C >> D >> E;
    
    int sum = 0;
    while (A != B) {
        if (A < 0) {
            sum = -A * C;
            A = 0;
        } else {
            if (A == 0) {
                sum += D;
            }
            sum += (B - A) * E; 
            A = B;
        }
    }
    
    cout << sum << endl;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t 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 string read_s(){string s="";char c=getchar();while(c<'!'||c>'~'){c=getchar();}while(c>='!'&&c<='~'){s+=c;c=getchar();}return s;}
void Main(){
    int N = read(), K = read();
    printf("%d\n", N-K+1);
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
    static void Main(string[] args){
    var vals = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList();
    int N=vals[0];
    int D=vals[1];
    int[,] xarray=new int[N,D];
    for(int i=0;i<N;i++){
        var xs = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList();
        for(int j=0;j<D;j++){
            xarray[i,j]=xs[j];
        }
    }
   /* double[] powlist=new double[400];
    for(int i=0;i<400;i++){
        powlist[i]=i*i;
    }*/
    int ans=0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            double sum=0;
            for(int k=0;k<D;k++){
            var pow=Math.Pow((xarray[i,k]-xarray[j,k]),2);
            sum+=pow;
            }
            //if(powlist.Contains(sum)){ans++;}
            if(Math.Sqrt(sum)==(int)(Math.Sqrt(sum))){ans++;}
        }
    }
    
    Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N - 1; i >= 0; i--)
const ll INF = 1000000000;
const ll mod = 1000000007;
#define PI 3.1415926535
using Graph = vector<vector<int>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true;} return false;}
typedef pair<int, int> pair;
bool seen[505][505];

//dpTable
//bool dp[100050];

int main(){
    int N,A,B;
    cin >> N >> A >> B;
    cout << min(A,B) << ' ' << max(A + B - N,0) << endl;
    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define fr first
#define se second
#define r_0 return 0
#define ll long long
#define pb push_back
#define TIME ios_base::sync_with_stdio(0);
using namespace std;

const long long INF = 1e7;
const long long N = 1e6 + 7;
const long long mod = 1e9 + 7;
const long double eps = 1E-7;

ll T = 1, n, m, b, ans, a, cnt;
string s;
vector < ll > v, v1;
set< char > st;
int main(){
    TIME
    cin >> s;
    if ( s.size() % 2 == 1 )
        return cout << "No", 0;
    for ( int i=0; i<s.size()-1; i++ ){
        if ( s[i] == 'h' and s[i+1] == 'i' )
            i ++;
        else
            return cout << "No", 0;
    }
        return cout << "Yes", 0;
}


Measured memory_bytes: 256
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;

      string str;


       cin>>a;

       a=!a;

       cout<<a<<endl;













}



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

int64_t mod=1e9+7;
vector<int64_t> inv,comb;

int64_t modpow(int64_t a,int64_t n){
  int64_t res=1;
  while(n>0){
    if(n&1){
      res*=a;
      res%=mod;
    }
    a*=a;
    a%=mod;
    n>>=1;
  }
  return res;
}

int64_t modinv(int64_t a){
  return modpow(a,mod-2);
}


int main(){
  int64_t n,a,b;
  cin >> n >> a >> b;
  inv.resize(b+1);
  comb.resize(b+1);
  comb.at(0)=1;
  for(int i=1;i<=b;i++){
    inv.at(i)=modinv(i);
  }
  for(int i=1;i<=b;i++){
    comb.at(i)=(((n-i+1)*inv.at(i))%mod*comb.at(i-1))%mod;
  }
  int64_t ans=0;
  ans=modpow(2,n)-1;
  ans-=comb.at(a);
  ans%=mod;
  if(ans<0){
    ans+=mod;
  }
  ans-=comb.at(b);
  ans%=mod;
  if(ans<0){
    ans+=mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        String s=scan.nextLine();
        int count=0;
        for(;;){
            String W=scan.next();
            if(W.equalsIgnoreCase(s)){
                count++;
            }
            if(W.equals("END_OF_TEXT")){
                break;
            }
        }
        System.out.println(count);

    }
}



Measured memory_bytes: 26084
import sys
from collections import deque
n,q = map(int, input().split())
S = []
for i in range(n):
    S.append(deque())

for i in range(q):
    l = list(map(int,input().split()))
    if l[0] == 0:
        S[l[1]].appendleft(l[2])
    elif l[0] == 1:
        if not S[l[1]]:
            continue
        else:
            print(S[l[1]][0])
    elif S[l[1]]:
        S[l[1]].popleft()




Measured memory_bytes: 14596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    // your code goes here
    ll n,k,s,i;
    cin >> n >> k >> s;
    if(s!=1000000000){
        for(i=1;i<=k;i++) cout << s << " ";
        for(i=k+1;i<=n;i++) cout << s+1 << " ";
    } else {
        for(i=1;i<=k;i++) cout << s << " ";
        for(i=k+1;i<=n;i++) cout << 1 << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1280
sList, tList = list(input()), list(input())

dp = [[0] * (len(tList) + 1) for _ in range(len(sList) + 1)]
for i, s in enumerate(sList, start=1):
    sameNum = 0
    for j, t in enumerate(tList, start=1):
        num = dp[i-1][j]
        if s == t:
            sameNum = max(num, dp[i-1][j-1] + 1)
        dp[i][j] = max(num, sameNum)

ans = ""

while(i > 0, j > 0):
    num = dp[i][j]
    if num == 0:
        break
    if sList[i-1] == tList[j-1]:
        ans = sList[i-1] + ans
        i -= 1
        j -= 1
    else:
        if dp[i-1][j] > dp[i][j-1]:
            i -= 1
        else:
            j -= 1

print(ans)


Measured memory_bytes: 114268
#include <stdio.h>
#include <string.h>

char x[200010];
int main()
{
	scanf("%s",x+1);
	int a = strlen(x+1);
	int s = 0;
	for(int i=1;i<=a;i++) s += (x[i]-'0');
	printf("%s",s%9==0?"Yes":"No");
}

Measured memory_bytes: 1924
// ABC167B.cpp

#include <iostream>
using namespace std;
int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    if (a >= k) { // 1のカードがたくさんある時
        ans = k;
        cout << ans << endl;
        return 0;
    }
    else { // 1のカードがあまりない時
        ans = a;
        k -= a;
    }
    if (b < k) {
        k -= b;
        ans -= k;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3144