akhauriyash/Code-Regression huggingface dataset:
using System;

class Program
    {
        static void Main()
        {
            while (true)
            {
                string[] line = Console.ReadLine().Split(' ');

                int height = int.Parse(line[0]);
                int width = int.Parse(line[1]);

                if (height == 0 && width == 0)
                    break;

                for (int i = 0; i < height; i++)
                {
                    for (int j = 0; j < width; j++)
                    {
                        if(i % 2 == 0)
                            if(j % 2 == 0)
                                Console.Write("#");
                            else
                                Console.Write(".");
                        else
                            if(j % 2 == 0)
                                Console.Write(".");
                            else
                                Console.Write("#");
                    }
                    Console.Write("\n");
                }
                Console.Write("\n");
            }
        }
    }

Measured memory_bytes: 19624
#include<bits/stdc++.h>
using namespace std;
int main(){
  int q;
  cin>>q;
  set<int> s;
  for(int i=0;i<q;i++){
    int a,b;
    cin>>a>>b;
    if(a==0){
    s.insert(b);
    cout<<s.size()<<endl;
    }
    if(a==1){
      if(s.find(b)!=s.end()) cout<<"1"<<endl;
      else cout<<"0"<<endl;
    }
    if(a==2){
      s.erase(b);
    }
  }
  return 0;
}



Measured memory_bytes: 12452
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdio>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
#define RO 1
#define SI 2
#define PA 3

int main(){
    int a,b,x;
    cin>>a>>b>>x;
    double rad;
    if(2*x<=a*a*b){
        rad=atan2((double)(a*b*b),(double)(2*x));
    }else{
        rad=atan2((double)(2*(a*a*b-x)),(double)(a*a*a));
    }
    double deg=rad*180.0/M_PI;

    printf("%.10f\n",deg);
}    



Measured memory_bytes: 384
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

bool adj[51][51] = {};

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

  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    adj[a][b] = true;
    adj[b][a] = true;
  }

  // cout << endl;
  int result = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      // cout << i << " " << j << endl;
      if (adj[i][j]) {

        bool visited[51] = {};

        queue<int> container;
        container.push(0);

        while (!container.empty()) {
          int p = container.front();
          container.pop();
          visited[p] = true;

          for (int k = 0; k < N; k++) {
            if (visited[k]) continue;
            if ((!(p == i && k == j)) && (!(p == j && k == i))) {
              if (adj[p][k] == true) {
                container.push(k);
              }
            }
          }
        }
        bool flag = true;
        for (int l = 0; l < N; l++) {
          if (visited[l] != true) {
            flag = false;
          }
        }
        if (!flag) {
          // cout << i + 1 << " " << j + 1 << endl;
          result++;
        }
      }
    }
  }

  cout << result << endl;
  return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

void Solve(){
	int n,m;
	cin >> n >> m;

	vector<pii> ps(m);
	rep(i,0,m) cin >> ps[i].first >> ps[i].second;
	sort(ps.begin(),ps.end());

	int dp[101];
	fill_n(dp,101,INF);
	dp[0]=0;
	rep(i,0,m){
		rep(j,ps[i].first,ps[i].second+1){
			if(dp[j-1]!=INF) dp[j]=min(dp[j],dp[ps[i].first-1]+1);
		}
	}

	if(dp[n]==INF) cout << "Impossible" << endl;
	else cout << dp[n] << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}

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


 int main(){
  int a, b, x;

  cin >> x >> a >> b;

  int ax;
  ax = (x-a);
  if (ax < 0) ax = ax * -1;

  int bx;
  bx = (x-b);
  if (bx < 0) bx = bx * -1;

  if(ax > bx) cout << "B" << endl;
   else if(ax < bx) cout << "A" << endl;

 return 0;
}

Measured memory_bytes: 256
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

class UnionFindTree
  class ParArray < Hash
    def [] key
      self[key] = key if super(key).nil?
      super(key)
    end
  end

  class SizeArray < Hash
    def [] key
      self[key] = 1 if super(key).nil?
      super(key)
    end
  end

  def initialize()
    @par = ParArray.new
    @size = SizeArray.new
  end

  private

  def find(x)
    return x if x == @par[x]
    return @par[x] = find(@par[x])
  end

  public

  def unite(x, y)
    x = find(x)
    y = find(y)

    return nil if x == y
    x, y = y, x if @size[x] < @size[y]

    @par[y] = x
    @size[x] += @size[y]
  end

  def same?(x, y)
    return find(x) == find(y)
  end

  def size(x)
    return @size[find(x)]
  end
end

n,m=gi
P=gi.map{|t|t-=1}
uf = UnionFindTree.new
rep m do
  x,y=gi
  uf.unite(x-1,y-1)
end
ans=0
rep n do |i|
  ans += 1 if uf.same?(P[i],i)
end
puts ans



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

using namespace std;
using ll = long long;

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

    int x;
    cin >> x;

    if(x >= 30) printf("Yes\n");
    else printf("No\n");

    return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
