akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> LV;

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

const int MAX = 670000;
long long fac[MAX], finv[MAX], inv[MAX];


// const int MOD = 1000000007;

// テーブルを作る前処理
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;
}

int main() {
	int x,y;cin >> x >> y;
    llong ans = 0;
    int xx=-1,yy=-1;
    for(int iy = 0;iy<y+1;iy++){
        int ix = iy*2;
        if( (ix - x)==(y - iy) ){
            yy = ix-x; xx = iy;
        }
        // REP(i,iy+1){
        //     // cout << ix-i << " " << iy+i << " : "<< iy << " " << i << endl;
        //     if((ix-i == x) && ((iy+i)== y)){
        //         xx=iy;yy=i;
        //         break;
        //     }
        // }
    }
    if(xx==-1){
        cout << 0 << endl;

    }else{
        COMinit();
        cout << COM(xx,yy)<< endl;
    }


}


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

int vis[100005],mx=-9;
map<int,map<int,int> >mp;
vector<int>adj[100005];

void dfs(int src,int par,int clr)
{
    vis[src]=1;  if(clr>mx)mx=clr;
    mp[par][src]=clr; mp[src][par]=clr; int p=0; int sz=adj[src].size();

    for(int lp=0;lp<sz;lp++)
    {
        int u=adj[src][lp];

        if(vis[u]==0)
        {
            p++; if(p==clr)p++;

            dfs(u,src,p);

        }

    }


}

int main()
{

    int n,m,i,j,k,a,b;
    vector< pair<int,int> >vct;

    scanf("%d",&n);
    for(i=1;i<=n-1;i++)
    {
        scanf("%d %d",&a,&b);  adj[a].push_back(b); adj[b].push_back(a);
        vct.push_back(make_pair(a,b));
    }

    dfs(1,-1,-1);

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

    for(i=1;i<=n-1;i++)
    {
        a=vct[i-1].first; b=vct[i-1].second; printf("%d\n",mp[a][b]);
    }



    return 0;
}


Measured memory_bytes: 28688
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

mod = 10 ** 9 + 7
def calc(num):
    ans = 1
    for i in range(1, num+1):
        ans *= i
        ans %= mod
    return ans

n, m = na()
if abs(n - m) >= 2:
    print(0)
else:
    inu = calc(n)
    saru = calc(m)
    if n == m:
        print(inu * saru * 2 % mod)
    else:
        print(inu * saru % mod)

Measured memory_bytes: 3444
#include <iostream>
#include<math.h>
#include<cmath>
#include<cstdlib>
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
	string sdush, t;
	cin >> sdush >> t;
	int count = 0;
	bool isCorrrect = false;
	int correctCount = 0;
	int index = 0;
	string ans[50], ans2;
	for (int i = 0; i < 50; i++)
	{
		ans2 += "z";
	}
	for (int i = sdush.length() - 1; i >= 0; i--)
	{
		count++;
		if (t.length() > count)
		{
			continue;
		}
		correctCount = 0;
		for (int j = 0; j < t.length(); j++)
		{
			if (sdush[i + j] == '?')
			{
				correctCount++;
				continue;
			}
			if (sdush[i + j] == t[j])
			{
				correctCount++;
			}
		}

		if (correctCount == t.length())
		{
			for (int k = 0; k < sdush.length(); k++)
			{
				if (k == i)
				{
					ans[index] += t;
					k += t.length() - 1;
				}
				else if (sdush[k] == '?')
				{
					ans[index] += 'a';
				}
				else
				{
					ans[index] += sdush[k];
				}
			}
			isCorrrect = true;
			index++;
		}

	}
	if (!isCorrrect)
	{
		ans2 = "UNRESTORABLE";
	}
	else 
	{
		for (int i = 0; i < index; i++)
		{
			if (ans2 > ans[i])
			{
				ans2 = ans[i];
			}
		}
	}
	cout << ans2 << endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int main(){
  double L; scanf("%lf", &L);
  printf("%.8lf\n", pow(L/3, 3));
  return 0;
}


Measured memory_bytes: 256
until (n=gets.to_i)==0
  l1=gets.split.map(&:to_i)
  l2=Array.new(n)
  count=0
  loop do
    l1.each.with_index do |num,id|
      l2[id]=l1.count{|item| item==num}
    end
    break if l1==l2
    count+=1
    l1=l2.dup
  end
  puts "#{count}\n#{l1.join(" ")}"
end

Measured memory_bytes: 8764
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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;
}

