akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int max(int a,int b,int c)
{
	if(a>=b&&a>=c)
	  return a;
	else if(b>=a&&b>=c)
	  return b;
	else
	  return c;
}
int function(int arr0[],int arr1[],int arr2[],int initial,int final,int k,int status,int memo[][3][3])
{
	if(initial>final)
	  return 0;
	if(memo[initial][k][status]!=-1)
	{
		  return memo[initial][k][status];
	}
	else
	{
		if(status==2)
		{
			if(k==0)
			{
				int x=arr1[initial]+function(arr0,arr1,arr2,initial+1,final,1,2,memo);
				int y=arr2[initial]+function(arr0,arr1,arr2,initial+1,final,2,2,memo);
				memo[initial][k][status]=x>y?x:y;
				return memo[initial][k][status];
			}
			else if(k==1)
			{
				int x=arr0[initial]+function(arr0,arr1,arr2,initial+1,final,0,2,memo);
				int y=arr2[initial]+function(arr0,arr1,arr2,initial+1,final,2,2,memo);
				memo[initial][k][status]=x>y?x:y;
				return memo[initial][k][status];
			}
			else
			{
				int x=arr1[initial]+function(arr0,arr1,arr2,initial+1,final,1,2,memo);
				int y=arr0[initial]+function(arr0,arr1,arr2,initial+1,final,0,2,memo);
				memo[initial][k][status]=x>y?x:y;
				return memo[initial][k][status];
			}
		}
		else
		{
			int x=arr0[initial]+function(arr0,arr1,arr2,initial+1,final,0,2,memo);
			int y=arr1[initial]+function(arr0,arr1,arr2,initial+1,final,1,2,memo);
			int z=arr2[initial]+function(arr0,arr1,arr2,initial+1,final,2,2,memo);
            return max(x,y,z);
		}
	}
}
int main()
{
	int n;
	cin>>n;
	int i,j,k;
	int arr0[n]={0},arr1[n]={0},arr2[n]={0};
	for(i=0;i<n;i++)
	{
		int x,y,z;
		cin>>x>>y>>z;
		arr0[i]=x;
		arr1[i]=y;
		arr2[i]=z;
	}
	int memo[n][3][3];
	for(i=0;i<n;i++)
	{
		for(j=0;j<3;j++)
		{
			for(k=0;k<3;k++)
			{
				memo[i][j][k]=-1;
			}
		}
	}
	int answer=function(arr0,arr1,arr2,0,n-1,0,1,memo);
	cout<<answer<<endl;
}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
#define FastRead                      \
                                    ios_base::sync_with_stdio(false); \
                                    cin.tie(0);
#define ll long long
#define endl "\n"
#define f for
using namespace std;
int main()

{
    FastRead
    ll int n,i,last,num,first,sum=0,j,c[10][10]= {0};
    cin>>n;
    f(i=1; i<=n; i++)
    {
        last=i%10;
        num=i;
        while(num!=0)
        {
            first=num%10;
            num=num/10;
        }

        c[first][last]++;

    }
    f(i=0; i<10; i++)
    {
        f(j=0; j<10; j++)
        {
            sum=sum+(c[i][j]*c[j][i]);
        }
    }
    cout<<sum;
    return 0;

}


Measured memory_bytes: 3616
n = int(input())
h = list(map(int, input().split()))
a = list(map(int, input().split()))

base = 1
while base <= n:
    base *= 2
tree = [0] * (base * 2)
dp = [0] * (n + 1)
# dp[i] - the max total beauty so far if the last taken flower has height i
for flower in range(n):
    # max dp[i] for i in [0, h[flower]-1]
    x = base + h[flower]
    best = 0
    while x > 1:
        if x % 2 == 1:
            best = max(best, tree[x - 1])
        x //= 2
    dp[h[flower]] = best + a[flower]
    i = base + h[flower]
    while i >= 1:
        tree[i] = max(tree[i], dp[h[flower]])
        i //= 2
print(max(dp))

Measured memory_bytes: 123600
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// std::ios::sync_with_stdio(false);

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

/*
 * 其实将每一个数都减去k就不用求平均值了, 然后就是求满足前缀和
 * sum[r]-sum[l-1]>=0, 有多少组就行了. 有点像逆序对.
 */

const int maxn = 2e5+5;

LL BIT[maxn];

/* incremental A[i] w/ value val */
void update(LL T[], const int n, int i, const LL val)
{
    if (i > 0) {
        while (i < n) {
            T[i] += val; i += (i & -i);
        }
    }
}

