akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define FS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld long double
#define pb push_back
#define bp __builtin_popcount
#define sz size()
#define ff first
#define ss second
#define vll vector<ll>
#define vbool vector<bool>
#define vpll vector<pair<ll,ll>>
#define pll pair<ll,ll>
#define vllv vector<vector<ll>>
#define setpri(x) cout<<setprecision(x)<<fixed;
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){if(n%x==0)return n/x; else return (n/x)+1;}
ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}
ll pow1(ll n,ll k,ll mm){
    if(k==0)return 1;
    if(k%2==0)return (pow1((n%mm)*(n%mm),k/2,mm))%mm;
    return ((n%mm)*(pow1((n%mm)*(n%mm),k/2,mm)%mm))%mm;
}
ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;
}
ll modinv(ll n,ll mod){
    return pow1(n,mod-2,mod);
}
bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
    if(a.ff != b.ff)return a.ff < b.ff;
    return a.ss > b.ss;
}
ll n;
string ans[100005];
string s[100004];
void dfs(ll i,ll a,ll b,ll c){
	
	if(i==n){
		cout<<"Yes\n";
		for(ll j=0;j<n;j++){
			cout<<ans[j]<<endl;
		}
		exit(0);
	}
	
	
	if(s[i]=="AB"){
		if(a){
			ans[i]='B';
			dfs(i+1,a-1,b+1,c);
		}
		if(b){
			ans[i]='A';
			dfs(i+1,a+1,b-1,c);
		}
	}
	if(s[i]=="AC"){
		if(a){
			ans[i]='C';
			dfs(i+1,a-1,b,c+1);
		}
		if(c){
			ans[i]='A';
			dfs(i+1,a+1,b,c-1);
		}
	}
	if(s[i]=="BC"){
		if(b){
			ans[i]='C';
			dfs(i+1,a,b-1,c+1);
		}
		if(c){
			ans[i]='B';
			dfs(i+1,a,b+1,c-1);
		}
	}
}
void solve(){
    ll i,j,k,l,m,x,y,z,r;
	
	ll a,b,c;
	cin>>n>>a>>b>>c;
	// vector<string> s(n);
	for(i=0;i<n;i++){
		cin>>s[i];
	}
	dfs(0,a,b,c);
	cout<<"No\n";
	
}
int main(){
    FS;
    ll i,j,k,n,m,x,y,z,q;
    q=1;
    // cin>>q;
    while(q--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 17712
n = int(input())
p_list = list(map(int, input().split()))

count = 0
for i in range(n - 2):
  if p_list[i] < p_list[i+1] and p_list[i+1] < p_list[i + 2]:
    count += 1
  elif p_list[i + 2] < p_list[i+1] and p_list[i+1] < p_list[i]: 
    count += 1
  else:
    continue
  
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i, n) for (ll i = 0; i < (n); i++)
#define fori(i, b, e) for (ll i = (b); i < (e); i++)
#define forr(i, b, e) for (ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second

class DSU
{
public:
    vector<int> f;
    vector<int> cnt;
    DSU(int sz)
    {
        f = vector<int>(sz);
        cnt = vector<int>(sz, 1);
        forn(i, sz) f[i] = i;
    }
    int get(int x)
    {
        return f[x] == x ? x : (f[x] = get(f[x]));
    }
    void merge(int x, int y)
    {
        x = get(x);
        y = get(y);
        if (x != y)
            f[x] = y, cnt[y] += cnt[x];
    }
    bool same(int x, int y)
    {
        return get(x) == get(y);
    }
    int count(int x)
    {
        return cnt[get(x)];
    }
};

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, m;
	cin >> n >> m;
	DSU dsu(n + 1);
	forn(i, m)
	{
		ll x, y, z;
		cin >> x >> y >> z;
		dsu.merge(x, y);
	}
	ll ans = 0;
	ll rmn = n;
	fori(i, 1, n + 1)
	{
		if(dsu.get(i) == i)
		{
			ll cnt = dsu.count(i);
			ans++, rmn -= cnt;
		}
	}
	cout << (ans + rmn) << endl;
	return 0;
}

Measured memory_bytes: 1280
from itertools import accumulate
import math
n, k = map(int, input().split())
a = list(map(int, input().split()))

c_sum = [0] * (n+1)
now = [0] * n

if k > 50:
    ans = [n] * n
    print(*ans)
    exit()

for i in range(k):
    c_sum = [0] * (n+1)
    for x, d in enumerate(a):
        s = max(0, x - d)
        c_sum[s] += 1
        e = min(n-1, x + d)
        c_sum[e+1] -= 1
    a = list(accumulate(c_sum))

print(*list(accumulate(c_sum))[:-1])

Measured memory_bytes: 178928
def resolve():
    S = input()
    if S[0] == "A" and S[2:-1].count("C") == 1:
        if S.count("A") == 1 and S.count("C") == 1:
            S = S.replace("A", "").replace("C", "")
            if S == S.lower():
                print("AC")
                return
    print("WA")


resolve()


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

