akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int main(){
  double a,b;
  cin >> a >> b;
  cout << (int)a/(int)b << endl;
  cout << (int)a%(int)b << endl;
  cout << fixed << setprecision(10) << a/b << endl;
  return 0;
}



Measured memory_bytes: 3280
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main()
{
    char C;
    cin >> C;
    cout << char(C + 1);
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String o = sc.nextLine();
    String e = sc.nextLine();

    for(int i = 0; i < e.length(); i++){
      System.out.print(String.valueOf(o.charAt(i)) + String.valueOf(e.charAt(i)));
    }

    if(o.length() > e.length()){
      System.out.print(String.valueOf(o.charAt(o.length()-1)));
    }

    System.out.println("");

  }
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

const int mod = 1e9 + 7;

signed main() {
  int n = read();
  vi a(n + 1), b(n + 1);
  REP(i, n) { a[i + 1] = read(); }
  int m = 0;
  for (int i = n; i > 0; i--) {
    int j = i + i;
    if (j > n) {
      b[i] = a[i];
    } else {
      while (j <= n) {
        b[i] += b[j];
        j += i;
      }
      b[i] &= 1;
      if (b[i] == a[i])
        b[i] = 0;
      else
        b[i] = 1;
    }
    m += b[i];
  }
  print(m);
  FOR(i, 1, n + 1) {
    if (b[i] == 1) print(i, 2);
  }
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/
set<ll> r;
int  d[15];
void rec(int depth, int digit) {
    if(depth>=11) return;
    d[depth] = digit;

    ll ret = 0;
    rep1(i,depth) ret += d[i] * pow(10, i-1);
    r.insert(ret);  // 記録

    for(int i = digit-1; i <= digit+1; ++i) if(0<=i && i<=9) {  // 遷移
            rec(depth+1, i);
    }
    return;
}

/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    ll k;
    cin >> k;

    rep(i,10) {
        rec(1, i);  // build
    }

//    debug(r.size());
    auto iter = r.begin();
    rep(i,k) {
//        debug(*iter);
        ++iter;
    }
    cout << *iter << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 9728
import numpy as np

def dfs(A, a, n, ans):
  if len(A) == n:
    tmp = np.array(A) + a
    if sum(tmp % 2) < len(A):
      ans += 1
    return ans
  
  for i in range(-1, 2):
    A.append(i)
    ans = dfs(A, a, n, ans)
    A.pop()
    
  return ans

n = int(input())
a = np.array(list(map(int, input().split())))

print(dfs([], a, n, 0))

Measured memory_bytes: 14388
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
using ll = long long; using ld = long double; const char nl = '\n';
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

#include <bits/extc++.h>
namespace pbds =  __gnu_pbds;
template <typename key, typename val=pbds::null_type, typename comp=less<key>>
using ostree=pbds::tree<key,val,comp,pbds::rb_tree_tag,pbds::tree_order_statistics_node_update>;
using vi = vector< int >; using vll = vector< ll >;
#define all(x) std::begin(x), std::end(x)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&);
string to_string(string const&s){return '"'+s+'"';}
string to_string(char const &c) {return to_string(string(1,c));}
string to_string(char const *c) {return to_string(string(c));}
string to_string(bool const &b) {return (b ? "1" : "0");}
template<typename... Args> string to_string(pair<Args...> const&p)
{return "("+to_string(p.first)+", "+to_string(p.second)+")";}
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&S)
{string s = "{"; for(auto const& e: S)s+=" "+to_string(e);s+=" }"; return s;}
template<typename Tail> void debug_out(Tail t) {cerr<<" "<<to_string(t)<<" ]"<<endl;}
template<typename Head, typename... Tail> void debug_out(Head h, Tail... t)
{cerr << " " << to_string(h) << ","; debug_out(t...);}
#define pr(...) cerr<<"["<<(#__VA_ARGS__)<<"] : [", debug_out(__VA_ARGS__)
template <typename T> void dbr(T lb, T ub)
{cerr<<'{';for(auto it=lb; it!=ub; it++)cerr<<' '<<to_string(*it); cerr<<" }"<<endl;}
template<typename T, typename Comp=less<T>> bool smin(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(v, mem) ? mem = v, true : false;}
template<typename T, typename Comp=less<T>> bool smax(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(mem, v) ? mem = v, true : false;}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */



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

  string s; cin >> s;
  cout << (s[1] != s[0] and s[2] != s[1] and s[3] != s[2] ? "Good" : "Bad") << endl;

}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define INF 200001 
using namespace std;
int n;
int A[1000][1000];
int D[1000][1000];
  
void Init(int f){
  for(int i=0;i<f;i++){
    for(int j=0;j<f;j++)D[i][j] = INF;
  } 
}
  
int main(){
  scanf("%d",&n);
  int u,k,C,V;
  Init(n);
   
  for(int i=0;i<n;i++){
      scanf("%d %d",&u,&k);    
      for(int j=0;j<k;j++){
    scanf("%d %d",&V,&C);
    D[u][V] = C;
    
      }    
  }
  for(int i=0;i<n;i++)D[i][i] = 0;
 
  for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j]= min(D[i][j],D[i][k] + D[k][j]);
 
  for(int i=0;i<n;i++)printf("%d %d\n",i,D[0][i]);
  
  
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

