akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassLibrary1
{
    public class ListNode
    {
        public int val;
        public ListNode next;
        public ListNode(int x) { val = x; }
    }


    public class Class1
    {
        static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long, long>, long>();


        static void Main(string[] args)
        {

            var nn = ReadLong();
            var aa = ReadString();


            var res = 0;

            for(int i=0; i<nn; i++)
            {
                if (aa.StartsWith("ABC")) res++;
                aa = aa.Substring(1);
            }

            Console.WriteLine(res);



        }

        class SortedMap
        {
            public long[][] elm = new long[100000][];
            public int index = 0;

            public SortedMap(long[] aa)
            {
                Array.Sort(aa);

                long tmp = 0;
                for(int i=0; i<aa.Length; i++)
                {
                    if(tmp != aa[i])
                    {
                        tmp = aa[i];
                        elm[index] = new long[2];
                        elm[index][0] = aa[i];
                        elm[index][1] = 1;
                        index++;
                    } else
                    {
                        elm[index][1]++;
                    }

                }

            }
        }


        class BitArr
        {
            public bool[] bitArr = new bool[64];

            public BitArr(long l)
            {
                var ll = l;
                for(int i=0; i<64; i++)
                {
                    bitArr[i] = (ll % 2) == 1;
                    ll = ll / 2;
                }
            }
        }

        public static int Digit(long num)
        {
            // Mathf.Log10(0)はNegativeInfinityを返すため、別途処理する。
            return (num == 0) ? 1 : ((int)Math.Log10(num) + 1);
        }

        public static long nCm(long n, long m, long mod)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            var a = n * nCm(n - 1, m - 1, mod) / m;
            //            return a % mod;
            return a;
            //return a % 1000000007;
        }

        private static string ReadString()
        {
            return Console.ReadLine();
        }
        private static string[] ReadStringArr()
        {
            return Console.ReadLine().Split(' ');
        }
        private static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadLongArr()
        {
            string[] s = ReadStringArr();
            long[] l = new long[s.Length];
            for(int i=0; i<l.Length; i++)
            {
                l[i] = long.Parse(s[i]);
            }

            return l;
        }
    }

}