/* Query the *accumulative* value of A[1,i] */
LL query(const LL T[], int i)
{
    LL sum = 0;
    if (i > 0) {
        while (i > 0) {
            sum += T[i]; i -= (i & -i);
        }
    }
    return sum;
}

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    int N,K;
    while (cin >> N >> K) {
        memset(BIT,0,sizeof(BIT));
        LL sum[N+1], ans = 0;
        pair<LL,int> S[N+1];
        int A[N+1];
        sum[0] = 0;
        FOR(i,1,N+1) {
            LL a; cin >> a;
            sum[i] = sum[i-1] + a-K;
            S[i] = make_pair(sum[i],i);
            ans += sum[i] >= 0;
        }
        sort(S+1,S+N+1);
        FOR(i,1,N+1)
            A[i] = lower_bound(S+1,S+N+1, make_pair(sum[i],i)) - S;
        FOR(i,1,N+1) {
            const int j = A[i];
            ans += query(BIT,j);
            update(BIT,N+1,j,1);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 7296
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;
using int64 = long long;

int main() {
    int x, n;
    cin >> x >> n;
    vector<bool> p(102, false);
    for (int i=0; i<n; i++) {
        int a;
        cin >> a;
        p[a] = true;
    }
    for (int i=0; i<51; i++) {
        if (!p[x-i]) {
            cout << x-i << endl;
            return 0;
        }
        if (!p[x+i]) {
            cout << x+i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3184
/* Author : bhavye9499 - Bhavye Anand Gupta */

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

typedef long long ll;
typedef long double ld;

#define endl "\n"
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define showArr(A,a,n) {for(int i=a; i<a+n; i++) cout << A[i] << " "; cout << endl;}
#define showPair(A,a,n) {for(int i=a; i<a+n; i++) cout << A[i].fi << " " << A[i].se << endl;}

const ll MOD = 1e9 + 7;

ll dp[110][100100], W[110], V[110], n, w;

ll fun(ll i, ll j);

int main() {
    ios::sync_with_stdio(false);
    memset(dp, -1, sizeof(dp));
    cin >> n >> w;
    for(int i = 0; i < n; i++) {
    	cin >> W[i] >> V[i]; 
    }
    ll ans = fun(0, w);
    cout << ans << endl;
}

ll fun(ll i, ll j) {
	if(dp[i][j] != -1)
		return dp[i][j];
	if(i >= n)
		return dp[i][j] = 0;
	if(W[i] <= j)
		return dp[i][j] = max(V[i] + fun(i + 1, j - W[i]), fun(i + 1, j));
	return dp[i][j] = fun(i + 1, j);
}

Measured memory_bytes: 86272
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 2010
#define M 4010
int hd[N], nx[M], e[M];
int n, k, ans = -1;
int dfs(int x, int fa, int dep) {
    int num = dep > k / 2;
    for (int i = hd[x]; i; i = nx[i])
        if (e[i] != fa) num += dfs(e[i], x, dep + 1);
    return num;
}
int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1, Num = 0, x, y; i < n; i++) {
        scanf("%d%d", &x, &y);
        nx[++Num] = hd[x], hd[x] = Num, e[Num] = y;
        nx[++Num] = hd[y], hd[y] = Num, e[Num] = x;
    }
    if (k & 1) {
        for (int i = 1; i <= n; i++)
            for (int j = hd[i]; j; j = nx[j]) {
                int x = dfs(i, e[j], 0) + dfs(e[j], i, 0);
                if (ans == -1 || ans > x) ans = x;
            }
    } else
        for (int i = 1; i <= n; i++) {
            int x = dfs(i, 0, 0);
            if (ans == -1 || ans > x) ans = x;
        }
    printf("%d\n", ans);
    return 0;
}

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

int main(){
	int N;
	cin >> N;
	int A[N];
	map<int, int> M;
	for(int i=0; i<N; i++){
		cin >> A[i];
		M[A[i]]++;
	}
	int cnt = 0, ans = 0;
	for(int i=1; i<=100000; i++){
		if(M[i] % 2 == 0 && M[i] != 0) cnt++;
		if(M[i]) ans++;
	}
	if(cnt % 2 == 0) cout << ans << endl;
	else cout << ans - 1 << endl;
	return 0;
}

Measured memory_bytes: 5376
a,b,c,d = gets.chomp.chars

['+','-'].repeated_permutation(3) do |op1,op2,op3|
    e = a+op1+b+op2+c+op3+d
    x = eval(e)
    if x == 7
        puts "#{e}=7"
        exit
    end
end
puts "hoge"

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	string s; cin>>s;
	if(s=="RRR"s)cout<<3;
	else if(s.find("RR",0)!=string::npos)cout<<2;
	else if(s.find("R",0)!=string::npos)cout<<1;
	else cout<<0;
	cout<<"\n"s;
}


Measured memory_bytes: 3640
import java.util.*;
import java.util.stream.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int N = sc.nextInt();
    sc.nextLine();
    List<Integer> P = new ArrayList<>();
    for (int i = 0; i < N; i++) P.add(sc.nextInt());
    int ans = 0;
    int min = X;
    for (int i = 0; i <= 101; i++) {
      if (P.contains(i)) continue;
      if (min > Math.abs(X-i)) {
        ans = i;
        min = Math.abs(X-i);
      }
    }
    System.out.println(ans);
  }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef vector<pll> vll;
typedef vector<vl> vvl;

#define fori(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i >= 0; i--)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define trav(x, a) for (auto &x : a)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define endl '\n'
#define sz(a) (int)(a).size()
#define fi first
#define se second

clock_t time_p = clock();
void time_taken()
{
    time_p = clock() - time_p;
    cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}

const ll mod = 1e9 + 7;
const ll INF = 1e18;

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    int n,k;
    cin >> n >> k;
    vi a(n);
    fori(i, n)
    {
        cin >> a[i];
    }
    vi ans;
    rep(i, k, n - 1)
    {
        int remove = a[i - k];
        int add = a[i];
        if(remove < add){
            ans.pb(1);
        }
        else
            ans.pb(0);
    }
    for(int x:ans){
        cout << (x ? "Yes" : "No") << endl;
    }

    time_taken();
    return 0;
}