int main(void){
    // Your code here!
    int cnt=0;
    char s[200001],t[200001];
    scanf("%s%s",s,t);
    for(int i=0;s[i]!='\0';i++){
        if(s[i]!=t[i])cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 2060
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().execute();
	}

	public void execute() {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		final long K = sc.nextLong();
		Map<Integer, Long> numCount = new HashMap<>();
		for (int i = 0; i < N; i++) {
			int ai = sc.nextInt();
			int bi = sc.nextInt();
			if (!numCount.containsKey(ai)) {
				numCount.put(ai, (long)bi);
			} else {
				long c = numCount.get(ai);
				numCount.put(ai, c + bi);
			}
		}

		Integer[] keys = numCount.keySet().toArray(new Integer[numCount.size()]);
		Arrays.sort(keys);

		long cnt = 0;
		for (int i = 0; i < keys.length; i++) {
			cnt += numCount.get(keys[i]);
			if (cnt>=K) {
				System.out.println(keys[i]);
				break;
			}
		}
		sc.close();
	}

}


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

bool is_palindrome(string s) {
    string t(s.rbegin(),s.rend());
    return t == s;
}

int main() {
    string s;
    cin >> s;
    int n = s.size();
    if (is_palindrome(s) && is_palindrome(s.substr(0,(n-1)/2)) && is_palindrome(s.substr((n+1)/2))) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    return 0;
}
    

Measured memory_bytes: 256
/*  (: ///////|||||| BEGINS |||||||\\\\ :) */
/* REMEMBER
Deletes all characters except first one     Deletes 4 characters from index number 1
    str.erase(1);                               str.erase(1,4);
Deletes character at position 4
 str.erase(str.begin() + 4);
bool compare(const pair<int, int>&a, const pair<int, int>&b)
{
   return a.second<b.second;
}
maxn = max_element(mp.begin(), mp.end(), compare)->second;
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    return (a.second < b.second);
}
min(a,b,c,d)==min({a,b,c,d});
priority_queue <int, vector<int>, greater<int>> gquiz; // to create min heap
*/
#include<bits/stdc++.h>
using namespace std;
#define ll             long long int
#define endl           '\n'
#define mod            1000000007
#define fo(i,n)        for(int i=1;i<=n;i++)
#define tol(s)         transform(s.begin(),s.end(),s.begin(),::tolower)
#define tou(s)         transform(s.begin(),s.end(),s.begin(),::toupper)
#define all(x)         (x).begin(), (x).end()
#define pb             push_back
#define lb             lower_bound
#define ub             upper_bound
#define tr(it, a)      for(auto it = a.begin();it!=a.end();it++)
#define gcd(a,b)       __gcd(a,b)
#define pq             priority_queue
#define fr             first
#define sc             second
#define sz(x)          x.size()
#define T              ll t=0;cin>>t;for(ll test=0;test<t;test++)
 
const int inf=0x3f3f3f3f;
bool ispalindrome(string s) 
{ 
    ll len=s.length(); 
    for(ll i=0;i<len;i++){ 
        if(s[i]!=s[len-i-1]) 
        return false; 
    } 
    return true; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res*a;
        a = a*a;
        b >>= 1;
    }
    return res;
}
long long isprime(long long n)
{
    for(long long i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)return 0;
    }
    return 1;
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif

int n;
cin>>n;
ll a[n];
for(ll i=0;i<n;i++)cin>>a[i];
ll cn=0;
for(ll i=0;i<n;i++)
{
    for(ll j=i+1;j<n;j++)
    {

        for(ll k=j+1;k<n;k++)
        {
            if(a[i]!=a[j] && a[j]!=a[k] && a[i]!=a[k]
            && a[i]+a[j]>a[k] && a[i]+a[k]>a[j] && a[j]+a[k]>a[i])cn++;
        }
    }
}

cout<<cn<<endl;





return 0;
}  

Measured memory_bytes: 3696
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define max(l,r) ((l)>(r)?l:r)
#define min(l,r) ((l)<(r)?l:r)
#define swap(l,r) {ll tp=l;l=r;r=tp;}

char s[202020];

////桁和(string)/////
ll ketawa(char* ts){
    ll sum = 0, tn = strlen(ts); 
    for (ll i = tn-1; i >= 0; i--){
        sum += ts[i]-'0';
    }
    return sum;
}
////

int main(){
    scanf("%s", s);
    if(ketawa(s)%9 == 0){ puts("Yes"); }else puts("No");
}


Measured memory_bytes: 1776
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			int N = Integer.parseInt(str);
			str = br.readLine();
			int K = Integer.parseInt(str);

			int res = 1;
			for(int i = 0; i < N; i++) {
				if(res < K) {
					res = res*2;
				}else {
					res += K;
				}
			}
			System.out.println(res);
//			long max  = 1000000007;
		}catch (Exception e) {
			System.exit(0);
		}
	}

}


Measured memory_bytes: 22740
//                          **********  YATIN KWATRA  ********** 

//AC bakshi Rabha

