akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 100100;

void solve() {
	ll n,ans=0;
	cin>>n;
	vll A(n); for(int i=0;i<n;i++) cin>>A[i],A[i]--;
	ll x=0;
	bool f=true;
	vector<bool> vis(n);
	while(1) {
		ans++;
		if(vis[A[x]]) {f=false;break;}
		x=A[x];vis[x]=true;if(x==1) break;
	}
	if(f) cout<<ans;
	else cout<<-1;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;
//	pre();
//	ll t;cin>>t;while (t--)
	solve();

}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    ll ans = 0;
    if(a + b >= c){
        ans = b + c;
    }else{
        ans = a + 2*b + 1;
    }
    cout << ans << endl;

    return 0;
}

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

void printArray(int A[], int N)
{
    for (int i = 0; i < N; i++) {
        cout << A[i];
        if (i != N - 1) {
            cout << ' ';
        }
    }
    cout << endl;
}

int selectionSort(int A[], int N){
    int minj;
    int sw = 0;
    for (int i = 0; i < N; i++) {
        minj = i;
        for (int j = i; j < N; j++) {
            if (A[j] < A[minj]) {
                minj = j;
            }
        }
        if (i != minj) {
            sw++;
        }

        swap(A[i], A[minj]);
    }
    return sw;
}

int main() {
    int A[100], N, i, sw;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sw = selectionSort(A, N);
    printArray(A, N);
    cout << sw << endl;
    return 0;
}

Measured memory_bytes: 3108
#include<cstdio>

using namespace std;

long long a[100100], b[100100];
int N;

long long solve(){
	long long sum = 0;
	for(int i = N - 1; i >= 0; --i){
		long long tmp = a[i] + sum;
		tmp %= b[i];
		long long cur = tmp == 0 ? 0 : (b[i] - tmp);
		sum += cur;
	}
	return sum;
}

void input(){
	scanf("%d", &N);
	for(int i = 0; i < N; ++i){
		scanf("%lld%lld", a + i, b + i);
	}
}

int main(){
	input();
	long long ans = solve();
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#define rep(i,j,k) for(register int i = j; i <= k; i++) 
#define dow(i,j,k) for(register int i = j; i >= k; i--)
#define fi first
#define se second
//#define P pair<ull,ull>
//#define PP pair<int,pair<int,int> >
//#define mp(a,b) make_pair(a,b)
#define ll long long
#define ull unsigned long long
using namespace std;
 
inline int read() { 
	int s = 0, t = 1; char c = getchar();
	while( !isdigit(c) ) { if( c == '-' ) t = -1; c = getchar(); }
	while( isdigit(c) ) s = s * 10 + c - 48, c = getchar();
	return s * t;
}

const int M = 4e4+5, N = 16, inf = 1e9+7; 
int n, f[N][M], g[N][M], h[M], ti[M], now;
inline void Min(int &x,int v) { if( x > v ) x = v; }
#define lower(x) (x & -x)
inline int Q(int x) { 
	if( ti[x] == now ) return h[x];
	return ti[x] = now, h[x] = h[lower(x)] + Q(x^lower(x)); 
}

int main() {
	n = read();
	int m = read(), x, y, v;
	rep(i,1,m) { 
		x = read() - 1, y = read() - 1, v = read();
		g[x][1<<y] += v;
		g[y][1<<x] += v;
	}
	rep(i,0,n-1) { 
		rep(j,1,(1<<n)-1) { 
			g[i][j] = g[i][j^lower(j)] + g[i][lower(j)];
		}
	}
	rep(i,0,n-1) rep(j,0,(1<<n)-1) f[i][j] = inf;
	f[0][1] = 0;
	rep(j,1,(1<<n)-1) { 
		rep(i,0,n-1) { 
			if( f[i][j] != inf ) { 
				x = (1<<n) - 1 - j;
				now++;
				rep(k,0,n-1) if( (x >> k) & 1 ) h[1<<k] = g[k][j^(1<<i)], ti[1<<k] = now;
				for(register int k = x; k; k=(k-1)&x) Min(f[i][k|j],f[i][j]+Q(k));
				rep(k,0,n-1) if( !((j >> k) & 1) && g[i][1<<k] ) Min(f[k][j|1<<k],f[i][j]+g[k][j^(1<<i)]);
			} 
		}
	}
	cout<<f[n-1][(1<<n)-1]<<endl;
	return 0; 
}

Measured memory_bytes: 4864
S = input()
 
n = len(S)
S_list = [int(S[0]), int(S[1]), int(S[2]), int(S[3])]
 
#1... -  0...+
def bit_to_notation(bit):
  bitlist = [0 for i in range(n-1)] 
  for i in range(n-1):
    if ((bit >> i) & 1):
      bitlist[n-2-i] = "+"
    else:
      bitlist[n-2-i] = "-"
  return bitlist
 
notation = 2 ** (n-1)
for bit in range(notation):
  sum4 = S_list[0]
  for j in range(n-1):
    if((bit >> j) & 1):
      sum4 += S_list[n-1-j]
    else:
      sum4 -= S_list[n-1-j]
      
  if(sum4 == 7):
    
    bitlist = bit_to_notation(bit)
    print(str(S_list[0]) + bitlist[0] + str(S_list[1]) + bitlist[1] 
          + str(S_list[2]) + bitlist[2] + str(S_list[3]) + "=7")
    break

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

struct UnionFind {
	vector<int>d;

	UnionFind(int N) :d(N, -1) {}

	int find(int x) {
		if (d[x] < 0)return x;
		return d[x] = find(d[x]);
	}
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return false;
		if (d[x] > d[y])swap(x, y);
		d[x] += d[y];
		d[y] = x;
		return true;
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return -d[find(x)];
	}
};

