akhauriyash/Code-Regression huggingface dataset:
/**
	如约而至是多么美好的词，等的辛苦，却不辜负
**/
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<vector>
typedef long long ll;
const int maxn = 1e6 + 7;
const int mod = 1e9 + 7;
const int INF = 0x7fffffff;
map<ll,ll>mp;
queue<int>q1;
deque<int>q2;
stack<int>st;
ll n, m,x=0,y,z,h,t,q,l,temp=0,cnt1=0,cnt2=0,s[maxn],st2[maxn],w[maxn],ans = 0, k,flag1;
ll dp[maxn],a[maxn];
string s1,s2[maxn];
int main(){
    scanf("%lld%lld",&n,&l);
    for(ll i=1;i<=n;i++)
        scanf("%lld",&a[i]);
    for(ll i=1;i<n;i++)
    {
        if(a[i]+a[i+1]>=l){
            temp=1;
            flag1=i;
            break;
        }
    }
    if(!temp) printf("Impossible");
    else{
        printf("Possible\n");
        for(ll i=1;i<flag1;i++)
            printf("%lld\n",i);
        for(ll i=n-1;i>=flag1;i--)
            printf("%lld\n",i);
    }
	return 0;
}


Measured memory_bytes: 13056
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  string s;
  cin >> s;
  s += '.';
  s += '.';
  if(c < d) {
    for(int i = a - 1; i < d - 1; i++){
      if(s[i] == s[i + 1] && s[i] == s[i + 2] && s[i] == '#'){
        cout << "No\n";
        return 0;
      }
    }
    cout << "Yes\n";
  }else{
    for(int i = a - 1; i < c - 1; i++){
      if(s[i] == s[i + 1] && s[i] == s[i + 2] && s[i] == '#'){
        cout << "No\n";
        return 0;
      }
    }
    bool ok = false;
    for(int i = b - 2; i < d - 1; i++){
      if(s[i] == s[i + 1] && s[i] == s[i + 2] && s[i] == '.'){
        ok = true;
      }
    }
    if(ok){
      cout << "Yes\n";
    }else{
      cout << "No\n";
    }
  }
  
  return 0;
}

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

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  string S;
  cin>>S;
  
  int check_1=0;
  
  int check_2=0;
  
  
  for(int i=0;i<S.size();i++){
    if(i%2==0){
      if(S[i]=='1'){
        check_1++;
      }
    }
    else if(i%2==1){
      if(S[i]=='0'){
        check_1++;
      }
    }
  }
  
  for(int i=0;i<S.size();i++){
    if(i%2==0){
      if(S[i]=='0'){
        check_2++;
      }
    }
    else{
      if(S[i]=='1'){
        check_2++;
      }
    }
  }
  
  cout<<min(check_1,check_2)<<endl;
}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define ppb pop_back
#define mp  make_pair
int main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	string str;
	cin>>str;
	if(str=="SUN"){
		cout<<7<<endl;
	}
	if(str=="SAT"){
		cout<<1<<endl;
	}
	if(str=="FRI"){
		cout<<2<<endl;
	}
	if(str=="THU"){
		cout<<3<<endl;
	}
	if(str=="WED"){
		cout<<4<<endl;
	}
	if(str=="TUE"){
		cout<<5<<endl;
	}
	if(str=="MON"){
		cout<<6<<endl;
	}
}

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

ll dp[100][100000];
ll fun(ll *w,ll *v,ll i,ll n,ll W){
    if(i>=n){
        return 0;
    }
    if(dp[i][W]!=-1){
        return dp[i][W];
    }
    if(W-w[i]>=0){
        return dp[i][W]=max(v[i]+fun(w,v,i+1,n,W-w[i]),fun(w,v,i+1,n,W));
    }
    return dp[i][W]=fun(w,v,i+1,n,W);
}

int main() 
{ 
ll n,W;
cin>>n>>W;
ll w[n],v[n];
for(int i=0;i<n;i++){
    cin>>w[i]>>v[i];
}
memset(dp,-1,sizeof(dp));
cout<<fun(w,v,0,n,W);

} 


Measured memory_bytes: 78336
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var s = cin.next();

            if(s.Length % 2 == 1)
            {
                Console.WriteLine("No");
                return;
            }

            for (int i = 0; i < s.Length; i+=2)
            {
                if (!(s[i] == 'h' && s[i + 1] == 'i'))
                {
                    Console.WriteLine("No");
                    return;
                }
            }
            Console.WriteLine("Yes");

        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
         
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007  
const int N = 100001; 



void solve(){
	int n,d;cin>>n>>d;
	int dis=d*d;
	int ans=0;
	rep(i,0,n){
		int x,y;cin>>x>>y;
		int cd=x*x+y*y;
		if(cd<=dis)ans++;
	}
	cout<<ans;
    return;
}
         
signed main(){
        IOS;    
        

        int t=1;
        // cin>>t;
        // fac[0] = 1; 
        // for (int i=1 ; i<=2000001; i++) fac[i] = fac[i-1]*i%mod; 
        rep(i,0,t){
            solve();
            cout<<"\n";
        //   cout<<" * "<<t<<"\n";
        }
    //    return 0;
}

Measured memory_bytes: 3648
#!usr/bin/env python3
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def LIR(n): return [LI() for i in range(n)]

