akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int dx[]={0,0,-1,1};
int dy[]={-1,1,0,0};
int n,m,a;
int solve(){
	vector<int>x(a+1);
	vector<int>y(a+1);
	vector<vector<char> >in(n+2,vector<char>(m+2));
	rep(i,n+2)rep(j,m+2){
		if(!i||!j||i==n+1||j==m+1)in[i][j]='X';
		else cin>>in[i][j];
		if(in[i][j]=='S')in[i][j]='0';
		if(isdigit(in[i][j])){
			int d=in[i][j]-'0';
			x[d]=i;y[d]=j;
		}
	}
	int out=0;
	rep(i,a){
		vector<vector<int> >tmp(n+2,vector<int>(m+2));
		vector<int>nx;
		vector<int>ny;
		rep(j,n+2)rep(k,m+2)tmp[j][k]=inf;
		tmp[x[i]][y[i]]=0;
		nx.pb(x[i]);
		ny.pb(y[i]);
		while(nx.size()){
			//rep(j,n+2){rep(k,m+2)cout<<tmp[j][k];cout<<endl;}
			if(nx[0]==x[i+1]&&ny[0]==y[i+1]){out+=tmp[nx[0]][ny[0]];break;}
			rep(j,4){
				if(in[nx[0]+dx[j]][ny[0]+dy[j]]!='X'&&tmp[nx[0]+dx[j]][ny[0]+dy[j]]>tmp[nx[0]][ny[0]]+1){
					tmp[nx[0]+dx[j]][ny[0]+dy[j]]=tmp[nx[0]][ny[0]]+1;
					nx.pb(nx[0]+dx[j]);
					ny.pb(ny[0]+dy[j]);
				}
			}
			nx.erase(nx.begin());
			ny.erase(ny.begin());
		}
	}
	return out;
}
int main(){
	cin>>n>>m>>a;
	cout<<solve()<<endl;
}