Measured memory_bytes: 13408
#include <iostream>
#include <cmath>
#include <vector>
#include <climits>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> v;
    for(int i = 0;i < n;i++)
    {
        int a;
        cin >> a;
        v.push_back(a);
    }
    int c = 0;
    for(int i = 0;i < n;i++)
    {
        int minj = i;
        for(int j = i;j < n;j++)
        {
            if(v.at(j) < v.at(minj))
            {
                minj = j;
            }
        }
        if(i != minj)
        {
            int t = v.at(i);
            v.at(i) = v.at(minj);
            v.at(minj) = t;
            c++;
        }
    }
    for(int i = 0;i < n;i++)
    {
        cout << v.at(i);
        if(i + 1 != n)
        {
            cout << " ";
        }
        else
        {
            cout << endl;
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 1220
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <algorithm>

#include <stdio.h>
#include <stdlib.h>

using namespace std;

int main(int argc, char *argv[]){

  int N;
  int K;
  cin >> N;
  cin >> K;
  int mul = 1;
  for(int i = 0; i < N; i++){
    if(mul < K){
      mul *= 2;
    }else{
      mul += K;
    }
  }
  cout << mul << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define INF 1e8
#define EPS 1e-9

#define rep(i,n) for(int i=0;i<n;i++)
#define p pair<int,int>
#define P pair<int,double>
#define mp make_pair

int w,h,used[60][10],cur,no,up[150][4],upno[150],sum[150],xl[150],xr[150],dx[]={1,0,-1,0},dy[]={0,1,0,-1};
double gx[150];
char m[60][10];
p b[150][4];

void dfs(int y,int x,char c){
	b[cur][no++]=mp(y,x);
	if(no==4){cur++;no=0;}
	used[y][x]=1;
	rep(i,4){
		int ny=y+dy[i],nx=x+dx[i];
		if(ny>=0&&ny<h&&nx>=0&&nx<w&&m[ny][nx]==c&&!used[ny][nx])dfs(ny,nx,c);
	}
}

P calc(int n){
	int m=1;
	double g=gx[n];
	rep(i,upno[n]){
		P u=calc(up[n][i]);
		m+=u.first;
		g+=u.second;
	}
	return mp(m,g);
}

int main(){
	while(cin>>w>>h&&w){
		rep(i,h)fill(used[i],used[i]+w,0);
		rep(i,150)fill(up[i],up[i]+4,-1);
		fill(upno,upno+150,0);
		fill(xl,xl+150,99);
		fill(xr,xr+150,-1);
		fill(gx,gx+150,0.5);
		rep(i,h)rep(j,w)cin>>m[i][j];
		cur=0;no=0;
		rep(i,h)rep(j,w)if(m[i][j]!='.'&&!used[i][j])dfs(i,j,m[i][j]);
		rep(i,cur){
			char c=m[b[i][0].first][b[i][0].second];
			rep(j,4)gx[i]+=(double)b[i][j].second/4;
			rep(j,4){
				int ny=b[i][j].first+1,nx=b[i][j].second;
				if(ny==h||m[ny][nx]!=c&&m[ny][nx]!='.'){
					xl[i]=min(xl[i],nx);
					xr[i]=max(xr[i],nx+1);
				}
			}
			rep(j,4){
				int ny=b[i][j].first-1,nx=b[i][j].second;
				if(ny>=0&&m[ny][nx]!=c&&m[ny][nx]!='.'){
					int bn,ok=1;
					rep(k,cur)rep(l,4)if(ny==b[k][l].first&&nx==b[k][l].second){bn=k;break;}
					rep(k,upno[i])if(bn==up[i][k])ok=0;
					if(ok)up[i][upno[i]++]=bn;
				}
			}
			/*cout<<upno[i]<<" ";rep(j,upno[i])cout<<up[i][j]<<" ";cout<<endl;
			cout<<gx[i]<<" "<<xl[i]<<" "<<xr[i]<<endl;*/
		}
		int ans=1;
		rep(i,cur){
			P c=calc(i);
			double g=c.second/c.first;
			if(g<xl[i]+EPS||xr[i]<g+EPS)ans=0;
		}
		cout<<(ans?"STABLE":"UNSTABLE")<<endl;
	}
}

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

int main(){
	int n;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int i=1;
	int s=0,ma=-1;
	while(i<n){
		i++;
		if(a[i]>a[i-1]){
			ma=max(ma,s);
			s=0;
			continue;
		}
		s++;
	}
	ma=max(ma,s);
	cout<<ma<<endl;
	return 0;
}


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

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

string K;
int D;

ll dp[10002][2][101];
//dp[i][j][k] := i - 1桁目(1-idx)まで決定済みで、これからi番目を決定する
//jが1ならばKとスレスレの状態、0ならばそうでない
//kはその時の各桁の和のmod D

int main() {
	cin >> K >> D;
	dp[0][1][0] = 1;
	for (int i = 0; i <= K.size(); i++) {
		for (int j = 0; j < 2; j++) {
			for (int amari = 0; amari <= D; amari++) {
				dp[i][j][amari] %= MOD;
				int limit = j ? K[i] - '0': 9;
				for (int keta_val = 0; keta_val <= limit; keta_val++) {
					dp[i + 1][(!j) ? 0 : ((keta_val == limit) ? 1 : 0)][(amari + keta_val) % D]
						+= dp[i][j][amari];
				}

			}
		}
	}
	//000...000はレグレーション違反なので、その分を引く
	cout << (dp[K.size()][0][0] + dp[K.size()][1][0] - 1 + MOD) % MOD << endl;

	return 0;
}

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

int main() {
  ll N,M;
  cin>>N>>M;
  graph g(N);
  rep(i,M){
    ll A,B;
    cin>>A>>B;
    A--;
    B--;
    g[A].push_back(B);
  }
  vector<ll> ans;
  ll l = INF;
  rep(i,N){
    queue<ll> bfs;
    vector<ll> d(N,-1);
    d[i] = 0;
    vector<ll> from(N,-1);
    bfs.push(i);
    bool loop = false;
    while(!bfs.empty()){
      ll t = bfs.front();
      bfs.pop();
      for(auto nx:g[t]){
        if(nx==i) {
          loop = true;
          d[i] = d[t] + 1;
          from[i] = t;
          break;
        }
        if(d[nx] != -1) continue;
        d[nx] = d[t] + 1;
        from[nx] = t;
        bfs.push(nx);
      }
      if(loop) break;
    }
    if(loop){
      if(chmin(l,d[i])){
        vector<ll> change;
        ll p = i;
        do{
          change.push_back(p);
          p = from[p];
        }while(p!=i);
        ans = change;
      }
    }
  }
  if(l==INF) cout<<-1<<endl;
  else {
    cout<<l<<endl;
    for(auto x:ans) cout<<x+1<<endl;
  }
}

Measured memory_bytes: 3728
#include<bits/stdc++.h> 
    #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define pb push_back
    #define int long long
    #define swap(x,y) (x^=y^=x^=y)

    #define debug1(a) cerr<<#a<<" = "<<(a)<<endl;
    #define debug2(a,b) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
    #define debug3(a,b,c) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
    #define debug4(a,b,c,d) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

    using namespace std;
    
    #define mod 1000000007
    long long modexpo(long long x, long long p){
        int res = 1;x = x%mod;
        while(p){
            if(p%2)res = res * x;
            p >>= 1;
            x = x*x % mod;
            res %= mod;
        }
        return res;
    }

    struct compare{
        bool operator() (const pair<int,int> a, const pair<int,int> b) const{
            return a.first < b.first;
        }
    };

    int32_t main(){
        IOS
        double w,h,x,y;
        cin >> w >> h >> x >> y;
        double ans = w*h;
        ans /= (double)2;
        int q = 0;
        if(x+x == w && y+y == h){
            q = 1;
        }
        cout << fixed << setprecision(10) << ans << " " << q << endl;
    } 

Measured memory_bytes: 3756
/********************************************************************************
	
	Code by a weak man who named CYJian, and he hopes the code can get more points.

	Algorithm: 

 ********************************************************************************/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

//{{{ FAST IO AND SOME FUNCTIONS
const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define ra read_alpha()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline char read_alpha() { char c = ge; while(!isalpha(c) && c != EOF) c = ge; return c; }
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T> inline void chkmin(T&a, T b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T&a, T b) { a = a > b ? a : b; }
//}}}

const int MAXN = 200010;

ll res;
int f[MAXN];
int c0[MAXN];
int c1[MAXN];
int fa[MAXN];

struct Node {
	int x, c0, c1;

	Node() {}
	Node(int x):x(x) { c0 = ::c0[x], c1 = ::c1[x]; }

	friend bool operator < (Node a, Node b) {
		return 1LL * a.c0 * b.c1 < 1LL * a.c1 * b.c0;
	}
	friend bool operator > (Node a, Node b) {
		return 1LL * a.c0 * b.c1 > 1LL * a.c1 * b.c0;
	}
};

priority_queue<Node, vector<Node>, less<Node> >q;

inline int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
inline void Merge(int x, int y) {
	x = find(x), y = find(y), fa[x] = y;
	res += 1LL * c0[x] * c1[y];
	c0[y] += c0[x], c1[y] += c1[x];
}

int main() {
#ifdef LOCAL
	FILE("");
#endif
	int n = ri;
	for(int i = 2; i <= n; i++) f[i] = ri;
	for(int i = 1; i <= n; i++) fa[i] = i;
	for(int i = 1; i <= n; i++) ri ? c1[i]++ : c0[i]++;
	for(int i = 2; i <= n; i++) q.push(Node(i));
	while(!q.empty()) {
		Node x = q.top(); q.pop();
		if(x.c0 != c0[x.x] || x.c1 != c1[x.x]) continue;
		cerr << x.x << endl;
		Merge(x.x, f[x.x]);
		if(find(x.x) > 1) q.push(Node(find(x.x)));
	} cout << res << endl;
	return 0;
}

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

int main(int argc, char *argv[])
{
  int N;
  cin >> N;
  for (long int i = 0; i <= 2500; ++i) {
    for (long int j = 0; j <= 2500; ++j) {
      long int ue = N * i * j;
      long int shita = 4 * i * j - j * N - i * N;
      if (shita > 0 && (ue / shita) * shita == ue) {
        cout << i << " " << j << " " << ue / shita << endl;
        return 0;
      }
    }    
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string A, B, C;
  cin >> A >> B >> C;
  int a, b;
  a = A.size();
  b = B.size();
  if (A.at(a - 1) == B.at(0) && B.at(b - 1) == C.at(0)) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

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

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  bool contained = false;
  rep(i, N.size()){
    if (N[i] == '9') contained = true;
  }

  if (contained) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){

    /*
    cards[行][列]
    cards[0][j] -> スペードのj+1
    cards[1][j] -> ハートのj+1
    cards[2][j] -> クラブのj+1
    cards[3][j] -> ダイヤのj+1
    */

    char mark;
    unsigned int number, n, i, j;
    unsigned int cards[4][13];

    for( i = 0; i < 4; i++ ){
        for ( j = 0; j < 13; j++ ){
            cards[i][j] = 0;
        }
    }

    cin >> n;

    for( i = 0; i < n; i++ ){

        cin >> mark >> number;

        if ( mark == 'S'){
            cards[0][number-1] = 1;
        }else if ( mark == 'H'){
            cards[1][number-1] = 1;
        }else if( mark == 'C'){
            cards[2][number-1] = 1;
        }else{
            cards[3][number-1] = 1;
        }

    }

    /*
    for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            cout << cards[i][j] << " ";
        }
        cout << endl;
    }

    0 1 1 1 1 1 1 1 1 1 1 1 1 
    1 1 0 1 1 1 0 1 1 1 1 1 1 
    1 1 1 1 1 1 1 1 1 1 1 0 1 
    1 1 1 1 1 1 1 0 1 1 1 1 1

    */

    for( i = 0; i < 4; i++ ){
        for( j = 0; j < 13; j++ ){
            if( cards[i][j] == 0){
                switch(i){
                    case 0:
                        cout << 'S' << " " << j+1 << endl;
                        break;
                    case 1:
                        cout << 'H' << " " << j+1 << endl;
                        break;
                    case 2:
                        cout << 'C' << " " << j+1 << endl;
                        break;
                    case 3:
                        cout << 'D' << " " << j+1 << endl;
                        break;
                }
            }
        }
    }

    return 0;

}


Measured memory_bytes: 3088
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
 
int main(){
int r=read();
puts(r<1200?"ABC":r<2800?"ARC":"AGC");
}

Measured memory_bytes: 256
N, K, *A = map(int, open(0).read().split())
ls = [0]*K.bit_length()
for c in A:
  for i in range(K.bit_length()):
    if c%2==1:
      ls[i] += 1
    c >>= 1
if ls==[]:
  print(sum(A))
  import sys
  sys.exit()
ls = ls[::-1]
s = bin(K)[2:]
m = (2**(len(s)-1))*(N-2*ls[0])
dp1 = [0]*(len(s))
dp2 = [0]*(len(s))
dp1[0] = m
for i in range(1,len(s)):
  c = s[i]
  if c=='1':
    m = (2**(len(s)-i-1))*(N-2*ls[i])
    dp1[i] = dp1[i-1]+m
    if N>2*ls[i]:
      dp2[i] = dp2[i-1]+m
    else:
      dp2[i] = max(dp1[i-1],dp2[i-1])
  else:
    dp1[i] = dp1[i-1]
    if N>2*ls[i]:
      m = (2**(len(s)-i-1))*(N-2*ls[i])
      dp2[i] = dp2[i-1]+m
    else:
      dp2[i] = dp2[i-1]
print(sum(A)+max(dp1[-1],dp2[-1]))

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

int main(){
    int W, H, x, y;
    cin >> W >> H >> x >> y;

    double ans = (double)W * H / 2;
    int flag = 0;
    if(x*2 == W && y*2 == H)
        flag = 1;

    printf("%.10f %d\n", ans, flag);
    
    return 0;
}



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

template <typename T>
void print(const T &v);

int main()
{
    int n, m;
    string s, t;
    cin >> n >> m >> s >> t;
    ll gcd = __gcd(n, m);
    ll lcm = n / gcd * m;

    for (int i = 0; i < gcd; i++)
    {
        if (s[i * n / gcd] != t[i * m / gcd])
        {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << lcm << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
};

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

typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main() {
    int x,y;cin>>x>>y;
    int res,res2;
    res = y - 2*x;
    res2 = 4*x - y;

    if(res>=0 && res%2==0 && res2>=0 && res2%2==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
 
#define MAX 200000
#define SE 2000000000
 
int L[MAX/2+2],R[MAX/2+2];
long v1,v2,v3;
 
long merge(int *A,int n,int left,int right,int mid){
  int i,j,k=0;
  long cnt=0;
 
  int n1=mid-left;
  int n2=right-mid;
 
  for(i=0;i<n1;i++) L[i]=A[left+i];
  for(i=0;i<n2;i++) R[i]=A[mid+i];
  L[n1]=R[n2]=SE;
  i=j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i++];
    }
    else{
      A[k]=R[j++];
      cnt+=n1-i;
    }
  }
  return cnt;
}
 
long mergeSort(int *A,int n,int right,int left){
  int mid;
  long v1,v2,v3; 
 
  if(left+1<right){
    mid=(left+right)/2;
    v1=mergeSort(A,n,mid,left);
    v2=mergeSort(A,n,right,mid);
    v3=merge(A,n,left,right,mid);
    return v1+v2+v3;
  }
  else return 0;
}
 
int main(){
  int A[MAX],n,i;
  long ans=0;
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
 
 
  ans=mergeSort(A,n,n,0);
  printf("%ld\n",ans);
 
  return 0;
}



Measured memory_bytes: 3360
#include <bits/stdc++.h>
#include <vector>
#include <cstdlib>

using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;
const int MAX = 100000;
long long h[MAX], dp[MAX];

void solve() {
  int N,K;
  cin >> N >> K;
  for(int i=0;i<N;i++){
    cin >> h[i];
  }
  for(int i=0;i<MAX;i++){
    dp[i] = INF;
  }
  dp[0] = 0;
  for(int i=0; i<N-1;i++){
    for(int j=1; j<= K; j++){
      if(i+j<N) chmin(dp[i+j], dp[i]+abs(h[i+j]-h[i]));
    }
  }
  cout << dp[N-1] <<endl;
  return;
}
 
int main() {
    solve();
    return 0;
}

Measured memory_bytes: 5052
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<set>
#include<fstream>
#include<map>
#include<vector>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int> P;
signed main() {
	int a, b; cin >> a >> b;
	if (a > b)cout << a - 1 << endl;
	else cout << a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat May 30 21:03:14 JST 2020
 **/

signed main() {
    std::string s;
    std::cin >> s;
    for (char c : s) {
        std::cout << (c == '?' ? 'D' : c);
    }
    std::cout << std::endl;
}


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

int main()
{
  int N, K;
  cin >> N >> K;
  int l[60];
  for (int i = 0; i < N; i++)
  {
    cin >> l[i];
  }
  
  sort(l, l + N, greater<int>());
  int length = 0;
  for (int i = 0; i < K; i++)
  {
    length += l[i];
  }
  cout << length << endl;
}

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

constexpr int MAXN = 1e5;
int height[MAXN];
int cost[MAXN];

int mn(int index, int k)
{
    long long lst = 1000000000000;
    for (int j = index - 1; j >= 0 && (index - j) <= k; j--)
    {
        long long temp = cost[j] + abs(height[index] - height[j]);
        lst = min(lst, temp);
    }
    return lst;
}

int main()
{
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> height[i];
    cost[0] = 0;
    cost[1] = abs(height[1] - height[0]);
    for (int i = 2; i < n; i++)
    {
        cost[i] = mn(i, k);
    }
    cout << cost[n-1] << "\n";
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=acos(-1);
const ll INF = 1LL<<62;
const ll MINF = -(1LL<<62);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)


int main() {
	IO;
	ll a,b,n;
	cin>>a>>b>>n;
	ll val=min(b-1,n);
	cout<<a*val/b;
	return 0;
}


Measured memory_bytes: 3612
while True:
    try:
        l = map(int, raw_input().split(","))
        v1 = l.pop(10)
        v2 = l.pop(10)
        p = v1*float(sum(l))/(v1+v2)
        for i in range(10):
            p -= l[i]
            if p <= 0:
                print i+1
                break
    except:
        break

Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=1010;
const ll mod=1e9+7;


int main(){
  int x,y,ans=0;
  cin >> x >> y;
  if(x==3){ans+=100000;}
  if(x==2){ans+=200000;}
  if(x==1){ans+=300000;}
  if(y==3){ans+=100000;}
  if(y==2){ans+=200000;}
  if(y==1){ans+=300000;}
  if(x==1&&y==1){ans+=400000;}



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

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

const int MX = 3005;

string s1,s2;
vector<vector<int>> dp(MX, vector<int>(MX, -1));

int LCS(int x, int y) {
    if (x >= (int)s1.size()) return 0;
    if (y >= (int)s2.size()) return 0;
    if (dp[x][y] != -1) return dp[x][y];

    if (s1[x] == s2[y]) return dp[x][y] = (1 + LCS(x + 1, y + 1));
    return dp[x][y] = max(LCS(x+1,y), LCS(x, y+1));
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> s1 >> s2;
    LCS(0, 0);

    string res;
    int x = 0, y = 0;
    while (x < (int)s1.size() && y < (int)s2.size()) {
        if (s1[x] == s2[y]) {
            res.push_back(s1[x]);
            x++;
            y++;
            continue;
        }
        if (dp[x+1][y] >= dp[x][y+1]) x++;
        else y++;
    }

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



Measured memory_bytes: 36096
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  string s; cin >> s;
  int len = s.length();
  // 最終的に奇数個で終わる
  if(s[0] == s[len-1]) {
    if(len % 2 == 0) {
      puts("First");
    } else {
      puts("Second");
    }
  }
  // 偶数個で終わる
  else {
    if(len % 2 == 1) {
      puts("First");
    } else {
      puts("Second");
    }
  }
  return 0;
}

Measured memory_bytes: 512
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End


/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template


signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cins(S);
    smatch smatch;
    if(regex_search(S,smatch,regex("^(|A)KIH(|A)B(|A)R(|A)$"))){
        cout << "YES" << nn;
    }else{
        cout << "NO" << nn;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef long long ll;
typedef int keytype;

void quicksort(keytype a[], int first, int last)
{
    int i, j;
    keytype x, t;

    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

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

int main(){
    int n, d, x;
    int a[100];

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

    int cnt = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j * a[i] + 1 <= d; ++j){
            cnt++;
        }
    }

    int ans = cnt + x;

    printf("%d\n", ans);

    return 0;
}


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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second
//#define x real()
//#define y imag()
#define length(a) (hypot((a).imag() , (a).real()))
#define point complex<ld>
#define perp(a) point((-(a).Y,(a).X))
#define dot(a,b) ( (conj(a)*(b)).real() )
#define cross(a,b) ( (conj(a)*(b)).imag() )
#define rotate0(p,ang) (p * exp(point(0,ang)) )

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

    ll n,d,ans=0;
    cin >> n >> d;
    for(int i=1; i<=n; i++)
    {
        ll x,y;
        cin >> x >> y;
        ll tmp = x*x + y*y;
        if (tmp <= d*d) ans++;
    }
    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 3628
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] ary = new Integer[n];
        for (int i = 0; i < n; i++) {
            ary[i] = Integer.parseInt(sc.next());
        }
        Arrays.sort(ary);
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int idx = ~Arrays.binarySearch(ary, ary[i] + ary[j], (x, y) -> x.compareTo(y) >= 0 ? 1 : -1);
                ans += idx - j - 1;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 50160
# from https://atcoder.jp/contests/abc133/submissions/6272850
n=int(input())
a=[int(i) for i in input().split()]
c=[0]
s=sum(a)

for i in range(2*n):
    c.append(c[-1]+a[(i*2+1)%n])
ans=[0]*n
for i in range(n):
    ans[i*2%n]=s-2*(c[i+n//2]-c[i])
print(*ans)

Measured memory_bytes: 73956
#include<bits/stdc++.h>
using namespace std;
#define what_is(x) cerr<<#x <<" is "<<x<<endl;
#define ll long long
#define gcd(a,b) __gcd(a,b)
#define pi 2*acos(0.0)
//use emplace_back() instead of push_back()
template<typename T>
void print(T t)
{
    for(const auto& e:t)cout<<e<<" ";
    cout<<endl;
}
ll power(ll x, ll y, ll p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    vector<ll>a(n);
    ll maxi=0;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        maxi=max(maxi,a[i]);
    }
    ll pri[maxi+1]={0};
    sort(a.begin(),a.end());
    ll ans=0;
    for(ll i=0;i<n;i++)
    {
        if(pri[a[i]]==0 && a[i]!=a[i+1])ans++;
        ll x=a[i];
        ll j=x;
        while(j<=maxi)
        {
            pri[j]++;
            j=x+j;
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 12660
def main():

    board = [list(map(int, input().split())) for _ in range(3)]
    n = int(input())

    calls = list(int(input()) for _ in range(n))

    cmap = { }
    for r in range(3):
        for c in range(3):
            cmap[board[r][c]] = (r, c)

    for call in calls:
        if call in cmap:
            r, c = cmap[call]
            board[r][c] = -1

    if (any(all(board[r][c] == -1 for r in range(3)) for c in range(3)) or
        any(all(board[r][c] == -1 for c in range(3)) for r in range(3)) or
        all(board[i][i] == -1 for i in range(3)) or
        all(board[i][2-i] == -1 for i in range(3))):
        print('Yes')
    else:
        print('No')
          
main()


Measured memory_bytes: 9176
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def rangeI(it, l, r):
    for i, e in enumerate(it):
        if l <= i < r:
            yield e
        elif l >= r:
            break

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

INF = 999999999999999999999999
MOD = 10**9+7

n = int(input())

factors = [1] * (n+1)

ans = 0
for i in range(2, n+1):
    for j in range(i, n+1, i):
        ans += j

for i in range(1, n+1):
    ans += i * factors[i]

print(ans)

Measured memory_bytes: 152632
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define inf (int)(3e18)
#define P pair<int,int>
#define mod (int)(1e9+7)

template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}


signed main() {
	int N,R;
	cin>>N>>R;
	if(N>=10)cout<<R<<endl;
	else cout<<R+100*(10-N)<<endl;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <deque>
#include <vector>
#include <string>
#include <bitset>
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF 1000000000
#define pb push_back
#define pf push_front
#define mp make_pair
#define endl "\n"
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP_R(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=((int)(m));i<(int)(n);++i)
#define FOR_R(i,m,n) for(int i=((int)(m)-1);i>=(int)(n);--i)
#define ALL(v) (v).begin(),(v).end()
typedef long long int lli;
using namespace std;

int main()
{
  int N;
  int A,B;
  
    
  cin >> N ;
  
  if( N == 1 )
    {
      printf("Hello World\n");
      
    }
  else
    {
      cin >> A >> B;

      printf("%d\n",A+B);
      

      
    }
  

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
int g[50][50];
typedef std::pair<int,int> P;
const int INF=100000000;
using namespace std;

int main(){

  int H,W;
  int ans;
  int k=0;
  cin>>H>>W;
  std::vector<string> s(H);
  for(int i=0;i<H;i++)cin>>s[i];
  for(int i=0;i<H;i++)for(int j=0;j<W;j++)g[i][j]=INF;
  for(int i=0;i<H;i++)for(int j=0;j<W;j++)if(s[i][j]=='.')k++;
  ans=k+1;

  queue<P> que;
  que.push(P(0,0));
  g[0][0]=1;
  int x[4]={0,0,1,-1};
  int y[4]={1,-1,0,0};
  while(que.size()){
    P l=que.front();
    que.pop();
    if(l.first==H-1&&l.second==W-1){
      ans=g[H-1][W-1];
      break;
    }
    else{
      for(int i=0;i<4;i++){
        int yy=l.first+y[i];
        int xx=l.second+x[i];
        if(xx>=0&&xx<W&&yy>=0&&yy<H&&s[yy][xx]=='.'&&g[yy][xx]==INF){
          g[yy][xx]=g[l.first][l.second]+1;
          que.push(P(yy,xx));
        }
      }
    }
  }
  cout<<k-ans<<endl;
}


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

int main(void)
{
    string s;
    getline(cin, s);  // 1行読み込む
    for(int i = 0; i < s.size(); i++) {
        char c = s[i];
        if ('A' <= c && c <= 'Z') {
            //c = tolower(c);
            c = c + 32;
        }
        else if('a' <= c && c <= 'z') {
            c = c - 32;
        }
        cout << c;
    }
    cout << endl;
}



Measured memory_bytes: 3192
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int T = sc.nextInt();
		int a[] = new int[T];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		System.out.println(eatSimpleCakes(K, T, a));

	}

	private static int eatSimpleCakes(int k, int t, int[] a) {
		Arrays.sort(a);
		for (int i = a.length - 1; i >= 0; i--) {
			for (int j = i - 1; j >= 0; j--) {
				if (a[i] == 0) {
					break;
				} else {
					if (a[i] >= a[j]) {
						a[i] = a[i] - a[j];
						a[j] = 0;
					} else {
						a[j] = a[j] - a[i];
						a[i] = 0;

					}
				}
			}
		}
		if (a[a.length - 1] == 0)
			return 0;
		else
			return a[a.length - 1] - 1;

	}

}


Measured memory_bytes: 9812
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <deque>
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main(){
    ll L,R; cin >> L >> R;
    R = min(R,L+4038);
    int ans = 2018;
    for(ll i=L; i<=R; i++){
        for(ll j=i+1; j<=R; j++){
            int x = i*j%2019;
            ans = min(ans,x);
        }
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}

const int MAXN = 5e3 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? (a * pw(a * a % MOD, b / 2)) % MOD : pw(a * a % MOD, b / 2))); }

ll v[MAXN], t[MAXN], dp[MAXN][MAXN];

vector<pll> V;

int main(){
    fast_io;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> v[i] >> t[i];
        V.push_back({v[i] + t[i], i});
    }
    sort(all(V));
    for(int i = 0;i <= n; i++){
        for(int j = 0; j <= n; j++){
            dp[i][j] = 1e18;
        }
    }
    for(int i = 0; i <= n; i++){
        dp[i][0] = 0;
    }
    int J = V[0].S;
    dp[0][1] = t[J];
    for(int i = 1; i < n; i++){
        int q = V[i].S;
        for(int j = 1; j <= n; j++){
            dp[i][j] = min(dp[i - 1][j], ((dp[i - 1][j - 1] <= v[q])? dp[i - 1][j - 1] + t[q] : (ll)1e18));
        }
    }
    for(int j = n; j >= 0; j--){
        if(dp[n - 1][j] <= 1e16){
            cout << j;
            return 0;
        }
    }
    return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

template<typename T> T fl(T x, T y) { return x / y; }
template<typename T> T ce(T x, T y) { return (x + y - 1) / y; }

LL n, h;
vector<pair<LL, int>> v;

int main() {
	cin >> n >> h;
	inc(i, n) {
		LL a, b;
		cin >> a >> b;
		v.EB(a, 0);
		v.EB(b, 1);
	}
	
	sort(RALL(v));
	LL s = 0, c = 0;
	inc(i, v.size()) {
		if(v[i].SE == 0) {
			LL d = ce(h - s, v[i].FI);
			c += d;
			s += d * v[i].FI;
		} else {
			s += v[i].FI;
			c++;
		}
		if(s >= h) { break; }
	}
	
	cout << c << endl;
	
	return 0;
}


Measured memory_bytes: 6512
def factorization(n):
    res = []
    m = 2
    while m ** 2 <= n:
        if n % m == 0:
            cnt = 0
            while n % m == 0:
                cnt += 1
                n //= m
            res.append([m, cnt])
        m += 1

    if n > 1:
        res.append([n, 1])

    return res


n = int(input())

mod = 10 ** 9 + 7

cnt = [0] * (n+1)
for i in range(2, n+1):
    for j, k in factorization(i):
        cnt[j] += k

res = 1
for c in cnt:
    if c > 0:
        res = res * (c + 1) % mod

print(res)

Measured memory_bytes: 71688
#include <bits/stdc++.h>
using namespace std;int n ,dp[3][102];
main(){cin >>n;for(int i = 1;i<3;i++) for(int j=1 ,a;j<=n;j++)cin >>a, dp[i][j] = max(dp[i-1][j],dp[i][j-1]) + a;cout<<dp[2][n];}

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

int main(){
    int n;
    cin >> n;
    int b[n-1];
    rep(i,n-1)cin >> b[i];
    int ans = b[0];
    rep(i,n-1){
        if(i == 0)continue;
        ans += min(b[i],b[i-1]);
        
    }
    ans += b[n-2];
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(){
    int i,j,tmp;
    int numdata[10000];
    for(i = 0;i<=10000;i++){
        scanf("%d",&tmp);
        if(tmp==0) break;
        if(tmp<=10000) numdata[i]=tmp; 
    }
    for(j=0;j<i;j++){
        printf("Case %d: %d\n",j+1,numdata[j]);
    }
    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<string> > S(H, vector<string>(W));
  int ansi, ansj;
  rep(i, H) rep(j, W) {
    cin >> S[i][j];
    if(S[i][j] == "snuke") ansi=i, ansj=j;
  }
  cout << char('A'+ansj) << 1+ansi << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <bitset>
#include <stack>
#include <cstdlib>
#include <complex>
#include <unordered_map>
#define REP(i,n) for(int i = 0; n > i; i++)
#define MODU 33
#define Range(x,a,b) ((a) <= (x) && (x) <= (b))
#define POWT(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef vector<int> Ivec;
typedef pair<int, int> pii;
typedef long long int ll;


int main() {
	int n;
	scanf("%d", &n);
	int Max = 0, Min = 1000;
	map<int, int> spe;
	vector<int> num;
	REP(i, n) {
		int a;
		scanf("%d", &a);
		Max = max(Max, a);
		Min = min(Min, a);
		num.push_back(a);
	}
	int Len = Max + 1;
	REP(i, Len) {
		spe[max(i - 0, Len - i - 1)]++;
	}

	REP(i, n) {
		if (spe[num[i]] > 0) {
			spe[num[i]]--;
		}
		else if (num[i] < ((int) (Len / 2) + 1)) {
			printf("Impossible\n");
			return 0;
		}
	}
	for (pii c : spe) {
		if (c.second > 0) {
			printf("Impossible\n");
			return 0;
		}
	}
	printf("Possible\n");
	return 0;
}

Measured memory_bytes: 384