#A
s = S()
if s[0] != "A":
    print("WA")
else:
    count = []
    for i in range(2,len(s)-1):
        if s[i] == "C": count.append(i)
    if len(count) != 1:
        print("WA")
    else:
        for i in range(1,len(s)):
            if i not in count:
                if s[i] == s[i].upper():
                    print("WA")
                    quit()
        print("AC")
#B

#C

#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 38512
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>
#include <list>
#include <stack>

typedef long long ll;
using namespace std;
const int mod = 1000000007;
const int MAX = 20*200+1;

vector< vector<int> > dp(21 , vector<int>(MAX, 0));

int main() {

    int n; cin >> n;
    vector<int> q(n);
    for (int i = 0; i < n; i++) {
        cin >> q[i];
    }

    dp[0][0] = 1;

    for (int ind = 0; ind < n; ind++) {
        for (int num = 0; num < MAX; num++) {
            int diff = num - q[ind];
            if (dp[ind][num]) {
                    dp[ind+1][num] = 1;
            }
            if (diff >= 0) {
                if (dp[ind][diff]) {
                    dp[ind+1][num] = 1;
                }
            }
        }
    }

    /*
    cout << '\n';
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j < 50; j++) {
            cout << dp[i][j] << ' ' ;
        }cout << '\n';
    }
    */

    int m; cin >> m;
    for (int i = 0; i < m; i++) {
        int num; cin >> num;
        if (dp[n][num])
            cout << "yes" << '\n';
        else 
            cout << "no" << '\n';
    }

}



Measured memory_bytes: 3264
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define MAX_N 200005
#define LL long long
int n,m,k;
string s;
int sum[12][1005];
bool mp[12][1005];
int ans=99999999;
int a[12];

bool check(int cnt,int j,int la){
	int s=0;
	for(int i=1;i<=cnt;i++){
		s=sum[a[i]][j]-sum[a[i]][la]-sum[a[i-1]][j]+sum[a[i-1]][la];
		if(s>k)return 0;
	}
	return 1;
}

void work(int t){
	int s=t,la=0;
	a[t+1]=n;
	for(int i=1;i<=m;i++)if(!check(t+1,i,la))s++,la=i-1;
	if(check(t+1,m,m-1))ans=min(ans,s);
}

void dfs(int now,int t){
	if(now==n){
		work(t);
		return;
	}
	a[t+1]=now,dfs(now+1,t+1);
	dfs(now+1,t);
}
int main(){
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++){
		cin>>s;
		for(int j=1;j<=m;j++)
			mp[i][j]=s[j-1]-'0',sum[i][j]=sum[i][j-1]+mp[i][j]+sum[i-1][j]-sum[i-1][j-1];
	}
	dfs(1,0);
	cout<<ans;
}

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

int main()
{
  int n,m;
  cin>>n>>m;
  int arr[m];
  for(int i=0;i<m;i++)
    cin>>arr[i];
    
    int sum=0;
    for(int i=0;i<m;i++)
      sum+=arr[i];
      
      if(sum>n)
       cout<<-1;
      else
      cout<<n-sum;
      
      return 0;
 }

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

int main() {
  int n,a;
  cin >> n;
  int i,j,m;
  m=10000000;
  for(i=0;i<n;i++){
    cin >> a;
    j=0;
    while(a%2==0){
      a/=2;
      j++;
    }
    if(j<m){
      m=j;
    }
  }
  cout << m << endl;
}


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

int H, W;

int main()
{
    long N;
		cin >> N;
		vector<long> t(N);
		vector<long> A(N);
		vector<long> B(N);
		for(int i = 0; i < N; i++){
			long buf;
			cin >> buf;
			A[buf - 1] += 1;
			t[i] = buf - 1;
		}
		long ansbuf = 0;
		for(int i = 0; i < N; i++){
			B[i] = (A[i] * (A[i] - 1) - (A[i] - 1) * (A[i] - 2)) / 2;
			ansbuf += (A[i] * (A[i] - 1)) / 2;
		}
		for(int i = 0; i < N; i++){
			cout << ansbuf - B[t[i]] << endl;
		}
		return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    for(;;){
    string s;
    std::cin >> s;
    if(s=="-"){
        exit(0);
    }
    int n;
    std::cin >> n;
    rep(i,n){
        int h;
        std::cin >> h;
        s=s.substr(h)+s.substr(0,h);
    }
    std::cout << s << std::endl;}
}


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

typedef long long ll; // -9,223,372,036,854,775,808 から 9,223,372,036,854,775,807

template <class T> using vec = std::vector<T>;
template <class T> using vec2 = vec<vec<T>>;
template <class T> using vec3 = vec<vec<vec<T>>>;

#define DEBUG
void solve(long long K, long long N, std::vector<long long> A){
    ll dist = K;
    ll Nhouse = N;

    sort(A.begin(), A.end());
    vec<ll> dists(Nhouse);
    for(int i=0; i < Nhouse; i++){
        dists[i] = (A[(i+1) % Nhouse] - A[i] + K) % K;
    }

    auto res = *max_element(dists.begin(), dists.end());
    cout << dist - res << endl;

}

