akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(){
    int n;
    cin >> n;
    string ans = "No";
    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            if(i*j == n) ans = "Yes";
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;
const double PI = acos(-1.0);

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll number1, ll number2)
{
    return number1 * number2 / gcd(number1, number2);
}
template <class T>
bool contain(const std::string &s, const T &v)
{
    // contain(to_string(N), '3')
    return s.find(v) != std::string::npos;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
        return c - '0';
    return 0;
}
using namespace std;

void transpose(vector<vector<char>> &b)
{
    if (b.size() == 0)
        return;

    vector<vector<char>> trans_vec(b[0].size(), vector<char>());

    for (int i = 0; i < b.size(); i++)
    {
        for (int j = 0; j < b[i].size(); j++)
        {
            trans_vec[j].push_back(b[i][j]);
        }
    }

    b = trans_vec; // <--- reassign here
}

int main()
{

    int ans = 0, n;
    string s;
    cin >> n >> s;
    rep(i, n - 2)
    {
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
        sc.Scan()
        return sc.Text()
}

func main() {
        var l int

        length := nextLine()
        targetStr := nextLine()

        l, _ = strconv.Atoi(length)

        targetLength := len(targetStr)
        if l < targetLength {
                //idx := l - 1
                // left := targetLength - idx
                head := targetStr[:l]

                // for i := 0; i < left; i++ {
                //      head = head + "."
                // }
                fmt.Println(head + "...")

        } else {
                fmt.Println(targetStr)
        }

}

Measured memory_bytes: 1756
import java.util.*;
public class Main{
public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
  int m=sc.nextInt();
  m/=1000;
  boolean b=false;
  for(int i=0;i<=n;i++){
  for(int j=0;j<=n-i;j++){
  	if(m==i*10+j*5+(n-i-j)){
    System.out.println(i+" "+j+" "+(n-i-j));
      b=true;
      break;
    }
  }
    if(b)break;
  }
  if(!b)System.out.println("-1 -1 -1");
}
}

Measured memory_bytes: 22740
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define inf 10000000000

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

    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    char diff = 'A' - 'a';
    cout << (char)(s1[0] + diff) << (char)(s2[0] + diff) << (char)(s3[0] + diff) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
    ~debug() { cerr << endl; }
    eni(!=) cerr << boolalpha << i; ris; }
    eni(==) ris << range(begin(i), end(i)); }
    sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
    }
    sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
    }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<long double> vld;
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846
#define sqr(a) ((a) * (a))
#define len(V) (int)V.size()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define fix(a) fixed << setprecision(a)
#define readv(x) for(auto &_ : (x)) {cin >> _;}
#define printv(x) for(auto &_ : (x)) {cout << _ << ' ';} cout << endl
#define EPS 1e-6
#define MAXN 100047

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n, a, b; cin >> n >> a >> b;
	string s; cin >> s;
	int x = a + b, b1 = 0;
	
	FOR(i, 0, n){
		if (s[i] == 'a' && x > 0){
			x--;
			cout << "Yes\n";
		}
		else if (s[i] == 'b' && b1 < b && x > 0){
			cout << "Yes\n";
			x--;
			b1++;
		}
		else cout << "No\n";
	}
	
	return 0;
}


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

using namespace std;

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

    int N;
    cin >> N;
    vector<int> W(N);
    for (int i = 0; i < N; ++i) {
        cin >> W[i];
    }
    int sum = accumulate(begin(W), end(W), 0);
    int cur = 0, res = 1000000;
    for (int i = 0; i < N - 1; ++i) {
        cur += W[i];
        sum -= W[i];
        res = min(res, abs(cur - sum));
    }
    cout << res << "\n";
    
    return 0;
}

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


typedef  long long ll;
typedef long double ld;
using namespace std;
using namespace __gnu_pbds;


#define endl "\n"
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int N=3e5+5;
ll mod=1e9+7;
ll mul (ll a, ll b)
{
    a%=mod;
    b%=mod;
    return (a*b)%mod;
}
ll add (ll a, ll b)
{
    a%=mod;
    b%=mod;
    return (a+b+mod)%mod;
}
ll fastpow(ll b, ll p)
{
    if(p==0)
        return 1;
    ll ans=fastpow(b,p/2);
    ans=mul(ans,ans);
    if(p%2)ans=mul(ans,b);
    return ans;
}

ll g1[N],g2[N],arr[N];
int main()
{
    FIO
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>arr[i];
    for(int i=1;i<n;i++)
    {
        g1[i]=__gcd(g1[i-1],arr[i-1]);
    }
     for(int i=n-2;i>=0;i--)
    {
        g2[i]=__gcd(g2[i+1],arr[i+1]);
    }
    ll ans=0;
    for(int i=0;i<n;i++)
        ans=max(ans,__gcd(g1[i],g2[i]));
    cout<<ans;



    return 0;
}



Measured memory_bytes: 5920
n=int(input())
lst = list(map(int, input().split()))
ans=[]
if not(1 in lst):
    print(-1)
    quit()
