akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
const int mod1=1e9+7;
const int P1=19260817;
const int P2=998244353;
const int mod2=1004535809;
#define ll long long
typedef pair<ll,ll>Pi;
ll fsp(ll x,int y){
	ll ans=1;
	while(y){
		if(y&1)	ans=ans*x%mod1;
		x=x*x%mod1,y>>=1;
	}
	return ans;
}
ll ksm(ll x,int y){
	ll ans=1;
	while(y){
		if(y&1)	ans=ans*x%mod2;
		x=x*x%mod2,y>>=1;
	}
	return ans;
}
char s[N];
map<Pi,int>ma;
ll n,l1,l2=1,r1,r2=1,ans,res1,res2,add1,add2,inv1,inv2;
int main(){
	scanf("%lld%s",&n,s+1);
	add1=fsp(P1,n);add2=ksm(P2,n);
	inv1=fsp(P1,mod1-2),inv2=ksm(P2,mod2-2);
	for(int i=n;i;i--){
		if(s[i]=='-'){
			res1=(res1-add1+mod1)%mod1;
			res2=(res2-add2+mod2)%mod2;
		}
		if(s[i]=='+'){
			res1=(res1+add1)%mod1;
			res2=(res2+add2)%mod2;
		}
		if(s[i]=='<'){
			res1=res1*inv1%mod1;
			res2=res2*inv2%mod2;
		}
		if(s[i]=='>'){
			res1=res1*P1%mod1;
			res2=res2*P2%mod2;
		}
	}
	for(int i=n;i;i--){
		ll k1=0,k2=0;
		if(s[i]=='-'){
			l1=(l1-add1+mod1)%mod1,k1=mod1-add1;
			r1=(r1-add2+mod2)%mod2,k2=mod2-add2;
		}
		if(s[i]=='<'){
			l1=l1*inv1%mod1,l2=l2*inv1%mod1;
			r1=r1*inv2%mod2,r2=r2*inv2%mod2;
		}
		if(s[i]=='>'){
			l1=l1*P1%mod1,l2=l2*P1%mod1;
			r1=r1*P2%mod2,r2=r2*P2%mod2;
		}
		if(s[i]=='+'){
			l1=(l1+add1)%mod1,k1=add1;
			r1=(r1+add2)%mod2,k2=add2;
		}
		++ma[Pi((k1-l1+mod1)*fsp(l2,mod1-2)%mod1,(k2-r1+mod2)*ksm(r2,mod2-2)%mod2)];
		ans+=ma[Pi((res1-l1+mod1)*fsp(l2,mod1-2)%mod1,(res2-r1+mod2)*ksm(r2,mod2-2)%mod2)];
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 31744
#include<stdio.h>
 
int main(void){
 int w,h,x,y,r;
 scanf("%d", &w);
 scanf("%d", &h);
 scanf("%d", &x);
 scanf("%d", &y);
 scanf("%d", &r);
 
if((0 <= x - r) && (x + r <= w) && (0 <= y - r) && (y + r <= h)){
  printf("Yes\n");
  }
else{
printf("No\n");
}
return 0;
}

Measured memory_bytes: 580
h,w=map(int,input().split());a=[list(input())for _ in[0]*h]
for y in range(h):
    for x in range(w):
        c=0
        if a[y][x]=='.':
            for i in range(8):
                u=x+[-1,-1,-1,0,0,1,1,1][i];v=y+[-1,0,1,-1,1,-1,0,1][i]
                if 0<=u<w and 0<=v<h and a[v][u]=='#':c+=1
            a[y][x]=c
for i in range(h):print(*a[i],sep='')

Measured memory_bytes: 3444
<?php

fscanf(STDIN, "%s", $s);

$chars = str_split($s);

$max = 0;
$tmp = 0;
foreach ($chars as $char) {
    if (!in_array($char, ['A', 'C', 'G', 'T'])) {
        $tmp = 0;
        continue;
    }

    $tmp++;

    $max = max($max, $tmp);
}

echo $max;


Measured memory_bytes: 4604
from collections import Counter
n = int(input())

a = []
while n % 2 == 0:
    a.append(2)
    n //= 2
f = 3
while f * f <= n:
    if n % f == 0:
        a.append(f)
        n //= f
    else:
        f += 2
if n != 1:
    a.append(n)

lst = Counter(a)
lst = list(lst.values())

ans = 0
for i in lst:
    cnt = 0
    while i - (cnt) > 0:
        cnt += 1
        i = i - (cnt)
        ans += 1
print(ans)

Measured memory_bytes: 9472
import math
s = input().rstrip()
alpha = set()
for i in range(len(s)):
  alpha.add(s[i])
if len(alpha) == len(s):
  print(math.ceil(len(s)//2))
elif len(alpha) == 1:
  print(0)
else:
  mincount = 10**12
  for X in alpha:
    tmp = list(s[::1])
    count = 0
    while 1:
      count += 1
      work = []
      alpha2 = set()
      for k in range(len(tmp)-1):
        if tmp[k] == X or tmp[k+1] == X:
          work.append(X)
          alpha2.add(X)
        else:
          work.append(tmp[k])
          alpha2.add(tmp[k])
      if len(alpha2) == 1:
        break
      else:
        tmp = work
    mincount = min(count,mincount)    
  print(mincount)

Measured memory_bytes: 3064
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u){
 int i, c;
 printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

 if(T[u].p==-1/*ここを埋める (fill this blank)*/) printf("root, ");
 else if(T[u].l==NIL/*ここを埋める(fill this blank)*/) printf("leaf, ");
 else printf("internal node, ");

 printf("[");
 for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){
   if(i) printf(", ");
   printf("%d", c);
 }
 printf("]\n");

}

void calcDepth(int u, int p){
 D[u] = p;
 if(T[u].r!=NIL/*ここを埋める(fill this blank)*/) calcDepth(T[u].r,p/*ここを埋める(fill this blank)*/);
 if(T[u].l!=NIL/*ここを埋める(fill this blank)*/) calcDepth(T[u].l,p+1/*ここを埋める(fill this blank)*/);
}

int main(){
 int i, j, k;
 int n;
 int id, sib, child;
 int root = NIL;
 scanf("%d", &n);
 for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;

 for(i=0; i<n; i++){
   scanf("%d %d", &id, &k);
   for(j = 0, sib = NIL; j<k; j++){ //子を入力する (input children)
     scanf("%d", &child);
     T[child].p = id;
     if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)
     else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
     sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
   }
 }

 //根を求める (find the root)
 for(i=0; i<n; i++){
   if(T[i].p == -1) root = i;
 }

 //それぞれのノードの深さを求める (find depth of each node)
 calcDepth(root, 0);

 //出力 (output)
 for(i=0; i<n; i++) print(i);

 return 0;
}



Measured memory_bytes: 6420
import java.io.*;
 
public class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        Long x=Long.parseLong(br.readLine());
        Long sum=(x/11)*2;
        x%=11;
        if(x>0){ sum+=(x>6) ? 2:1; }
        System.out.println(sum);
    }
    
}