int main(void)
{
	int i,j,k;
	
	for(i=1;i<10;i++){
		for(j=1;j<10;j++){
			k=i*j;
			printf("%dx%d=%d\n",i,j,k);
		}
	}
	return 0;
}

Measured memory_bytes: 524
#include<cstdio>
#include<algorithm>
#define mod 1000000007
using namespace std;
typedef long long ll;
#define LL long long 
ll je[200010];
ll x,y;
LL Gcd(LL a, LL b, LL &x, LL &y)
{
    if(b==0)
	{
        x=1;
        y=0;
        return a;
    }
    LL gcd=Gcd(b,a%b,x,y);
    LL tmp=x;
    x=y;
    y=tmp-(a/b)*y;
    return gcd;
}
LL C(LL m,LL n)
{
    Gcd(je[m]*je[n-m]%mod,mod,x,y);
    return je[n]*(x+mod)%mod;
}
int main()
{
	LL H,W,A,B;
    je[0]=1;
    for(LL i=1;i<200005;i++)
        je[i]=(je[i-1]*i)%mod;
    scanf("%lld%lld%lld%lld",&H,&W,&A,&B);
    LL ans=0;
    for(LL i=B+1;i<=W;i++)
    {
        LL tmp=(C(H-A-1,i-1+H-A-1)*C(W-i,W-i+A-1))%mod;
        ans=(ans+tmp)%mod;
    }
    printf("%lld",ans);
    return 0;
}


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


int gcd(int p, int q){
    if (p%q == 0) return q; 
    return gcd(q,p%q);
}

int main(){
int k,a[300], sum = 0;

cin >> k;

for (int i = 1;i <= k;i++){
    a[i]=i;
}


for (int i = 1;i <= k;i++){
   for(int j = 1;j <= k;j++){
       for(int s = 1;s <= k;s++){
           sum += gcd(gcd(a[i],a[j]),a[s]);
       }
   }

}
cout << sum << endl;

}

Measured memory_bytes: 3548
#include <iostream>

using namespace std;

int n;
int a[100005];
bool cnt[35];

int main(void)
{
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	
	int grundy = 0;
	for(int i = 0; i < n; i++) grundy ^= a[i];
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 35; j++){
			if(a[i] & (1<<j)){
				cnt[j] = true;
				break;
			}
		}
	}
	
	int ans = 0;
	for(int i = 30; i >= 0; i--){
		if(!cnt[i]) continue;
		if(grundy & (1<<i)){
			ans++;
			grundy ^= (1<<(i+1))-1;
		}
	}
	if(grundy == 0) cout << ans << endl;
	else cout << -1 << endl;
	
	return 0;
}

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