// 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)
int main(){
    long long K;
    scanf("%lld",&K);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(K, N, std::move(A));
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    string s;
    cin >> s;
    rep(i,s.size()){
        if(s[i] == '?') s[i] = 'D';
    }
    cout <<s << endl;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
int a,b,c; 
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>a>>b>>c;
	if(a-b==b-c)  cout<<"YES"<<endl;
	else    cout<<"NO"<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){int b=0;for(auto itr :a){if(b++!=0)cout << " "; cout << itr;} }
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
struct Edge{int to,cap,rev;};
class Dinic{//max flow
public:
    int n;
    vector<vector<Edge> >G;
    vector<int> level,iter;
    Dinic(int size){
        n=size;
        G=vector<vector<Edge> >(n);
    }
    void add_Edge(int from, int to, int cap){
        //rev は逆辺にアクセスできる
        //e = G[from][index]
        //G[e.to][e.rev].to = from,.rev = index
        Edge q={to,cap,int(G[to].size())};
        G[from].emplace_back(q);
        q={from,0,int(G[from].size()-1)};
        G[to].emplace_back(q);
    }
    void bfs(int s){
        level=vector<int>(n,-1);
        queue<int>q;
        level[s]=0;
        q.push(s);
        while(!q.empty()){
            int v=q.front();q.pop();
            for(int i=0;i<G[v].size();i++){
                Edge &e=G[v][i];
                if(e.cap>0&&level[e.to]<0){
                    level[e.to]=level[v]+1;
                    q.push(e.to);
                }
            }
        }
    }
    int dfs(int v,int t, int f) {
        if(v==t)return f;
        for(int &i=iter[v];i<G[v].size();i++){
            Edge &e=G[v][i];
            if(level[v]>=level[e.to]||e.cap<=0) continue;
            int d =dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
        return 0;
    }
    int max_flow(int s,int t) {//from s to t,ford_fulkerson
        int flow=0;
        while(1){
            bfs(s);
            if(level[t]<0)return flow;
            iter=vector<int>(n);
            int f;
            while((f=dfs(s,t,INF))>0)flow+=f;
        }
    }
};
signed main(){
    int v,e;
    cin>>v>>e;
    Dinic yebi(v+1);
    rep(i,e){
        int a,b,c;cin>>a>>b>>c;
        yebi.add_Edge(a,b,c);
    }
    cout<<yebi.max_flow(0, v-1)<<endl;
}



Measured memory_bytes: 3184
import copy
N, M = map(int, input().split())

inf = 10 ** 9 + 7
dp = [[inf] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    dp[a][b] = c
    dp[b][a] = c

old_dp = copy.deepcopy(dp)
check = [[False] * N for _ in range(N)]
count = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

count = 0
for i in range(N):
    for j in range(N):
        if old_dp[i][j] != dp[i][j] and old_dp[i][j] != inf:
            count += 1

print(count // 2)


Measured memory_bytes: 9864
#include<bits/stdc++.h>
using namespace std;
#define EPSILON numeric_limits<double>::epsilon()
int main()
{
    int n,l;
    cin >> n >>l;
    int arr[n+1];
    for(int i=1;i<=n;i++)
        arr[i] = l+i-1;
        sort(arr+1,arr+n+1);
    int sum = accumulate(arr+1,arr+n+1,0);
    int in = 1;
    while(in<=n&&arr[in]<0)
        in++;
        if(in==1||in%(n+1)==n)
          sum -= (arr[in]);
          else sum = (abs(sum-arr[in])>abs(sum-arr[in-1])?sum-arr[in-1]:sum-arr[in]);
    //  else sum = min(sum-arr[in],sum-arr[in-1]);
      cout << sum;



}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		StringBuilder sb = new StringBuilder();
		Scanner scan = new Scanner(System.in);
		while(true){
		//Scanner scan = new Scanner(System.in);


		int H = scan.nextInt();
	    int W = scan.nextInt();


	    if(H == 0 && W == 0)break;
	    for(int i = 1;i <= H ;i++){
	    	for(int j = 1;j <= W; j++){
	    		if((i + j)% 2 == 0){

	    			System.out.print("#");
	    		}else{

	    			System.out.print(".");
	    		}

	    	}
	    	System.out.println();

	    }

	    System.out.println();
	   }

	}
}

Measured memory_bytes: 35160
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;

    int sum=0,K=N;
    while(K>0){
        sum+=K%10; K/=10;
    }
    
