akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
  static InputReader in;
  static PrintWriter out;
  
  static class Solution {
    void solve() throws IOException {
      while (true) {
        int n = in.nextInt();
        if (n == 0) {
          break;
        }
        double variance = 0;
        double stddev;
        double sum = 0;
        double avg;
        
        double[] score = new double[n];
        for (int i = 0; i < n; i++) {
          score[i] = in.nextDouble();
          sum += score[i];
        }
        avg = sum / n;
        
        for (int i = 0; i < n; i++) {
          variance += Math.pow(score[i] - avg, 2);
        }
        variance /= n;
        
        stddev = Math.sqrt(variance);
        out.printf("%.5f\n", stddev);
      }
      
      
//      End solve()
    }
//    End Solution
}


  public static void main(String[] args) throws IOException {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out);
    Solution solver = new Solution();
    solver.solve();
    out.close();
}


  static class InputReader {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream));
    }

    public int nextInt() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Integer.parseInt(st.nextToken());
    }

    public long nextLong() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Long.parseLong(st.nextToken());
    }

    public String next() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return st.nextToken();
    }

    public double nextDouble() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Double.parseDouble(st.nextToken());
    }

  }

}

Measured memory_bytes: 26644
#include <stdio.h>

int main(){
  int n,mochi[110],d[101],ans=0,i;
  
  scanf("%d",&n);
  
  for(i=0;i<101;i++)d[i]=0;
                      
  for(i=1;i<=n;i++){
    scanf("%d",&mochi[i]);
    d[mochi[i]]++;
  }
  
  for(i=1;i<=100;i++)if(d[i]>0)ans++;
  
  printf("%d\n",ans);
  
  return 0;
}


Measured memory_bytes: 128
ls = []
ans = 0
while 1:
    ls1=(list(map(str,input().split())))
    if ls1[1] == "?":
        break
    else:
        ls.append(list(ls1))
        ls1.clear()
for i in range(len(ls)):
    if ls[i][1] == "+":
        ans = int(ls[i][0])+int(ls[i][2])
        print(ans)
    elif ls[i][1] == "-":
        ans = int(ls[i][0])-int(ls[i][2])
        print(ans)
    elif ls[i][1] == "*":
        ans = int(ls[i][0])*int(ls[i][2])
        print(ans)
    elif ls[i][1] == "/":
        ans = int(ls[i][0])//int(ls[i][2])
        print(ans)



Measured memory_bytes: 5604
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work
vector<vector<pll>> ADJ;
vector<ll> QE;
pair<ll,bool> dfs(ll u,ll t,ll p=-1)
{
    if (u==t)
    {
        return {0,true};
    }
    for(auto v:ADJ[u])
    {
        if(v.fi!=p)
        {
            pair<ll,bool> Z=dfs(v.fi,t,u);
            if (Z.se)
            {
                Z.fi+=pow(2,v.se);
                return Z;
            }
        }
    }
    return {0,false};
}
int main()
{
   
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

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

    READV(N);
    ADJ.resize(N+1);
    FORI(i,0,N-1)
    {
        READV(a);
        READV(b);
        ADJ[a].pb({b,i});
        ADJ[b].pb({a,i});
    }
    READV(M);
    QE.resize(M);
    FORI(i,0,M)
    {
        READV(a);
        READV(b);
        QE[i]=dfs(a,b).fi;
    }
    ll ans=0;
    FORI(i,0,pow(2,M))
    {
        ll x=i;
        ll c=0;
        ll z=0;
        FORI(j,0,M)
        {
            if (x%2)
            {
                z=z|QE[j];
                c++;
            }
            x=x/2;
        }
        ll g=0;
        FORI(j,0,N)
        {
            g+=z%2;
            z/=2;
        }
        ans+=pow(-1,c)*pow(2,N-1-g);
    }
    cout<<ans<<endl;

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


   
    return 0;
}

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

