akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	int
		a,b,c;
	cin >> a; cin >> b;// cin >> c;
	//a[0]==a[2]?cout << "Yes"<< endl: cout << "No" << endl;
	cout << (a - 1)*(b - 1) << endl;
	
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
    int a[200009];
    bool p[1000009]={false};
    int vis[1000009]={0};
    int n;
    cin>>n;
    int ans=n;
    for(int i=1;i<=n;i++) {cin>>a[i]; p[a[i]]=true ;vis[a[i]]++;}
    for(int i=1;i<=1000000;i++) if(vis[i]>1) {ans=ans-vis[i]; vis[i]=0;}
    for(int i=1;i<=1000000;i++)
    {
        if(p[i]) for(int j=2*i;j<=1000000;j+=i) {ans=ans-vis[j]; vis[j]=0 ;}
    }
    cout<<ans;
}


Measured memory_bytes: 9232
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <deque>

using namespace std;

string S;

deque<string> tmp;

int Q, T[200005],F[200005];
string C[200005];

int main(void) {

	cin >> S;
	int N = S.size();
	for (int i = 0; i < N; i++) {
		tmp.push_back(S.substr(i,1));
	}
	cin >> Q;

	for (int i = 1; i <= Q; i++) {
		cin >> T[i];
		if (T[i] == 1) {}
		else { cin >> F[i] >> C[i]; }
	}

	int r = 0;
	for (int i = 1; i <= Q; i++) {
		if (T[i] == 1) {
			r = 1 - r;
		}
		else {
			if ((r == 0 && F[i] == 1) || (r == 1 && F[i] == 2)) { tmp.push_front(C[i]); }
			else { tmp.push_back(C[i]); }
		}
	}

	string ans = "";

	while (tmp.size() > 0) {
		if (r == 0) {
			string y = tmp.front(); tmp.pop_front();
			ans += y;
		}
		else {
			string y = tmp.back(); tmp.pop_back();
			ans += y;
		}
	}

	cout << ans << endl;
	

	return 0;
}

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

int main() {
  
  int n;
  cin >> n;
  
  int ans = n+pow(n,2)+pow(n,3);
  
  cout << ans << endl;
  
}


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

using namespace std;

#define FOR(i, a, b) for (int(i) = a; (i) <= (b); ++(i))
#define rep(i, n) FOR(i, 0, n-1 )
#define all(c) (c).begin(), (c).end()
#define mod 1000000007LL
#define INF 123456789012345
#define int long long

signed main() {
  int n,k;cin>>n>>k;
  cout << (n%k!=0) << endl; 
}


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

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  fspcnt = 0;
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

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

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}*/


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  string s;
  int64_t w;
  cin >> s;
  cin >> w;
  string ss;
  rep(i,s.size()){
    if(i % w == 0){
      ss.push_back(s.at(i));
    }
  }
  cout << ss << endl;
    
}

Measured memory_bytes: 256
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
constexpr bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
constexpr bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

void Pr(bool f){
  cout << (f ? "OK" : "NG") << "\n";
  exit(0);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll k, a, b;
  cin >> k >> a >> b;
  rep(i, 4000){
    if(a <= i*k && i*k <= b){
      Pr(1);
    }
  }
  Pr(0);
}


Measured memory_bytes: 3648
#include <iostream>
#include <stack>
using namespace std;
bool solve(string str){
	stack<char> stk;
	for(int i=0; i<str.length(); ++i){
		if(str[i]==')' || str[i]==']'){
			if(stk.empty() || str[i]!=stk.top())	return false;
			stk.pop();
		}else if(str[i]=='(')	stk.push(')');
		else if(str[i]=='[')	stk.push(']');
	}
	return stk.empty();
}
int main(){
	string str;
	while(getline(cin,str)){
		if(str==".")	break;
		cout << (solve(str)? "yes": "no") << endl;
	}
}

Measured memory_bytes: 1184
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main() {
	int N, Y;
	cin >> N >> Y;
	int maisuu10000 = -1, maisuu5000 = -1, maisuu1000 = -1;
	for (int a = 0; a <= N; a++) {
		for (int b = 0; b <= N; b++) {
			int c = N - a - b;
			int gokei = 10000 * a + 5000 * b + 1000 * c;
			if (gokei == Y && a+b+c==N&&c>=0) {
				maisuu10000 = a;
				maisuu5000 = b;
				maisuu1000 = c;
			}
		}
	}
	cout << maisuu10000 << " " << maisuu5000 << " " << maisuu1000 << endl;
	return 0;
}