int main() {
	init();

	int N, M; cin >> N >> M;
	vector<int>vec(N);
	rep(i, 0, N)cin >> vec[i];

	UnionFind uf(N);
	rep(i, 0, M) {
		int a, b; cin >> a >> b;
		--a; --b;
		uf.unite(a,b);
	}
	int ans = 0;
	rep(i, 0, N) {
		if (uf.same(vec[i] - 1, i))++ans;
	}
	cout << ans << "\n";

	return 0;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;


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

    int n = s.size();
    int a = 0, b = 0, c = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'a') a++;
        if(s[i] == 'b') b++;
        if(s[i] == 'c') c++;
    }

    // 各文字の出現回数の差が1以下であれば良い
    // 同じ文字が2余るとアウト
    if(abs(a - b) <= 1 && abs(b - c) <= 1 && abs(a - c) <= 1) {
        cout << "YES" << endl;
        return 0;
    }


    cout << "NO" << endl;

    return 0;
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int

int main()
{
  int n, m;
  cin >> n >> m;
  int k[m];
  vector<vector<int>> s(m);
  rep(i, m)
  {
    cin >> k[i];
    rep(j, k[i])
    {
      int a;
      cin >> a;
      s[i].push_back(a);
    }
  }
  int p[m];
  rep(i, m)
  {
    cin >> p[i];
  }
  int ans = 0;
  for (int bit = 0; bit < (1 << n); ++bit)
  {
    vector<int> S;
    bool flag=true;
    for (int i = 0; i < n; ++i)
    {
      if (bit & (1 << i))
      { // 列挙に i が含まれるか
        S.push_back(1);
      }
      else
      {
        S.push_back(0);
      }
    }
    for (int j = 0; j < m; j++)
    {
      int count = 0;
      rep(q,k[j]){
if(S[s[j][q]-1]){
  count++;
}
      }
      if(count%2!=p[j]){
        flag=false;
      }
    }
  if(flag){
    ans++;
  }
  
  }

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


Measured memory_bytes: 256
N = int(input())
A, B = map(int, input().split())
P = list(map(int, input().split()))
P1 = [p for p in P if p <= A]
P2 = [p for p in P if A < p <= B]
P3 = [p for p in P if B < p]
print(min(len(P1), len(P2), len(P3)))

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

int main(int argc, char const *argv[]) {
    int A, B;
    cin >> A >> B;
    if (A > B) cout << A + A -1 << endl;
    else if (A < B) cout << B + B -1 << endl;
    else cout << A + B << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c=1,i;
int main()
{
    cin>>a>>b;
    for(i=0;i<a;i++)
	{
        if(c>b)
		    c+=b;
        else 
		    c*=2;
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
dp = [[0] * 3 for _ in range(N)]
dp[0][0], dp[0][1], dp[0][2] = map(int, input().split())
for i in range(1,N):
    a, b, c= map(int, input().split())
    dp[i][0] = max(dp[i-1][1]+a,dp[i-1][2]+a)
    dp[i][1] = max(dp[i-1][0]+b,dp[i-1][2]+b)
    dp[i][2] = max(dp[i-1][1]+c,dp[i-1][0]+c)
print(max(dp[N-1]))

Measured memory_bytes: 22796
#include<cstdio>
#include<cstring>
#define min(a,b) (a<b?a:b)
int main()
{
	char a[55],b[55];
	scanf("%s\n%s",a+1,b+1);
	int lena=strlen(a+1);
	int lenb=strlen(b+1);
	for(int i=1;i<=min(lena,lenb);i++){
		printf("%c%c",a[i],b[i]);
	}
	if(lena>lenb){
		printf("%c",a[lena]);
	}
	puts("");
	return 0;
}

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

#define loop(i, n) for(int i = 0;i < n;i++)

int main(void){

    string str;
    cin >> str;

    if(str.back()-'0' == 2 || str.back()-'0' == 4 || str.back()-'0' == 5 || str.back()-'0' == 7 || str.back()-'0' ==  9) cout << "hon" << endl;
    else if(str.back()-'0' == 0 || str.back()-'0' == 1 || str.back()-'0' == 6 || str.back()-'0' == 8) cout << "pon" << endl;
    else cout << "bon" << endl;

    return 0;
}

Measured memory_bytes: 3628
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

//# include <ext/pb_ds/assoc_container.hpp>
//# include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;
using namespace std;
 
//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;
//	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//	shuffle(permutation.begin(), permutation.end(), rng);



int main () {
	SpeedForce;
	
	int a, b, c;
	cin >> a >> b >> c;

	swap(a, b);
	swap(a, c);

	cout << a << ' ' << b << ' ' << c << '\n';

	return Accepted;
}

// B...a

Measured memory_bytes: 18688
def get_carrot() :
    global speed, stock, U, K, i, T, accel_time
    if speed == U :
        speed = V
        accel_time = T
    elif stock == K :
        accel_time = T
    else :
        stock += 1
    i += 1

def accel_time_end() :
    global stock, accel_time, T, U, speed
    if stock > 0 :
        accel_time += T
        stock -= 1
    else :
        speed = U

N, K, T, U, V, L = map(int, input().split())
carrot=[]
for i in range(N) :
    carrot.append(int(input()))

stock = 0
time = 0
accel_time = 0
i = 0
speed = U
now = 0

while True :
    if i < N :
        if accel_time == 0 :
            time += (carrot[i] - now) / speed
            now = carrot[i]
            get_carrot()
            
        elif (carrot[i] - now) < accel_time * speed :
            time_tmp = (carrot[i] - now) / speed
            time += time_tmp
            accel_time -= time_tmp
            now = carrot[i]
            get_carrot()
        
        elif accel_time * speed < (carrot[i] - now) :
            now += accel_time * speed
            time += accel_time
            accel_time = 0
            accel_time_end()
        
        elif  accel_time * speed == (carrot[i] - now) :
            now = carrot[i]
            time += accel_time
            accel_time = 0
            accel_time_end()
            get_carrot()
        
    else :
        if ( accel_time * speed < L - now ) and accel_time != 0:
            now += accel_time * speed
            time += accel_time
            accel_time = 0
            accel_time_end()
        else :
            time += (L - now) / speed
            now += (L - now)
            print('{:.10f}'.format(time))
            break


Measured memory_bytes: 5632
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

double binom(int m,int k,double p)
{
	double x=pow(p,k)*pow(1-p,m-k);
	for(int i=0;i<k;i++)
		x*=(m-i)/(i+1.);
	return x;
}

int main()
{
	for(int n,m,L;cin>>n>>m>>L;){
		vector<double> ps(n);
		vector<int> ts(n),vs(n);
		for(int i=0;i<n;i++) cin>>ps[i]>>ts[i]>>vs[i],ps[i]/=100;
		
		vector<vector<double>> ss(n,vector<double>(m+1));
		for(int i=0;i<n;i++)
			for(int j=0;j<=m;j++)
				ss[i][j]=binom(m,j,ps[i]);
		
		vector<double> res(n);
		for(int i=0;i<n;i++)
			for(int j=0;j<=m;j++){
				double temp=1;
				for(int k=0;k<n;k++) if(k!=i){
					double win=0;
					for(int l=0;l<=m;l++)
						// l/vs[i]+j*ts[i] < l/vs[k]+l*ts[k]
						if((L+j*ts[i]*vs[i])*vs[k]<(L+l*ts[k]*vs[k])*vs[i])
							win+=ss[k][l];
					temp*=win;
				}
				res[i]+=ss[i][j]*temp;
			}
		
		for(int i=0;i<n;i++)
			printf("%.8f\n",res[i]);
	}
}

Measured memory_bytes: 1384
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int infI=1e9+5;
const long long infL=1e16;
const int MOD=998244353;
const int MAX=2e5+5;

#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define iii pair<ii,int>
#define ll long long
#define pll pair<ll,ll>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define forn(i,a,b) for(ll i=a;i<b;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define endl '\n'
#define popb pop_back()
#define se second
#define fi first
#define test(t) int t;cin>>t;while(t--)
#define debug(x) cerr<<"=>"<<#x<<" = "<<x<<endl

ll power(ll a,ll b){
    if(b==0){
        return 1;
    }
    if(b==1){
        return a;
    }
    ll temp=power(a,b/2);
    temp=(temp*temp)%MOD;
    if(b%2){
        temp=(temp*a)%MOD;
    }
    return temp;
}

//only use if mod is prime
ll mod_inv(ll a,ll mod){
    a%=mod;
    return power(a,mod-2);
}

void extended_gcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return;
    }
    ll x1,y1;
    extended_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-((a/b)*y1);
    return;
}

//TLE can also occur if vectors are not passed by reference, debug statements can also cause TLE.
//priority_queue implements max heap by default

int main(){
    fastio;
    // think about edge cases like n=1(especially graph questions).
    int n,s;
    cin>>n>>s;
    ll ans = 0;
    vl dp(s+1,0);
    dp[0]=1;
    forn(i,0,n){
        int a;
        cin>>a;
        vl tmp(s+1,0);
        for(int j = s;j>=0;--j){
            tmp[j] += 2*dp[j];
            tmp[j]%=MOD;
            if(j+a<=s){
                tmp[j+a]+=dp[j];
                tmp[j+a]%=MOD;
            }
        }
        dp = tmp;
    }
    cout<<dp[s];
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>

using namespace std;

typedef pair<bool,int>P;
const int MAX = 3000001;
int N,Q,maxi,mini;
P data[MAX];

void make(){
  int now = 0;
  for(int i = 0; i <= maxi; i++){
    data[i].second = now;
    if(data[i].first) now = i;
  }
}

void input(){
  cin >> N >> Q;
  
  for(int i = 0; i < N; i++){
    int n;
    scanf("%d",&n);
    data[n].first = true;
    maxi = max(maxi,n);
    mini = min(mini,n);
  }
}

int getans(int q){
  if(q == 1) return 0;
  int start = mini;
  while(start%q){
    start -= start%q;
    start += q;
  }

  int ans = 0;

  for(int i = start; i <= maxi; i+=q){
    if(ans == q-1) return ans;
    ans = max(ans,data[i].second%q);
  }
  return max(ans,maxi%q);
}

void solve(){

  for(int i = 0; i < Q; i++){
    int q;
    scanf("%d",&q);
    printf("%d\n",getans(q));
  }
}

int main(){

  maxi = 0;
  mini = MAX;

  input();
  make();
  solve();

  return 0;
}

Measured memory_bytes: 24664
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int>W(N);
  for(int i=0;i<N;i++){
    cin>>W.at(i);
  }
  int ans=1e9;
  for(int i=1;i<N;i++){
    int l=0,r=0;
    for(int j=0;j<i;j++){
      l+=W.at(j);
    }
    for(int j=i;j<N;j++){
      r+=W.at(j);
    }
    ans=min(ans,abs(l-r));
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3624
use std::io;
use std::str::FromStr;

fn get_parms<T: FromStr>() -> Vec<T>
where
    <T as FromStr>::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).expect("stdin error");
    return buf.split_whitespace().map(|x| x.parse().unwrap()).collect();
}

fn main() {
    let vec = get_parms::<f64>();
    let r = vec[0];
    println!(
        "{:.6} {:.6}",
        std::f64::consts::PI * r * r,
        std::f64::consts::PI * 2.0 * r
    );
}



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

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

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

template <typename T>
int getFormer(const vector<T> &vec, T x) {
    return upper_bound(vec.begin(), vec.end(), x) - vec.begin() - 1;
}

template <typename T>
int getLatter(const vector<T> &vec, T x) {
    return lower_bound(vec.begin(), vec.end(), x) - vec.begin();
}

long long check(long long mid, const vector<long long>& acc) {
    int N = acc.size() / 2;
    for (int i = 0; i < N; i++) {
        int j = lower_bound(acc.begin() + i, acc.begin() + i + N + 1, acc[i] + mid) - acc.begin();
        int k = lower_bound(acc.begin() + j, acc.begin() + i + N + 1, acc[j] + mid) - acc.begin();
        if (acc[j] - acc[i] < mid || acc[k] - acc[j] < mid || acc[i + N] - acc[k]< mid) continue;

        return true;
    }

    return false;
}

int main() {
    int N;
    cin >> N;
    vector<long long> acc(2 * N + 1, 0);
    REP(i, N) {
        cin >> acc[i + 1];
        acc[i + N + 1] += acc[i + 1];
    }
    REP(i, 2 * N) {
        acc[i + 1] += acc[i];
    }

    long long lb = -1, ub = (acc[N]) / 3 + 1;
    while (ub - lb > 1) {
        long long mid = (ub + lb) / 2;
        if (check(mid, acc)) {
            lb = mid;
        } else {
            ub = mid;
        }
    }

    cout << lb << endl;
    return 0;
}


Measured memory_bytes: 4420
#include "stdio.h"
#include "malloc.h"

#define min(X, Y) ((X) < (Y) ? (X) : (Y))

int main()
{
    int N,K,i;
    scanf("%d %d",&N,&K);
    long long *arr = malloc(N*sizeof(long long));
    long long *dp = malloc(N*sizeof(long long));
    for(i=0;i<N;i++)
    {
        scanf("%lld",arr+i);
        dp[i] = __LONG_LONG_MAX__;
    }

    dp[N-1] = 0;

    dp[N-2] = abs(arr[N-1] - arr[N-2]);

    i = N-3;

    while(i>=0)
    {
        for(int k=i+1;k<min(i+K+1,N);k++)
            dp[i]=min(dp[i],dp[k]+abs(arr[i]-arr[k]));
        i--;
    }
    printf("%lld",dp[0]);
    return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		Digital digital;
		
		while(true){
			line = br.readLine();
			int num = Integer.valueOf(line);
			if(num == -1){
				break;
			}
			digital = DigitalType.NN.getDigital();

			int sig;
			Digital digNum;
			for(int i = 0; i < num; i++){
				line = br.readLine();
				sig = Integer.valueOf(line);
				
				digNum = DigitalType.getDigitalFromNumber(sig);
				System.out.println(getDiffSignal(digital, digNum));
				digital = digNum;
			}
		}
	}
	
	private static String getDiffSignal(Digital dig1, Digital dig2){
		String result = "";
		result = result + getDiff(dig1.getG(), dig2.getG());
		result = result + getDiff(dig1.getF(), dig2.getF());
		result = result + getDiff(dig1.getE(), dig2.getE());
		result = result + getDiff(dig1.getD(), dig2.getD());
		result = result + getDiff(dig1.getC(), dig2.getC());
		result = result + getDiff(dig1.getB(), dig2.getB());
		result = result + getDiff(dig1.getA(), dig2.getA());
		return result;
	}
	
	private static String getDiff(int num1, int num2){
		if(num1 == num2){
			return "0";
		}else{
			return "1";
		}
	}
	
	private enum DigitalType{
		NN(-1, "00000000"),
		N0(0, "0111111"),
		N1(1, "0000110"),
		N2(2, "1011011"),
		N3(3, "1001111"),
		N4(4, "1100110"),
		N5(5, "1101101"),
		N6(6, "1111101"),
		N7(7, "0100111"),
		N8(8, "1111111"),
		N9(9, "1101111");

		private int number;
		private Digital digital;
		
		DigitalType(int number, String signal){
			this.number = number;
			this.digital = new Digital(signal);
		}
		
		public Digital getDigital(){
			return digital;
		}
		
		public int getNumber() {
			return number;
		}

		public static Digital getDigitalFromNumber(int num){
			for(DigitalType type : DigitalType.values()){
				if(type.getNumber() == num) return type.getDigital();
			}
			return null;
		}
	}
	
	private static class Digital {
		Integer g = 0,f = 0,e = 0,d = 0,c = 0,b = 0,a = 0;
		
		public Digital(String sig){
			setSignal(sig);
		}
		
		public void setSignal(String sig){
			String[] nums = sig.split("");
			g = getNumber(g, Integer.parseInt(nums[0]));
			f = getNumber(f, Integer.parseInt(nums[1]));
			e = getNumber(e, Integer.parseInt(nums[2]));
			d = getNumber(d, Integer.parseInt(nums[3]));
			c = getNumber(c, Integer.parseInt(nums[4]));
			b = getNumber(b, Integer.parseInt(nums[5]));
			a = getNumber(a, Integer.parseInt(nums[6]));
		}
		
		private int getNumber(Integer target, Integer num){
			if(target == 0){
				if(num == 1) return 1;
			}else{
				if(num == 1) return 0;
			}
			return target;
		}

		public Integer getG() {
			return g;
		}

		public Integer getF() {
			return f;
		}

		public Integer getE() {
			return e;
		}

		public Integer getD() {
			return d;
		}

		public Integer getC() {
			return c;
		}

		public Integer getB() {
			return b;
		}

		public Integer getA() {
			return a;
		}
	}

}

Measured memory_bytes: 24948
// 問題: 4つの袋からコインを1枚ずつ取り出してちょうどV円になる組み合わせを求める
// 解法: 2つの袋から作れる金額の組み合わせを総当たりで作成し、組み合わせる

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

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

#define pb push_back
#define mp make_pair

map<ll, ll> make_map(vector<ll>& As) {
    map<ll, ll> ret;
    for(auto a: As) ++ret[a];
    return ret;
}

map<ll, ll> make_combination(map<ll, ll>& As, map<ll, ll>& Bs) {
    map<ll, ll> ret;
    for(auto a: As) {
        for(auto b: Bs) {
            auto val = a.first + b.first;
            auto cnt = a.second * b.second;
            ret[val] += cnt;
        }
    }
    return ret;
}

ll coin_combination(ll N, ll V,
                    vector<ll>& As, vector<ll>& Bs,
                    vector<ll>& Cs, vector<ll>& Ds) {
    auto Amap = make_map(As);
    auto Bmap = make_map(Bs);
    auto Cmap = make_map(Cs);
    auto Dmap = make_map(Ds);
    auto ABmap = make_combination(Amap, Bmap);
    auto CDmap = make_combination(Cmap, Dmap);

    ll ret = 0;
    for (auto ab: ABmap) {
        auto val = ab.first;
        auto cnt = ab.second;
        // cout << "val, cnt = " << val << "," << cnt << endl;
        if (CDmap.count(V - val)) {
            ret += cnt * CDmap[V - val];
        }
    }

    return ret;
}

int main() {
    ll N, V;
    cin >> N >> V;
    vector<ll> As(N);
    vector<ll> Bs(N);
    vector<ll> Cs(N);
    vector<ll> Ds(N);
    REP(n, N) cin >> As[n];
    REP(n, N) cin >> Bs[n];
    REP(n, N) cin >> Cs[n];
    REP(n, N) cin >> Ds[n];
    cout << coin_combination(N, V, As, Bs, Cs, Ds) << endl;

    return 0;
}



Measured memory_bytes: 128352
w,h,n = map(int,input().split())
xmin, ymin = 0,0
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        if xmin < x:
            xmin = x
    elif a == 2:
        if w > x:
            w = x
    elif a == 3:
        if ymin < y:
            ymin = y
    else:
        if h > y:
            h = y
        
s = (w-xmin)*(h-ymin)
if (w-xmin) <= 0 or (h-ymin) <= 0:
    print(0)
else:
    print(s)

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e9;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 20000;
constexpr ll nx[4] = {1,0,-1,0};
constexpr ll ny[4] = {0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<bool> done(n,0);
    cins(all(a));
    int cnt = 0;
    rep(i,n){
        if ((done[i] == 0) && (a[a[i]-1]-1 == i)){
            cnt++;
            done[i] = 1;
            done[a[i]-1] = 1;
        }
    }
    PRINT(cnt);
}


Measured memory_bytes: 1024
#include <iostream>
#include <complex>

const double tol = 1e-15;

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

  for (int i = 0; i < q; ++i) {
    double x0, y0, x1, y1, x2, y2, x3, y3;
    std::cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

    double ip = (x1 - x0) * (x3 - x2) + (y1 - y0) * (y3 - y2);
    double norm1 = std::sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
    double norm2 = std::sqrt((x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2));
    double theta = ip / norm1 / norm2;

    int result = 0;
    if (std::abs(theta) < tol) {
      result = 1;
    } else if (std::abs(theta) > 1 - tol) {
      result = 2;
    }

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

  return 0;
}


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

namespace Program
{
    class D
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var line = Console.ReadLine();
            int ret=0, r = 0, w = N-1;
            bool rfind = false, wfind = false;
            for (int i = 0; i < N;i++)
            {
                if (r >= w)
                {
                    break;
                }
                rfind = line[r] == 'W';
                wfind = line[w] == 'R';

                if (rfind && wfind)
                {
                    ret++;
                    r++;
                    w--;
                }
                if (! rfind) { r++; }
                if (! wfind) { w--; }
            }
            Console.WriteLine(ret);
        }
    }
}


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