using namespace std;

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

    priority_queue<double> q;
    for (int i=0; i<n; i++) {
        int a;
        cin >> a;
        q.push(a);
    }

    for (int i=0; i<m; i++) {
        double p = q.top();
        q.pop();
        q.push(p/2);
    }

    long long ans = 0;
    while (!q.empty()) {
        ans += q.top();
        q.pop();
    }

    cout << ans << endl;
}


Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  int N; cin>>N;
  vector<string> s(N);
  vector<int> t(N);
  REP(i,N) cin>>s[i]>>t[i];
  string X; cin>>X;
  int ans = 0;
  bool ok = false;
  REP(i,N) {
    if(ok) ans += t[i];
    if(s[i] == X) ok = true;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()

int main(){
	int a,b;
	cin >> a >> b;
	string ret;

	if (a > 0 && b > 0){
		ret = "Positive";
	}else if (a <= 0 && b > 0){
		ret = "Zero";
	}else if (a < 0 && b == 0){
		ret = "Zero";
	}else if (a < 0 && b < 0){
		if ((b - a)%2 == 1){
			ret = "Positive";
		}else{
			ret = "Negative";
		}
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };



signed main() {
	int i, j;
	int n;

	cin >> n;

	if (n == 25) {
		cout << "Christmas" << endl;
	}
	else if (n == 24) {
		cout << "Christmas Eve" << endl;
	}
	else if (n == 23) {
		cout << "Christmas Eve Eve" << endl;
	}
	else if (n == 22) {
		cout << "Christmas Eve Eve Eve" << endl;
	}









	getchar();
	getchar();
	return 0;
}

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


import sys
import math

def move(point,n,arg):
  return [ point[0]+n*arg[0], point[1]+n*arg[1] ]

theta = 90
p = [0.0,0.0]
for s in sys.stdin:
  d = map(int , s.split(","))
  arg = [ math.cos(theta*math.pi/180), math.sin(theta*math.pi/180) ]
  p = move(p,d[0],arg)
  theta -= d[1]
  if d == [0,0]:
    for e in p:
      print int(e)

Measured memory_bytes: 4432
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define debug(x1) cout<<#x1<<": "<<x1<<endl
#define debug2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl

signed main(){
  int n, k; cin >> n >> k;
  int mod = 1000000007;
  int cnt = 0, left = 0, right = 0;
  for(int i=0; i<=n; i++) {
    left += i;
    right += n-i;
    if(i+1>=k){
      cnt += (right-left+1) % mod;
      cnt = cnt % mod;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    string s; cin >> s;
    for(int i=0;i<3;i++){
        cout << s[i];
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ld INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }
typedef pair<ld, int> P;

ld calc(ld x1, ld y1, ld r1, ld x2, ld y2, ld r2) {
  ld res = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
  res = sqrt(res) - r1 - r2;
  if (res < 0) res = 0;
  return res;
}

vector<P> G[1010];
vector<ld> d(1010, INF);

void dijkstra(int s) {
  d[s] = 0;
  priority_queue<P, vector<P>, greater<P>> pq;
  pq.push({0, s});
  while (!pq.empty()) {
    ld dist = pq.top().first;
    int v = pq.top().second;
    pq.pop();
    if (d[v] < dist) continue;
    for (P p: G[v]) {
      ld c = p.first;
      int u = p.second;
      if (chmin(d[u], d[v] + c)) {
        pq.push({d[u], u});
      }
    }
  }
}


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

  ld xs, ys, xt, yt;
  cin >> xs >> ys >> xt >> yt;
  int n;
  cin >> n;
  int s = n, t = n + 1;
  vector<ld> x(n), y(n), r(n);
  rep(i, n) cin >> x[i] >> y[i] >> r[i];

  rep(i, n) {
    ld cost = calc(xs, ys, 0, x[i], y[i], r[i]);
    G[s].push_back({cost, i});
  }
  rep(i, n) {
    ld cost = calc(xt, yt, 0, x[i], y[i], r[i]);
    G[i].push_back({cost, t});
  }
  rep(i, n) {
    rep(j, i) {
      ld cost = calc(x[i], y[i], r[i], x[j], y[j], r[j]);
      G[i].push_back({cost, j});
      G[j].push_back({cost, i});
    }
  }
  ld cost = calc(xs, ys, 0, xt, yt, 0);
  G[s].push_back({cost, t});
  dijkstra(s);
  cout << d[t] << '\n';







  
  return 0;
}

Measured memory_bytes: 42768
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=1 +117;
const int MM=125000 +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}


int m,n,sum,d;
LL v[NN]={};
int p[NN]={};
struct item{
	LL w,v;
	int cnt;
}a[NN]={};
LL t[MM]={};
void add(int VOL,int v,int w){
	for(int i=VOL;i>=v;--i){
		t[i]=min(t[i],t[i-v]+w);
	}
}
bool cmp(item a,item b){
	return a.v*b.w>b.v*a.w;
}
int main(){
	//open();
	n=read();
	sum=read();
	d=read();
	v[1]=read(); 
	for(int i=2;i<=n;++i){
		v[i]=read(),p[i]=read();
	}
	for(int i=n;i>=1;--i){
		a[i].v+=1;
		a[i].w+=v[i];
		a[i].cnt=d;
		a[p[i]].v+=a[i].v;
		a[p[i]].w+=a[i].w;
	}
	a[1].cnt=1e9;
	int siz=n*n*n;
	for(int i=0;i<=siz;++i)t[i]=sum+1;
	t[0]=0;
	for(int i=1;i<=n;++i){
		int k=min(n,a[i].cnt);
		a[i].cnt-=k;
		int now=1;
		while(k){
			if(k<=now)now=k;
			if((LL)now*a[i].w<=sum){
				add(siz,now*a[i].v,now*a[i].w);
			}
			k-=now;
			now<<=1;
		}
	}
	sort(a+1,a+1+n,cmp);
	LL op=0;
	for(int nv=0;nv<=siz;++nv){
		int rem=sum-t[nv];
		if(rem<0)continue;
		LL ans=nv;
		for(int i=1;i<=n;++i){
			int ad=rem/a[i].w;
			if(ad>a[i].cnt)ad=a[i].cnt;
			ans+=ad*a[i].v;
			rem-=ad*a[i].w;
		}
		op=max(ans,op);
	}
	printf("%lld\n",op);
	close();
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <stdio.h>

#include <vector>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <climits>

using namespace std;

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

	int ans = 0;

	for (int i = 1; i <= n; i = i + 2) {
		int count = 0;
		for (int j = 1; j <= n ;j++) {
			if (i % j == 0) count++;
		}

		if (count == 8)ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>
long long dp[51][51][2501]={0};
int main(void){
	int n,a,i,x[51];
	scanf("%d %d",&n,&a);
	for(i=0;i<n;i++)scanf("%d",&x[i]);
	long long ans=0;
	dp[0][0][0]=1;
	for(i=0;i<51;i++)dp[i][0][0]=1;
	for(int j=0;j<n;j++){
		for(int k=1;k<=n;k++){
			for(int s=0;s<=2500;s++){
				if(s>=x[j])dp[j+1][k][s]=dp[j][k][s]+dp[j][k-1][s-x[j]];
				else dp[j+1][k][s]=dp[j][k][s];

			}
		}
	}
	for(int k=1;k<=n;k++){ans+=dp[n][k][k*a];}
	
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 49920
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

# 繰り返し二乗法
def pow_r_mod(x:int, n:int, mod=10**9+7)->int:
    # 計算量 : log N
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        x %= mod
        n //= 2
    return (K * x) % mod

def table(n:int, p=10**9+7):
    global fact, factinv, inv
    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]
    for i in range(2, n+1):
        #fact.append((fact[-1] * i) % p)
        inv.append((-inv[p % i] * (p // i)) % p)
        #factinv.append((factinv[-1] * inv[-1]) % p)

m, a, b = mi()

P = 10**9+7
N = 2*(10**5)
table(N)

mca = 1
for i in range(1, a+1):
    mca *= (m-i+1) * inv[i]
    mca %= P

mcb = mca
for i in range(a+1, b+1):
    mcb *= (m-i+1) * inv[i]
    mcb %= P

print((pow_r_mod(2, m)-1-mca-mcb) % P)


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

int main(){
  int n, cnt = 0, ans = 0;
  int p[100010] = {};
  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> p[i];
    if(p[i] == i) cnt++;
  }
  if(cnt == 0){
    cout << 0 << endl;
  }else{
    for(int i = 1; i <= n; i++){
      if(p[i] == i){
        swap(p[i], p[i+1]);
        ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdlib> //abs(int x)
using namespace std;

int n, k;
     
int solve(int* H){
  int C[n];
  C[0] = 0;
  C[1] = abs(H[1]-H[0]);
  for (int i=2; i<n; i++){
    int m = 1<<30;
    for (int j=i-k; j<i; j++){
      if (j>=0){
        m = min(m, C[j]+abs(H[i]-H[j]));
      } 
    }
    C[i] = m;
  }
  return C[n-1];
}
     
int main(){
  cin >> n >> k;
  int H[n];
  for (int i=0; i<n; i++){
    cin >> H[i];
  }
  cout << solve(H) << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
    int m,n,ans1=0,ans2=0;

    scanf("%d %d",&m,&n);

    if(m>=2){
        ans1=m*(m-1)/2;
    }

    if(n>=2){
        ans2=n*(n-1)/2;
    }

    printf("%d\n",(ans1+ans2));


    return 0;
}

Measured memory_bytes: 256
//header{{{
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <boost/hana/functional/fix.hpp>
#include <boost/sort/spreadsort/spreadsort.hpp>
//#include <boost/graph/adjacency_list.hpp>
//#include <boost/graph/dijkstra_shortest_paths.hpp>
//#include <boost/graph/graph_utility.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
  
using namespace std;
//using namespace boost::multiprecision;
//using namespace boost::math;

/*
typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS,
        boost::no_property, boost::property<boost::edge_weight_t, int> > Graph;
*/

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define FixPoint boost::hana::fix
#define bsort boost::sort::spreadsort::spreadsort
#define int int_fast64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};

struct negrightshift {
    inline int operator() (const int &x, const unsigned offset) {
        return -(x >> offset);
    }
};
//}}}


signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.setf(ios_base::fixed);
    cout.precision(10);

    int n, W;
    cin >> n >> W;

    vector w(n + 1, 0), v(n + 1, 0);

    reps(i,n){
        cin >> w[i] >> v[i];
    }

    vector dp(n + 1, vector(W + 1, -1LL));

    dp[0][0] = 0;

    auto res = FixPoint([&](auto rec, int r, int c){
        if(c < 0 || r < 0){
            return (-LINF);
        }else if(~dp[r][c]){
            return (dp[r][c]);
        }

        dp[r][c] = max({rec(r-1, c), rec(r, c-1), rec(r-1, c - w[r]) + v[r]});

        return (dp[r][c]);
    })(n, W);

    cout << res << '\n';

    return 0;
}

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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(long long i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const double EPS = 1e-9;
const ll powll = 1LL<<1;

/*
while(!frag && cin >> a >>b, a|b)
*/

int main(void){
    ll x,k,d; cin >> x >> k >> d;
    ll t = abs(x)/d;
    if((k-t) <= 1){
        if(x < 0){
            cout << abs(x+k*d) << "\n";
        }else{
            cout << abs(x-k*d) << "\n";
        }
    }else{
        ll kk;
        if((k-t)%2){
            kk = t+1;
        }else{
            kk = t;
        }

        if(x < 0){
            cout << abs(x+kk*d) << "\n";
        }else{
            cout << abs(x-kk*d) << "\n";
        }
    }
}


Measured memory_bytes: 3612
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        n: usize,
        d: [(u8, u8); n],
    }
    let mut ans = false;
    let mut count = 0;
    for i in d.iter() {
        if i.0 == i.1 {
            count += 1;
            if count == 3 {
                ans = true;
                break;
            }
        } else {
            count = 0;
        }
    }
    if ans {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2204
#include<bits/stdc++.h>
#define fr(i1,m) for(int i1=0;i1<m;i1++)
using namespace std;
int main()
{
       long n,k,x,y;
       while(cin>>n>>k>>x>>y)
       {
           if(n<k)
           {
               cout<<n*x<<"\n";
               continue;
           }
           else
           {
               cout<<k*x+(n-k)*y<<"\n";
           }
       }
        return 0;

}




Measured memory_bytes: 256
import math
n,m=map(int,input().split())
num=10**9+7
if abs(n-m)>=2:
    print(0)
elif abs(n-m)==1:
    print((math.factorial(n)*math.factorial(m))%num)
else:
    print((2*math.factorial(n)*math.factorial(m))%num)


Measured memory_bytes: 5184
use proconio::input;

#[proconio::fastout]
fn main() {
    input! {
        s: String,
        t: String,
    }
    let mut ans = 0;
    let len: usize = s.len();
    for i in 0..len {
        if s.as_bytes()[i] != t.as_bytes()[i] {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2872
#include <stdio.h>

int main(){
  int i, j, N;
  scanf("%d",&N);
  for(i=1;i<10;i++){
    for(j=1;j<10;j++){
      if(N==i*j) {
        puts("Yes");
        return 0;
      }
    }
  }
  puts("No");
}

Measured memory_bytes: 1640
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double lb;
typedef vector<int,vector<int>> vvec;
typedef long double ld;

//----***Like a Pythonista***----
#define REP(i,j,n) for (ll i=j;i<(n);i++)
#define RREP(i,n,j) for (ll i = n; j<i;i--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
inline ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }

//----***定数***----
const int MOD=1000000007;
#define INF 1e9;
#define EPS 1e-9;

//----***入出力***----
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
#define HERE  cout<<"Here"<<endl;

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}initial_;

signed main(){
  int N,K;cin>>N>>K;
  string S;cin>>S;
  int ans=0;
  REP(i,1,S.size()){
    if(S.at(i)==S.at(i-1)){ans++;}
  }
  int cnt=0,left=0,right=S.size()-1;
  while(cnt<K&&left<right){
    int bf_l=left,bf_r=right;
    while(left<right){
      left++;
      if(S.at(bf_l)!=S.at(left)){
        break;
      }
      bf_l=left;
    }
    while(left<right){
      right--;
      if(S.at(bf_r)!=S.at(right)){
        break;
      }
      bf_r=right;
    }
    if(right>left)ans+=2;
    if(left!=0&&right!=S.size()-1&&right==left&&S.at(left-1)!=S.at(right)&&S.at(left)!=S.at(right+1)) ans+=2;
    cnt++;
    if(right<=left)break;
  }
  ans=ans;
  // if(right<=left){
  //   debug(cnt);
  //   debug(right);
  //   debug(left);
  // }
  if(cnt-1<K&&right<=left&&left>0&&right<S.size()-1&&(right!=0)&&left!=S.size()-1&&(S.at(0)!=S.at(S.size()-1))){
    ans++;
  }
  print(ans)


}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if((a==b&&a!=c)||(a==c&&a!=b)||(c==b&&a!=c)) cout<<"Yes";
	else printf("No");
	return 0;
}


Measured memory_bytes: 256
using System;

namespace _042_A_Thief
{
	class Program
	{
		static void Main ( string[] args )
		{
			string inputStr;
			int processCount = 1;

			while ((inputStr = Console.ReadLine ()) != "0")
			{
				int weight = int.Parse (inputStr);
				int itemCount = int.Parse (Console.ReadLine ());
				Item[] items = new Item[itemCount + 1];

				for (int lp = 1; lp <= itemCount; lp++)
				{
					int[] input = Array.ConvertAll (Console.ReadLine ().Split (','), int.Parse);
					items[lp] = new Item (input[0], input[1]);
				}

				var result = Check (items, weight);

				Console.WriteLine ("Case " + processCount + ":");
				Console.WriteLine (result.Value + "\n" + result.Weight);

				processCount++;
			}
		}

		static Item Check ( Item[] elements, int maxWeight )
		{
			int[,] n = new int[elements.Length + 1, maxWeight + 1];
			Item maxValue = new Item (int.MinValue, int.MinValue);

			for (int index = 1; index < elements.Length; index++)
			{
				for (int weight = 1; weight <= maxWeight; weight++)
				{
					n[index, weight] = n[index - 1, weight];

					if (elements[index].Weight <= weight)
					{
						n[index, weight] =
							Math.Max (
								n[index - 1, weight],
								n[index - 1, weight - elements[index].Weight] + elements[index].Value
							);

						if (maxValue.Value < n[index,weight])
						{
							maxValue = new Item (n[index, weight], weight);
						}
						else if (maxValue.Value == n[index, weight])
						{
							if (weight < maxValue.Weight)
							{
								maxValue = new Item (n[index, weight], weight);
							}
						}
					}
				}
			}

			return maxValue;
		}

		class Item
		{
			public Item (int value,int weight)
			{
				this.Value = value;
				this.Weight = weight;
			}

			public int Value { private set; get; }
			public int Weight { private set; get; }
		}
	}
}



Measured memory_bytes: 13356
import numpy as np

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

v, aj = 0, 0
for i in a:
    tmp = i * (ai - i)
    if v < tmp:
        v = tmp
        aj = i
# print(v, aj)
print(*(ai, aj))


Measured memory_bytes: 23032
<?php
while(!feof(STDIN)) {
    $ret = fscanf(STDIN, "%d" . PHP_EOL, $input);
    if (1 === $ret) {
        $inputs[] = $input;
    }
}

foreach($inputs as $number) {
    echo pattern_count($number), PHP_EOL;
}

function pattern_count($max) {
    $pattern = 0;
    for ($a = 0; $a <=9; $a++) {
        for ($b = 0; $b <=9; $b++) {
            for ($c = 0; $c <=9; $c++) {
                for ($d = 0; $d <=9; $d++) {
                    $sum = $a + $b + $c + $d;
                    //printf('%d = %d + %d + %d + %d' . PHP_EOL, $sum, $a, $b, $c, $d);
                    if ($sum === $max) {
                        $pattern++;
                    }
                }
            }
        }
    }
    return $pattern;
}

Measured memory_bytes: 15364
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int K,N,diff=-1;
    cin>>K>>N;
    int A[N];
    for(int i=0; i<N; i++)
        cin>>A[i];
    sort(A,A+N);
    diff  = A[0]+K-A[N-1];
    for(int i=0; i<N-1; i++)
    {
        diff = max(A[i+1]-A[i],diff);
    }
    cout<<K-diff;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b ? a:b;}
ll min(ll a, ll b) {return a<b ? a:b;}


int main() {
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    
    ll ans=0;
    
    if(a+b>=c*2) {
        ans=c*2*min(x, y)+min(a, c*2)*(x-min(x, y))+min(b, c*2)*(y-min(x, y));
    }else {
        ans=a*x+b*y;
    }
    
    pt(ans);
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

int main() {
  int e;
  while (cin >> e, e != 0) {
    int m = 1000000;
    for (int z = 0; z * z * z <= e; z++) {
      int y = (int)sqrt(e - z * z * z);
      m = min(m, (e - z * z * z - y * y) + y + z);
    }

    cout << m << endl;
  }

  return 0;
}

Measured memory_bytes: 2980
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();

        System.out.println(b + Math.min(a+b+1,c));
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    int A;
    int B;
    cin >> A >> B;
    if(A != 1 && B != 1){
        cout << 1 << endl;
        return 0;
    }
    if(A != 2 && B != 2){
        cout << 2 << endl;
        return 0;
    }
    cout << 3 << endl;
    
}


Measured memory_bytes: 256
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
s = gets.chomp

ans = 0

carry = 0
flg = false
(s.size-1).downto(0).each do |i|
  n = s[i].to_i
  if n >=5 && flg
    carry += 1
  end

  n += carry
  carry = 0

  if n <= 5
    ans += n
  else
    ans += 10 - n
    carry += 1
  end
  flg = n == 5
end

puts ans + carry




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


void solve(std::string S){
  int result = 0;
  for(int i=S.size();i>0;i--) {
    for(int j=0;j+i<S.size()+1;j++) {
      string t = S.substr(j, i);
      bool a = true;
      for(int k=0;k<t.size();k++) {
        if (t[k] == 'A' || t[k] == 'T' || t[k] == 'G' || t[k] == 'C') {
          continue;
        }
        a = false;
      }
      if (!a) {
        continue;
      }
      result = i;
    }
    if (result != 0) {
      break;
    }
  }

  cout << result << endl;
}

// Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

int main(void) {
	int n;
	int hoge = 1;

	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		if (a % 2 == 0)
			hoge *= 2;
	}

	printf("%d\n", (int)pow(3, n) - hoge);

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int       long long int
#define vi        vector<int>
#define vii       vector<pii>
#define pii       pair<int, int>
#define mii       map<int, int>
#define pb        push_back
#define rev(v)    reverse(v.begin(), v.end())
#define all(v)    v.begin(), v.end()
#define rall(v)   v.rbegin(), v.rend()
#define endl      '\n'
#define F         first
#define S         second
#define PI        3.14159265359
#define MAXN      100007

const int mod = 1e9 + 7;

int dp[MAXN], arr[MAXN];
int n;

int solve(int idx)
{
   if (idx >= n)
      return INT_MAX;
   if (idx == n - 1)
      return 0;
   if (dp[idx] != -1)
      return dp[idx];

   dp[idx] = min(abs(arr[idx] - arr[idx + 1]) + solve(idx + 1), abs(arr[idx] - arr[idx + 2]) + solve(idx + 2));

   return dp[idx];
}

int32_t main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);

   memset(dp, -1, sizeof dp);
   cin >> n;
   for (int i = 0; i < n; ++i)
   {
      cin >> arr[i];
   }
   cout << solve(0) << endl;
   return 0;
}

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

using namespace std;
#define int long long
#define x first
#define y second

#define vert int v, int tl, int tr
#define tm ((tl + tr) >> 1)
#define left (v << 1), tl, tm
#define right (v << 1) + 1, tm, tr

typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;

vector<int> byh[200009];

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

    int h, w, n;
    cin >> h >> w >> n;

    vector<pii> a(n);
    int y = 1;

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

    for (int i = 1; i <= h; i ++) {
        sort(byh[i].begin(), byh[i].end());
    }

    for (int i = 1; i <= w; i ++) {
        byh[h + 1].push_back(i);
    }

    for (int i = 1; i <= h; i ++) {
        auto ret = upper_bound(byh[i + 1].begin(), byh[i + 1].end(), y) - byh[i + 1].begin();
        if (ret > 0) {
            cout << i;
            return 0;
        }

        if (ret == byh[i + 1].size() || byh[i + 1][ret] != y + 1) {
            y++;
        }
    }

    return 0;
}


Measured memory_bytes: 16504
N = int(input())
ABa = []
ans = 0
for i in range(N):
    a, b = list(map(int, input().split()))
    ABa.append(a+b)
    ans -= b
ABa.sort(reverse = True)
for i in range(N):
    if i % 2 == 0:
        ans += ABa[i]
print(ans)

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

int main() 
{
	ll l , r;
	cin >> l >> r;
	if(r-l>2020)
		cout << 0;
	else
	{
		ll ans = 2019*2019 ;
		for(ll i = l ; i <= r ; i++)
			for(ll j = i+1 ; j <= r ; j++)
				ans = min(ans,((i%2019)*(j%2019))%2019);
		cout << ans;
	}
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        long[] dist = new long[N+1];
        final long inf = Long.MAX_VALUE/2;
        Arrays.fill(dist,inf);
        dist[1]=0;
        ArrayList<Edge>[] map = new ArrayList[N+1];
        for(int i=0;i<=N;i++) map[i]=new ArrayList<>();
        for(int i=0;i<M;i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            long c = (-1)*sc.nextLong();
            map[a].add(new Edge(b,c));
        }
        for(int pass=1;pass<N;pass++){ // do N-1 pass. if no negative cycle, already finished for all vertice
            for(int ver = 1;ver<=N;ver++){
                if(dist[ver]==inf) continue;
                for(int i=0;i<map[ver].size();i++){
                    Edge e = map[ver].get(i);
                    if(dist[e.to]>dist[ver]+e.weight) dist[e.to]=dist[ver]+e.weight;
                }
            }
        }

        long ans = dist[N]*(-1);

        boolean[] neg = new boolean[N+1];
        for(int pass=1;pass<=N;pass++){
            for(int ver=1;ver<=N;ver++){
                if(dist[ver]==inf) continue;
                for(int i=0;i<map[ver].size();i++){
                    Edge e = map[ver].get(i);
                    if(dist[e.to]>dist[ver]+e.weight){
                        dist[e.to]=dist[ver]+e.weight;
                        neg[e.to] = true;
                    }
                    if(neg[ver]) neg[e.to]=true;
                }
            }
        }
        if(neg[N]) System.out.println("inf");
        else System.out.println(ans);
    }
    static class Edge {
        int to;
        long weight;
        public Edge(int t, long w){
            this.to = t;
            this.weight = w;
        }
    }
}


Measured memory_bytes: 29992
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>

#define ll long long
#define ull unsigned long long

using namespace std;

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

	int len = S.size();

	string sol = "";
	for (int ii = 0; ii < len; ++ii){
		sol += 'x';
	}

	cout << sol << endl;

	return 0;
}


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

int main(){
    int N, K; cin >> N >> K;
    int A[N];
    for(int i = 0; i < N; i++) cin >> A[i];
    
    // int ans = (N - 1) / (K - 1);
    // ans += (N - 1) %  (K - 1);
    int ans = 0;
    for(int i = 0; i < (N - 1); i += (K - 1)){
        ans++;
    }

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

Measured memory_bytes: 640
while True:
    a,op,b = input().split()
    a = int(a)
    b = int(b)
    if op == '+':
        print(a+b)
    elif op == '-':
        print(a-b)
    elif op == '*':
        print(a*b)
    elif op == '/':
        print(int(a/b))
    if op == '?':
        break


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

int most_right_white(char *c,int N,int b){
	for(int i=b; i<N; i++){
		if(c[i]=='R')
			continue;
		if(c[i]=='W')
			return i;
	}
	return N-1;
}

int most_left_red(char *c, int N, int t){
	for(int i=t; i>=0; i--){
		if(c[i]=='W')
			continue;
		if(c[i]=='R')
			return i;
	}
	return 0;
}
 
int main() {
	int N;
	cin >> N;
	char c[N];
	for(int i=0; i<N; i++){
		cin >> c[i];
	}

	int count = 0;
	int b = most_right_white(c,N,0);
	int t = most_left_red(c,N,N-1);
	while(b<t){
		char tmp = c[b];
		c[b] = c[t];
		c[t] = tmp;
		count++;
		b = most_right_white(c,N,b);
		t = most_left_red(c,N,t);
	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3768
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <set>
#define Inf 111111111111111ll
#define ll long long
using namespace std;


bool HasBit(int m,int pos) {
    return ((m>>pos)&1);
}


int main() {
    string S;
    cin>>S;
    
    
    
    int mask = 0;
    
    string ans;
    
    while(1) {
        
        if (ans.compare(S)>0) {
            cout << ans << endl;
            return 0;
        }
        
        int copt=-1;
        for(int c=0;c<26;c++) {
            if (HasBit(mask,c))
                continue;
            string cand = ans;
            cand.push_back(c+'a');
            
            for(int cc=25;cc>=0;cc--) {
                if (!HasBit(mask,cc) && cc != c)
                    cand.push_back(cc+'a');
            }
            if (cand.compare(S)>0) {
                copt=c;
                break;
            }
        }
        
        
        if (copt==-1)
            break;
        
        ans.push_back(copt+'a');
        mask |= (1<<copt);

        
    }
    
    cout << -1 << endl;
    return 0;
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD =1e9+7;
using ll=long long;
using Graph = vector<vector<int>>;

int main() {
    ll q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    s = min({s, q*4, h*2});
    d = min(2*s, d);
    cout << n/2 * d + n%2*s << endl;
}

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

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

Measured memory_bytes: 256
#define _USE_MATH_DEFINES  

#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>

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

    std::vector<int> vec(n);

    for(int i = 0; i < n; ++i){
        std::cin >> vec.at(i);
    }

    std::reverse(vec.begin(), vec.end());

    for(int i = 0; i < n; ++i){
        std::cout << vec.at(i);
        if(i < n - 1){
            std::cout << " ";
        }else{
            std::cout << std::endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
 
using namespace std;
 
int main()
{
    long long int h,w;
    cin >> h >> w;
    long long int tmp = h*w;
    
    if(h == 1 || w == 1){
        cout << 1 << endl;
        return 0;
    }
    if(tmp%2 == 0){
        cout << tmp/2 << endl;
    }else{
        cout << tmp/2+1 << endl;
    }
 
    return 0;
}

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

long long solve();

int main()
{
	printf("%lld\n", solve());

	return 0;
}

long long solve()
{
	long long k, a, b;
	scanf("%lld%lld%lld", &k, &a, &b);
	if (k <= a) return k + 1;
	long long sum{a};
	k -= a - 1;
	if (b - a > 2)
	{
		sum += k / 2 * (b - a);
		if (k & 1) sum++;
	}
	else
	{
		sum += k;
	}
	return sum;
}

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

int main(){
  int A = 0;
  int B = 0;
  
  cin>>A;
  cin>>B;
  
  if (B%A==0){
    cout<<A+B<<endl;
  }
  else{
    cout<<B-A<<endl;
  }
}

    


Measured memory_bytes: 384
def main():
  n, m = map(int,input().split())
  light = [[0]*n for _ in range(m)]
  for i in range(m):
    kk = list(map(int, input().split()))
    k = kk.pop(0)
    for j in range(k):
      light[i][kk[j]-1] = 1
  p = list(map(int, input().split()))

  ans = 0
  for i in range(2**n): # switchのbit
    sw = [0]*n
    for j in range(n):
      if ((i >> j) & 1):
        sw[j] = 1

    flag = True
    for j in range(m):
      cnt = 0
      for k in range(n):
        if sw[k] == 1 and light[j][k] == 1:
          cnt += 1
      if cnt % 2 != p[j]:
        flag = False
        break
    if flag:
      ans += 1
    
  print(ans)

if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
X, Y = map(int, input().split())
n = (2 * X - Y) / 3
m = (2 * Y - X) / 3

if n < 0 or m < 0 or not n.is_integer() or not m.is_integer():
    print(0)
    exit()

MOD = 10**9 + 7
class ModInt:
    def __init__(self, x):
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return (
            ModInt(self.x + other.x) if isinstance(other, ModInt) else
            ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x) if isinstance(other, ModInt) else
            ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x) if isinstance(other, ModInt) else
            ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __pow__(self, other):
        return (
            ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(self.x, other, MOD))
        )

    __radd__ = __add__

    def __rsub__(self, other):
        return (
            ModInt(other.x - self.x) if isinstance(other, ModInt) else
            ModInt(other - self.x)
        )

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return (
            ModInt(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(other * pow(self.x, MOD - 2, MOD))
        )

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(other, self.x, MOD))
        )

n, m = map(int, [n, m])
fact = [ModInt(1)]
for i in range(1, X + Y + 1):
    fact.append(fact[i-1] * i)

def cmb(n, r):
    return fact[n] / fact[n-r] / fact[r]

print(cmb(n+m, min(n, m)))


Measured memory_bytes: 245092
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    int a, b, c, d; cin >> a >> b >> c >> d;
    if (a+b>c+d) cout << "Left" << endl;
    else if (a+b==c+d) cout << "Balanced" << endl;
    else cout << "Right" << endl;
}

Measured memory_bytes: 3640
#include<iostream>
using namespace std;
int main(){
	int x[6];
	cin >> x[1] >> x[2] >> x[3] >> x[4] >> x[5];
	for (int i = 0; i < 6; i++) {
		if (x[i] == 0) {
			cout << i << endl;
		}
	}
}

Measured memory_bytes: 3620