    if(N%sum==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    
}


Measured memory_bytes: 256
// ConsoleApplication22.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//

#include <cstdio>
#include<iostream>
#include<vector>
#include<utility>
#include<cctype>
#include<algorithm>

using namespace std;

int H, W;
char C[50][52];
vector<pair<int, int> > p[256];
bool memed[52][52][52][52];
int mem[52][52][52][52];

int rec(int hy, int hx, int ty, int tx) {
	if (ty < hy || tx < hx || C[hy][hx] == '#')return -1e9;
	if (hy == ty&&hx == tx)return 0;
	if (memed[hy][hx][ty][tx]++)return mem[hy][hx][ty][tx];
	int mx = max(rec(hy + 1, hx, ty, tx), rec(hy, hx + 1, ty, tx));//??????????????£?????´???
	if (islower(C[hy][hx])) {
		for (auto e : p[toupper(C[hy][hx])]) {
			if (ty < e.first || tx < e.second || e.first < hy || e.second < hx)continue;
			int sx = -1e9;
			if (hy + 1 == e.first&&hx == e.second || hy == e.first&&hx + 1 == e.second) {
				sx = 1;
			}else {
				for (int i = 0; i < 2; i++) {
					for (int j = 0; j < 2; j++) {
						sx = max(sx, rec(hy + i, hx + (i ^ 1), e.first - j, e.second - (j ^ 1)) + 1);
					}
				}
			}
			if (e.first == ty&&e.second == tx) {
				mx = max(mx, sx);
			}
			else {
				for (int i = 0; i < 2; i++) {//00,01->(0,1),(1,0)
					mx = max(mx, sx + rec(e.first + i, e.second + (i ^ 1), ty, tx));
				}
			}
		}
	}
	return mem[hy][hx][ty][tx] = mx;
}

int main() {
	while (cin >> H >> W, H | W) {
		fill(***begin(memed), ***end(memed), false);
		for (auto &e : p) {
			e.clear();
		}
		for (int i = 0; i < H; i++) {
			cin >> C[i];
			for (int j = 0; j < W; j++) {
				p[C[i][j]].emplace_back(i, j);
			}
		}
		int ans = rec(0, 0, H - 1, W - 1);
		cout << ((ans < 0) ? -1 : ans) << endl;
	}
}

Measured memory_bytes: 31104
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ll n,k,d;
	cin>>n>>k>>d;
	n = abs(n);
	ll need=n/d;
	if(need>k)
    {
        n-=d*k;
       cout<<n<<endl;
    }
    else
    {
        n-=need*d;
        k-=need;
        //cout<<n<<" "<<k<<" "<<d<<endl;
        ll a = n;
        ll b = abs(n-d);
        //cout<<a<<" "<<b<<endl;
        if(k&1)
        {
            cout<<b<<endl;
        }
        else
            cout<<a<<endl;
    }

}



Measured memory_bytes: 3624
#include <iostream>

using namespace std;

const int N = 8;
int rows[8];
bool cols[8];
bool dpos[15];
bool dneg[15];
bool skip[8];

void displayBoard(){
	for(auto i = 0; i < N; ++i){
		for(auto j = 0; j < N; ++j){
			if(j == rows[i] && cols[j]) cout << 'Q';
			else cout << '.';
		}
		cout << endl;
	}
}

void putQueen(int i){
	if(i == N){
		displayBoard();
		return;
	}
	if(skip[i]){
		putQueen(i + 1);
		return;
	}
	for(auto j = 0; j < N; ++j){
		if(cols[j] || dpos[i + j] || dneg[i - j + N - 1]) continue;
		rows[i] = j;
		cols[j] = dpos[i + j] = dneg[i - j + N - 1] = true;
		putQueen(i + 1);
		cols[j] = dpos[i + j] = dneg[i - j + N - 1] = false;
	}
}

int main(){
	for(auto i = 0; i < N; ++i){
		rows[i] = 0;
		cols[i] = false;
		skip[i] = false;
	}
	for(auto i = 0; i < 2 * N - 1; ++i){
		dpos[i] = false;
		dneg[i] = false;
	}
	// memset(rows, 0, sizeof(rows));
	// memset(cols, false, sizeof(cols));
	// memset(dpos, false, sizeof(dpos));
	// memset(dneg, false, sizeof(dneg));

	int k;
	cin >> k;
	for(auto i = 0; i < k; ++i){
		int r, c;
		cin >> r >> c;
		skip[r] = true;
		rows[r] = c;
		cols[c] = dpos[r + c] = dneg[r - c + N - 1] = true;
	}
	// displayBoard();
	putQueen(0);
}


Measured memory_bytes: 3108
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N,K=map(int,input().split())
A=[int(input()) for i in range(N)]
class SegmentTree:
    def __init__(self,n,segfunc,ide_ele):
        self.segfunc=segfunc
        self.ide_ele=ide_ele
        self.num=2**(n-1).bit_length()
        self.dat=[ide_ele]*2*self.num
    
    def init(self,iter):
        for i in range(len(iter)):
            self.dat[i+self.num]=iter[i]
        for i in range(self.num-1,0,-1):
            self.dat[i]=self.segfunc(self.dat[i*2],self.dat[i*2+1])
    
    def update(self,k,x):
        k+=self.num
        self.dat[k]=x
        while k:
            k//=2
            self.dat[k]=self.segfunc(self.dat[k*2],self.dat[k*2+1])
    
    def query(self,p,q):
        if q<=p:
            return self.ide_ele
        p+=self.num
        q+=self.num-1
        res=self.ide_ele
        while q-p>1:
            if p&1==1:
                res=self.segfunc(res,self.dat[p])
            if q&1==0:
                res=self.segfunc(res,self.dat[q])
                q-=1
            p=(p+1)//2
            q=q//2
        if p==q:
            res=self.segfunc(res,self.dat[p])
        else:
            res=self.segfunc(self.segfunc(res,self.dat[p]),self.dat[q])
        return res
MAX=max(A)+1
s=SegmentTree(MAX,lambda a,b: max(a,b),0)

s.update(A[0],1)
ans=1