using namespace std;

#define INF ((int64_t)2e18)
#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define Matrix vector<vector<int>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 3;

signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, m;

  cin >> n >> m;

  vector<int> arr(n + m);
  for (int i = 0; i < n; i++)
    arr[i] = 0;
  for (int i = n; i < n + m; i++)
    arr[i] = 1;

  int ans = 0;
  for (int i = 0; i < arr.size(); i++) {
    for (int j = i + 1; j < arr.size(); j++) {
      ans += (((arr[i] + arr[j]) & 1) == 0);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a==5&&b==7&&c==5||a==5&&b==5&&c==7||a==7&&b==5&&c==5){
   cout << "YES" << endl;}
   else{
       cout << "NO" << endl;
   }

}

Measured memory_bytes: 256
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}

}

use input::*;

fn dfs(g: &Vec<Vec<usize>>, from: usize, to: usize, remain: usize) -> bool {
    if remain == 0 {
        if to == from {
            return true;
        }
        return false;
    }

    for z in &g[from] {
        if dfs(g, *z, to, remain - 1) {
            return true;
        }
    }
    false
}

fn main() {
    let (n, m): (usize, usize);
    input!(n, m);
    let mut graph = vec![Vec::new(); n];
    for _ in 0..m {
        let (a, b): (usize, usize);
        input!(a, b);
        graph[a - 1].push(b - 1);
        graph[b - 1].push(a - 1);
    }

    if dfs(&graph, 0, n - 1, 2) {
        p("POSSIBLE");
    } else {
        p("IMPOSSIBLE");
    }
}