Measured memory_bytes: 6020
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define INF             1e14
#define dd              double
#define MOD             1000000007
#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) 
#define nl              cout<<endl
#define fill(a,val)     memset(a,val,sizeof(a))
#define mp              make_pair
#define endl            "\n"
#define pb              push_back
#define ff              first    
#define ss              second
#define SIZE            200005
#define all(v)          v.begin(),v.end()
#define s(ar,n)         sort(ar,ar+n)
#define rs(ar,n)        sort(ar, ar+n, greater<ll>()) 
#define oa(a,n)         for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n)         for(ll i=0;i<n;i++)cin>>a[i];
#define maxa(ar,N)      *max_element(ar,ar+N)
#define mina(ar,N)      *min_element(ar,ar+N)
#define fastio()        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define printclock      cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
ll power(ll x, ll y){
    ll res=1;x=x;
    while(y>0){
        if(y&1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}  
ll logtwo(ll n){
    if(n==1)
        return 0;
    return logtwo(n/2)+1;
}
signed main()
{
    fastio(); 
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll N,M,K;
        cin>>N>>M>>K;
        if((M%N==0)||(K%N==0)||(K/N-M/N)>0)
            cout<<"OK"<<endl;
        else
            cout<<"NG"<<endl;
    }
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  if (s.size() % 2 == 0 && s.substr(0, n / 2) == s.substr(n / 2, n / 2)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

int main(){
    int x, y;
    cin >> x >> y;
    bool flag = false;
    for(int i = 0; i <= x; i++){
        int legs = 2*i + 4*(x-i);
        if(legs == y)flag = true;
    }
    string ans = "No";
    if(flag)ans = "Yes";
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int gi()
{
	char c; int x=0,f=1;
	for(;c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
	for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+c-'0';
	return x*f;
}
const int N=1e5+5,Mod=1e9+7;
char a[N];
inline int po(int x, int y)
{
	int r=1;
	while(y)
	{
		if(y&1) r=1ll*r*x%Mod;
		x=1ll*x*x%Mod, y>>=1;
	}
	return r;
}
int main()
{
	scanf("%s",a+1);
	int n=strlen(a+1);
	int ans=po(3,n-1),ret=2;
	for(int i=2;i<=n;++i)
	{
		if(a[i]=='0') continue;
		ans=(ans+1ll*ret*po(3,n-i)%Mod)%Mod;
		ret=2ll*ret%Mod;
	}
	printf("%d",(ans+ret)%Mod);
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    long long int mul = 1;
    long long int a[100010];
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        if(a[i] == 0){
            return cout << 0 , 0;
        }
    }
    for(int i = 1; i <= n; i++){
       if(a[i] > powl(10, 18) / mul) return cout <<-1, 0; 
        else mul *= a[i];
    }
    return cout << mul , 0;
}

Measured memory_bytes: 4416
/* (c) 2018 nupetan */
#include <stdio.h>
int main(){
	int amount,rank,i,j;
	int cards[4][14]={};
	char type;

	scanf("%d",&amount);

	while(amount--){
		scanf(" %c",&type);
		scanf("%d",&rank);
		switch(type){
			case 'S':cards[0][rank]=1;break;
			case 'H':cards[1][rank]=1;break;
			case 'C':cards[2][rank]=1;break;
			case 'D':cards[3][rank]=1;break;
			default :printf("Error invalid inputs\n");
					return -1;
		}
	}

	for(i=0;i<4;i++){
		for(j=1;j<14;j++){
			if(cards[i][j]==0){
				switch(i){
					case  0:printf("S %d\n",j);break;
					case  1:printf("H %d\n",j);break;
					case  2:printf("C %d\n",j);break;
					case  3:printf("D %d\n",j);break;
					default:printf("Error logic is incorrect\n");
							return -1;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 1756
import itertools
n,m,x=map(int,input().split())
l=[[0]]*n
ln=[0]*m
kan=0
for i in range(n):
  l[i]=list(map(int,input().split()))
  for j in range(m+1):
    if j==0:
      kan+=l[i][j]
    else:
      ln[j-1]+=l[i][j]
if sorted(ln)[0]<x:
  print(-1)
else:
  mkan=-1
  for i in range(n+1):
    itr=itertools.combinations(range(n),i)
    for comb in itr:
      kan=0
      ln=[0]*m
      for j in comb:
        kan+=l[int(j)][0]
        for ii in range(m):
          ln[ii]+=l[int(j)][ii+1]
      if sorted(ln)[0]>=x:
        if mkan==-1 or mkan>kan:
          mkan=kan
  print(mkan)


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

int main(){
 int N,K; cin >> N >> K; int cnt = 0;
  for(int i = 0; i < N; i++){ 
    int a; cin >> a; if( a >= K){ cnt++;}}
  
  cout << cnt << endl; return 0;}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  while(h!=0&&w!=0){
    int i,j;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if(i==0||i==h-1||j==0||j==w-1)
	  cout << "#";
	else cout << ".";
      }
      cout << endl;
    }
    cout << endl;
    cin >> h >> w;
  }
  return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
#define LL long long
#define ULL unsigned long long

int a[400][400];
int cnt[400];
bool ban[400];
int con[400];

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            scanf("%d",&a[i][j]);
    int ans=n;
    for(int i=1;i<=m;i++){
            memset(cnt,0,sizeof(cnt));
            for(int j=1;j<=n;j++){
                for(int k=1;k<=m;k++){
                    if(!ban[a[j][k]]){
                        cnt[a[j][k]]++;
                        break;
                    }
                }
            }
            int mx=0,p=0;
            for(int j=1;j<=m;j++)
                if(cnt[j]>mx)
                    mx=cnt[j],p=j;
            ban[p]=true;
            ans=min(ans,mx);
    }
    printf("%d\n",ans);
    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int n, k;
const int N = 1001;
int a[N];

struct fastio {
  fastio() {
    ios::sync_with_stdio(false);
    cout << setprecision(10) << fixed;
    cin.tie(0);
  }
};
fastio _fast_io;

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a, a + n);
  int sum = 0;
  for (int i = 0; i < k; ++i) {
    sum += a[i];
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <map>

using namespace std;

int main()
{
    int n; cin >> n;
    map<int, int> a;
    for (int i = 0; i < n; ++i) { 
        int tmp;
        cin >> tmp;
        a.insert(make_pair(tmp, i+1));
    }
    for (std::size_t j = 1; j < (size_t)(n + 1); ++j) {
        cout << a[j] << " ";
    }
    return 0;
}




Measured memory_bytes: 5504
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <math.h> 

using namespace std;



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

	string s, ans;
	cin >> s;
	int n = s.length(), i, j, k, x;
	vector<int> ad(n + 1, -10000000), ap(n + 1, -10000000), lastd(n + 1), lastp(n + 1);
	ad[0] = 0; 
	for (i = 0; i < n; i++) {
		if ((s[i] == 'D') || (s[i] == '?')) {
			if (ad[i] + 1 > ad[i + 1]) {
				ad[i + 1] = max(ad[i + 1], ad[i] + 1);
				lastd[i + 1] = 0;
			}
			if (ap[i] + 2 > ad[i + 1]) {
				ad[i + 1] = max(ad[i + 1], ap[i] + 2);
				lastd[i + 1] = 1;
			}
		}
		if ((s[i] == 'P') || (s[i] == '?')) {
			if (ad[i] > ap[i + 1]) {
				ap[i + 1] = max(ap[i + 1], ad[i]);
				lastp[i + 1] = 0;
			}
			if (ap[i] > ap[i + 1]) {
				ap[i + 1] = max(ap[i + 1], ap[i]);
				lastp[i + 1] = 1;
			}
		}
	}

	ans = s;
	if (ad[n] > ap[n]) x = 0;
	else x = 1;

	for (i = n - 1; i >= 0; i--) {
		if (x == 0) {
			ans[i] = 'D';
			x = lastd[i + 1];
		}
		else {
			ans[i] = 'P';
			x = lastp[i + 1];
		}
	}

	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 6780
#include <cstdio>
#include <cstdlib>
#include <cstddef>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <iostream>
#include <iomanip>

#define ASDF (1000000007)
#define MODADD(A, B) (A = (A + B) % ASDF)

long modpow(long src, long pow, long mod)
{
    long res = 1;
    while (0 < pow) {
        if (pow % 2 == 1) {
            res = (res * src) % mod;
            pow--;
        }
        src = (src * src) % mod;
        pow /= 2;
    }
    return res;
}

long modinv(long src, long mod)
{
    return modpow(src, mod - 2, mod);
}

long getgcd(long a, long b) {
    while (0 < a && 0 < b) {
        if (a < b)
            b = b % a;
        else
            a = a % b;
    }
    return std::max(a, b);
}

int main(void)
{
    long n;
    long c, d;
    long tot = 0;
    int i, j;
    std::cin >> n;
    long cnt[101][64];
    for (i = 0; i < 64; i++) {
        if (i == 9 || i == 33 || i == 6) {
            cnt[3][i] = 0;
        }
        else {
            cnt[3][i] = 1;
        }
    }
    for (j = 4; j <= n; j++) {
        for (i = 0; i < 64; i++) {
            cnt[j][i] = 0;
        }
        for (i = 0; i < 64; i++) {
            int upper = i / 16;
            int lower = i % 16;
            long prev = cnt[j - 1][i];
            if (i == 6) {
                /* nothing */
            }
            else if (i == 10 || i == 11 || i == 14) {
                MODADD(cnt[j][4 * i], prev);
                MODADD(cnt[j][4 * i + 2], prev);
                MODADD(cnt[j][4 * i + 3], prev);
            }
            else if (lower == 2 || lower == 8) {
                MODADD(cnt[j][4 * lower], prev);
                MODADD(cnt[j][4 * lower + 2], prev);
                MODADD(cnt[j][4 * lower + 3], prev);
            }
            else if (lower == 1) {
                MODADD(cnt[j][4 * lower], prev);
                MODADD(cnt[j][4 * lower + 1], prev);
                MODADD(cnt[j][4 * lower + 3], prev);
            }
            else {
                MODADD(cnt[j][4 * lower], prev);
                MODADD(cnt[j][4 * lower + 1], prev);
                MODADD(cnt[j][4 * lower + 2], prev);
                MODADD(cnt[j][4 * lower + 3], prev);
            }
        }
    }
    long res = 0;
    for (i = 0; i < 64; i++) {
        MODADD(res, cnt[n][i]);
    }
    std::cout << res << std::endl;
    //		std::cout << std::fixed << std::setprecision(8) << d * (1.0 + a / (1.0 * b)) << std::endl;
    return 0;
}


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

using namespace std;

#define pb push_back
#define NL endl
#define pi 2.0*acos(0.0)
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;

ll dp[3] = {0, 0, 0}, input[3];

int main() {
    ll n, a, b, c, maxm;
    cin >> n;
    cin >> dp[0] >> dp[1] >> dp[2];
    for (ll i = 0; i < n - 1; i++) {
        for (ll a = 0; a < 3; a++) cin >> input[a];
        for (ll k = 0; k < 3; k++) {
            maxm = -1;
            for (ll l = 0; l < 3; l++) {
                if (k != l) {
                    maxm = max(maxm, dp[l] + input[k]);
                }
            }
            input[k] = maxm;
        }
        for (ll b = 0; b < 3; b++) dp[b] = input[b];
    }
    cout << max(max(dp[0], dp[1]), dp[2]) << '\n';
}


Measured memory_bytes: 3608
import java.util.*;
import java.lang.*;
import java.io.*;
 
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
 
		int n = in.nextInt();
		int[][] a = new int[n][2];
		for(int i = 0; i < n; i++)
		{
			a[i] = in.ar(2);
		}
 
		Arrays.sort(a, (int[] x, int[] y) -> x[1] - y[1]);
		int cur = 0;
 
		for(int i = 0; i < n; i++)
		{
			cur += a[i][0];
			if(cur > a[i][1])
			{
				out.println("No");
				out.close();
				return;
			}
		}
 
		out.println("Yes");
		out.close();
	}
 
	static class InputReader
	{
		BufferedReader reader;
		StringTokenizer tokenizer;
 
		public InputReader(InputStream stream)
		{
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}
 
		public String next()
		{
			while(tokenizer == null || !tokenizer.hasMoreTokens())
			{
				try
				{
					tokenizer = new StringTokenizer(reader.readLine());
				}
				catch(IOException e)
				{
					throw new RuntimeException(e);
				}
			}
 
			return tokenizer.nextToken();
		}
 
		public int nextInt()
		{
			return Integer.parseInt(next());
		}
 
		public long nextLong()
		{
			return Long.parseLong(next());
		}
 
		public int[] ar(int n)
		{
			int[] a = new int[n];
			for(int i = 0; i < n; i++)
				a[i] = nextInt();
 
			return a;
		}
	}
}

Measured memory_bytes: 60832
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = (a * b);
		if (c % 2 == 0) {
			System.out.println("Even");
		}else {
			System.out.println("Odd");
		}
	}
}

Measured memory_bytes: 23252
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String s = input.next();
        String t = input.next();
        if (s.equals(t.substring(0,s.length()))){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35704
#include <stdio.h>
typedef long long ll;
using namespace std;

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

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

ll abs(ll a) {
  return a > 0 ? a : -a;
}

int main(void) {
  ll i, j, k, n, ans = 1e15;
  scanf("%lld%lld", &n, &k);
  ll x[n];
  for(i = 0; i < n; ++i) scanf("%lld", &x[i]);
  for(i = k - 1; i < n; ++i) {
    if(x[i] * x[i - k + 1] < 0) {
      if(ans > min(-x[i - k + 1] * 2 + x[i], x[i] * 2 - x[i - k + 1])) ans = min(-x[i - k + 1] * 2 + x[i], x[i] * 2 - x[i - k + 1]);
   } else if(ans > max(abs(x[i]), abs(x[i - k + 1]))) ans = max(abs(x[i]), abs(x[i - k + 1]));
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 896
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
    #define lb lower_bound 
    #define ub upper_bound
    #define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define vi vector<int> 
	#define vvi vector<vi>
    #define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)	
    #define all(c) (c).begin(),(c).end()
    #define sz(x)       (int)x.size() 
	#define PI 3.14159265358979323846
    
	 const int N =1e4;
    
     int mod= 1e9+7,INF=1e17;
     
     int dx[4]={0,0,+1,-1};
     int dy[4]={+1,-1,0,0};
    
     struct edge{
		   int a,b,c;
		 };
		 
     vector<edge> v(N);
     vi v1[N],v2[N];
     int ok[N],r1[N],r2[N];
   
  void dfs1(int u){
	 if(r1[u]) return;
	 
	 r1[u]=1;
	 for(auto to: v1[u]){
		 dfs1(to);
	 } 	   
  }
  
  
   void dfs2(int u){
	 if(r2[u]) return;
	 
	 r2[u]=1;
	 for(auto to: v2[u]){
		 dfs2(to);
	 } 	   
  }
  		 
     void solve(){
          
         int n,m,p,f=0;
         cin>>n>>m>>p;
         
         
         rep(i,0,m){
			  int x,y,z;
			  cin>>x>>y>>z;
			  --x;--y;
			  z-=p;
			  z= -z;
			  v[i].a=x;
			  v[i].b=y;
			  v[i].c=z;
			  
			  v1[x].pb(y);
			  v2[y].pb(x);	    
			    
			}
			
			 dfs1(0);
			 dfs2(n-1);
	
	   rep(i,0,n){
	     if(r1[i] && r2[i]){
	       ok[i]=1;
	       //cout<<i<<" ";
	     }
	   }
	   //cout<<endl;
	  
	   bool st=true;
	   vi d(n,INF);
	   d[0]=0;
	   int cnt=0;
	   
	   while(st){
		   st=false;
		   
		   rep(i,0,m){
			   
			  if(!ok[v[i].a]) continue;
			  if(!ok[v[i].b]) continue;
			   
			  if(d[v[i].b] > d[v[i].a]+v[i].c){
				  d[v[i].b] = d[v[i].a]+v[i].c;
				  st=true;			     
			  }
		  }
		  cnt++;	  
		 if(cnt>n){
			  cout<<-1;
			  return;
		 }
	   }
	   //cout<<d[n-1]<<endl;
	   
	   int ans=-d[n-1];
	   ans=max((int)0,ans);
	   cout<<ans<<endl;   	

     }

      int32_t main() {
	    cool;
	    int t=1;
        //cin>>t;
	    while(t--)
	       solve();
	       
	       
	       return 0;	   
	   }


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

int main(){
  int N;
  cin >> N;
  vector<int> A(100009);
  A[0]=0;
  for(int i=1;i<=N;i++)cin >> A[i];
  A[N+1]=0;
  int ans=0;
  for(int i=0;i<=N;i++){ans+=abs(A[i]-A[i+1]);}
  for(int i=1;i<=N;i++){
    int q=ans;
    q=q-abs(A[i-1]-A[i])-abs(A[i]-A[i+1])+abs(A[i-1]-A[i+1]);
    cout << q << endl;
  }
}

Measured memory_bytes: 1664
n = int(input())
monster = list(map(int, input().split()))
hero = list(map(int, input().split()))

ans = 0
for i in range(n):
  if hero[i] < monster[i]:
    ans += hero[i]
  else:
    ans += monster[i]
    hero[i] -= monster[i]
    if hero[i] < monster[i+1]:
      monster[i+1] -= hero[i]
      ans += hero[i]
    else:
      ans += monster[i+1]   
      monster[i+1] = 0
print(ans)

Measured memory_bytes: 82020
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

map<int, int> prime_factor(int n){
	map<int, int> res;
	for(int i = 2; i * i <= n; i++){
		while(n % i == 0){
			++res[i];
			n /= i;
		}
	}
	if(n != 1) res[n]++;
	return res;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n, p;
	cin >> n >> p;
	map<int, int> mp = prime_factor(p);
	int ans = 1;
	for(auto i : mp){
		if(i.second >= n){
			rep(j, 0, i.second / n){
				ans *= i.first;
			}
		}
	}
	cout << ans << endl;
}

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

bool isA(const string& str, int indx) {
	if(str[indx++] != '>')
		return false;
	if(str[indx++] != '\'')
		return false;

	int count0 = 0;
	for(; indx < str.size(); indx++) {
		if(str[indx] == '=')
			count0++;
		else
			break;
	}
	if(indx >= str.size())
		return false;
	if(str[indx++] != '#' || count0 == 0)
		return false;
	int count1 = 0;
	for(; indx < str.size(); indx++) {
		if(str[indx] == '=')
			count1++;
		else
			break;
	}

	if(count0 == count1 && indx + 1 == str.size() && str[indx] == '~')
		return true;
	return false;
}

bool isB(const string & str, int indx) {
	if(str[indx++] != '>')
		return false;
	if(str[indx++] != '^')
		return false;

	int count = 0;
	for(; indx + 1 < str.size(); indx += 2) {
		if(string(str.begin() + indx, str.begin() + indx + 2) == "Q=")
			count++;
		else
			break;
	}
	if(count > 0 && string(str.begin() + indx, str.begin() + indx + 2) == "~~" && indx + 2 == str.size())
		return true;
	return false;
}

int main() {
	string str;
	int n;

	cin >> n;
	for(int t = 0; t < n; t++) {
		int type = 0;
		cin >> str;
		for(int i = 0; i < str.size(); i++) {
			if(str[i] == '>') {
				if(isA(str, i)) {
					type = 1;
					break;
				}
				else if(isB(str, i)) {
					type = 2;
					break;
				}
			}
		}

		switch(type) {
			case 0:
				cout << "NA" << endl;
				break;
			case 1:
				cout << "A" << endl;
				break;
			case 2:
				cout << "B" << endl;
				break;
		}
	}
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

const int MX = 200100;
ll A[MX], B[MX];

void add(ll *bit, int i, ll x){
	for(i++; i < MX; i += i & -i) bit[i] += x;
}
ll sum(ll *bit, int i){
	ll res = 0;
	for(i++; i; i -= i & -i) res += bit[i];
	return res;
}
void add(ll *a, int l, int r, int x){
	add(a, l, x);
	add(a, r, -x);
}
int findzero(){
	int lo = 0, hi = 1 << 32 - __builtin_clz(MX), mid;
	ll k = 0;
	while(lo + 1 < hi){
		mid = (lo + hi) / 2;
		if(mid > MX || A[mid] >= k) hi = mid;
		else k -= A[lo = mid];
	}
	return hi - 1;
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int q; cin >> q;
	
	vector<tuple<int,int,int>> in;
	vi as;
	
	rep(i, q){
		int t, a = 0, b = 0; cin >> t;
		if(t == 1){
			cin >> a >> b;
			as.pb(a);
		}
		in.emplace_back(t, a, b);
	}
	sort(all(as)); as.erase(unique(all(as)), as.end());
	for(auto it : in){
		int t, a, b; tie(t, a, b) = it;
		if(t == 2){
			int p = findzero();
			cout << as[p] << " " << sum(A, p) * as[p] + sum(B, p) << endl;
			continue;
		}
		a = lower_bound(all(as), a) - as.begin();
		
		add(A, 0, a, -1);
		add(B, 0, a, as[a]);
		
		add(A, a, MX, 1);
		add(B, a, MX, -as[a]);
		
		add(B, 0, MX, b);
	}
	
	return 0;
}

Measured memory_bytes: 7472
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>


#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int n;
int node[1000000];

void init(int _n){
  n = 1;
  while(n < _n) n *= 2;
  for(int i = 0; i < n * 2 - 1; i++) node[i] = 0;
}

void add(int idx, int x){
  idx += (n - 1);
  node[idx] += x;
  while(idx > 0){
    idx = (idx - 1) / 2;
    node[idx] = node[idx * 2 + 1] + node[idx * 2 + 2];
  }
}

int getSum(int a, int b, int idx = 0, int left = 0, int right = -1){
  if(right < 0) right = n;
  if(right <= a || b <= left) return 0;
  if(a <= left && right <= b) return node[idx];
  
  int vl = getSum(a, b, idx * 2 + 1, left, (left + right) / 2);
  int vr = getSum(a, b, idx * 2 + 2, (left + right) / 2, right);
  //cerr << "cerr: " << vl << " " << vr << endl;
  return vl + vr;
}

signed main(){
  int N, Q, com, x, y;
  cin >> N >> Q;
  init(N);
  for(int i = 0; i < Q; i++){
    cin >> com >> x >> y;
    if(com) cout << getSum(x - 1, y) << endl;
    else add(x - 1, y);
  }
  return 0;
}


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

int main(){
    int x;
    rep(i,10000){
        cin >> x;
        if(x == 0) break;
        cout << "Case " << i+1 << ": " << x << endl;
    } 
}



Measured memory_bytes: 3100
#include<iostream>
#include<vector>
#include<map>
#include<queue>
#define INF 1000000000
using namespace std;
typedef pair<int,int> P;
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
int main(){
	int w,h;
	while(cin>>w>>h,h||w){
		cin.ignore();
		vector<string> s(h*2-1);
		for(int i=0;i<h*2-1;i++){
			getline(cin,s[i]);
			if(i%2==0)
				s[i]+=" ";
		}
		vector<vector<int> > d(h,vector<int>(w,INF));
		queue<P> q;
		q.push(P(0,0));
		d[0][0]=1;
		while(!q.empty()){
			int y=q.front().first,x=q.front().second;
			q.pop();
			for(int i=0;i<4;i++){
				int ny=y+dy[i],nx=x+dx[i];
				if(ny>=0&&nx>=0&&ny<h&&nx<w&&s[2*y+dy[i]][2*x+dx[i]]!='1'&&d[ny][nx]>d[y][x]+1){
					d[ny][nx]=d[y][x]+1;
					q.push(P(ny,nx));
				}
			}
		}
		if(d[h-1][w-1]==INF)
			d[h-1][w-1]=0;
		cout<<d[h-1][w-1]<<endl;
	}
	
	
	return 0;
}

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

int main(){
    string N;
    int c = 0, c1 = 0;
    bool sign = true;

    cin >> N;

    for(int lp=0; lp<N.length(); lp++){
        if(sign != N[lp]-'0') c++;
        if(sign == N[lp]-'0') c1++;
        sign = sign == true ? false : true;
    }
    
    int result = c < c1 ? c : c1;
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
#include <iterator> 
using namespace std;

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)

#define nl '\n'
#define ioi exit(0);


#define PI 3.14159265

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
//~ const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};
  
int main() 
{ 
	string s; cin>> s;
	if(s[0] == '7' || s[1]== '7'|| s[2] == '7')
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
} 




Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define MaxSize 100005
using namespace std;

int a[1000005],dp[1000005];

int main()
{
    int n, z=0, mi=1000000007;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]<=mi)
        {
            z++;
            mi=a[i];
        }
    }
    printf("%d\n",z);
	return 0;
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
#include <string>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#define int ll
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll > 
#define debug(x)   cerr<<#x<<": "<<x<<endl
// #define mod  1000000007
#define N 100005
// #define MAX 200005
#define mod1 1000000007
#define mod2 998244353
#define bitcnt __builtin_popcount
#define PI acos(-1)
//#define endl "\n"
// const int inf = (int)1e18 + 10;
const int mod = 1e9 + 7;

const int inf = 1e15;
const int MAX = 1000000;
map < string , int > m;
signed main(){
  fast;
 
  int n;
  string str;
  cin >> n;
  for(int i = 0 ; i < n ; i++){
        cin >> str;
        sort(str.begin() , str.end());
        m[str] += 1;
  }

  int ans = 0;
  map < string , int > :: iterator it = m.begin();
  for(it = m.begin() ; it!= m.end() ; ++it){
        int x = it->ss;
        ans += x*(x-1)/2;
  }

  cout << ans << endl;











}


Measured memory_bytes: 11264
// practice with Dukkha, coached by rainboy
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 300;

int aa[N][N];

int main() {
	int n, m, l; cin >> n >> m >> l;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			aa[i][j] = l + 1;
	while (m--) {
		int i, j, c; cin >> i >> j >> c, i--, j--;
		if (c <= l)
			aa[i][j] = aa[j][i] = c;
	}
	for (int k = 0; k < n; k++)
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				aa[i][j] = min(aa[i][j], aa[i][k] + aa[k][j]);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			aa[i][j] = aa[i][j] <= l ? 1 : n;
	for (int k = 0; k < n; k++)
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				aa[i][j] = min(aa[i][j], aa[i][k] + aa[k][j]);
	int q; cin >> q;
	while (q--) {
		int i, j; cin >> i >> j, i--, j--;
		int k = aa[i][j];
		if (k == n)
			k = 0;
		cout << k - 1 << '\n';
	}
	return 0;
}


Measured memory_bytes: 3948
#include <stdio.h>

int main()
{
    int arr[3], i;
    for(i=0; i<=2; i++){
        scanf("%d", &arr[i]);
    }
    if(arr[0]==arr[1])
        printf("%d", arr[2]);
    else if(arr[1]==arr[2])
        printf("%d", arr[0]);
    else
        printf("%d", arr[1]);
    return 0;
}


Measured memory_bytes: 128
def Schedule(schedule):
    """
    :return: 複数の区間が与えられた時の重複の無い区間の選び方の最大数
    """
    schedule = sorted(schedule, key=lambda x: x[1])
    N = len(schedule)
    res = 0
    end = -float("inf")
    tmp = 0
    for i in range(N):
        if end < schedule[i][0] or tmp == C-1:  # 重複がダメならば等号を消す
            end = schedule[i][1]  # 終点でソートされているので、自動的に可能な中で最速の終点が選ばれている
            res += 1
            tmp = 0
        else:
            tmp += 1
    return res

################################################################################

import sys
input = sys.stdin.readline

N, C, K = map(int, input().split())
schedule = []
for i in range(N):
    start = int(input())
    schedule.append((start, start + K))               # schedule = (始点、終点)

print(Schedule(schedule))

Measured memory_bytes: 82572
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

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

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}"<<endl;
  return o;
}

//逆元　a/b の modをとるとき -> a*modinv(b)%mod
long long modinv(long long a, long long m = 1e9+7) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m; 
  if (u < 0) u += m;
  return u;
}
ll const mod = 1e9+7;

// combination
const int MAX = 510000;
const ll MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// べき乗
ll modpow(ll x, ll n) {
    x = x%MOD;
    if(n==0) return 1;  //再帰の終了条件

    else if(n%2==1) {
        return (x*modpow(x, n-1))%MOD;  //nが奇数ならnを1ずらす
    }
    else return modpow((x*x)%MOD, n/2)%MOD;  //nが偶数ならnが半分になる
}

int main() {
  int H,W;
  cin >> H >> W;
  int ch,cw,dh,dw;
  cin >> ch >> cw >> dh >> dw;
  ch--; cw--; dh--; dw--;
  vector<vector<char>> g(H,vector<char>(W));
  rep(i,H) rep(j,W) cin >> g[i][j];
  vector<vector<int>> ans(H,vector<int>(W,10000000));
  ans[ch][cw] = 0;
  priority_queue<vector<int>,vector<vector<int>>,greater<>> q;
  q.push({0,ch,cw});
  vector<int> x={1,0,0,-1},y={0,1,-1,0};
  vector<int> xx={2,1,0,-1,-2,2,1,-1,-2,2,-2,2,1,-1,-2,2,1,0,-1,-2},
    yy = {2,2,2,2,2,1,1,1,1,0,0,-1,-1,-1,-1,-2,-2,-2,-2,-2};

  while(!q.empty()) {
    auto t = q.top();
    q.pop();
    
    if (t[1]==dh&&t[2]==dw) {
      cout << t[0] << endl;
      return 0;
    }
    // ans[t[1]][t[2]] = t[0];
    
    rep(i,4) {
      if (t[1]+x[i]>=0 && t[1]+x[i]<H && t[2]+y[i]>=0 && t[2]+y[i]<W && g[t[1]+x[i]][t[2]+y[i]]=='.' && ans[t[1]+x[i]][t[2]+y[i]]>t[0]) {
        ans[t[1]+x[i]][t[2]+y[i]] = t[0];
        q.push({t[0],t[1]+x[i],t[2]+y[i]});
      }
    }
    
    rep(i,20) {
      if (t[1]+xx[i]>=0 && t[1]+xx[i]<H && t[2]+yy[i]>=0 && t[2]+yy[i]<W && g[t[1]+xx[i]][t[2]+yy[i]]=='.' && ans[t[1]+xx[i]][t[2]+yy[i]]>t[0]+1) {
        // ans[t[1]+x[i]][t[2]+y[i]] = t[0];
        ans[t[1]+xx[i]][t[2]+yy[i]] = t[0]+1;
        q.push({t[0]+1,t[1]+xx[i],t[2]+yy[i]});
      }
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 8700
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    for i in range(N-K):
        if A[i] < A[i+K]:
            print('Yes')
        else:
            print('No')

if __name__ == "__main__":
    main()


Measured memory_bytes: 33392
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define rep(i,a,b) for(int i=a;i<b;i++)
#define  rr read()
#define ll long long
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define CloseIo   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int read()
{
    char ch = getchar();
	int x = 0, f = 1;
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
struct node
{
	 int v;
	 ll w;
	 node(ll sw,int sv)
	 {
	 	 w=sw;
	 	 v=sv;
	 }
};
const int N=2e5+5;
vector<node>v[2*N+1];
int vis[N]={0};
void dfs(int u,int p,ll d)
{
	 
	 for(int i=0;i<v[u].size();i++)
	 {
	 	 int vv=v[u][i].v;
	 	 if(vv==p)continue;
	 	 if((d+v[u][i].w)%2)vis[vv]=1;
	 	
	 	 	 dfs(vv,u,d+v[u][i].w);
		  
	 }
}
int main()
{
  int n=rr;

  memset(vis,0,sizeof(vis));
  rep(i,0,n-1)
  {
  	 int x=rr,y=rr;
	   ll w;
  	 cin>>w;
  	 v[x].push_back(node(w,y));
  	 v[y].push_back(node(w,x));
  	 
  }
  dfs(1,0,0);
  for(int i=1;i<=n;i++)
  printf("%d\n",vis[i]);
}




Measured memory_bytes: 18048
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
using namespace std;

int main(){
  int h,w,H,W;
  cin >>H>>W>>h>>w;

  cout<<(H-h)*(W-w)<<endl;


}


Measured memory_bytes: 256
from collections import deque

n = int(input())
a = list(map(int,input().split()))
b = deque()
for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.appendleft(a[i])
if n % 2 == 1:
    b.reverse()
print(' '.join(map(str, b)))


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

int main(int argc, char const *argv[])
{
	//freopen("in.txt", "r", stdin);
	long long  a[3], sum = 0;
	for(int i = 0; i < 3; i++) 
		cin >> a[i];
	int k;
	scanf("%d", &k);
	sort(a, a+3);
	sum = a[0] + a[1];
	for(int i = 0; i < k; i++) {
		a[2] *= 2;
	}
	sum += a[2];
	cout << sum << endl;
	return 0;
}

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

using namespace std;

long long f(long long b, long long n){
	return (n < b) ? n : f(b, n / b) + n % b;
}

int main(){
	long long n, s;
	cin >> n >> s;

	if (n == s){
		cout << n + 1 << endl;
		return 0;
	}

	for (long long i = 2; i <= sqrt(n); i++){
		if (f(i, n) == s){
			cout << i << endl;
			return 0;
		}
	}

	if (n < s){
		cout << -1 << endl;
		return 0;
	}

	for (long long i = sqrt(n); i > 0 ; i--){
		if ((n-s) % i == 0 && f((n - s)/i + 1, n) == s){
			cout << (n - s)/i + 1 << endl;
			return 0;
		}
	}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/
 
const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

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

    int n, m; cin >> n >> m;
    vector<int> s(n), t(m);
    for(int i=0; i<n; ++i) cin >> s[i];
    for(int i=0; i<m; ++i) cin >> t[i];

    vector<vector<ll>> dp(n+5, vector<ll>(m+5, 0)), sum(n+5, vector<ll>(m+5, 0));

    for(int i=1; i<=n; ++i){
        for(int j=1; j<=m; ++j){
            if(s[i-1] == t[j-1]) dp[i][j] = sum[i-1][j-1]+1;
            else dp[i][j] = 0;

            sum[i][j] = sum[i][j-1] + sum[i-1][j] - sum[i-1][j-1] + dp[i][j];
            chmod(sum[i][j]);
        }
    }

    cout << (sum[n][m]+1)%mod << endl;
    
    return 0;
}



Measured memory_bytes: 63232
import heapq
N, M = [int(_) for _ in input().split()]
H = [-int(_) for _ in input().split()]
heapq.heapify(H)
ans = 0
for _ in range(M):
    a = heapq.heappop(H)
    heapq.heappush(H, a / 2)
print(-sum(int(a) for a in H))



Measured memory_bytes: 14180
#include<stdio.h>
#include<string.h>
using namespace std;

#define LIM 19430400
#define LEN 13

char H[LIM][LEN];


int toInt(char str) {
  if ( str == 'A' ) return 1;
  else if ( str == 'C' ) return 2;
  else if ( str == 'G' ) return 3;
  else if ( str == 'T' ) return 4;
  else return 0;
}

long long getKey(char str[]) {
  int i, m, p = 1, sum = 0;
  for ( i = 0; i < strlen(str); i++ ) {
    m = toInt(str[i]);
    sum += m * p;
    p *= 5;
  }
  return sum;
}

int h1(long long key) { return key % LIM; }
int h2(long long key) { return 1 + (key % (LIM - 1)); }
long long hashValue(long long key, int i) { return h1(key) + i * h2(key); }

int insert(char str[]) {
  long long key = getKey(str);
  for ( int i = 0; i < LIM; i++ ) {
    long long h = hashValue(key, i);
    if (strcmp(H[h], str) == 0) return 1;
    else if (strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 1;
    }
  }
  return 0;
}
int find(char str[]) {
  long long key = getKey(str);
  for ( int i = 0; i < LIM; i++ ) {
    long long h = hashValue(key, i);
    if (strcmp(H[h], str) == 0) return 1;
    else if (strlen(H[h]) == 0) return 0;
  }
  return 0;
}

int main() {
  int n;
  char com[6], str[12];
  scanf("%d", &n);

  while( scanf("%s %s", com, str) != EOF ) {
    if ( com[0] == 'i' ) {
      insert(str);
    } else {
      if (find(str)) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }

  return 0;
}



Measured memory_bytes: 48400
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define M 998244353
#define fi first
#define se second
#define endl '\n'
#define INF 1e18
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main()
{
     ll n;
     cin>>n;
     set<string>s;

     ll i;
     for(i=0;i<n;i++)
     {
         string ss;
         cin>>ss;
         s.insert(ss);
     }
     ll ans = s.size();
     cout<<ans<<endl;
}


Measured memory_bytes: 19256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  string s;cin>>s;ll A=0,B=0,C=0,i;
  REP(i,s.size()){
    if(s[i]=='a')A++;
    if(s[i]=='b')B++;
    if(s[i]=='c')C++;
  }
  if(abs(A-B)<=1&&abs(B-C)<=1&&abs(C-A)<=1)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 512
def find_zeros(a):
    res = []
    for i in range(len(a)):
        if a[i] == 0:
            res.append(i)
    return res


def solve():
    N = input()
    h = [int(n) for n in input().split()]

    cnt = 0
    while sum(h) != 0:
        idx_zeros = find_zeros(h)
        idx_zeros = [-1] + idx_zeros + [len(h)]
        for l, r in zip(idx_zeros[:-1], idx_zeros[1:]):
            for i in range(l+1,r):
                h[i] -= 1
            if l+1<r:
                cnt += 1
    return cnt 


def main():
    ans = solve()
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author TM
 */


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <numeric>
#include <iterator>

#define SIZE 100005
#define MOD 1000000007
#define INF 100000000

using namespace std;

class DTriangles {
public:
    void solve(std::istream &cin, std::ostream &cout) {
        int n;
        cin >> n;
        vector<int> vec(n);
        long long int ans = 0;
        for (int i = 0; i < n; ++i) cin >> vec[i];
        sort(vec.begin(), vec.end());
        for (int j = 0; j < n; ++j) {
            for (int k = j + 1; k < n; ++k) {
                auto iter = lower_bound(vec.begin(), vec.end(), vec[j] + vec[k]);
                int index = max(0, int(distance(vec.begin(), iter) - k - 1));
                ans += index;
            }
        }
        cout << ans << endl;
    }
};


int main() {
    DTriangles solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#include <set>
#include <numeric>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;

void solve(){

}
int main(){
    int N,A,B,C;
    cin >> N >> A >> B >> C;
    vector<int> L(N);
    for (int i = 0; i < N; ++i) {
        cin >> L[i];
    }

    int ans = INT_MAX;
    int sz = pow(4, N);
    for (int i = 0; i < sz; ++i) {
        vector<int> a,b,c;
        int t = i;
        for (int k = 0; k < N; ++k) {
            int idx = t % 4;
            t /= 4;
            if (idx == 0) { a.push_back(L[k]); }
            if (idx == 1) { b.push_back(L[k]); }
            if (idx == 2) { c.push_back(L[k]); }
        }

        int tmp = 0;
        if (a.empty()) {
            continue;
        }
        tmp += (10 * (a.size() - 1));
        if (b.empty()) {
            continue;
        }
        tmp += (10 * (b.size() - 1));
        if (c.empty()) {
            continue;
        }
        tmp += (10 * (c.size() - 1));

        int suma = accumulate(all(a),0);
        int sumb = accumulate(all(b),0);
        int sumc = accumulate(all(c),0);

        /*
        while (!a.empty()) {
            suma += a.front();
            a.pop();
        }
        int sumb = 0;
        while (!b.empty()) {
            sumb += b.front();
            b.pop();
        }
        int sumc = 0;
        while (!c.empty()) {
            sumc += c.front();
            c.pop();
        }
        */

        tmp += (abs(suma - A) + abs(sumb - B) + abs(sumc - C));
        ans = min(ans, tmp);
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int count=0;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]!=t[i])
            count++;
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 3896
#include <stdio.h>
int bs(int);
int n, S[100000];
int main(){
  int q,T[50000],i,x=0;
  
    scanf("%d",&n);
  for(i = 0; i < n; i++)
    scanf("%d",&S[i]);
  
  scanf("%d",&q);
  for(i = 0; i < q; i++)
    scanf("%d",&T[i]);

  for(i = 0; i < q; i++){
    if(bs(T[i]) == T[i]) x++;
  }
  
  printf("%d\n",x);
  
  return 0;
}

int bs(int key){
  int l,r,m;
  l = 0;
  r = n;
   while(l<r){
      m = (l+r)/2;
      if(key == S[m])
	return key;
      else if(key < S[m]) r = m;
      else l = m+1;
   }
   return 0;
}



Measured memory_bytes: 2268
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,dp[105][100005],s[100005],a[105],mod=1000000007;
int main()
{
    cin>>n>>m;
    for(ll i=1;i<=n;i++) cin>>a[i];
    for(ll i=0;i<=n;i++) dp[i][0]=1;
    for(ll i=1;i<=n;i++){
        s[0]=dp[i][0];
        for(ll j=1;j<=m+1;j++) s[j]=s[j-1]+dp[i-1][j];
        for(ll j=1;j<=m;j++) dp[i][j]=(dp[i][j]+s[j]-s[j-min(j,a[i])-1])%mod;
    }
    cout<<dp[n][m];
    return 0;
}

Measured memory_bytes: 79360