#include <bits/stdc++.h>
#define ll                      long long 
#define ull                     unsigned long long 
#define FIO                     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl                    "\n"
#define fo(i,a,b)               for(int i = a; i<=b ; i++)
#define rfo(i,a,b)              for(int i = a; i>=b ; i--)
#define vii                      vector<int>
#define vll                     vector<ll>
#define pq                      priority_queue
#define uom                      unordered_map                
#define all(v)                  v.begin(),v.end()
#define mp                      make_pair
#define pb                      push_back
#define pob                     pop_back
#define ff                      first
#define ss                      second
#define pii                     pair<int,int> 
#define pll                     pair<long,long>
#define mll                     map<ll,ll>
#define mii                     map<int,int>
#define vvii                    vector<vii>
#define vvll                    vector<vll>
#define mod                     1000000007
#define pi                      3.1415926535897932384626433832795
// #define node                    Node

using namespace std;

void INPUT() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

}


void solve()
{ 
        ll n,m;
        cin >> n >> m;

        ll ans = n*m;
        cout << ans << endl;
    
       
}
int main() {
    
    FIO
    INPUT();
    
    int t;
    t = 1;
 //   cin >> t;
    
    while(t--)
    {
       solve();
    }
    return 0;
}


Measured memory_bytes: 3640
h,w = map(int,input().split())

arr=[]
arr.append([".","#"]+["."]*w)
for _ in range(h):
    arr.append(["."]+list(input())+["."])
arr.append(["."]*w+["#","."])
#for row in arr:
#    print(row)

for i in range(h):
    for j in range(w):
        if arr[i+1][j+1]=='#':
            if arr[i][j+1]==arr[i+1][j] or arr[i+2][j+1]==arr[i+1][j+2]:
                print("Impossible")
                exit(0)

print("Possible")


Measured memory_bytes: 3064
<STDIN>;
my @p = split //, <STDIN>;
my $l = scalar(@p) - 1;
my $m = $l;
my $w = [];
my $e = [];
my $i = 0;
my $tw = 0, $te = 0;
foreach(@p) {
    $w->[$i] = $_ eq 'W' ? $w->[$i - 1 < 0 ? 0 : $i - 1] + 1 : $w->[$i - 1 < 0 ? 0 : $i - 1];
    $e->[$i] = $_ eq 'E' ? $e->[$i - 1 < 0 ? 0 : $i - 1] + 1 : $e->[$i - 1 < 0 ? 0 : $i - 1];
    $i++;
}
foreach(0 ... $l) {
    my $k = $_;
    my $a1 = $k == 0 ? 0 : $w->[$k - 1];
    my $a2 = $e->[$l] - $e->[$k];
    #print $k, $a1, $a2,"\n";
    $m = $a1 + $a2 if $a1 + $a2 < $m;
}

print $m;

Measured memory_bytes: 71916
n = int(input())
a = list(map(int, input().split()))

ans = 0
p = 0
used = False
count = 1
for i in range(n):
    if a[i]^p == a[i]+p:
        if used:
            count += 1
        used = True
        p += a[i]
    else:
        c = count
        for j in range(i-c, i):
            count -= 1
            p -= a[j]
            if p^a[i] == p+a[i]:
                break
        if count == 0:
            p = a[i]
            count = 1
        else:
            count += 1
            p += a[i]
    ans += count
print(ans)


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

inline int rd() {
  int x = 0;
  bool f = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + (c ^ 48);
    c = getchar();
  }
  return f ? -x : x;
}

int r, c, k, v[N][N];

ll ans, f[N][N][4];