for x in A[1:]:
    p=max(x-K,0)
    q=min(x+K+1,MAX)
    res=s.query(p,q)
    s.update(x,res+1)
    ans=max(ans,res+1)
print(ans)

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

int main(void)
{
	long long n, a, b;
	long long min, max;

	cin >> n >> a >> b;

	if (a > b) {
		cout << 0 << endl;
		return (0);
	}

	if (n == 1 && a != b) {
		cout << 0 << endl;
		return (0);
	}

	min = a * (n - 1) + b;
	max = b * (n - 1) + a;

	cout << max - min + 1 << endl;

	return (0);

}

Measured memory_bytes: 256
S = input()
T = input()
len_T = len(T)

min_ = 1000
for i in range(len(S) - len_T + 1):
  s = S[i:i+len_T]
  cnt = 0
  for j in range(len_T):
    if s[j] != T[j]: cnt += 1
  min_ = min(min_, cnt)
print(min_)   

Measured memory_bytes: 9064
a = input()
b = list(a)
k = int(''.join([b[0] for _ in range(len(b))]))
if k >= int(a):
    print(k)
else:
    if b[0] != '9':
        print(int(''.join([str(int(b[0]) + 1) for _ in range(len(b))])))
    else:
        print(int(''.join(['1' for _ in range(len(b)+1)])))

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Edge
{
public:
    int to, cost;
    Edge(){};
    Edge(int to0, int cost0){to = to0; cost = cost0;}
};

long long minSpanningTree(const vector<vector<Edge> >& edges)
{
    int n = edges.size();
    vector<bool> used(n, false);
    int usedNum = 0;
    vector<int> minCost(n, INT_MAX);
    priority_queue<pair<int,int> ,vector<pair<int,int> >, greater<pair<int,int> > > q;
    q.push(make_pair(0, 0));

    long long ret = 0;
    while(!q.empty()){
        pair<int, int> p = q.top();
        q.pop();
        int v = p.second;
        if(used[v])
            continue;
        ret += p.first;
        used[v] = true;
        if(++usedNum == n)
            return ret;
        for(unsigned i=0; i<edges[v].size(); ++i){
            Edge e = edges[v][i];
            if(!used[e.to] && e.cost < minCost[e.to]){
                minCost[e.to] = e.cost;
                q.push(make_pair(e.cost, e.to));
            }
        }
    }
    return -1;
}


int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        vector<vector<Edge> > edges(n);
        for(int i=0; i<m; ++i){
            int a, b, cost;
            char c;
            cin >> a >> c >> b >> c >> cost;
            edges[a].push_back(Edge(b, cost/100-1));
            edges[b].push_back(Edge(a, cost/100-1));
        }

        cout << minSpanningTree(edges) << endl;
    }
}

Measured memory_bytes: 0
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        Integer[] a = new Integer[N];
        for (int i = 0; i < N; i++) {
            a[i] = scan.nextInt();
        }
        Arrays.sort(a, Comparator.reverseOrder());
        int alice_total = 0;
        int bob_total = 0;
        for (int k = 0; k<N; k++) {
            if (k%2 == 0) {
                alice_total+=a[k];
            } else {
                bob_total += a[k];
            }
        }
        System.out.println(alice_total - bob_total);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100;
const ll MOD = 1000000007;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


ll mpow(ll x, ll n){//繰り返し二乗法 計算量O(logN)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans * x % MOD;
        x = x * x % MOD;
        n  = n >> 1;
    }
    return ans;
}


int main(){
    int n, a, b;
    cin >> n >> a >> b;
    //何も取り除かない場合2^n - 1通り　nCa とnCbを引けばいい
    ll ans = mpow(2, n) - 1;
    ans %= MOD;
    ll tmp1 = 1, tmp2 = 1;
    rep(i, a){
        tmp1 *= i + 1;
        tmp2 *= n - i;
        tmp1 %= MOD;
        tmp2 %= MOD;
    }
    tmp1 = mpow(tmp1, MOD - 2);
    tmp2 *= tmp1;
    tmp2 %= MOD;
    ans -= tmp2;
    if(ans < 0) ans += MOD;
    ans %= MOD;


    tmp1 = 1;
    tmp2 = 1;
    rep(i, b){
        tmp1 *= i + 1;
        tmp2 *= n - i;
        tmp1 %= MOD;
        tmp2 %= MOD;
    }
    tmp1 = mpow(tmp1, MOD - 2);
    tmp2 *= tmp1;
    tmp2 %= MOD;
    ans -= tmp2;
    if(ans < 0) ans += MOD;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int n, ans = 0;
    char a[110], b[110], c[110];
    scanf("%d", &n);
    scanf("%s%s%s", a, b, c);

    for (int i = 0; i < n; i++)
    {
        if (a[i] == b[i])
        {
            if (b[i] == c[i])
            {
                continue;
            }
            else
            {
                ans++;
            }
        }
        else if (b[i] == c[i])
        {
            ans++;
        }
        else if (c[i] == a[i])
        {
            ans++;
        }
        else
        {
            ans += 2;
        }
    }
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> pl;
const ll INF=100000000000000001;
const double PI=3.141592653589;


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

  int ans=0;
  if(b*2<a){
    ans=a-b*2;
  }

  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val T = Array(N) { readLine()!!.toLong() }

    println(T.fold(1L, ::lcm))
}