Measured memory_bytes: 18684
n, k = map(int, input().split())
x = map(int, input().split())
a = [0]
b = [0]
for x_ in x:
    if x_ >= 0:
        a.append(x_)
    else:
        b.append(abs(x_))

a.sort()
b.sort()

res = float('inf')
for i in range(k+1):
    try:
        res = min(res, a[i]+2*b[k-i], 2*a[i]+b[k-i])
    except:
        continue

print(res)

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

int main() {
    int n;
    cin >> n;
    vector<int> atm;
    atm.push_back(1);
    int r = 1;
    while (r * 6 <= n) {
        r *= 6;
        atm.push_back(r);
    }
    r = 1;
    while (r * 9 <= n) {
        r *= 9;
        atm.push_back(r);
    }
    int m = atm.size();
    sort(atm.begin(), atm.end());
    vector<vector<int>> dp(m, vector<int>(n+1));
    rep(i, m) {
        rep(j, n+1) {
            if (i == 0) {
                dp[i][j] = j;
            } else {
                dp[i][j] = dp[i-1][j];
                if (j-atm[i] >= 0) {
                    dp[i][j] = min(dp[i][j], dp[i-1][j-atm[i]]+1);
                    dp[i][j] = min(dp[i][j], dp[i][j-atm[i]]+1);
                }
            }
        }
    }
    cout << dp[m-1][n] << endl;
}

