akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main()
{
    char mark;
    int n,num,h[13],s[13],d[13],c[13];
    cin >>n;
    for(int i=0;i<13;i++){
        h[i]=1;
        s[i]=1;
        d[i]=1;
        c[i]=1;
    }
    for(int i=0;i<n;i++){
        cin >>mark>>num;
        if(mark=='H')
            h[num-1]=0;
        if(mark=='S')
            s[num-1]=0;
        if(mark=='D')
            d[num-1]=0;
        if(mark=='C')
            c[num-1]=0;
    }
    for(int i=0;i<13;i++)
        if(s[i])
            cout<<"S "<<i+1<<endl;
    for(int i=0;i<13;i++)
        if(h[i])
            cout<<"H "<<i+1<<endl;
    for(int i=0;i<13;i++)
        if(c[i])
            cout<<"C "<<i+1<<endl;
    for(int i=0;i<13;i++)
        if(d[i])
            cout<<"D "<<i+1<<endl;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;

const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int d,g;
	cin >>d >>g;
	vector<ll> p(d), c(d);
	rep(i, d) cin >>p[i] >> c[i];
	rep(i, d) c[i] /=100; g /=100;
	
	int mn = 1<<28;
	rep(i, 1<<d){
		int ct =0, sm = 0, mxj = -1;;
		rep(j, d) {
			if(i>>j &1){
				sm += p[j] *(j+1); sm += c[j];
				ct += p[j];
			}else mxj = j;
		}

		if(mxj>-1 && sm < g && sm + p[mxj] * (mxj+1) >= g){
			int z= (g - sm +mxj) /(mxj+1);
			ct +=z;
			sm += z* (mxj+1);
			
		}
		//dbg(i,mn,ct,sm, g, mxj);
		if(sm >= g) mn = min(ct, mn);
	}
	cout << mn <<"\n";
	return 0;
}


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

int main() {
	string s1, s2;
	cin >> s1 >> s2;

	if (s1.at(0) == s2.at(2) && s1.at(1) == s2.at(1) && s1.at(2) == s2.at(0)) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]

#[allow(unused_macros)]
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