int main(){
  int l,r; cin >> l >> r;
  if(r-l>=2018){
    cout << 0 << endl;
    return 0;
  }
  vector<int> a;
  for(int i=l; i<=r; i++) a.push_back(i%2019);
  int ans=INF;
  rep(i,a.size()-1){
    for(int j=i+1; j<a.size(); j++){
      ans=min(ans,(a[i]*a[j])%2019);
    }
  }
  cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll N = 100005, inf = 1e18, mod = 1e9+7;

ll n, m, s, t, d[2][N], c[2][N];
vector<pll> adj[N];
priority_queue<pll> pq;

void calc (ll I, ll S){
    for(ll i=1;i<=n;i++) d[I][i] = inf;
    d[I][S] = 0; c[I][S] = 1;
    pq.push({0, S});
    while(!pq.empty()){
        ll A, B; tie(A, B) = pq.top(); A *= -1; pq.pop();
        if(d[I][B] != A) continue;
        for(auto &T : adj[B]){
            ll X, Y; tie(X, Y) = T;
            if(d[I][X] > A + Y){
                d[I][X] = A + Y;
                c[I][X] = 0;
                pq.push({-A-Y,X});
            }
            if(d[I][X] == A + Y){
                c[I][X] += c[I][B];
                c[I][X] %= mod;
            }
        }
    }
}

int main()
{
    scanf("%lld%lld%lld%lld",&n,&m,&s,&t);
    for(ll i=1;i<=m;i++) 
   {
        ll A,B,C;
        scanf("%lld%lld%lld",&A,&B,&C);
        adj[A].push_back({B, C});
        adj[B].push_back({A, C});
    }
    calc(0, s); calc(1, t);
    ll Ans = c[0][t] * c[0][t] % mod;
    for(ll i=1;i<=n;i++){
        if(d[0][i] + d[1][i] != d[0][t]) continue;
        if(d[0][i] == d[1][i]) Ans = (Ans + mod - c[0][i] * c[1][i] % mod * c[0][i] % mod * c[1][i] % mod) % mod;
        for(auto &T : adj[i]){
            ll A, B; tie(A, B) = T;
            if(d[0][i] + B != d[0][A] || d[1][A] + B != d[1][i] || d[0][A] <= d[1][A] || d[1][i] <= d[0][i]) continue;
            Ans = (Ans + mod - c[0][i] * c[1][A] % mod * c[0][i] % mod * c[1][A] % mod) % mod;
        }
    }
    printf("%lld\n",Ans);
    return 0;
}

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

#define lli long long
#define FOR(i,a,b) for (lli i=(a);i<(b);i++)
#define REP(i,n) for (lli i=0;i<(n);i++)
#define rep(i,n) for (lli i=0;i<(n);i++)

#define INF INT_MAX/3
#define PB push_back
#define pb push_back
#define all(a) (a).begin(),(a),end()
#define pll pair<lli,lli>

int main(){
  lli n,m;
  lli a[100][100];
  lli b[100];

  cin>>n>>m;
  rep(i,n){
    rep(j,m){
      cin>>a[i][j];
    }
  }
  rep(i,m){
    cin>>b[i];
  }

  rep(i,n){
    lli ans=0;
    rep(j,m){
      ans += a[i][j]*b[j];
    }
    cout<<ans<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3100
// 参考: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8

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

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

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

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

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

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

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

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

fn main() {
    input! {
        n: i64,
        m: usize,
        a_list: [i64; m],
    }

    let mut total: i64 = 0;
    for i in a_list {
        total += i;
    }

    if n >= total {
        println!("{}", n - total);
    } else {
        println!("{}", -1);
    }
}


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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    string s;
    cin >> s;
    string flag = "No";
    for(int i=0; i<s.length(); i++){
        if(s[i]=='9'){
            flag = "Yes";
            break;
        }
    }
    cout << flag << endl;
    return 0;
}

Measured memory_bytes: 256
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

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

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)

int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    cin>>n;
    cout<<n/2+ (n%2 ? 1:0)<<endl;
    return 0;
}



Measured memory_bytes: 256
s=input()
for _ in range(int(input())):
    o=input().split()
    a,b=map(int,o[1:3]);b+=1
    c=o[0][2]
    if c=='p':s=s[:a]+o[3]+s[b:]
    elif c=='i':print(s[a:b])
    elif c=='v':s=s[:a]+s[a:b][::-1]+s[b:]



Measured memory_bytes: 5612
#include <iostream>
#include <cstdio>
#include <bitset>
using namespace std;
bitset<4000005> f;
int main()
{
	int n;
	scanf("%d",&n);
	f[0]=1;
	int s=0;
	for (int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		f|=f<<x;
		s+=x;
	}
	for (int i=(s+1)>>1;i<=s;i++)
		if (f[i])
		{
			printf("%d",i);		
			break;
		}
	return 0;
}

Measured memory_bytes: 1664
from bisect import bisect_left
n = int(input())
l = [int(_) for _ in input().split()]
l.sort()
cnt = 0
for i in range(n):
	for j in range(i+1,n):
		cnt += max(0, bisect_left(l, l[i] + l[j]) - (j+1))
print(cnt)

Measured memory_bytes: 3188
n = gets.to_i
array = gets.chomp.split().map(&:to_i).sort
q = gets.to_i
numbers = gets.chomp.split().map(&:to_i)
ans = []

(1..2**n-1).each do |i|
  sum = 0
  i.to_s(2).rjust(n, '0').split('').each_with_index do |bit, index|
    next if bit == '0'
    sum += array[index]
  end
  ans << sum
end

ans = ans.uniq.sort

numbers.each do |i|
  puts ans.include?(i) ? "yes" : "no"
end



