akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	double a,b,x;
	cin >> a >> b >> x;
	double s=x/a;
	double rad;
	if(s>=a*b/2){
		double h=(a*b-s)*2/a;
		rad=atan2(h,a);
	}
	else{
		double w=s*2/b;
		rad=atan2(b,w);
	}
	double deg=rad/(2*pi)*360;
	cout << DOUBLE << deg << endl;
	return 0;
}


Measured memory_bytes: 512
using System;
using System.Linq;

namespace ALDS1_4_B
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            int[] x1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int n2 = int.Parse(Console.ReadLine());
            int[] x2 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int ret = 0;
            for (int i = 0; i < n2; i++)
            {
                if (Array.BinarySearch(x1,x2[i]) >= 0) ret++;
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 23256
#include <bits/stdc++.h>
#define INF 1e18
#define MOD 1000000007
#define PI M_PI
#define ll long long
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REP(i, n) for (int i=0; i<n; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define print(x) cout << x << endl;
#define debug(x) cout << #x << " = " << endl;

using namespace std;

void solve()
{
    int X, Y;
    cin >> X >> Y;
    int ans = 0;

    if (X == 1) {
        ans += 300000;
    } else if (X == 2) {
        ans += 200000;
    } else if (X == 3) {
        ans += 100000;
    }

    if (Y == 1) {
        ans += 300000;
    } else if (Y == 2) {
        ans += 200000;
    } else if (Y == 3) {
        ans += 100000;
    }

    if ((X == 1) && (Y == 1)) {
        ans += 400000;
    }
    print(ans);
}

int main()
{
    solve();

    return 0;
}


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


int main() {
	int N, A, B;
	cin >> N >> A >> B;
	ll sum = 0;

	for (int i = 1; i <= N; i++)
	{
		int tmp_sum = 0;
		int num = i;
		while (num > 0)
		{
			tmp_sum += num % 10;
			num /= 10;
		}
		if (tmp_sum >= A && tmp_sum <= B)
		{
			sum += i;
		}
	}
	cout << sum << endl;

}


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

int N, M, Q; // 長さN、M種類の数列
vector<int> a, b, c, d; // Qの要素

long long score(const vector<int> &A){
    long long res = 0;
    for(int i = 0; i < Q; ++i){
        if(A[b[i]] - A[a[i]] == c[i]) res += d[i]; // Qの条件を満たしたらスコアを追加
    }
    return res;
}


// 数列を全探索で作る
long long dfs(vector<int> &A){
    // 長さNになったら終了
    if(A.size() == N){
        return score(A);    // 長さNになったらその時点でのスコアを返す
    }

    long long res = 0;
    int prev_last = (A.empty() ? 0 : A.back());  // 前の項が空なら0,そうでなければ前の項 
    for(int add = prev_last; add < M; ++add){  // 単調増加
        A.push_back(add);       // 1~Mを追加
        res = max(res, dfs(A)); // 再帰しながら最大のスコアを返す
        A.pop_back();           // 最後尾を除去してforに戻る
    }

    return res;
}

int main(){
    cin >> N >> M >> Q;
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);

    for(int q = 0; q < Q; ++q){
        cin >> a[q] >> b[q] >> c[q] >> d[q];
        --a[q], --b[q]; 
    }

    vector<int> A;
    cout << dfs(A) << endl;

}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
const int mod=1000000007;
const int maxn=100005;
int fa[maxn];
struct Node
{
    ll x,y,id;
}node[maxn];
struct Edge
{
    ll cost,p1,p2;
}edge[maxn*2];
int cmp1(Node a,Node b)
{
    return a.x<b.x;
}
int cmp2(Node a,Node b)
{
    return a.y<b.y;
}
int cmp3(Edge a,Edge b)
{
    return a.cost<b.cost;
}

int Find(int u)
{
    if(fa[u]==u)
        return fa[u];
    return fa[u]=Find(fa[u]);
}

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld%lld",&node[i].x,&node[i].y);
        node[i].id=i;
        fa[i]=i;
    }
    sort(node+1,node+1+n,cmp1);
    int cnt=0;
    for(int i=2;i<=n;i++)
    {
        edge[++cnt].p1=node[i-1].id;
        edge[cnt].p2=node[i].id;
        edge[cnt].cost=node[i].x-node[i-1].x;
    }
    sort(node+1,node+1+n,cmp2);
    for(int i=2;i<=n;i++)
    {
        edge[++cnt].p1=node[i-1].id;
        edge[cnt].p2=node[i].id;
        edge[cnt].cost=node[i].y-node[i-1].y;
    }
    sort(edge+1,edge+1+cnt,cmp3);
    ll ans=0;
    int num=0;
    for(int i=1;i<=cnt;i++)
    {
        int fa_p1=Find(edge[i].p1);
        int fa_p2=Find(edge[i].p2);
        if(fa_p1==fa_p2) continue;
        else
        {
             fa[fa_p1]=fa_p2;
             num++;
             ans+=(edge[i].cost);
        }
        if(num==n-1)
            break;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 7808
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var seqB = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

        var sum = seqB.First() + seqB.Last();
        for (int i = 1; i < seqB.Length; ++i)
        {
            sum += seqB[i - (seqB[i] > seqB[i - 1] ? 1 : 0)];
        }
        Console.WriteLine(sum);
    }
}


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