int main() {
  int N, K;
  cin >> N >> K;
  int X, Y;
  cin >> X >> Y;

  int ans;
  if (N <= K)
    ans = X * N;
  else
    ans = X * K + Y * (N - K);

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; long long D, A; 	
	cin >> N >> D >> A; 
	pair<long long, long long> M[200010]; 
	for(int i = 0; i < N; i++) cin >> M[i].first >> M[i].second; 
	sort(M, M+N); 
	long long H[200010] = {}; 
	long long X[200010] = {}; 
	for(int i = 1; i <= N; i++){
		X[i] = M[i-1].first; H[i] = M[i-1].second; 
	}
	X[0] = -1e18; 
	long long num[200010] = {}; 
	long long sum[200010] = {}; 
	for(int i = 1; i <= N; i++){
		int a = i-1; 
		int b = lower_bound(X, X+N+1, X[i] - D*2) - X; 
		long long c = sum[a] - sum[b-1];
		if(H[i] <= c * A){
			sum[i] = sum[i-1]; continue; 
		}
		else{
			num[i] = (H[i] - c * A + A - 1) / A; 
			sum[i] = sum[i-1] + num[i]; 
		}
	}
	cout << sum[N] << endl; 
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main(){
  ll n,k;
  cin>>n>>k;
  vector<vector<ll>> d(2010,vector<ll>(2010));
  d[0][0]=1LL;
  for(ll i=1;i<2009;i++){
    for(ll j=0;j<i;j++){
      if(j==0) d[i][j]=1LL;
      else{
        d[i][j]=(d[i-1][j-1]+d[i-1][j])%M;
      }
    }
    d[i][i]=0LL;
  }
  n=n-k+1LL;
  ll c=n;
  for(ll i=1;i<=k;i++){
    cout<<(((n*d[k][i-1])%M)*modinv(i,M))%M<<endl;
    n=(n*modinv(i,M))%M;
    c--;
    n=n*c%M;
  }
}

Measured memory_bytes: 31872
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793




int main(){
    ll ans=0;
    int n;
    cin >> n;
    vector<ll> a(n),b(n);
    rep(i,n)cin >> a.at(i) >> b.at(i);
    reverse(a.begin(),a.end());
    reverse(b.begin(),b.end());
    rep(i,n){
        ll x=a.at(i)+ans;
        ll psh;
        if((x%b.at(i))==0)psh=0;
        else psh=b.at(i)-(x%b.at(i));
        ans+=psh;
    }
    cout << ans << endl;
}
       

Measured memory_bytes: 4824
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[n];
  rep(i,n) cin>>a[i];
  int ans=0;
  sort(a,a+n);
  rep(i,n){
    repi(j,i+1,n){
      repi(k,j+1,n){
	//cout<<a[i]<<" "<<a[j]<<" "<<a[k]<<endl;
	if(a[i]!=a[j] && a[j]!=a[k] && a[i]!=a[k]){
	  if(a[k]<a[i]+a[j]) ans++;
	}
      }
    }
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3640
N=int(input())
h=list(map(int, input().split()))
c=i=0
while sum(h)>0:
  if h[i]>0:
    j=i
    c+=1
    while j<N and h[j]>0:
      h[j]-=1
      j+=1
  else:
    i+=1
print(c)

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

#define ll long long
#define pll pair<ll, ll>
#define rep(x, l, r) for (x = l; x < r; x++)

const ll mod=1000000007;
const char nl='\n';

void solve()
{
	ll i, j, k, l, m, n, u, v,x,y,z,c,r,g,q;
    cin>>n>>k;
    vector<ll> arr(n),ans(n,100000000000000);
    for(i=0;i<n;i++) cin>>arr[i];
    ans[0]=0;
    for(i=0;i<n;i++){
        x=k;
        j=i+1;
        while(x && j<n){
            ans[j]=min(ans[j], abs(arr[j]-arr[i])+ans[i]);
            x--;
            j++;
        }
    }
    cout<<ans[n-1];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
//    cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}


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

vector<int> t, s, d;
bool cmp(int i, int j) { return t[i] < t[j]; }

int main() {
    int N, M;
    while (cin >> N >> M, N) {
        vector<int> res(N, 0); res[0] = 1;
        t.resize(M); s.resize(M); d.resize(M);
        for (int i = 0; i < M; ++i) cin >> t[i] >> s[i] >> d[i], --s[i], --d[i];
        vector<int> ind(M); iota(ind.begin(), ind.end(), 0);
        sort(ind.begin(), ind.end(), cmp);
        for (auto i : ind) {
            if (res[s[i]] == 1) res[d[i]] = 1;
        }
        int num = 0;
        for (auto r : res) num += r;
        cout << num << endl;
    }
}


Measured memory_bytes: 3456
N,K=map(int,input().split())
ls=list(map(int,input().split()))
ls_p=[(ls[i]+1)/2 for i in range(N)]
a=0
for i in range(K):
  a+=ls_p[i]
b=a  
for i in range(N-K):
  c=a+ls_p[i+K]-ls_p[i]
  b=max([b,c])
  a=c
print(b)

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

bool all_same(string S){
	char prev = S[0];
  	for (const auto &s: S)
      if (prev != s) return false;
  	return true;
}

int64_t f(string S){
    int n = S.length();
    int64_t ans = 0;
    int cnt = 0;
    char prev = 'A';
    for (int i = 0; i < n; i++){
        if (prev == S[i])
            cnt++;
        else{
            ans += cnt / 2;
            cnt = 1;
            prev = S[i];
        }
    }
    ans += cnt / 2;
    return ans;
}

int main(void){
    // Your code here!
    string S;
    int64_t k;
    cin >> S >> k;
  	
  	if (all_same(S)){
  		cout << S.size() * k / 2 << endl;
  		return 0;
	}
  
    cout << f(S) + (f(S + S) - f(S)) * (k - 1) << endl;
}


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


def solve(A: int, B: int, C: int):
    print(max(C - (A - B), 0))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)

if __name__ == '__main__':
    main()


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

int main(){
    vector<int> v(10);
    for(int i = 0; i< 10; i++){
        cin >> v[i];
    }
   sort(v.begin(),v.end(),greater<int>());
   cout << v[0] << endl;
   cout << v[1] << endl;
   cout << v[2] << endl;
}

Measured memory_bytes: 3120
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())

ans = [0]*N
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            val = x**2+y**2+z**2+x*y+y*z+z*x
            if val<=N:
                ans[val-1] += 1

for v in ans:
    print(v)

Measured memory_bytes: 74472
import Control.Applicative

main = do 
    [a, b] <- map read . words <$> getLine
    s <- lines <$> getContents
    mapM_ putStrLn (solver a b s)
    
solver :: Int -> Int -> [String] -> [String]
solver a b s = zipWith2 (f '#') s $ fmap2 (head . show) $ foldl1 (zipWith2 (+)) $ liftA3 (.) ud rl [fmap2 (fromEnum . ('#' == )) s]
    where
        ud = [shiftl s0, id, shiftr s0]
        rl = [(fmap (shiftl 0)), id, (fmap (shiftr 0))]
        fmap2 = fmap . fmap
        zipWith2 = zipWith . zipWith
        shiftl x xs = tail xs ++ [x]
        shiftr x xs = x : (init xs)
        s0 = take b (repeat 0)
        f a b c = if (a == b) then a else c

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

#define pb(a) push_back(a)
#define mp make_pair

#define dump(x)  cout << #x << " = " << (x) << "\n";
#define COUT(x) cout<<(x)<<"\n"

int main()
{
    int n, d, x = 0;
    cin >> n >> d >> x;
    vector<int> a(n);
    int ct = 0;
    REP(i, n)
    {
        cin >> a[i];
        for(int j = 0; j < d; j += a[i])
        {
            ct++;
        }
    }
    ct += x;
    COUT(ct);

    return 0;
}

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    if(N == 4)return 0 & puts("aaca\nbbca\nacbb\nacaa");
    if(N == 2)return 0 & puts("-1");
    unsigned long M{N * (N + 1)}, R{N + 1};
    string t(M, '.');
    for(unsigned long i{0}; i < N; ++i)t[(i + 1) * (N + 1) - 1] = '\n';
    t[0] = t[1] = t[M - 2] = t[M - 3] = 'a';
    t[R] = t[2 * R] = t[M - R - 2] = t[M - 2 * R - 2] = 'b';
    t[R - 2] = t[2 * R - 2] = t[(N - 1) * R] = t[(N - 2) * R] = 'a';
    t[R - 3] = t[R - 4] = t[M - R + 1] = t[M - R + 2] = 'b';
    for(unsigned long i{1}, j{R + 1}; i + 3 < N; ++i, j += R + 1)t[j + 1] = t[j + 2] = t[j + R] = t[j + 2 * R] = char('a' | (i & 1) << 1);
    cout << t;
    return 0;
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    string s;
    cin >> n >> s >> q;
    vector<set<int>> ve(26);
    for (int i = 0; i < n; ++i) {
        ve[s[i]-'a'].insert(i);
    }

    while (q--) {
        int type;
        cin >> type;
        if (type == 1) {
            int i;
            char ch;
            cin >> i >> ch;
            --i;
            ve[s[i]-'a'].erase(i);
            s[i] = ch;
            ve[s[i]-'a'].insert(i);
        } else {
            int l, r, cnt = 0;
            cin >> l >> r;
            --l, --r;
            for (int i = 0; i < 26; ++i) {
                auto it1 = ve[i].lower_bound(l);
                auto it2 = ve[i].upper_bound(r);
                if (it1 != it2) ++cnt;
            }
            cout << cnt << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 24348
#include <iostream>
#include <vector>
 
bool judge(int m, int total, int a)
{
  return (a >= (double)total / 4 / m);
}
 
int main()
{
    int n,m;
    std::vector<int> a;
 
  	std::cin >> n >> m;
	a.resize(n);
 
  	int total = 0;
    for (int i = 0; i < n; ++i)
    {
      std::cin >> a[i];
      total += a[i];
    }
 
  	int selectable = 0;
    for (int i = 0; i < n; ++i)
    {
      if (judge(m, total, a[i]))
      {
        ++selectable;
      }
      
      if (selectable >= m)
      {
        std::cout << "Yes" << std::endl;
        return 0;
      }
    }
 
  	std::cout << "No" << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector< int > vi;
typedef pair< int , int > pi;
typedef set< int > se;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define Fn 1.618033987
int main() 
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin>>n;
    if(n%1000==0)
    {
        cout<<0<<"\n";
    }
    else{
    ll ans=n/1000;
    ++ans;
    ans=ans*1000;
    ans=ans-n;
    cout<<ans<<'\n';}
    return 0; 
}

Measured memory_bytes: 3616
use proconio::{input, fastout};
use proconio::marker::Chars;

macro_rules! echo {
  ($val:expr) => {
    println!("{}", $val);
  }
}

fn check(s: &Vec<char>, i: usize, t: &Vec<char>) -> bool {
  if i + t.len() > s.len() {
    return false;
  }
  for j in 0..t.len() {
    if s[i+j] != t[j] {
      return false;
    }
  }
  true
}

#[fastout]
fn main() {
  input!{
    s: Chars
  };
  let mut idx = s.len();
  let keywords = ["dream", "dreamer", "erase", "eraser"];
  let keywords : Vec<Vec<char>> = keywords.iter().map(|kw| kw.chars().collect()).collect();
  loop {
    let old_idx = idx;
    for kw in &keywords {
      if idx >= kw.len() && check(&s, idx-kw.len(),kw) {
        idx -= kw.len();
        break;
      }
    }
    if old_idx == idx {
      echo!("NO");
      break;
    }
    if idx == 0 {
      echo!("YES");
      return;
    }
  }
  // let mut dp = vec![false; s.len()+1];
  // dp[0] = true;
  // let keywords = ["dream", "dreamer", "erase", "eraser"];
  // let keywords : Vec<Vec<char>> = keywords.iter().map(|kw| kw.chars().collect()).collect();
  // for i in 0..s.len() {
  //   if dp[i] {
  //     for kw in &keywords {
  //       if check(&s, i, kw) {
  //         dp[i+kw.len()] = true;
  //       }
  //     }
  //   }
  // }
  // if dp[s.len()] {
  //   echo!("YES");
  // } else {
  //   echo!("NO");
  // }
}


Measured memory_bytes: 2588
#include<stdio.h>
#include<math.h>
#define EPS 1e-10

double surface(double x1,double y1,double x2, double y2, double x3 ,double y3){
  double len1,len2,len3;
  double s;

  len1 = sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );
  len2 = sqrt( (x2-x3)*(x2-x3) + (y2-y3)*(y2-y3) );
  len3 = sqrt( (x1-x3)*(x1-x3) + (y1-y3)*(y1-y3) );

  s = (len1 + len2 + len3) / 2.0;

  return sqrt( s*(s-len1)*(s-len2)*(s-len3) );
}

int main(void){

  double s1,s2,s3,sp;
  double x1,x2,x3,xp;
  double y1,y2,y3,yp;

  while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp) != EOF){

    s1 = surface(x2,y2,x3,y3,xp,yp);
    s2 = surface(x1,y1,x3,y3,xp,yp);
    s3 = surface(x1,y1,x2,y2,xp,yp);
    sp = surface(x1,y1,x2,y2,x3,y3);

    if(fabs(s1 + s2 + s3 - sp) < EPS)printf("YES\n");
    else printf("NO\n");

  }

  return 0;
} 

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