Measured memory_bytes: 8148
#include <bits/stdc++.h>
#define forna(i,a,n) for(int i=a;i<n;i++)
typedef long long int lli;
using namespace std;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lli t,n,first,second,third,a,b,c;string s;
// cin>>t;
// while(t--){
cin>>n;
lli v[n];
// vector<int>v;
forna(i,0,n) {cin>>v[i];}//m[ar[i]]++;}
if(n<3) {cout<<0;return 0;}
// for(auto x:m) v.push_back(x.first);
sort(v,v+n);
lli tot=0;
forna(i,0,n){
  // first=m[v[i]];
  a=v[i];//second=m[v[i+1]];
  // lli sum=v[i]+v[i+1];
  forna(j,i+1,n){
    // second=m[v[j]];
    b=v[j];
    forna(k,j+1,n){
      // third=m[v[k]];
      c=v[k];
      //if(c>a+b) break;
      if(a+b>c&&b+c>a&&a+c>b&&a!=b&&a!=c&&b!=c){
        tot++;
      }
    }
}
}
cout<<tot<<endl;
}


Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;

int main(){
    double a,b,x ;
    cin >> a >> b >> x ;
    //ラジアンを度数に変換->　*pi/180
    double change = 180/M_PI ;
    double ans = 0;
    if (x <= a*a*b /2.0)
    {
        /* code */
        double angle = atan2(2.0*x/(a*b),b) ;
        ans = 90.0 - angle*change ;
    }else
    {
        double aa = (a*a*b - x) / (a*a) * 2 ;
        ans = atan2(aa,a) * change ;
    }
    

    cout << fixed << setprecision(10);
    cout << ans << endl ;   
}

Measured memory_bytes: 256
N = int(input())
flower_plan = [int(i) for i in input().split()]

# だるま落としのようにやる
cnt = 0
while True:
    if not any(flower_plan):
        break
    else :
        i = 0
        while i < N:
            if flower_plan[i] == 0:
                i += 1
            else :
                cnt += 1
                while i < N and flower_plan[i] > 0:
                    flower_plan[i] -= 1
                    i += 1
print(cnt)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt(), y = sc.nextInt(), i, ans = 0;
        if(x > y){    
            for(i = 1; i <= x % y; i++){
                if((x%y)%i==0 && y%i==0)ans = i;
            }
        }else if (x < y){
            for(i = 1; i <= y % x; i++){
                if((y%x)%i==0 && x%i==0)ans = i;
            }
        }else{
            ans = x;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 26336
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,ans=0;
	cin>>n;
	string s;
	unordered_set<string> us;
	while(n--){
		cin>>s;
		if(us.find(s)==us.end()){
			ans++;
			us.insert(s);
		}
	}
	cout<<ans<<"\n";
}


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

int main() {
	string input;
	cin>>input;
	int lenght=input.size();
	for(int i=0;i<lenght;i++){
		for(int m=i+1;m<lenght;m++){
			if(input[i]==input[m]){
				cout<<"no"<<endl;
				return 0;
			}
		}
	}
	cout<<"yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<numeric>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int& x : A) cin >> x;

  long long t = 0;
  for (int i = 0; i < N; i++) {
    t += (i % 2 ? -1 : 1) * 2 * A[i];
  }
  t /= 2;

  vector<int> ans(N);
  ans[0] = t;
  for (int i = 1; i < N; i++) {
    ans[i] = 2 * A[i - 1] - ans[i - 1];
  }

  for (int& x : ans) cout << x << " ";
  cout << endl;
}