tailrec fun gcd(x: Long, y: Long): Long = if (y == 0L) x else gcd(y, x % y)

/**
 * Calculate the least common multiple of `x` and `y`
 */
fun lcm(x: Long, y: Long): Long = x / gcd(x, y) * y


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

string solve(int sx, int sy, int tx, int ty){
	int i;
	string str;
	for (i=0; i<ty-sy; i++) str.push_back('U');
	for (i=0; i<tx-sx; i++) str.push_back('R');
	for (i=0; i<ty-sy; i++) str.push_back('D');
	for (i=0; i<tx-sx; i++) str.push_back('L');
	str.push_back('L');
	for (i=0; i<ty-sy+1; i++) str.push_back('U');
	for (i=0; i<tx-sx+1; i++) str.push_back('R');
	str.push_back('D');
	str.push_back('R');
	for (i=0; i<ty-sy+1; i++) str.push_back('D');
	for (i=0; i<tx-sx+1; i++) str.push_back('L');
	str.push_back('U');
	return str;
}

int main(){
	int sx, sy, tx, ty;
	cin >> sx;
	cin >> sy;
	cin >> tx;
	cin >> ty;
	string answer = solve(sx, sy, tx, ty);
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())

a = [[False] * 14 for i in range(4)]

t = 'SHCD'
dic = {t[i]: a[i] for i in range(4)}

for i in range(n):
    k, no = input().split()
    no = int(no)
    dic[k][no] = True

for i in range(4):
    for j in range(1, 14):
        if not a[i][j]:
            print(t[i], j)


Measured memory_bytes: 5600
# Aizu Problem ITP_1_5_D: Structured Programming
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")

res = []


def CHECK_NUM2(n, i):
    x = i
    if x % 3 == 0:
        res.append(i)
    else:
        while True:
            if x % 10 == 3:
                res.append(i)
                break
            x //= 10
            if x == 0:
                break
    i += 1
    if i <= n:
        CHECK_NUM(n, i)
        
def CHECK_NUM(n, i):
    while True:
        x = i
        if x % 3 == 0:
            res.append(i)
        else:
            while True:
                if x % 10 == 3:
                    res.append(i)
                    break
                x //= 10
                if x == 0:
                    break
        i += 1
        if i > n:
            break
        
def call(n):
    CHECK_NUM(n, 1)
    

n = int(input())
#n=1000
call(n)
print(' ' + ' '.join([str(r) for r in res]))

Measured memory_bytes: 8228
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD  998244353 // 1000000007 // //100000000
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << " "; cout << endl;}

ll lx[4] = {0, 0, 1, -1};
ll ly[4] = {1, -1, 0, 0};
ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}
ll lcm(ll a, ll b) {return (a/__gcd(a, b))*b; }

void solve(){
    ll n, m;
    cin >> n >> m;
    cout << (int)((1900*m + 100*(n-m))*pow(2, m));
}

int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define INF 2e8
#define all(a) a.begin(), a.end()

int main() {
  /*105, 135, 165, 189, 195*/
  int n;
  cin >> n;
  if (n < 105)
    printf("%d", 0);
  else if (n < 135)
    printf("%d", 1);
  else if (n < 165)
    printf("%d", 2);
  else if (n < 189)
    printf("%d", 3);
  else if (n < 195)
    printf("%d", 4);
  else
    printf("%d", 5);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner t = new Scanner(System.in);
        
        int a = t.nextInt();
        int b = t.nextInt();
        int c = t.nextInt();
        
        int d = b/a;
        
        if (d > c){
            System.out.println(c);
        } else {
            System.out.println(d);
        }
    }   
}

Measured memory_bytes: 21844
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <regex>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
const long long INF =  999999999;

int main(){
  int n;
  string s,t;
  cin>>n;
  cin>>s>>t;
  REP(i,s.length()){
    cout<<s[i]<<t[i];
  }
  cout<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
ll LCM(ll a,ll b){return (a*b)/GCD(a,b);}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int n;
	cin >> n;
	int a[n];
	int odd[100010] = {};
	int even[100010] = {};
	REP(i, n){
		cin >> a[i];
		if (i % 2 == 0) odd[a[i]]++;
		else even[a[i]]++;
	}
	pair<int, int> odd_mid = {0, 0};
	pair<int, int> odd_max = {0, 0};
	pair<int, int> even_mid = {0, 0};
	pair<int, int> even_max = {0, 0};
	REP(i, 100010){
		if (odd[i] > odd_max.second){
			odd_mid = odd_max;
			odd_max = {i, odd[i]};
		}
		else if (odd[i] > odd_mid.second){
			odd_mid = {i, odd[i]};
		}
		if (even[i] > even_max.second){
			even_mid = even_max;
			even_max = {i, even[i]};
		}
		else if (even[i] > even_mid.second){
			even_mid = {i, even[i]};
		}
	}

/*	cout << "odd_max = "  << odd_max.first << " " << odd_max.second << endl;
	cout << "odd_mid = "  << odd_mid.first << " " << odd_mid.second << endl;
	cout << "even_max = " << even_max.first << " " << even_max.second << endl;
	cout << "even_mid = " << even_mid.first << " " << even_mid.second << endl;
*/
	if (odd_max.first != even_max.first) cout << n/2 - odd_max.second + n/2 - even_max.second << endl;
	else {
		cout << min(n/2-odd_mid.second + n/2-even_max.second, 
					n/2-odd_max.second + n/2-even_mid.second) << endl;
					

	}

}