using namespace std;

typedef	pair<double,int>	pii;

struct pack{
	int deno,nume;
	string s;
};

bool operator<(const pack &p1,const pack &p2)
{
	double r1=1.*p1.nume/p1.deno,r2=1.*p2.nume/p2.deno;
	if(abs(r1-r2)<1e-8 && p1.s>p2.s)	return true;
	if(r1+1e-8<r2)	return true;
	return false;
}

int main()
{
	for(int n;cin>>n,n;){
		pack eff[50];
		for(int i=0;i<n;i++){
			string l;
			int p,a,b,c,d,e,f,s,m;
			cin>>l>>p>>a>>b>>c>>d>>e>>f>>s>>m;
			eff[i].deno=a+b+c+m*(d+e);
			eff[i].nume=m*s*f-p;
			eff[i].s=l;
		}
		sort(eff,eff+n);
		for(int i=n-1;i>=0;i--)	cout<<eff[i].s<<endl;
		cout<<'#'<<endl;
	}

	return 0;
}

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

map < long long, long long > m;
map < long long, long long > c;

long long jump[200005];
bool visited[200005];
bool pass = false;
long long aux = -1;
long long ini = -1;

long long buck(long long pos, long long sal) {
  m[sal] = pos;
  if (visited[pos]) {
    ini = pos;
    aux = c[pos];
    return sal - c[pos];
  }
  c[pos] = sal;
  visited[pos] = true;
  return buck(jump[pos], sal + 1); 
}