Measured memory_bytes: 8224
def loadIcicle():
	icicles = []
	line = input().strip().split(" ")
	N, L = int(line[0]), int(line[1])
	while True:
		icicles.append(int(input().strip()))
		if len(icicles) == N: break
	return icicles, N, L
icicles, N, L = loadIcicle()

def calcDiff(icicles, N):
	diff_2times = [0]*N

	for idx in range(N):
		dif_right = icicles[idx+1] - icicles[idx] if idx != N-1 else -icicles[idx]
		dif_left = icicles[idx] - icicles[idx-1] if idx != 0 else icicles[idx]

		dif_right = 1 if dif_right > 0 else -1
		dif_left = 1 if dif_left > 0 else -1

		if dif_right - dif_left < 0: diff_2times[idx] = -1
		elif dif_right - dif_left > 0: diff_2times[idx] = 1
		else: diff_2times[idx] = 0

	return diff_2times

diff_2times = calcDiff(icicles, N)

time = [-1]*N
peakX = [i for i in range(N) if diff_2times[i]==-1]
for i in peakX:
	time[i] = L - icicles[i]

	isLocalMinL, isLocalMinR = False, False
	posL = i
	posR = i
	while not (isLocalMinL and isLocalMinR):
		posL -= 1
		if posL < 0:
			isLocalMinL = True
		if not isLocalMinL:
			if time[posL] == -1:
				time[posL] = (L-icicles[posL]) + time[posL+1]
			else:
				time[posL] = (L-icicles[posL]) + max(time[posL-1], time[posL+1])

			if diff_2times[posL] == 1:
				isLocalMinL = True

		posR += 1
		if posR >= N:
			isLocalMinR = True
		if not isLocalMinR:
			if time[posR] == -1:
				time[posR] = (L-icicles[posR]) + time[posR-1]
			else:
				time[posR] = (L-icicles[posR]) + max(time[posR-1], time[posR+1])

			if diff_2times[posR] == 1:
				isLocalMinR = True