Measured memory_bytes: 2048
use proconio::input;

fn main() {
    input!(k: u64);
    let mut ans = vec![49 + k / 50; 50];
    for i in 0..(k % 50) as usize {
        for j in 0..50 {
            ans[j] -= 1;
        }
        ans[i] += 51;
    }
    println!("50");
    println!(
        "{}",
        ans.iter()
            .map(|&x| x.to_string())
            .fold(String::new(), |acc, x| if acc.is_empty() {
                x
            } else {
                acc + " " + x.as_ref()
            })
    );
}


Measured memory_bytes: 2128
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath> // sqrt
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif


int main(void) {
    int64_t num;
    cin >> num;

    string ans;
    while(num) {
        int64_t idx = (num-1)%26;
        debug("%d\n", idx);
        ans.push_back(idx+'a');
        num -= idx;
        num /= 26;
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
from collections import Counter
 
M = 998244353
n = int(input())
a = map(int, input().split())
x, c = next(a), Counter(a)
r = 0
if x == c[0] == 0:
  r = x = 1
  for i in range(1, n):
    p = x; x = c.get(i)
    if x is None:
      break
    r = r * pow(p, x, M) % M
    n -= x
print((r, 0)[n > 1])

Measured memory_bytes: 22636
'use strict';
process.stdin.on('data', function(chunk) {
    var inputs = chunk.toString().trim().split(' ');
    var W = Number(inputs[0]);
    var H = Number(inputs[1]);
    var x = Number(inputs[2]);
    var y = Number(inputs[3]);
    var r = Number(inputs[4]);
  
    var x0 = W - x - r;
    var x1 = W - x + r;
    var y0 = H - y - r;
    var y1 = H - y + r;
  
    if ((x0 >= 0 && x1 <= W) && (y0 >= 0 && y1 <= H)) {
        console.log('Yes');
    } else {
        console.log('No');
    }
  
  
  
  
  
  
  
});
process.stdin.resume();
process.stdin.setEncoding('utf8');

Measured memory_bytes: 15556
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second

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

    int n;cin>>n;

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

    int ans=0;

    for(auto mm:m)
    {
        if(mm.fi>mm.se)ans+=mm.se;
        else if(mm.fi<mm.se)ans+=mm.se-mm.fi;
    }

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 8032
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) {
            os << ',';
        }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __Setup;

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    ll N, X, M;
    cin >> N >> X >> M;
    ll now = X;
    ll nxt;
    vector<ll> v;
    set<ll> se;
    {
        v.emplace_back(X);
        se.insert(X);
    }
    while(1) {
        nxt = (now * now) % M;
        if(se.count(nxt)) {
            break;
        }
        now = nxt;
        v.emplace_back(now);
        se.insert(now);
    }
    if(se.count(0)) {
        cout << accumulate(ALL(v), 0LL) << endl;
        return 0;
    }
    ll sz = (ll)v.size();
    ll start;
    for(ll i = 0; i < sz; i++) {
        if(v[i] == nxt) {
            start = i;
            break;
        }
    }
    ll loopsz = sz - start;
    ll loopsum = 0;
    for(ll i = start; i < sz; i++) {
        loopsum += v[i];
    }
    debug(start, loopsz, loopsum, sz);
    debug(v);
    if(N <= sz) {
        ll ans = 0;
        for(int i = 0; i < N; i++) {
            ans += v[i];
        }
        cout << ans << endl;
        return 0;
    }
    ll ans = accumulate(ALL(v), 0LL) + loopsum * (max(N - sz, 0LL) / loopsz);
    N -= (sz + loopsz * (max(0LL, N - sz) / loopsz));
    for(ll i = 0; i < N; i++) {
        assert(start <= i + start && i + start < sz);
        ans += v[i + start];
    }
    cout << ans << endl;
}


Measured memory_bytes: 5904
def main():
    N, Y = map(int,input().split())
    x, y, z = [0, 0, 0]
    
    for i in range(N + 1):
        for j in range(N + 1 - i):
            if i * 10000 + j * 5000 + (N-i-j) * 1000 == Y and N-i-j >= 0:
                print(i, j , N-i-j)
                return
    
    print(-1, -1, -1)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9184
N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
x.sort(reverse=True)
y.sort()
a=0
for z in range(X+1,Y+1):
    if z>x[0] and z<=y[0]:
        a=1
        break
if a==1:
    print('No War')
else:
    print('War')


Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
#define FOR(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int x[5];
	cin>>x[0]>>x[1]>>x[2]>>x[3]>>x[4];
	sort(x,x+5,greater<int>());
	cout<<x[0]<<" "<<x[1]<<" "<<x[2]<<" "<<x[3]<<" "<<x[4]<<endl;
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

#define MAX 722

typedef struct {
  int t;
  int m;
  int s;
}Log;