while (1 in lst):
  l=len(lst)
  for i in range(l):
    if(lst[-i-1]==l-i):
      ans=[l-i]+ans
      del(lst[-i-1])
      break
  else:
    print(-1)
    quit()
if(len(ans)!=n):
    print(-1)
    quit()
for i in ans:
  print(i)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#define  endl '\n'
#define all(s) s.begin(),s.end()
#define lowbit(x) (x&-x)
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define pb push_back
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
const int N=2e5+10;
int main()
{
	int n,m,q,k;
	double r;
	cin>>r;
	cout<<2*PI*r;
}


Measured memory_bytes: 3764
import numpy as np

a_matrix = []
for i in range(3):
    a_matrix.extend(list(map(int,input().split())))
flag_list = [0 for i in range(9)]

N = int(input())
for i in range(N):
    b = int(input())
    if b in a_matrix:
        pos = a_matrix.index(b)
        flag_list[pos] = 1

ans = 'No'
flag_matrix = np.array(flag_list).reshape(3,3)
for i in range(3):
    c = sum(flag_matrix[:,i])
    d = sum(flag_matrix[i,:])
    if (c==3 or d==3):
        ans = 'Yes'

c = flag_matrix[0,0]+flag_matrix[1,1]+flag_matrix[2,2]
d = flag_matrix[0,2]+flag_matrix[1,1]+flag_matrix[2,0]
if (c==3 or d==3):
    ans = 'Yes'
print(ans)


Measured memory_bytes: 21348
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    ll a, b, n; cin >> a >> b >> n;

    ll x = b-1ll;
    if (x>n) x=n;
    cout << a*x / b - a * (x/b) << endl;
}

Measured memory_bytes: 3640
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << std::setprecision(10) << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n;
	std::cin >> n;
	double sum = 0;
	rep(i,n) {
		double a;
		std::string b;
		std::cin >> a >> b;
		if(b=="JPY") sum+=a;
		else sum+=a*380000.0;
	}
	print(sum);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#define print(n) std::cout << n << std::endl
#define print_no_indention(n) std::cout << n
using namespace std;


int main() {
    char a,b;
    cin >> a >> b;
    int count = 0;

    if(a == 'H')count++;
    if(b == 'H')count++;

    if(count % 2 == 0) print("H");
    else print("D");

}

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

#define i64 long long int

int n, m;
vector<pair<int, int> > e[55];

vector<int> t, p[22];

i64 pw[55];
i64 ans;

bool dfs_path(int cur, int par, int ed) {
	if(cur==ed) return true;
	
	for(int i=0;i<(int)e[cur].size();i++) {
		int nxt = e[cur][i].first;
		if(nxt==par) continue;
		
		t.push_back(e[cur][i].second);
		if(dfs_path(nxt, cur, ed)) return true;
		
		t.pop_back();
	}
	return false;
}

vector<int> get_path(int st, int ed) {
	t.clear();
	dfs_path(st, -1, ed);
	return t;
}

void dfs_calc(int id, set<int> s, bool flag) {
	if(id==m) {
		if(flag) ans -= pw[n-1-s.size()];
		else ans += pw[n-1-s.size()];
		
		return;
	}
	
	dfs_calc(id+1, s, flag);
	for(int i=0;i<(int)p[id].size();i++)
		s.insert(p[id][i]);
	dfs_calc(id+1, s, 1-flag);
}

int main() {
	scanf("%d", &n);
	for(int i=1;i<n;i++) {
		int x,y;
		scanf("%d%d", &x, &y);
		e[x].push_back(make_pair(y, i-1));
		e[y].push_back(make_pair(x, i-1));
	}
	scanf("%d", &m);
	for(int i=0;i<m;i++) {
		int x,y;
		scanf("%d%d", &x, &y);
		p[i] = get_path(x, y);
	}
	
	pw[0] = 1LL;
	for(int i=1;i<=n;i++)
		pw[i] = pw[i-1]*2;
	
	ans = 0LL;
	set<int> s; s.clear();
	dfs_calc(0, s, 0);
	cout<<ans<<endl;
	
	return 0;  
}

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

#define pll pair<ll,ll>
#define ff first
#define snd second
#define pb push_back
#define vll vector<ll>
#define vpll vector<pll>
#define endl "\n"
#define MOD 1000000007
using namespace std;

ll const N = 1e5+1;


void solve()
{
   char a;
   cin>>a;
   
   if(a>='A' && a<='Z')
   cout<<"A";
   else
   cout<<"a";
}
 
int main() {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
	    int t=1;
	    //cin>>t;
	    while(t--)
	    {
	            solve();
	    }
	    return 0;
}

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