print(max(time))

Measured memory_bytes: 17820
import java.util.*

data class Edge(val from: Int, val to: Int, val weight: Long) {
    constructor(from: Long, to: Long, weight: Long) : this(from.toInt(), to.toInt(), weight)
}

class Graph(val n: Int) {
    val edges = Array(n) { ArrayList<Edge>() }
}

val INF = 1e+15.toLong()

fun bellmanFord(g: Graph, s: Int): Triple<Array<Long>, Array<Int>, Array<Boolean>> {
    val N = g.n
    val dist = Array(N) {INF}
    val prev = Array(N) {-1}

    dist[0] = 0

    for (k in 1 .. N) {
        for (v in 0 until N) {
            for (e in g.edges[v]) {
                if (dist[e.from] != INF && dist[e.to] > dist[e.from] + e.weight) {
                    dist[e.to] = dist[e.from] + e.weight
                    prev[e.to] = e.from
                }
            }
        }
    }

    val dist2 = dist.copyOf()
    for (k in 1 .. N) {
        for (v in 0 until N) {
            for (e in g.edges[v]) {
                if (dist2[e.from] != INF && dist2[e.to] > dist2[e.from] + e.weight) {
                    dist2[e.to] = dist2[e.from] + e.weight
                }
            }
        }
    }

    val affectedByNegativeLoop = Array(N) { idx -> dist[idx] != dist2[idx] }

    return Triple(dist, prev, affectedByNegativeLoop)
}

fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map { s -> s.toInt() }
    val g = Graph(N)

    for (i in 1 .. M) {
        val (a, b, c) = readLine()!!.split(" ").map {s -> s.toLong()}
        g.edges[(a - 1).toInt()].add(Edge(a - 1, b - 1, -c))
    }

    val (dist, prev, affectedByNegativeLoop) = bellmanFord(g, 0)

    if (affectedByNegativeLoop[N - 1]) {
        println("inf")
    } else {
        println(-dist[N - 1])
    }
}

Measured memory_bytes: 70092
#include <bits/stdc++.h>
#define pb push_back
#define l first
#define r second
#define int long long
#define pi pair<int, int>

using namespace std;

const int maxn = 200001, mod = 998244353;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    string s; cin >> s;
    int cb = 0, pn = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'c' || pn >= a + b) {
            cout << "No\n";
            continue;
        }
        if (s[i] == 'b') ++cb;
        if (s[i] == 'b' && cb > b) {
            cout << "No\n";
            continue;
        }
        cout << "Yes\n"; ++pn;
    }

    return 0;
}


Measured memory_bytes: 848
#include<stdio.h>
int main()
{
	char r[5]={'A','B','C','D','E'};
	int s1[5],i,s2[5],m=0,l;
	while(1){
		for(i=0;i<5;i++){
			scanf("%d%d",&s1[i],&s2[i]);
			if(s1[i]==0&&s2[i]==0){
				return 0;
			}
		}
		for(i=0;i<5;i++){
			if(m<s1[i]+s2[i]){
				m=s1[i]+s2[i];
				l=i;
			}
		}
		printf("%c %d\n",r[l],m);
		m=0;
	}
	return 0;
}

Measured memory_bytes: 600
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	X := nextInt()
	Y := nextInt()
	var a, b int
	x := X
	y := Y
	for x > 0 && y > 0 {
		if x < y {
			x -= 1
			y -= 2
			a++
		} else {
			x -= 2
			y -= 1
			b++
		}
	}
	if !(x == 0 && y == 0) {
		fmt.Println(0)
		return
	}
	cmb := NewCombination()
	cmb.build()
	fmt.Println(cmb.c(a+b, a))
}

const mod int = 1000000007

type Combination struct {
	max, mod int
	fact     []int
	factInv  []int
	inv      []int
}

func NewCombination() *Combination {
	c := &Combination{}
	c.max = 666667 //最大値を入れてみて増やす
	c.mod = int(1e9) + 7
	c.fact = make([]int, c.max)
	c.factInv = make([]int, c.max)
	c.inv = make([]int, c.max)
	return c
}

func (c *Combination) build() {
	c.inv[1], c.fact[0], c.factInv[0] = 1, 1, 1
	var i int
	for i = 2; i < c.max; i++ {
		c.inv[i] = c.inv[c.mod%i] * (c.mod - c.mod/i) % c.mod
	}
	for i = 1; i < c.max; i++ {
		c.fact[i] = c.fact[i-1] * i % c.mod
		c.factInv[i] = c.factInv[i-1] * c.inv[i] % c.mod
	}
	log.Println("build finish")
}

func (c *Combination) c(n, k int) int {
	if c.inv[0] == 0 {
		c.build()
	}
	if n < 0 || k < 0 || n < k {
		return 0
	}
	return ((c.fact[n] * c.factInv[k] % c.mod) * c.factInv[n-k]) % c.mod
}

func (c *Combination) p(n, k int) int {
	if k < 0 || k > n {
		return 0
	}
	return c.fact[n] * c.factInv[n-k] % c.mod
}