Measured memory_bytes: 5112
#include <cstdio>
#include <map>
using namespace std;

int main() {
    int N; scanf("%d", &N);
    map<int, int> mp;
    for(int i=0; i<N; i++) {
        int A; scanf("%d", &A);
        for(int k=A-1; k<=A+1; k++) {
            mp[k]++;
        }
    }

    int ans = 0;
    for(auto x : mp) {
        if(ans < x.second) {
            ans = x.second;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
int a, b, c, n;
int main(){
	scanf("%d%d%d%d", &a, &b, &c, &n);
	if(n<=a) cout<< n;
	else if(n<=a+b) cout<< a;
	if(n>a+b) cout<< a-n+a+b;
	return 0;
}

Measured memory_bytes: 3616
N=int(input())
l=list(map(int,input().split()))
ans=[0]*(N+1)
for i,j in enumerate(l):
   ans[i+1]=ans[i]+j
ans.pop(0)
import collections
f_ans=collections.Counter(ans)
ans=f_ans[0]
f_ans=[i for i in list(f_ans.values()) if i>1]
from scipy.special import comb
for i in f_ans:
   ans+=comb(i,2)
print(int(ans))

Measured memory_bytes: 49884
using System;
class Program
{
  static void Main()
  {
    int N = int.Parse(Console.ReadLine());
    string[] A = Console.ReadLine().Split(' ');
    string[] B = Console.ReadLine().Split(' ');
    string[] C = Console.ReadLine().Split(' ');
    
    int satis = 0;
    int bmeal = -2; // 0 ~ N-1
    for (int i = 0; i < N; i++)
    {
      int meal = int.Parse(A[i]); // 0 ~ N-1
      satis += int.Parse(B[meal - 1]);
      if (bmeal + 1 == meal)
      {
        satis += int.Parse(C[meal - 2]);
      }
      bmeal = meal;
    }
   
    Console.WriteLine(satis);
  }
}

Measured memory_bytes: 11092
N, M = map(int, input().split())


class BellmanFord(object):
    def __init__(self, edges, n_nodes, start):
        self.edges = edges
        dist = [float('inf')] * n_nodes
        dist[start] = 0
        prev = [None] * n_nodes

        for _ in range(n_nodes - 1):
            for u, v, weight in edges:
                if dist[u] == float('inf'):
                    continue
                if dist[v] > dist[u] + weight:
                    dist[v] = dist[u] + weight
                    prev[v] = u
        self.dist = dist
        self.prev = prev

    def check(self, goal=None):
        if goal is None:
            for u, v, weight in self.edges:
                if self.dist[v] > self.dist[u] + weight:
                    return False
            return True
        else:
            negative = [False] * N
            for _ in range(N):
                for u, v, weight in self.edges:
                    if self.dist[u] == float('inf'):
                        continue
                    if negative[u] or self.dist[v] > self.dist[u] + weight:
                        negative[v] = True
            return not negative[goal]


edges = [None] * M
for i in range(M):
    a, b, c = map(int, input().split())
    edges[i] = (a - 1, b - 1, -c)

bf = BellmanFord(edges, N, 0)
if bf.check(N - 1):
    print(-bf.dist[N - 1])
else:
    print('inf')


Measured memory_bytes: 3308
inputf = input

N, K = [int(x) for x in inputf().split(" ")]
P = [int(x) for x in inputf().split(" ")]
exp = [ (p*(p+1)//2)/p for p in P]
res = []
res.append(sum(exp[:K]))
for i in range(N-K):
    res.append(res[i]-exp[i]+exp[i+K])
print(max(res))

Measured memory_bytes: 80736
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int N;

int main(){
    cin >> N;
    map<ll,ll> a;
    rep(i,N){
        ll A;
        cin >> A;
        a[A]++;
    }


    ll v = -1;
    for(auto p : a){
        if(p.se >= 2){
            v = p.fi;
        }
    }


    ll x = v;
    a[v] -= 2;

    v = -1;

    for(auto p : a){
        if(p.se >= 2){
            v = p.fi;
        }
    }

    ll y = v;

    if(x < 0 or y < 0){
        cout << 0 << endl;
        return 0;
    }

    ll ans = x * y;
    cout << max(0ll,ans) << endl;
}


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

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

    ll A, B, C;
    cin >> A >> B >> C;

    if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0) {
        cout << 0 << endl;
    } else {
        if (A > B) swap(A, B);
        if (B > C) swap(B, C);
        cout << A * B << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <climits>
#include <iomanip>
#include <math.h>
using namespace std;
#define MAXSIZE 100005
#define PI 3.141592653589793
#define MOD_CONST 1000000007
typedef long long int lli;

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

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

int main()
{
    int n;
    cin >> n;
    vector<int> m(n);
    for (int i = 0; i < n - 1; i++)
    {
        int t;
        cin >> t;
        m[t]++;
    }
    for (int i = 1; i < n; i++)
    {
        cout << m[i] << "\n";
    }
    cout << "0";
    return 0;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef pair<ll, ll> P;
#define INF (1LL << 31)
#define FOR(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define PRINT(V) for (auto v : (V)) cout << v << " "

int main()
{
    string s, t; cin >> s >> t;
    
    vector<string> ans;
    ll dif_st;
    if (t.size() <= s.size()){
        dif_st = s.size() - t.size();
    }else{
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    string sa = s;
    replace(sa.begin(), sa.end(), '?', 'a');
    
    rep(i, dif_st + 1){
        bool f = true;
        string u = "";

        
        rep(j, t.size()){
            if (s[i + j] == t[j] || s[i + j] == '?') {
                u += t[j];
            }else{
                f = false;
            }
        };
        
        if (f) {
            string v = sa;
            v.replace(i, u.size(), u);
            ans.push_back(v);
        }
    };

    sort(ans.begin(), ans.end());
    if (ans.size() == 0) cout << "UNRESTORABLE" << endl;
    else cout << ans[0] << endl;
    return 0;
}


Measured memory_bytes: 256
#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() {
	int n, k;
	cin >> n >> k;
	int res = 1;
	rep(i, n) {
		res = min(res + k, res * 2);
	}
	cout << res << endl;
	return 0;
}

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

public class Main {
	public static void main(String[] args) {

		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
			int n = Integer.parseInt(br.readLine());
			String[] str = br.readLine().split(" ");
			int s[] = new int[n + 1];
			for (int i = 0; i < n; i++) {
				s[i] = Integer.parseInt(str[i]);
			}
			int q = Integer.parseInt(br.readLine());
			str = br.readLine().split(" ");
			int cnt = 0;
			for (int i = 0; i < q; i++) {
				int key = Integer.parseInt(str[i]);
				if (linearSearch(s, key) != -1) {
					cnt++;
				}
			}
			System.out.println(cnt);

		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	static int linearSearch(int[] s, int key) {

		s[s.length - 1] = key;
		int i = 0;
		while (s[i] != key) {
			i++;
		}
		if (i == s.length - 1) {
			return -1;
		}
		return i;

	}

}



Measured memory_bytes: 26812
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;
typedef long long ll;
const int N = 1000005,p = 9901,MOD = 1e9+7;
vector<ll> G[N];
ll Hash[N];
map<ll,ll> m;
map<ll,ll>::iterator it;
void dfs(ll u)
{
    Hash[u] = 1;
    for(int i = 0;i < G[u].size();i++)
    {
        ll v = G[u][i];
        dfs(v);
        Hash[u] = (Hash[u]+Hash[v]*p)%MOD;
    }
    m[Hash[u]]++;
}
int main()
{
    int n,u,v;
    cin >> n;
    for(int i = 1;i <= n-1;i++)
    {
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
    }
    dfs(1);
    ll ans = 0;
    for(it = m.begin();it != m.end();it++)
        ans += it->second*(it->second-1)/2;
    printf("%lld\n",ans);
    return 0;
}

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

int main(){
  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;

  if( A1 + A2 + A3 >= 22 ){
    cout << "bust" << endl;
  }else{
    cout << "win" << endl;
  }

}


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

using namespace std;


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

	int n;
	cin>>n;

	vector<vector<int>> happiness(n,vector<int>(3));

	for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>happiness[i][j];
        }
	}

	vector<vector<int>> dp(n,vector<int>(3));
	dp[0]=happiness[0];
	for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(((j+1)^(k+1))!=0){
                    dp[i][j]=max(happiness[i][j]+dp[i-1][k],dp[i][j]);
                }
            }
        }
	}
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<'\n';
	return 0;
}


Measured memory_bytes: 14264
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0

for i in range(N):

  for j in range(i + 1, N):
    
    cnt += bisect.bisect_left(L, L[i] + L[j]) - (j + 1)

print(cnt)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
int main(){
    string s,c;
//    c = "coffee";
    cin >> s;
    LL  s_len = s.length();
    vector<string> c_ary(c.length());
    vector<string> s_ary(s.length());
    for (int i = 0; i < s_len; i++) {
//        cout << s.substr(i,1) << endl;
//        c_ary[i] = c.substr(i,1);
        s_ary[i] = s.substr(i,1);
    }
    if(s_ary[2] == s_ary[3] && s_ary[4] == s_ary[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
/*
    bool ans_flg = 1;
    for (int i = 2; i < s_len; i++) {
        if(s_ary[i] != c_ary[i]) ans_flg = 0;
        cout << i << "s_ary[i] :" << s_ary[i] << "c_ary[i] :" << c_ary[i] << endl;
    }
    if(ans_flg = 1) cout << "Yes" << endl;
    else cout << "No" << endl;
*/
    return 0;
}

Measured memory_bytes: 256
N = int(input())
w = list(map(int, input().split(' ')))


border = N // 2
w1 = sum(w[:border])
w2 = sum(w[border:])

sub = w1 - w2
direction = None
if sub > 0:
  # w1が大きい
  direction = -1
  border -= 1
elif sub < 0:
  # w2が大きい
  direction = 1
else:
  # 両者等しい
  print('0')
  exit()

prev_sub = 0
while(True):
  prev_sub = sub
  w1 += direction * w[border]
  w2 += -direction * w[border]
  border += direction

  sub = w1 - w2
  if abs(sub) >= abs(prev_sub):
    print(abs(prev_sub))
    exit()


Measured memory_bytes: 3064
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

def gcd(x, y):
    if x < y:
        x = x ^ y
        y = x ^ y
        x = x ^ y
    div = x % y
    while div != 0:
        x = y
        y = div
        div = x % y
    return y


N=II()
MP1={}
A0 = 0
B0 = 0
AB0 = 0
RES=1
for i in range(N):
    A, B = LI()
    if A*B != 0:
        G = gcd(abs(A),abs(B))
        A //= G
        B //= G
        v = (abs(A), abs(B), A*B > 0)
        if not v in MP1:
            MP1[v] = 1
        else:
            MP1[v] += 1

    if A == 0 and B != 0: A0 += 1
    if A != 0 and B == 0: B0 += 1
    if A == 0 and B == 0: AB0 += 1

# print(MP1)

VIS = set()
for (vv, n) in MP1.items():
    (A, B, isPos) = vv
    v = (B, A, not isPos)
    if not v in VIS and not vv in VIS:
        VIS.add(v)
        VIS.add(vv)
        if v in MP1:
            m = MP1[v]
            RES = (RES*POW(2, n))%DVSR + (RES*POW(2, m))%DVSR - RES
            RES %= DVSR
        else:
            RES *= POW(2, n)
            RES %= DVSR

if A0 and B0:
    RES = (RES*POW(2, A0))%DVSR + (RES*POW(2, B0))%DVSR - RES
elif A0:
    RES = RES*POW(2, A0)%DVSR
elif B0:
    RES = RES*POW(2, B0)%DVSR


print((RES+AB0-1)%DVSR)


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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll C[30];

int main()
{
    string S;
    cin >> S;
    memset(C, 0, sizeof(C));
    REP(i, S.length())
    {
        if (i > 0 && S[i] == S[i - 1])
        {
            cout << i << " " << i + 1 << endl;
            return 0;
        }

        if (i > 0 && i < S.length() - 1 && S[i - 1] == S[i + 1])
        {
            cout << i << " " << i + 2 << endl;
            return 0;
        }
    }
    cout << "-1 -1" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100000
char arr[MAXN+10];
int awal,n,akhir,lastawal,lastakhir,res;
bool flag,cek;
int main(){
    fgets(arr,MAXN+5,stdin);
    for(n = 0; arr[n]!='\n'; n++);
    awal = 0;
    akhir = n-1;
    lastawal = awal;
    lastakhir = akhir;
    flag = true;
    while(awal<akhir){
        while(awal<akhir and arr[awal]=='x')awal++;
        while(awal<akhir and arr[akhir]=='x')akhir--;
        if(awal>=akhir)break;
        if(arr[awal]!=arr[akhir]){
            flag = false;
            break;
        }
        res += abs((awal-lastawal)-(lastakhir-akhir));
        lastawal = awal;
        lastakhir = akhir;
        awal++;
        akhir--;
    }
    if(arr[awal] !='x')res += abs((awal-lastawal)-(lastakhir-akhir));
    for(int i = 0; i < n; i++){
        if(arr[i]!='x')cek = true;
    }
    if(!cek){
        cout<<0<<endl;
        return 0;
    }
    if(!flag){
        cout<<-1<<endl;
        return 0;
    }else{
        cout<<res<<endl;
    }

}


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

// {{{
#define PI pair<int, int>
#define mk make_pair
#define reg register
#define ll long long
#define rep(i, a, b) for(reg int i = a; i <= b; ++i)
#define per(i, a, b) for(reg int i = a; i >= b; --i)
// }}}

using namespace std;

inline int min(reg int a, reg int b) { return a < b ? a : b; }
inline int max(reg int a, reg int b) { return a > b ? a : b; }
inline int read() {
  reg int s = 0; reg char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
  return s;
}

int main() {
  int n = read(), k = read();
  if (n < k) puts("0");
  else puts("10");
  return 0; 
}


/*******************************************
 _________________________________________
< A.cpp is created by zrz who is weak >
 -----------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
********************************************/

Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		long n = long.Parse(Console.ReadLine());//int.Parseは文字列を整数に変換。
		long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    long[] defaultPass = new long[n+1];
    long[] skipPass = new long[n];
    long sumMemo = 0;
    long answer = 0;
    
    for(long i = 1; i < n-1; i++)
    {
      defaultPass[i] = Math.Abs(nums[i] - nums[i-1]);
      skipPass[i] = Math.Abs(nums[i+1] - nums[i-1]);
    }
    defaultPass[0] = Math.Abs(nums[0]);
    skipPass[0] = Math.Abs(nums[1]);
    defaultPass[n-1] = Math.Abs(nums[n-1] - nums[n-2]);
    defaultPass[n] = Math.Abs(nums[n-1]);
    skipPass[n-1] = Math.Abs(nums[n-2]);

    for(long i = 0; i <= n; i++)
    {
      sumMemo += defaultPass[i];
      //Console.WriteLine(sumMemo);
    }

    for(long i = 0; i < n; i++)
    {
      answer = sumMemo;
      //Console.WriteLine(answer);
      answer -= defaultPass[i] + defaultPass[i+1];
      //Console.WriteLine(answer);
      answer += skipPass[i];
      Console.WriteLine(answer);
    }
	}
}

Measured memory_bytes: 26844
# -*- coding: utf-8 -*-
# get two integers separated with half-width break
N, M = map(int, raw_input().split())
n = []
m = []
for i in range(N):
    n.append(map(int, raw_input().split()))

for i in range(M):
    m.append(map(int, raw_input().split()))

for i in range(N):
    distances = [abs(n[i][0] - m[j][0]) + abs(n[i][1] - m[j][1]) for j in range(M)]
    print(distances.index(min(distances)) + 1)


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

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll ac{0},wa{0},tle{0},re{0};
    ll t;
    cin>>t;
    while(t--)
    {
       string s;
       cin>>s;
       
       if(s=="AC")
       {
            ac++;
       }
       else if(s=="WA")
       {
            wa++;
       }
       else if(s=="TLE")
       {
            tle++;
       }
        else if(s=="RE")
       {
            re++;
       }
     }
    cout<< "AC x "<<ac<<endl;
       cout<< "WA x "<<wa<<endl;
       cout<< "TLE x "<<tle<<endl;
       cout<< "RE x "<<re<<endl;
    return 0;
}

Measured memory_bytes: 3656
/**Author:Sagor*/

#include<bits/stdc++.h>

using namespace std;
#define pri(n)          printf("%d\n",n)
#define prll(n)         printf("%lld\n",n)
#define prd(n)          printf("%lf\n",n)
#define scll(n)         scanf("%lld",&n)
#define sci(n)          scanf("%d",&n)
#define scd(n)          scanf("%lf",&n)
#define pi              acos(-1)
#define ll              long long
#define pb              push_back
#define vsort(v)        sort(v.begin(),v.end())
#define asort(n)        sort(ar,ar+n)
#define for1(i,n)       for(i=1;i<=n;i++)
#define for0(i,n)       for(i=0;i<n;i++)
#define mod             1000000007
#define watch(x)        cout << (#x) << " is " << (x) <<"\n";
#define LIMIT           10000000 /**upto 10^8*/
bool prime[10000003];
int onlyprime[1000009];

void SieveOfEratosthenes()
{
	for(int i=4;i<=LIMIT;i+=2) prime[i]=true;

	for (int p=3; p*p<=LIMIT; p+=2)
	{
		if (prime[p] == false)
		{
			for (int i=p*p; i<=LIMIT; i += (2*p))
				prime[i] = true;
		}
	}
	onlyprime[0]=2;
	int k=1;
	for(int i=3;i<=LIMIT;i+=2){
        if(prime[i]==false){
            onlyprime[k++]=i;
        }
	}
}
ll occurance[1000009];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);/**Dont't use scanf of printf*/
    ll t,i,pro,a,cnt=0,q,j,root,r,n;
    cin>>n;
    ll ar[n+5];
    for0(i,n){
        cin>>ar[i];
        occurance[ar[i]]++;
    }
    if(occurance[1]>=2) cout<<"0\n";
    else if(occurance[1]==1) cout<<"1\n";
    else{
        for0(i,n){
            bool flag=0;
            if(occurance[ar[i]]>1) continue;
            root=sqrt(ar[i]);
            for(j=2;j<=root;j++){
                if(ar[i]%j==0 && (occurance[j]>0 || occurance[ar[i]/j]>0)){
                    flag=1;
                    break;
                }
            }
            if(flag==0) cnt++;
        }
        cout<<cnt<<"\n";
    }



    return 0;
}