int main() {
  LL n, W; cin >> n >> W;
  vector<LL> w(n), v(n);
  rep(i, n) cin >> w[i] >> v[i];

  vector<LL> w0, w1, w2, w3;
  rep(i, n) {
    if (w[i] == w[0])          w0.push_back(v[i]);
    else if (w[i] == w[0] + 1) w1.push_back(v[i]);
    else if (w[i] == w[0] + 2) w2.push_back(v[i]);
    else if (w[i] == w[0] + 3) w3.push_back(v[i]);
  }

  sort(all(w0));
  reverse(all(w0));
  sort(all(w1));
  reverse(all(w1));
  sort(all(w2));
  reverse(all(w2));
  sort(all(w3));
  reverse(all(w3));
  vector<LL> sum0(w0.size() + 1, 0);
  vector<LL> sum1(w1.size() + 1, 0);
  vector<LL> sum2(w2.size() + 1, 0);
  vector<LL> sum3(w3.size() + 1, 0);
  for (int i = 1; i <= w0.size(); i ++) sum0[i] = sum0[i - 1] + w0[i - 1];
  for (int i = 1; i <= w1.size(); i ++) sum1[i] = sum1[i - 1] + w1[i - 1];
  for (int i = 1; i <= w2.size(); i ++) sum2[i] = sum2[i - 1] + w2[i - 1];
  for (int i = 1; i <= w3.size(); i ++) sum3[i] = sum3[i - 1] + w3[i - 1];
  LL ans = 0;
  for (LL i0 = 0; i0 <= w0.size(); i0 ++) {
    for (LL i1 = 0; i1 <= w1.size(); i1 ++) {
      for (LL i2 = 0; i2 <= w2.size(); i2 ++) {
        for (LL i3 = 0; i3 <= w3.size(); i3 ++) {
          if (i0 * w[0] + i1 * (w[0] + 1) + i2 * (w[0] + 2) + i3 * (w[0] + 3) <= W) {
            ans = max(ans, sum0[i0] + sum1[i1] + sum2[i2] + sum3[i3]);
          }
        }
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  int i;
  int x =  max({a,b,c});
  for(i=0;i<k;i++){
    x *= 2;
  }
  cout << a+b+c+x-max({a,b,c}) << "\n";
  return 0;
}

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


int main(){
  int N,K;
  cin >> N >> K;
  vector<ll> H(N);
  rep(i,N){
    cin >> H[i];
  }
  sort(H.begin(),H.end());
  reverse(H.begin(),H.end());
  ll ans = 0;
  for(int i = K;i<N;i++){
    ans += H[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

mod = 10**9+7

n = int(input())
g = [[] for _ in range(n)]

for _ in range(n-1):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

par = [-1]*n
depth = [-1]*n
sizesub = [1 for _ in range(n)]
black = [0 for _ in range(n)]

root = 0
stack = [root]

while stack:
    v = stack.pop()
    if depth[v] == -1:
        if v == root:
            depth[v] = 0
        else:
            depth[v] = depth[par[v]] + 1
            stack.append(v)
        for w in g[v]:
            if depth[w] == -1:
                par[w] = v
                stack.append(w)
    else:
        sizesub[par[v]] += sizesub[v]
        black[par[v]] += pow(2, sizesub[v], mod) - 1


cnt = 0

for i in range(n):
    tmp = pow(2, n-1, mod) - pow(2, n-sizesub[i], mod) - black[i]
    tmp %= mod
    cnt += tmp
    cnt %= mod


def inv(a, mod):
    r = [1, 0, a]
    w = [0, 1, mod]
    while w[2] != 1:
        q = r[2]//w[2]
        r_new = [r[0]-q*w[0], r[1]-q*w[1], r[2]-q*w[2]]
        r = w
        w = r_new
    x, y = w[0], w[1]    # a*x+y*mod = 1
    return (mod+x % mod) % mod


print(inv(pow(2, n, mod), mod)*cnt % mod)


Measured memory_bytes: 89032
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::vector<std::vector<std::pair<int, int>>> v(n);
    for (int i = 0; i < n; i++) {
        int m;
        std::cin >> m;
        for (int j = 0; j < m; j++) {
            int x, y;
            std::cin >> x >> y;
            v[i].emplace_back(x - 1, y);
        }
    }

    int ret = 0;
    for (int i = 0; i < (1 << n); i++) {
        bool ok = true;
        for (int j = 0; j < n; j++) {
            int f = i & (1 << j);
            if (!f) continue;
            for (auto e : v[j]) {
                if (e.second ^ ((i >> e.first) & 1)) ok = false;
            }
        }
        if (ok) ret = std::max(ret, __builtin_popcount(i));
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string hyy;
	int st,wsy=0,ph=0,gsc;
	cin>>hyy;
	for (ph=0;ph<hyy.size();ph++)
	{
		if (hyy[ph]=='C')wsy=1;
		if (hyy[ph]=='F'&&wsy==1)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())

n = ni()

a = [ni() for _ in range(n)]
c = collections.Counter(a).values()
ans = 0
for t in c:
    if t % 2 != 0:
        ans += 1
print(ans)


Measured memory_bytes: 16628
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int a,b,c;
	cin >> a >> b >> c;
	cout << min({a + b, b + c, c + a});
}

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

char field[30][30];

const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};
const char dir1[] = {'^', '<', 'v', '>'};
const char dir2[] = {'U', 'L', 'D', 'R'};

int main() {
  int T; scanf("%d", &T);
  while (T--) {
    int W, H;
    scanf("%d%d", &H, &W);
    memset(field, '#', sizeof(field));
    int ty, tx, td;
    for (int y = 1; y <= H; ++y) {
      for (int x = 1; x <= W; ++x) {
        scanf(" %c", &field[y][x]);
        for (int k = 0; k < 4; ++k) {
          if (field[y][x] == dir1[k]) {
            ty = y; tx = x; td = k;
            field[y][x] = '.';
            break;
          }
        }
      }
    }

    int N; scanf("%d", &N);
    for (int i = 0; i < N; ++i) {
      char op; scanf(" %c", &op);
      for (int k = 0; k < 4; ++k) {
        if (op == dir2[k]) {
          td = k;
          int ny = ty+dy[k], nx = tx+dx[k];
          if (field[ny][nx] == '.') { ty = ny; tx = nx; }
          break;
        }
      }
      if (op == 'S') {
        int by = ty, bx = tx;
        while (field[by][bx] == '.' || field[by][bx] == '-') {
          by += dy[td]; bx += dx[td];
        }
        if (field[by][bx] == '*') {
          field[by][bx] = '.';
        }
      }
    }

    for (int y = 1; y <= H; ++y) {
      for (int x = 1; x <= W; ++x) {
        if (ty == y && tx == x) {
          printf("%c", dir1[td]);
        } else {
          printf("%c", field[y][x]);
        }
      }
      puts("");
    }
    if (T > 0) { puts(""); }
  }
}

Measured memory_bytes: 0
/*بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll c[24][24];
ll cc[24];
void solve()
{
    ll a,b,n,m=0,i,j,l=0,r,k=0,kk=0,z=0,ans=INT_MAX,sum=0,y=0,x,s1,sk;
    vector < ll > v;
    string s;

    cin >> n >> m >> x;

    for(i=0;i<n;i++)
    {
        cin >> cc[i];

        for(j=0;j<m;j++)
        {
            cin >> r;
            c[i][j]=r;
        }
    }

    for(i=0;i<(1<<n);i++)
    {
        sum=0;
        vector < ll > vk(m);

        for(j=0;j<n;j++)
        {
            if(i&(1<<j))
            {
                sum+=cc[j];

                for(k=0;k<m;k++)
                {
                    vk[k]+=c[j][k];
                }
            }
        }

        bool tr=true;

        for(j=0;j<m;j++)
        {
            if(vk[j]<x)
            {
                tr=false;
            }
        }

        if(tr==true)
        {
            ans = min(ans,sum);
        }

    }

    if(ans==INT_MAX)
    {
        ans=-1;
    }

    cout << ans << endl;

}

int main()
{
    int t;

    solve();
}


Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main() {
    int N, H, W;
    cin >> N >> H >> W;

    int ans = 0;
    for (int i = 0; i < N; ++i) {
        int A, B;
        cin >> A >> B;
        ans += (A >= H) && (B >= W);
    }

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


Measured memory_bytes: 256
// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

/*全てのライブラリをインクルード*/
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

ll f(ll n,ll x){
    if(n>=0)return n/x+1;
    else if(n==-1)return 0;
}

int main()
{
    ll a, b, x, count;
    cin >> a >> b >> x;
    count=f(b,x)-f(a-1,x);
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3608
N,M,C = list(map(int,input().split()))
B = list(map(int,input().split()))
A = []
for i in range(N):
    A.append(list(map(int,input().split())))

cnt = 0

for i in range(N):
    sumnum = 0
    for j in range(M):
        sumnum += A[i][j]*B[j]
    sumnum += C
    if sumnum > 0:
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include <list>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <algorithm>

#define MOD 1000000007

typedef long long ll;

using namespace std;

// n 以下の素数のリストを計算
vector<int> getPrime(int n) {
	vector<int> primeVec;
	for (int i = 2; i <= n; i++) {
		int divCount = 0;
		for (int j = 1; j * j <= i; j++) {
			if (i % j == 0) {
				divCount++;
			}
		}
		if (divCount == 1) {
			primeVec.push_back(i);
		}
	}

	return primeVec;
}

int main(){
    int N;
    cin >> N;
    ll ans = 1;

    if (N != 1) {
	    vector<int> primeVec = getPrime(N);
	    map<int, int> factoringMp;

	    for (int i = 2; i <= N; i++) {
	    	int res = i;
	    	for (auto itr = primeVec.begin(); itr != primeVec.end(); itr++) {
	    		int count = 0;
	    		int div = *itr;
				if (res < div) {
					break;
				}
				while (res % div == 0) {
					res /= div;
					count++;
				}

				auto mpItr = factoringMp.find(div);
				if (mpItr != factoringMp.end()) {
					factoringMp[div] += count;
				}
				else {
					factoringMp[div] = count;
				}
	    	}
	    }

	    for (auto itr = factoringMp.begin(); itr != factoringMp.end(); itr++) {
	    	int expNum = itr -> second;
	    	ans = ans * (expNum + 1) % MOD;
	    }
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main (){
	
	int a,b;
	scanf("%d %d", &a, &b);
	
	int x=a;
	a=0;
	
	for (int i=0; i<x; i++){
		a=a+i;
	}
	int y=b;
	b=0;
	for(int i=0; i<y; i++){
		b=b+i;
	}
	printf("%d", a+b);
	
	return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <algorithm>

using namespace std;

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

    vector<vector<char>> S(H,vector<char>(W,'.'));

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            char s;
            cin >> s;

            S[i][j] = s;
        }
    }

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            char now = S[i][j];
            int b = 0;
            for(int h = -1; h < 2; h++){
                for(int w = -1; w < 2; w++){
                    if(i+h >= 0 && i+h < H && j+w >= 0 && j+w < W){
                        char search = S[i+h][j+w];
                        if(search ==  '#'){
                            b++;
                        }
                    }
                }
            }
            if(now == '#'){
                cout <<  '#';
            }else{
                cout << b;
            }
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
# t=int(input())
t=1
graph=defaultdict(lambda:[])
for _ in range(t):
    n,m=map(int,stdin.readline().split())
    for _ in range(m):
        a,b=map(int,stdin.readline().split())
        graph[a].append(b)
        graph[b].append(a)
    root=1
    ans=defaultdict(lambda:0)
    visited=defaultdict(lambda:False)
    q=deque()
    q.append(1)
    visited[1]=True
    count=0
    while(len(q)>0):
        temp=q.popleft()
        for i in graph[temp]:
            if(not visited[i]):
                visited[i]=True
                ans[i]=temp
                q.append(i)
                count+=1
    if(count==n-1):
        print("Yes")
        for i in range(2,n+1):
            print(ans[i])
    else:
        print("No")

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

using namespace std;

template<typename T,T inf>
int lis(vector<T>&v){
  int N=v.size();
  vector<T>dp(N,inf);
  for(int i=0;i<N;i++)*lower_bound(dp.begin(),dp.end(),v[i])=v[i];
  int res=0;
  for(int i=0;i<N;i++)if(dp[i]!=inf)res=i;
  return res+1;
}

int main(){
  int N;
  cin>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  cout<<lis<int,INT_MAX>(A)<<endl;
  return 0;
}



Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String input = sc.next();
        int cnt = 0;
        for (int i = 0; i < input.length(); i++) {
            if (input.charAt(i) == '+')
                cnt += 1;
            else
                cnt -= 1;
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 35580
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

int main(){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if (b/a < c) {
        printf("%d\n", b/a);
    }else{
        printf("%d\n", c);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
  long long W, H, x, y;
  cin >> W >> H >> x >> y;
  
  cout << (double)W * H / 2.0 << " ";
  if(x * 2 == W && y * 2 == H) cout << 1;
  else cout << 0;
    
  
  
  return 0;
}

Measured memory_bytes: 256
open Printf
open Scanf

let id x = x

let h, w = scanf "%d %d" (fun h w -> h, w)

let mat =
    Array.init h (fun i ->
        Array.init w (fun j ->
            scanf " %c" id
        )
    )

let () =
    for i = 0 to w - 1 do
        let b = ref true in
        for j = 0 to h - 1 do
            if mat.(j).(i) = '#' then b := false
        done;
        if !b then
            for j = 0 to h - 1 do
                mat.(j).(i) <- ' '
            done
    done;
    for j = 0 to h - 1 do
        let b = ref true in
        for i = 0 to w - 1 do
            if mat.(j).(i) = '#' then b := false
        done;
        if !b then
            for i = 0 to w - 1 do
                mat.(j).(i) <- ' '
            done
    done;
    for j = 0 to h - 1 do
        let b = ref false in
        for i = 0 to w - 1 do
            if mat.(j).(i) <> ' ' then
                (printf "%c" mat.(j).(i); b := true)
        done;
        if !b then printf "\n"
    done


Measured memory_bytes: 2688
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int a, b, c, d, ans = 0;
    cin >> a >> b >> c >> d;
    if(a != c) ans = 1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<string,pint> pstr;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main()
{
	int n,a;string s;vector<pstr> v;
	cin>>n;
	rep(i,n){
		cin>>s>>a;v.pb(mp(s,mp(-a,i+1)));
	}
	sort(All(v));
	rep(i,n) cout<<v[i].se.se<<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int count = 1;
        int n = Integer.parseInt(sc.nextLine());
        Integer d[] = new Integer[n];

        int i = 0;
        while (sc.hasNext()) {
            int val = Integer.parseInt(sc.nextLine());
            d[i] = val;
            i++;
        }
        Arrays.sort(d, Comparator.reverseOrder());

        int nowSize = d[0];
        for (Integer size : d) {
            if (size < nowSize) {
                nowSize = size;
                count++;
            }
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 25300
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int N, A, B, C;
vector<int> l;
int ans = INF;

void dfs(vector<int> v){
    if(v.size() == N){
        int a = 0, b = 0, c = 0, sum = 0;
        for(int i=0;i<N;i++){
            if(v[i] == 0) continue;
            if(v[i] == 1) (a ? sum += 10 : 0), a += l[i];
            if(v[i] == 2) (b ? sum += 10 : 0), b += l[i];
            if(v[i] == 3) (c ? sum += 10 : 0), c += l[i];
        }
        sum += abs(A - a) + abs(B - b) + abs(C - c);
        if(a == 0 || b == 0 || c == 0) return;
        chmin(ans, sum);
    }
    else{
        REP(i,4){
            auto tmp = v;
            tmp.push_back(i);
            dfs(tmp);
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> A >> B >> C;
    l.resize(N);
    REP(i,N) cin >> l[i];
    vector<int> v;
    dfs(v);
    cout << ans << endl;
}

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

#define N 500000
#define INFTY (10000000001)

int countMerge = 0;

void merge(long *, int, int, int);
void mergeSort(long *, int, int);
long *makeArray(int);
void copyArray(long *, long *, int, int);

int main() {
  int i, n;
  long A[N];

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

  mergeSort(A, 0, n);

  for (i = 0; i < n; i++) {
    if (i == 0) printf("%d", A[i]);
    else printf(" %ld", A[i]);
  }
  printf("\n");
  printf("%d\n", countMerge);
  
  return 0;
}

void mergeSort(long *A, int left, int right) {
  int mid;
  
  if (left + 1 < right) {
    mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
  
}

void merge(long *A, int left, int mid, int right) {
  int i, j, k;
  
  int nl = mid - left;
  int nr = right - mid;
  
  long *L = makeArray(nl + 1);
  long *R = makeArray(nr + 1);
  
  copyArray(L, A, nl, left);
  copyArray(R, A, nr, mid);
  L[nl] = R[nr] = INFTY;

  j = i = 0;
  for (k = left; k < right; k++) {
    countMerge++;
    if (L[i] <= R[j]) {
      A[k] = L[i];
      i++;
    } else {
      A[k] = R[j];
      j++;
    }
  }
  
  free(L);
  free(R);
}

long *makeArray(int size) {
  return (long *)malloc(size * sizeof(long));
}

void copyArray(long *A, long *B, int n, int m) {
  int i;
  for (i = 0; i < n; i++) {
    A[i] = B[m + i];
  }
}



Measured memory_bytes: 9228
#include <iostream>
#include <complex>
#include <cmath>
using namespace std;

typedef complex<double> point;

#define PI M_PI
#define EPS (1e-10)
#define X real()
#define Y imag()

class Triangle{
private:	
	point a,b,c;
	double edgeA,edgeB,edgeC;
	double angleA,angleB,angleC;
	double calc_angle(double a,double b, double c){
		return acos((b*b+c*c-a*a)/(2.0*b*c));
	}
	bool equal(double a, double b){
		return (abs(a-b) < EPS)? true: false;
	}

public:
	Triangle(point p1,point p2,point p3){
		a=p1; b=p2; c=p3;
		edgeA=abs(b-c);
		edgeB=abs(c-a);
		edgeC=abs(a-b);
		angleA=calc_angle(edgeA,edgeB,edgeC);
		angleB=calc_angle(edgeB,edgeC,edgeA);
		angleC=calc_angle(edgeC,edgeA,edgeB);
	}
	double circumscribed_radius(){
		return (edgeA/(2.0*sin(angleA)));
	}
	double circumscribed_X(){
		double A=sin(2.0*angleA);
		double B=sin(2.0*angleB);
		double C=sin(2.0*angleC);
		return((a.X*A+b.X*B+c.X*C)/(A+B+C));
	}
	double circumscribed_Y(){
		double A=sin(2.0*angleA);
		double B=sin(2.0*angleB);
		double C=sin(2.0*angleC);
		return((a.Y*A+b.Y*B+c.Y*C)/(A+B+C));
	}
};

int main(void){
	double x1,y1;
	double x2,y2;
	double x3,y3;
	int n;
	double r,px,py;

	cin >> n;
	for(int i=0;i<n;i++){
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		point p1(x1,y1);
		point p2(x2,y2);
		point p3(x3,y3);
		Triangle Tr(p1,p2,p3);
		r=Tr.circumscribed_radius();
		px=Tr.circumscribed_X();
		py=Tr.circumscribed_Y();
		cout << fixed;
		cout.precision(3);
		cout << px << " " << py << " " << r << endl;
		if(i==20) break;
	}
	return 0;
}

Measured memory_bytes: 1384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=1000003,INF=1<<30;
vector<ll> G[MAX],dev[MAX];

ll rui(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}
vector<int> prime;
bool is_prime[MAX+1];

void sieve(int n){
    for(int i=0;i<=n;i++){
        is_prime[i]=true;
    }
    
    is_prime[0]=is_prime[1]=false;
    
    for(int i=2;i<=n;i++){
        if(is_prime[i]){
            prime.push_back(i);
            for(int j=2*i;j<=n;j+=i){
                is_prime[j] = false;
            }
        }
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    sieve(1000002);
    
    int N;cin>>N;
    for(int i=0;i<N;i++){
        int a;cin>>a;
        for(int j=1;j*j<=a;j++){
            if(a%j==0){
                G[j].push_back(a);
                if(j*j!=a) G[a/j].push_back(a);
            }
        }
    }
    
    ll ans=0;
    
    for(int i=1;i<=1000000;i++){
        int j=i;
        for(int p:prime){
            if(j%p==0){
                dev[i].push_back(p);
                while(j%p==0) j/=p;
            }
            if(is_prime[j]){
                dev[i].push_back(j);
                break;
            }
            if(j==1) break;
        }
    }
    
    for(int g=1;g<=1000000;g++){
        if(G[g].size()>=2){
            vector<ll> S(G[g].size());
            S[0]=G[g][0];
            for(int i=1;i<G[g].size();i++){
                S[i]=S[i-1]+G[g][i];
                S[i]%=mod;
            }
            
            ll sum=0;
            
            for(int i=0;i<G[g].size();i++){
                sum+=G[g][i]*((S[G[g].size()-1]-S[i]+mod)%mod);
                sum%=mod;
            }
            
            sum*=rui(g,mod-2);
            sum%=mod;
            
            ll res=sum;
            
            for(int bit=1;bit<1<<int(dev[g].size());bit++){
                int q=1,cnt=0;
                for(int i=0;i<dev[g].size();i++){
                    if(bit&(1<<i)){
                        q*=dev[g][i];
                        cnt++;
                    }
                }
                if(cnt%2==0){
                    res+=sum*q;
                    res%=mod;
                }else{
                    res+=mod-sum*q%mod;
                    res%=mod;
                }
            }
            
            ans+=res;
            ans%=mod;
            
        }
    }
    
    cout<<ans<<endl;
    
}



Measured memory_bytes: 171140
H,N=gets.split.map(&:to_i)

INF = 100000000

# 0からカウントするので+1
dp = Array.new(H+1, INF)
N.times do |n|
  dp[0] = 0
  a,b=gets.split.map(&:to_i)
  0.upto(H) do |hp|
    idx = hp + a
    idx = H if H < idx
    dmg = dp[hp] + b
    dp[idx] = dmg if dmg < dp[idx]
  end
end
puts dp[H]


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

int main() {
	bool reved = false;
	int n;
	cin >> n;
	vector<int> a(n);
	
	vector<pair<int,int>> ans;
	
	int Max = -1, pos;
	
	for(int i = 0; n > i; i++){
		cin >> a[i];
		if(abs(a[i]) > Max){
			Max = abs(a[i]);
			pos = i;
		}
	}
	
	if(a[pos] < 0){
		reverse(a.begin(), a.end());
		reved = true;
		for(int i = 0;n > i; i++)
			a[i] *= -1;
		pos = n - pos - 1;
	}
	
	ans.push_back({pos, 0});
	ans.push_back({pos, 0});
	
	for(int i = 0;n - 1 > i; i++){
		ans.push_back({i, i + 1});
		ans.push_back({i, i + 1});
	}
	
	cout << ans.size() << endl;
	for(auto& b : ans){
		if(reved){
			b.first = n - b.first - 1;
			b.second = n - b.second - 1;
		}
		
		cout << b.first + 1 << " " << b.second + 1<< endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 888
#include <map>
#include <vector>
#include <cstdio>
#include <algorithm>

using namespace std;
const int Max_N(405);
typedef long long int LL;

struct val
{
	val(const int &v0 = 0, const int &v1 = 0, const int &v2 = 0, const int &v3 = 0)
	{
		v[0] = v0, v[1] = v1, v[2] = v2, v[3] = v3;
	}
	int v[4];
	inline bool operator<(const val &b) const
	{
		for (int i = 0;i < 4;++i)
			if (v[i] != b.v[i])
				return v[i] < b.v[i];
		return false;
	}
	val getnext() const
	{
		val x;
		for (int i = 0;i < 3;++i)
			x.v[i] = v[i + 1];
		x.v[3] = v[0];
		return x;
	}
};
int N;
val V[Max_N];
map<val, LL> G, F;
LL Ans;

void insert(map<val, LL> &H, val x, int v = +1)
{
	for (int i = 0;i < 4;++i, x = x.getnext())
		H[x] += v;
}

int main()
{
	scanf("%d", &N);
	for (int i = 1;i <= N;++i)
		for (int j = 0;j < 4;++j)
			scanf("%d", &V[i].v[j]);
	for (int j = N;j >= 1;--j)
	{
		F = G;
		for (int i = j - 1;i >= 1;--i)
		{
			val up = V[i], dn = V[j], a, b, c, d;
			for (int k = 0;k < 4;++k, dn = dn.getnext())
			{
				LL Ret(1LL);
				if (F[a = val(up.v[3], up.v[2], dn.v[3], dn.v[2])] == 0)
					goto loop;
				Ret *= F[a], insert(F, a, -1);
				if (F[b = val(up.v[2], up.v[1], dn.v[0], dn.v[3])] == 0)
				{
					insert(F, a);
					goto loop;
				}
				Ret *= F[b], insert(F, b, -1);
				if (F[c = val(up.v[1], up.v[0], dn.v[1], dn.v[0])] == 0)
				{
					insert(F, a), insert(F, b);
					goto loop;
				}
				Ret *= F[c], insert(F, c, -1);
				if (F[d = val(up.v[0], up.v[3], dn.v[2], dn.v[1])] == 0)
				{
					insert(F, a), insert(F, b), insert(F, c);
					goto loop;
				}
				Ret *= F[d], insert(F, d, -1);
				Ans += Ret, insert(F, a), insert(F, b), insert(F, c), insert(F, d);
				loop :
				;
			}
			insert(F, V[i]);
		}
		insert(G, V[j]);
	}
	printf("%lld", Ans);
	return 0;
}

Measured memory_bytes: 384
fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)

fun cumGcd(x: List<Int>): List<Int> {
    var n = x.count()
    var res = x.toMutableList()

    res[0] = 0
    for (i in 0 until n - 1) {
        res[i + 1] = gcd(res[i], x[i])
    }
    return res
}

fun main(args: Array<String>) {
    var n = readLine()!!.toInt()
    var xs = readLine()!!.split(" ").map(String::toInt)
    var left = cumGcd(xs)
    var right = cumGcd(xs.reversed())
    var ans = 0
    for (i in 0 until n) {
        val g = gcd(left[i], right[n - 1 - i])
        if (ans < g) {
            ans = g
        }
    }
    println(ans)
}


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

print("Yes");
n, m = [int(x) for x in input().split()] # nは頂点の数、mは辺の数
g = [[] for _ in range(n)] # 隣接リスト

for _ in range(m):
    aa, bb = [int(x) for x in input().split()]
    a = aa-1;
    b = bb-1;
    g[a].append(b)
    g[b].append(a)

from collections import deque

queue = deque([0])
d = [None] * n # uからの距離の初期化
d[0] = 0 # 自分との距離は0
while queue:
    v = queue.popleft()
    for i in g[v]:
        if d[i] is None:
            d[i] = d[v] + 1
            queue.append(i)


baka = 1;

while baka <= n-1:
    aho = len(g[baka]); #ahoはつながっている通路の個数
    manuke = 0;
    while manuke <= aho-1:
        xx = d[g[baka][manuke]];
        if xx == d[baka] - 1:
            print(g[baka][manuke]+1);
            break;
        manuke = manuke + 1;
    
    baka = baka + 1;



Measured memory_bytes: 33888
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<ctime>

using namespace std;

template <typename T>

inline T read()
{
	T x=0,f=1;char c=getchar();
	while(!isdigit(c))
	{if(c=='-') f=-f;c=getchar();}
	while(isdigit(c))
	{x=(x<<3)+(x<<1)+(c-48);c=getchar();}
	return x*f;
}

#define lint long long int
#define ulint unsigned lint

const int inf=1e9+1e7;

int gcd(int A,int B)
{

	return ( A==0 ? B : gcd(B%A,A) );

}

int main(void)
{

	// freopen("testdata.in","r",stdin);
	// freopen("testdata.out","w",stdout);

	int n=read<int>();
	lint ans=0;

	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			for(int k=1;k<=n;k++)
			{
				int tmp=( i>j ? gcd(j,i) : gcd(i,j) );
				int res=( tmp>k ? gcd(k,tmp) : gcd(tmp,k) );
				ans+=(lint)res;
			}

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

	return 0;

}

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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split().Select(i => Convert.ToInt32(i)).ToArray();
            int K = input[0];
            int X = input[1];
            int min = X - (K - 1);
            int max = X + (K - 1);
            min = (min < -1000000) ? -1000000 : min;
            max = (max > 1000000) ? 1000000 : max;
            for (var i = min; i < max; i++)
            {
                Console.Write($"{i} ");
            }
            Console.Write($"{max}");
        }
    }
}


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

using namespace std;
#define rep(i,n) for(int i=1;i<n+1;i++)
#define ll long long int

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

rep(i,n){

cout<<sum-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1])<<endl;

}

  return 0;
}


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

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

	for (int i = 1; i < 10; ++i) {
		int contest = 111 * i;
		if (N <= contest) {
			cout << contest << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256