int main() {
  r = rd();
  c = rd();
  k = rd();
  int x, y;
  while (k--) {
    x = rd(); y = rd();
    v[x][y] = rd();
  }
  for (int i = 1; i <= r; ++i)
    for (int j = 1; j <= c; ++j)
      for (int k = 0; k <= 3; ++k) { 
        f[i][j][k] = max(f[i][j][k], f[i][j - 1][k]);
        if (k > 0) f[i][j][k] = max(f[i][j][k], f[i][j - 1][k - 1] + v[i][j]);
        if (k == 0) for (int lst = 0; lst <= 3; ++lst) f[i][j][k] = max(f[i][j][k], f[i - 1][j][lst]);
        if (k == 1) for (int lst = 0; lst <= 3; ++lst) f[i][j][k] = max(f[i][j][k], f[i - 1][j][lst] + v[i][j]);
        ans = max(ans, f[i][j][k]);
      }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 320432
#include<iostream>
#include<vector>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define all(v) v.begin(),v.end()
#define pb push_back
#define INF 1e10
using namespace std;
typedef long long ll;

ll func(ll a){
	return (a>0)?a:-a;
}

ll min(ll a,ll b){
	return (a<b)?a:b;
}

int main(){
	int n;
	cin>>n;
	ll a[n];
	vector<ll> vec;
	rep(i,n)cin>>a[i];
	sort(a,a+n);
	rep(i,n){
		if(i==0){
			vec.pb(func(a[0]-a[1]));
		}else if(i==n-1){
			vec.pb(func(a[i]-a[i-1]));
		}else{
			vec.pb(func(a[i]-a[i+1]));
			vec.pb(func(a[i]-a[i-1]));
		}
	}
	rep(i,n)vec.pb(a[i]);
	sort(all(vec));
	ll m;
	rep(i,vec.size()){
		if(vec[i]>0){
			m=vec[i];
			break;
		}
	}
	ll com=INF;
	bool check=true;
	while(check){
		check=false;
		rep(i,n){
			if(a[i]%m){
				ll res=a[i]%m;
				com=min(com,res);
				check=true;
			}
		}
		m=min(m,com);
	}
	cout<<min(com,m)<<endl;
	return 0;
}

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

#define endl '\n'
using namespace std;
using ll = long long;

const ll MOD = 1e9+7;

class Matrix2D : public vector<vector<ll>>
{
private:
public:
    Matrix2D(){}
    Matrix2D(size_t rn, size_t cn, bool standard = true)
    {
        this->resize(rn);
        for(auto &r:(*this)) r.resize(cn, 0);
        if(rn == cn && standard) 
            for(size_t i = 0; i < rn; i++) (*this)[i][i] = 1;
    }
    size_t getRowNum() { return this->size(); }
    size_t getColNum() { return (*this)[0].size(); }
    Matrix2D operator*(Matrix2D that)
    {
        assert(this->getColNum() == that.getRowNum());
        Matrix2D res(this->getRowNum(), that.getColNum(), false);
        for(size_t i = 0; i < res.getRowNum(); i++)
            for(size_t j = 0; j < res.getColNum(); j++)
                for(size_t k = 0; k < this->getColNum(); k++)
                    res[i][j] = (res[i][j] + (*this)[i][k] * that[k][j])%MOD;
        return res;
    }
    Matrix2D powerN(size_t n)
    {
        assert(this->getRowNum() == this->getColNum());
        if(n == 0) return Matrix2D(this->getRowNum(), this->getColNum());
        Matrix2D res = (*this)*(*this);
        if(n%2 == 0) return res.powerN(n/2);
        return (*this) * res.powerN(n/2);
    }
    void print(ostream &out)
    {
        for(auto &r:*this)
        {
            for(auto &c:r)
                out << c << " ";
            out << endl;
        }
    }
};

const int N = 55;
ll n, k;
Matrix2D mat;

void init();
void process();

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    init();
    process();
    cout.flush();
    return 0;
}

void init()
{
    cin >> n >> k;
    mat = Matrix2D(n, n, false);
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            cin >> mat[i][j];
}

void process()
{
    mat = mat.powerN(k);
    Matrix2D cnt(n, 1);
    for(int i = 0; i < n; i++) cnt[i][0] = 1;
    cnt = mat * cnt;
    ll ans = 0;
    for(int i = 0; i < n; i++) ans = (ans + cnt[i][0])%MOD;
    cout << ans << endl;
}



Measured memory_bytes: 1664
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <deque>
#define ll long long

using namespace std;

vector<int> lst;


int bin_search(int q) {
	int stt = 0;
	int end = lst.size();
	while (stt < end - 1) {
		int md = (stt + end) / 2;
		if (lst[md] == q) return 1;
		else if (lst[md] < q) {
			stt = md;
		}
		else {
			end = md;
		}
	}
	if (lst[stt] == q) return 1;
	return 0;
}

int main() {
	int n; cin >> n;
	lst.assign(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> lst[i];
	}

	vector<int> query;
	cin >> n;
	query.assign(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> query[i];
	}

	int sum = 0;
	for (int i = 0; i < query.size(); i++) {
		int q = query[i];
		sum += bin_search(q);
	}
	cout << sum << endl;



	return 0;

}





Measured memory_bytes: 3368
#include <iostream>
using namespace std;
int main(void) {
  string S, T; 
  cin >> S >> T;
 bool ans = false;
  for (int i= 0; i < S.size(); ++i) {
    if (S == T) {
      ans = true;
      break;
    }
    S = S.back() + S.substr(0, S.size()-1); 
  }
  if (ans) {
    cout << "Yes" << endl;
  }
    else {
      cout << "No" << endl; 
    }
  return 0;
}

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

#define inp 200005
#define check exit(0)
#define nl cout<<endl;
#define mod 1000000007 
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(v) for(int i=0;i<v.size();i++) {cout<<v[i]; (i==v.size()-1) ? cout<<"\n":cout<<" "; }

using namespace std;

// Pick yourself up, 'cause...

vector<ll> v(inp),h(inp);
vector<ll> st(inp<<2,0);

int n;

void update(int i,ll nwans,int si=1,int ss=1,int se=n)
{
    if(ss==se) { st[si]=max(st[si],nwans); return; }
    int mid=(ss+se)/2;
    if(i<=mid) update(i,nwans,si*2,ss,mid);
    else update(i,nwans,si*2+1,mid+1,se);
    st[si]=max(st[2*si],st[2*si+1]);
}

int ch;
ll query(int l=1,int r=ch,int si=1,int ss=1,int se=n)
{
    if(ss>r || se<l) return 0;
    if(ss>=l && se<=r) return st[si];
    int mid=(ss+se)/2;
    return max(query(l,r,si*2,ss,mid),query(l,r,si*2+1,mid+1,se));
}

