akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}

	public Main() {
		new AOJ0571().doIt();
	}


	class AOJ0571{
		void doIt(){
			char[] input = in.next().toCharArray();
			int result = 0;
			int n = input.length;
			int cnt = 0;
			ArrayList<Data> list = new ArrayList<Data>();
			for(int i=1;i<n;i++){
				if(input[i]==input[i-1]){
					cnt++;
				}else{
					list.add(new Data(input[i-1],cnt+1));
					cnt = 0;
				}
			}
			if(cnt==0){
				list.add(new Data(input[n-1],1));
			}else list.add(new Data(input[n-1], cnt+1)); 
//			System.out.println(list);
			for(int i=0;i<list.size()-2;i++){
				if(!(list.get(i).r=='J'&&list.get(i+1).r=='O'&&list.get(i+2).r=='I'))continue;
				if(list.get(i+1).num>list.get(i).num)continue;
				if(list.get(i+1).num>list.get(i+2).num)continue;
				result = Math.max(result, list.get(i+1).num);
			}
			System.out.println(result);
		}
		class Data{
			char r;
			int num;
			public Data(char r,int num) {
				this.r = r;
				this.num = num;
			}
			public String toString(){
				return r+" "+num;
			}
		}
	}

}

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

vector<int> dy = {-1, 1, 0,  0};
vector<int> dx = { 0, 0, 1, -1};

int h, w;
queue<pair<int, int>> todo; // y, x

// 次に動こうとしている点(nx, ny)に通路があるかの判定。訪れたかどうかは不問
bool movable(int ny, int nx, vector<string> & maze) {
    if (ny < 0 || ny >= h || nx < 0 || nx >= w)
        return false;

    if (maze.at(ny).at(nx) == '#')
        return false;

    return true;
}

int bfs(int sy, int sx, vector<string> & maze)
{
    /*
    -1: 見つけてない
    >= 0: 発見済み。(スタートからの距離)
    */
    vector<vector<int>> visited(h, vector<int>(w, -1));
    visited.at(sy).at(sx) = 0;
    todo.push(pair<int, int>(sy, sx));

    int maxDist = -1;
    while (!todo.empty())
    {
        int y = todo.front().first;
        int x = todo.front().second;
        todo.pop();

        rep(i, 4) {
            int ny = y + dy.at(i);
            int nx = x + dx.at(i);
            if (movable(ny, nx, maze) && visited.at(ny).at(nx) == -1) {
                visited.at(ny).at(nx) = visited.at(y).at(x) + 1;
                maxDist = max(maxDist, visited.at(ny).at(nx));
                todo.push(pair<int, int>(ny, nx));
            }
        }
    }
    return maxDist;
}