Measured memory_bytes: 12956
#include<cstdio>
#include<cstring>
#define MAXN 500000
struct node
{
	int key;
	node *fa;
	node *ch[2];
}tree[MAXN+5];
node *Root,*NIL,*ncnt;
void Init()
{
	NIL=&tree[0];
	ncnt=&tree[1];
	NIL->ch[0]=NIL;
	NIL->ch[1]=NIL;
	NIL->fa=NIL;
	Root=NIL;
}
inline node *NewNode(int val)
{
	node *p=++ncnt;
	p->key=val;
	p->ch[0]=p->ch[1]=NIL;
	return p;
}
void Insert(node *&rt,node *fa,int val)
{
	if(rt==NIL)
	{
		node *p=NewNode(val);
		p->fa=fa;
		rt=p;
		return;
	}
	int d=(val>=rt->key);
	Insert(rt->ch[d],rt,val);
}
void PreOrder(node *rt)
{
	if(rt==NIL)
		return;
	printf(" %d",rt->key);
	PreOrder(rt->ch[0]);
	PreOrder(rt->ch[1]);
}
void InOrder(node *rt)
{
	if(rt==NIL)
		return;
	InOrder(rt->ch[0]);
	printf(" %d",rt->key);
	InOrder(rt->ch[1]);
}
node *Find(node *rt,int val)
{
	if(rt==NIL)
		return NIL;
	if(rt->key==val)
		return rt;
	int d=(val>=rt->key);
	return Find(rt->ch[d],val);
}
node *FindNext(node *rt)
{
	if(rt==NIL)
		return NIL;
	node *y=rt->ch[1];
	while(y->ch[0]!=NIL)
		y=y->ch[0];
	return y;
}
void Delete(node *rt,int val)
{
	node *x,*y,*z=Find(rt,val);
	if(z==NIL)	//for safety
		return;

	if(z->ch[0]==NIL||z->ch[1]==NIL)	//make sure y
		y=z;
	else
		y=FindNext(z);

	if(y->ch[0]!=NIL)	//make sure x
		x=y->ch[0];
	else
		x=y->ch[1];

	if(x!=NIL)	//make sure fa(y isn't leaf)
		x->fa=y->fa;

	if(y->fa==NIL)	//val==Root->val(delete Root)
		Root=y;

	else if(y==y->fa->ch[0])	//make sure ch
		y->fa->ch[0]=x;
	else if(y==y->fa->ch[1])
		y->fa->ch[1]=x;

	if(y!=z)	//sp
		z->key=y->key;
}
int main()
{
	Init();
	int n,x;
	char op[100];
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%s",op);
		if(op[0]=='i')
			scanf("%d",&x),Insert(Root,NIL,x);
		else if(op[0]=='p')
		{
			InOrder(Root);
			printf("\n");
			PreOrder(Root);
			printf("\n");
		}
		else if(op[0]=='f')
		{
			scanf("%d",&x);
			if(Find(Root,x)!=NIL)
				printf("yes\n");
			else
				printf("no\n");
		}
		else if(op[0]=='d')
		{
			scanf("%d",&x);
			Delete(Root,x);
		}
	}
	return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    ll n, k; cin >> n >> k;
    ll g, m = 0; // gcd, max
    bool ok ;
    vector<ll> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    if(n == 1) {
        if(a[0] != k) ok = false; 
        else ok = true;
    }
    else {
        ll g, m; // gcd, max
        g = my_gcd(a[0], a[1]);
        rep(i, n) {
            if(m < a[i]) m = a[i];
            g = my_gcd(g, a[i]);
        }
        // kが大きすぎ
        if(k > m) ok = false;
        else {
            // 1が作れる
            if(g == 1) ok = true;
            // 割り切れる
            else if((k%g) == 0) ok = true;
            // 割り切れない
            else ok = false;
        }
    }
    if(ok) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;

    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