int main()
{
    jaldi

    cin>>n;

    for(int i=1;i<=n;i++) cin>>h[i];
    for(int i=1;i<=n;i++) cin>>v[i];

    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        ch=h[i];
        ll cv=v[i];

        ll maxans = cv+query();
        ans=max(ans,maxans);
        update(ch,maxans);
        //trace(maxans);
    }
   
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 12620
l = map(int, raw_input().split())
a=0
for i in xrange(l[0]+1):
    for j in xrange(l[0]+1-i):
        k=l[0]-i-j
        if k*10000+j*5000+i*1000==l[1]:
            a=1
            print "%d %d %d" % (k,j,i)
            break
    if a==1:
        break
if a==0:
    print "-1 -1 -1"


Measured memory_bytes: 2568
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long[] n = Arrays.stream(sc.nextLine().split(" "))
      .mapToLong(Long::parseLong).toArray();
    long ans = Long.MIN_VALUE; 
    for (int i = 0; i <= 1; i++) {
      for (int j = 2; j <= 3; j++) {
        ans = Math.max(ans, n[i]*n[j]);
      }
    }
    System.out.println(ans);
  }
}

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

bool isEven(string s){
    int l = s.size()/2;
    for(int i=0, j=l; j<s.size(); i++, j++){
        if(s[i] != s[j]) return false;
    }
    return true;
}