int main(){
	ll n;
	while(cin>>n,n){
		ll ans = 0;
		for(int i=0;i<n/4;i++){
			ll a;
			cin >> a;
			ans += a;
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3100
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char c[301000];int dp[301000][3][3],hj[301000],mi[301000],mod=1e9+7;
int main()
{
	scanf("%s",c);dp[0][0][0]=1;int n=strlen(c);
	mi[0]=1;for(int i=1;i<=n;i++)mi[i]=(mi[i-1]*2)%mod;
	for(int i=n;i>=1;i--)if(c[i-1]=='?')hj[i]=hj[i+1]+1;else hj[i]=hj[i+1];
	long long ans=0;
	for(int i=1;i<=n;i++)
	for(int x=0;x<=2;x++)
	for(int y=0;y<=2;y++)
	{
		if(c[i-1]=='1')
		{
			if(y==0)
				if(x+1>=3)ans=(ans+(long long)dp[i-1][x][y]*(long long)mi[hj[i+1]])%mod;
				else dp[i][x+1][y]=(dp[i][x+1][y]+dp[i-1][x][y])%mod;
			else dp[i][x][y-1]=(dp[i][x][y-1]+dp[i-1][x][y])%mod;
		}
		if(c[i-1]=='0')
		{
			if(y==2)dp[i][x][1]=(dp[i][x][1]+dp[i-1][x][y])%mod;
			else dp[i][x][y+1]=(dp[i][x][y+1]+dp[i-1][x][y])%mod;
		}
		if(c[i-1]=='?')
		{
			if(y==0)
				if(x+1>=3)ans=(ans+(long long)dp[i-1][x][y]*(long long)mi[hj[i+1]])%mod;
				else dp[i][x+1][y]=(dp[i][x+1][y]+dp[i-1][x][y])%mod;
			else dp[i][x][y-1]=(dp[i][x][y-1]+dp[i-1][x][y])%mod;
			if(y==2)dp[i][x][1]=(dp[i][x][1]+dp[i-1][x][y])%mod;
			else dp[i][x][y+1]=(dp[i][x][y+1]+dp[i-1][x][y])%mod;
		}
	}
	for(int y=0;y<=2;y++)for(int x=y+1;x<=2;x++)ans=(ans+dp[n][x][y])%mod;
	printf("%lld",ans);return 0;
}//01(010,001)可消 000消 dp[i][x][y]表示前i个数，1数量x，0数量y 方案数 

Measured memory_bytes: 13440
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
ll lcm(ll x,ll y){
	return x/__gcd(x,y)*y;
}
int main() {
	int n;cin>>n;
	ll arr[n];
	loop(n,i,0)cin>>arr[i];
	ll l=1;
	loop(n,i,0){
		l=lcm(l,arr[i]);
	}
	cout<<l<<endl;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>

using namespace std;

template<typename T, typename S>
istream& operator >> (istream& is, pair<T, S>& p) {
    is >> p.first >> p.second;
    return is;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& v) {
    for (auto& x : v) {
        is >> x;
    }
    return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& v) {
    for (auto& x : v) {
        os << x << " ";
    }
    os << "\n";
    return os;
}

bool Possible(const vector<int>& a, int v) {
    vector<int> b(a.size());
    for (int i = 0; i < a.size(); ++i) b[i] = (int)(a[i] >= v);
    int n = (a.size() + 1) / 2;
    if (b[n - 1] == b[n - 2] || b[n - 1] == b[n]) {
        return b[n - 1];
    }
    int l = n - 2, r = n;
    while (l > 0 && b[l - 1] != b[l]) --l;
    while (r < 2 * n - 2 && b[r] != b[r + 1]) ++r;
    if ((n - 1 - l) == (r - n + 1)) {
        if (l == 0) {
            return (b[n - 1] + n - 1) % 2;
        } else {
            return b[l];
        }
    } else {
        if ((n - 1 - l) < (r - n + 1)) return b[l];
        else return b[r];
    }
}

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

#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    vector<int> a(2 * n - 1);
    cin >> a;
    int l = 1, r = 2 * n;
    while (r - l > 1) {
        int t = (r + l) / 2;
        if (Possible(a, t)) {
            l = t;
        } else {
            r = t;
        }
    }
    cout << l;
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, n;
    cin >> h >> w >> n;
    int m = max(h, w);
    if(n%m==0) cout << n/m << '\n';
    else cout << n/m+1 << '\n';

    return 0;
}

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

int main()
{
  int n;
  cin >> n;
  vector<double> x(n);
  vector<string> u(n);
  int i;
  for(i = 0; i < n; i++)
  {
    cin >> x.at(i) >> u.at(i);
  }
  double ans = 0;
  for(i = 0; i < n; i++)
  {
    if(u.at(i) == "JPY")
    {
      ans += x.at(i);
    }
    else
    {
      ans += x.at(i) * 380000.0;
    }
  }
  cout << fixed << setprecision(5) << ans << endl;
}
  

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <functional>

int main()
{
  long long x, y, z, k;
  scanf("%lld%lld%lld%lld", &x, &y, &z, &k);
  long long a[1000];
  long long b[1000];
  long long c[1000];
  for (long long i = 0; i < x; ++i)
  {
    scanf("%lld", a + i);
  }
  for (long long i = 0; i < y; ++i)
  {
    scanf("%lld", b + i);
  }
  for (long long i = 0; i < z; ++i)
  {
    scanf("%lld", c + i);
  }
  
  std::sort(c, c + z, std::greater<long long>());

  long long xy[1000000];
  for (long long i = 0; i < y; ++i)
  {
    for (long long j = 0; j < x; ++j)
    {
      xy[i * x + j] = a[j] + b[i];
    }
  }
  std::sort(xy, xy + x * y, std::greater<long long>());
  
  long long xyz[3000000];
  long long lim = std::min(k, x * y);
  for (long long i = 0; i < lim; ++i)
  {
    for (long long j = 0; j < z; ++j)
    {
      xyz[i * z + j] = xy[i] + c[j];
    }
  }
  std::sort(xyz, xyz + lim * z, std::greater<long long>());
  
  for (long long i = 0; i < k; ++i)
  {
    printf("%lld\n", xyz[i]);
  }
  return 0;
}

Measured memory_bytes: 31488
a = int(input())
b = int(input())
c = int(input())
x = int(input())
counter = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if 500*i + 100*j + 50*k == x:
        counter += 1
print(counter)


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

int main(){
    string s;
    int count = 0;
    cin >> s;
    if (s[0] == '1') ++count;
    if (s[1] == '1') ++count;
    if (s[2] == '1') ++count;
    cout << count << endl;
}

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

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

    int res = 0;
    res += s % 2;
    s -= s % 2;
    s /= 10;

    res += s % 2;
    s -= s % 2;
    s /= 10;

    res += s % 2;
    s -= s % 2;
    cout << res << endl;
}

Measured memory_bytes: 256
import math
a, b, deg = map(int, input().split())
rad = math.radians(deg)

S = a * b * math.sin(rad) / 2
c = (a ** 2 + b ** 2 - 2 * a * b * math.cos(rad)) ** (1 / 2)
L = a + b + c
h = S * 2 / a

print(S,L,h)


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

using namespace std;
typedef long long ll;
const int inf=1e9+1;
ll max(ll a, ll b)
 { return (a > b)? a : b; }

ll knapsack (ll n,ll k, ll w[], ll v[])
{
    ll ar[n+1][k+1];
    for (ll i=0;i<=n;i++)
   {
       for (ll j=0;j<=k;j++)
       {
          if (i==0 || j==0)
            ar[i][j]=0;
          else if (w[i-1]>j)
            ar[i][j]=ar[i-1][j];
              else
                ar[i][j]=max(v[i-1]+ar[i-1][j-w[i-1]],ar[i-1][j]);
         }
    }
    return ar[n][k];
}
int main(){

   ll n,k;
   cin >> n >> k;
   ll w[n],v[n];
   for (ll i=0;i<n;i++)
    cin >> w[i] >> v[i];

   cout << knapsack(n,k,w,v);
    return 0;
}


Measured memory_bytes: 79104
#include <iostream>
#include <limits.h>
#include <algorithm>
using namespace std;

int n, h[100010];
int dp[100010];

int solve(int k) {
    if (dp[k] >= 0) return dp[k];
    
    int a, b;
    a = solve(k - 1) + abs(h[k] - h[k - 1]);
    b = solve(k - 2) + abs(h[k] - h[k - 2]);
    dp[k] = min(a, b);
    return dp[k];
}


int main(void){
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
        dp[i] = -1;
    }
    dp[1] = 0;  h[0] = h[1];
    
    
    cout << solve(n) << endl;
}


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

int main() {
  int N, x, y, z, w;
  cin >> N ;
  x = N / 1000;
  y = (N - 1000 * x) / 100;
  z = (N - 1000 * x - 100 * y) / 10;
  w = (N - 1000 * x - 100 * y -10 * z);
  
  //cout << x << endl;
  //cout << y << endl;
  //cout << z << endl;
  //cout << w << endl;
  
  if (x == y && y == z ) {
    cout << "Yes" << endl;
  }
//  else if (x == y && y == w) {
//    cout << "Yes" << endl;
//  }
//  else if (x == z && z == w) {
//    cout << "Yes" << endl;
//  }
  else if (y == z && z == w) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define ld          long double
#define endl        "\n"

const int mod = 1e9+7;

inline int add(int a, int b) { int res = a + b; if(res >= mod) res -= mod;  return res; }
inline int sub(int a, int b) { int res = a - b; if(res < 0) res += mod; return res;}
inline int mul(int a, int b) { return (a * b)%mod; }

const int N = 2e5+5;
int n, m;
int a[N];
int pre[N];

int cnt(int x) {
    int ans = 0;
    int l = 0, r = n-1;
    while(l <= r) {
        while(a[l] + a[r] < x && l<r) {
            r--;
        } 
        if(l == r && a[l]+a[r] < x) {
            return ans;
        } 
        ans += 1 + 2*(r-l);
        l++;
    }
    return ans;
}

int fs(int x) {
    int ans = 0;
    int l = 0, r = n-1;
    while(l <= r) {
        while(a[l] + a[r] < x && l<r) {
            r--;
        }
        if(l==r && a[l]+a[r] < x) {
            return ans;
        }
        ans += 2*a[l] + 2*(pre[r] - pre[l] + (r-l)*a[l]);
        l++;
    }
    return ans;
}

void solve() {
    cin >> n >> m;
    for(int i=0; i<n; i++) cin >> a[i];
    sort(a, a+n);   reverse(a, a+n);
    pre[0] = a[0];
    for(int i=1; i<n; i++) pre[i] = pre[i-1] + a[i];
    int l = 1, r = 1e11;
    while(r-l > 1) {
        int mid = (l+r)/2;
        int ways = cnt(mid);
        if(ways > m) l = mid;
        else r = mid;
    }
    int ans = 0;
    if(cnt(l)==m) {
        ans += fs(l);
    } else if(cnt(r)==m) {
        ans = fs(r);
    } else {
        ans = fs(r) + (m - cnt(r))*l;
    }
    cout << ans << endl;
}

signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(18);

    int T = 1;
    //cin >> T;

    while(T--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1e9 + 7;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, a;
    cin >> x >> a;
    if (x < a)
        cout << 0 << endl;
    else
        cout << 10 << endl;
    return 0;
}

Measured memory_bytes: 256
S = input()
T = input()
change_min = 1001
for i in range(len(S)-len(T)+1):
  change = 0
  for j in range(len(T)):
    if S[i+j] != T[j]:
      change += 1
  change_min = min(change_min, change)
print(change_min)

Measured memory_bytes: 9044
#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <climits>
#include  <vector>
#define ll long long
#define REP(a,b) for(int a=0; a<b; a++)
using namespace std;

vector <ll> rope;

int main() {
  ios_base::sync_with_stdio(false);
  int N, L;
  cin >> N >> L;
  REP(i, N){
    ll temp;
    cin >> temp;
    rope.push_back(temp);
  }
  bool possible = false;
  int last = INT_MAX;
  REP(i, N-1){
    if(rope[i]+rope[i+1] >= L){
      possible = true;
      last = i;
    }
  }
  if(possible){
    cout << "Possible" << endl;
    REP(i, last){
      cout << i+1 << endl;
    }
    for(int i = N-2; i >= last; i--){
      cout << i+1 << endl;
    }
  }else{
    cout << "Impossible" << endl;
  }
}

Measured memory_bytes: 1780
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define intarr(arr, n)  ll arr[n];  for (ll i = 0; i < n; i++)  cin >> arr[i]
#define inpvec(vec,n) for(ll i=0;i<n;i++){ll var;cin>>var;vec.push_back(var);}
#define ff first
#define ss second
#define pb push_back
#define mkp make_pair
#define vec vector<ll>
#define pi pair<ll,ll>
#define changeline cout<<endl
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define mod2 998244353
#define NO cout << "NO" <<endl
#define YES cout << "YES" <<endl
#define mem(arr,val) memset(arr,val,sizeof(arr));
const ll mod=1e9+7;
#define piii 3.14159265358979323846264338327950


bool prime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
bool subsequence_checker(string str1, string str2, ll m, ll n) 
{ 
    if (m == 0) return true; 
    if (n == 0) return false; 
    if (str1[m-1] == str2[n-1]) 
        return subsequence_checker(str1, str2, m-1, n-1); 
    return subsequence_checker(str1, str2, m, n-1); 
}

//////////////////////////////////////////////////// Lets Do It ////////////////////////////////////////////////////////


void solve(){

    string a,b;

    cin>>a>>b;

    ll n = a.length();

    ll ans = 0;
    loop(i,0,n)
    {
        if(a[i]!=b[i])
            ans++;

    }
    cout<<ans;

    return;           
} 
 
int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
    IOS;
    ll t;
    //cin>>t;
    t=1;

    while(t--){
        solve();
        cout<<endl;
    }

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
} 

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(int i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

int main(void){
  string s,t;cin >> s >> t;
  int n = s.length(), m = t.length();
  string dp[2][m+1];
  string *prev = dp[0];
  string *next = dp[1];
  REP(j,m+1){
    prev[j] = "";
    next[j] = "";
  }
  REP(i,n){
    REP(j,m){
      if(s[i] == t[j]) next[j+1] = prev[j]+s[i];
      else{
        if(next[j].length()>prev[j+1].length())
        next[j+1] = next[j];
        else next[j+1] = prev[j+1];
      }
    }
    swap(next,prev);
  }
  swap(next,prev);
  cout << next[m] << endl;
  return 0;
}


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


int main() {
	string s;
	cin >> s;
	if (s.at(2) == s.at(3) && s.at(4) == s.at(5)){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <stdio.h>
    #define MAX_N 20
     
    int main()
    {
      int n;
      int p[MAX_N];
      int i;
      int c = 0;
      scanf("%d", &n);
      for (i = 0; i < n; i++)
      {
        scanf("%d", &p[i]);
      }
      for (i = 0; i < n - 2; i++)
      {
        if ((p[i] > p[i + 1] && p[i + 1] > p[i + 2]) || (p[i] < p[i + 1] && p[i + 1] < p[i + 2]))
        {
          c++;
        }
      }
      printf("%d\n", c);
    }

Measured memory_bytes: 128
n = int(input())
h = list(map(int, input().split()))
h0min = h[0]
h0max = h[0]
for i in range(1, n):
    hi = h[i]
    if hi < h0min:
        print('No')
        break
    h0min = max(h0min, hi - 1)
    h0max = hi
else:
    print('Yes')


Measured memory_bytes: 14396
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, a = 0;
  cin >> N;
  vector<int> A(N);
  
  for(int i = 0; i < N; i++)
    cin >> A.at(i);
  
  int i = 0;
  for(;1;){
    if(a == 1){
      cout << i << endl;
      break;
    }
    a = A.at(a) - 1;
    if(i >= N){
      cout << -1 << endl;
      break;
    }
    i++;
  }
}

Measured memory_bytes: 3752
#include <iostream>

using namespace std;
int a[32] = {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 main(){
    int k;
    cin >> k;
    k--;
    cout << a[k] << endl;
}

Measured memory_bytes: 256
n,a,b = map(int,input().split())
x = list(map(int,input().split()))
ans = 0
for i in range(n-1):
    if (x[i+1]-x[i])*a <= b:
        ans += (x[i+1]-x[i])*a
    else:
        ans += b
print(ans)


Measured memory_bytes: 19964
n = int(input())
s1 = input()
s2 = input()
mod = 10 ** 9 + 7
table = []
y = 0
for i in range(len(s1)):
    if s1[i] == s2[i]:
        table.append("x")
    else:
        if y == 0:
            table.append("y")
            y += 1
        else:
            y -= 1
if table[0] == "x":
    ans = 3
else:
    ans = 6

for i in range(len(table))[1:]:
    if table[i] == "x":
        if table[i - 1] == "x":
            ans *= 2 % mod
        else:
            pass
    else:
        if table[i - 1] == "x":
            ans *= 2 % mod
        else:
            ans *= 3 % mod
print(ans % mod)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;
int main() {
    bool cards[4][14];
    int n,rank;
    char suit;

    for (int s=0;s<4;s++)
        for(int r=1;r<=13;r++)
            cards[s][r] = 0;

    cin>>n;
    for(int i=0;i<n;i++){
        cin>> suit >>rank;
        if(suit=='S')cards[0][rank]=1;
        if(suit=='H')cards[1][rank]=1;
        if(suit=='C')cards[2][rank]=1;
        if(suit=='D')cards[3][rank]=1;
    }
    
    for(int s=0;s<4;s++){
        for(int r=1;r<=13;r++){
            if(cards[s][r])continue;
            if(s == 0) suit='S';
            if(s == 1) suit='H';
            if(s == 2) suit='C';
            if(s == 3) suit='D';
            cout<< suit <<' '<< r << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3084
#include <cstdio>
#include <vector>

using namespace std;

bool isPalindromic(int num) {

    int i = 0, j;
    vector<int> digits;

    while (num) {
        digits.push_back(num % 10);
        num /= 10;
    }

    j = digits.size();

    while (i < j) {
        if (digits[i++] != digits[--j]) return false;
    }

    return true;

}

int main() {

    int a, b, count = 0;

    scanf("%d%d", &a, &b);

    for (int i = a; i <= b; ++i) {
        if (isPalindromic(i)) ++count;
    }

    printf("%d\n", count);

    return 0;

}


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

const int N = 1e5 + 10;
int n, ans, ar[N];

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> ar[i];
	
	for (int i = 1; i <= n; i++)
		if (ar[i] == i) {
			swap(ar[i], ar[i + 1]);
			ans++;
		}
	cout << ans;
}

Measured memory_bytes: 640
from bisect import bisect_left
N = int(input())
S = input()
X = {"R": [], "G": [], "B": []}
Xset = {"R": set(), "G": set(), "B": set()}
for i, c in enumerate(S):
    X[c].append(i)
    Xset[c].add(i)

ans = 0
for i in range(N - 2):
    si = S[i]
    for j in range(i + 1, N - 1):
        sj = S[j]
        if si == sj:
            continue
        x = ["R", "G", "B"]
        x.remove(si)
        x.remove(sj)
        sk = x[0]
        ks = X[sk]
        count = len(ks) - bisect_left(ks, j)
        if 2 * j - i in Xset[sk]:
            count -= 1
        ans += count
print(ans)

Measured memory_bytes: 69536
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const double pi=acos(-1);

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

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i=0;i<n;i++) cin >> p[i];
    sort(p.begin(),p.end());
    p[n-1]/=2;
    int ans=0;
    for(int i=0;i<n;i++) ans+=p[i];
    cout << ans << endl;
}


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

typedef long  long ll;
#define FF first
#define SS second
#define INF 2000000000


int main(){
    int h, n;
    cin >> h >> n;
    int arr[n];
    int sum = 0;
    for(int i = 0; i < n; ++i){
        cin >> arr[i];
        sum += arr[i];
    }

    if(sum >= h){
        cout << "Yes" << "\n";
    }
    else{
        cout << "No" << "\n";
    }

}

Measured memory_bytes: 640
//Abhinav ---IIIT_A
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
#define vpii vector<pair<int,int>>
#define vi vector<int>
#define mpii map<pair<int,int>,int>
#define mpivpii map<int,vector<pair<int,int>>>
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define mpi map<int,int>
#define vvi vector<vector<int>>
#define vvvi vector<vvi>
ld pie=3.141592653589;
int mod=1e9+7;

int n,m;

vi adj[100005]; 
int dp[100005];

int dfs(int s){
	if(dp[s]!=-1) return dp[s];
	dp[s]=0;
	for(auto it : adj[s]){
		int ans=dfs(it);
		dp[s]=max(dp[s],1+ans);
	}
	return dp[s];
}

void solve(){
	cin>>n>>m;
	f(i,0,m){
		int u,v; cin>>u>>v; --u; --v;
		adj[u].pb(v);
	//	adj[v].pb(u);
	}	
	f(i,0,n) dp[i]=-1;
	f(i,0,n) if(dp[i]==-1) dp[i]=dfs(i);
	int mx=0;
	f(i,0,n) mx=max(mx,dp[i]);
	cout<<mx<<"\n";
	return ;
}



signed main(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
  int t=1; //cin>>t;
  while(t--) solve();
  return 0;
}
// check for overflows dummy !!!


Measured memory_bytes: 11800
#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
vector<ll> a, p;

ll f(ll N, ll X){
    if(N == 0){
        if(X<=0){
            return 0;
        }else{
            return 1;
        }
    }
    if(X <= 1+ a[N-1]){
        return f(N-1, X-1);
    }else{
        return p[N-1] + 1 + f(N-1, X-2-a[N-1]);
    }
}

int main(){
    ll n, x;
    ll tmp;
    cin >> n >> x;
    a.push_back(1);
    p.push_back(1);
    for(int i=0; i<n; i++){
        tmp = a[i]*2+3;
        a.push_back(tmp);
        tmp = p[i]*2+1;
        p.push_back(tmp);
    }
    tmp = f(n,x);
    cout << tmp << endl;
    return 0;
}

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

using namespace std;

int main() {
	int a, b, c, x, y;
	scanf("%d %d %d %d %d",&a,&b,&c,&x,&y);
	c*=2;
	if(a+b<=c) {
		printf("%d\n",x*a+b*y);
		return 0;
	}
	if(c<=min(a,b)) {
		printf("%d\n",max(x,y)*c);
		return 0;
	}
	printf("%d\n",min(x,y)*c+abs(x-y)*(x>y?min(a,c):min(b,c)));
	return 0;
}

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


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

    string a;
    cin >> a;
    int c=0;
    int maxi=0;
    for (int i=0;i<3;i++){
        if (a[i]=='R'){
            c++;
            maxi=max(c,maxi);
        }
        else
            c=0;
    }
    cout << maxi;
    return 0;
}


Measured memory_bytes: 3668
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	int a[4001];
	char c[4001];
	scanf("%d ", &n);
	int b[2001], w[2001];
	for(int i=1; i<=2*n; i++){
		scanf("%c %d ", &c[i], &a[i]);
		if(c[i]=='B'){
			b[a[i]]=i;
		}else{
			w[a[i]]=i;
		}
	}

	int dp[2001][2001]={};
	int bn[2001][4001]={}, wn[2001][4001]={};
	for(int i=1; i<=n; i++){
		for(int k=1; k<=2*n; k++){
			if(c[k]=='B' && a[k]<=i){
				bn[i][k]=bn[i][k-1]+1;
			}else{
				bn[i][k]=bn[i][k-1];
			}
			if(c[k]=='W' && a[k]<=i){
				wn[i][k]=wn[i][k-1]+1;
			}else{
				wn[i][k]=wn[i][k-1];
			}
		}
	}
	for(int i=0; i<=n; i++){
		if(i==0){
			for(int j=1; j<=n; j++){
				dp[0][j]=dp[0][j-1]+j-1-wn[j-1][w[j]];
			}
		}else{
			dp[i][0]=dp[i-1][0]+i-1-bn[i-1][b[i]];
			for(int j=1; j<=n; j++){
				dp[i][j]=min(dp[i-1][j]+i+j-1-bn[i-1][b[i]]-wn[j][b[i]], dp[i][j-1]+i+j-1-bn[i][w[j]]-wn[j-1][w[j]]);
			}
		}
	}
	printf("%d\n", dp[n][n]);
	return 0;
}

Measured memory_bytes: 78592
//Solution for aoj:0042 A Thief
#include<bits/stdc++.h>
using namespace std;
#define int  long long unsigned int
int w, n, c;
char a;
int trs[1001][2];
int dp[1001][1001];
signed main(){
	while (cin >> w){
		if (!w)
			return 0;
		c++;
		cin >> n;
		for (int i = 1; i <= n; i++){
			cin >> trs[i][0] >> a >> trs[i][1];
		}
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= w; j++){
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
				if (j >= trs[i][1])
					dp[i][j] = max(dp[i][j], dp[i - 1][j - trs[i][1]] + trs[i][0]);
			}
		}
		for (int i = 1; i <= w; i++){
			if (dp[n][i] == dp[n][w]){
				cout << "Case " << c << ':' << endl << dp[n][i] << endl << i << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 9000
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define printclock cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n";
#define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define deb1(x) cout << #x << ": " << x << endl
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define prec(n) fixed << setprecision(n)
#define all(a) a.begin(), a.end()
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define pii pair<int, int>
#define vii vector<int>
#define ld long double
#define int long long
#define MOD LLONG_MAX
#define mp make_pair
#define pb push_back
#define endl "\n";
inline void get(vector<int> &arr, int n)
{
    int a;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        arr.push_back(a);
    }
}
inline void print(vector<int> &arr, int n)
{
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << endl;
}
/*----------------------------------TEMPLATE------------------------------------*/
int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    fast;
    /*----------------------------PEEPEEPOOPOO-------------------------------------*/
    int t;
    t = 1;
    while (t--)
    {
        string s,t;
        cin >> s >> t;
        int n = s.size();
        int m = t.size();
        int ans = m;
        for(int i =0;i+m<=n;i++)
        {
            int count = 0;
            for(int j=i;j<i+m;j++)
            {
                if(t[j-i]!=s[j]) count++;
            }
            ans = min(ans,count);
        }
        cout << ans << endl;
    }
    return 0;
}
/*--------------------------------PEEPEEPOOPOO-------------------------------------*/

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

int main()
{
	int N, K;
	cin >> N >> K;
	vector<int> h(N);
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	vector<int> dp(N, 1e9 + 1);
	dp[0] = 0;
	for (int i = 1; i < N; i++) {
		for (int j = max(i - K, 0); j < i; j++) {
			dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
		}
	}
	cout << dp[N - 1] << endl;
	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using llong = long long;
using P = pair<int, int>;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   double r;
   cin >> r;
   double area = r * r * M_PI;
   double cir = 2 * r * M_PI;
   printf("%0.5f %0.5f\n", area, cir);
   return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector <int> A(n);

    for (int i = 0; i < n; i++) {
        cin >> A[i];
        A[i]--;
    }
    int res = 0;

    for (int i = 0; i < n; i++) {
        if (A[A[i]] == i) {
            res++;
        }
    }
    cout << res / 2 << '\n';
    return 0;
}

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

int main()
{
	int n;
    cin>>n;
  	long long sum=0;
  	int x;
  	for(int i=1;i<=n;i++)
    {
      cin>>x;
      sum+=(x-1);
    }
  	cout<<sum;
	return 0;
}

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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<int> dp(n+1);
    int ans = 0;
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        if (dp[a[i]-1]) {
            dp[a[i]] = 1;
            ans = max(ans,a[i]);
        }
    }
    if (ans == 0) {
        cout << -1 << '\n';
    }
    else {
        cout << n-ans << endl;
    }
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

ll mpow(ll x, ll n) {
  ll ans=1;
  while(n>0) {
    if(n&1) {
      ans=ans*x%mod;
    }
    x=x*x%mod;
    n>>=1;
  }
  return ans;
}

vec tfact(1e7+1);
void fact(ll n) {
  for(ll i=0;i<=n;i++) {
    if(i==0) {
      tfact[i]=1;
    }
    else {
      tfact[i]=tfact[i-1]*i%mod;
    }
  }
}

ll comb(ll n, ll k) {
  return tfact.at(n)*mpow(tfact.at(k),mod-2)%mod*mpow(tfact.at(n-k),mod-2)%mod;
}

int main() {
  ll n,a,b,c;
  cin >> n >> a >> b >> c;
  fact(2*n);
  ll ans=0;
  for(ll i=n;i<2*n;i++) {
    ll res=comb(i-1,n-1)*((mpow(a,n)*mpow(b,i-n)%mod+mpow(b,n)*mpow(a,i-n)%mod)%mod)%mod;
    res=res*mpow(mpow(a+b,mod-2),i)%mod;
    res=res*i%mod;
    ans+=res;
    ans%=mod;
  }
  ans=ans*100%mod*mpow(100-c,mod-2)%mod;
  cout << ans << endl;
}

Measured memory_bytes: 78336
#include "bits/stdc++.h"
using namespace std;

int MOD = 1000 * 1000 * 1000 + 7;

const int MXN = 21;

int n;
int match[MXN][MXN];

int dp[MXN][(1<<MXN)];

int ways(int x, int bts) {
	if (x == n) {
		return (bts == ((1 << n) - 1));
	}
	if (dp[x][bts] != -1) return dp[x][bts];
	int res = 0;
	for (int i=0; i<n; i++) {
		if ((1 << i) & bts) continue;
		if (match[x][i]) {
			res += ways(x+1, (bts | (1 << i)));
			res = res % MOD;
		}
	}
	return dp[x][bts] = res;
}

int main() {
	
	for (int i=0; i<MXN; i++) for (int j=0; j<(1<<MXN); j++) dp[i][j] = -1;
	
	cin >> n;
	for (int i=0; i<n; i++) {
		for (int j=0; j<n; j++) {
			cin >> match[i][j];
		}
	}
	
	cout << ways(0, 0);
	
	
}




Measured memory_bytes: 172288
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>

int main() {

    int S, N, L, tmp1, ans = 0;

    std::cin >> N >> L;

    //最小値味
    int low_taste = 100000;

    //N個のリンゴを使ったアップルパイの味
    int all_taste = 0;
    int flag = 1;//正1負0
    for(int i = 1; i <= N; i++){
        all_taste += L + i - 1;
        if(abs(L + i - 1) < abs(low_taste)){
            low_taste = L + i - 1;
        }
    }

    ans = all_taste - low_taste;

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

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class Main{
	public static void main(String[]args){
	Scanner scan=new Scanner(System.in);
	int a=scan.nextInt();
	int b=scan.nextInt();
	long count=0;
	long ans=0;
	int AB[][]=new int[a][2];
	for(int i=0;i<a;i++) {
		int x=scan.nextInt();
		int y=scan.nextInt();
		AB[i][0]=x;
		AB[i][1]=y;
	}
	  Arrays.sort(AB, new Comparator<int[]>() {
	        @Override
	        public int compare(int[] o1, int[] o2) {
	            return o1[0] - o2[0];
	        }
	    });
	  for(int i=0;i!=a;i++) {
		  if((count+AB[i][1])>b) {
			  ans+=(long)AB[i][0]*(b-count);
			  break;
		  }
		  else {
			  count+=AB[i][1];
			  ans+=(long)AB[i][0]*(long)AB[i][1];
		  }
	  }
	  System.out.println(ans);
	}
}

Measured memory_bytes: 90684
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; i++)

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

	if (A <= 2 * B) {
		cout << 0 << endl;
	} else {
		cout << A - 2 * B << endl;
	}

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
		
		if((a+b==c)||(b+c==a)||(a+c==b)){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define sz 100010
#define BeatMeScanf ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define pii pair<int,int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair

int const mod = 1e9;

int main()
{
    BeatMeScanf;
    int cnt  = 0;
    string a, b;
    cin>>a>>b;
    for(int i=0;i<a.size();i++) {
        if(a[i] != b[i]) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

const int P = 1000003;

int Q, fac[P], inv[P];

int qpow(int a, int b) {
	int s = 1;
	for (; b; b >>= 1) {
		if (b & 1) {
			s = 1ll * s * a % P;
		}
		a = 1ll * a * a % P;
	}
	return s;
}

int main() {
	read(Q);
	fac[0] = 1;
	for (int i = 1; i < P; ++i) {
		fac[i] = 1ll * fac[i - 1] * i % P;
	}
	inv[P - 1] = qpow(fac[P - 1], P - 2);
	for (int i = P - 1; i; --i) {
		inv[i - 1] = 1ll * inv[i] * i % P;
	}
	while (Q--) {
		int x, d, n;
		read(x), read(d), read(n);
		if (d == 0) {
			print(qpow(x, n));
			continue;
		}
		x = 1ll * x * qpow(d, P - 2) % P;
		if (x <= 0 || x + n - 1 >= P) {
			print(0);
			continue;
		}
		print(1ll * fac[x + n - 1] * inv[x - 1] % P * qpow(d, n) % P);
	}
}


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

int main(void){
    // Your code here!
    ll a,b,c,d,x,y;
    cin>>a>>b>>c>>d;
   
    ll arr[4];
    arr[0]=a*c;
    arr[1]=a*d;
    arr[2]=b*c;
    arr[3]=b*d;
    
    x=*max_element(arr,arr+4);
    cout<<x<<endl;
}


Measured memory_bytes: 3620