Measured memory_bytes: 17156
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
using namespace std;
 
int main(void)
{
    long double a, b, c;
    scanf("%Lf%Lf%Lf", &a, &b, &c);
    long double eps = 1.0e-14;
    
    if (sqrtl(a) + sqrtl(b) + eps < sqrtl(c)) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
  int N, T;
  cin >> N >> T;
  int minc = 10001;
  for (int i = 0; i < N; i++) {
    int c, t;
    cin >> c >> t;
    if (t <= T && c <= minc)
      minc = c;
  }

  if (minc == 10001)
    cout << "TLE" << endl;
  else
    cout << minc << endl;

  return 0;
}

Measured memory_bytes: 256
// by tmt514
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#define SZ(x) ((int)(x).size())
#define FOR(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
using namespace std;
typedef long long LL;

int main(void) {
  LL k, a, b;
  cin >> k >> a >> b;
  LL x=1;
  while (k>0) {
    if(x>=a && k>1 && b>a+2) {
      x += (b-a)*(k/2);
      k%=2;
    } else if (x>=a) {
      x += k;
      k = 0;
    }
    if(x<a) {
      LL t = min(k, a-x);
      x += t;
      k -= t;
    }
  }
    cout << x << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// 複数行の標準入力
		ArrayList<String> strList = new ArrayList<String>();
		Scanner in = new Scanner(System.in);
		while (in.hasNext()) {
			String buf = in.nextLine();
			strList.add(buf);
		}
		in.close();

		// 入力データの分割
		int strLength = Integer.parseInt(strList.get(0));
		String s = strList.get(1);
		String t = strList.get(2);
		String tmpS = null;
		for (int i = 1; i <= strLength; i++) {
			String tmp = s.substring(strLength - i);
			if (t.startsWith(tmp)) {
				tmpS = s + t.substring(i);
			}
		}
		if (tmpS == null) {
			tmpS = s + t;
		}

		int resultLength = tmpS.length();

		System.out.println(resultLength);
	}
}


Measured memory_bytes: 9044
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, 0, N)
    {
        cin >> a[i];
        --a[i];
    }
    vector<bool> visited(N, false);
    int curr = 0;
    bool goal = false;
    int num = 0;
    while (true)
    {
        if (curr == 1)
        {
            goal = true;
            break;
        }
        if (visited[curr])
        {
            break;
        }
        visited[curr] = true;
        curr = a[curr];
        ++num;
    }
    cout << (goal ? num : -1) << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cstdio>
#define lim 100010

using namespace std;

typedef long long int LL;
struct edge { int to; int cost; };

vector<edge> Graph[lim];
LL depth[lim];

void dfs (int v, int p, LL d) {
    depth[v] = d;
    for (int i = 0; i < Graph[v].size(); i++) {
        if (Graph[v][i].to == p) continue;
        dfs(Graph[v][i].to, v, d + Graph[v][i].cost);
    }
}

int main() {
    int N, a, b, c;
    int Q, K, x, y;
    edge tmp;

    scanf("%d", &N);
    // cin >> N;

    for (int i = 0; i < N - 1; i++) {
        // cin >> a >> b >> c;
        scanf("%d %d %d", &a, &b, &c);
        a--, b--;
        tmp.to = b; tmp.cost = c;
        Graph[a].push_back(tmp);
        tmp.to = a;
        Graph[b].push_back(tmp);
    }

    // cin >> Q >> K;
    scanf("%d %d", &Q, &K);
    K--;

    dfs(K, -1, 0);

    for (int i = 0; i < Q; i++) {
        // cin >> x >> y;
        scanf("%d %d", &x, &y);
        x--; y--;
        // cout << depth[x] + depth[y] << endl;
        printf("%lld\n", depth[x] + depth[y]);
    }

    return 0;
}

Measured memory_bytes: 14336
import java.util.*;

public class Main {

    int N;
    String S;
    int[] array;

    public Main() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        S = sc.next();
        array = new int[N];
        for (int i = 0; i < N; i++) {
            if (S.charAt(i) == 'E') {
                array[i] = 0;
            } else {
                array[i] = 1;
            }
        }
    }

    public void run() {
        int count = 0;
        for (int i = 1; i < N; i++) {
            if (array[i] == 0) {
                count++;
            }
        }
        int min = count;
        for (int i = 1; i < N; i++) {
            if (array[i-1] == 0 && array[i] == 0) {
                count--;
            } else if (array[i-1] == 0 && array[i] == 1) {

            } else if (array[i-1] == 1 && array[i] == 0) {

            } else {
                count++;
            }
            if (min > count) {
                min = count;
            }
        }
        System.out.println(min);
    }

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

}


Measured memory_bytes: 28476
#include <iostream>
#include <vector>
#include <algorithm>

#define ll long long

using namespace std;

int main(){


    int a,b;
    cin >> a >> b;

    if(a >= 13){
        cout << b << endl;
    }else if(a >= 6){
        cout << b / 2 << endl;
    }else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

# In[7]:


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


# In[8]:


if N == 1 and M == 1:
    print(1)
elif N == 1 or M == 1:
    print(max(N,M) - 2)
elif N >= 2 or M >= 2:
    print((N-2)*(M-2))


# In[ ]:






Measured memory_bytes: 9056
#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>
#include <cstring>
#include <sstream>
#include <cassert>
#include <iomanip>
using namespace std;
static const double EPS = 1e-8;
typedef long long ll;
typedef pair<int,int> PI;
#ifndef M_PI
const double M_PI=acos(-1);
#endif
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int(a.size()))
#define F first
#define S second