vector<vector<int>> g(100001);
vector<int> d1(100001);
vector<int> d2(100001);
void dfs1(int p,int x){
	for(int i = 0; i < g[x].size(); i++) {
		if (p != g[x][i]){
			d1[g[x][i]] = d1[x] + 1;
			dfs1(x,g[x][i]);
		}
	}
}

void dfs2(int p,int x){
	for(int i = 0; i < g[x].size(); i++) {
		if(p != g[x][i]){
			d2[g[x][i]] = d2[x] + 1;
			dfs2(x,g[x][i]);
		}
	}
}

int main(){
	int n;cin>>n;
	for(int i = 0; i < n - 1; i++) {
		int a,b;cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
	}
	d1[1] = 0;
	d2[n] = 0;
	dfs1(1,1);
	dfs2(n,n);
	int fe = 0,su = 0;
	for(int i = 1; i <= n; i++) {
		// cout << "fe->" << d1[i] << " su->" << d2[i] << endl;
		if (d1[i] <= d2[i]){
			fe++;
		}
		else{
			su++;
		}
	}
	if (fe > su){
		cout << "Fennec" << endl;
	}
	else{
		cout << "Snuke" << endl;
	}
	return 0;
}

Measured memory_bytes: 11136
ans = 0
ans_tmp = 0
s = input()
for i in range(len(s)):
    ans_tmp = 0
    for s_bubun in s[i:]:
        if s_bubun in ("A","T","G","C"):
            ans_tmp +=1
        else:
            break
    ans = max(ans_tmp,ans)