int main()
{
    string s;
    cin >> s;
    for(int i=2; i<s.size(); i+=2){
        string t = s.substr(0, s.size() - i);
        if(isEven(t)){
            cout << t.size() << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy

int n, m;
int sz[100005];
int parent[100005];
vector<pair<int, int>> a(100005);

int find_comp(int x) {
	if (x != parent[x]) {
		parent[x] = find_comp(parent[x]);
	}
	return parent[x];
}

bool same_comp(int x, int y) {
	return find_comp(x) == find_comp(y);
}

void join_comp(int X, int Y) {
	int x = find_comp(X);
	int y = find_comp(Y);
	if (sz[x] > sz[y]) {
		parent[y] = x;
		sz[x] += sz[y];
	} else {
		parent[x] = y;
		sz[y] += sz[x];
	}
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
	// n islands and m bridges
    cin >> n >> m;
    vector<ll> ans(m + 1);
    // initilly, every one island is parent of itself
    // with size of 1
    for (int i = 0; i < n; ++i) {
		parent[i] = i;
		sz[i] = 1;
	}
	for (int i = 0; i < m; ++i) {
		cin >> a[i].first >> a[i].second;
		// -- here to index from zero
		--a[i].first;
		--a[i].second;
	}
	// total number of inconveniences
	ans[m] = (ll) n * (n - 1) / 2;
	// go from back to start, and start building bridges
	for (int i = m - 1; i >= 0; --i) {
		int x = a[i].first;
		int y = a[i].second;
		// if they belong to the same component,
		// then the inconvenience doesn't change
		if (same_comp(x, y)) {
			ans[i] = ans[i + 1];
			continue;
		}
		// find_comp(x) finds the parent of x
		// sz[find_comp(x)] finds the size of that parent
		ll size_x = sz[find_comp(x)];
		ll size_y = sz[find_comp(y)];
		join_comp(x, y);
		ans[i] = max(ans[i + 1] - size_x * size_y, 0LL);
	}
	for (int i = 1; i <= m; ++i) {
		cout << ans[i] << nl;
	}
	
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



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

int main(void)
{
    int k,a,b;
    cin>>k>>a>>b;
    int c = a/k;
    if(c*k>=a && c*k<=b) {
        puts("OK");
        return 0;
    }
    ++c;
    if(c*k>=a && c*k<=b) {
        puts("OK");
        return 0;
    }
    puts("NG");
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	int n,m;
	cin>>n>>m;
	vi in(n);
	rep(i,n)in[i]=i;
	while(m--){
		int a,b;
		cin>>a>>b;
		a--;b--;
		int d=in[b];
		in[b]=in[a];
		rep(i,n)if(d==in[i])in[i]=in[a];
	}
	vi q(n,0);
	rep(i,n)q[in[i]]++;
	int co1=0,co2=0;
	rep(i,n)if(q[i]==1)co1++;
	else if(q[i]>1)co2++;
	cout<<abs(co2-co1)<<endl;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
const int N=200100;
typedef long long ll;
ll ans;
struct node{
	int x,y,id;
	bool operator < (const node&a)const{
		if((ll)x*a.y!=(ll)y*a.x)return (ll)x*a.y>(ll)y*a.x;
		return id<a.id;
	}
}a[N];
set<node>S;
int n,fa[N],p[N];
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=2;i<=n;++i)cin>>p[i];
	for(int i=1;i<=n;++i){
		int x;cin>>x;if(x==0)a[i].x++;else a[i].y++;
		a[i].id=fa[i]=i;if(p[i])S.insert(a[i]);
	}
	while(!S.empty()){
		node x=*S.begin();S.erase(S.begin());
		int u=find(x.id),v=find(p[u]);
		if(p[v])S.erase(a[v]);
		ans+=(ll)a[v].y*a[u].x;
		a[v].x+=a[u].x;a[v].y+=a[u].y;fa[u]=v;
		if(p[v])S.insert(a[v]);
	}
	cout<<ans<<'\n';
	return 0;
}


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

using namespace std; 

#define pb push_back
#define fi first
#define se second
#define all(vec) vec.begin(),vec.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define SZ(x) (int)x.size()

typedef  vector<string> vs;
typedef  vector<int> vi;
typedef  vector<long long> vl;	


bool check(int val){
	
	stringstream s;
	
	s << val;  
	
	string st = s.str(); 
	
	vi v(3);
	
	f(i,0,SZ(st)){
		if(st[i]=='3'){
			v[0] = 1;
		}
		if(st[i]=='5'){
			v[1] = 1;
		}
		if(st[i]=='7'){
			v[2] = 1;
		}
	}
	
	return v[0]&&v[1]&&v[2];
	
}

int main(){
	
	int n;
	
	vl pre;

	pre.pb(3); 
	pre.pb(5); 
	pre.pb(7);
	
	
	int x = 1;
	
	int lastSZ = 0;
	f(i,0,10){
		
		x *=10;
		
		int sz = SZ(pre);
		long long val = 1;
		f(k,0,3){
			val = pre[k] * x;
			f(j,lastSZ,sz){
				pre.pb(val+pre[j]);
			}
		}
		
		lastSZ = sz;
	}
	
	
	cin >> n;
	
	int ans = 0;
	
	f(i,0,SZ(pre)){
		if(pre[i]>=357){
			if(pre[i]<=n){
				if(check(pre[i])){
					ans++;
				}
			}
		}
	}
	
	cout << ans << endl;
	
    return 0;
}


Measured memory_bytes: 6512
n=int(input())
x=[]
y=[]
h=[]
for i in range(n):
    a,b,c=map(int,input().split())
    x.append(a)
    y.append(b)
    h.append(c)
    if c >0:
        data=[a,b,c]

for ans_x in range(101):
    for ans_y in range(101):
        ans_h = data[2]+abs(ans_x-data[0])+abs(ans_y-data[1])
        i = 0
        while i < n:
            if h[i]!= max(0,ans_h-abs(x[i]-ans_x)-abs(y[i]-ans_y)):
                break
            else:
                i += 1
        if i == n:
            print(ans_x,ans_y,ans_h)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{

    long long int a,b,c,d,i,j,k,l;
    string s;
    cin>>a>>s;
    if(a%2!=0)
    {
        cout<<"No";
        return 0;
    }
    else{
        d=0;
        for(i=0;i<a/2;i++)
        {
            if(s[i]!=s[a/2+i])
            {
                cout<<"No";
                return 0;
            }
        }
        cout<<"Yes";
        return 0;
    }
}


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

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n);
  vector<int> b(m);
  rep(i,n) cin >> a[i];
  rep(i,m) cin >> b[i];
  ll t = 0;
  rep(i,m) t += b[i];
  int j = m;
  int ans = 0;
  rep(i,n+1) {
    while (j > 0 && t > k) {
      --j;
      t -= b[j];
    }
    if (t > k) break;
    ans = max(ans, i+j);
    if (i == n) break;
    t += a[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4784
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A, B;
		A = sc.nextInt();
		B = sc.nextInt();
		sc.close();

		long gcd = 0;
		for (int i = 1; i < Math.max(A, B); i++) {
			if (A % i == 0 && B % i == 0) {
				gcd = i;
			}
		}
		long lcm = A * B / gcd;
		System.out.println(lcm);
	}
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
int h[200005];
int main(){
	int n,k;
	long long ans=0;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>h[i];
	if(n<=k){
		cout<<'0'; return 0;
	}
	sort(h+1,h+n+1);
	for(int i=n-k;i>=1;i--)
		ans+=h[i];
	cout<<ans;
	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

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

    bool f = false;
    REP(h,1,3501) {
        REP(n,1,3501) {
            ll num = N*h*n;
            ll den = 4*h*n - N*(h+n);
            if(den > 0 && num % den == 0) {
                PS(h); PS(n); PR(num/den);
                f = true;
                break;
            }
        }
        if(f) break;
    }

    return 0;
}

/*



*/

Measured memory_bytes: 3616
#include <iostream>
#include<algorithm>
#include<cmath>
#include <string>
#include <vector>

 int main (){
	 int n, a, b;
	 int ans = 0;
	 int sum = 0;
	 int a1 = 0;

	 std::cin >> n >> a >> b;

	 for (int i = 1; i <= n; ++i) {
		 sum = i;
		 while (true) {
			 if (sum == 0) {
				 break;
			 }

			 a1 += sum % 10;
			 
			 sum /= 10;
		 }
		 if (a1 >= a && a1 <= b) {
			 ans += i;
		 }
		 a1 = 0;
	 }

	 std::cout << ans << std::endl;

	 return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
//int const INF=1001001001;
//ll const INF=1001001001001001001;
ll const MOD=1000000007;

string S;

int main(){
    cin>>S;

    int ans=0;

    rep(i,3){
        if(S[i]=='R') ans=1;
    }
    rep(i,2){
        if(S[i]=='R' && S[i+1]=='R') ans=2;
    }
    if(S=="RRR") ans=3;

    cout<<ans<<endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

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

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    int r = 0;
    int m = n / 2;

    if (n % 2 == 0) {
        r = (b[m] + b[m - 1]) - (a[m] + a[m - 1]) + 1;

    } else {
        r = b[m] - a[m] + 1;
    }

    cout << r << endl;

    // Bをソートして大きい順に半分とる Nが奇数として中央値はそれより小さくなる

    return 0;
}

Measured memory_bytes: 4788
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x)
#define printl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
 
int main(){
    ll N; cin >> N;
    vll p(N+1);
    rep(i, 0, N){
        ll a; cin >> a;
        p[a] = i+1;
    }
    ll c = 1;
    ll mx = 1;
    rep(i, 2, N+1){
        if(p[i] > p[i-1]){
            c++;
            if(i == N){
                mx = max(mx, c);
            }
        }else{
            mx = max(mx, c);
            c = 1;
        }
    }
    cout << N - mx;
}

Measured memory_bytes: 1920
import sys
import math
def input(): return sys.stdin.readline().rstrip()

def main():
    N, M = map(int, input().split())
    m_sqrt = int(math.sqrt(M)) + 2

    ans = set()
    for i in range(1, m_sqrt):
        if M % i == 0:
            if M // i >= N:
                ans.add(i)
            if i >= N:
                ans.add(M // i)
    print(max(ans))
            
if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#pragma region templates 


//#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<math.h>
#include<string>
#define all(v) v.begin(),v.end()
#define maxall(v) *max_element(all(v))
#define minall(v) *min_element(all(v))
#define REV(x) reverse(x.begin(),x.end())
#define pi pair<int,int>
#define SORT(v) sort(all(v))
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007

using namespace std;

ll gcd(ll a, ll b) { if (a == 0)return(b); else return(gcd(b % a, a)); }
int modularexpo(ll a, ll b, ll c)
{
	if (a == 0)
	{
		return 0;
	}
	if (b == 0)
	{
		return 1;
	}
	else {
		if (b % 2 == 0)
		{
			long smallans = modularexpo(a, b / 2, c);
			int ans = ((smallans % c) * (smallans % c)) % c;
			return (ans + c) % c;
		}
		else {
			long smallans = modularexpo(a, b - 1, c);
			long ans = a % c;
			ans = ((ans % c) * (smallans % c)) % c;
			return (ans + c) % c;
		}
	}
}
long combination(int n, int r)
{
	long long ans = 1;
	r = r > n - r ? n - r : r;
	int j = 1;
	for (; j <= r; j++, n--)
	{
		if (n % j == 0)
		{
			ans *= n / j;
		}
		else
			if (ans % j == 0)
			{
				ans = ans / j * n;
			}
			else
			{
				ans = (ans * n) / j;
			}
	}
	return ans;
}
int binary(int* arr, int l, int r, int x)
{
	while (l <= r)
	{
		int mid = (l + r) / 2;
		if (arr[mid] == x)
		{
			return mid;
		}
		else if (arr[mid] < x)
		{
			l = mid + 1;
		}
		else
		{
			r = mid - 1;
		}
	}
	return -1;
}
#pragma endregion
ll recur(int* arr, int n, int i, int j,int flag, ll*** dp)
{
	if (i == j && flag == 0)
	{
		return arr[i];
	}
	else if (i == j && flag == 1)
	{
		return (arr[i] * -1);
	}
	if (dp[flag][i][j] != -1)
	{
		return dp[flag][i][j];
	}
	else {
		if (flag == 0)
		{
			ll ans = max(recur(arr, n, i + 1, j, flag ^ 1, dp) + arr[i], recur(arr, n, i, j-1, flag ^ 1, dp) + arr[j]);
			 dp[flag][i][j] = ans;
			 return dp[flag][i][j];
		}
	
		else {
			ll ans = min(recur(arr, n, i + 1, j, flag ^ 1, dp) - arr[i], recur(arr, n, i, j - 1, flag ^ 1, dp)-arr[j]);
			dp[flag][i][j] = ans;
			return dp[flag][i][j];
		}
	
	}

}
int main()
{
	int n;
	std::cin >> n;
	int* arr = new int[n];
	for (int i = 0; i < n; i++)
	{
		std::cin >> arr[i];
	}
	ll*** dp = new ll * *[2];
	for (int i = 0; i < 2; i++)
	{
		dp[i] = new ll * [n];
		for (int j = 0; j < n; j++)
		{
			dp[i][j] = new ll[n];
			for (int k = 0; k < n; k++)
			{
				dp[i][j][k] = -1;
			}
		}
	}
	std::cout << recur(arr, n, 0, n - 1, 0, dp);

	return 0;
}


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

using namespace std;

#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int, int>
#define all(x) x.begin(), x.end()
#define Matrix vector<vector<int>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'

constexpr int INF = 2e18;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e5 + 3;

signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int t;

  // cin >> t;
  t = 1;

  while (t--) {
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int ans = 0;

    int v = min(a, k);
    ans += v;
    k -= v;
    v = min(b, k);
    ans += v * 0;
    k -= v;
    v = min(c, k);
    ans += v * (-1);
    k -= v;
    cout << ans << endl;
  }
}

Measured memory_bytes: 3652
A, B = map(int, input().split())
list = []
for i in range(2, 14):
    list.append(str(i))
list.append('1')

Alice = list.index(str(A))
Bob = list.index(str(B))

if Alice > Bob:
    print('Alice')
elif Alice < Bob:
    print('Bob')
else:
    print('Draw')

Measured memory_bytes: 3064
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] a = sc.next().split("");
        String[] b = sc.next().split("");
        String[] c = sc.next().split("");

        if (a[a.length-1].equals(b[0]) && b[b.length-1].equals(c[0])) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <fstream>
#include <sstream>
#include <random>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <queue>
#include <iostream>
#include <functional>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <set>
#include <iomanip>

#define ll long long
#define mod 1000000007
using namespace std;

int main() {

    int h;
    int n;
    cin>>h>>n;

    int dp[h + 1];
    for(int i = 0; i <= h; i++) {
        dp[i] = 100000000;
    }
    dp[0] = 0;

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

    for(int i = 1; i <= h; i++) {
        for (int j = 0; j < n; j++) {
            if(a[j] >= i) {
                dp[i] = min(dp[i], b[j]);
            }
            else {
                dp[i] = min(dp[i], dp[i - a[j]] + b[j]);
            }
        }
    }


    cout<<dp[h]<<'\n';
    return 0;
}


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

using namespace std;

class cIsRightTriangle
{
public:
	bool judge(vector<int>&);
};

bool cIsRightTriangle::judge(vector<int> &v)
{
	sort(v.begin(), v.end());
	if (v[2] * v[2] == (v[0] * v[0] + v[1] * v[1]))
		return true;
	else
		return false;
}

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

	int n;
	cin >> n;
	cIsRightTriangle ct;
	vector<int> vd(3);

	for (int i = 0; i < n; ++i)
	{
		cin >> vd[0] >> vd[1] >> vd[2];
		cout << (ct.judge(vd) ? string("YES") : string("NO")) << endl;
	}

	return 0;
}

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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


int main()
{
    int A,B;
    cin >> A >> B;

    if( A+B >= 10 ) cout << "error" << endl;
    else cout << A+B << endl;

}


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

using namespace std;

int main() {
	long long n, k; cin >> n >> k;
	vector<int> a(n);
	for (auto& e : a) cin >> e, --e;
	vector<int> flag(n);
	int cnt = 0, now = 0;
	while (true) {
		++cnt;
		if (flag[now]) break;
		flag[now] = cnt;
		now = a[now];
	}
	if (k >= flag[now] - 1) {
		k -= flag[now] - 1;
		k %= cnt - flag[now];
	} else now = 0;
	while (k--) now = a[now];
	cout << now + 1 << endl;

	return 0;
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(const T x,const T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}

typedef long long ll;
typedef pair<ll, ll> P;

const int MOD=1e9+7;
const int MAX=1e5+100;

int main() {
  // 最も数が多い隣り合った３数の数
  // 起点をnと決めたら、n+3のlower_boundをして、その数のmaxを取っていく
  // 次はlower_boundのところから
  int N;cin>>N;
  vector<int> AS(N);
  REP(i,N) cin>>AS[i];
  sort(ALL(AS));

  int ans = 1;
  int tmp = AS[0];
  while (true) {
    auto it = lower_bound(ALL(AS),tmp);
    auto it1 = lower_bound(ALL(AS),tmp+1);
    auto it3 = lower_bound(ALL(AS),tmp+3);
    int ho = it3-it;
    mmax(ans,ho);

    if (it1==AS.end()) break;
    tmp = *it1;
  }
  OUT(ans);

  return 0;
}

Measured memory_bytes: 640
N, M = map(int, input().split())
works = dict()
for _ in range(N):
  a, b = map(int, input().split())
  if a in works.keys():
    works[a].append(-1 * b)
  else:
    works[a] = [-1 * b]
#print(works)

import heapq
cando = []
total = 0
day = M - 1
while day >= 0:
  lt = M - day

  if lt in works.keys():
    for salary in works[lt]:
      heapq.heappush(cando, salary)

  #print('day:{}, lt:{}, len(cando):{}'.format(day, lt, len(cando)))

  if len(cando) > 0:
    total += -1 * heapq.heappop(cando)

  #print('day:{}, total:{}'.format(day, total))

  day -= 1

print(total)

Measured memory_bytes: 25992
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(),v.end()

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    vector<ll> a(n, 0), b(n - 1, 0);
    for (ll i = 0; i < n - 1; i++)
    {
        cin >> b[i];
    }

    a[0] = b[0];

    for (ll i = 1; i < n - 1; i++)
    {
        a[i] = min(b[i - 1], b[i]);
    }

    a[n - 1] = b[n - 2];

    ll ans = 0;
    for (auto x : a)
    {
        ans += x;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256