int tx[]={1,0,-1,-1,0,1},ty[]={1,1,0,-1,-1,0};

main(){
  int t,n;
  while(cin>>t>>n,t|n){
    set<PI> syo;
    rep(i,n){
      int x,y;
      cin>>x>>y;
      syo.insert(mp(x,y));
    }
    int sx,sy;
    cin>>sx>>sy;
    queue<pair<PI,int> >q;
    q.push(mp(mp(sx,sy),0));
    set<PI> vis;
    while(!q.empty()){
      int c=q.front().S,cx=q.front().F.F,cy=q.front().F.S;
      q.pop();
      if(vis.count(mp(cx,cy)))continue;
      vis.insert(mp(cx,cy));
      if(c==t)continue;
      rep(i,6){
	int nx=cx+tx[i],ny=cy+ty[i];
	if(vis.count(mp(nx,ny)) || syo.count(mp(nx,ny)))continue;
	q.push(mp(mp(nx,ny),c+1));
      }
    }
    cout<<SZ(vis)<<endl;
  }
}

Measured memory_bytes: 1016
import java.util.*;

public class Main {
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n =Integer.parseInt(scan.next());
		int[] h=new int [n];
		int max=0;
		for (int i=0;i<n;++i) {
			h[i]=Integer.parseInt(scan.next());
			max=Math.max(max, h[i]);
		}
		
		int count=0;
		boolean last=false;
		while (max>0) {
			--max;
			count++;
			last=false;
			for (int i=0;i<n;++i) {
				if (h[i]>0) {	
					last=true;
					--h[i];
				}else if (i+1<n&&h[i+1]>0&&last) {
					++count;
				}
			}
			
			
		}
		
		System.out.print(count);

	}
}
//end


Measured memory_bytes: 21844
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = str(input())

score = 0
result = []
for i in range(len(T)):

    if i < K:
        if(T[i]=="r"):
            p = P
        elif(T[i]=="s"):
            p = R
        else:
            p = S

        result.append(1)

    else:
        if(T[i]!=T[i-K]) or (T[i]==T[i-K] and result[i-K]==0):
            if(T[i]=="r"):
                p = P
            elif(T[i]=="s"):
                p = R
            else:
                p = S
            result.append(1)
        else:
            p = 0
            result.append(0)


    score+=p

print(score)

Measured memory_bytes: 4212
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))

int main() {
  int N, L;
  scanf("%d %d", &N, &L);
  int r = L + N - 1, eat;
  if (r <= 0)
    eat = r;
  else if (L >= 0)
    eat = L;
  else
    eat = 0;
  printf("%d", (r + L) * (r - L + 1) / 2 - eat);
}


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

using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

template<int MOD> struct MInt {
  long long val;
  constexpr MInt(long long val = 0) : val(val % MOD) { if (val < 0) val += MOD; }
  constexpr MInt operator+(const MInt& n) const { return MInt(val) += n; }
  constexpr MInt operator-(const MInt& n) const { return MInt(val) -= n; }
  constexpr MInt operator*(const MInt& n) const { return MInt(val) *= n; }
  constexpr MInt& operator+=(const MInt& n) { val = (val + n.val) % MOD; return *this; }
  constexpr MInt& operator-=(const MInt& n) { val = (MOD + val - n.val) % MOD; return *this; }
  constexpr MInt& operator*=(const MInt& n) { val = (val * n.val) % MOD; return *this; }
  constexpr MInt pow(long long n) const {
    MInt pow = val, ans = 1;
    for (long long p = n; p > 0; p >>= 1, pow *= pow)
      if (p & 1) ans *= pow;
    return ans;
  }
  constexpr friend ostream& operator<<(ostream& os, const MInt& n) { os<<n.val; return os; }
};
constexpr int MOD = 1e9+7;
using mint = MInt<MOD>;

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

  vector<pair<ll, ll>> v;
  int zeros = 0;
  vector<ll> A(N), B(N);
  rep(i, N) {
    cin >> A[i] >> B[i];
    if (A[i] == 0 && B[i] == 0)
      ++zeros;
    else {
      ll g = gcd(A[i], B[i]);
      A[i] /= g; B[i] /= g;
      if (B[i] < 0) {
        A[i] *= -1; B[i] *= -1;
      }
      if (A[i] == -1 && B[i] == 0) A[i] = 1;
      v.emplace_back(A[i], B[i]);
    }
  }
  all(sort, v);

  int count = 0; // ペアに含まれているやつ
  mint X = 1;
  rep(i, v.size()) {
    auto [a, b] = v[i];
    int countV = all(upper_bound, v, v[i]) - all(lower_bound, v,  v[i]),
        tmp = all(upper_bound, v, make_pair(b, -a)) - all(lower_bound, v, make_pair(b, -a));
    if (tmp > 0) {
      count += countV + tmp;
      X *= (mint(2).pow(countV)) + (mint(2).pow(tmp)) - 2 + 1;
    }
    i += countV-1;
  }

  mint ans = mint(2).pow(N-zeros-count) * X - 1;
  cout << ans + zeros << endl;

  return 0;
}