print(ans)

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int n;
    cin >> n;
    int a[n + 2] = {};
    ll sum = 0;
    rep(i, n) {
        cin >> a[i + 1];
        sum += abs(a[i + 1] - a[i]);
    }
    sum += abs(a[n + 1] - a[n]);
    rep(i, n) {
        cout << sum - abs(a[i + 1] - a[i]) - abs(a[i + 2] - a[i + 1]) + abs(a[i + 2] - a[i]) << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll mod = 1e9+7;
 ll n , k;
ll dp[100002][101][2];
string num;

ll func(ll pos , ll N , ll f , ll sum)
{
    if(pos == N)
    {
           
        if(sum%k == 0)
        {
            return 1;
        }
        return 0;
    }

    if(dp[pos][sum][f] != -1 && f == 0)
    {
        return dp[pos][sum][f]%mod;
    }

    ll limit ;
    if(f == 1)
    limit = num[pos]-48;
    else
    limit = 9;
    ll ans = 0;
    for(ll i = 0 ; i <= limit ; i++)
    {
        ll nf = f;
        if(i != limit)
        nf = 0;
        ll new_sum =(sum + i)%k;
       ans = (ans%mod + func(pos+1 , N , nf , new_sum )%mod)%mod;
    }

    dp[pos][sum][f] = ans;
    return ans;
}

int main() {
    cin >> num;
    cin >> k;
    ll N = 0 ;
    ll temp = n;
    for(ll i = 0 ; i <= 100001 ; i++)
    {
        for(ll j = 0 ; j <= 100 ; j++)
        dp[i][j][0] = -1 , dp[i][j][1] = -1;
    }
    N = num.size();

 
    ll ans = (func(0, N , 1 , 0)-1);
    if(ans < 0)
    ans += mod;

    cout << ans;
}


Measured memory_bytes: 162216
#include<bits/stdc++.h>
using namespace std;    
int main()
{
    ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    int a[n],sum=0,ans=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    sort(a,a+n,greater<int>());
    int p=(sum+4*m-1)/(4*m);
    bool flag=true;
    for(int i=0;i<m;i++)
    {
        if(a[i]<p)
        {
            flag=false;
            break;
        }
    }
    if(flag==true)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    
    return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import System.IO.Unsafe
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
-- end of templete

f :: [(Char, Char)] -> Char -> Char
f [] c = c
f ((x,y):s) c = if c==x then y else f s c

g :: String -> (Char, Char)
g (x:_:y:_) = (x,y)

main = do
    n <- getInt
    when (n/=0) $ do
        t <- map g <$> replicateM n getLine
        m <- getInt
        replicateM m getLine >>= putStrLn . map (f t . head)
        main

Measured memory_bytes: 22808
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000






int main() {
	int a[N];
	int n, x, y;
	x = -1;
	y = -1;
	scanf("%d", &n);
	f(i, n) {
		scanf("%d", &a[i]);
		if (a[i] > x) {
			y = x;
			x = a[i];
		}
		else if (a[i] > y)y = a[i];
	}

	f(i, n) {
		if(a[i]==x)printf("%d\n", y);
		else printf("%d\n", x);
	}



	return 0;
}

Measured memory_bytes: 2304
N=int(input())
A=list(map(int,input().split()))
value=A[0]
araiguma=sum(A[1:])
num=int(abs(value-araiguma))
for i in range(1,N-1):
    value+=A[i]
    araiguma-=A[i]
    temp=int(abs(value-araiguma))
    if num>temp:num=temp
print(num)


Measured memory_bytes: 23800
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<utility>
using namespace std;

int main() {
	int n, q, t;
	string name;
	queue<pair<string, int> > Q;

	cin >> n >> q;

	for (int i = 0; i < n; i++) {
		cin >> name >> t;
		Q.push(make_pair(name, t));
	}

	pair<string, int> u;
	int elaps = 0, a;

	while (!Q.empty()) {
		u = Q.front(); Q.pop();
		a = min(u.second, q);
		u.second -= a;
		elaps += a;
		if (u.second > 0) {
			Q.push(u);
		}
		else {
			cout << u.first << " " << elaps << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 6316
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String S = scan.next();
        char[] data = S.toCharArray();
        TreeMap<Integer, Integer> a = tree('A', data);
        TreeMap<Integer, Integer> b = tree('B', data);
        TreeMap<Integer, Integer> c = tree('C', data);
        TreeMap<Integer, Integer> questions = tree('?', data);
        int Q = questions.size() - 2;
        long ans = 0;
        long mod = 1000000007;
        for (int center : b.keySet()) {
            if (center == 0 || center == 100010) {
                continue;
            }
            int x_right = a.lowerKey(center);
            int x_right_count = a.get(x_right);
            int x_question = questions.floorKey(x_right);
            int x_question_count = questions.get(x_question);
            long left1 = (long) (x_right_count - x_question_count) * pow(3, x_question_count, mod);
            left1 %= mod;
            long left2 = x_question_count < 1 ? 0 : x_question_count * pow(3, x_question_count - 1, mod);
            left2 %= mod;
            long left = left1 + left2;
            left %= mod;

            int z_left = c.higherKey(center);
            int z_left_count = c.size() - c.get(z_left) - 1;
            int z_question = questions.ceilingKey(z_left);
            int z_question_count = questions.size() - questions.get(z_question) - 1;
            long right1 = (long) (z_left_count - z_question_count) * pow(3, z_question_count, mod);
            right1 %= mod;
            long right2 = z_question_count < 1 ? 0 : z_question_count * pow(3, z_question_count - 1, mod);
            right2 %= mod;
            long right = right1 + right2;
            right %= mod;

            long subtotal = left * right;
            subtotal %= mod;
            ans += subtotal;
            ans %= mod;
        }
        System.out.println(ans);
    }
    long pow(int base, int count, long mod) {
        if (count == 0) {
            return 1;
        }
        if (count % 2 == 1) {
            long x = base * pow(base, count - 1, mod);
            x %= mod;
            return x;
        }
        long x = pow(base, count/2, mod);
        x %= mod;
        x *= x;
        x %= mod;
        return x;
    }
    TreeMap<Integer, Integer> tree(char target, char[] data) {
        TreeMap<Integer, Integer> x = new TreeMap<>();
        int count = 0;
        x.put(0, count);
        for (int i = 1; i <= data.length; i++) {
            if (data[i-1] == target || data[i-1] == '?') {
                x.put(i, ++count);
            }
        }
        x.put(100010, ++count);
        return x;

    }
}


Measured memory_bytes: 85692
#include<iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;
int main()
{
    int A[50];
   string s;
   int w,n;
    A[0]=0;
   while(cin>>w>>n)
   {
        for(int i=1;i<=w;i++)
       {
           A[i]=i;
       }
       while(n--)
       {

       cin>>s;
       int len=s.length();
       int d=s.find(',',0);
       string a=s.substr(0,d);
       string b=s.substr(d+1,len-1);
       int c=atoi(a.c_str());
       int e=atoi(b.c_str());
      // cout<<a<<endl<<b<<endl<<c<<endl<<e<<endl;
         int h= A[c];
         A[c]=A[e];
         A[e]=h;

       }
for(int i=1;i<=w;i++)
      cout<<A[i]<<endl;
   }
}

Measured memory_bytes: 1220