int main(){
  int N; //PC
  int M; //テ・ツュツヲテァツ板?
  Log data[1000];
  int log[MAX];
  int r;
  int Q,T;
  int i,j;


  while(scanf("%d%d",&N,&M),N!=0&&M!=0){
    scanf("%d",&r);
    for(i=0;i<r;i++){
      scanf("%d%d%d%d",&data[i].t,&T,&data[i].m,&data[i].s);
      if(data[i].s==0) data[i].s = -1;
      data[i].t -=540;
  }
    scanf("%d",&Q);
    for(i=0;i<Q;i++){
      int Ts,Te,m;
      int ans=0;
      scanf("%d%d%d",&Ts,&Te,&m);
      Ts-=540;
      Te-=540;
      for(j=0;j<MAX;j++) log[j]=0;
      for(j=0;j<r;j++){
	if(data[j].m==m) log[data[j].t+(data[j].s<0?1:0)] +=data[j].s;
      }
      for(j=1;j<MAX;j++) log[j]+=log[j-1];
      for(j=Ts;j<Te;j++){
	if(log[j]&&log[j+1]) ans++;
      }
      printf("%d\n",ans);
    }
  }
  return 0;
}

Measured memory_bytes: 612
// 1835
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 
 
int32_t main()
{
    fast;
    int W, H, N;
    cin >> W >> H >> N;
    int left = 0, right = W, bottom = 0, top = H;
 
    for(int i=0; i<N; i++) {
          int x, y, a;
        cin >> x >> y >> a;
 
        if(a == 1) {
            left = max(left, x);
        }
        else if(a == 2) {
            right = min(right, x);
        }
        else if(a == 3) {
            bottom = max(bottom, y);
        }
        else if(a == 4) {
           top = min(top, y);
        }
    }
    if(left >= right || bottom >= top) {
        cout << 0 << endl;
        return 0;
    }
    cout << (right - left) * (top - bottom ) << "\n";

    
    
    
    return 0;
}

Measured memory_bytes: 3560
N, L = map(int, input().split())
a = [L+i-1 for i in range(1, N+1)]
if a[0] >= 0:
    print(sum(a[1:]))
elif a[0] < 0 and a[-1] < 0:
    print(sum(a[:-1]))
else:
    print(sum(a))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
using namespace std;
signed main(){
  ll n,a,b,c[10000];
  ll x=0,y=0,z=0;
  cin>>n>>a>>b;
  for(ll i=0;i<n;i++){
	cin>>c[i];
  }
  for(ll i=0;i<n;i++){
	if(a>=c[i]){
      x++;
    }else if(a<c[i] && b>=c[i]){
      y++;
    }else if(a<c[i] && b<c[i]){
      z++;
    }
  }
  cout<<min(x,min(y,z))<<"\n";
  return(0);
}

Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline().strip()
 
def main():
    nk=list(map(int,input().split()))
    h=list(map(int,input().split()))
    n=nk[0]
    k=nk[1]
    dp=[10**9]*n
    dp[0]=0
    dp[1]=abs(h[1]-h[0])
    for i in range(2,n):
        dp[i]=min(dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-k),i))
        # for j in range(max(0,i-k),i):
        #     dp[i]=min(dp[j]+abs(h[i]-h[j]),dp[i])
 
    print (dp[-1])
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 20436
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
	vector<int> mv;
	for(int i=0;i<n;i++){
		int t;cin>>t;
		mv.push_back(t);
	}
	for(int i=0;i<(int)mv.size()-1;i++){
		for(int j=i;j<(int)mv.size();j++){
			vector<int> tmp=mv;
			swap(mv[i],mv[j]);
			int suc=1;
			for(int z=0;z<(int)mv.size();z++){
				if(!z)continue;
				if(mv[z]<=mv[z-1]){
					suc=0;break;
				}
			}
			mv=tmp;
			if(suc){cout<<"YES"<<endl;return 0;}
		}
	}
	cout<<"NO"<<endl;
	return 0;
}


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

using namespace std;

typedef long long ll;

#define newline cout<<"\n"
#define deb(x) cout<<#x<<" "<<x<<endl;

template<typename... T>
void read(T&... args){
    ((cin>>args), ...);
}

template<typename... T>
void write(T... args){
    ((cout<<args<<" "), ...);
}

void printarr(vector<ll> &v){
    for(ll x: v){
        cout<<x<<" ";
    }
    newline;
}

const ll MOD = 1e9+7;
const ll nax = 1e7+7;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    
    ll n; cin>>n;

    ll pos = 0;

    string s = "";

    if(n==0){
        cout<<0<<endl;
        return 0;
    }

    while(n!=0){
        // cout<<n<<endl;
        // cout<<n<<endl;
        if(abs(n)%2==1){
            // cout<<1;
            s+='1';
            ll x = 1;
            if(pos%2==1){
                n+=x;
            }
            else{
                n-=x;
            }
            n/=2;
        }
        else{
            // cout<<0;
            s+='0';
            n/=2;
        }
        pos++;
    }
    reverse(s.begin(), s.end());
    cout<<s<<endl;
    newline;
    
    return 0;
}

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