int main() {
    cin >> h >> w;
    vector<string> maze(h);
    rep(i, h) cin >> maze.at(i);

    int ans = -1;
    rep(i, h)
    {
        rep (k, w) {
            if (maze.at(i).at(k) == '#')
                continue;

            ans = max(bfs(i, k, maze), ans);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
n,y = map(int,input().split())
for i in range(0,n+1):
    for j in range(0,n-i+1):
        if i*10000 + j*5000 + (n-i-j)*1000 == y:
            print('{0} {1} {2}'.format(i,j,n-i-j))
            sys.exit()
 
print('{0} {1} {2}'.format(-1,-1,-1))

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

N = ii()
alpha = [chr(i) for i in range(97, 97+26)]
N_ = N
'''
alpha = [chr(i) for i in range(97, 97+26)]
if 0 <= N <= 25:
    print(alpha[i])
elif 26<= N <= 702:
'''
ans = ''
N -= 1
a = float('inf')
flag = False
'''
while True:
    N, a = N//26, N%26
    #print(N, a)
    #if flag == False:
    if ans == '' or ans[-1] != 'z' :
        ans += alpha[a-1]
    else:
        ans += alpha[a-2]
        flag = False
    if N == 0:
        break

'''
while True:
    N, a = N//26, N%26
    #print(N, a)
    #if not flag:
    #if not flag:
    ans += alpha[a]
    #else:
        #ans += alpha[a-1]
    flag = True
    N -= 1
    if N < 0:
        break
    #else:
        #ans += alpha[a-1]
        #flag = False
    #if a == 25:
        #flag = True


#l = [26]
#tmp = 26
#while True:
    #tmp *= 26
    #if tmp + l[-1] >= 1000000000000001:
        #break
    #l.append(tmp + l[-1])

#if N_ in l:
    #print(ans[1:][::-1])
#else:
print(ans[::-1])

Measured memory_bytes: 9872
import java.util.*;

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

        int n = sc.nextInt();
        int[] p = new int[n];
        int ans = 0;

        for(int i=0; i<n; i++){
            p[i] = sc.nextInt();
        }
        for(int i=0; i<n-2; i++){
            if(p[i]<p[i+1] && p[i+1]<p[i+2]){
                ans += 1;
            }
            else if(p[i]>p[i+1] && p[i+1]>p[i+2]){
                ans += 1;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 25300
N, M = map(int, input().split())
X = [int(x) for x in input().split()]
X.sort(reverse=True)
X_diff = []
for i in range(len(X)-1):
    X_diff.append(X[i] - X[i+1])
X_diff.sort()
if N < M:
    print(sum(X_diff[:M-N]))
else:
    print(0)

Measured memory_bytes: 13832
#pragma GCC optimize("Ofast")
  #pragma GCC target("avx,avx2,fma")
  #include <bits/stdc++.h>
  using namespace std;
  //---------------------------------//
  void __print(int x) {cerr << x;}
  void __print(long x) {cerr << x;}
  void __print(long long x) {cerr << x;}
  void __print(unsigned x) {cerr << x;}
  void __print(unsigned long x) {cerr << x;}
  void __print(unsigned long long x) {cerr << x;}
  void __print(float x) {cerr << x;}
  void __print(double x) {cerr << x;}
  void __print(long double x) {cerr << x;}
  void __print(char x) {cerr << '\'' << x << '\'';}
  void __print(const char *x) {cerr << '\"' << x << '\"';}
  void __print(const string &x) {cerr << '\"' << x << '\"';}
  void __print(bool x) {cerr << (x ? "true" : "false");}

  template<typename T, typename V>
  void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
  template<typename T>
  void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
  void _print() {cerr << "]\n";}
  template <typename T, typename... V>
  void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
  #ifndef ONLINE_JUDGE
  #define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
  #else
  #define deb(x...)
  #endif
 //------------------------------//

  typedef long long int ll;
  typedef pair<int,int> pi;
  typedef pair<ll,ll> pll;
  typedef vector<int> vi;
  typedef vector<ll> vll;
  typedef vector<pi> vpi;
  typedef vector<pll> vpll;

  #define  ff           first
  #define  ss           second
  #define  pb           push_back
  #define  IOS          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define  all(x)       (x).begin(), (x).end()
  #define  ps(x,y)      fixed<<setprecision(y)<<x
  #define  rep(i,a,b)   for(ll i=a ; i<b ; ++i)

  const ll MOD = 1e9 + 7;
  const ll INF = 1e18;
  const ll maxn = 1e6 + 4;


  void solve(){
     int n,m;
     cin >> n >> m;
     vector<vector<ll>> dis(n+1,vector<ll> (n+1,INT_MAX));
     vll a(m),b(m),c(m);
     for(int i=0;i<m;i++){
       cin >>a[i] >> b[i] >> c[i];
       dis[a[i]][b[i]]=c[i];
       dis[b[i]][a[i]]=c[i];
     }
     for(int i=1;i<=n;i++)dis[i][i]=0;
     for(int k=1;k<=n;k++){
       for(int i = 1;i<=n;i++){
         for(int j =1;j<=n;j++){
           if(dis[i][j] > dis[i][k] + dis[k][j]){
             dis[i][j] = dis[i][k] + dis[k][j];
           }
         }
       }
     }
     ll ans=0;
     for(int i=0;i<m;i++){
       bool ok = false;
       for(int j=1;j<=n;j++){
         for(int k=1;k<=n;k++){
           if(dis[j][k] == (dis[j][a[i]]+c[i] + dis[b[i]][k])){
             ok = true;
             break;
           }
         }
         if(ok)break;
       }
      if(!ok)ans++;
     }
     cout << ans;
  }

  int main(){
    IOS
    	solve();
    //cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }

// integer overflow

Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int n,m,q;
int val[55];
int a[55],b[55],c[55],d[55];
int res;
int all[55];
vector<pair<pii,int> > str[55];
int suf[55];
void dfs(int now,int mn,int ans){
    if(suf[now]+ans<res) return;
    if(now==n+1){
        res=max(res,ans);
        return;
    }
    for(int i=mn;i<=m;i++){
        val[now]=i;
        int nowans=ans;
        for(int j=0;j<(int)str[now].size();j++)
            if(val[now]-val[str[now][j].fi.fi]==str[now][j].fi.se)
                nowans+=str[now][j].se;
        dfs(now+1,i,nowans);
    }
}
int main(){
    scanf("%d %d %d",&n,&m,&q);
    for(int i=1;i<=q;i++)
        scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]),str[b[i]].pb(mp(mp(a[i],c[i]),d[i])),all[b[i]]+=d[i];
    for(int i=n;i>=1;i--) suf[i]=suf[i+1]+all[i];
    dfs(1,1,0);
    printf("%d\n",res);
    return 0;
}

Measured memory_bytes: 3836
import sys
N,Y = map(int,input().split())
for i10 in range(0,N+1):
  for i05 in range(0,N-i10+1):
    if N < i10 + i05:
      continue
    if Y == (10000 * i10 + 5000 * i05 + 1000 *(N-i10-i05)):
      print(i10,i05,N-i10-i05)
      sys.exit()
print(-1,-1,-1)

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

#define times(n, i)      uptil(0, n, i)
#define rtimes(n, i)     downto((n) - 1, 0, i)
#define upto(f, t, i)    for(auto i##0_to = (t), i = decltype(t)(f); i <= i##0_to; i++)
#define uptil(f, t, i)   for(auto i##0_to = (t), i = decltype(t)(f); i <  i##0_to; i++)
#define downto(f, t, i)  for(auto i##0_to = decltype(f)(t), i = (f); i >= i##0_to; i--)
#define downtil(f, t, i) for(auto i##0_to = decltype(f)(t), i = (f); i >  i##0_to; i--)
using LD = long double;
#define double LD
#define long long long
#define LL long
#define int long
template<class T> using vec = vector<T>;
using VB = vec<bool>;   using WB = vec<VB>;
using VC = vec<char>;   using WC = vec<VC>;
using VI = vec<int>;    using WI = vec<VI>;
using VD = vec<double>; using WD = vec<VD>;
using VS = vec<string>; using WS = vec<VS>;
using PI = pair<int, int>;  using VPI = vec<PI>; using WPI = vec<VPI>;
using MI = map<int, int>;   using VMI = vec<MI>;

#if defined(EBUG) && !defined(ONLINE_JUDGE)
    #define debug true
    #define _GLIBCXX_DEBUG
    #define _LIBCPP_DEBUG 2
    #define _LIBCPP_DEBUG2 2
    #define ln << endl
    #define dd(x) cerr << #x << " = " << (x) << ", "
    #define ddd(x) cerr << #x << " = " << (x) ln
#else
    #define debug false
    #define ln << '\n'
    #define dd(x) cerr
    #define ddd(x) cerr
#endif
#define tb << '\t'
#define sp << ' '
#define db dd
#define dbg ddd

template<class T>          inline istream& operator>>(istream& s, vec<T>& v) { for(auto&& p : v) s >> p; return s; }
template<class T, class S> inline ostream& operator<<(ostream&, const pair<T, S>&);
template<class T>          inline ostream& operator<<(ostream&, const vec<T>&);
template<class T, class S> inline ostream& operator<<(ostream&, const map<T, S>&);
#define DEFINE_ITER_OUTPUT(s, x, sep) { int i = 0; for(const auto& x##0_elem : x) { if(i++) s << sep; s << x##0_elem; } return s; }
template<class T, class S> inline ostream& operator<<(ostream& s, const pair<T, S>& p) { return s << "(" << p.first << "," << p.second << ")"; }
template<class T>          inline ostream& operator<<(ostream& s, const vec<T>& v) DEFINE_ITER_OUTPUT(s, v, ' ')
template<class T, class S> inline ostream& operator<<(ostream& s, const map<T, S>& m) DEFINE_ITER_OUTPUT(s, m, ' ')
template<class T>          inline ostream& operator<<(ostream& s, const vec<vec<T>>& w) DEFINE_ITER_OUTPUT(s, w, '\n')
template<class T, class S> inline ostream& operator<<(ostream& s, const vec<map<T, S>>& vm) DEFINE_ITER_OUTPUT(s, vm, '\n')

void solve();

signed main() {
    if(!debug) {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(20);

    solve();

    return 0;
}

void solve() {
// A B C K
/* <foxy.memo-area> */
int A;int B;int C;int K;cin>>A;cin>>B;cin>>C;cin>>K;
/* </foxy.memo-area> */

    if(K & 1) {
        cout << B - A ln;
    } else {
        cout << A - B ln;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

int main()
{
	int n;
	cin>>n;
	set<char> colors;
	for(int i = 0; i < n;i++){
		char c;
		cin>>c;
		if( colors.count(c) == 0){
			colors.insert(c);
		}
	}
	if( colors.size() == 3){
		cout<<"Three"<<endl;
	}else{
		cout<<"Four"<<endl;
	}
	return 0;
}



Measured memory_bytes: 3128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, B;
	int K;
	cin >> A >> B >> K;
	REP(i, K / 2) {
		if (A % 2 == 1)A--;
		B += A / 2;
		A /= 2;
		if (B % 2 == 1)B--;
		A += B / 2;
		B /= 2;
	}
	if (K % 2 == 1) {
		if (A % 2 == 1)A--;
		B += A / 2;
		A /= 2;
	}
	cout << A << " " << B << endl;
	PAU;
	return 0;
}


Measured memory_bytes: 504
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    void solve(Scanner sc, PrintWriter pw) {
        int N = sc.nextInt();
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = 0;
        for (int i = 0; i + 2 < N; i++) {
            C ^= sc.nextLong();
        }
        pw.println(func(A, B, C));
    }

    private long func(long a, long b, long c) {
        long delta = a + b - c;
        if ((delta % 2) > 0) {
            return -1;
        }
        long andResult = delta / 2;
        if (andResult > a) {
            return -1;
        }
        long remain = a + b - 2L * andResult;
        if ((remain & andResult) > 0) {
            return -1;
        }
        long aResult = andResult;
        for (int i = 40; i >= 0; i--) {
            long bit = (1L << i);
            if ((remain & bit) > 0) {
                if ((aResult | bit) <= a) {
                    aResult |= bit;
                }
            }
        }
        return aResult == 0 ? -1 : a - aResult;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        new Main().solve(sc, pw);
        pw.flush();
        pw.close();
        sc.close();
    }
}


Measured memory_bytes: 36356
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	vector<int> ans(n);
	for(int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		ans[a - 1] = i + 1;
	}

	for(int i = 0; i < n; ++i) {
		cout << ans[i] << " ";
	}
	
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define FOR(i,a,n) for(int i=a,i##_len=(int)(n);i<i##_len;++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i=(int)n;i>=0;--i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1001001001; const long long INFLL=1001001001001001001ll;
template<class T> ostream& operator << (ostream &os, const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is, vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
    #ifdef int
        cerr<<"\x1b[7m"<<"'int' is defined as 'long long' !!!!"<<"\x1b[m"<<endl;
    #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

vector<vector<int>> g;
vector<bool> r;
int N,M;
int dfs(int v) {
    bool f=false;
    REP(i,N) {
        if(!r[i]) {
            f=true;
            break;
        }
    }
    if(!f) {
        return 1;
    }

    int ret=0;
    FORE(u,g[v]) {
        if(r[u]) continue;
        r[u]=true;
        ret+=dfs(u);
        r[u]=false;
        f=true;
    }
    return ret;
}
signed main() {
    cin>>N>>M;
    r=vector<bool>(N,false);
    g=vector<vector<int>>(N);
    REP(i,M) {
        int a,b;
        cin>>a>>b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    r[0]=true;
    cout<<dfs(0)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
using namespace std;

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

const long long INF = 1LL << 60;
char s[60][60];
int bomb[60][60];
int main()
{
	int N,K;
	cin >> N >> K;
	long long res = 1;
	for (int i = 0;i < N;i++) {
		if (i == 0) {
			res *= K;
		}
		else {
			res *= (K - 1);
		}
	}
	
	cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int dh[4] = {0,1,0,-1};
int dw[4] = {1,0,-1,0};
int main() {
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<vector<int>> ans(h, vector<int>(w, 0));
    int dir = 0;
    int hh, ww = 0;
    rep(i, n) {
        rep(j, a[i]) {
            ans[hh][ww] = i + 1;
            hh += dh[dir]; ww += dw[dir];
            if(hh<0||hh>=h||ww<0||ww>=w||ans[hh][ww]!=0) {
                hh -= dh[dir]; ww -= dw[dir];
                dir = (dir+1)%4;
                hh += dh[dir]; ww += dw[dir];
            }
        }
    }
    rep(i, h) {
        rep(j, w) {
            printf("%d ",ans[i][j]);
        }puts("");
    }
}

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

using namespace std;

typedef long long LL;

const LL INF = 1e18;
const int N = 100010;

LL f[N];

int x[N];
int n, T, E;

int main() {
	scanf("%d %d %d", &n, &E, &T);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &x[i]);
	}
	int p = 0;
	LL mn = INF;
	for (int i = 1; i <= n; i++) {
		f[i] = INF;
		while(2 * (x[i] - x[p + 1]) > T) {
			mn = min(f[p] - 2 * x[p + 1], mn);
			++p;
		}
		f[i] = min(f[i], mn + 2 * x[i]);
		f[i] = min(f[i], f[p] + T);
	}
	cout << f[n] + E << endl;
	return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

int main() {
	int N; string s, t;
	cin >> N >> s >> t;

	if (s == t) {
		puts("0");
		return 0;
	}

	vector<pii> v[2];

	rep(i, N-1) {
		if (s[i] != s[i+1]) {
			v[0].eb(s[i]-'0', i);
		}
		if (t[i] != t[i+1]) {
			v[1].eb(t[i]-'0', i);
		}
	}

	if (v[0].size() == 0) {
		cout << N << endl;
		return 0;
	}

	ll ans = TEN(18);

	for (int d = -N; d <= N; ++d) {
		deque<pii> s[2];
		rep(t, 2) {
			for (auto p : v[t]) {
				s[t].eb(p);
			}		
		}

		if (d < 0) {
			rep(i, -d) {
				s[1].push_front(mp(-1, -1));
			}
		} else {
			rep(i, d) {
				s[0].push_front(mp(-1, -1));
			}
		}
		while (s[0].size() < s[1].size()) {
			s[0].eb(mp(-1, N-1));
		}
		while (s[0].size() > s[1].size()) {
			s[1].eb(mp(-1, N-1));
		}

		bool ok = true;
		ll dis = 0;

		rep(i, s[0].size()) {
			if (s[0][i].fi != -1 && s[1][i].fi != -1 && s[0][i].fi != s[1][i].fi) {
				ok = false;
			}
			dis += abs(s[0][i].se - s[1][i].se);
		}

		if (ok) {
			ans = min(ans, dis);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<queue>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;

int main()
{
	int m, n, *A, nail, i, j;
	cin >> n;
	A = new int[n];
	r(i, n)cin >> A[i];

	queue<int> cpp;
	cin >> m;
	r(i, m)	cin >> j, cpp.push(j);

	bool include = true;
	//front 代表先扎进去的那一头 ，back才是最后面 
	//pop()删除的是最前面的，县扎进去的
	//之所以出错是因为我以为pop()是吧最后面的给弹出来，把队列当成了栈，妈的！！！老子本来想用栈的，用错了！！！

	if (m > n)include = false;
	else if (m == n)
		r(i, n) {
		if (cpp.front() != A[i])
		{
			include = false; break;
		}
		cpp.pop();
	}
	else
	{
		nail = 0;
		while (m--)
		{
			for (i = nail; i < n; i++)
			{
				if (cpp.front() == A[i])
				{
					nail = i;
					cpp.pop();
					break;
				}
			}
			if (nail != i)
			{
				include = false;
				break;
			}
		}
	}
	if (include)cout << "1" << endl;
	else cout << "0" << endl;

	return 0;
}


Measured memory_bytes: 4460
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    
    int N;
    cin >> N;
    
    int p[10000] = {};
    
    int n = N;
    int i = 0;
    
    while(n--){
        cin >> p[i];
        i++;
        
    }
    
    sort(p,p+10000,greater<int>());
    
    p[0] = p[0]/2;
    
    n = N;
    i = 0;
    int ans = 0;
    while(n--){
        ans = ans+p[i];
        i++;
        
    }
    
    cout << ans << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const ll INF = ll(1e15)+10;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;

int main() {
	string S;
	cin >> S;
	int numA = 0;
	int numB = 0;
	rep(i, S.size()) {
		if (S[i] == 'A') numA++;
		if (S[i] == 'B') numB++;
	}
	if (numA > 0 && numB > 0) cout << "Yes";
	else cout << "No";
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
let readIntArray () =
    stdin.ReadLine().Split(" ") |> Array.map int

readIntArray ()
|> (fun [| x; y |] -> [ 1 .. x ] |> List.map ((+) (y - 1)))
|> fun x ->
    let m = x |> List.minBy abs
    x |> List.filter ((<>) m) |> List.sum
|> printfn "%d"


Measured memory_bytes: 30152
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

int main(){
    string s;
    cin >> s;
    int cnt = 0;
    int ans = 0;

    rep(i,3){
        if(s[i] == 'R'){
            cnt++;
        }else{
            ans = max(ans,cnt);
            cnt = 0;
        }
    }
    ans = max(ans,cnt);

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

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

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

 string s;cin >> s;
 vector<int> mark(n,0);
 vector<int> ans(q);

 for(int i=1;i<n;i++){
    if(s[i]=='C' && s[i-1]=='A'){
      mark[i]++;
    }
   mark[i]+=mark[i-1];
 }

 for(int i=0;i<q;i++){
   int a,b; cin >> a >> b;
   a--;b--;
   ans[i]=mark[b]-mark[a];
 }

 for(int i=0;i<q;i++) cout << ans[i] << endl;


 //for(int i=0;i<n;i++)cout << mark[i] << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int h,w;
char arr[55][55],trash;
int main(void)
{
    scanf("%d %d",&h,&w);
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++) scanf("%c",&arr[i][j]);
        scanf("%c",&trash);
    }
    for(int i=2;i<h;i++)
        for(int j=2;j<w;j++)
            if(arr[i][j]=='#')
                if((arr[i-1][j]=='#'||arr[i+1][j]=='#'||arr[i][j-1]=='#'||arr[i][j+1]=='#')) continue;
                else return !printf("No");
    printf("Yes");
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
using namespace std;
 
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0103 

int main() {
	int n;
	cin >> n;
	for (int k = 0; k < n; k++) {
		queue<int> q;
		int ans = 0;
		int out = 0;
		while (true) {
			string s;
			cin >> s;
			if (s == "HIT") {
				q.push(1);
				if (q.size() > 3) {
					ans++;
					q.pop();
				}
			} else if (s == "HOMERUN") {
				while (q.size() > 0) {
					if (q.front() == 1) ans++;
					q.pop();
				}
				ans++;
			} else {
				out++;
				if (out == 3) break;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3056
#include<stdio.h>
#include<stdlib.h>


struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k)
{
  while(u!=NIL && k!=u->key)
    {
      if(k< u->key) u=u->left;
      else u=u->right;
    }
  return u;

}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL)
    {
      y=x;
      if(z->key < x->key) x=x->left;
      else x=x->right;
    }
  z->parent=y;
  
  if(y==NIL) root=z;
  else if(z->key < y->key) y->left=z;
  else y->right=z;
}



void inorder(Node u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);

}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);

}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20556
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);


ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b){
  ll r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return b;
}


ll LCM(ll a,ll b){
  ll c=a,d=b,r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return c/b*d;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

vector<pair<char,ll>> runlength(string s,vector<pair<char,ll>> p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
    return p;
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
  return p;
}



/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n,ans=0;
  cin>>n;
  for(ll i=1;i<=n/2+1;i++){
    ll k=n-i;
    if(i!=k && !(k<i)){
      ans++;
    }
  }
  cout<<ans<<endl;
}

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

using namespace std;

typedef tuple<int, int, int> TP;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

int N;
vector<vector<int>> city;

int main() {
  cin >> N;
  city.assign(N * N, vector<int>());
  for (int i = 0; i < 2 * N * N - 2 * N; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    city[a].push_back(b);
    city[b].push_back(a);
  }

  vector<vector<int>> ans(N, vector<int>(N, -1));
  vector<bool> used(N * N, false);
  for (int i = 0; i < N * N; i++) {
    if (city[i].size() == 2) {
      ans[0][0] = i;
      used[i] = true;

      for (int j = 0; j < N - 1; j++) {
        int index = -1, deg = 1e9;
        for (auto nv : city[ans[0][j]]) {
          if (used[nv]) continue;
          if (city[nv].size() < deg) {
            index = nv;
            deg = city[nv].size();
          }
        }
        used[index] = true;
        ans[0][j + 1] = index;
      }

      for (int y = 0; y < N - 1; y++) {
        for (int x = 0; x < N; x++) {
          int v = ans[y][x];
          for (auto nv : city[v]) {
            if (used[nv]) continue;
            ans[y + 1][x] = nv;
            used[nv] = true;
          }
        }
      }

      for (int y = 0; y < N; y++) {
        for (int x = 0; x < N; x++) {
          cout << ans[y][x] + 1 << " ";
        }
        cout << endl;
      }
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 3500
s=input()
t=input()
 
listA=[s.count(chr(i)) for i in range(ord('a'),ord('z')+1)]
listB=[t.count(chr(i)) for i in range(ord('a'),ord('z')+1)]

listA.sort()
listB.sort()

print('Yes' if listA==listB else 'No')

Measured memory_bytes: 3632
let () = Scanf.scanf "%d %d" @@ fun a b ->
  (* 
    n * (n + 1) / 2 - h = a
    (n + 1) * (n + 2) / 2 - h = b

    b - a = (n + 2) * (n + 1) / 2 - n * (n + 1) / 2 
    b - a = n + 1
    n = b - a + 1
    h = n * (n + 1) / 2 - a
  *)
  let n = b - a in
  Printf.printf "%d\n" @@ n * (n + 1) / 2 - b


Measured memory_bytes: 384
#include <iostream>
#include<vector>
#include<climits>
#define ll long long
#include<cmath>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k;
    cin>>n>>k;
    vector<ll> s(n+5);
    vector<int>dp(n+5);
    dp[0]=dp[1]=0;
    s[0]=INT_MAX;
    for(int i=1; i<=n; i++){
        cin>>s[i];
    }
    ll ans;
    for( int i=2; i<=n; i++ ){
        ans = INT_MAX;
        for(int j=1; j<=k; j++){
            if(i-j > 0){
            ans = min( ans, dp[i-j]+abs(s[i]-s[i-j]) );
            }
            //ans = min( ans, dp[i-j]+abs(s[i]-s[i-j]) ) ;
        }
        //dp[i] = min( abs(s[i] - s[i-1])+dp[i-1] , abs(s[i] - s[i-2])+dp[i-2]);
        dp[i] = ans;
    }
    cout<<dp[n];
}


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

nusuke = [0] * N
res = 0

for i in range(K):
  d = int(input())
  a = list(map(int, input().split()))
  for j in range(d):
    nusuke[a[j] - 1] += 1

for value in nusuke:
  if(value == 0):
    res += 1

print(res)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
const ll N = 200030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;

int main()
{

int a,b;
cin>>a>>b;
cout<<a/b+(a%b!=0);


}

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

int main(){
  string S, T;
  cin >> S >> T;
  int LS=S.size();
  int LT=min(S.size(),T.size());
  int temp=0;
  for(int i=LS-LT; i>=0; i--){
    int cnt=0;
    for(int j=0; j<LT; j++){
      if(S.at(i+j)==T.at(j) || S.at(i+j)=='?') cnt++;
    }
    if(cnt==LT){
      for(int j=0; j<LT; j++){
        S.at(i+j)=T.at(j);
      }
      for(int i=0; i<LS; i++){
        if(S.at(i)=='?') S.at(i)='a';
      }
      break;
    }
    else temp++;
  }
  if(temp==LS-LT+1 || LT<T.size()) cout << "UNRESTORABLE" << endl;
  else cout << S << endl;
}

Measured memory_bytes: 256
from itertools import accumulate
n=int(input())
l=list(accumulate(range(4473)))

while True:
    for i,x in enumerate(l):
        if n==x:
            for y in range(1,i+1):
                print(y)
            exit()
        elif n<x:
            print(i)
            n-=i
            break

Measured memory_bytes: 9296
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvlong long vector<vector<long long>>
#define vvc vector<vector<char>>
#define vlong long vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
using namespace std;

int main() {
	long long colors = 0;
	long long N; cin >> N;
	vector<long long> a(3, 0);
	long long ans = 1;
	for (int i = 0; i < N; i++) {
		sort(ALL(a));
		long long x; cin >> x;
		if (x == 0) colors++;
		long long cnt = 0;
		if (x == a[0]) cnt++;
		if (x == a[1]) cnt++;
		if (x == a[2]) cnt++;

		if (x == a[0]) {
			a[0]++;
		}
		else {
			if (x == a[1]) {
				a[1]++;
			}
			else {
				if (x == a[2]) {
					a[2]++;
				}
				else {
					cout << 0 << endl;
					return 0;
				}
			}
		}
		ans *= cnt;
		ans %= MOD;
	}

	cout << ans << endl;
}

Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main(){
	int n,i;
	while(cin>>n&&n!=-1){
	double x=1.0,y=0.0,l,kakudo=0.0,r;
	 for(i=1;i<n;i++){
		 l=sqrt(x*x+y*y);
		 kakudo+=atan(1/l);
		 r=sqrt(l*l+1.0);
		 x=r*cos(kakudo);
		 y=r*sin(kakudo);
		}
	 printf("%2lf\n%2lf\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
// #include "ane.cpp"

const int INF  = 1e9;
const long long INFLL = 1e18;
const int NMAX = 100005;
const int MMAX = 100005;
const int KMAX = 1005;
const int MOD  = 1e9 + 7;
using namespace std;

// comment to disable debug functions
#define DEBUG

// frequently used macros

#if __cplusplus >= 201103L
#define ALL(v) begin(v),end(v)
#define SORT(v) sort(begin(v), end(v))
#define FIND(v,x) find(begin(v), end(v), (x))
#else
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(v.begin(), v.end())
#define FIND(v,x) find(v.begin(), v.end(), (x))
#endif

#define fi first
#define se second

#define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \
memset((from), 0, sizeof(from)); } while(0)
#ifdef DEBUG
#define DUMP(x) do{ std::cerr << (#x) << ": " << x << std::endl; }while(0)
#else
#define DUMP(x) do{}while(0)
#endif

// frequent used aliases
typedef long long ll;
typedef pair<int, int> p;
typedef pair<ll, int> lp;
typedef pair<ll, ll> llp;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<vec> mat;
typedef vector<vecll> matll;

// frequently used constants
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};

// frequently used structs
struct edge{
  int to,cost;
};

// printf for debug
#ifndef DEBUG
void debug(const char* format, ...){}
#else
void debug(const char* format, ...){
  va_list arg;
  va_start(arg, format);
  vprintf(format, arg);
  va_end(arg);
}
#endif

// dump vector
#ifdef DEBUG
#define DUMPV(v, c) do{       \
  printf("%s: ", #v);         \
  for (int i = 0; i < (c); ++i) \
  {                           \
  cout << (v)[i] << " ";      \
  }                           \
  cout << endl;               \
} while(0)
#else
#define DUMPV(v,c)
#endif

// std::fill of multi dimensions
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
  std::fill( reinterpret_cast<T*>(array),
             reinterpret_cast<T*>(array+N),
             val );
}

// binary search
ll BSearch(ll ok, ll ng, bool (*f)(ll)){
  ll mid;
  while(abs(ok - ng) > 1LL) {
    mid =  (ok + ng) / 2LL;
    if(f(mid)) {
      debug("BSearch: f(%d) == true\n", mid);
      ok = mid;
    }
    else
    {
      debug("BSearch: f(%d) == false\n", mid);
      ng = mid;
    }
  }
  return ok;
}

ll NUM_TEST_CASE = 1;

ll N,M,K,A,B,C,D,E;
int dp[NMAX] = {};

string S;
vec v;

ll ans = {};

void solve(){
  // main algorithm
  if(K % 2 == 0) {
    ans = A - B;
  }
  else {
    ans = B - A;
  }
}
void debug(){
  // output debug information

}
void answer(){
  // output answer
  cout << ans << endl;
}
void init(){
  // initialize for each test case
  // Fill(dp, -1);
}
int main(int argc, char const *argv[])
{
  // operate inputs

  // cin >> NUM_TEST_CASE;

  for (int test_case = 0; test_case < NUM_TEST_CASE; ++test_case)
  {
    init();

    cin >> A >> B >> C >> K;
    solve();
    #ifdef DEBUG
    debug();
    #endif
    answer();
  }

  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace c
{
    class Program
    {
        static int solve(string s, char r)
        {
            int ret = 0;
            foreach (char c in s) {
                if (c != r)
                    ret++;
                r = r == '0' ? '1' : '0';
            }
            return ret;
        }
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int ans = Math.Min(solve(s, '0'), solve(s, '1'));
            Console.WriteLine(ans);
        }
    }
}


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

int main() {
 int a,b,c,k;
 cin >> a >> b >> c >> k;
 rep(i,k){
   if(max({a,b,c}) == a) a *= 2;
   else if(max({a,b,c}) == b) b *= 2;
   else c *= 2;
 }
 cout << a+ b + c << endl;
 } 

Measured memory_bytes: 3524
# -*- coding: utf-8 -*-
from collections import Counter
def inpl(): return list(map(int, input().split()))
N = int(input())
A = inpl()
Ai = range(N)
Ad = {a:i for i, a in enumerate(A)}
F = inpl()

C = [0]*N
for f in F:
    C[Ad[f]] += 1

if not 0 in C:
    print("Yes")
else:
    print("No")
    print(*list(map(str, A)))
    lack = C.index(0)
    ans = A[:lack] + [A[lack-1]] + A[lack+1:]
    print(*ans)



Measured memory_bytes: 30148
#include <bits/stdc++.h>
struct Istream {
	Istream() {
#ifdef DEBUG
		freopen("input","r",stdin);
#endif
	}
	template <class T> 
	Istream &operator >>(T &x) {
		static char ch;static bool neg;
		for(ch=neg=0;ch<'0' || '9'<ch;neg|=ch=='-',ch=getchar());
		for(x=0;'0'<=ch && ch<='9';(x*=10)+=ch-'0',ch=getchar());
		x=neg?-x:x;
		return *this;
	}
}is;
struct Ostream {
	template <class T>
	Ostream &operator <<(T x) {
		x<0 && (putchar('-'),x=-x);
		static char stack[233];static int top;
		for(top=0;x;stack[++top]=x%10+'0',x/=10);
		for(top==0 && (stack[top=1]='0');top;putchar(stack[top--]));
		return *this;
	}
	Ostream &operator <<(char ch) {
		putchar(ch);
		return *this;
	}
}os;
const int MAXN=1e5+11;
struct Edge {
	int u,v,c;
	Edge(int u,int v,int c):u(u),v(v),c(c) {}
	friend bool operator <(Edge const &a,Edge const &b) {
		return a.c<b.c;
	}
};
int dsu[MAXN];
int Root(int x) {
	return dsu[x]==0?x:dsu[x]=Root(dsu[x]);
}
int main() {
	int n;is>>n;
	static std::pair<int,int> p[MAXN],xi[MAXN],yi[MAXN];
	for(int i=1;i<=n;++i) {
		is>>p[i].first>>p[i].second;
		xi[i]=std::pair<int,int>(p[i].first,i);
		yi[i]=std::pair<int,int>(p[i].second,i);
	}
	std::sort(xi+1,xi+1+n);
	std::sort(yi+1,yi+1+n);
	std::vector<Edge> edges;
	for(int i=1;i<=n-1;++i) {
		edges.push_back(Edge(xi[i].second,xi[i+1].second,xi[i+1].first-xi[i].first));
		edges.push_back(Edge(yi[i].second,yi[i+1].second,yi[i+1].first-yi[i].first));
	}
	std::sort(edges.begin(),edges.end());
	long long Ans=0;
	int cnt=0;
	for(Edge &e : edges) {
		if(Root(e.u)!=Root(e.v)) {
			Ans+=e.c;
			dsu[Root(e.u)]=Root(e.v);
			if(++cnt==n-1) {
				break;
			}
		}
	}
	os<<Ans<<'\n';
	return 0;
}


Measured memory_bytes: 8308
D=int(input())
c = list(map(int,input().split()))
s=[[0 for e in range(26)] for f in range(D)]
for i in range(D):
 s[i]=list(map(int,input().split()))
last=[0]*26
ans=0
point=[0]*D
for i in range(D):
 t=int(input())
 ans+=s[i][t-1]
 last[t-1]=i+1
 for j in range(26):
  ans+=c[j]*(last[j]-(i+1))
  point[i]=ans
for i in range(D):
 print(point[i])

Measured memory_bytes: 9508
import java.util.*;

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

	public Main() {
		new AOJ0547().doIt();
	}

	class AOJ0547{
//		右向きで曲がれる->0
//		上向きで曲がれる->1
//		右向きで曲がれない->2
//		上向きで曲がれない->3
		int dp[][][],N=101;
		void doIt(){
			dp = new int[101][101][4];
			for(int i=1;i<N;i++){
				dp[0][i][0] = 1;
				dp[i][0][1] = 1;
			}
			for(int y=1;y<N;y++)for(int x=1;x<N;x++){
				dp[y][x][0] = (dp[y][x][0] + dp[y][x-1][0] + dp[y][x-1][2])%100000;
				dp[y][x][1] = (dp[y][x][1] + dp[y-1][x][1] + dp[y-1][x][3])%100000;
				dp[y][x][2] = (dp[y][x][2] + dp[y][x-1][1])%100000;
				dp[y][x][3] = (dp[y][x][3] + dp[y-1][x][0])%100000;
			}
			while(true){
				int w = in.nextInt(),h = in.nextInt();
				if(w+h==0)break;
				int result = 0;
				for(int i=0;i<4;i++)result += dp[h-1][w-1][i];
				System.out.println(result%100000);
			}
		}
	}
}

Measured memory_bytes: 17552
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int N, A, B;

int main() {
  cin >> N >> A >> B;
  cout << min(N * A, B) << endl;

  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
string s;
int n,a,b,c,d;
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>a>>b>>c>>d;
	cin>>s;
	s=" "+s+"#####";
	if(d>c){
		for(int i=min(a,b);i<=max(c,d)-1;i++){
			if(s[i]=='#'&&s[i+1]=='#')return puts("No")&0;
		}
		puts("Yes");
	}else{
		//d<c
		for(int i=a;i<=c-1;i++){
			if(s[i]=='#'&&s[i+1]=='#'){
				return puts("No")&0;
			}
		}
		for(int i=b-1;i<=d-1;i++){
			if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.'){
				return puts("Yes")&0;
			}
		}
		puts("No");
	}
	return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	string s; ll k; cin>>s>>k;
	int siz = s.size()-1;
	int seq_cnt = 0;
	//when 1-charactor
	if(s.size()==1){cout<<k/2<<endl; return 0;}

	for(int i = siz; i>=0; --i){
		if(s[siz] == s[i])seq_cnt++;
		else break;
	}
	//when all elements are same
	if(seq_cnt == s.size()){
		cout<<s.size()*k/2<<endl;
		return 0;
	}

	//others
	ll need_repl = 0;
	rep(i,s.size()-1){
		if(s[i] == s[i+1]){
			need_repl++;
			++i;
		}
	}
	int seq_cnt_h = 0;
	for(int i = 0; i<=siz; ++i){
		if(s[siz] == s[i])seq_cnt_h++;
		else break;
	}
	need_repl *= k;
	if((seq_cnt_h%2 && seq_cnt%2) && s[0] == s[siz]){
		need_repl += (k-1LL);
	}
	cout<<need_repl<<endl;
}

// int main(){
// 	string s; ll k; cin>>s>>k;
// 	if(s.size() == 1){
// 		cout<<k/2<<endl;
// 		return 0;
// 	}
// 	int cnt = 0;
// 	int ch = 0;
// 	rep(i,s.size()-1){
// 		if(s[i] == s[i+1]){++cnt; ++i; ch++; continue;}
// 		ch = 0;
// 	}
// 	bool ok = ((s[s.size()-1] != s[s.size()-2]) || ch%2);
// 	// cout<<ch<<' '<<ok<<endl;
// 	ll ans = cnt*k;
// 	if(s[0] == s[s.size()-1] && ok){
// 		ans += (k-1);
// 	}
// 	cout<<ans<<endl;
// 	return 0;
// }

// int main(){
// 	string s; ll k; cin>>s>>k;
// 	if(s.size() == 1){
// 		cout<<k/2<<endl;
// 		return 0;
// 	}
// 	// if(s.size() == 2){
// 	// 	if(s[0] == s[1]){
// 	// 		cout<<k<<endl;
// 	// 	}else{
// 	// 		cout<<0<<endl;
// 	// 	}
// 	// 	return 0;
// 	// }
// 	int cnt = 0;
// 	int ch = 0;
// 	rep(i,s.size()-1){
// 		if(s[i] == s[i+1]){++cnt; ++i; continue;}
// 	}
// 	for(int i = s.size()-1; i>=0; --i){
// 		if(s[i] == s[s.size()-1])ch ++;
// 		else break;
// 	}
// 	// cout<<cnt<<' '<<ch<<endl;
// 	// cout<<ch<<' '<<ok<<endl;
// 	ll ans = cnt*k;
// 	if(s[0] == s[s.size()-1] && ch%2){
// 		ans += (k-1);
// 	}
// 	if(k%2 && ch==s.size() && s.size()%2){
// 		cout<<(ll)s.size()*k-ans<<endl;
// 	}else{
// 		cout<<ans<<endl;
// 	}
// 	return 0;
// }

Measured memory_bytes: 256