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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


 
signed main() {
    int N, K;
    string S;
    cin >> N >> S >> K;

    rep(i,N){
        if(S[i]!=S[K-1]) cout << "*";
        else cout << S[i];
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

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

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[20][20];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}

int main() {
	cin >> R >> C;
	ll res = 0;
	rep(i, R) {
		rep(j, C) {
			cin >> maze[i][j];
		}
	}
	sy = 1; sx = 1; gy = 2; gx = 1;
	for(ll i=1;i<=R;i++) {
		for (ll j = 1; j <= C; j++) {
			for(ll k = 1; k <= R; k++) {
				for (ll l = 1; l <= C; l++) {
					sy = i;
					sx = j;
					gy = k;
					gx = l;
					if (maze[gy - 1][gx - 1] == '#' || maze[sy - 1][sx - 1] == '#')continue;
					ll p = bfs();
					chmax(res, p);
				}
			}
		}
	}
	cout << res << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__

int main() {
    ll N, K; cin >> N >> K;
    vl P(N);
    rep(i, N) {
        cin >> P[i];
        P[i]--;
    }
    vl C(N); rep(i, N) cin >> C[i];

    ll ans = -LINF;
    rep(si, N) {
        ll x = si;
        vl s;
        ll total = 0;
        while (1) {
            x = P[x];
            total += C[x];
            s.push_back(C[x]);
            if (x == si) break;
        }

        ll l = s.size();
        ll t = 0;
        rep(i, l) {
            t += s[i];
            if (i + 1 > K) break;
            ll now = t;
            if (total > 0) {
                ll e = (K - (i + 1)) / l;
                now += total * e;
            }
            ans = max(now, ans);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3812
//コピペ from; https://atcoder.jp/contests/agc033/submissions/5256876 kotatsugame

#include <iostream>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<queue>
#include<utility>

typedef long long ll;

#define rep0(i, n) for(int i=0; i < (int)(n); i++)
#define rep1(i, n) for(int i=1; i < (int)(n); i++)
#define rall(x) (x).rbegin(),(x).rend()
#define fill(x,y) memset(x,y,sizeof(x))
#define debug1(i) cout << i << '\n'
#define debug2(i,j) cout << i << j << '\n'

using namespace std;

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

int main() {
	int h, w;
	cin >> h >> w;
	char s[1000];
	queue<pair<int, int>>P;

	rep0(i, h) {
		cin >> s;
		rep0(j, w) {
			if (s[j] == '#') {
				P.push(make_pair(i, j));
				dis[i][j] = 1;
			}
		}
	}

	while (!P.empty()) {
		int x = P.front().first, y = P.front().second;
		P.pop();
		rep0(r, 4) {
			int tx = x + dx[r], ty = y + dy[r];
			if (tx < 0 || ty < 0 || tx >= h || ty >= w || dis[tx][ty]>0)continue;
			dis[tx][ty] = dis[x][y] + 1;
			P.push(make_pair(tx, ty));
		}
	}

	int ans = 0;
	rep0(i, h)rep0(j, w)if (ans < dis[i][j])ans = dis[i][j];
	cout << ans-1;
}

Measured memory_bytes: 12304
Scanf.scanf "%d %d %d" (fun n m k ->
    let par = Array.init n (fun i -> i) in
    let size = Array.make n 1 in
    let near = Array.make n 0 in
    let rec root x =
        if par.(x) = x then x else
            let r = root par.(x) in
            let () = par.(x) <- r in
            r
    in
    for i = 1 to m do
        Scanf.scanf " %d %d" (fun a b ->
            let a = a - 1 in let b = b - 1 in
            near.(a) <- near.(a) + 1;
            near.(b) <- near.(b) + 1;
            if root a <> root b then (
                size.(par.(a)) <- size.(par.(a)) + size.(par.(b));
                par.(par.(b)) <- par.(a)
            )
        )
    done;
    for i = 1 to k do
        Scanf.scanf " %d %d" (fun c d ->
            let c = c - 1 in let d = d - 1 in
            if root c = root d then (
                near.(c) <- near.(c) + 1;
                near.(d) <- near.(d) + 1;
            )
        )
    done;
    for i = 0 to n - 1 do
        Printf.printf "%d " (size.(root i) - near.(i) - 1)
    done
)

Measured memory_bytes: 7168
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
  char c;
  cin>>c;
  char star[5]="ACTG";
  for(int i=0;i<4;i++){
    if(c==star[i]){
      cout<<star[(i+2)%4]<<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++)
#define int long long

signed main() {
  int N, M; cin >> N >> M;
  vector<pair<int,int>> p(N);
  rep(i, N) cin >> p[i].first >> p[i].second;
  
  sort(p.begin(), p.end());
  
  int ans = 0;
  int i = 0;
  
  while(M>0) {
    if(p[i].second > 0) {
      ans += p[i].first;
      p[i].second--;
      M--;
    } else {
      i++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#define loop(i, sta, end, inc) for(int i = sta; i <= end; i += inc)
#define itr(it, l)             for(auto it = l.begin(); it != l.end(); it ++)
#define in(a, b, c)            assert( b <= a && a <= c)
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define ii  pair<long long int, long long int>
#define vi  vector <long long int>
#define vii vector <pair <long long int, long long int > >
#define all(cont)  cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define what_is(x) cerr<<#x<<" ="<<x<<" ";
#define error(args...)  { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define LINT_MAX  9223372036854775807
#define LINT_MIN -9223372036854775808
#define EPS 1e-9
#define MOD 1000000007
#define DEBUG 0

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
void err(istream_iterator<string> it) { cerr<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    if(DEBUG == 0)return;
	cerr << *it << " = " << a <<" ";
	err(++it, args...);
}

int dp[100000];
int B[100000];
vector<int> A[100000];
int fun(int x){
	//cout<<x<<" ";
	if(A[x].size()==0)return 0;
	if(dp[x]!=0)return dp[x];
	int temp=0;
	forn(i,A[x].size())temp=max(temp,fun(A[x][i])+1);
	dp[x]=temp;
	return dp[x];
}
int main(){
    //freopen("test.txt", "r", stdin);
    int n,m;cin>>n>>m;
    
    forn(i,m){
    	int x,y;cin>>x>>y;
    	A[x].push_back(y);
    }
    int ans=0;
    forn1(i,n){
    	ans=max(ans,fun(i));
    }
    cout<<ans<<endl;
   /* cout<<"ssa"<<endl;
    queue<int> q;
    forn(i,n){
    	if(B[i]==0)q.push(i);
    	dp[i]=0;
    }
    while(!q.empty()){
    	int x=q.front();
    	q.pop();
    	cout<<x<<" ";
    	forn(i,A[x].size()){
    		dp[A[x][i]]=max(dp[A[x][i]],dp[x]+1);
    		q.push(A[x][i]);
    	}
    }
    int ans=0;
    forn(i,n)ans=max(ans,dp[i]);
    cout<<ans<<endl;*/

    return 0;
}



Measured memory_bytes: 8192
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;
const int INF = 1100000000;

int main(){
	ios_base::sync_with_stdio(false);
	int l, n;
	cin >> l >> n;
	vector<int> p(n + 1), d(n), t(n);
	vector<tuple<int, int, int>> warps(n);
	for(int i = 0; i < n; ++i){
		int ip, id, it;
		cin >> ip >> id >> it;
		warps[i] = make_tuple(ip, id, it);
	}
	sort(warps.begin(), warps.end());
	for(int i = 0; i < n; ++i){
		p[i] = get<0>(warps[i]);
		d[i] = get<1>(warps[i]);
		t[i] = get<2>(warps[i]);
	}
	p[n] = l;
	vector<int> dp(n + 1, INF);
	dp[0] = p[0];
	for(int i = 0; i < n; ++i){
		const int x =
			lower_bound(p.begin(), p.end(), p[i] + d[i]) - p.begin();
		if(x <= n){
			const int y = dp[i] + t[i] + (p[x] - (p[i] + d[i]));
			dp[x] = min(dp[x], y);
		}
		if(i <  n){ dp[i + 1] = min(dp[i + 1], dp[i] + p[i + 1] - p[i]); }
	}
	cout << dp[n] << endl;
	return 0;
}


Measured memory_bytes: 1232
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int D = int.Parse(Console.ReadLine());
		int[]C = new int[26];
		string[]str = Console.ReadLine().Split();
		for(var i=0;i<26;i++){
			C[i] = int.Parse(str[i]);
		}
		int[,]A = new int[D,26];
		for(var i=0;i<D;i++){
			string[]str2 = Console.ReadLine().Split();
			for(var j=0;j<26;j++){
				A[i,j] = int.Parse(str2[j]);
			}
		}
		int[]ans = new int[D];
		int[]W = new int[26];
		for(var i=0;i<D;i++){
			int maxValue = 0;
			int maxj = 0;
			for(var j=0;j<26;j++){
				int value = A[i,j] + W[j]*(i+1-W[j]);
				if(value > maxValue){
					maxValue = value;
					maxj = j;
				}
			}
			ans[i] = maxj+1;
			W[maxj] = i+1;
		}
		for(var i=0;i<D;i++){
			Console.WriteLine(ans[i]);
		}
	}
}

Measured memory_bytes: 18424
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,a,b = readline() |> split |> parseMap
	if a==b
		println(1)
	elseif n==1||a>b
		println(0)
	elseif n == 2
		println(1)
	else
		println(b*(n-1)+a-a*(n-1)-b+1)
	end
end

main()

Measured memory_bytes: 168996
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
  int n;
  scanf("%d", &n);
  char *s = malloc (sizeof(char) * (n + 1));
  scanf("%s", s);
  int ans = 0;
  for (int j = 0; j < n - 1; j++) {
    int tmp = 0;
    int a[n];
    a[0] = 0;
    for (int i = 1; i < n - j; i++) {
      int start;
      if (i < tmp + a[tmp]) {
        if ((i - tmp) + a[i - tmp] < a[tmp]) {
          a[i] = a[i - tmp];
          continue;
        } else {
          a[i] = a[tmp] - (i - tmp);
          start = tmp + a[tmp];
        }
      } else {
        a[i] = 0;
        start = i;
      }
      for (int k = start; k < n - j; k++) {
        if (s[k - i] == s[k]) {
          a[i]++;
        } else {
          break;
        }
      }
      tmp = i;
      if (ans < a[i]) {
        if (a[i] < i) {
          ans = a[i];
        } else if (ans < i) {
          ans = i;
        }
      }
    }
    s++;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
//double pi=3.1415926535898;
//double pi=acos(-1.0);
#define scarr(a,s,e) for(int i=s;i<=int(e);i++) scanf("%d ",&a[i]);
#define prarr(a,s,e) for(int i=s;i<=int(e);i++) printf("%d ",a[i]);
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define rng(i,a,b) for(int i=a;i>=int(b);i--)
#define rep(i,a,b) for(int i=a;i<=int(b);++i)
#define lop(i,n)   for(int i=0;i<int(n);i++)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define mkp        make_pair
#define fr         first
#define se         second
#define sc(x)      scanf("%d",&x)
#define pr(x)      printf("%d ",x)
#define scl(x)     scanf("%lld",&x)
#define prl(x)     printf("%lld ",x)
#define prln(x)    printf("%d\n",x)
#define r0         return 0;
#define CC         continue;
#define scd(x)     scanf("%lf",&x)
#define prd(x)     printf("%.10f\n",x);
#define bb(x)      cerr<< x <<endl;
//#define max(a,b) a<b?b:a
//#define min(a,b) a<b?a:b
const ll M   = 1e7+9 ;
const ll inf = 1e19  ;
const int si = 1e5+9 ;
//////////////////////    Hi    ^_^  hack me if you can :P

int main()
{
string s;
cin >> s;
for (int i=0;i<12;i++){
    cout<<s[i];
    if(i==3)
        cout<<' ';
}
cout<<endl;
r0;
}



/*

ll pwmod(ll a, ll n, ll mod) {
    ll ret = 1;
    while (n) {
        if (n & 1) ret = ret * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return ret;
}

*/
/*
freopen("output.txt","w",stdout);
freopen("input.txt","r",stdin);
for (int i=0;i<n;i++)            Hi    ^_^  hack me if you can :P
int mx[]= {0,0,1,1,1,-1,-1,-1};
int my[]= {1,-1,0,1,-1,0,1,-1};
bool inside (int i,int j) {return (i>=0 && i<n && j>=0 && j<m);}
*/


Measured memory_bytes: 256
n = int(input())
c = [int(input()) for _ in range(n)]
mod = 10 ** 9 + 7

color_sum = {i: 0 for i in range(10 ** 6)}
dp = [1 for _ in range(n+1)]
dp[0] = 1
dp[1] = 1
color_sum[c[0]] = 1

for i in range(2, n+1):
    dp[i] = dp[i-1]

    if c[i-2] == c[i-1]:
        continue

    dp[i] += color_sum[c[i-1]]
    dp[i] %= mod

    color_sum[c[i-1]] += dp[i-1]
    color_sum[c[i-1]] %= mod


print(dp[n])

Measured memory_bytes: 106904
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	ll a, b, c;
	cin >> a >> b >> c;
	int n;
	cin >> n;
	rep(i, n) {
		if (a >= b) b *= 2;
		else if (b >= c) c *= 2;
	}
	puts(a < b && b < c ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    string c;
    long double b=0;
    long double j=0;
    long double x=0;
    long double rate=380000.0;
    for(int i=0; i<n; ++i){
        cin >> x >> c;
        if(c=="JPY"){
            j+=x;
        }else if (c=="BTC")
        {
            b+=(rate*x);
        }
    }
    cout << (j+b) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;
int dp[808080][12];

int main(){
    string s;
    cin >> s;
    while(s != "0"){
        memset(dp, 0, sizeof(dp));
        if(s[0]-'0' != 0) dp[0][s[0]-'0']++;
        rep1(i, s.size()){
            int x = s[i]-'0';
            rep(j, 11){
                int nx = (j*10+x) % 11;
                dp[i][nx] += dp[i-1][j];
            }
            if(x != 0) dp[i][x]++;
        }
        int ans = 0;
        rep(i, s.size()){
            ans += dp[i][0];
        }
        cout << ans << endl;
        cin >> s;

    }

}



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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

ll dp[101010][3];
ll abc[101010][3];

int main() {
    ll inf = 1e10;
    ll N;
    cin >> N;
    rep(i, N) {
        rep(j, 3) cin >> abc[i][j];
    }

    fill(dp[0], dp[3], -inf);

    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    for (int i=0; i<N; ++i) {
        // a
        dp[i+1][0] = max({dp[i+1][0], dp[i][1]+abc[i][0], dp[i][2]+abc[i][0]});
        dp[i+1][1] = max({dp[i+1][1], dp[i][0]+abc[i][1], dp[i][2]+abc[i][1]});
        dp[i+1][2] = max({dp[i+1][2], dp[i][0]+abc[i][2], dp[i][1]+abc[i][2]});
    }

    cout << max({dp[N][0], dp[N][1], dp[N][2]}) << endl;
    return 0;
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;


int main() {
    int n; cin >> n;
    map<int, int> m;
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        m[a]++;
    }

    int ans = m.size();
    if(ans % 2 == 0) cout << ans - 1 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 4992
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A, B, C, D):

    B -= A
    A = 0
    M = N - 1
    for i in range(N):
        u = i * D - (M-i) * C
        l = i * C - (M-i) * D
        if l <= B <= u:
            return 'YES'

    return 'NO'


def main():
    N, A, B, C, D = read_int_n()
    print(slv(N, A, B, C, D))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7648
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;i++)
#define per(i,a,b) for(int i=(b),i##_st=(a);i>=i##_st;i--)
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define dbg(x) cerr<<#x" = "<<x<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define Es(x,i) for(Edge *i=G[x];i;i=i->nxt)
typedef long long ll;
typedef pair<int,int> pii;
const int inf=~0u>>1,MOD=1e9+7;
char *TT,*mo,but[(1<<15)+2];
#define getchar() ((TT==mo&&(mo=((TT=but)+fread(but,1,1<<15,stdin)),TT==mo))?-1:*TT++)
inline ll rd() {
    ll x;char c,f=1;while(!isdigit(c=getchar()))f=c!='-';x=c-'0';
    while(isdigit(c=getchar()))x=x*10+c-'0';return f?x:-x;
}
 
const int N=100000+19;
 
double x[N],tmp;
int P[60][N],Q[N];
int A[N];
int n,m,u;
ll K;
 
int main(){
	n=rd();
	rep(i,1,n)i[x]=rd();
	m=rd(),K=rd();
	rep(i,1,n-1){
		i[0[P]]=i;
		i[Q]=i;
	}
	rep(i,1,m){
		u=rd();
		swap(u[0[P]],P[0][u-1]);
	}
	rep(t,1,59){
		rep(i,1,n-1) i[t[P]]=P[t-1][P[t-1][i]];
	}
	rep(t,0,59) if (K>>t&1){
		rep(i,1,n-1) i[Q]=i[Q][t[P]];
	}
	tmp=1[x];
	printf("%.10lf\n",tmp);
	rep(i,1,n-1){
		tmp+=x[Q[i]+1]-i[Q][x];
		printf("%.10lf\n",tmp);
	}
}

Measured memory_bytes: 27008
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(nullptr); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N, M;
    cin >> N >> M;
    priority_queue<int> pq;
    rep(i, 0, N) {
        int x;
        cin >> x;
        pq.push(x);
    }
    rep(i, 0, M) {
        int x = pq.top(); pq.pop();
        pq.push(x / 2);
    }
    int ans = 0;
    while (sz(pq)) {
        int x = pq.top(); pq.pop();
        ans += x;
    }
    cout << ans << endl;
    return (0^_^0);
}



Measured memory_bytes: 1400
//Increment Decrement

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end()
struct edge{int to;ll cost;};
const int inf = 2147483647;

int main (){
    int n,c=0,ans=0;string s;cin>>n>>s;
    rep(i,0,n){
        if(s[i]=='I')c++;
        else if(s[i]=='D')c--;
        ans= max(c,ans);
    }

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

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

int main()
{
  int A, B;
  cin >> A >> B;
  if ((A - B * 2) > 0)
  {
    cout << A - B * 2 << endl;
  }
  else
  {
    cout << 0 << endl;
  }
}


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

int main() {
  int n,m;
  cin >> n >> m;
  priority_queue<int>a;
  rep(i,n){
    int b;
    cin >> b;
    a.push(b);
  }
  rep(i,m){
    int t = a.top()/2;
    a.pop();
    a.push(t);
  }
  ll ans = 0;
  rep(i,n){
    ans += a.top();
    a.pop();
  }
  cout << ans << endl;
}

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

int main() {
    long long N; cin >> N;
    vector<long long>C(N - 1), S(N - 1), F(N - 1);
    for (long long i = 0; i < N - 1; i++) {
        cin >> C.at(i) >> S.at(i) >> F.at(i);
    }
    vector<long long>ans(N, 0);
    for (long long i = 0; i < N; i++) {
        if (i == N - 1) continue;
        else {
            ans.at(i) += S.at(i);
            for (long long j = i; j < N - 1; j++) {
                if (ans.at(i) < S.at(j)) {
                    ans.at(i) = S.at(j) + C.at(j);
                }
                else if ((ans.at(i) - S.at(j)) % F.at(j) == 0) ans.at(i) += C.at(j);
                else {
                    long long sum = (ans.at(i) - S.at(j)) / F.at(j) + 1;
                    ans.at(i) = S.at(j) + sum * F.at(j) + C.at(j);
                }
            }
        }
    }
    for (long long i = 0; i < N; i++) {
        cout << ans.at(i) << endl;
    }
}

Measured memory_bytes: 3616
from sys import stdin, setrecursionlimit
from collections import defaultdict
from math import gcd

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


MOD = 1000000007
N, *AB = map(int, stdin.buffer.read().split())
d = defaultdict(int)
zeros = 0
for a, b in zip(AB[::2], AB[1::2]):
    if a == 0 and b == 0:
        zeros += 1
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        if a < 0:
            a *= -1
            b *= -1
        if a == 0 and b == -1:
            b = 1
        d[(a, b)] += 1

ans = 1
free = 0
for (a, b), n in d.items():
    if b > 0:
        if (b, -a) in d:
            m = d[(b, -a)]
            ans = ans * (pow(2, n, MOD) + pow(2, m, MOD) - 1) % MOD
        else:
            free += n
    else:
        if (-b, a) not in d:
            free += n

ans = (ans * pow(2, free, MOD) + zeros - 1) % MOD
print(ans)


Measured memory_bytes: 77348
#include<bits/stdc++.h>
#define int long long

using namespace std;

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

    int n, arr[50];
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> arr[i];

    int cnt = 0;
    for (int i = 0; i < n; i++)
        cnt += (arr[i] != i + 1);

    if (cnt > 2)
        cout << "NO\n";
    else
        cout << "YES\n";

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int X = Integer.parseInt(sc.next());
        int Y = Integer.parseInt(sc.next());
        
        int maxX = X;
        int minY = Y;
        for(int i = 0; i < n; i++){
            int x = Integer.parseInt(sc.next());
            if(x > maxX) maxX = x;
        }
        for(int i = 0; i < m; i++){
            int y = Integer.parseInt(sc.next());
            if(y < minY) minY = y;
        }
        
        if(maxX < minY){
            System.out.println("No War");
        }else{
            System.out.println("War");
        }
    }
}

Measured memory_bytes: 22228
import math
def main():
    N, D = map(int, input().split())
    pt = []
    for _ in range(N):
        p = list(map(int, input().split()))
        pt.append(p)

    ans = 0
    for i in range(N):
        for j in range(i):
            l = 0
            for k in range(D):
                l += pow(pt[i][k]-pt[j][k], 2)
            l = math.sqrt(l)
            if l == int(l): ans += 1
    return ans

if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3064
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  string s1,s2;
  int count=0;
  cin>>s1;
  cin>>s2;
  for(int i=0;i<s1.length();i++)
  {
    if(s1[i]!=s2[i])
      count++;
  }
  cout<<count;
 }

Measured memory_bytes: 3748
#include"bits/stdc++.h"
using namespace std;
typedef long long int ll;
#define crap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mx5 100005
#define MOD 1000000007

int main() {
	crap;
	int n;
	cin >> n;
	vector<double> dp(n+1,0.0);
	dp[0] = 1;
	for( int i=0; i<n; i++ ){
	    double p;
	    cin >> p;
	    for( int j=i+1; j>=0; j-- ){
	        dp[j] = dp[j-1]*p + (1-p)*dp[j];
	    }
	}
	double ans = 0;
	for( int i=0; i<=n; i++ ){
	    if( i > n-i )
	     ans+=dp[i];
	}
	printf("%.10lf",ans);

	
	return 0;
}

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

const string ALPHABETS = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int n;
    string tmpS;
    int nalphabets[26];
    for(int i=0;i<26;i++) nalphabets[i] = 1e5;

    cin >> n;
    for(int i=0;i<n;i++){
        cin >> tmpS;
        int tmpnalphabets[26] = {};
        for(auto s: tmpS) tmpnalphabets[s - 'a']++;
        for(int j=0;j<26;j++) nalphabets[j] = min(nalphabets[j], tmpnalphabets[j]);
    }

    for(int i=0;i<26;i++){
        for(int j=0;j<nalphabets[i];j++){
            cout << ALPHABETS[i];
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

		ArrayList<Character> ans = new ArrayList<>();

		for(int i = 0; i<sString.length(); i++){
			if (ans.size() == 0){
				ans.add(sString.charAt(i));
			}else if (ans.get(ans.size()-1) != sString.charAt(i)){
				ans.remove(ans.size()-1);
			}else {
				ans.add(sString.charAt(i));
			}
		}
		System.out.println(sString.length() - ans.size());
	}
}


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

int main(){
  int N;
  cin >> N;
  vector<string> s(N);
  for(int i = 0; i < N; i++){
    cin >> s.at(i);
  }
  for(int i= 0; i < N; i++){
    sort(s.at(i).begin(), s.at(i).end());
  }
  sort(s.begin(), s.end());
  vector<long long> t(N, 1);
  int u = 0;
  for(int i = 0; i < N - 1; i++){
    if(s.at(i) == s.at(i + 1)){
      t.at(u) += 1;
    }
    else{
      u += 1;
    }
  }
  long long v = 0;
  for(int l = 0; l < N; l++){
    if(t.at(l) >= 2){
      v += t.at(l)*(t.at(l) - 1) / 2;
    }
  }
  cout << v << endl;
}

Measured memory_bytes: 8064
s = list(map(int, input()))
o = s[::2]
e = s[1::2]
l_o = len(o)
l_e = len(e)
o_o = sum(o)
o_e = sum(e)

print(min(l_o - o_o + o_e, o_o + l_e - o_e))


Measured memory_bytes: 4640
#include <stdio.h> 
 int main(void){
   int n,a,b,c,d,ans;
    while(scanf("%d",&n)!=EOF){
    ans =0;
      for(a=0;a<10;a++){
        for(b=0;b<10;b++){
          for(c=0;c<10;c++){
             for(d=0;d<10;d++){
                if(a+b+c+d == n)
                    ans++;
               }
            } 
          }
       }
      printf("%d\n",ans);
     }
  return 0;
}

Measured memory_bytes: 596
n,m=map(int,input().split())
a=[input() for i in range(n)]
b=[input() for i in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        x=[]
        for k in range(m):
            x.append(a[i+k][j:j+m])
        if x==b:
            print("Yes")
            exit()
print("No")


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<unistd.h>
#include <array>
#include <map> 
#define ALL(a)  (a).begin(),(a).end()



using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd(int a, int b)
{
  if(a>b){
    return gcd(b,a);
  }
	return a == 0 ? b : gcd(b % a, a);
}
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a';
    if((ans < 0) || (ans > 25)){
        ans = 26;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}

int binary_searchh(long long x,long long k[],int n){
  int l=0;
  int r=n;
  while(r-l>=1){
    int i=(l+r)/2;
    if(k[i]==x)return i;
    else if(k[i]<x)l=i+1;
    else r=i;
  }
  return -1;
}

struct File {
    int aa;
    int bb;

    File(const int& aa, const int& bb)
        : aa(aa), bb(bb) {}
};

bool operator<(const File& a, const File& b)
{
    // ファイル種別、ファイル名の順番で優先順位を付けて比較
    return std::tie(a.aa, a.bb) < std::tie(b.aa, b.bb);
}

long long kaijo(long long x){
  long long l=10*10*10*10*10*10*10*10*10+7;
  long long sum=1;
  for(int i=x;i>0;i--){
    sum*=i;
    if(sum>l){
      sum%=l;
    }
  }
  return sum;
}






int main(){
  long long x,y;
  cin>>x>>y;
  long long z=abs(abs(x)-abs(y));
  if((x>0&&y>0&&x<y)||(x<0&&y<0&&x<=y)){
    cout<<z<<endl;
  }else if((x>0&&y>0)||(x<0&&y<0&&x>y)){
    cout<<z+2<<endl;
  }else if((x==0&&y>0)||(x<0&&y==0)){
    cout<<z<<endl;
  }else{
    cout<<z+1<<endl;
  }



}





  
  


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

int main() {
    long long ans;
    int N;
    long long K;
    cin >> N >> K;
    vector<long long> A(N), F(N);
    for(int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    for(int i = 0; i < N; i++) {
        cin >> F.at(i);
    }
    sort(A.begin(), A.end());
    sort(F.begin(), F.end(), greater<int>());
    long long X = 0;
    for(int i = 0; i < N; i++) {
        long long Y = A.at(i) * F.at(i);
        X = max(X, Y);
    }
    long long l = 0, r = X;
    while(l < r) {
        long long M = (l + r) / 2;
        long long Count = 0;
        for(int i = 0; i < N; i++) {
            if(M < A.at(i) * F.at(i))
                Count += A.at(i) - M / F.at(i);
        }
        if(K >= Count)
            r = M;
        else
            l = M + 1;

        // cout << l << " " << r << endl;
    }
    ans = l;

    cout << ans << endl;
}


Measured memory_bytes: 3328
from collections import defaultdict
from itertools import combinations
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n = I()
s = SR(n)
d = defaultdict(int)
for c in ['M', 'A', 'R', 'C', 'H']:
    d[c] = 0
for name in s:
    if name[0] in {'M', 'A', 'R', 'C', 'H'}:
        d[name[0]] += 1
combs = list(combinations(['M', 'A', 'R', 'C', 'H'], 3))

ans = 0
for c in combs:
    ans += d[c[0]] * d[c[1]] * d[c[2]]
print(ans)


Measured memory_bytes: 10104
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=1000000000000000000,mod=1000000007,BS,k;
ll fact[500005],ifact[500005];
ll power(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1)
        res=(res*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return res;
}
ll ncr(ll n,ll r){
    ll res;
    res=fact[n];
    res=(res*ifact[n-r])%mod;
    res=(res*ifact[r])%mod;
    return res;
}
ll npr(ll n,ll r){
    if(n<r)
    return 0;
    ll num;
    num=fact[n];
    num=(num*ifact[n-r])%mod;
    // num%=mod;
    return num%mod;
}
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
        fact[0]=1;
        for(ll i=1;i<500005;i++)
        fact[i]=(i*fact[i-1])%mod;
        ifact[500004]=power(fact[500004],mod-2);
        for(ll i=500003;i>=0;i--){
            ifact[i]=((i+1)*ifact[i+1])%mod;
        }
        ll n,m,sum=0,num;cin>>n>>m;
        for(ll i=0;i<n;i++){
            num=npr(m,n-i);
            num=(num*ncr(n,i))%mod;
            num=(num*npr(m-(n-i),i))%mod;
            num=(num*npr(m-(n-i),i))%mod;
            if(i%2==0){
                sum=(sum+num)%mod;
            }
            else{
                sum=(sum-num+mod)%mod;
            }
        }
        num=npr(m,n);
        num=(num*num)%mod;
        if(n%2)
        sum=(num-sum+mod)%mod;
        else
        sum=(num+sum)%mod;
        cout<<sum;
}


Measured memory_bytes: 11380
n = int(input())


def getNumsOfDivisorsOfEachNumbers(n: int):
    # validation check
    if not isinstance(n, int):
        raise("[ERROR] parameter must be integer")
    if n < 0:
        raise("[ERROR] parameter must be not less than 0 (n >= 0)")
    nums = [0] * (n + 1)  # 0-indexed
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            nums[j] += 1
    nums.pop(0)
    return nums


l = getNumsOfDivisorsOfEachNumbers(n)

res = 0
for c in l:
    res += c

res -= l[n - 1]

print(res)


Measured memory_bytes: 16672
sub f{my$d+=pop;$c[$_-1]||=$';$d[$_]=$d,map f($d-1),@$_ if$d>$d[$_]}<>=~$";@c=(0)x$`;map{push@$_,$_[--$|]for@_=<>=~/\d+/g}1..$';<>;$_*=/ .* /,f$&for reverse<>;print"@c"

Measured memory_bytes: 117376
package main

import "fmt"

func main() {
	var c string
	fmt.Scanf("%s", &c)
	fmt.Println(succ(c))
}

func reverse(s string) string {
	ans := ""
	for i, _ := range s {
		ans += string(s[len(s)-i-1])
	}
	return string(ans)
}

func succ(s string) string {
	r := reverse(s)
	ans := ""
	carry := 1
	lastLetter := string(r[0])
	for i, _ := range r {
		lastLetter = string(r[i])
		a := lastLetter
		if carry == 1 {
			if lastLetter == "z" {
				a = "a"
				carry = 1
			} else {
				if r[i] == 0 {
					a = "1"
				} else {
					a = string(r[i] + 1)
					carry = 0
				}
			}
		}
		ans += a
	}
	if carry == 1 {
		if lastLetter == "z" {
			ans += "a"
		}
	}
	return reverse(ans)
}


Measured memory_bytes: 512
def calc(n, b):
    r = b[0]
    for i in range(1, n-1):
        r += min(b[i-1], b[i])
    r += b[len(b)-1]
    return r


n = int(input())
b = list(map(int, input().split()))

r = calc(n, b)
print(r)


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

int to_int(char s){
  if (s == 'A'){
    return 10;
  }else if (s == 'B'){
    return 11;
  }else if (s == 'C'){
    return 12;
  }else if (s == 'D'){
    return 13;
  }else if (s == 'E'){
    return 14;
  }else if (s == 'F'){
    return 15;
  }else{
    return -1;
  }
}

int main(){
  char x, y;
  cin >> x >> y;
  if (x == y){
    cout << "=" << endl;
  }else{
    int xx, yy;
    xx = to_int(x);
    yy = to_int(y);
    if (x < y){
      cout << "<" << endl;
    }else{
      cout << ">" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {

fast();

{
  int x,a,b;
  cin>>x>>a>>b;
  x=x-a;
  if(x>0)
  {
    if(x%b==0)
    {
      cout<<0<<endl;
    }
    else
    {
      cout<<x%b<<endl;
    }
  }
  
  
  

}
return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    k = int(input())

    res = 1
    for _ in range(n):
        if res < k:
            res *= 2
        else:
            res += k

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 2940
INF = 10 ** 10
n, _ = gets.split.map(&:to_i)
nums = gets.split.map(&:to_i)
lowest = INF
possible = 0
nums.each do |num|
  possible = [possible, (num - lowest)].max
  lowest = [lowest, num].min
end

count = 0
lowest = INF
nums.each do |num|
  count += [(num - lowest - possible + 1), 0].max
  lowest = [lowest, num].min
end

count_reverse = 0
highest = 0
nums.reverse.each do |num|
  count_reverse += [(highest - num - possible + 1), 0].max
  highest = [highest, num].max
end
puts [count, count_reverse].min


Measured memory_bytes: 11916
#include<cstdio>
#include<cstring>
int num[10]={0,1,2,3,4,5,6,7,8,9};
int check(int x)
{
    int flag=0,a;
    while(x)
    {
        a=x%10;
        if(num[a]==1)
        {
            flag=1;
            break;
        }
        x=x/10;
    }
    if(flag==1)
        return 0;
    if(flag==0)
        return 1;
}
int main()
{
    int n,k,d,i,D[15];
    while(scanf("%d %d",&n,&k)!=EOF)
    {
        memset(num,0,sizeof(num));
        for(i=0;i<k;i++)
        {
            scanf("%d",&d);
            num[d]=1;
        }
        for(i=n;;i++)
            if(check(i))
            {
                printf("%d\n",i);
                break;
            }
    }
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include <algorithm>
#include <string>
#include<math.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int main() {
    int a;
    cin >> a;
    cout << (a <= 999 ? "ABC" : "ABD") << endl;
    return 0;
}


Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
  string f = readln.chomp;
  string s = readln.chomp;
  auto n = f.length;
  bool flag = true;
  foreach (i; 0..n) {
    flag &= f[i] == s[$ - 1 - i];
  }
  writeln = flag ? "YES" : "NO";
}


Measured memory_bytes: 256
N,K = map(int,input().split())

mod = int(1e9+7)

##O(K)
upper = 0
for i in reversed(range(N+1-K,N+1)):
    upper += i
upper_point = N-K
##O(K)
lower = 0
for i in range(K):
    lower += i
lower_point = K
ans = 0

for i in range(K,N+2):
    ##print("N:",i,upper-lower+1)
    
    ans += upper - lower + 1
    upper += upper_point
    lower += lower_point

    upper_point -= 1
    lower_point += 1

print(ans%mod)


Measured memory_bytes: 9196
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <limits.h>
using namespace std;

typedef pair<int, int> P;

bool compare(const P &l, const P &r) {
  return l.second > r.second;
}

int max(int a, int b) {
  return (a > b) ? a : b;
}

int min(int a, int b) {
  return (a < b) ? a : b;
}

int main() {
  int w, n, c=0;
  P x[1000];
  int buf1[1001];
  int buf2[1001];
  int *p1, *p2, *tmp;
  int a, b;

  while (scanf("%d", &w) && w) {
    ++c;
    scanf("%d", &n);
    for (int i=0; i<n; i++) {
      scanf("%d,%d", &x[i].first, &x[i].second);
    }
    sort(x, x+n, compare);
    memset(buf1, 0, sizeof(int)*(w+1));
    memset(buf2, 0, sizeof(int)*(w+1));
    p1 = buf1;
    p2 = buf2;
    for (int i=0; i<n; i++) {
      int t = w-x[i].second;
      for (int j=0; j<=w; j++) {
        if (p1[j]) {
          p2[j] = max(p1[j], p2[j]);
          if (j<=t) p2[j+x[i].second] = max(p1[j+x[i].second], p1[j]+x[i].first);
        }
      }
      p2[x[i].second] = max(p1[x[i].second], x[i].first);
      tmp = p1;
      p1 = p2;
      p2 = tmp;
    }
    a = 0;
    for (int i=0; i<=w; i++) {
      a = max(a, p1[i]);
    }
    b = INT_MAX;
    for (int i=0; i<=w; i++) {
      if (p1[i]==a) {
        b = min(b, i);
      }
    }
    printf("Case %d:\n", c);
    printf("%d\n", a);
    printf("%d\n", b);
  }
  return 0;
}

Measured memory_bytes: 1052