Measured memory_bytes: 1408
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def isqrt(n):
    if n > 0:
        x = 1 << (n.bit_length() + 1) // 2
        y = (x + n // x) // 2
        while y < x:
            x = y
            y = (x + n // x) // 2
        return x
    elif n == 0:
        return 0
    else:
        raise ValueError("isqrt() argument must be nonnegative")


def main():
    N = int(readline())

    ans = [0] * (N + 1)
    sqrt_n = isqrt(N)
    for x in range(1, sqrt_n + 1):
        for y in range(1, sqrt_n + 1):
            for z in range(1, sqrt_n + 1):
                s = x * x + y * y + z * z + x * y + y * z + z * x
                if s <= N:
                    ans[s] += 1

    print(*ans[1:], sep='\n')

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 74744
#include <iostream>
#include<math.h>
#include<iomanip>
using namespace std;
int main(void){
    double r,S,l;
    cin >> r;
    S=M_PI*r*r;
    l=2*M_PI*r;
    cout << fixed << setprecision(6) << S << " " << l << endl;
}



Measured memory_bytes: 3248
#include <stdio.h>

int main(void) {
  int D;
  scanf("%d", &D);

  if(D == 25)
    printf("Christmas\n");
  else if(D == 24)
    printf("Christmas Eve\n");
  else if(D == 23)
    printf("Christmas Eve Eve\n");
  else if(D == 22)
    printf("Christmas Eve Eve Eve\n");
  
  return 0;
}


Measured memory_bytes: 128
t=[]
for i in range(5):
    time=int(input())
    amari=10-time%10
    amari=0 if amari==10 else amari
    t.append((amari,time))

t.sort()
ans=0
for i in range(5):
    if i<4:
        ttt=t[i][0]+t[i][1]
    else:
        ttt=t[i][1]
    ans+=ttt
print(ans)

Measured memory_bytes: 3060
H,W,K = list(map(int,input().split()))

c = [[] for _ in range(H)]
s = [[] for _ in range(H)]
t = [[] for _ in range(W)]

for i in range(H):
    c[i] = input()
for i in range(H):
    s[i] = c[i].count("#")

num_total = 0

for j in range(W):
    t[j] = 0
    for i in range(H):
        if c[i][j] == "#":
            t[j] += 1
            num_total += 1


ans = 0
for i in range(2**len(s)):
    num0 = 0
    for j in range(len(s)):
        if ((i >> j) & 1):
            num0 += s[j]
    for k in range(2**len(t)):
        num = num0
        for l in range(len(t)):
            if ((k >> l) & 1):
                num += t[l]
                for j in range(len(s)):
                    if ((i >> j) & 1):
                        if c[j][l] == "#":
                            num -= 1
        if num_total - num == K:
            ans += 1

print(ans)


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

#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end()

using LL   =  long long;
using pii  =  pair <int, int>;
using vii  =  vector <pii>;

const int INF = INT_MAX;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

int n, h;
int A[N];
int B[N];

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

    cin>>n>>h;

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

    vii v;
    for(int i = 1; i <= n; i++)
    {
        v.pb({A[i], 1});
        v.pb({B[i], 0});
    }

    sort(all(v));

    int i = v.size()-1, moves = 0;
    while(h > 0) {
        if(v[i].s == 0) {
            h -= v[i].f;
            i--, moves++;
        }
        else {
            moves += ceil(1.0 * h / v[i].f) + 1e-9;
            break;
        }
    }

    cout<<moves<<"\n";
    return 0;
}


Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;

int main() {
	int A, B;
	cin >> A >> B;
	int n = 64;
	vector<vector<string>> data0(n / 2, vector<string>(n, "."));
	vector<vector<string>> data1(n / 2, vector<string>(n, "#"));
	for (int i = 0; i < B - 1; ++i) {
		data0[2 * (i / (n / 2))][2 * (i % (n / 2))] = "#";
	}
	for (int i = 0; i < A - 1; ++i) {
		data1[1 + 2 * (i / (n / 2))][2 * (i % (n / 2))] = ".";
	}
	cout << n << " " << n << endl;
	for (int i = 0; i < (n / 2); ++i) {
		for (int j = 0; j < n; ++j) {
			cout << data0[i][j];
		}
		cout << endl;
	}
	for (int i = 0; i < (n / 2); ++i) {
		for (int j = 0; j < n; ++j) {
			cout << data1[i][j];
		}
		cout << endl;
	}
}


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

int main(){
  int n,k;
  cin >>n >>k;
  if(n%k == 0) cout << 0 << endl;
  else cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define VLA valarray<long long>
#define VVLA vector<VLA>
using namespace std;

int main() {
    int n, m, l;
    cin >> n >> m >> l;
    VVLA A(n, VLA(m));
    VVLA B(l, VLA(m));
    REP(i, n) REP(j, m) cin >> A.at(i)[j];
    REP(i, m) REP(j, l) cin >> B.at(j)[i];
    VLA ans(m);
    REP(i, n) REP(j, l) {
        ans = A.at(i) * B.at(j);
        cout << ans.sum();
        j != l-1 ? cout<<" " : cout<<endl;}
}

Measured memory_bytes: 3200
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val N = sc.nextInt
  val A = Array.fill(N)(sc.nextLong)

  val z = A.foldLeft((0L, 0L)) { case ((sum, prevHeight), height) => if (height >= prevHeight) (sum, height) else (sum + prevHeight - height, prevHeight) }._1

  println(z)
}


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


int main()
{
  string s;
  cin >> s;
  if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
    cout << "Bad\n";
  else
    cout << "Good\n";
  return 0;
}

Measured memory_bytes: 3560
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    R, C, K, *RCV = map(int, read().split())

    item = dict()
    for r, c, v in zip(*[iter(RCV)] * 3):
        item[(r - 1, c - 1)] = v

    dp = [[0] * (C + 1) for _ in range(R + 1)]
    for i in range(R):
        v = [0] * 4
        for j in range(C):
            for k in range(4):
                if v[k] < dp[i][j + 1]:
                    v[k] = dp[i][j + 1]
            if (i, j) in item:
                for k in range(2, -1, -1):
                    if v[k + 1] < v[k] + item[(i, j)]:
                        v[k + 1] = v[k] + item[(i, j)]
            dp[i + 1][j + 1] = v[3]

    print(dp[R][C])

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 206108
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    int N, K;
    scan(N);
    scan(K);

    auto x = new int[](N);
    x = readln.split.to!(int[]);

    int ans;

    foreach (i ; 0 .. N) {
        ans += min(2 * x[i], 2 * (K - x[i]));
    }

    writeln(ans);
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

for i in range(1,N+1):
    tmpstr = str(i)
    tmplist = list(tmpstr)
    tmpsum = 0
    for j in tmplist:
        tmpsum += int(j)
    
    if tmpsum >= A and tmpsum <= B:
        goal += i

print(goal)


Measured memory_bytes: 2940
#include<stdio.h>
#include<algorithm>
using namespace std;
int d[120];
int main(){
	int a,b,c;scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<a;i++)scanf("%d",d+i);
	for(int i=0;i<a;i++){
		for(int j=0;j<=b+c;j+=d[i]){
			if(b-c<=j&&j<=b+c){
				printf("%d\n",i+1);
				return 0;
			}
		}
	}
	printf("-1\n");
}

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