Measured memory_bytes: 10456
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
       
		if(a.equals("H")){
          if(b.equals("D")){System.out.print("D");}
          if(b.equals("H")){System.out.print("H");}
        }
        if(a.equals("D")){
          if(b.equals("H")){System.out.print("D");}
          if(b.equals("D")){System.out.print("H");}
        }
      
    }
}

Measured memory_bytes: 21716
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int n;
    scanf("%d",&n);
    float p;
    
    if(n%2==0){
        p=1.0/2.0;
        printf("%.6f",p);
    }else{
        float tmp;
        tmp=((float)n+1)/2.0;
        p=tmp/n;
        printf("%.6f",p);
    }
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

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

ll lcm(ll a, ll b){
    ll g = gcd(a, b);
    return a / g * b;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n), f(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> f[i];
    sort(a.begin(), a.end());
    sort(f.rbegin(), f.rend());
    ll ok = 1e18, ng = -1;
    while(ok - ng > 1){
        ll mid = (ok + ng) / 2;
        ll cost = 0;
        rep(i,n){
            ll add = (a[i]*f[i] - mid + f[i] - 1) / f[i];
            chmax(add, 0LL);
            cost += add;
        }
        if(cost <= k) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
    return 0;
}


Measured memory_bytes: 6364
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef set<string> ss;

int main() {FIN
	
	int n, i;
	string s;
	ss items;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> s;
		items.insert(s);
	}
	cout << items.size() << "\n";
	return 0;
}


Measured memory_bytes: 19284
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>

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

using namespace std;

const int INF = 100100100;
vector<int> to[100005];

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

    rep(i, M) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    queue<int> q;
    vector<int> dist(N, INF);
    vector<int> pre(N, -1);
    dist[0] = 0;
    q.push(0);
    while (!q.empty()) {
        int v = q.front(); q.pop();
        for (int u: to[v]) {
            if (dist[u] != INF) continue;
            dist[u] = dist[v] + 1;
            pre[u] = v;
            q.push(u);
        }
    }

    cout << "Yes" << endl;
    rep(i, N) {
        if (i==0) continue;
        int ans = pre[i];
        ++ans;
        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 10204
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;$n:expr) => {
        (0..$n).map(|_| scan!()).collect::<Vec<_>>()
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (a, b) = scan!(i64, i64);
    let sum = a + b;
    if sum < 10 {
        println!("{}", sum);
    } else {
        println!("error");
    }
}


Measured memory_bytes: 4352
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

class Prog
{
    public Prog() { }
    public static int Main()
    {
        new Prog().calc();
        return 0;
    }

    Scanner cin;

    public void calc()
    {
        cin = new Scanner();
        var s = cin.next();
        Console.WriteLine(s.Replace(',', ' '));
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

Measured memory_bytes: 2648
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctype.h>
#include <math.h>
using namespace std;


int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22){
        cout<<"bust"<<endl;
    }
    else{
        cout<<"win"<<endl;
    }
}


Measured memory_bytes: 256
import math

n, k = map(int, input().split())

a = list(map(int, input().split()))

emin = 100001
cont = 0
for ea in a:
    emin = min(emin, ea)

for i in range(len(a)):
    if i + 1 < len(a) and a[i] == emin and a[i + 1] == emin:
        cont += 1

all = 1 + math.ceil((n - k) / (k - 1))
con = 1 + math.ceil(math.floor(cont + 1 - k) / (k - 1))

print(all - con)


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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

ll dp[210][210];

int main(int argc, char **argv)
{
	ll N, M, R;
	cin >> N >> M >> R;
	vector<ll> r(R); REP(i, R) cin >> r[i], --r[i];

	REP(i, N) REP(j, N) dp[i][j] = INF;
	REP(i, M)
	{
		ll s, t, d; cin >> s >> t >> d;
		--s, --t;
		dp[s][t] = d;
		dp[t][s] = d;
	}

	REP(v, N)REP(s, N)REP(g, N)
		dp[s][g] = min(dp[s][v] + dp[v][g], dp[s][g]);

	sort(ALL(r));
	ll res{INF};
	do
	{
		ll tmp{0};
		REP(i, R-1)
		{
			tmp += dp[r[i]][r[i+1]];
		}
		res = min(res, tmp);
	} while (next_permutation(ALL(r)));

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


Measured memory_bytes: 512
require 'set'

def compress(used_x)
	x_map = {}
	used_x.to_a.uniq.sort.each_with_index{|x, i| x_map[x] = i}
	x_map
end

loop do
    n = gets.to_i
    break if n == 0
    used_x = Set.new
    used_y = Set.new
    w_points = []
    n.times do
        x, y = gets.split.map(&:to_i)
        used_x << x
        used_y << y
        w_points << [x, y]
    end

    x_min = Float::INFINITY
    x_max = - x_min
    y_min = Float::INFINITY
    y_max = - y_min

    4.times do
        x, y = gets.split.map(&:to_i)
        used_x << x
        x_max = x if x > x_max
        x_min = x if x < x_min
        used_y << y
        y_max = y if y > y_max
        y_min = y if y < y_min
    end

    cx = compress(used_x)
    cy = compress(used_y)

    v_lines = []
    (w_points + [w_points[0]]).each_cons(2) do |p1, p2|
        x1, y1 = p1
        x2, y2 = p2
        next if x1 != x2
        y1, y2 = y2, y1 if y1 > y2
        v_lines << [cx[x1], cy[y1], cy[y2]]
    end
    v_lines.sort_by!(&:first)

    a = (0..cx.values.max).map { [0] * (cy.values.max + 1) }

    (0..cy.values.max).each do |y|
        crossed = v_lines.select {|x, y1, y2| y1 <= y && y < y2 }
        crossed.each_slice(2) do |l1, l2|
            x1, _, _ = l1
            x2, _, _ = l2
            (x1..x2-1).each do |x|
                a[x][y] = 1
            end
        end
    end

    (cy[y_min]..cy[y_max]-1).each do |y|
        (cx[x_min]..cx[x_max]-1).each do |x|
            a[x][y] = 0
        end
    end

    cx_inv = cx.invert
    cy_inv = cy.invert

    s = 0
    (0..cy.values.max).each do |y|
        (0..cx.values.max).each do |x|
            s += (cx_inv[x+1] - cx_inv[x]) * (cy_inv[y+1] - cy_inv[y]) if a[x][y] == 1
        end
    end

    p s
end

Measured memory_bytes: 9188
import java.util.Scanner;


// 145_a
public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        int a = scan.nextInt();
        int b = scan.nextInt();
        if (a <= 9 && b <= 9) {
            System.out.println(a * b);
        } else {
            System.out.println(-1);
        }

        //        HashMap<String, Integer> map = new HashMap<>();
        //        map.put("SUN", 7);
        //        map.put("MON", 6);
        //        map.put("TUE", 5);
        //        map.put("WED", 4);
        //        map.put("THU", 3);
        //        map.put("FRI", 2);
        //        map.put("SAT", 1);

    }

}