int main(){
    ll n,k; cin >> n >> k;
    vector<ll> a(n),f(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> f[i];
    sort(all(a));
    sort(all(f));
    reverse(all(f));
    
    ll l=0; ll r=1000000000000;
    while(r!=l){
        ll ce=(l+r)/2;
        bool ok=true;
        ll tmp=0;
        rep(i,n){
            if(a[i]*f[i]>ce) tmp+=((a[i]*f[i]-ce)+f[i]-1)/f[i];
            if(tmp>k){
                ok=false;
                break;
            }
        }
        if(ok) r=ce;
        else l=ce+1;
    }
    cout << r << endl;
return 0;
}

//rate1379

Measured memory_bytes: 3456
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
pair<int,int>a[100];
int main(){
	int n,m,z;
	while(true){
	cin>>n>>m;
	if(!(n+m))break;
	rep(i,m)a[i].first=n,a[i].second=i+1;
	rep(i,n)rep(j,m){cin>>z;a[j].first-=z;}
	sort(a,a+m);
	rep(i,m){if(i)cout<<" ";cout<<a[i].second;}
	cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <list>
#include <deque>

using namespace std;

long long fun(char x){
    if(x=='A') return 4;
    if(x=='G') return 1;
    if(x=='C') return 2;
    return 3;
}

long long convert(string s){
    long long p=1,ans=0;
    int n=s.size();
    for(int i=n-1;i>-1;i--){
        ans+=p*fun(s[i]);
        p*=5;
    }
    return ans;
}

 int main(){
     set<long long> dic;
     int n;
     cin >> n;
     for(int i=0;i<n;i++){
         string order,s;
         cin >> order >> s;
         long long str=convert(s);
         if (order=="insert"){
             dic.insert(str);
         }
         else{
             if(dic.count(str)){
                 cout << "yes" << endl;
             }
             else{
                 cout << "no" << endl;
             }
         }
     }
     //AOJ course3-2
}


Measured memory_bytes: 16032
primes = [0, 0] + [1]*9999999
for i in range(2, 3163):
    if primes[i]:
        for j in range(i*i, 10000001, i):
            primes[j] = 0

while True:
    n = int(input())
    if n == 0:
        break
    for i in range(5, n+1)[::-1]:
        if primes[i] and primes[i-2] and primes[i-6] and primes[i-8]:
            print(i)
            break

Measured memory_bytes: 163252
# E - Almost Everywhere Zero
n=int(input())
K=int(input())
s=str(n)
n=len(s)
ans=0

dp=[[[0]*2 for j in range(K+1)] for i in range(n+1)]
dp[0][0][0]=1
for i in range(n):
    for j in range(K+1):
        for k in range(2):
            # if i>=n:continue
            nd=int(s[i])
            for d in range(10):
                ni=i+1
                nj=j
                nk=k
                if d!=0:nj+=1
                if nj>K:continue
                # k=0:nより小さいことが確定していない
                # k=1:nより小さいことが確定している
                if k==0:
                    # 次の桁が超えるとNG
                    if d>nd:continue
                    if d<nd:nk+=1
                dp[ni][nj][nk]+=dp[i][j][k]

ans=dp[n][K][0]+dp[n][K][1]
print(ans)               



Measured memory_bytes: 41200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX_N 100005
ll N,M,R,Q;
struct edge {ll to,cost;};
vector< edge > G[MAX_N+100];

ll d[11][MAX_N+100];
typedef pair<ll,ll> P;

void dijkstra(int si,ll d[MAX_N+100]){
  si+=MAX_N;
  fill(d,d+MAX_N+100, (1LL<<60) );
  d[si]=0;
  priority_queue< P , vector<P> , greater<P> > Q;
  Q.push( P(0,si) );
  while(!Q.empty()){
    P p=Q.top();Q.pop();
    ll cost=p.first;
    ll pos=p.second;
    if(d[pos]<cost)continue;
    for(int i=0;i<(int)G[pos].size();i++){
      edge e=G[pos][i];
      if(d[e.to]<=cost+e.cost)continue;
      d[e.to]=cost+e.cost;
      Q.push( P(d[e.to],e.to) );
    }
  }
}

int main(){
  scanf("%lld %lld %lld %lld",&N,&M,&R,&Q);
  for(int i=0;i<M;i++){
    ll a,b,c;
    scanf("%lld %lld %lld",&a,&b,&c);
    G[b].push_back( (edge){a,c} );
  }
  for(ll i=1;i<=N;i++){
    G[MAX_N+i%R].push_back( (edge){i,0} );
  }
  for(int i=0;i<R;i++)dijkstra(i,d[i]);

  ll ans=0;
  while(Q--){
    ll x,y,z;
    scanf("%lld %lld %lld",&x,&y,&z);
    ll mini=(1LL<<60);
    for(int i=0;i<R;i++){
      mini=min(mini, d[i][x]+d[i][y]);
    }
    if(mini<z){
      ans+=(z-mini);
    }
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 20092
#include<iostream>
using namespace std;
int main(){
    int m, d;
    cin >> m >> d;
    int d1 = 2, d10 = 2;
    int ans = 0;
    for (int month = 3; month <= m;month++) {
        for (d10 = 2; d10 * 10 + d1 <= d; d10++) {
            for (d1 = 2; d1 < 10 && d10 * 10 + d1 <= d; d1++) {
                if (d1 * d10 == month) {
                    ans++;
                }
            }
            d1 = 2;
        }
        d10 = 2;
    }
    cout << ans << endl;
    return 0;
}


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

const double eps=1e-7;

int sgn(double a){
    if (fabs(a)<eps) return 0;
    if (a>0) return 1;
    return -1;
}

struct Point{
    Point(double _x=0,double _y=0):x(_x),y(_y){}
    
    Point operator + (Point p) const {return Point(x+p.x,y+p.y);}
    Point operator - (Point p) const {return Point(x-p.x,y-p.y);}
    Point operator * (double d) const {return Point(x*d,y*d);}
    
    double Length() const{
        return sqrt(x*x+y*y);
    }
    
    double SqrLength() const{
        return x*x+y*y;
    }
    
    void Read(){
        scanf("%lf%lf",&x,&y);
    }
    
    void Write(){
        printf("%.10f %.10f\n",x,y);
    }
    
    double x,y;  

    friend double Dot(Point p1,Point p2){
        return p1.x*p2.x+p1.y*p2.y;
    }
    
    friend double Cross(Point p1,Point p2){
        return p1.x*p2.y-p1.y*p2.x;
    }
};

struct Line{
    Line(){}
    
    void Read() {
        s.Read(); t.Read();
    }
    
    Point Direction() const{
        return t-s;
    }
    
    Point s,t;
    
    
    
    friend Point Project(Point p,Line l){
        Point dir=l.t-l.s;
        return l.s+dir*(Dot(dir,p-l.s)/dir.SqrLength());
    }
    
    friend Point Reflect(Point p,Line l){
        Point q=Project(p,l);
        Point ret=q*2-p;
        return ret;
    }
    
    // 2: Parallel 1: orthogonal 0: otherwise
    friend int Type(Line l1,Line l2){
        Point d1=l1.Direction(),d2=l2.Direction();
        if (sgn(Cross(d1,d2))==0) return 2;
        if (sgn(Dot(d1,d2))==0) return 1;
        return 0;
    }
};

int main(){
    int n; scanf("%d",&n);
    while(n--){
        Line l1,l2;
        l1.Read(); l2.Read();  
        int ans=Type(l1,l2);
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 3248
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>

using namespace std;

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

int main(){
    long int a, b, c;
    cin >> a >> b >> c;
    if (c < a + b){
        cout << "No" << endl;
        return 0;
    }

    if (4 * a * b < (c - a - b) * (c - a - b)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    
}

Measured memory_bytes: 256
inData = input().split(' ')

seisu1 = int(inData[0])
seisu2 = int(inData[1])
ansK = int(inData[2])
ansList = []
maxSeisu = min([seisu1, seisu2])

for i in range(1, maxSeisu + 1):
    if (seisu1 % i == 0) and (seisu2 % i == 0):
        ansList.append(i)

ansListLen = len(ansList)
print(ansList[ansListLen - ansK])

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int main(){
    cin.sync_with_stdio(false);
    int n, x;
    cin >> n >> x;

    int a[n];
    int sum[n - 1];
    rep(i, n) {
        cin >> a[i];
        if (i > 0) sum[i - 1] = a[i] + a[i - 1];
    }

    ll cnt = 0;
    rep(i, n - 2) {
        if (sum[i] <= x) continue;
        int d = sum[i] - x;
        if (d > a[i + 1]) {
            sum[i + 1] -= a[i + 1];
        } else {
            sum[i + 1] -= d;
        }
        cnt += d;
    }
    if (sum[n - 2] > x) cnt += sum[n - 2] - x;

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int n, h;
    int a[100010], b[100010];
    vector<pair<int, int>> v,w;
    cin >> n >> h;
    REP(i, n){
    int x, y;
    cin >> x >> y;
    v.push_back(make_pair(x,y));
    w.push_back(make_pair(y,x));
    }
    sort(v.rbegin(), v.rend());
    sort(w.rbegin(), w.rend());
    int line = v[0].first;
    int cnt = 0;
    for (int i = 0; i <n; i++)
    {
        if(w[i].first>=line ){
            cnt++;
            h -= w[i].first;
            if(h<=0){
                cout << cnt << endl;
                return 0;
            }
        }
        //cerr << cnt << endl;
    }
    cout << (h + line - 1) / line + cnt << endl;
    
    return 0;
}

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

int n;
double p[3100];
double dp[3100][3100];



int main() {
	cin >> n;
	for(int i=0; i<=n; i++){
		cin >> p[i];
	}
	dp[0][0] = 1.0;

	for(int i=0; i<n; i++){
		for(int j=0; j<=i; j++){
			dp[i+1][j+1] += dp[i][j] * p[i];
			dp[i+1][j] += dp[i][j] * (1-p[i]);
		}
	}
	double ans = 0;
	int m = (n+1)/2;
	for(int i=m; i<=n; i++){
		ans += dp[n][i];
	}

	printf("%.10lf", ans);
}

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

using namespace std;

string s;
int le;

int main() {
	cin >> s;
	le = s.size();
	for (int i = 0; i < le; i++) {
		if (s[i] == '?') {
			cout << "D";
		}
		else {
			cout << s[i];
		}
	}
	return 0;
}

Measured memory_bytes: 3764
#include<cstdio>
#include<algorithm>
using namespace std;

const int H_MAX = 10005;
const int N_MAX = 1005;
int dp[H_MAX];
const int INF = 200000000;

int main(){
    int h, n;
    scanf("%d %d", &h, &n);
    int A[N_MAX], B[N_MAX];
    for(int i = 0; i < n; i++){
        int a, b;
        scanf("%d %d", &A[i], &B[i]);
    }

    for(int i = 0; i < h; i++) dp[i] = INF;
    dp[h] = 0;

    for(int i = 0; i < n; i++){
        for(int j = h-A[i]; j > 0; j--){
            dp[j] = min(dp[j], dp[j+A[i]] + B[i]);
        }
    }

    int ans;
    ans = INF;
    for(int i = 0; i < n; i++){
        int mini = INF;
        for(int j = 1; j <= A[i]; j++) mini = min(mini, dp[j]);
        ans = min(ans, mini + B[i]);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
($H,$W,$D)=glob<>;
for$y(1..$H){
	@_[glob<>]=map[$y,$_],1..$W
}
for$d($D+1..$H*$W){
	$s[$d]=
		$s[$d-$D]+
		abs(@{$_[$d]}[0]-@{$_[$d-$D]}[0])+
		abs(@{$_[$d]}[1]-@{$_[$d-$D]}[1])
}
<>;
for(<>){
	/ /;
	print$s[$']-$s[$`],$/
}


Measured memory_bytes: 35072
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>


#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
// rep(i,1,10) is from 1 to 9 and rep(I,10,1) is from 9 to 1
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define mi multiset<int>
#define mii multiset<pii>
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";

// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>


// using namespace __gnu_pbds;
using namespace std;

int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}

int modp(int a,int n)
{
    if(n==0) return 1;
    if(n==1) return a;
    int res=modp(a,n/2);
    if(n%2==0) return (res*res);
    else return (a*res*res);
}

// vi adj[1000000];


void solve()
{
    int t,n,m,i,k,r,l,u,v,w,j,s,sum=0,pos,flag=0,count=0;
    string S,T,U;
    int x,y,z;
    cin>>x>>y>>z;
    swap(x,y);
    swap(x,z);
    cout<<x<<" "<<y<<" "<<z;
}


signed main()
{
    // #ifndef ONLINE_JUDGE 
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
    // #endif
    // ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        // cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a, b, i=1;
  scanf("%d%d", &a, &b);
  while(floor(i++*0.08) <=a){
  if(floor(i*0.08) == a && floor(i*0.1) ==b )
    return !printf("%d\n", i); 
  }
  printf("-1\n");
  return 0;
}

Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
typedef unsigned long long ull;
string s, t; ull p[4009], h1[4009][4009], h2[4009][4009];
int main() {
	cin >> s >> t; p[0] = 1;
	for (int i = 0; i < 4005; i++) p[i + 1] = p[i] * 10007;
	int n = s.size(), m = t.size();
	for (int i = 0; i < n; i++) {
		ull h = 0;
		for (int j = i + 1; j <= n; j++) {
			h += p[s[j - 1] - 97];
			h1[j - i][i] = h;
		}
	}
	for (int i = 0; i < m; i++) {
		ull h = 0;
		for (int j = i + 1; j <= m; j++) {
			h += p[t[j - 1] - 97];
			h2[j - i][i] = h;
		}
	}
	int z = min(n, m);
	for (int i = 1; i <= z; i++) sort(h1[i], h1[i] + n - i + 1);
	for (int i = 1; i <= z; i++) sort(h2[i], h2[i] + m - i + 1);
	int ret = 0;
	for (int i = 1; i <= z; i++) {
		int l = 0;
		for (int j = 0; j < n - i + 1; j++) {
			while (l < m - i + 1 && h2[i][l] < h1[i][j]) l++;
			if (h2[i][l] == h1[i][j]) ret = max(ret, i);
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 158256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
 
constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 1010;

vector<int> G[110][MAX];

int dfs(int a, int h){
    if(h == 0) return a;
    return dfs(G[a][h][0], h-1);
}

int main(){
    int n, m, a;
    while(scanf("%d%d%d", &n, &m, &a) && n){
        rep(i, 110)rep(j, MAX) G[i][j].clear();
        rep(i, m){
            int h, p, q;
            scanf("%d%d%d", &h, &p, &q);
            G[p][h].push_back(q);
            G[q][h].push_back(p);
        }
        rep(i, n+1)For(j, 1, MAX)if(G[i][j].empty()) G[i][j].push_back(i);
        printf("%d\n", dfs(a, MAX-1));
    }
}


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

int main() {
    string s;
    ll n;
    cin >> s >> n;
    int i = 0;
    for (; i < s.length() && s[i] == '1'; i++) {};
    if (i >= s.length()) cout << 1 << endl;
    else if (i + 1 > n) cout << 1 << endl;
    else cout << s[i] << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
#define int long long

signed main() {
    int n;
    cin >> n;
    int l, r;
    int sum = 0;
    rep(i, n) {
        cin >> l >> r;
        sum += r - l + 1;
    }
    cout << sum << endl;
}

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

maxcount = 0
for i in range(len(S) - len(T)+1):
    count = 0
    for j in range(len(T)):
        if S[i + j] == T[j]:
            count += 1
        maxcount = max(maxcount, count)
print(len(T) - maxcount)


Measured memory_bytes: 67652
x1, y1, x2, y2 = list(map(int, input().split()))
diff_x = x2 - x1
diff_y = y2 - y1
if diff_x > 0:
  if diff_y > 0:
    x3 = x2 - diff_y
    y3 = y2 + diff_x
    x4 = x3 - diff_x
    y4 = y3 - diff_y
  if diff_y == 0:
    x3 = x2
    y3 = y2 + diff_x
    x4 = x3
    y4 = y1
  if diff_y < 0:
    x3 = x2 - diff_y
    y3 = y2 + diff_x
    x4 = x3 - diff_x
    y4 = y3 - diff_y
if diff_x == 0:
    x3 = x2 - diff_y
    y3 = y2
    x4 = x3
    y4 = y1
if diff_x < 0:
  if diff_y > 0:
    x3 = x2 - diff_y
    y3 = y2 + diff_x
    x4 = x3 - diff_x
    y4 = y3 - diff_y
  if diff_y == 0:
    x3 = x2
    y3 = y2 + diff_x
    x4 = x1
    y4 = y3
  if diff_y < 0:
    x3 = x2 - diff_y
    y3 = y2 + diff_x
    x4 = x3 - diff_x
    y4 = y3 - diff_y
print("{} {} {} {}".format(x3, y3, x4, y4))

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

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n; cin>>n;
	vector<int> a(n), gf(n), gb(n);
	for(auto &x : a){
		cin>>x;
	}
	gf[0] = a[0]; gb[n - 1] = a[n - 1];
	for(int i = 1; i < n; i++){
		gf[i] = __gcd(gf[i - 1], a[i]);
	}
	for(int i = n - 2; i >= 0; i--){
		gb[i] = __gcd(gb[i + 1], a[i]);
	}
	int ans = max(gb[1], gf[n - 2]);
	for(int i = 1; i + 1 < n; i++){
		ans = max(ans, __gcd(gf[i - 1], gb[i + 1]));
	}
	cout<<ans<<endl;

	return 0;
}

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

#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int my_rand(int l, int r) {
    return uniform_int_distribution<int>(l, r) (rng);
}


int main() {
//    freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;
    map<int,int> M;
    M[0]++;
    int sum = 0;
    long long ans = 0;
    for(int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        sum += x;
        sum %= m;
        ans += M[sum];
        M[sum]++;
    }
    cout << ans << endl;
}





Measured memory_bytes: 6476
#include<stdio.h>
#define N 100
  

int main()
{
  int i,j,minj,key,n,count=0;
  int A[N];
  scanf("%d",&n);
  
  for(i=0;i<=n-1;i++) scanf("%d",&A[i]);
  

  for(i=0;i<=n-1;i++){
    minj=i;
    for(j=i;j<=n-1;j++){
      if(A[j]<A[minj]) minj=j;
    }
 

   key=A[i];
   if(minj!=i){
  
    A[i]=A[minj];
    A[minj]=key;
    count++;
    }
  }
 
  for ( i = 0; i < n-1; i++ ){
  
  printf("%d ", A[i]);
  }
  printf("%d\n", A[n-1]);
  
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=301,INF=1<<30;

int main(){
    
    ll K;cin>>K;
    
    if(K==10){
        for(int i=1;i<=9;i++){
            cout<<i<<endl;
        }
        cout<<19<<endl;
    }else{
        vector<ll> A;
        vector<double> B;
        int cnt=27;
        for(int i=1;i<=9;i++){
            cout<<i<<endl;
        }
        for(int i=1;i<=9;i++){
            cout<<i*10+9<<endl;
        }
        for(int i=1;i<=9;i++){
            cout<<i*100+99<<endl;
        }
        for(int keta=1;keta<=12;keta++){
            for(int i=100;i<=999;i++){
                ll a=(i+1)*pow(10,keta)-1;
                double asum=(i/100)+(i%100/10)+(i%10)+(keta)*9;
                A.push_back(a);
                B.push_back(a/asum);
            }
        }
        
        for(int i=0;i<A.size();i++){
            bool ok=true;
            for(int j=i+1;j<A.size();j++){
                if(B[i]>B[j]){
                    ok=false;
                    break;
                }
            }
            if(ok){
                cout<<A[i]<<endl;
                cnt++;
            }
            if(cnt==K) break;
        }
    }
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <functional>

#define MOD (1000000007)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 3000000;

long long fac[MAX], finv[MAX], inv[MAX];


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


// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

map<ll,ll> prime;//素因数分解でそれぞれの素数がいくつ出てきたかを保存するmap

//O(√n)
//整列済み(mapはkeyで自動で整列される)
void prime_factorize(ll n){
    if(n<=1) return;
    ll l=sqrt(n);
   for(ll i=2;i<=(ll)(l);i++) { //
        if(n%i==0){
            prime_factorize(i);prime_factorize(ll(n/i));return;
        }
    }
    //mapでは存在しないkeyの場合も自動で構築される
    prime[n]++;return;
}


vector<ll> A, B, C;
map<ll, ll> m;
int main() {
    COMinit();

    ll K;
    cin >> K;
    string S;
    cin >> S;

    ll ret = 0;

    for(ll i = 0; i <= K; i++ ) {
        ll temp = COM(S.size() - 1 + K - i, S.size()-1);
        temp = (temp * modpow(25, K-i, MOD)) % MOD;
        temp = (temp * modpow(26, i, MOD)) % MOD;

        ret = (ret + temp) % MOD;
    }

    cout << ret << endl;

            

    return 0;    
}



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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
 int n,m,K;
 cin>>n>>m>>K;
 vector<string>  v(n);
 for(int i =0; i<n; i++)
	cin>>v[i];
 int ans =0, cnt = 0;
 for(int i =0; i<(1<<n); i++){
	 for(int j =0; j<(1<<m); j++){
		 cnt=0;
		 for(int k=0; k<n; k++){
			 for(int l=0; l<m; l++){
				 if(((i>>k)&1) || ((j>>l)&1)) continue;
				 if(v[k][l]=='#') cnt++;
				 }
			 }
			 if(cnt==K) ans++;
		 }
	 }
	 cout<<ans;
	 return 0;
}


Measured memory_bytes: 3660
import java.util.Scanner;
import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.lang.Math;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long i = b/c + b/d - b/lcm(c,d);
        long j = (a-1)/c + (a-1)/d - (a-1)/lcm(c,d);
        System.out.println((b-a+1) - (i-j));
    }

    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }

    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }

}


Measured memory_bytes: 21844
N, M = map(int, input().split())
keys = []

for _ in range(M):
    cost, _ = map(int, input().split())
    mask = 0
    for i in map(int, input().split()):
        mask |= (1 << (i - 1))
    keys.append((cost, mask))


allstate = (1 << N) - 1
dp = [float('inf')] * (1<<N)
dp[0] = 0

for cost, key_set in keys:
    for state in range(1<<N):
        if dp[state] == float('inf'): continue
        nstate = state | key_set
        dp[nstate] = min(dp[nstate], dp[state] + cost)

print(dp[-1] if dp[-1] != float('inf') else -1)


Measured memory_bytes: 48344
#include<bits/stdc++.h>
using namespace std;
int n, m;
char s[1010][1010];
queue <pair<int,int> >q;
int st[1010][1010], vis[1010][1010];
const int X[]={0,0,1,-1};
const int Y[]={1,-1,0,0};
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; ++i){
		scanf("%s",s[i]);
		for(int j=1; j<=m; ++j)if(s[i][j-1]=='#')q.push(make_pair(i,j)),vis[i][j]=1;
	}
	int mxst=0;
	while(!q.empty()){
		int x=q.front().first, y=q.front().second; q.pop();
		mxst=max(mxst,st[x][y]);
		for(int i=0; i<4; ++i){
			int dx=x+X[i],dy=y+Y[i];
			if(dx>0&&dy>0&&dx<=n&&dy<=m&&!vis[dx][dy]){
				q.push(make_pair(dx,dy)); st[dx][dy]=st[x][y]+1; vis[dx][dy]=1;
			}
		}
	}
	printf("%d",mxst);
	return 0;
}

Measured memory_bytes: 15376
#include <bits/stdc++.h>
using namespace std;
int N;
string S;
int ans;
int cnt=0;
int main(){
    cin >> S;
    N = S.size();
    for(int i=0;i<N;i++){
        if(S[i]=='x'){
            cnt++;
        };
    }
    // cout << cnt << endl;
    if(cnt>=8){
        cout << "NO";
    }
    else{
        cout << "YES";
    }
}


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
ans = ''
for i in S():
    if ord(i) + n > 90:
        ans += chr(ord(i) + n - 26)
    else:
        ans += chr(ord(i) + n)


print(ans)



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

int main()
{
    int N;
    std::vector<int> a;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int b;
        cin >> b;
        a.push_back(b);
    }
    std::sort(a.begin(), a.end());

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) {
            ans += a[N - i - 1];
        } else {
            ans -= a[N - i - 1];
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<algorithm>

using namespace std;

#define LL long long


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

	cout << (a * 3 + p) / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

int main()
{
    ll K, A, B;
    cin >> K >> A >> B;
    ll res = 0LL;
    if(B - A <= 2 || K < A-1) res = 1 + K;
    else {
        res = A;
        K -= A-1;
        res += (K/2LL)*(B-A);
        K %= 2LL;
        if(K > 0) res += K;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#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 a, b, c;
    cin >> a >> b >> c;
    set<int> res;
    for(int i = 1;; i++) {
        int r = (a * i) % b;
        if(r == c) {
            cout << "YES" << endl;
            return 0;
        }
        if(res.count(r)) {
            cout << "NO" << endl;
            return 0;
        }
        res.insert(r);
    }
    return 0;
}

Measured memory_bytes: 256
def solve(a):
	for i in M-set(a):
		for x,y in xy:
			if x == i and y not in a: break
		else:
			r = solve([i]+a)
			if r: return r
	return a
m = input()
M = set(range(1,m+1))
xy = [map(int,raw_input().split()) for i in range(input())]
for i in solve([]): print i

Measured memory_bytes: 4232
n=int(input())
A=["M","A","R","C","H"]
B=[0,0,0,0,0]
s=[]
for i in range(n):
    S=input()
    if S[0] in A:
        s.append(S)
#print(s)
for i in s:
    for j in range(5):
        if A[j]==i[0]:
            B[j]+=1
            break
c=B.count(0)
if c>2:
    print(0)
else:
    c=0
    for i in range(3):
        for j in range(i+1,4):
            for k in range(j+1,5):
                c+=(B[i]*B[j]*B[k])
    print(c)
#print(B)


Measured memory_bytes: 10136
# In progress
h, w = map(int, input().split())
# Setting
mine_set = set()
next_to_grid_list = [(1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0),
                     (-1, 1), (0, 1), (1, 1)]


def add_number_for_dot(mine):
    for next_to_grid in next_to_grid_list:
        if is_constrained(mine[0] + next_to_grid[0], mine[1] + next_to_grid[1]):
            if type(grids[mine[0] + next_to_grid[0]][mine[1] + next_to_grid[1]]) is int:
                grids[mine[0] + next_to_grid[0]][mine[1] + next_to_grid[1]] += 1


def is_constrained(i, j):
    if 0 <= i < h and 0 <= j < w:
        return True
    else:
        return False


# Register grids information
grids = []
for i in range(h):
    grids.append(list(input()))
    for j in range(w):
        if grids[i][j] == "#":
            mine_set.add((i, j))
        else:
            grids[i][j] = 0

# add number to "."
for mine in mine_set:
    add_number_for_dot(mine)

# Show result
for i in range(h):
    s_i = [str(grid) if type(grid) is int else grid for grid in grids[i]]
    print("".join(s_i))

Measured memory_bytes: 3316
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<set>
#include<map>

using namespace std;

#define x first
#define y second
#define NMAX 200005
#define INF 1000000009
#define MOD 1000000007

int n, answer;
char s[3][NMAX];

int main (){
    
    scanf("%d\n",&n);
    
    scanf("%s", s[1]);
    scanf("%s", s[2]);
    int before = 0;
    for(int i = 0; i < n; i++) {
        if(s[1][i] == s[2][i]) {
            if(!before)
                answer = 3;
            else if(before == 1) {
                answer *= 2;
                answer %= MOD;
            }
            before = 1;
        }
        else {
            if(!before) {
                answer = 6;
            }
            else if(before == 1) {
                answer = ((long long)answer * 2) % MOD;
            }
            else
                answer = ((long long)answer * 3) % MOD;
            before = 2;
            i++;
        }
    }
    
    printf("%d\n", answer);
    
    return 0;
}

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (auto i=0; i<n; i++)
#define	Rep1(i, n)	for (auto i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	ll N, M;
	cin >>N >>M;
	vector<ll> A(N, 0);
	ll S=0;
	Rep0(i, N) {
		cin >>A.at(i);
		S +=A.at(i);
	}
	Sort(A);
	Rev(A);
	if (A.at(M-1)*4*M>=S)
		cout <<"Yes" <<endl;
	else
		cout <<"No" <<endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include<algorithm>
#include <numeric>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  int a[N];
  for(int i=0;i<N;i++){
   cin >> a[i]; 
  }
  int ans=0;
  for(int i=0;i<N;i++){
   ans+=a[i]-1; 
  }
  cout << ans << endl;
  return 0;}

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

int main(){
  int n;
  cin >> n;
  n=n%10;
  if(n==3){
    cout << "bon";
  }
  else if(n==0 || n==1 || n==6 || n==8 ){
    cout << "pon";
  }
  else{
    cout << "hon";
  }
  return 0;
}

Measured memory_bytes: 3644
#include <cstdio>
#include <algorithm>
#include <cmath>
//#include
using namespace std;
const double EPS = 1e-10;
const double g = 9.8;
int N;
double V, X, Y;
double L[55], B[55], R[55], T[55];
//?算以 vy 的速度?直向上射出 t 秒后的高度
double calc(double tv, double tt) {
    return tv*tt - g*tt*tt/2;
}
//a 相? lb 和 ub 的位置
int cmp(double lb, double ub, double a) {
    return a < lb + EPS ? -1 : a > ub - EPS ? 1 : 0;
}
//判断当射出路径?? （qx, qy) ?，蛋能否?中猪
bool check(double qx, double qy) {
    double a = g*g/4, b = g*qy - V*V, c = qx*qx + qy*qy;
    double D = b*b - 4*a*c;
    if(D < 0 && D > -EPS) D = 0;
    if(D < 0) return 0;
    for(int td = -1; td <= 1; td += 2) {
        double t2 = (-b+td*sqrt(D)) / (2*a);
        if(t2 <= 0) continue;
        double t = sqrt(t2);
        double vx = qx / t, vy = (qy+g*t*t/2) / t;

        double yt = calc(vy, X / vx);
        if(yt < Y - EPS) continue;

        bool ok = 1;
        for(int i = 0; i < N; ++i) {
            if(L[i] >= X) continue;
            if(R[i] == X && Y <= T[i] && B[i] <= yt) ok = 0;
            int yL = cmp(B[i], T[i], calc(vy, L[i] / vx));
            int yR = cmp(B[i], T[i], calc(vy, R[i] / vx));
            int HX = cmp(L[i], R[i], vx * vy / g);
            int HY = cmp(B[i], T[i], calc(vy, vy / g));
            if(yL * yR <= 0) ok = 0;
            if(HX == 0 && HY >= 0 && yL == -1) ok = 0;
        }
        if(ok) return 1;
    }
    return 0;
}
void solve(void)
{
   //截掉猪以右的障碍物
   for(int i = 0; i < N; i++)
       R[i] = min(R[i], X);
   bool ok = check(X, Y);   //直接撞上猪
   for(int i = 0; i < N; i++)
   {
       ok |= check(L[i], T[i]);
       ok |= check(R[i], T[i]);
   }
   puts(ok ? "Yes" : "No");
}
int main()
{
   scanf("%d %lf %lf %lf", &N, &V, &X, &Y);
   for(int i = 0; i < N; i++)
       scanf("%lf %lf %lf %lf", &L[i], &B[i], &R[i], &T[i]);
   solve();
   return 0;
}

Measured memory_bytes: 1040
fun main(arr: Array<String>) {
    val (n,x) = readLine()!!.split(" ").map { it.toInt() }
    val a = readLine()!!.split(" ").map { it.toLong() }.toMutableList()
    var ans = 0L
    for(i in (1 until n)) {
        while (a[i-1]+a[i] > x) {
            var idx = i
            if(i == a.lastIndex && a[i-1] > 0) {
                idx = i-1
            } else if(i-1 == 0 && a[i] > 0) {
                idx = i
            } else if(a[i] > 0) {
                idx = i
            } else {
                idx = i-1
            }
            val eat = Math.min(Math.max((a[i-1]+a[i]) - x, 0), a[idx])
            a[idx] -= eat
            ans += eat
        }
    }
    println(ans)
}

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

int main() {
  long long N,count=1;
  cin >> N;
  vector<string> S(N);
  for (int i=0;i<N;i++) cin >> S[i];
  sort(S.begin(),S.end());
  for (int i=1;i<N;i++) {
    if (S[i]!=S[i-1]) count++;
  }
	
  cout << count << endl;
}


Measured memory_bytes: 9588
#include<bits/stdc++.h>
using namespace std;
const int inf=1e9+7;
string s;
string t;
int main(){
	cin>>s;
	cin>>t;
	int slen=s.length();
	int tlen=t.length();
	int ans=999999;
	for(int i=0;i<=slen-tlen;i++){
		int cnt=0;
		for(int j=0;j<tlen;j++){
			if(s[i+j]!=t[j]){
				cnt++;
			}
		}
		ans=min(ans,cnt);
	}
	cout<<ans<<endl;
	return 0;
}

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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X,i) ((X>>i)&1)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define ina(x,n) rep(x_i,n) cin>>x[x_i]
#define outa(x,n) rep(x_i,n) cerr<<x[x_i]<<" \n"[x_i==n-1]

using ll  = long long int;
using vl  = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;
using vll = vector<pll>;

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

const int inf = (1<<28);
const ll infl = (1LL<<60);
const int mod = 1e9+7;

int toBlack(char s, char t) {
    return s == '.' && t == '#';
}

int toWhite(char s, char t) {
    return s == '#' && t == '.';
}

int main() {
    int h, w; cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    vvl dp(h, vl(w, inf));
    dp[0][0] = (s[0][0] == '.') ? 0 : 1;
    rep(i,h-1) {
        dp[i+1][0] = dp[i][0] + toBlack(s[i][0], s[i+1][0]);
    }
    rep(j,w-1) {
        dp[0][j+1] = dp[0][j] + toBlack(s[0][j], s[0][j+1]);
    }
    rng(i,1,h) {
        rng(j,1,w) {
            chmin(dp[i][j], dp[i-1][j] + toWhite(s[i][j], s[i-1][j]));
            chmin(dp[i][j], dp[i][j-1] + toWhite(s[i][j], s[i][j-1]));
        }
    }
    cout << dp[h-1][w-1] << endl;
    return 0;
}


Measured memory_bytes: 384