long long ans(long long pos, long long sal) {
  if (sal == 0)
    return pos;
  return ans(jump[pos], sal - 1);
}

int main() {
  long long n;
  long long k;
  cin >> n >> k;
  for (long long i = 0; i < n; i++) {
    cin >> jump[i];
    jump[i]--;
  }
  long long b = buck(0, 0);
  if (k < aux) {
    cout << ans(0, k) + 1 << '\n';
  }else {
    k -= aux;
    long long rest = k % b;
    cout << ans(ini, rest) + 1 << '\n';
  }
  return 0;
}

Measured memory_bytes: 48448
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

	int n;
	cin >> n;
	vll a(n);
	vll s(n);
	vll t(n);
	cin >> a[0];
	s[0] = a[0];
	repr(i, 1, n) {
		cin >> a[i];
		s[i] = s[i - 1] + a[i];
	}

	t[n - 1] = a[n - 1];
	reprev(i, n-1) {
		t[i] = t[i + 1] + a[i];
	}
	
	ll ans = INFL;
	rep(i, n-1) {
		ans = min(ans, abs(s[i] - t[i + 1]));
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4992
/*AOJ 0033 ball DFS*/ 
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;

int ball[15],lside[15],rside[15];
int kase;

void dfs(int i,int l,int r){
	if(i> 10){
		kase = 1;
		return;
	}
	if(kase)	return;
	if(ball[i]>lside[l-1]){
		lside[l] = ball[i];
		dfs(i+1,l+1,r);
	}
	if(ball[i]>rside[r-1]){
		rside[r] = ball[i];
		dfs(i+1,l,r+1);
	}
}


int main(void){
	int n;
	scanf("%d",&n);
	while(n--){
		for(int i=1;i<=10;i++)
			scanf("%d",&ball[i]);
		kase = 0;
		dfs(1,1,1);
		if(kase)	printf("YES\n");
		else	printf("NO\n");
	}
	return 0;
}


Measured memory_bytes: 3092
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);

		int n=sc.nextInt();

		char s[]=new char[n];
		int r[]=new int[n];
		for(int i=0;i<n;i++){
			String str=sc.next();
			s[i]=str.charAt(0);
			r[i]=sc.nextInt();
		}

		int sp[]=new int[13];
		int he[]=new int[13];
		int cl[]=new int[13];
		int di[]=new int[13];
		int x;
		for(int i=0;i<n;i++){
			switch(s[i]){
			case 'S':
				x=r[i];
				sp[x-1]++;
				break;
			case 'H':
				x=r[i];
				he[x-1]++;
				break;
			case 'C':
				x=r[i];
				cl[x-1]++;
				break;
			case 'D':
				x=r[i];
				di[x-1]++;
				break;
			}
		}
			for(int i=0;i<13;i++){
				if(sp[i]==0)		System.out.println("S "+(i+1));
			}
			for(int i=0;i<13;i++){
				if(he[i]==0)		System.out.println("H "+(i+1));
			}
			for(int i=0;i<13;i++){
				if(cl[i]==0)		System.out.println("C "+(i+1));
			}
			for(int i=0;i<13;i++){
				if(di[i]==0)		System.out.println("D "+(i+1));
			}
		}
	}