Measured memory_bytes: 21844
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
#define pb push_back
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=1000000007LL;
const ll MOD=998244353LL;
//const ll MOD=1777777777LL;
//const ll MAX_V=114514LL;
//const ll MAX = 500010LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={0,0,1,-1};
vl dy={1,-1,0,0};




int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << fixed << setprecision(10);
  /*--------------------------------*/
  ll n;cin>>n;
  vl a(n);
  rep(i,n)cin>>a[i];
  ll key=a[0];
  for(ll i=1;i<n;i++)key^=a[i];
  rep(i,n){
    cout<<(a[i]^key);
    if(i!=n-1)cout<<" ";
  }
  cout<<endl;
}

Measured memory_bytes: 4772
int main(){
  int a,b,c,i,sum=0;
  scanf("%d %d", &a, &b);
  for(i=0;i<b;i++){
    scanf("%d", &c);
    sum+=c;
  }
  if((a-sum)>=0){
    printf("%d", a-sum);
  }else{
    printf("-1");
  }
  return 0;
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
#define mk make_pair
#define pb push_back
#define lowbit(x) x&(-x)
using namespace std;
typedef long long ll;
typedef pair <ll,ll> PAIR;
const int N = 2e5+7;
const int M = 2019;
const int INF = 0x3f3f3f3f;

map <int,int> mp;

int main(){
	string s;
	cin >> s;
	
	mp[0]++;
	int len = s.size();
	int base = 1;
	int now = 0;
	
	ll ans = 0;
	for(int i = len-1;i >= 0;--i){
		(now += base%M*(s[i]-'0')%M) %= M;
		ans += mp[now];
		mp[now]++;
		(base *= 10%M) %= M;
	}
	
	printf("%lld\n",ans);
    return 0;
}


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

const int MAX_N = 999999;
bool prime[MAX_N + 1];

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

int is_prime(int n)
{
  return prime[n];
}

int main()
{
  int n, i;
  int ans;
  sieve();
  while(cin >> n){
    ans = 0;
    for(i = 1; i <= n; i++){
      if(is_prime(i)){
	ans++;
      }
    }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORR(x, arr) for(auto& x:arr)
#define ITR(x, c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

ll a, b, c, x, y;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> a >> b >> c >> x >> y;
	ll ans = 0;
	if (2*c <= a+b) {
		ll mi = min(x, y);
		ans += 2*c*mi;
		x -= mi;
		y -= mi;
		if (2*c <= a) ans += x*2*c;
		else ans += x*a;
		if (2*c <= b) ans += y*2*c;
		else ans += y*b;
	}
	else {
		ll mi = min(x, y);
		ans += (a+b)*mi;
		x -= mi;
		y -= mi;
		ans += x*a;
		ans += y*b;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  string S; cin >> S;
  ll K; cin >> K;
  int n = -1;
  for (int i = 0; i < S.length(); ++i) {
    if (S[i] != '1') break;
    n = i;
  }
  if (n == -1) {
    cout << S[0] << endl;
  } else {
    cout << ( (K <= n + 1) ? S[0] : S[n + 1] ) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
program abc133c
  use,intrinsic :: iso_fortran_env
  implicit none
  logical :: f = .false.
  integer(int64) :: l, r, i, j, ans = 2019
  read *, l, r
  if (r - l + 1 >= 2019) then
     print *, 0
  else
     do j = l+1,r
        do i = l,j-1
           ans = min(ans,mod(i*j,2019))
           if (ans == 0) then
              f = .true.
              exit
           end if
        end do
        if (f) exit
     end do
     print *, ans
  end if
end program abc133c


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  int n; cin >> n;
  string s; cin >> s;
  int ans = n;
  FOR(i, 1, n) {
    if (s[i] == s[i - 1]) --ans;
  }
  cout << ans << '\n';
  return 0;
}


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

typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vint;
typedef vector<uint> vuint;
typedef vector<ull> vull;
typedef vector<ll> vll;

#define init(type,var) type var;cin>>var;
#define vinit(type,var,n) vector<type> var((uint)n);loop(i,0,n)cin>>var[i];
#define linit(type,var,n) list<type> var;loop(i,0,n){type _v;cin>>_v;var.push_back(_v);}
#define range(container) container.begin(),container.end()
#define loop(i,first,end) for(ull i=(first);i<(end);i++)
#define outl(out) cout<<(out)<<endl;

const ull INF = (ull)(-1LL);

typedef ll dint;

typedef vector<dint> vdint;

int main(void){
	init(dint, a);
	init(dint, b);

	outl((a > 9 || b > 9) ? -1 : a * b);

	return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N, K;
vector<int> ans;
void decliment() {
    if(ans.back() == 1) {
        ans.pop_back();
        return;
    }
    ans.back()--;
    while(ans.size() < N) {
        ans.push_back(K);
    }
    return;
}
int main() {
    //cout.precision(10);
    cin >> K >> N;
    if(K % 2 == 0) {
        cout << K / 2 << " ";
        for(int i = 2; i <= N; i++) {
            cout << K << " ";
        }
        cout << endl;
        return 0;
    }
    for(int i = 0; i < N; i++) {
        ans.push_back((K + 1) / 2);
    }
    for(int i = 0; i < N / 2; i++) {
        decliment();
    }
    for(int i = 0; i < ans.size(); i++) {
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3568
n,t=list(map(int,input().split()))
ab=sorted([list(map(int,input().split())) for _ in range(n)],key=lambda x:x[0])

dp=[[-10**10]*(t+1) for _ in range(n+1)]
dp[0][0]=0
dp[1][0]=0
ans=ab[0][1]
for i in range(1,n):
    for j in range(t):
        dp[i+1][j]=max(dp[i][j],dp[i][j-ab[i-1][0]]+ab[i-1][1] if j>=ab[i-1][0] else -10**10)
        ans=max(ans,dp[i+1][j]+ab[i][1])

print(ans)

Measured memory_bytes: 145828
#include<bits/stdc++.h>
using namespace std;
long long s[45];
int main()
{
	long long h;
	cin >> h;
	s[0]=1;
	for(int i=1;i<=42;i++)
		s[i]=s[i-1]*2;
	/*for(int i=1;i<=41;i++){
		cout << s[i] << endl;
	}*/
	for(int i=0;i<=42;i++){
		if(h<s[i]){
			cout << s[i]-1 << endl;
			break;
		} 
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

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

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (int i = m; i < (n); ++i)
using namespace std;
using ll = long long;

int main(){
    string s;
    cin >> s;
    int n = s.size() + 1;
    vector<int> num(n);
    rep(i,n){
        if ((i == 0 && s.at(i) == '<') || (i == n-1 && s.at(i-1) == '>')){
            num[i] = 0;
        }
        else if (i != 0 && i != n-1 && s.at(i-1) == '>' && s.at(i) == '<'){
            num[i] = 0;
        }
    }
    repp(i,n,1){
        if (i == n-1 && s.at(i-1) == '<'){
            num[i] = num[i-1] + 1;
        }
        else if (i != n-1 && s.at(i-1) == '<' && s.at(i) == '<'){
            num[i] = num[i-1] + 1;
        }
    }
    for (int i = n-2; i >= 0; i--){
        if (i == 0 && s.at(i) == '>'){
            num[i] = num[i+1] + 1;
        }
        else if (i != 0 && s.at(i-1) == '>' && s.at(i) == '>'){
            num[i] = num[i+1] + 1;
        }
    }
    repp(i,n-1,1){
        if (s.at(i-1) == '<' && s.at(i) == '>'){
            num[i] = max (num[i-1] + 1, num[i+1] + 1);
        }
    }
    ll ans = 0;
    rep(i,n){
        ans += num[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 2820
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int count=0;
    cin >> s;
    
    for (int i=1; i < s.length(); i++) {
        if( s[i] == s[i-1] ) {
            if ( s[i-1] == '1') {
                s[i] = '0';
            } else {
                s[i] = '1';
            }
            count++;
        }
    }
    
    cout << count << endl;
    
}


Measured memory_bytes: 512
from collections import defaultdict
def main():
    H, W, M = map( int, input().split())
    HW = [ tuple( map( int, input().split())) for _ in range(M)]
    R = [0]*H
    C = [0]*W
    d = defaultdict( lambda : False)
    for h, w in HW:
        R[h-1] += 1
        C[w-1] += 1
        d[(h-1,w-1)] = True
    MR = max(R)
    MC = max(C)
    ans = MR+MC-1
    NR = []
    NC = []
    for index, r in enumerate(R):
        if r == MR:
            NR.append(index)
    for index, c in enumerate(C):
        if c == MC:
            NC.append(index)
    # print(NR)
    # print(NC)
    # print(ans,d)
    for r in NR:
        for c in NC:
            if not d[(r,c)]:
                # print(r,c)
                print(ans+1)
                return
    print(ans)
    # 自身を除く
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 126456
from collections import deque
n = int(input())
al = list(map(int,input().split()))

b = deque()

if n % 2 == 0:
    for i in range(n):
        if i % 2 != 0:
            b.appendleft(str(al[i]))
        else:
            b.append(str(al[i]))
else:
    for i in range(n):
        if i % 2 == 0:
            b.appendleft(str(al[i]))
        else:
            b.append(str(al[i]))

print(' '.join(b))

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

namespace abc134_b
{
    static class Program
    {
        static void Main(string[] args)
        {
            var items = Console.ReadLine().ToIntArray();
            var n = items[0];
            var d = items[1];
            var wide = d * 2 + 1;
            Console.WriteLine($"{n / wide + (n % wide == 0 ? 0 : 1)}");
        }

        static int ToInteger(this string s)
        {
            return int.Parse(s);
        }

        static int[] ToIntArray(this string s, char separator = ' ')
        {
            return s.Split(separator).Select(m => m.ToInteger()).ToArray();
        }
    }
}


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

int main() {
	string num;
	int count_num =0,
		count_up=0,
		i=0;

	while (1) {
		cin >> num;
		if (num == "0") {
			break;
		}
		count_num = num.length();
		for (i = 0; i <count_num; i++){
			count_up += num[i] - '0';
		}
		cout << count_up<< endl;
		count_up = 0;
		count_num = 0;
	}
	return 0;
}


Measured memory_bytes: 3156
from itertools import permutations
n,ma, mb = map(int, input().split())
abc = []
inf = float('INF')
hw = 400 + 1
dp = [[inf for i in range(hw)] for j in range(hw)]
dp[0][0] = 0
for _ in range(n):
    a,b,c = map(int, input().split())
    abc.append((a,b,c))

abc.sort(key = lambda x:(-x[0],x[1]))
for a,b,c in abc:
    for i in range(hw-a)[::-1]:
        for j in range(hw-b)[::-1]:
            if dp[i+a][j+b] > dp[i][j] + c:
                dp[i+a][j+b] = dp[i][j] + c

a,b = ma, mb
ans = [dp[a*i][b*i] for i in range(1,hw // max(a,b)) if dp[a*i][b*i] < inf]
print(min(ans) if len(ans) else -1)
# [print(i, f) for i,f in enumerate(dp[200:])]
# print(ans)

Measured memory_bytes: 46940
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cassert>
#include<iomanip>
using namespace std;
typedef pair<double,double> P;
int p,n;
int d[] = {-2,-1,0,1,2};

int main()
{
  while(cin >> p >> n,p|n)
    {
      P a = P(0,1);
      P b = P(1200900,1);
      double np = sqrt(p);
      //cout << "np = " << np << endl;
      for(double v=1;v<=n;v++)
	{
	  /*
	  for(int i=0;i<5;i++)
	    {
	      int ux = np*v+d[i];
	      if(ux > n)continue;
	      if(__gcd(ux,(int)v) != 1)continue;
	      //cout << ux << "/" << v << endl;
	      if(ux/v < np && np-a.first/a.second > np-ux/v)a = P(ux,v);
	      if(ux/v > np && b.first/b.second-np > ux/v-np)b = P(ux,v);
	    }
	  
	  */
	  int l = 0;
	  int r= 110000;
	  int ux;
	  while(l+1 < r)
	    {
	      ux = (l+r)/2.0;
	      if(np < ux/v)r = ux;
	      else         l = ux;
	    }
	 
	  if(ux > n)goto Next;
	  if(__gcd(ux,(int)v) != 1)goto Next;

	  if(ux/v < np && np-a.first/a.second > np-ux/v)
	    a = P(ux,v);
	    
	  if(ux/v > np && b.first/b.second-np > ux/v-np)b = P(ux,v);

	Next:;
	  if(l > n)goto Next2;
	  if(__gcd(l,(int)v) != 1)goto Next2;
	  if(l/v < np && np-a.first/a.second > np-l/v)a = P(l,v);
	  if(l/v > np && b.first/b.second-np > l/v-np)b = P(l,v);

	Next2:;
	  if(r > n)continue;
	  if(__gcd(r,(int)v) != 1)continue;
	  if(r/v < np && np-a.first/a.second > np-r/v)a = P(r,v);
	  if(r/v > np && b.first/b.second-np > r/v-np)b = P(r,v);
	}

  cout << b.first << "/" << b.second << " " << a.first << "/" << a.second << endl;
}
return 0;
}

Measured memory_bytes: 1228
#include<stdio.h>
int main(void)
{
        int a,b;
        scanf("%d%d",&a,&b);
        if((a+b)/2.0==(a+b)/2) printf("%d\n",(a+b)/2);
        else printf("%d\n",(a+b)/2+1);
        return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int f,n;
int main ()
{
cin>>n;
int a[n] ,b[n];

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

Measured memory_bytes: 1536
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

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

#define io ios_base::sync_with_stdio(false)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
#define mod 1000000007
#define pii pair<int, int>
#define PI 2*acos(0.0)

int main()
{
    io;
    int n, k;
    cin>>n>>k;
    unsigned ll sum[n+1], ans = 0;
    sum[0]= 0;
    for(int i = 1; i <= n; i++)
        sum[i] = sum[i-1] + i;
    for(int j = k; j <= n; j++)
        ans += ((sum[n] - sum[n-j] -sum[j-1] + 1)%mod);
    ans = (ans+1)%mod;
    cout << ans;
    return 0;
}

Measured memory_bytes: 5160