const int INF = 1e9;

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

	int x, y;
	cin >> x >> y;
	
	bool resp = false;
	for (int i = 0; i <= x; i++) {
		int count = i * 4 + (x - i) * 2;
		if (count == y)
			resp = true;
	}
	if (resp)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];

  vector<ll> sum(5, 0);
  rep(i, n) {
    if (s[i][0] == 'M') sum[0]++;
    else if (s[i][0] == 'A') sum[1]++;
    else if (s[i][0] == 'R') sum[2]++;
    else if (s[i][0] == 'C') sum[3]++;
    else if (s[i][0] == 'H') sum[4]++;
  }

  ll ans = 0;
  rep(i, 5) {
    FOR(j, i + 1, 5) {
      FOR(k, j + 1, 5) {
        ans += sum[i] * sum[j] * sum[k];
      }
    }
  }
  cout << ans << endl;


  
  return 0;
}

Measured memory_bytes: 6144
N, W = map(int, input().split())

value_table = [[] for i in range(4)]
for i in range(N):
    w, v = map(int,input().split())
    if i == 0:
        w1 = w
    value_table[w-w1] += [v]

[value_table[i].sort(reverse=True) for i in range(4)]

ans = 0
value_table_ruiseki = [[0] for i in range(4)]
for i in range(4):
    for v in value_table[i]:
        value_table_ruiseki[i] += [value_table_ruiseki[i][-1] + v]

ans = 0
for i, iv in enumerate(value_table_ruiseki[0]):
    for j, jv in enumerate(value_table_ruiseki[1]):
        for k, kv in enumerate(value_table_ruiseki[2]):
            for ell, ellv in enumerate(value_table_ruiseki[3]):
                weight = i*w1 + j*(w1+1) + k*(w1+2) + ell*(w1+3)
                value = iv + jv + kv + ellv
                if weight <=W:
                    ans = max(ans, value)

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    ll a,b,h;
    cin>>a>>b>>h;
    cout<<(a+b)/2.0*h<<endl;
    return 0;
}


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

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

Measured memory_bytes: 256
N,T = map(int,input().split())
t = list(map(int,input().split()))
sum = 0
for i in range(N):
    if i == (N-1):
        sum += T
    elif t[i+1]-t[i] >= T:
        sum += T
    else:
        sum += t[i+1]-t[i]

print(sum)

Measured memory_bytes: 26836
def main():
  n = int(input())
  S = input()
  ans = 0
  dp = [0]*(n*n)
  for j in range(n-1, 0, -1):
    for i in range(j-1, -1, -1):
      if j == n-1:
        dp[i*n+j] = int(S[i] == S[j])
      else:
        if S[i] == S[j]:
          dp[i*n+j] = dp[i*n+j+1+n] + 1
      ans = max(ans, min(dp[i*n+j], j-i))
  print(ans)
if __name__ == "__main__":
  main()