func (c *Combination) h(n, k int) int {
	if n == 0 && k == 0 {
		return 1
	}
	return c.c(n+k-1, k)
}

// c:N 個の整数の中から，相異なる K 個の整数を選ぶパターンの数C(N,K)
// p:N 個の整数の中から，相異なる K 個の整数を選び，順番に並べるパターンの数P(N,K)
// h:N 個の整数の中から，重複を許して K 個の整数を選ぶパターンの数H(N,K)

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		log.Fatal(err)
	}
	return i
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var inf = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

// bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
//     return arg1.first > arg2.first;
// }

int gcd(int a, int b) {
    if (a<b) swap(a, b);

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

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

    vector<int> a(n);
    for(int in=0;in<n;in++) {
        cin >> a.at(in);
    }

    sort(a.begin(), a.end());
    int ans=1e9;
    for(int in=1;in<n;in++) {
        cin >> a.at(in);
        ans = min(ans, gcd(a.at(0), a.at(in)));
    }

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


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

int n;
long long x,a[2010],b[2010][2010],ans=2e17,res;
int main()
{
	scanf("%d%lld",&n,&x);
	for(int i=0;i<=n-1;++i)
	scanf("%lld",&a[i]);
	for(int i=0;i<=n-1;++i)
	{
		b[0][i]=a[i];
		res+=a[i];
	}
	ans=min(ans,res);
	for(int k=1;k<=n-1;++k)
	{
		res=0;
		for(int i=0;i<=n-1;++i)
		{
			b[k][i]=min(b[k-1][i],a[(i-k+n)%n]);
			res+=b[k][i];
		}
		res+=x*k;
		ans=min(ans,res);
	}
	printf("%lld\n",ans);
	return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int dp[1<<26];
int cnt[200010];
int opt[200010];

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

  string S;
  cin >> S;
  int N = SZ(S);

  cnt[0] = 0;
  REP(i,N){
	cnt[i+1] = cnt[i] ^ (1 << (S[i]-'a'));
  }

  fill(opt, opt+200010, 1e9);
  fill(dp, dp+(1<<26), 1e9);
  dp[0] = 0;
  opt[0] = 0;
  for(int i=0;i<N;++i){
	mini(opt[i+1], dp[cnt[i+1]] + 1);
	REP(k,26){
	  mini(opt[i+1], dp[cnt[i+1] ^ (1<<k)] + 1);
	}
	mini(dp[cnt[i+1]], opt[i+1]);
  }

  cout << opt[N] << endl;

  return 0;
}


Measured memory_bytes: 264340
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        var S = Console.ReadLine();
        if(S == "ABC")
        {
            Console.WriteLine("ARC");
        }
        else
        {
            Console.WriteLine("ABC");
        }

    }
}


Measured memory_bytes: 25788
#include<cstdio>
#include<algorithm>
using namespace std;

int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	int N;
	long long ans=0,minb=1e9;
	scanf("%d",&N);
	for(int i=1;i<=N;i++) {
		long long a,b;
		scanf("%lld %lld",&a,&b);
		ans+=a;
		if(a>b)minb=min(minb,b);
	}
	printf("%lld\n",minb==1e9?0:ans-minb);
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define PP(p) cout<<(p)<<" ";
#define pb push_back
#define mp make_pair
#define INF 1e18

typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef pair<int, int> pi;
//int dy[8]={1,1,1,0,-1,-1,-1,0};
//int dx[8]={-1,0,1,1,1,0,-1,-1};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

int N,M;
vi a,b;
string S;
void input(){
	cin>>S;
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	input();
	S[3]='8';
	cout<<S<<endl;
	return 0;
}



Measured memory_bytes: 764
#include <iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
#include<cmath>
#include<string>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int main()
{
    char s[108]= {0};
    char t[108]= {0};
    cin>>s;
cin>>t;
    int l=strlen(s),i,j;
    for( j=l-1; j>=0; j--)
    {
        int k=0;
      for(i=j;;i++)
      {
          if(i>=l)i=0;
          if(k>=l)break;
          if(s[k++]!=t[i])goto p;
      }
      if(i==j)
      {
          printf("Yes\n");
          exit(0);
      }
      p:;
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 256
import java.util.*; 
import java.io.*;

public class Main {
    static StringTokenizer st;
    static BufferedReader br;  
    static PrintWriter out;
 
    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));

        int N = nextInt();
        long[] input = new long[N];

        for (int i=0; i<N; i++) {
            input[i] = nextLong();
            if(input[i]==0) {
                System.out.println(0);
                return;
            }
        }

        long ans =input[0];

        for (int i=1; i<N; i++) {
            // If you directly perform multiplication on 64-bit integers, it causes overflow
            // if((Math.log10(ans) + Math.log10(input[i]) >= 18) && ans * input[i] != 1e18){
            //if(ans> 1e18/ input[i]){ 
            // > not working, need use <=, because 1e18/ input[i] will lose 0.000001
            if(!(ans<= (long)(1e18)/ input[i])){ 
                System.out.println(-1);
                return;
            }
            ans = ans * input[i];
        }

        System.out.println(ans);
 
    }
    
      
    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    public static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

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


Measured memory_bytes: 48736