int main() {

  string s, p;
  cin >> s >> p;

  s += s;

  for ( long long int i = 0; i < s.size(); i++ ) {

    if ( s.substr( i, p.size() ) == p ) {
      cout << "Yes" << endl;
      return 0;
    }

  }

  cout << "No" << endl;
  return 0;

  return 0;

}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define vi vector<int>
#define tests int t; cin>>t; while(t--)
#define ll long long
#define vll vector<long long>

using namespace std;

char c[10]={'0','1','2','3','4','5','6','7','8','9'};

int ind(char d){
    int i=0; 
    while(c[i]!=d) i++;
    return i;
}


void solve(){
    
    string s;
    cin>>s;
    int n=s.length();
    int sum=0;
    for(int i=0; i<n; i++){
        sum+=ind(s[i]);
    }
    if(sum%9==0){
        cout<<"Yes"<<endl;
        return;
    }
    cout<<"No"<<endl;
}


int main(){
    
   
    solve();
}

Measured memory_bytes: 3728
N = int(input())
A = list(map(int,input().split()))

cnt = 0
check = True
while check:
  for i in range(N):
    if A[i] % 2 == 1:
      check = False
      break
    else:
      A[i] //= 2
  else:
    cnt += 1
    
print(cnt)

Measured memory_bytes: 9060
#include<stdio.h>
#include<string.h>
#include<math.h>

int main(){
	double tyo[20][2],a,b,c,z,s;
	int n,i,j;
	
	s=0;
	n=0;
	while(~scanf("%lf,%lf",&tyo[n][0],&tyo[n][1])){
		++n;
	}
	
	for(i=1;i<n-1;i++){
		a=sqrt(pow(tyo[0][0]-tyo[i][0],2)+pow(tyo[0][1]-tyo[i][1],2));
		b=sqrt(pow(tyo[0][0]-tyo[i+1][0],2)+pow(tyo[0][1]-tyo[i+1][1],2));
		c=sqrt(pow(tyo[i+1][0]-tyo[i][0],2)+pow(tyo[i+1][1]-tyo[i][1],2));
		z=(a+b+c)/2;
		
		s+=sqrt(z*(z-a)*(z-b)*(z-c));
	}
	
	printf("%lf\n",s);
}

Measured memory_bytes: 0
import java.util.*;
import java.lang.Math;
import java.text.DecimalFormat;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    double r = sc.nextDouble();
    sc.close();

    // r * r * 3.14
    double area = r * r * Math.PI;
    DecimalFormat f = new DecimalFormat("0.00000");
    System.out.print(f.format(area) + " ");
    // 2 * r * 3.14
    double circleLength = 2 * r * Math.PI;

    System.out.print(circleLength);
  }
}


Measured memory_bytes: 28020