Measured memory_bytes: 256
import sys

def I(): return(int(sys.stdin.readline()))
def IR(n): return([I() for _ in range(n)])

def main():
    N = I()
    A = IR(N)

    x = 0
    for a in A:
        x ^= a

    dic = {}
    for a in A:
        dic[a^(a-1)] = True
    
    ans = 0
    while(x!=0):
        y=0
        while ((1<<(y+1))<=x):
            y+=1
        if dic.get((1<<(y+1))-1,False):
            x^=((1<<(y+1))-1)
            ans += 1
        else:
            return(-1)
    return(ans)

if __name__ == "__main__":
    print(main())


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

int main(){
	int a, b;
	cin >> a >> b;
	int wa=a+b;
	bool judge=false;
	if(a%3==0 || b%3==0 || wa%3==0) judge=true;
	if(judge) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
}


Measured memory_bytes: 3568
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main
{
	public static void main(String[] args)
	{
		FastReader reader = new FastReader();
		int ans = 0;
		int n = reader.nextInt();

		for(int i=1; i<=n; i++)
		{
			int x = reader.nextInt();
			if((x&1) == 1 && (i&1) == 1)
			{
				ans++;
			}
		}

		System.out.println(ans);

	}
	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

		public FastReader()
		{
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next()
		{
			while (st == null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
	}
}



Measured memory_bytes: 32588
from itertools import chain
m,k=map(int,input().split())
if 0<k<2**m and m>=2:
    print(*[str(i) for i in chain(range(0,k),range(k+1,2**m),[k],range(2**m-1,k,-1),range(k-1,-1,-1),[k])])
elif k==0:
    print(*[str(i) for i in chain(range(0,2**m),range(2**m-1,-1,-1))])
else:
    print(-1)

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

int main() {
	int n; cin >> n;
	int L[100];

	int sum = 0, maxv = 0;
	for (int i = 0; i < n; i++) {
		cin >> L[i];
		sum += L[i];
		maxv = max(maxv, L[i]);
	}

	cout << (maxv < sum - maxv ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
/**
 *   created: 07 December 2019  18:00:06
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define int long long
#define PB push_back
#define PPB pop_back
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================

int32_t main()
{
	optimizeIO();
	int tt=1;
	//cin>>tt;
	while(tt--){
		int a,b,c;
		cin>>a>>b>>c;
		if(a+b+c>=22){
			cout<<"bust";
		}
		else
			cout<<"win";
	}
	return 0;
}


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

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)'''

s=input().rstrip("\n")
e=len(s)
l=["dream","dreamer","erase","eraser"]
for i in range(len(s))[::-1]:
    #print(s[i:e])
    #print(s)
    if s[i:e] in l:
        e=i
        s=s[:i]  
        continue
    if len(s[i:e])>7:
        print("NO")
        sys.exit()
if len(s)>0 and s not in l:
    print("NO")
else:
    print("YES")

Measured memory_bytes: 9248
#!/usr/bin/env python3
import sys
from fractions import gcd


def solve(A: int, B: int):
    print(A*B//gcd(A, B))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5048
n, m= map(int, input().split())

links = [[] for x in range(n + 1)]
sums = [0 for x in range(n + 1)]
adds = [0 for x in range(n + 1)]

links[0].append(1)

buf = [map(int, input().split()) for _ in range(n - 1)]

for link in buf:
  a, b= link
  links[a].append(b)
  links[b].append(a)


buf = [map(int, input().split()) for _ in range(m)]
for px in buf:
  p, x = px
  adds[p] += x

que = [0,[1]]
checked = [0 for x in range(n+1)]

que = [[-1, [0]]]

while que:
  link = que.pop()
  par = link[0]
  childs = link[1]

  for child in childs:
    if checked[child] != 1:
      sums[child] = sums[par] + adds[child]
      que.append([child, links[child]])
      checked[child] = 1

  
print(*sums[1:])

Measured memory_bytes: 169800
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,v[10]={},x,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>x;
		v[x]=1;
	}
	int f=0;
	while(!f){
	//	printf("%d\n",n);
		int num=n,yes=1;
		while(num){
			if(v[num%10]==1){
				yes=0;
				break;	
			}
			num/=10;
		}
		if(yes){
			break;
		}
		n++;
	} 
	cout<<n;
	
}

Measured memory_bytes: 384
#include <cstdio>
#include <list>
using namespace std;

/* https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/3/ALDS1_3_C
 * input:
7
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5
 * output:
6 1 2
 * input2:
9
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5
deleteFirst
deleteLast
 * output2:
1
 */
int main() {
    int ret = 0;
    int n, v;
    char command[100];

    list<int> l;

    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        scanf("%s", command);

        if(command[0] == 'i') {
            scanf("%d", &v);
            l.push_front(v);
        } else if(command[6] == 'F') {
            l.pop_front();
        } else if (command[6] == 'L') {
            l.pop_back();
        } else if (command[0] == 'd') {
            scanf("%d", &v);
            for(list<int>::iterator it = l.begin(); it != l.end(); it++) {
                if (*it == v) {
                    l.erase(it);
                    break;
                }
            }
        } else {
            continue;
        }
    }

    int i = 0;
    for(list<int>::iterator it = l.begin(); it != l.end(); it++) {
        if(i++) printf(" ");
        printf("%d", *it);
    }
    printf("\n");

    return ret;
}



Measured memory_bytes: 34068
#!/usr/bin/env python3
import sys

rl = sys.stdin.buffer.readline
INF = sys.maxsize


K = int(rl())

def solve(K):
  L = ((9 * K) // 7) if K % 7 == 0 else (9 * K)
  if L % 2 == 0 or L % 5 == 0:
    return -1
  a = 1 % L
  for i in range(L):
    a = (a * 10) % L
    if a == 1:
      return i + 1

  return -1

print(solve(K))

Measured memory_bytes: 62904
#include <bits/stdc++.h>
#define ll long long
#define pi 3.14159265358979
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
 
int main(){
    ll n,sum=0,summ=0,a[200005];
    cin>>n;
    rep(i,n){
        cin>>a[i];
        sum+=(a[i])%mod;
      sum%=mod;
        summ+=((a[i]%mod)*(a[i]%mod))%mod;
      summ%=mod;
    }
    cout<<(((sum*sum+mod-summ)%mod)*((mod+1)/2))%mod;
}

Measured memory_bytes: 5136
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};
long double eps = 1e-6;
long double pi = acos(-1);

template< int mod = 1000000007 >
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        x = (int) (1LL * x * p.x % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while(n > 0) {
            if(n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt< mod >(t);
        return (is);
    }

    static int get_mod() { return mod; }
};

const int mod = 998244353;
using mint = ModInt< mod >;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);


    int n,s;
    cin>>n>>s;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    mint dp[n+1][s+1]={};
    dp[0][0] = 1;
    for(int i=0;i<n;i++){
        for(int j=0;j<=s;j++){
            if(j+a[i]<=s)dp[i+1][j+a[i]] += dp[i][j];
            dp[i+1][j] += mint(2)*dp[i][j];
        }
    }
    cout << dp[n][s] << endl;

}

Measured memory_bytes: 38776
'use strict'

function main(input){
  const s = input.split('').map(x => parseInt(x));

  if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3]){
    console.log('Bad');
  }else{
    console.log('Good');
  }

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	long long cnt;
	int n;
	char a[52],c[52];
	cin>>n;
	cin>>a;
	cin>>c;
	int i;
	bool left;   //0,为X型；1为Y型
//	if(n==1){
//		cnt=3;
//	} else{
		if(a[0]==c[0]){ 
	    	left=0;          //第一个（左邻）为x型 
	  		cnt=3; 
	  		i=1;
		} 
		else{
			left=1;   //第一个（左邻）为Y型 
			cnt=6;
			i=2;
		} 
		while(i<=n-1){
			if(left==0){    //左邻是X型;
				if(a[i]==c[i]){    //新遇到的是X型 
					cnt*=2;
					left=0;            //刷新左邻为X 
					i++;
				} else{             //新遇到的是Y型 
					cnt*=2;
					left=1;          //刷新左邻为Y 
					i=i+2;
				}
			}
			else{                //左邻为Y型 
				if(a[i]==c[i]){    //新遇到的是X型 
					cnt*=1;
					left=0;            //刷新左邻为X 
					i++;
				} else{             //新遇到的是Y型 
					cnt*=3;
					left=1;          //刷新左邻为Y 
					i=i+2;
				}
			} 
		}
//	}

	cout<<cnt % 1000000007<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>

using namespace std;

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mis map<int,string>
#define msi map<string,int>
#define mll map<ll,ll>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep1(i,n) for(int i=1; i<=(int)(n); i++)
#define all(c) c.begin(),c.end()
#define srta(a) sort(all(a))
#define srtd(a) sort(all(a),greater<型>())
#define rvs(s) reverse(all(s))
#define psb push_back
#define ppb pop_back
#define isu isupper
#define isl islower
#define lb(a,k) lower_bound(all(a),k)
#define ub(a,k) upper_bound(all(a),k)
#define bs(a,k) binary_search(all(a),k)

const int I_INF = 1001001001;
const ll LL_INF = 1001001001001001001;
const ld EPS = 0.001;



int main() {
    ll N, M, K;
    cin >> N >> M >> K;

    vl a(N);
    vl b(M);
    rep(i,N) cin >> a[i];
    rep(i,M) cin >> b[i];

    vl sum_a(N+1, 0);
    vl sum_b(M+1, 0);
    rep(i,N) sum_a[i+1] += sum_a[i] + a[i];
    rep(i,M) sum_b[i+1] += sum_b[i] + b[i];

    ll cnt = 0;
    rep (i, N+1) {
        ll rem = K-sum_a[i];
        if (rem < 0) break;

        auto it = ub(sum_b, rem);
        ll cnt_b = it-sum_b.begin()-1;
        cnt = max(cnt, cnt_b+i);
    }

    cout << cnt << endl;
}


Measured memory_bytes: 9592
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n,k;
  cin>>n>>k;
  cout<<n-k+1<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int w = scanner.nextInt();
        while (w != -1) {
            int x = 0;
            if (w <= 10) {
                x = 4280 - 1150;
            } else if (10 < w && w <= 20) {
                x = 4280 - 1150 - (w - 10) * 125;
            } else if (20 < w && w <= 30) {
                x = 4280 - 1150 - 1250 - (w - 20) * 140;
            } else {
                x = 4280 - 1150 - 1250 - 1400 - (w - 30) * 160;
            }
            System.out.println(x);

            w = scanner.nextInt();
        }
    }
}