fn main() {
    input!{
        n: usize,
        k: usize,
    }

    println!("{}", if n % k == 0 { 0 } else { 1 });
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
using namespace std;
bool vis[105];
int main()
{

    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        vis[i]=(x==y);
    }
    for(int i=1;i<=n-2;i++)
    {
        if(vis[i]&&vis[i+1]&&vis[i+2])
        {
            puts("Yes");
            return 0;
        }

    }
    puts("No");


    return 0;
}


Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int b;
  scanf("%d", &b);

  printf("%d\n",a[b-1]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
#define all(obj) obj.begin(), obj.end()
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
 
using namespace std;
 
typedef unsigned long long ull;
typedef long long int ll;
constexpr ll bigNum = 1000000007;
 
signed main()
{
    fast;
    //ここから本体
    int n;
    cin >> n;
    vector<string> a(n);
    for (int i = 0; i < n; i++)
    {
        string x;
        cin >> x;
        sort(all(x));
        a[i] = x;
    }
    sort(all(a));
 
    ll ans = 0;
    ll c = 1;
    for (int i = 0; i < n - 1; i++)
    {
        if (a[i] == a[i + 1])
            c++;
        else
        {
            ans += (c * (c - 1)) / 2;
            c = 1;
        }
    }
    ans += (c * (c - 1)) / 2;
    cout << ans << endl;
}

Measured memory_bytes: 5760
// I can't tell you what it really is,
// I can only tell you what it feels like.
#include "bits/stdc++.h"
using namespace std;
 
#define int long long
#define F first
#define S second
#define sz(x) ((int)x.size())
#define rep(i,a,n) for (int i = a; i <= n; ++i)
#define all(v)  v.begin(), v.end()
#define pb push_back
#define P pair < int, int >
#define E cout << '\n'

const int mod = 1e9 + 7;
const int N = 4e5 + 5;

int a[N];
 
inline void solve() {
   string a, b;
   int ans(0);
    cin >> a >> b;
    // cout << a << ' ' << b << '\n';
   rep(i,0,2)
    ans += a[i] == b[i];
    cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  //cin >> t; while(t--)
  solve();
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
from heapq import heappush, heappop
import math
import bisect
import random

def LI(): return list(map(int, input().split()))
def I(): return int(input())
def LIM(): return list(map(lambda x:int(x) - 1, input().split()))
def LS(): return input().split()
def S(): return input()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007



def main():
    n = I()
    n_list =  sorted(LI())
    ans = float('inf')
    for i in range(n_list[0], n_list[-1] + 1):
        ret = 0
        for j in n_list:
            ret += (i - j) ** 2
        ans = min(ans, ret)


    return ans








print(main())

Measured memory_bytes: 40688
#include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, (b), sizeof(a))
#define fore(i,a) for(int i=0;i<a;i++)
#define fore1(i,j,a) for(int i=j;i<a;i++)
#define print(ar) for(int i=0;i<ar.size();i++)cout<<ar[i]<<" ";
#define END cout<<'\n'
const double pi=acos(-1.0);
 
typedef pair<int, int> PII;
 
typedef vector<long long> VI;
 
typedef vector<string> VS;
 
typedef vector<PII> VII;
 
typedef vector<VI> VVI;
 
typedef map<int,int> MPII;
 
typedef set<int> SETI;
 
typedef multiset<int> MSETI;
 
typedef long int li;
 
typedef unsigned long int uli;
 
typedef long long int ll;
 
typedef unsigned long long int  ull;
ll fastexp (ll a, ll b, ll n) {
  ll res = 1;
  while (b) {
      if (b & 1) res = res*a%n;
      a = a*a%n;
      b >>= 1;
  }
  return res;
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
//VI vect[2020202];
int main()
 {  fast();
	int t, n, k;

	    cin >> n;
	 fore1(i,-200,201){
       fore1(j,-200,201){
         if(pow(i,5)-pow(j,5)==n)
         {cout<<i<<" "<<j<<endl;i=565,j=565;}}}}
	  
	


Measured memory_bytes: 4068
#include<cstdio>
using namespace std;
int n,m,x;
inline int rd()
{
	char tmp=getchar();
	int ddd=0;
	while('0'>tmp&&tmp<'9')
	{
		tmp=getchar();
	}
	while('0'<=tmp&&tmp<='9')
	{
		ddd=(ddd<<3)+(ddd<<1)+(tmp^48);
		tmp=getchar();
	}
	return ddd;
}
int main()
{
	n=rd();
	m=rd();
	x=(m<<1)+1;
	printf("%d",n%x==0?n/x:n/x+1);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n, m;
unordered_map<int, bool> um;
vector<int> v[100001];
vector<int> ansf;
vector<int> ansr;
void dfsr(int node)
{
    // search rear hamiltonish path
    for (auto i : v[node])
    {
        if (um[i])
            continue;
        um[i] = true;
        ansr.push_back(i);
        dfsr(i);
        return;
    }
}
void dfsf(int node)
{
    //search front hamiltonish path
    for (auto i : v[node])
    {
        if (um[i])
            continue;
        um[i] = true;
        ansf.push_back(i);
        dfsf(i);
        return;
    }
}
int main()
{
    cin >> n >> m;
    rep(i, m)
    {
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    // check node 1
    // if the dimension is less than 1
    ansf.push_back(1);
    um[1] = true;
    dfsr(1);
    dfsf(1);
    reverse(ansf.begin(), ansf.end());
    cout << ansf.size() + ansr.size() << endl;
    for (auto i : ansf)
    {
        cout << i << ' ';
    }
    for (auto i : ansr)
    {
        cout << i << ' ';
    }
    cout << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<string> V(N);
  for (int i = 0; i < N; i++)
    cin >> V.at(i);
  sort(V.begin(),V.end());
  
  int count = 1;
  for (int j = 1; j < N; j++) {
    if (V.at(j) != V.at(j - 1))
      count++;
  }
  
  cout << count << endl;

     
}


Measured memory_bytes: 9420
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    a--, b--, c--, d--;
    string s;
    cin >> s;

    bool ok = true;
    for(int i=a;i<c;i++){
        if(s[i] == '#' && s[i+1] == '#'){
            ok = false;
        }
    }
    for(int i=b;i<d;i++){
        if(s[i] == '#' && s[i+1] == '#')
            ok = false;
    }

    if(c < d){
        cout << (ok ? "Yes" : "No") << endl;
    }
    else {
        bool ok2 = false;
        for(int i=b-1;i<d;i++){
            if(s[i] == '.' && s[i+1] == '.' && s[i+2] == '.')
                ok2 = true;
        }
        cout << (ok && ok2 ? "Yes" : "No") << endl;
    }

    

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    int N,K; cin >> N >> K;
    int res = 1;
    for (int i = 0; i < N; ++i) {
        res = (res * 2 < res + K) ? res * 2 : res + K;
    }
    cout << res << endl;
}

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

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

  int ans = A*C >= B ? B/A : C;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
inline int rd(){
	char c=getchar();int x=0,flag=1;
	for(;c<'0'||c>'9';c=getchar())if(c=='-')flag=-1;
	for(;c>='0'&&c<='9';c=getchar())x=x*10+c-'0';
	return x*flag;
}
struct node{
	ll x;int id;
	friend bool operator < (node a,node b){
		return a.x<b.x;
	}
}p[200010];
int n,k,a[200010],st[200010]={0};
inline void update(int x){
	for(;x<=n+1;x+=x&-x)
		st[x]++;
	return;
}
inline int ask(int x){
	int res=0;
	for(;x;x-=x&-x)
		res+=st[x];
	return res;
}
int main(){
	ll sum=0;n=rd();k=rd();
	for(int i=1;i<=n;i++)
		a[i]=rd()-k;
	for(int i=1;i<=n;i++)
		p[i]=(node){sum+=a[i],i};
	p[0]=(node){0,0};
	sort(p,p+n+1);
	a[p[0].id]=1;
	for(int i=1;i<=n;i++)
		a[p[i].id]=a[p[i-1].id]+(p[i].x!=p[i-1].x);
	ll ans=0;update(a[0]);
	for(int i=1;i<=n;i++){
		ans+=ask(a[i]);
		update(a[i]);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4864
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

#define fo(i, a, b) for(int i = a; i <= b; i++)
#define _fo(i, a, b) for(int i = a; i >= b; i--)
#define foa(i, a) for (auto &i : a)
#define sz(a) ((int) a.size())
#define all(a) begin(a), end(a)
#define fi first
#define se second
#define pb(x) push_back(x)

typedef int64_t ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int MAX = 2e5+5;
const int MOD = 1e9+7;
const ll INF = INT_MAX;
const ll _INF = INT_MIN;

ll add(ll a, ll b) { return (a+b) % MOD; }
ll mul(ll a, ll b) { return (a*b) % MOD; }

int n, k;
int fac[MAX], infac[MAX];  

int inv(int val) {
	int curr = 1, temp = MOD-2;
	
	while(temp > 0) {
		if(temp & 1) curr = mul(curr, val);
		val = mul(val, val);
		temp >>= 1;
	}
	
	return curr;
}

void precompute() {
	fac[0] = 1;
	fo(i, 1, n) fac[i] = mul(i, fac[i-1]);
	infac[n] = inv(fac[n]);
	_fo(i, n-1, 0) infac[i] = mul(i+1, infac[i+1]);
}

ll nCr(int a, int b) {
	return mul(mul(fac[a], infac[a-b]), infac[b]);   
}

int solve() {
	int valid = min(n-1, k), ans = 0;
	
	fo(i, 1, valid) ans = add(ans, mul(nCr(n, i), nCr(n-1, i)));
	ans = add(ans, 1);
	
	return ans;
}

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin >> n >> k;
	precompute();
	cout << solve();
}

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

int main() {
  int n, k;
  cin >> n >> k;

  int ans = 1;
  for (int i = 0; i < n; i ++) {
    if (ans * 2 >= ans + k) {
      ans += k;
    } else {
      ans *= 2;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
a = []
while True:
  H, W = list(map(int, input().split(' ')))
  if H == 0 and W == 0:
    break
  a.append([H, W])
for l in a:
  for h in range(l[0]):
    for w in range(l[1]):
      if (w == 0 or w == l[1] - 1) or (h == 0 or h == l[0] - 1):
        print('#', end='')
      else:
        print('.', end='')
    print('', sep="\n")
  print('', sep="\n")


Measured memory_bytes: 7016
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i =0;i<n;i++)
typedef long long int ll;
#define ALL(a) a.begin(),a.end()
int main() {
  string s,t;cin >> s >>t;int cnt = 0,ans = 1e9;
  rep(i,s.size()){
    if(i+t.size() > s.size())continue;
    cnt = 0;
    rep(j,t.size()){
      if(s[i+j] != t[j])cnt++;
    }ans = min(ans,cnt);
  }cout << ans << endl;
}

Measured memory_bytes: 3632
from bisect import bisect_right

N = int(input())
A = [int(input()) for _ in range(N)]

t = [-A[0]]
for a in A[1:]:
    if a <= -t[-1]:
        t.append(-a)
    else:
        t[bisect_right(t, -a)] = -a
print(len(t))


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

namespace Structured_Program_I
{
    class Print_a_Frame
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var token = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                var H = token[0];
                var W = token[1];

                if (H == 0 && W == 0) break;

                for (int i = 0; i < H; i++)
                {
                    for (int j = 0; j < W; j++)
                    {
                        if (i == 0 || i == H - 1 || j == 0 || j == W - 1) Console.Write("#");
                        else Console.Write(".");
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
        }
    }
}

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

typedef long long ll;
typedef pair<ll, char> llc;
typedef vector<llc> vllc;

bool sortDeliciousness(llc a, llc b){
	return a.first > b.first;
}

int main() {FIN
	
	ll x, y, a, b, c, i, j = 0, d, as, bs, cs;
	cin >> x >> y >> a >> b >> c;
	vllc ds(a + b + c);
	for (i = 0; i < a; i++) {
		cin >> d;
		ds[j++] = llc(d, 'r');
	}
	for (i = 0; i < b; i++) {
		cin >> d;
		ds[j++] = llc(d, 'g');
	}
	for (i = 0; i < c; i++) {
		cin >> d;
		ds[j++] = llc(d, 'c');
	}
	
	sort(ds.begin(), ds.end(), sortDeliciousness);
	d = 0; as = 0; bs = 0; cs = 0;
	j = 0;
	while (as + bs + cs < x + y) {
		llc ap = ds[j++];
		if (ap.second == 'r') {
			if (as < x) {
				d += ap.first;
				as++;
			}
		} else if (ap.second == 'g') {
			if (bs < y) {
				d += ap.first;
				bs++;
			}
		} else {
			d += ap.first;
			cs++;
		}
	}
	
	cout << d << "\n";
	
	return 0;
}


Measured memory_bytes: 4992
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

total = 0
for i in range(N):
    yusha_life = Bs[N-1-i]
    yusha_life -= As[N-i]
    if yusha_life <= 0:
        total += Bs[N-1-i]
        As[N-i] -= Bs[N-1-i]
    else:
        total += As[N-i]
        total += min(yusha_life, As[N-i-1])
        As[N-i-1] = 0 if As[N-i-1] <= yusha_life else As[N-i-1] - yusha_life

print(total)


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

int main(){
  long long int A, B, K;
  cin >> A >> B >> K;
  if (A-K<0) {
    cout << 0 << " " << ((B+A-K<0)?0:B+A-K) << "\n";
  } else {
    cout << A-K << " " << B << "\n";
  }
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc107_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] nums = Console.ReadLine().Split(' ');
            int n = int.Parse(nums[0]);
            int i = int.Parse(nums[1]);

            Console.WriteLine(n + 1 - i);
        }
    }
}


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


int main() {
  int n, m;
  cin >> n >> m;
  
  if (m * 2 >= n) cout << 0 << endl;
  else cout << n - m * 2 << endl;
}

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

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

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

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

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

    vector<vector<ll> >item(N,vector<ll>(2));
    rep(i, N) cin >> item[i][0] >> item[i][1];

    vector<vector<ll> >dp(N+1, vector<ll>(W+1, 0));

    rep(i,N)
    {
        rep(j,W+1)
        {
            if( j >= item[i][0] ) dp[i+1][j] = max(dp[i][j], dp[i][j - item[i][0]] + item[i][1]);
            else dp[i+1][j] = dp[i][j];
        }
    }
    /*
    rep(i,dp.size())
    {
        rep(j, dp[0].size()) cout << dp[i][j] << " ";
        cout << endl;
    }
    */
    cout << dp[N][W] << endl;



}


Measured memory_bytes: 80256
k, a, b = map(int,input().split())

if b-a <= 2:
    print(k+1)
else:
    ans = a
    k -= a-1
    if k%2 == 0:
        ans += (b-a)*(k//2)
    else:
        ans += (b-a)*(k//2)
        ans += 1
    print(ans)

Measured memory_bytes: 9180
"use strict";

// よそからもらってきたコード
function existsSameValue(a){
  let s = new Set(a);
  return s.size != a.length;
}

function Main(input) {
  let N = input.trim().split("\n")[0];
  let Nums = input.trim().split("\n")[1].split(" ").map(x=> x*1);
  let isDouble = existsSameValue(Nums);
  let ans = "YES";
  if(isDouble){
  	ans = "NO"
  }
  
  console.log(`${ans}`);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 44160
/*我是萌新*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip> 
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
ll gcd(ll a, ll b){
    return b?gcd(b,a%b):a;
}
ll lcm(ll a, ll b){
    return a/gcd(a,b)*b;
}
bool cmp(int x, int y)
{
    return x > y;
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll n,k;
    while (cin >> n>>k)
    {
        ll a=n%k;
        ll b=a-k;
        if(b<0)b=-1*b;
        cout<<min(a,b)<<'\n';
    }
}



Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>

#define fr first
#define sc second
#define mk make_pair

using namespace std;

int x, ans = 0, i;

int main()
{
    cin >> x;
    for(i = 1; i <= 1e9; i++)
    {
        if(x <= 0)
            break;
        x = x - i;
        ans++;
    }

    cout << i - 1;
    return 0;
}


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

string S;
int x, y;
bool dpx[8001][16010] = {{0}};
bool dpy[8001][16010] = {{0}};

int main(void){
    
    cin >> S;
	scanf("%d %d", &x, &y);
	x += 8000, y += 8000;
	
	vector<int> vx, vy;
	int cnt = 0, sum = 0;
	for(int i = 0; i < S.size(); ++i){
	    if(S[i] == 'T'){
	        ++cnt;
	        if(sum == 0) continue;
	        (cnt % 2 == 1) ? vx.push_back(sum) : vy.push_back(sum);
	        sum = 0;
	    }
	    else ++sum;
	}
	(cnt % 2 == 0) ? vx.push_back(sum) : vy.push_back(sum);
	
	sum = accumulate(vx.begin(), vx.end(), 0);
	int xmx = 8000 + sum, xmn = 8000 - sum;
	sum = accumulate(vy.begin(), vy.end(), 0);
	int ymx = 8000 + sum, ymn = 8000 - sum;
	
	for(int i = 0; i < vx.size(); ++i){
	    if(i){
	        for(int j = xmn; j <= xmx; ++j){
	            if(dpx[i - 1][j]) dpx[i][j - vx[i]] = true;
	            if(dpx[i - 1][j]) dpx[i][j + vx[i]] = true;
	        } 
	    }
	    else dpx[0][8000 + vx[i]] = (S.front() == 'T') ? dpx[0][8000 - vx[i]] = true : true;
	}
	
	for(int i = 0; i < vy.size(); ++i){
	    if(i){
	        for(int j = ymn; j <= ymx; ++j){
	            if(dpy[i - 1][j]) dpy[i][j - vy[i]] = true;
	            if(dpy[i - 1][j]) dpy[i][j + vy[i]] = true;
	        } 
	    }
	    else dpy[0][8000 + vy[i]] = dpy[0][8000 - vy[i]] = true;
	}
	dpx[0][8000] = dpy[0][8000] = true;
	
	int a = (vx.size()) ? vx.size() - 1 : 0, b = (vy.size()) ? vy.size() - 1 : 0;
	if(dpx[a][x] && dpy[b][y]) printf("Yes\n");
	else printf("No\n");
	
    return 0;
}


Measured memory_bytes: 64256
#include <iostream>
#include<bits/stdc++.h> 
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin >> s;
    
    if(s == "hi" || s == "hihi" ||  s == "hihihi" || s == "hihihihi" || s == "hihihihihi")
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
}


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

bool cmp(string a, string b) {
	return a + b < b + a;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int L; cin >> L;
	string s, t; cin >> s >> t;
	if (cmp(t, s)) swap(s, t);

	int S = s.size(), T = t.size();
	for (int i = L / S; i >= 0; --i) {
		int j = (L - S * i);
		if (j % T) continue;
		j /= T;
		string ans = "";
		while(i--) ans += s;
		while(j--) ans += t;
		cout << ans << endl;
		return 0;
	}
}

Measured memory_bytes: 1684
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i,a,n) for(ll i=a;i<n;i++)
#define w(_t) ll _t;cin>>_t;while(_t--)
ll arr[3000][3000];
ll dp[3000][3000][4];
ll rec(ll i,ll j,ll r,ll c,ll nr){
    
    if(i==r && j==c) return nr<3?arr[i][j]:0;
    if(i>r || j>c) return -1;
    //cout<<i<<" "<<j<<" "<<nr<<" "<<dp[i][j][nr]<<endl;
    if(dp[i][j][nr]!=-1) return dp[i][j][nr];
    
    if(nr==3) dp[i][j][nr]= max(rec(i+1,j,r,c,0),rec(i,j+1,r,c,nr));
    else dp[i][j][nr]= max(arr[i][j]+rec(i+1,j,r,c,0),max(arr[i][j]+rec(i,j+1,r,c,nr+1),rec(i,j+1,r,c,nr)));
    return dp[i][j][nr];
}



int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    ll r,c,k,u,v,x;cin>>r>>c>>k;
    f(i,0,r) f(j,0,c) arr[i][j]=0;
    f(i,0,r) f(j,0,c) f(k,0,4) dp[i][j][k]=-1;
    f(i,0,k){
        cin>>u>>v>>x;
        arr[u-1][v-1]=x;
    }
    cout<<rec(0,0,r-1,c-1,0);
    return 0;
}

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

int main(){
	string s;
	int ans = 0;
	cin >> s;
	for(int i=0; i<s.length()/2; i++){
		if(s[i] != s[s.length()-1-i]){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def merge(A, left, mid, right):
    n1 = mid-left
    n2 = right-mid
    L = [0]*(n1+1)
    R = [0]*(n2+1)
    for i in range(n1):
        L[i] = A[left+i]
    for i in range(n2):
        R[i] = A[mid+i]
    L[n1] = R[n2] = sys.maxint
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

def mergeSort(A, left, right):
    if left+1 < right:
        mid = (left+right)/2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)

M = [int(raw_input()) for i in range(10)]
mergeSort(M, 0, len(M))
for i in range(1, 4):
    print M[len(M)-i]

Measured memory_bytes: 6476
#include<stdio.h>

int main(){
   int a,b;
    
    do{
     scanf("%d",&a);
    
    }while(a>1000||a<-1000);
    
    do{
    
     scanf("%d",&b);

    }while(b>1000||b<-1000);


    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: 580
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		while(true){
			int n = stdIn.nextInt();
			if(n==0){
				return;
			}
			else if(n==1){
				System.out.println("1 1");
				continue;
			}
			
			int a[][] = new int[n][2];
			a[0][0] = 0;
			a[0][1] = 0;
			int minx=0, miny=0, maxx=0, maxy=0;
			for(int i=1;i<n;i++){
				int m = stdIn.nextInt();
				int d = stdIn.nextInt();
				a[i][0] = a[m][0];
				a[i][1] = a[m][1];
				if(d==0){
					a[i][0]--;
					if(a[i][0]<minx){
						minx = a[i][0];
					}
				}
				else if(d==1){
					a[i][1]--;
					if(a[i][1]<miny){
						miny = a[i][1];
					}
				}
				else if(d==2){
					a[i][0]++;
					if(a[i][0]>maxx){
						maxx = a[i][0];
					}
				}
				else if(d==3){
					a[i][1]++;
					if(a[i][1]>maxy){
						maxy = a[i][1];
					}
				}
			}
			System.out.println((maxx-minx+1)+" "+(maxy-miny+1));
		}
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>
 
#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin4(X,Y,Z,W) scanf("%d %d %d %d",&X,&Y,&Z,&W)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)
#define ll_cin(X) scanf("%lld", &X)
 
#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)
 
typedef long long  ll;
#define rept(x, s, n) for (int x = s; x < n; x++)
 
#define S_RTN(S)  s_cout(S);return 0
 
 
#define _itoa(A,N) sprintf(A, "%d", N);
 
int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);
 
int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);
 
 
int s_asorts(const void* a, const void* b);
 
//昇順
int s_asorts(const void* a, const void* b) {
    return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
    return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
    return(*(int*)a - *(int*)b);
}
int l_cins2(int n, long* a, long* b) {
    int i;
    rept(i, 0, n) {
        l_cin2(*(a + i), *(b + i));
    }
    return 0;
}
int i_cins(int n, int* a) {
    int i;
    for (i = 0; i < n; i++) {
        i_cin(*(a + i));
    }
 
    return 0;
}
int _gcd(int a, int b) {
    int r, tmp;
    if (a < b) { tmp = a; a = b; b = tmp; }
    r = a % b;
    while (r) {
        if (!r) break;
        a = b; b = r;
        r = a % b;
    }
    return(b);
}
 
long _max(long a, long b) {
    return a > b ? a : b;
}
long _min(long a, long b) {
    return a < b ? a : b;
}
int _swp(int* a, int* b)
{
    int tmp;
    tmp = *b; *b = *a; *a = tmp;
    return 0;
}

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}


int main(){
    char a[100];
    char b[100];
    int i=0;
    scanf("%s",a);
    scanf("%s",b);
    while(a[i]!=0){
        if(a[i]!=b[i]){
            printf("No");
            return 0;
        }
        i++;
    }
    printf("Yes");
}


Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int p[200005];
int main()
{
	ll k,n,cnt=0,sum=0,st,en,maxx=-1;
	double ans;
	ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin >> n >> k;
	for(int i=0;i<n;i++) {
		cin >> p[i];
		sum+=p[i];
		cnt++;
		if(cnt==k){
			if(sum>maxx){
				st=i-k+1;
				en=i;
				maxx=sum;
			}
			sum-=p[i-k+1];
			cnt--;
		}
	}
	printf("%.6lf\n",double(1.0*(maxx+k)/2));
	return 0;
} 

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

using namespace std;

#define ll long long

int main()
{
	int n;
	int x, y;
	
	cin >> n;

	x = 800 * n;
	y = 200 * (n / 15);

	cout << x - y << endl;

	return (0);
}

Measured memory_bytes: 256
N = int(input())
a = [int(i) for i in input().split()]
b = list(set(a))
flag = False
if len(b) == 3:
    if b[0]^b[1] == b[2] and N % 3 == 0 and a.count(b[0]) == a.count(b[1]) and a.count(b[1]) == a.count(b[2]):
        flag = True
elif len(b) == 2:
    if b[0]^b[0] == b[1]:
        if N % 3 == 0 and a.count(b[0]) == a.count(b[1]) * 2:
            flag = True
    if b[1]^b[1] == b[0]:
        if N % 3 == 0 and a.count(b[1]) == a.count(b[0]) * 2:
            flag = True
elif len(b) == 1:
    if b[0] == 0:
        flag = True
if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14708
#include<bits/stdc++.h>
using namespace std;
int a[10000006];
int main()
{
    long long n,i,cnt=0,sum=0;
    cin>>n;
    for( i=1;i<=n;i++)
    {
        if(i%3==0 or i%5==0)
        {
            continue;
        }
        else
        {
            sum+=i;
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define PI 3.141592653589
#define ll long long
using namespace std;

int main(){
  int n, l;
  cin >> n >> l;

  vector<int> a(n);
  int sum = 0;
  int cp_l = l;
  int mn = 101, mx = -101;
  bool flag = false;

  for(int i=0; i<n; ++i){
    if(cp_l==0) flag =true;
    a[i] = cp_l;
    sum += a[i];
    mn = min(mn, a[i]);
    mx = max(mx, a[i]);
    ++cp_l;
  }

  if(flag){
    cout << sum;
    return 0;
  }
  
  if(sum>=0) cout << sum -mn;
  else cout << sum - mx;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100000
#define NIL -1
typedef struct{
  int p,l,r;
}Node;

int depth(int, int);
void print(int);

Node T[MAX];
int n,D[MAX];

int main(){
  int i,j,d,v,c,l,r;

  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",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0)
	T[v].l=c;
      else
	T[l].r=c;
      l=c;
      T[c].p=v;   
    }
  }

  for(i=0;i<n;i++){
    if(T[i].p==NIL)
      r=i;
  }

  depth(r,0);

  for(i=0;i<n;i++)
    print(i);

  return 0;
}

int depth(int u, int p){
  D[u]=p;

  if(T[u].r!=NIL)
    depth(T[u].r,p);
  if(T[u].l!=NIL)
    depth(T[u].l,p+1);
}

void print(int u){
  int i,c;

  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);

  if(T[u].p==NIL)
    printf("root, ");
  else if(T[u].l==NIL)
    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");
}

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

int main()
{
    int N, M;
    int a[8*(8-1)/2];
    int b[8*(8-1)/2];
    int i, j;

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

    // 1起点を調べるため、2～N
    vector<int> order(N-1);
    for(i = 0; i < (N-1); i++) {
        order[i] = i + 2;
    }

    int count = 0;
    do {
        int current = 1;
        for(i = 0; i < (N-1); i++) {
            for(j = 0; j < M; j++) {
                if((a[j] == current && b[j] == order[i]) ||
                   (a[j] == order[i] && b[j] == current)) {
                    current = order[i];
                    break;
                }
            }
            if(j == M) {
                break;
            }
        }
        if(i == (N-1)) {
            count += 1;
        }
    } while(next_permutation(order.begin(), order.end()));
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>

using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
int power(int a,int b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
}


int32_t main()
{
    IOS
    
    
        
        string s,s1;
        cin>>s>>s1;
        cout<<(s[0]==s1[0])+(s[1]==s1[1])+(s[2]==s1[2]);

}

Measured memory_bytes: 256
--[[ https://www.slideshare.net/iwiwi/ss-3578491 3~18of73 ]]--

--半分の実装のみ(これでも十分早いらしい)
local UFT = {}

---要素数nでpar[]を初期化
function UFT.new(n)
	local obj = {par = {}}
	for i = 1, n do
		obj.par[i] = i
	end
	return setmetatable(obj,{__index = UFT})
end

---木の根を求める
function UFT:find(x)
	if self.par[x] == x then
		-- 根
		return x
	else
		-- 経路圧縮
		self.par[x] = self:find(self.par[x])
		return self.par[x]
	end
end

---xとyが同じ集合に属するか否か
function UFT:same(x, y)
	return self:find(x) == self:find(y)
end

---xとyの属する集合を併合
function UFT:union(x, y)
	x = self:find(x)
	y = self:find(y)
	if x == y then
		return
	end

	self.par[x] = y
end

--[[ I referred until here. ]]--
local max = math.max
local min = math.min

local read = io.read

local n, m = read("n", "n")
local uft = UFT.new(n)
for i = 1, m do
	local a_i, b_i = read("n", "n")
	uft:union(a_i, b_i)
end

local is_finded_num_t = {}
for i = 1, n do
	local par_num = uft:find(i)
	if is_finded_num_t[par_num] then
		is_finded_num_t[par_num] = is_finded_num_t[par_num] + 1
	else
		is_finded_num_t[par_num] = 1
	end
end

local uft_par_max = -1
for i = 1, n do
	if is_finded_num_t[i] then
		uft_par_max = max(uft_par_max, is_finded_num_t[i])
	end
end

print(uft_par_max)


Measured memory_bytes: 37468
h, n = map(int, input().split())
inf = 10**10
dp = [[inf for i in range(h+1)] for j in range(n+1)]
#dp[i][j] := i番目の魔法まで考えたとき、hpをh減らす最小コスト
dp[0][0] = 0
for i in range(1,n+1):
    damage, cost = map(int, input().split())
    for j in range(h+1):
        if j - damage < 0:
            dp[i][j] = min(cost, dp[i][j], dp[i-1][j])
        else:
            dp[i][j] = min(dp[i][j - damage] + cost, dp[i-1][j])
print(dp[-1][h])

Measured memory_bytes: 125564
#include <stdio.h>

int main(){
  int N,X,T;
  scanf("%d %d %d",&N,&X,&T);
  
  int C=0;
  while(N>0){
    N=N-X;
    C=C+1;
  }
  
  printf("%d\n",C*T);
  return 0;
}

Measured memory_bytes: 1732
s=input()
l=len(s);mod=10**9+7
dp=[[0]*13 for i in range(l)]
rem=[1,10,9,12,3,4]
for i in range(l)[::-1]:
  dig=(l-i-1)%6
  if s[i]=="?":
    if i==l-1:
      for j in range(10):
        dp[-1][(j*rem[dig])%13]=1
    else:
      for j in range(10):
        for h in range(13):
          dp[i][(h+j*rem[dig])%13]+=dp[i+1][h]
          dp[i][(h+j*rem[dig])%13]%=mod
  else:
    a=int(s[i])
    if i==l-1:
      dp[i][(a*rem[dig])%13]=1
    else:
      for j in range(13):
        dp[i][(j+a*rem[dig])%13]+=dp[i+1][j]
        dp[i][(j+a*rem[dig])%13]%=mod
print(dp[0][5])


Measured memory_bytes: 62300
#include <bits/stdc++.h>
using namespace std;
#define PI 3.1415926535
const long long int MOD = 998244353;
#define pb push_back
#define mp make_pair
#define fill(a)  memset(a, 0, sizeof (a))
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define watch(x) cout << (#x) << " is " << (x) << endl;
const long long int MAXX = 2e5+5;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector< iii > viii;

ll lcm(ll a, ll b) {
   return a / __gcd(a, b) * b;
}
int XOR(int x, int y){
  return (x | y) & (~x | ~y);
}
bool cmp(const pair<int,int> &a,const pair<int,int> &b) {
    return (a.second < b.second);
}
// bool isl = binary_search(x.begin(), x.end(), 5);
// __builtin_popcount(x)  - Returns the number of set bits in x
const long long int N = 1e7;
int binsearch(int lo, int hi){
    while(lo<hi){
        int mid=(lo+hi)/2;
        if((mid))   // check(mid)
            hi=mid;
        else
            lo=mid+1;
    }
    return lo;
}
int power(int x,int y){
    int res=1;
    while(y>0){
      if(y&1) res=((res*x));

      y/=2;
      x=((x*x));
    }
    return res;
}
ll a[100];
int main(){
    FAST  
    ll n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    ll buy=1,j=0;
    ll cur=1000,stocks=0;
    for(int i=1;i<=n;){
        j=i;
        if(buy){
            while(j<=n && a[j]>=a[j+1]){
                j++;
            }
            if(j>n) break;
            stocks+= (cur/a[j]);
            cur-= (cur/a[j])*a[j];
            i=j+1;
            buy=0;
        }
        else{
            while(j<=n && a[j]<=a[j+1]){
                j++;
            }
            if(j>n) break;
            cur+= (stocks)*a[j];
            stocks=0;
            i=j+1;
            buy=1;
        }
    }
    cout<<cur;
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(),(a).end()

using namespace std;

int main(int argc, char const *argv[]) {
  ll Q,H,S,D,N;
  scanf("%lld%lld%lld%lld%lld",&Q,&H,&S,&D,&N);
  if(Q*4<S){
    S=Q*4;
  }
  if(H*2<S){
    S=H*2;
  }
  if(S*2<D){
    D=S*2;
  }
  if(N%2==0){
    printf("%lld\n",D*(N/2));
  }else{
    printf("%lld\n",(D*((N-1)/2))+S);
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define repm(i, m, n) for (int i = (m); i < (n); i++)
#define rep_rev(i, n) for (int i = int (n); i >= 0; i--)
typedef long long ll;
using namespace std;

int main() {
	int n, d[100];
	cin >> n;
	rep(i, n)cin >> d[i];

	int sum = 0;
	rep(i, n)for (int j = i + 1; j < n; j++) {
		sum += d[i] * d[j];
	}
	cout << sum << endl;

	return 0;
}

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

#define vi vector<int>
#define pb push_back
#define ll long long
#define qi queue<int>
#define vll vector<long long>
#define si set<int>
#define mi map<int,int>
#define mod %
#define frt(i,a,b) for(int i=a;i<b;i++)
#define fre(i,a,b) for(int i=a;i<=b;i++)
#define pair_int pair<int,int>
#define pair_ll pair<ll,ll>
#define pq priority_queue
#define N 100007



int main()
{
   string s,t;
   cin >> s >> t;
   int n = s.length();
   int m = t.length();

   int dp[n+1][m+1];
   
   char ex[n+1][m+1];
   int x[n+1][m+1];
   int y[n+1][m+1];

   

   fre(i,0,n)
   {
   	  fre(j,0,m)
   	  {
   	  	 if(i==0 || j==0) 
   	  	 {
   	  	 	dp[i][j]=0;
   	  	 	
   	  	 }

   	  	 else if(s[i-1]==t[j-1])
   	  	 {
   	  	 	dp[i][j] = dp[i-1][j-1]+1;
   	  	 	x[i][j] = i-1;
   	  	 	y[i][j] = j-1;
   	  	 	ex[i][j] = s[i-1];
   	  	 }
   	  	 	

   	  	 else
   	  	 {
   	  	 	if(dp[i-1][j] >= dp[i][j-1] && dp[i-1][j] >= dp[i-1][j-1])
   	  	 	{
   	  	 		dp[i][j] = dp[i-1][j];
   	  	 		x[i][j] = i-1;
   	  	 		y[i][j] = j;
   	  	 		ex[i][j] = '.';
   	  	 		
   	  	 	}
   	  	 	else if(dp[i-1][j-1] >= dp[i][j-1] && dp[i-1][j-1] >= dp[i-1][j])
   	  	 	{
   	  	 		dp[i][j] = dp[i-1][j-1];
   	  	 		x[i][j] = i-1;
   	  	 		y[i][j] = j-1;
   	  	 		ex[i][j] = '.';
   	  	 	}
   	  	 	else
   	  	 	{
   	  	 		dp[i][j] = dp[i][j-1];
   	  	 		x[i][j] = i;
   	  	 		y[i][j] = j-1;
   	  	 		ex[i][j] = '.';	
   	  	 	}
   	  	 } 	 	
   	  }
   }

   int p = n;
   int q = m;
   int p1,q1;
   string str = ".";

   while(p>0 && q>0)
   {
   		if(ex[p][q]!='.')
   			str = str + ex[p][q];

   		p1 = x[p][q];
   		q1 = y[p][q];
   		p = p1;
   		q = q1;
   }

   // rev(str.begin(), str.end());
   str = str.substr(1,str.length()-1);
   reverse(str.begin(), str.end());
   cout << str << endl;
   // cout << ans << endl;
   return 0;

}

  


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

const int MOD = (int)1e9+7;

int main(){
	int N,M;
	cin >> N >> M;
	vector<int> L(M),R(M);
	for(int i=0;i<M;i++)	cin >> L.at(i) >> R.at(i);

	int l=1,r=N;
	for(int i=0;i<M;i++){
		l=max(l,L.at(i));
		r=min(r,R.at(i));
	}
	if(l>r)	cout << 0 << endl;
	else	cout << r-l+1 << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <cstdio>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)

const int MAX_D = 130;

struct Integer{
    Integer(int i = 0){
        memset(digits, 0, sizeof(digits));
        n = 0;

        while(i > 0){
            digits[n++] = i % 10;
            i /= 10;
        }
    }
    Integer(const std::string& s){
        memset(digits, 0, sizeof(digits));
        n = 0;

        bool f = false;
        for(int j=(int)s.size()-1;j>=0;j--){
            if(!std::isdigit(s[j])){continue;}

            if(s[j] != '0'){
                digits[n++] = s[j] - '0';
                f = true;
            }else if(f){
                digits[n++] = s[j] - '0';
            }
        }
    }
    int digits[MAX_D], n;
};

Integer operator*(const Integer& lhs, const Integer& rhs){
    Integer res;
    for(int i=0;i<MAX_D;i++){
        for(int j=0;j<MAX_D;j++){
            if(i + j >= MAX_D){continue;}
            int x = lhs.digits[i] * rhs.digits[j] + res.digits[i+j];
            res.digits[i+j] = x % 10;
            if(i + j + 1 < MAX_D){
                res.digits[i+j+1] += x / 10;
            }
        }
    }

    return res;
}

Integer operator+(const Integer& lhs, const Integer& rhs){
    Integer res;
    for(int i=0;i<MAX_D;i++){
        int x = lhs.digits[i] + rhs.digits[i] + res.digits[i];
        res.digits[i] = x % 10;
        if(i+1 < MAX_D){
            res.digits[i+1] = x / 10;
        }
    }

    return res;
}

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

    Integer x(100000), k1(105), k2(1000);
    REP(i, N){
        x = x * k1;
        
        FOR(j, 2, MAX_D){
            x.digits[j-2] = x.digits[j];
        }

        if(x.digits[0] || x.digits[1] || x.digits[2]){
            REP(i, 3){x.digits[i] = 0;}
            x = x + k2;
        }
    }

    bool f = false;
    for(int i=MAX_D-1;i>=0;i--){
        if(x.digits[i] != 0){
            f = true;
        }

        if(f){
            printf("%d", x.digits[i]);
        }
    }
    puts("");
}

Measured memory_bytes: 1148
#include <iostream>

using namespace std;

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    int sum = max({a,b,c}) * 3;
    if (sum%2 != (a+b+c)%2) sum += 3;
    int ans = sum - a - b - c;
    ans /= 2;

    cout << ans << endl;
}

Measured memory_bytes: 256
/*input
4
1
3
2
4
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back

#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)

#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int raise(int a,int n,int m = MOD){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= raise(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int floor1(int n,int k){
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}

int ceil1(int n,int k){
    return floor1(n+k-1,k);
}

const int N = 3e5+1;
int pos[N];
int p[N];
int dp[N];

void solve(){
    int n;
    cin >> n;
    RE(i,n){
      cin >> p[i];
      pos[p[i]] = i;
    }
    dp[0] = 0;
    pos[0] = 0;
    int mx = 0;
    RE(i,n){
      dp[i] = dp[i-1]*(pos[i] > pos[i-1])+1;
      mx = max(mx,dp[i]);
    }
    cout << n-mx;
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
  return 0;
}

Measured memory_bytes: 8300