Measured memory_bytes: 229912
#include<bits/stdc++.h>
using namespace std;
int main(){
    char a[3];
    cin>>a;
    if(a[0] == '7' || a[1] == '7' || a[2] == '7'){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3484
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

const int INF = INT_MAX / 4;
const double EPS = 1e-12;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define EACH( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

int main()
{
	while ( true )
	{
		int e;
		cin >> e;

		if ( !e )
		{
			break;
		}

		ULL min = INT_MAX;

		for ( ULL y = 0; y * y <= e; y++ )
		{
			for ( ULL z = 0; z * z * z <= e; z++ )
			{
				LL x = e - z * z * z - y * y;

				if ( x < 0 )
				{
					break;
				}

				if ( x + y * y + z * z * z == e )
				{
					min = std::min( min, x + y + z );
				}
			}
		}

		cout << min << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;

int main()
{
        int n;

        cin >> n;

        double x[n], y[n], D1 = 0, sum2 = 0, sum3 = 0, D2, D3, D_max = 0;
        vector<double> D_inf;

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

        for(int i = 0; i < n; i++) {
                D1 += abs(x[i]-y[i]);
        }

        for(int i = 0; i < n; i++) {
                sum2 += pow((x[i]-y[i]),2);
        }
        D2 = sqrt(sum2);

        for(int i = 0; i < n; i++) {
                sum3 += pow(abs(x[i]-y[i]),3);
        }
        D3 = pow(sum3, 1.0/3.0);

        for(int i = 0; i < n; i++) {
                D_inf.push_back(abs(x[i]-y[i]));
        }

        for(int i = 0; i < n; i++) {
                if(D_inf[i] > D_max) D_max = D_inf[i];
        }

        cout.setf(ios::fixed, ios::floatfield);
        cout << D1 << endl;
        cout << D2 << endl;
        cout << D3 << endl;
        cout << D_max << endl;

        return 0;
}



Measured memory_bytes: 3436
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

    ll h, w, m, ans=0;
    cin >> h >> w >> m;
    vector<ll> r(h, 0), c(w, 0);
    map<ll, set<ll> > mp_c;
    vector<pair<ll, ll> > v(m);
    for(ll i=0; i<m; i++){
        ll x, y;
        cin >> x >> y;
        x--, y--;
        r[x]++;
        c[y]++;
        v[i]={x, y};
        mp_c[y].insert(x);
    }
    map<ll, vector<ll> > mp;
    for(ll i=0; i<h; i++)
        mp[r[i]].push_back(i);
    vector<ll> mx=mp.rbegin()->second;
    ll total=mp.rbegin()->first;
    for(ll j=0; j<w; j++){
        if(mp_c[j].size()==0) ans=max(ans, total);
        else if(mp_c[j].size()==h) ans=max(ans, total+h-1);
        else if(mx.size()==0) ans=max(ans, (ll)mp_c[j].size());
        else{
            ll flag=0;
            for(ll num: mx){
                if(mp_c[j].find(num)==mp_c[j].end()){
                    ans=max(ans, (ll)mp_c[j].size()+total);
                    flag=1;
                    break;
                }
            }
            if(!flag) ans=max(ans, total+(ll)mp_c[j].size()-1);
        }
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 59732
process.stdin.resume();
process.stdin.setEncoding('utf8');

process.stdin.on('data', function(chunk) {
    var inputs = chunk.trim().split(" ");
    var result1 = (parseInt(inputs[0]) + parseInt(inputs[1])) * 2;
    var result2 = parseInt(inputs[0]) * parseInt(inputs[1]);
    
    console.log(result2, result1);
});

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

int main(){
    int H,N;
    int A;
    int ans = 0;

    std::cin >> H >> N;
    for(int i = 0; i < N; i++){
        scanf("%d", &A);
        ans = ans + A;
    }

    if(ans >= H){
        std::cout << "Yes";
    }else{
        std::cout << "No";
    }
}

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

int main(void)
{
  int s,l,k,j,i;
  string n,m[1001]={};
  k = 0;
  do{
    k = k+1;
    cin >> n;
    m[k] = n;
  }while(n != "0");

  j = k-1;
  for(k = 1; k <= j; k++){
    i = m[k].size();
    s = 0;
    for(l = 0; l<=i-1; l++)
      s = s + (m[k][l]-'0');
    cout << s <<  endl;
  }
  return 0;
}

Measured memory_bytes: 3144
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <iterator>
#include <cmath>
using namespace std;

void solve(std::istream &ist, std::ostream &ost)
{
    /* ------- 宣言と入力 ------- */

    int N;
    string S;

    ist >> N;
    ist >> S;

    /* ------- 計算 ------- */

    unordered_set<int> R;
    unordered_set<int> G;
    unordered_set<int> B;

    for (int i = 0; i < N; i++)
    {
        if (S[i] == 'R')
        {
            R.emplace(i);
        }
        else if (S[i] == 'G')
        {
            G.emplace(i);
        }
        else if (S[i] == 'B')
        {
            B.emplace(i);
        }
    }

    // unordered_set<int> maxsize;
    long long ans = R.size() * G.size() * B.size();

    if (R.size() >= max(G.size(), B.size()))
    {
        for (auto g : G)
        {
            for (auto b : B)
            {
                if (R.find(min(g, b) - abs(g - b)) != R.end())
                {
                    ans--;
                }

                if (R.find(max(g, b) + abs(g - b)) != R.end())
                {
                    ans--;
                }

                if (abs(g - b) % 2 == 0)
                {
                    if (R.find(max(g, b) - abs(g - b)/2) != R.end())
                    {
                        ans--;
                    }
                }
            }
        }
    }
    else if (G.size() >= max(B.size(), R.size()))
    {
        for (auto b : B)
        {
            for (auto r : R)
            {
                if (G.find(min(b, r) - abs(b - r)) != G.end())
                {
                    ans--;
                }

                if (G.find(max(b, r) + abs(b - r)) != G.end())
                {
                    ans--;
                }

                if (abs(b - r) % 2 == 0)
                {
                    if (G.find(max(b, r) - abs(b - r)/2) != G.end())
                    {
                        ans--;
                    }
                }
            }
        }
    }
    else if (B.size() >= max(R.size(), G.size()))
    {
        for (auto r : R)
        {
            for (auto g : G)
            {
                if (B.find(min(r, g) - abs(r - g)) != B.end())
                {
                    ans--;
                }

                if (B.find(max(r, g) + abs(r - g)) != B.end())
                {
                    ans--;
                }

                if (abs(r - g) % 2 == 0)
                {
                    if (B.find(max(r, g) - abs(r - g)/2) != B.end())
                    {
                        ans--;
                    }
                }
            }
        }
    }

    cout << ans << endl;
}

#ifndef WOMAIN
int main()
{
    solve(std::cin, std::cout);
    return 0;
}
#endif


Measured memory_bytes: 3400
#include <stdio.h>

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



Measured memory_bytes: 2044
#include<stdio.h>
int main(void)
{
  int num, days, mod,sum=0;
  scanf("%d%d%d",&num,&days,&mod);
  int eat[num], i,j;
  for(i=0; i<num; i++)
  {
    scanf("%d",&eat[i]);
  }
  for(i=0;i<num;i++)
  {
    j=1;
    while(j<=days)
    {
      if(j%eat[i]==1 || eat[i]==1) sum++;
      j++;
    }
  }
  sum=sum+mod;
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;

void solve() {
  int n, h, w;
  cin >> n >> h >> w;
  int a = 0;
  int b = 0;
  int c = 0;
  while(n--) {
    int x;
    cin >> x;
    if(x >= h+1 && x <= w) b++;
    else if(x <= h) a++;
    else c++;
  }
  cout << min(a, min(b, c)) << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


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

vector<string> S = {"dreamer", "dream", "erase", "eraser"};
bool dp[111111];

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

   dp[0] = true;
   for (int i = 0; i <= s.size(); i++) {
      for (int j = 0; j < S.size(); j++) {
         int size = S[j].size();
         if (i >= size) {
            dp[i] |= dp[i-size] && s.substr(i-size, size) == S[j];
         }
      }
   }

   puts(dp[s.size()]?"YES":"NO");

   return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(ll)(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n,k;
  ci(n>>k);
  ll ans=0;
  FOR(i,0,n){
    ll a;
    ci(a);
      ans+=min(abs(a-k),a);
  }
  co(2*ans)
}

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

using namespace std;
#define int long long
const int INF = 200000000007;


 
signed main(){
    int n;
    cin>>n;
    int d[n];
    for(int i=0;i<n;i++)cin>>d[i];
    sort(d,d+n);
    if(d[n/2]==d[n/2 -1])cout<<0;
    else{
        cout<< d[n/2 ]-d[n/2 -1];
    }
  
    
    return 0;
}

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

int main(void)
{
	int r, c, tmp;
	cin >> r >> c;
	vector < vector<int> > d(r+1, vector<int>(c+1));

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

	for (int j=0; j<c; j++)
		d[r][c] += d[r][j];

	for (int i=0; i<r+1; i++){
		for (int j=0; j<c+1; j++){
			if (j!=0) cout << " ";
			cout << d[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1256
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

const double PI = acos(-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

#define endl "\n"


const int MOD=1e9+7;

int mul(const int v1, const int v2, int mod=MOD) {
    return (int)((1LL * v1 * v2) % mod);
}

int pl(int v1, int v2, int mod=MOD) {
    int res = v1 + v2;

    while(res < 0)
        res += mod;

    while(res>=mod)
        res-=mod;

    return res;
}

/* int pow */
int toPower(int a, int p, int mod=MOD) {
    int res = 1;
    while (p != 0) {
        if (p & 1)
            res = mul(res, a, mod);
        p >>= 1;
        a = mul(a, a, mod);
    }
    return res;
}

int inv(const int x, const int mod=MOD) {
    return toPower(x, mod - 2);
}

int fraction(const int nom, const int denom) {
    return mul(nom, inv(denom));
}

/* 
 * Its a bit mathy.
 * 10^n - 9^n -9^n + 8^n
 * All sequences 
 * minus the ones without a '9' 
 * minus the ones without a '0'
 * plus the ones we subtraced twice.
 * It is called pigeon principle.
 */
void solve() {
    cini(n);

    int ans10=1;
    int ans9=1;
    int ans8=1;
    if(n<2) {
        cout<<0<<endl;
        return;
    }
    for(int i=0; i<n; i++) {
        ans10=mul(ans10, 10);
        ans9=mul(ans9, 9);
        ans8=mul(ans8, 8);
    }

    int ans=pl(ans10, -ans9);
    ans=pl(ans, -ans9);
    ans=pl(ans, ans8);

    cout<<ans<<endl;

}

signed main() {
    solve();
}

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS


Measured memory_bytes: 3656
/*

Sviatoslav Bidzilia 2019
CF: anakib1

*/

#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <chrono>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <deque>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdarg.h>
#include <functional>
#include <utility>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unisgned long long
#define ld long double
#define all(a) a.begin(), a.end()
#define SORT(a) sort(all(a))
#define pii pair<int, int>
#define tii triple<int, int, int>
#define e 1e-7
#define PI acos(-1)
#define inf 1e17
#define vi vector<int>
#define F first
#define S second
#define rng(x) for(int _ = 0; _ < (x); _++)
#define rngi(i, x) for(int i = 0; i < (x); i++)
#define rngsi(s, i, x) for(int i = (s); i <(x); i++)
#define int long long

template<typename A, typename B, typename C>
struct triple
{
	A X;
	B Y;
	C Z;
	triple(A a = 0, B b = 0, C c = 0) :X(a), Y(b), Z(c) {}
};
template<typename A, typename B, typename C>
triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0)
{
	return triple<A, B, C>(a, b, c);
}
template<typename A, typename B, typename C>
bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b)
{
	if (a.X != b.X)
		return a.X < b.X;
	if (a.Y != b.Y)
		return a.Y < b.Y;
	return a.Z < b.Z;
}
template<typename T, typename SS>
ostream& operator<<(ostream& ofs, const pair<T, SS>& p)
{
	ofs << "( " << p.F << " , " << p.S << " )";
	return ofs;
}
template<typename T>
void print(T a)
{
	for (auto i : a)
		cout << i << ' ';
	cout << '\n';
}
template<typename T>
T max(T a, T b, T c)
{
	return max(a, max(b, c));
}
template<typename T>
T min(T a, T b, T c)
{
	return min(a, min(b, c));
}
struct custom_hash
{
	static uint64_t splitmix64(uint64_t x)
	{
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const
	{
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};
#define mxh 20010

signed main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	srand(time(NULL));
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(false);
	int h, n;
	cin >> h >> n;
	vector<pii> a(n);
	for (auto& i : a)
		cin >> i.first >> i.second;
	vi dp(mxh, inf);
	dp[0] = 0;
	for (int x = 1; x <= 2 * h; x++)
		for (auto i : a)
			if (i.first >= x)
				dp[x] = min(dp[x], i.second);
			else
				dp[x] = min(dp[x], dp[x - i.first] + i.second);
	int ans = dp[h];
	for (int i = h + 1; i <= 2 * h; i++)
		ans = min(ans, dp[i]);
	cout << ans << '\n';
	
}

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

typedef long long ll;
const int MAX_n = 200000;

int main() {
	int n;
	static ll a[MAX_n];

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

	int n0;
	for(int i = n - 1; i >= 0; i -= 2) {
		std::cout << a[i] << " ";
		n0 = i;
	}
	n0 = (n0 == 1) ? 0 : 1;

	for(int i = n0; i < n; i += 2) {
		std::cout << a[i] << " ";
	}

	std::cout << std::endl;
}


Measured memory_bytes: 3712
#include <iostream>
using namespace std;
void print(int sequence[], int N); // 出力するための関数
int selectionSort(int sequence[], int N); //挿入ソートの関数

int main(void){
    
    // 定義：数列を「 sequence 」、数列の個数を「 N 」とソート回数を「 count 」と置く
    int sequence[100], N, count;

    cin >> N;
    
    // 反復：数列に値を入力する
    for(int i = 0; i < N; i++){
        cin >> sequence[i];
    }

    count = selectionSort(sequence, N); //選択ソートの関数
    print(sequence, N); // 出力するための関数
    cout << count << endl;
    
    return 0;
    
}


/***********************  出力するための関数   ******************************/

void print(int sequence[], int N){
    for(int i = 0; i < N; i++){
        cout << sequence[i] << ((i != N-1) ? " " : "\n");
    }
}


/***********************  選択ソートの関数  ******************************/

int selectionSort(int sequence[], int N){
    int count = 0;
    for(int i = 0; i < N; i++){
        
        // 定義：最小の値の場所「 minPosition 」を定義 ➡  初めを i と置く 
        int minPosition = i;
            for(int j = i+1; j < N; j++){
                
                // 比較：最小の場所を比較して探している
                if(sequence[j] < sequence[minPosition]) minPosition = j;
            }
            // 比較：交換があるか確認
            if(i != minPosition){
                swap(sequence[i], sequence[minPosition]);
                count++;
        }
    }
    
    return count;
}






Measured memory_bytes: 3116
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;

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

long long N, W;
vector<long long> w, v;
long long dp[110][100010];

int main() {
    scanf("%Ld %Ld", &N, &W);
    w.resize(N); v.resize(N);
    for (int i = 0; i < N; i++) scanf("%Ld %Ld", & w[i], & v[i]);

    for (int i = 0; i < N; i++) {
        for (long long w_sum = 0; w_sum <= W; w_sum++) {
            if (w_sum >= w[i]) chmax(dp[i+1][w_sum], v[i] + dp[i][w_sum - w[i]]);
            chmax(dp[i+1][w_sum], dp[i][w_sum]);
        }
    }

    printf("%Ld\n", dp[N][W]);
}

Measured memory_bytes: 79360
N, K = map(int, input().split())
*P, = map(int, input().split())
*C, = map(int, input().split())

ans = -float('inf')
v = []
for n in range(N):
    loop, score = 0, 0
    t = n
    for i in range(min(N, K)):
        n = P[n]-1
        score += C[n]
        ans = max(ans, score)
        if n == t:
            loop = i+1
            break
    v.append((loop, score))

for n in range(N):
    loop, score = v[n]
    if loop > 0 and score > 0:
        r = (K-1)//loop
        nscore = r*score
        for i in range(K-r*loop):
            n = P[n]-1
            nscore += C[n]
            ans = max(nscore, ans)
print(ans)


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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;

int main(){
  int N;
  cin>>N;
  vector<pair<int,int>> x,y;
  vector<int> X,Y;
  vector<pair<int,int>> G[100000];
  for(int i(0);i<N;i++){
    int xi,yi;
    cin>>xi>>yi;
    X.push_back(xi);
    Y.push_back(yi);
    x.push_back({xi,i});
    y.push_back({yi,i});
  }
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  for(int i(0);i<N-1;i++){
    G[x[i].second].push_back({x[i+1].first - x[i].first, x[i+1].second});
    G[x[i+1].second].push_back({x[i+1].first - x[i].first, x[i].second});

    G[y[i].second].push_back({y[i+1].first - y[i].first, y[i+1].second});
    G[y[i+1].second].push_back({y[i+1].first - y[i].first, y[i].second});
  }

  // ここからがプリム法(重み付きグラフGに関して)
  priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
  vector<int> used(N);
  q.push({0,0});
  ll ans(0); //全域最小コスト
  while(!q.empty()){
    pair<int,int> now = q.top();q.pop();
    int v = now.second;
    if(used[v] == 1) continue;
    used[v] = 1;
    ans += now.first;
    for(auto next:G[v]){
      int nv = next.second;
      if(used[nv] == 0){
        q.push({min(abs(X[nv]-X[v]),abs(Y[nv]-Y[v])),nv}); //コストの計算が独特(本来であれば、next.firstがコストとなる)
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

    int h, n; cin >> h >> n;
    vi a(n);
    ll su = 0;
    for(int i=0;i<n;++i) {
        cin >> a[i];
        su += a[i];
    }
    if(h > su) cout << "No" << endl;
    else cout << "Yes" << endl;


}


Measured memory_bytes: 640