Measured memory_bytes: 26144
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e5+2;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int n;
      cin>>n;
      vector<pii> a;
      for(int i=1;i<=n;i++)
      {
            int x;
            cin>>x;
            a.pb({x,i});
      }
      sort(all(a));
      for(auto x:a) cout<<x.se<<" ";
}
// I never lose. I either win or I learn

Measured memory_bytes: 2544
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    int N; cin >> N;
    vector<pair<int, int>> A(N);
    int Rmin, Rmax, Bmin, Bmax;
    Rmin = Bmin = 1e9;
    Rmax = Bmax = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i].first >> A[i].second;
        if (A[i].first > A[i].second) swap(A[i].first, A[i].second);
        Rmin = min(Rmin, A[i].first), Rmax = max(Rmax, A[i].first);
        Bmin = min(Bmin, A[i].second), Bmax = max(Bmax, A[i].second);
    }
    sort(begin(A), end(A));
    Int ans = (Int)(Rmax - Rmin) * (Bmax - Bmin);
    int m = 1e9;
    for (int i = 0; i < N-1; i++) {
        m = min(m, A[i].second);
        Rmin = min(m, A[i+1].first);
        Rmax = max(Rmax, A[i].second);
        Bmin = min(Bmin, A[i].first);
        ans = min(ans, (Int)(Rmax - Rmin) * (Bmax - Bmin));
        if (Rmin != A[i+1].first) break;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <vector>
#include <stdio.h>
#include <string>

int main(){
	int n,A,B; cin >> n >> A >> B ;
  	string s; cin>> s;
  	int cnt_t = 0;//total
  	int cnt_a = 0;//abroad
  
 	for(int i= 0; i<n; i++){

    if(s[i] == 'a' && cnt_t < A+B){
      cout << "Yes" << endl;
      cnt_t++;
    } 
    else if (s[i] == 'b' && cnt_t < A+B && cnt_a < B){
      cout << "Yes" << endl;
      cnt_t++;
      cnt_a++;
    }
    else {
    cout << "No" << endl;
    }
    }

  
}

Measured memory_bytes: 896
#pragma GCC optimize "trapv"
#include <bits/stdc++.h>
#define int int64_t
#define M 1000000007
#define SZ 200005
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;



int32_t main()
{
	int n,len;
	cin>>n;
	string s;
	cin>>s;
	len=s.size();
	if(n>=len)
	{
		cout<<s<<"\n";
	}
	else
	{
		cout<<s.substr(0,n)<<"...\n";
	}
	
	return 0;
}

/*
	cin>>n;
		int a[n];
		for(i=0;i<n;i++)
		{
			cin>>a[i];
		}

	string s;
		cin>>s;

	ifstream cin("input.txt");
	ofstream cout("output.txt");
*/

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
const double PI = acos(-1);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

/*C++になってるか確認したほうがよくない？WOWWOW*/
/*DP使ったほうがよくない？？WOWWOW*/

int main(){
    int K; cin>>K;
    string S, ans; cin>>S;

    if(S.size()<=K){
        ans=S;
    }
    else{
        ans=S.substr(0, K)+"...";
    }
    cout<<ans<<endl;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

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

void solve() {
  int x, y;
  cin >> x >> y;
  repc(a, x) {
    int b = x - a;
    int sum = a * 2 + b * 4;
    if (sum == y) yes();
  }
  no();
}


Measured memory_bytes: 3652
// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
    "1 2" => "Even",
    "10 2" => "Even",
    "1 23" => "Odd"
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        a: u32,
        b: u32,
    }

    let ans = if (a * b) % 2 == 0 { "Even" } else { "Odd" };
    ans.to_string()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
const int maxn=100005;
int n,a[maxn];
int cnt[2][maxn];
int id[2][maxn];
vector<int>q[2];
int main(){
 // freopen("aa.in","r",stdin);
  int n;scanf("%d",&n);
  for(int i=1;i<=n;i++){
    scanf("%d",a+i);
    cnt[i&1][a[i]]++;
  }
  for(int i=0;i<2;i++){
    for(int j=1;j<maxn;j++)id[i][j]=j;
    sort(id[i]+1,id[i]+maxn,[&](int x,int y){
      return cnt[i][x]>cnt[i][y];
    });
  }
  int ans=n;
  for(int i=0;i<2;i++){
    for(int j=1;j<=min(2,n/2);j++){
      q[i].push_back(id[0][j]);
      q[i].push_back(id[1][j]);
    }
  }
  for(int i=0;i<4;i++){
    for(int j=0;j<4;j++)if(q[0][j]!=q[1][i]){
      int res=0;
      for(int k=1;k<=n;k++){
        if(k&1){
          if(a[k]!=q[1][i])res++;
        }else{
          if(a[k]!=q[0][j])res++;
        }
      }
      ans=min(ans,res);
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int e[705][705];
vector<int> g[705];
int col[705];
int cnt[3];
int used[705];
int dp[705][705];
bool binary_graph(int v,int c){
	col[v]=c;
	cnt[c+1]++;
	used[v]=true;
	bool ret = true;
	for(int i=0;i<g[v].size();i++){
		int u = g[v][i];
		if(used[u]){
			if(col[u]==c){
				ret=false;
			}
		}else{
			if(!binary_graph(u,-c))ret=false;
		}
	}
	return ret;
}
int N,M;
int main(){
	cin >> N >> M;
	for(int i=0;i<N;i++){
		e[i][i]=1;
	}
	for(int i=0;i<M;i++){
		int A,B;
		cin >> A >> B;
		A--;B--;
		e[A][B]=e[B][A]=1;
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(e[i][j]==0){
				g[i].pb(j);
			}
		}
	}
	bool res = true;
	vector<int> vec;
	for(int i=0;i<N;i++){
		if(!used[i]){
			cnt[0]=cnt[2]=0;
			res &= binary_graph(i,1);
			//cout << res << endl;
			//cout << cnt[0] << ' ' << cnt[2] << endl;
			if(res)vec.pb(abs(cnt[0]-cnt[2]));
		}
	}
	if(!res){
		cout << -1 << endl;
		return 0;
	}
	dp[0][0]=1;
	for(int i=0;i<vec.size();i++){
		for(int j=0;j<=700;j++){
			if(dp[i][j]==0)continue;
			dp[i+1][abs(j-vec[i])]=1;
			dp[i+1][j+vec[i]]=1;
		}
	}
	int K = -1;
	for(int i=0;i<=700;i++){
		if(dp[vec.size()][i]==1){
			K=i;
			break;
		}
	}
	//cout << K << endl;
	int C = (N+K)/2,D = (N-K)/2;
	//cout << C << ' ' << D << endl;
	cout << C*(C-1)/2+D*(D-1)/2 << endl;
	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }

  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
  int N; cin >> N;
  int ans = 0;
  for(int i = 1; i <= N; ++i) {
    if(i % 2 == 1) {
      auto x = divisor(i);
      if(x.size() == 8) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
from collections import defaultdict
import queue

N,M = map(int,input().split())

L = [list(map(int,input().split())) for i in range(M)]

renketu = 0
for m in range(M): #取り除く辺
    D = defaultdict(list) #探索準備
    for l in L[:m]+L[m+1:]:
        a,b = l[0],l[1]
        D[a].append(b)
        D[b].append(a)
    Q = queue.Queue()
    Q.put(L[0][0])
    walked = [L[0][0]]
    #print(walked,end="→")
    while(True):
        now = Q.get()
        for d in D[now]:
            if d not in walked:
                Q.put(d)
                walked.append(d)
        #print(walked,end="→")
        if len(walked)==N:break
        if Q.empty():break
    if len(walked)==N:
        #print("{} is not Bridge".format(L[m]))
        renketu+=1
    #print()
        
print(M-renketu)

Measured memory_bytes: 3952
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b;
  cin>>n>>a>>b;
  int ans=0;
  for(int i=1;i<=n;i++){
    int t=i;
    int sum=0;
    while(t){
      sum+=t%10;
      t/=10;
    }
    if(sum<a||b<sum)continue;
    ans+=i;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    s = in_s()

    if s.isupper():
        ans = 'A'
    else:
        ans = 'a'

    print(ans)


if __name__ == '__main__':
    main()


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

#define sz(x) int(x.size())
#define pii pair<int, int>
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define Debug(X) cout << #X << " = " << X << '\n'
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 2e4 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

int f[maxn];

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin);  freopen(Task".out", "w", stdout);
  int n, h; cin >> h >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
  memset(f, inf, sizeof f);
  f[0] = 0;
  const int mx = 2e4;
  for (int i = 0; i < n; ++i){
    for (int p = 0; p <= mx - a[i]; ++p) f[p + a[i]] = min(f[p + a[i]], f[p] + b[i]);
  }

  int ans = inf;
  for (int p = h; p <= mx; ++p) ans = min(ans, f[p]);
  cout << ans;
}




Measured memory_bytes: 384
li=[int(input()) for i in range(5)]
t = [0,0,0,0,0]
for i in range(5):
    if li[i] % 10 == 0:
        t[i] = 10
    else:
        t[i] = li[i] % 10
T = 10 - min(t)

score = 0
for i in range(5):
    if li[i] % 10 == 0:
        score += li[i]
    else:
        score += li[i] + 10 - li[i] % 10

score -= T
print(score)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <bitset>
#include <functional>
using namespace std;
const constexpr int INF = 1e9;
//typedef std::pair<std::string,double> P;


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

typedef long long ll;
typedef vector<int> VI;
const constexpr ll MOD = 1e9+7;
vector<pair<int, int> > vp;
 
struct Less {
    bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
        return x.first > y.first;
    }
};

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


//グラフの隣接リスト
VI g[200010];
//頂点の入次数を管理
int h[100010];
ll N, H;
string s;
ll a[100010], b[100010];

int main(void) {
    int i;
    cin >> N >> i;
    cout << N-i+1 << endl;
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using ll = long long;
#define int long long
bool ok(string t, int i){
    if(count(t.begin(), t.end(), char(i + 'a')) == t.size()) return true;
    else return false;
}
signed main(void){
    string s; cin>>s;
    int ans = s.size();
    rep(i, 26){
        int cnt = 0;
        int tmp = 0;
        rep(j, s.size()){
            if(s[j] == i + 'a') {tmp = max(tmp, cnt); cnt = 0; }
            else cnt++;
        }
        tmp = max(tmp, cnt);
        //cout<<tmp<<endl;
        ans = min(ans, tmp);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import math
n,d=map(int,input().split())
x=[list(map(int,input().split())) for _ in range(n)]
a=0
for i in range(n):
	for j in range(i+1,n):
		a += math.modf(math.sqrt(sum([abs(x[i][k] - x[j][k])**2 for k in range(d)])))[0] < 1e-9
print(a)

Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func readLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func lineToInts(line string) []int {
	var res []int
	for _, s := range strings.Split(line, " ") {
		i, _ := strconv.Atoi(s)
		res = append(res, i)
	}
	return res
}

func judge(as, bs []int, m, c int) bool {
	calc := 0
	for j := 0; j < m; j++ {
		calc += as[j] * bs[j]
	}
	calc += c
	return calc > 0
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	line1 := lineToInts(readLine(sc))
	n := line1[0]
	m := line1[1]
	c := line1[2]

	bs := lineToInts(readLine(sc))
	res := 0
	for i := 0; i < n; i++ {
		as := lineToInts(readLine(sc))
		if judge(as, bs, m, c) {
			res++
		}
	}
	fmt.Println(res)
}


Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>

int
isprime(int x)
{
    int i = 3;

    if (x == 2)
        return 1;

    if (x < 2)
        return 0;

    if ((x % 2) == 0)
        return 0;

    while (i <= sqrt(x)) {
        if ((x % i) == 0)
            return 0;
        i = i + 2;
    }
    return 1;
}

int
main()
{
    int n, i, x, c = 0;

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%d", &x);
        if (isprime(x))
            c++;
    }
    printf("%d\n", c);
    return 0;
}


Measured memory_bytes: 2100
cards = ""
for i in range(10):
    e = input()
    if e == "-":
        break
    else:
        cards = e
        len_cards = len(cards)
        m = int(input())
        for j in range(m):
            cards += cards
            h = int(input())
            cards = cards[h:h-len_cards]
        print(cards)


Measured memory_bytes: 5596
def main():
    ns=input()
    ln=len(ns)
    n=int(ns)
    cd={}
    for b in range(1,10):
        for e in range(1,10):
            c=0
            if b==e and (ln>1 or b<=n):
                c+=1 
            if ln>2:
                c+=(10**(ln-2)-1)//9
            if ln>1:
                if b<int(ns[0]):
                    c+=10**(ln-2)
                elif b==int(ns[0]):
                    if ln>2:
                        c+=int(ns[1:-1])
                    if e<=int(ns[-1]):
                        c+=1
            cd[(b,e)]=c 
    s=0
    for b in range(1,10):
        for e in range(1,10):
            s+=cd[(b,e)]*cd[(e,b)]
    print(s)

main()

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

#define int long long int
#define ff first
#define ss second
#define pb push_back


int bexp(int a, int b)
{
    int res = 1;

    while (b)
    {
        if (b & 1) res = (res * a);

        a = (a * a); 
        b >>= 1;
    }
    return res;
}

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

#define N 200010
#define MOD 1000000007


int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);

    int n;
    cin >> n;

    int ans = (n / 500) * 1000 + ((n % 500) / 5) * 5;

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

Measured memory_bytes: 256
package main

import "fmt"

var a, b int

// a <= x * 8 / 100 < a+1
// b <= x / 10 < b+1
// x-10 < 10 * b <= x
func main() {
	fmt.Scan(&a, &b)
	for x := 10 * b; x < 10*b+10; x++ {
		if a == x * 8 / 100 {
			fmt.Println(x)
			return
		}
	}
	fmt.Println(-1)
}


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

mod = 10 ** 9 + 7
ans = 0
60.times do |d|
  one = 0
  a.each do |ai|
    one += 1 if ai[d] == 1
    # zero += 1 if ai[d] == 0
  end
  ans += one * (n - one) * (2 ** d)
  ans %= mod
end
p ans


Measured memory_bytes: 34820
import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline()[:-1]
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def MF(): return map(float, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LF(): return list(map(float, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]

def main():
    while 1:
        n,r=MI()
        if n==0:break
        aa=list(range(n,0,-1))
        for _ in range(r):
            p,c=MI()
            aa=aa[p-1:p-1+c]+aa[:p-1]+aa[p-1+c:]
        print(aa[0])

main()



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

using namespace std;

typedef long long ll;

ll n, m, k, sum;

void dfs(ll dep, double wa)
{
    for (int i = 1; i <= m; i++)
    {
        if (dep == n)
        {
            if ((wa + i - k) < 1)
                sum += 1;
            else
                sum += (wa + i - k);
        }
        else
            dfs(dep + 1, wa + i);
    }
}

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

    while (true)
    {
        sum = 0;
        cin >> n >> m >> k;
        if (n == 0 && m == 0 && k == 0)
            break;
        dfs(1, 0);
        double bunbo = 1;
        for (int i = 0; i < n; i++)
            bunbo *= m;
        //cout<<sum<<endl<<bunbo<<endl;
        cout << fixed << setprecision(10) << sum / bunbo << endl;
    }
    return 0;
}


Measured memory_bytes: 3228
N,M=gets.split.map(&:to_i)
ms = M.times.map {
    k,*ss=gets.split.map(&:to_i)
    ss.inject(0) { |m,s| m += 1 << (s-1) }
}
*ps = gets.split.map(&:to_i)
mps = ms.zip(ps)

def bit_count(n)
    (0..N-1).count {|i| n[i] == 1}
end

puts (0..2**N-1).count {|i|
    mps.all? {|m,p| bit_count(m&i) % 2 == p }
}

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

int main(){
  int n;
  cin >> n;
  int cnt = 0, ban = 1;
  rep(i,n){
    int a;
    cin >> a;
    if(a != ban) cnt++;
    else ban ++;
  }
  if(cnt == n) cout << -1 << endl;
  else cout << cnt << endl;
}


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

int main(){
	int n;
  	cin >> n;
  
  	for(int i = 0; i <= n/4;i++){
    	for(int j = 0; j <= n/7;j++){
        	if(i*4+j*7==n){
            	cout << "Yes" <<endl;
              return 0;
            }
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int c11, c12, c13;
    int c21, c22, c23;
    int c31, c32, c33;
    
    cin >> c11 >> c12 >> c13;
    cin >> c21 >> c22 >> c23;
    cin >> c31 >> c32 >> c33;
    
    if(c11-c12==c21-c22&&c21-c22==c31-c32){
        
        if(c12-c13==c22-c23&&c22-c23==c32-c33){
            
            cout << "Yes" << endl;
            
            return 0;
            
        }
        
    }
    
    cout << "No" << endl;
    
    return 0;
    
}

Measured memory_bytes: 256