Measured memory_bytes: 26308
#include <iostream>
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define ll long long
char k[3]={'R','B','G'};
ll gcd(ll a,ll b)
{
	return b==0?a:gcd(b,a%b);
}
ll sumr[4005],sumg[4005],sumb[4005];
int main(int argc, char** argv) {
	int n;
	scanf("%d",&n);
	string s;
	cin>>s;
	ll ans=0;
	rep(i,0,s.length()-1)
	{
		sumr[i+1]=sumr[i];
		sumb[i+1]=sumb[i];
		sumg[i+1]=sumg[i];
		if(s[i]=='R')sumr[i+1]++;
		if(s[i]=='G')sumg[i+1]++;
		if(s[i]=='B')sumb[i+1]++;
	}
	rep(i,0,s.length()-1)
	{
		rep(j,i+2,s.length()-1)
		{
			if(s[i]==s[j])continue;
			if((s[i]!=s[j]&&s[i]!=s[(i+j)/2]&&s[j]!=s[(i+j)/2])&&(i+j)/2-i==j-(i+j)/2)
			{
				ans--;
			}
			int now=0;
			rep(l,0,2)
			{
				if(s[i]!=k[l]&&s[j]!=k[l])now=l;
			}
			if(now==0)
			{
				ans+=sumr[j]-sumr[i+1];//r,b,g
			}
			else if(now==1)
			{
				ans+=sumb[j]-sumb[i+1];
			}
			else ans+=sumg[j]-sumg[i+1];
		

		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3796
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long a[] = new long[N];
        int re1 = 0,re2=0,re4=0;
        int ans = 0;
        for (int i = 0; N > i; i++) {
            a[i] = sc.nextInt();
            if (a[i] % 4== 0) {
                re4++;
            }
            else if (a[i] % 2==0) {
                re2++;
            }
        }
        re1=N-(re4+re2);
        if ((re2==0&&re1<=re4+1)||(re2>0&&re1<=re4)) {
            System.out.println("Yes");
        } 
        else{
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 51012
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する
//素因数分解
vector<pair<long,long> > PrimeFactorize(llong N){
    
    llong prime=2;
    llong index=0;
    vector<pair<long,long> > P;
    pair<long,long> X;
    llong NUM=N;
    for(int prime=2; prime*prime<=NUM; prime++){
        while(N%prime==0){
            N = N / prime;
            index = index + 1;
        }
        if(index!=0){
            X.first = prime;
            X.second = index;
            P.push_back(X);
        }
        index = 0;
    }
    if(N!=1){
        X.first = N;
        X.second = 1;
        P.push_back(X);
    }
    return P;
}
int main(){
    llong N;
    vector<pair<long,long> > P;
    cin >> N;
    P = PrimeFactorize(N);
    cout << N <<":";
    for(int i=0; i<P.size(); i++){
        for(int j=0; j<P[i].second; j++){
            cout << " " << P[i].first;
        }
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <string>

class Dice {
	private:
		std::vector<int> faces;

		void setFaces(int f1, int f2, int f3, int f4, int f5, int f6) {
			faces[0] = f1;
			faces[1] = f2;
			faces[2] = f3;
			faces[3] = f4;
			faces[4] = f5;
			faces[5] = f6;
		}
	public:
		Dice(){}
		int getTop() {
			return faces[0];
		}
		void setFace(int val) {
			faces.push_back(val);
		}

		void roll(char dir) {
			switch (dir) {
				case 'N':
					setFaces(faces[1], faces[5], faces[2], faces[3], faces[0], faces[4]);
					break;
				case 'S':
					setFaces(faces[4], faces[0], faces[2], faces[3], faces[5], faces[1]);
					break;
				case 'W':
					setFaces(faces[2], faces[1], faces[5], faces[0], faces[4], faces[3]);
					break;
				case 'E':
					setFaces(faces[3], faces[1], faces[0], faces[5], faces[4], faces[2]);
					break;
			}
		}
		

};

int main()
{
	Dice dice;
	int val;
	for (int i = 0; i < 6; i++) {
		std::cin >> val;
		dice.setFace(val);
	}
	std::string rolls;
	std::cin >> rolls;
	for (std::string::iterator it = rolls.begin(); it < rolls.end(); it++) {
		dice.roll(*it);
	}
	std::cout << dice.getTop() << "\n";
    return 0;
}




Measured memory_bytes: 3212
import java.util.*;
import java.util.regex.*;
import static java.lang.Math.*;
import static java.lang.System.out;

// AOJ5
public class Main {
	final Scanner sc=new Scanner(System.in);
	final int[] vx={0,1,0,-1}, vy={-1,0,1,0};
	static class Point{
		int x, y;
		Point(int x, int y){	this.x=x;	this.y=y;}
		Point(){	this.x=0; this.y=0;}
		@Override public String toString(){	return "("+this.x+","+this.y+")";}
		static boolean ok(int x,int y,int X,int Y,int min){	return (min<=x&&x<X)&&(min<=y&&y<Y);}
		static boolean ok(int x,int y,int X,int Y){	return ok(x,y,X,Y,0);}
	}
	public static void main(String[] args) {
		new Main().A();
	}
	
	void A(){
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n == 0 && m == 0){
				break;
			}
			int [] taro = new int[n];
			int [] hanako = new int[m];
			int sum1 = 0,sum2 = 0;
			for(int i = 0; i < n; i++){
				taro[i] = sc.nextInt();
				sum1 += taro[i];
			}
			for(int i = 0; i < m ;i++){
				hanako[i] = sc.nextInt();
				sum2 += hanako[i];
			}
			Arrays.sort(taro);
			Arrays.sort(hanako);
			boolean flg = true;
			for(int i =0; i < n ;i++){
				for(int j = 0; j < m; j++){
					int temp1 = sum1 - taro[i] + hanako[j];
					int temp2 = sum2 - hanako[j] + taro[i];
					if(temp1 ==  temp2){
						flg = false;
						System.out.println(taro[i] + " " + hanako[j]);
						break;
					} 
				}
				if(! flg){
					break;
				}
			}
			if(flg){
				System.out.println(-1);
			}
		}
		
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
ll optimalGame(vector<ll> &arr,int i,int j,vector<ll> &prefixSum,vector<vector<ll>> &dp){
	if(i == j){
		return arr[i];
	}
	if(dp[i][j]!=-1){
		return dp[i][j];
	}
	ll ans = max((arr[i]+(prefixSum[j]-prefixSum[i]-optimalGame(arr,i+1,j,prefixSum,dp))),(arr[j]+(prefixSum[j-1]-prefixSum[i-1]-optimalGame(arr,i,j-1,prefixSum,dp))));
	return dp[i][j] = ans;
}
int main(int argc,char const* argv[]){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin>>n;
	vector<ll> arr(n+1);
	for(int i=1;i<=n;i++){
		cin>>arr[i];
	}
	vector<ll> prefixSum(n+1,0);
	vector<vector<ll>> dp(n+1,vector<ll>(n+1,-1));
	prefixSum[1] = arr[1];
	for(int i=2;i<=n;i++){
		prefixSum[i] = prefixSum[i-1] + arr[i];
	}
	ll taro = optimalGame(arr,1,n,prefixSum,dp);
	ll jiro = prefixSum[n] - taro;
	cout<<taro-jiro<<endl;
	return 0;
}

Measured memory_bytes: 71040
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
//const ll MOD=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI = 2.0*acos(0);

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

void solve(int ca){
    string T; cin>>T;
    ll ans=0;
    if(T.length()==1){
        if(T[0]=='?') cout<<"D"<<endl;
        else cout<<T<<endl;
        return;
    }
    for (int i = 0; i < T.length(); ++i) {
        if(T[i]!='?') continue;
        if(i==0) T[i]='D';
        else if(i==T.length()-1) T[i]='D';
        else{
            if(T[i]=='P') T[i]='D';
            else T[i]='D';
        }
    }
    cout<<T<<endl;
}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(0);
#endif
    return 0;
}


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

using namespace std;

int getAreaSum(int map[2001][2001], int x1, int y1, int x2, int y2 )
{
  return map[x2][y2] - map[x1][y2] - map[x2][y1] + map[x1][y1];
}

int main(void)
{
  int i, j, N, K;
  int x[100000] = { 0 };
  int y[100000] = { 0 };
  char c[100000] = { 0 };
  int npos[100000][2] = { 0 };
  int map[2001][2001] = {{ 0 }};
  int offset_x, offset_y;
  int cnt, cnt_max;
  
  // scan number
  scanf("%d %d",&N,&K);

  // scan parameter
  for(i=0;i<N;i++)
  {
    scanf("%d %d %c",&x[i],&y[i],&c[i]);
  }

  // normalization to black
  for(i=0;i<N;i++)
  {
    if(c[i]=='B')
    {
      npos[i][0] = x[i]%(2*K);
      npos[i][1] = y[i]%(2*K);
    }
    else if(c[i]=='W')
    {
      npos[i][0] = (x[i]+K)%(2*K);
      npos[i][1] = y[i]%(2*K);
    }
    map[npos[i][0]+1][npos[i][1]+1]++;
  }

  /*printf("before\n");
  for(i=0;i<=2*K;i++)
  {
    for(j=0;j<=2*K;j++)
    {
      printf("%d ",map[i][j]);
    }
    printf("\n");
  }*/
  
  // sum
  for(i=1;i<=2*K;i++)
  {
    for(j=1;j<=2*K;j++)
    {
      map[i][j] += map[i][j-1] + map[i-1][j] - map[i-1][j-1];
    }
  }

  /*printf("after\n");
  for(i=0;i<=2*K;i++)
  {
    for(j=0;j<=2*K;j++)
    {
      printf("%d ",map[i][j]);
    }
    printf("\n");
  }*/
  
  cnt_max = -1;
  // BWB WBW
  // WBW BWB
  // BWB WBW
  for(offset_x=1;offset_x<=K;offset_x++)
  {
    for(offset_y=1;offset_y<=K;offset_y++)
    {
      cnt = 0;
      cnt += getAreaSum(map,0,0,offset_x,offset_y);
      cnt += getAreaSum(map,0,offset_y+K,offset_x,2*K);
      cnt += getAreaSum(map,offset_x,offset_y,offset_x+K,offset_y+K);
      cnt += getAreaSum(map,offset_x+K,0,2*K,offset_y);
      cnt += getAreaSum(map,offset_x+K,offset_y+K,2*K,2*K);
      if (max(cnt,N-cnt)>cnt_max)
      {
        cnt_max = max(cnt,N-cnt);
      }
    }
  }
  
  printf("%d",cnt_max);
  
  return 0;
}

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

using namespace std;
char a[12][1010];
bool vis[12];
const int Inf = 1e9;
int n,m,k,pre[12];

int Solve()
{
    memset(pre , 0 , sizeof(pre));
    int c = 0, idx, Res = 0, Timer = 0;
    bool check = true;
    for(int j = 0; j<m; j++)
    {
        idx = 0;
        for(int i = 0; i<=n; i++)
        {
            Timer++;
            c+=(a[i][j] == '1');
            if(vis[i])
            {
                if(pre[idx] + c > k)
                {
                    check = false;
                    break;
                }
                pre[idx]+=c, c = 0, idx++;
            }
        }
        if(Timer > (n + 1) * m * 2)   return Inf;
        if(!check)  Res++ , memset(pre, 0, sizeof(pre)), j-- , check = true , c = 0;
    }
    return Res;
}

int main()
{
    cin >> n >> m >> k;
    for(int i = 0; i<n; i++)
    {
        for(int j = 0; j<m; j++)
        {
            cin >> a[i][j];
            a[n][j] = '0';
        }
    }
    int Ans = Inf;
    for(int i = 0; i<=(1 << n); i++)
    {
        memset(vis, 0, sizeof(vis));
        vis[n] = true;
        for(int j = 0; j<n; j++)
        {
            if(i & (1 << j))  vis[j] = true;
        }
        Ans = min(Ans, __builtin_popcount(i) + Solve());
    }
    cout << Ans;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
#include <set>
using namespace std;
using ll = long long;
using Lf = long double;
using plong = pair<ll,ll>;
const int mod = 1000000007;

int main(){
    ll N,K;cin>>N>>K;
    deque<ll> _V;
    for(ll i=0;i<N;i++){
        ll v;cin>>v;
        _V.push_front(v);
    }
    const ll INF = 99999999999;
    ll res=-INF;
    for(ll k=0;k<=K;k++){
        for(ll a=0;a<=min(N,k);a++){
            for(ll b=0;a+b<=min(N,k);b++){
                ll tmp=0;
                vector<ll> have;
                deque<ll> V = _V;
                for(ll i=0;i<a;i++){
                    have.push_back(V.front());V.pop_front();
                }
                for(ll i=0;i<b;i++){
                    have.push_back(V.back());V.pop_back();
                }
                sort(have.begin(),have.end());
                ll ind=0;
                if(have.size()!=0){
                    for(ll i=0;i<K-k;i++){
                        if(i==have.size()-1)break;
                        if(have[i]<0){
                            ind++;
                        }
                    }
                }
                for(ll i=ind;i<have.size();i++){
                    tmp+=have[i];
                }
                // cout<<"a:"<<a<<", b:"<<b<<":"<<tmp<<endl;
                res = max(res,tmp);
            }
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

//const long long int MOD = 1000000007;
const int MOD = 1000000007;
//const int MOD = 998244353;
//const long long int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
int N, M, K, H, W, L, R;

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

	string s;
	cin >> s;
	N = s.size();
	for (auto i : s) {
		if (i == 'o')M++;
	}
	M += 15 - N;
	if (M >= 8)cout << "YES\n";
	else cout << "NO\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define vl vector<ll>
#define forn(i,a,b) for(ll i=1;i<=b;++i)
#define forr(i,a,b) for(ll i=0;i<b;++i)
#define vll vector<pair<ll,ll> >
#define r0 return 0
#define be begin()
#define en end()
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define el endl; cf
#define mp make_pair
#define cf cout.flush()
int main()
{
   ios;
   unordered_map<ll,ll> mpp;
   mpp.clear();
   ll s;
   cin >> s;
   vl v ;
   v.pb(s);
   mpp[s]++;
   ll cnt = 2;
   ll j = 1 ;
   while(true)
   {
       ll foo ;
       if(v[j-1]&1){
        foo = 3*v[j-1]+1;
       }
       else foo = v[j-1]/2;
       ++j;
       v.pb(foo);
       if(mpp[foo]){
        break;
       }
       mpp[foo]++;
       ///cout << foo <<el;
       cnt++;
   }
   cout << cnt << el ;
   r0 ;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, H, AB):
    ma = max(AB, key=lambda x: x[0])[0]
    AB.sort(key=lambda x: x[1], reverse=True)

    ans = 0
    i = 0
    while H > 0:
        if i < N and AB[i][1] >= ma:
            H -= AB[i][1]
            i += 1
            ans += 1
        else:
            n = int(math.ceil(H / ma))
            H -= ma * n
            ans += n

    return ans


def main():
    N, H = read_int_n()
    AB = [read_int_n() for _ in range(N)]
    print(slv(N, H, AB))


if __name__ == '__main__':
    main()


Measured memory_bytes: 31372
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <numeric>
#include <utility>
#include <iomanip>

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

int main() {
    int k;
    cin >> k;
    vector<bool> check(k, false);
    int ans = 1;
    int seven = 7;
    for (int i=0; i<k; i++) {
        if (seven%k == 0)
            break;
        if (check[seven%k]) {
            ans = -1;
            break;
        }
        check[seven%k] = true;
        seven = seven*10 + 7;
        seven %= k;
        ans++;
    }
    cout << ans << endl;
}


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

int main() {
  int n;
  string s;
  string t;
  int cnt=0,ans=0;

  cin >> n >> s;

  vector<int> a(n,0);


  for(int i=0;i<n;i++) {
    a[i] = (char)(s[i]-'0');
  }


  for(int i=0;i<10;i++) {
    for(int j=0;j<10;j++) {
      for(int k=0;k<10;k++) {
        cnt = 0;
        for(int l=0;l<n;l++) {
          if(cnt==0 && i==a[l]) cnt++;
          else if(cnt==1 && j==a[l]) cnt++;
          else if(cnt==2 && k==a[l]) {cnt++; ans++;}
        }
      }
    }
  }


  cout << ans <<  endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;



pair<int, ll>  f(int digit, ll fr) {
    if (fr == 1) return mp(digit, 0);
    ll ans = fr / 2 * (2 * digit > 9 ? 2 : 1);
    int d = 2 * digit;
    d = d / 10 + d % 10;

    auto here = f(d, fr / 2);
    ans += here.second;
    if (fr % 2) {
        int s = here.first + digit;
        if (s < 10) {
            return mp(s, ans + 1);
        }
        else {
            return mp(s / 10 + s % 10, ans + 2);
        }
    }

    return mp(here.first, ans);
}


int main() {
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    string s;
    int n, d;
    ll fr, ans = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> d >> fr;
        auto fir = f(d, fr);
        ans += fir.second;
        if (fir.first || !s.empty()) {
            s += '0' + fir.first;
        }
    }

    while (s.size() > 1) {
        int l1 = s[s.size() - 1] - '0', l2 = s[s.size() - 2] - '0';
        s.pop_back(), s.pop_back();
        if (l1 + l2 > 9) {
            l1 += l2;
            l1 = l1 / 10 + l1 % 10;
            ans += 2;
        }

        else {
            l1 += l2;
            ans++;
        }

        s += l1 + '0';
    }

    cout << ans;


}

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

using namespace std;

typedef long long ll;

int main(){
	ll t;
    t=1;
  	while(t--){
      ll n,m;
      cin>>n>>m;
      if(n==m){
        cout<<"Yes"<<endl;
      }else{
        cout<<"No"<<endl;
      }
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

vector<int> G[100003];
int N;

bool dfs(int pa, int pb, int number, bool used[100003]){
    //    cout<<pa<<" "<<pb<<" "<<number<<endl;
    bool res = false;
    
    if(number == N)return true;
    vector<int> next1,next2;
    
    rep(i,G[pa].size()){
        int to = G[pa][i];
        if(used[to])continue;
        next1.pb(to);
    }
    
    rep(i,G[pb].size()){
        int to=G[pb][i];
        if(used[to])continue;
        next2.pb(to);
    }
    
    rep(i,next1.size()){
        rep(j,next2.size()){
            if(next1[i]==next2[j])continue;
            used[next1[i]]=true;
            used[next2[j]]=true;
            res |= dfs(next1[i], next2[j], number+2, used);
            used[next1[i]]=false;
            used[next2[j]]=false;
        }
    }
    return res;
}


int main(){
    int u,v;
    cin>>N>>u>>v;
    rep(i,N-1){
        int a,b;
        cin>>a>>b;
        G[a].pb(b);
        G[b].pb(a);
    }
    
    rep(i,N+1){
        if(G[i].size()>=4){
            cout<<"No"<<endl;
            return 0;
        }
    }
    
    bool used[100003]={};
    used[u]=used[v]=true;
    
    bool res = dfs(u,v,2,used);
    
    if(res)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
}

Measured memory_bytes: 19656
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

#define CLR(a) memset((a), 0 ,sizeof(a))

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

int main(void){
  string s;
  cin >> s;
  bool flag = false;
  for(int i=0;i<s.length();i++){
    if(s[i] == 'C') flag = true;
    if(flag && s[i] == 'F'){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
while True:
    m, f, r = map(int, input().split())
    if m == f == r == -1:
        break
    else:
        if m == -1 or f == -1:
            ans = "F"
        elif m + f >= 80:
            ans = "A"
        elif m + f >= 65:
            ans = "B"
        elif m + f >= 50:
            ans = "C"
        elif m + f >= 30:
            if r >= 50:
                ans = "C"
            else:
                ans = "D"
        else:
            ans = "F"
    print(ans)


Measured memory_bytes: 5596