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

#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef tuple<int, int, int> TP;
typedef vector<int> VI;
typedef double T;
typedef vector<T> VT;
typedef vector<VT> VVT;

const LL MOD = 1e9 + 7;
const double EPS = 1e-10;
mt19937 rng(7); // random generator using 7 for seed

const int MAXN = 1e5 + 10;

int a[MAXN], b[MAXN], c[MAXN];
LL dp1[MAXN], dp2[MAXN], dp3[MAXN];

int main() {
    int n;
    cin >> n;
    for(int i=1;i<=n;i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    for(int i=1;i<=n;i++) {
        dp1[i] = max(dp2[i-1], dp3[i-1]) + a[i];
        dp2[i] = max(dp1[i-1], dp3[i-1]) + b[i];
        dp3[i] = max(dp1[i-1], dp2[i-1]) + c[i];
    }
    printf("%lld\n", max(dp1[n], max(dp2[n], dp3[n])));
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int mod=1e9+7;

int main(){
    int n;cin>>n;
    int a[n];rep(i,n)cin>>a[i];
    int mabs=0;
    int p;
    rep(i,n){
        if(chmax(mabs,abs(a[i])))p=i;
    }
    cout<<2*n-1<<endl;
    rep(i,n){
        cout<<p+1<<" "<<i+1<<endl;
    }
    if(a[p]<0){
        rep(i,n-1)cout<<n-i<<" "<<n-1-i<<endl;
    }
    else{
        rep(i,n-1)cout<<i+1<<" "<<i+2<<endl;
    }
}

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

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<ll,pi >
#define ppi pair<pi,ll>
#define ppp pair<pi,pi >
#define ex(str,a,b) str.substr((int)(a),min((int)str.size()-a,(int)(b-a+1))) 
#define all(X) X.begin(),X.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   __builtin_popcount(n) : no. of set bits in n.
*/

const int M = (1<<20)+5;
const int md = 1e9+7;

priority_queue<ll,vector<ll >,greater<ll > > pq;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

ll ar[M];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n,k,i;
	cin >> n >> k;
	for(i=1;i<=n;++i)
	{
		cin >> ar[i];
		if(i>k)
		{
			if(ar[i]>ar[i-k])
				cout << "Yes" << "\n";
			else
				cout << "No" << "\n";
		}
	}
}

Measured memory_bytes: 5224
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;
int Inf = (1 << 30);
ll inf = (1LL << 60);
const int MOD = 1e9 + 7;
int ans = 0;
void dfs(int n, Graph &G, vector<bool> &visited ,int v) {
	int i;
	bool flag = true;
	for (i = 0; i < n; i++) {
		if (!visited[i] && i != v) flag = false;
	}
	if (flag) {
		ans++;
		return;
	}
	visited[v] = true;
	for (auto c : G[v]) {
		if (visited[c]) continue;
		dfs(n, G, visited, c);
	}
	visited[v] = false;
}
int main() {
	int n, m;
	cin >> n >> m;
	int i;
	Graph G(n, V(n, 0));
	for (i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<bool> visited(n, false);
	dfs(n, G , visited, 0);
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int N,K,X,Y;
    cin >> N ;
    cin >> K ;
    cin >> X >> Y ;
    if(N<=K){
        cout << (N*X) << endl ;
    }
    else{
        cout << ((K*X) + ((N-K)*Y)) << endl ;
    }


    return 0;
}


Measured memory_bytes: 256
// 5:12
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <map>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <stack>
#include <queue>
#include <cstring>
#include <iterator>

#define FOR(n) for(int cnt=0;cnt<(n);++cnt)
#define FOR_R(it,cont) for(auto it=rbegin(cont);it!=rend(cont);++it)
#define FOR_F(it,cont) for(auto it=begin(cont);it!=end(cont);++it)
#define ALL(cont) begin(cont), end(cont)
#define LB(b,e,v) lower_bound(b,e,v)
#define UB(b,e,v) upper_bound(b,e,v)

using namespace std;
typedef pair<int,int> P;
int N;
vector<int> edges[100010];
int K;
int lv[100010];
int uv[100010];
int ans[100010];
bool visited[100010];
bool OK = true;
int INF = 2*1000*1000;

void dfs(int current) {
  int nlv = lv[current],nuv=uv[current];
  visited[current]=true;
  FOR_F(edge, edges[current]) {
    int to=*edge;
    if (visited[to]) continue;
    dfs(to);
    nlv = max(nlv, lv[to]-1);
    nuv = min(nuv, uv[to]+1);
  }
  lv[current] = nlv;uv[current] = nuv;
}

void setValues(int current, int prev) {
  if (lv[current]>uv[current]) {
    OK = false;
    return;
  }
  visited[current]=true;
  if (prev==-1) {
    ans[current]=lv[current];
  } else {
    int temps[]={ans[prev]+1, ans[prev]-1};
    bool flag = true;
    for(int i=0;i<2;++i) {
      if (temps[i]>=lv[current] && temps[i] <=uv[current]) {
        ans[current] = temps[i];
        flag = false;
      }
    }
    if (flag) {
      OK=false;return;
    }
  }
  FOR_F(edge, edges[current]) {
    int to=*edge;
    if (visited[to]) continue;
    setValues(to, current);
  }
}

int main() {
  fill(ALL(lv), -INF);
  fill(ALL(uv), INF);
  scanf("%d", &N);
  FOR(N-1) {
    int A,B;
    scanf("%d%d", &A,&B);--A;--B;
    edges[A].push_back(B);
    edges[B].push_back(A);
  }
  scanf("%d", &K);
  int startPos;
  FOR(K) {
    int V,P;
    scanf("%d%d", &V, &P);--V;
    startPos=V;
    lv[V]=P;
    uv[V]=P;
  }
  fill(ALL(visited),false);
  dfs(startPos);
  fill(ALL(visited),false);
  setValues(startPos, -1);
  if (OK) {
    printf("Yes\n");
    FOR(N) {
      printf("%d\n", ans[cnt]);
    }
  } else {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 13952
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<vector<int>> g(10005);
vector<int> num(10005);
ll m;
vector<bool> visited(10005), visited2(10005);
vector<int> c(10005);

void bfs(int s) {
	queue<int> Q;
	Q.push(s);
	int cnt = 0;
	while (!Q.empty()) {
		int v = Q.front(); Q.pop();
		num[v] = c[cnt];
		cnt++;
		visited[v] = true;
		for (int to: g[v]) {
			if (visited[to]) continue;
			Q.push(to);
		}
	}
} 

void bfs2(int s) {
	queue<int> Q;
	Q.push(s);
	while (!Q.empty()) {
		int v = Q.front(); Q.pop();
		visited2[v] = true;
		for (int to: g[v]) {
			if (visited2[to]) continue;
			m += min(num[v], num[to]);
			Q.push(to);
		}
	}
}

int main() {
	int n;
	cin >> n;
	
	rep (i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	rep (i, n) cin >> c[i];

	sort(rrng(c));

	bfs(0);
	bfs2(0);

	cout << m << endl;
	rep (i, n) cout << num[i] << " ";
	cout << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=10;
struct node{
	int x,y;
}a[N];
double num[N][N];
double ans=0;
int n;
int nn[]={0,0,2,4,12,48,240,1440,10080};
int f(int n){
	int t=1;
	for(int i=1;i<=n;i++){
		t=t*i;
	}
	return t;
}
//int f1(int n){
//	if(n==2){
//		return 1;
//	}
//	return n*(n-1)/f(n-2);
//}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d %d",&a[i].x,&a[i].y);
	}
//	int len=f(n)*(n-1)/f1(n);
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			num[i][j]=sqrt(1.0*(a[i].x-a[j].x)*(a[i].x-a[j].x)+1.0*(a[i].y-a[j].y)*(a[i].y-a[j].y));
			ans+=(num[i][j]*nn[n]);
		}
	}
	printf("%.10f\n",ans/f(n));
	return 0;
}

Measured memory_bytes: 256
def getlist():
	return list(map(int, input().split()))

#初期化
N, M, Q = getlist()
List = [[0] * (N + 1) for i in range(N + 1)]
for i in range(M):
	L, R = getlist()
	List[R][L] += 1

#累積和前処理
for i in range(N):
	for j in range(N + 1):
		List[i + 1][j] += List[i][j]
for i in range(N + 1):
	for j in range(N):
		List[i][j + 1] += List[i][j]

#クエリ処理
for i in range(Q):
	p, q = getlist()
	print(List[q][q] - List[q][p - 1])

Measured memory_bytes: 59352
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    a = list(map(int, input().split()))
    #使う本数の種類
    b = set()
    matti = [2,5,5,4,5,6,3,7,6]
    for i in a:
        b.add(matti[i-1])

    dp = [-1]*(n+1)
    dp[0] = 0
    for i in range(n+1):
        for j in b:
            if i >= j:
                dp[i] = max(dp[i-j]+1, dp[i])

    keta = dp[-1]
    res = []
    a.sort(reverse=True)
    cnt = n
    while cnt>0:
        for i in a:
            if cnt >= matti[i-1]:
                if dp[cnt]-dp[cnt-matti[i-1]]==1:
                    res.append(str(i))
                    cnt -= matti[i-1]
                    break
    print(''.join(res))


if __name__ == '__main__':
    main()

Measured memory_bytes: 4044
sx,sy,tx,ty = map(int,input().split())
x=tx-sx
y=ty-sy

ans="R"*x+"U"*y + "L"*x+"D"*y + "D"+"R"*(x+1)+"U"*(y+1)+"L" + "U"+"L"*(x+1)+"D"*(y+1)+"R"
print(ans)

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

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

    int K, S;
    cin >> K >> S;

    int ans = 0;
    for(int X = 0; X <= K; ++X){
        for(int Y = 0; Y <= K; ++Y){
            int Z = S - (X + Y);
            if(0 <= Z && Z <= K)
                ++ans;
        }
    }
    cout << ans << endl;

    return 0;
};

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lson l,mid,o<<1
#define rson mid+1,r,o<<1|1
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> PII;
const int INF=0x3f3f3f3f;
const LL MAX_N=2e5 + 10;
const LL mod=1e9+7;
const double PI=acos(-1);


int main()
{
    int a , b, c, ans;
    cin >> a >> b >> c;
    ans = min(a + b, a + c);
    ans = min(ans, b + c);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N,M = map(int, input().split())
tmp = [False] * N
for _ in range(M):
  a,b = map(int, input().split())
  if a == 1:
    if tmp[b-1]:
      print('POSSIBLE')
      exit()
    else:
      tmp[b-1] = True
  elif b == N:
    if tmp[a-1]:
      print('POSSIBLE')
      exit()
    else:
      tmp[a-1] = True
print('IMPOSSIBLE')

Measured memory_bytes: 4596
import sys


fin = sys.stdin.readline
N = int(fin())
X_list = [int(elem) for elem in fin().split()]
sorted_indices = sorted(range(N), key=lambda i: X_list[i])
org_pos_to_sorted = {org_p: sorted_p for sorted_p, org_p in enumerate(sorted_indices)}

left_mid = X_list[sorted_indices[N // 2 - 1]]
right_mid = X_list[sorted_indices[N // 2]]
result = []
for i in range(N):
    sorted_pos = org_pos_to_sorted[i]
    if sorted_pos >= N // 2:
        result.append(left_mid)
    else:
        result.append(right_mid)

print(*result, sep="\n")


Measured memory_bytes: 119548
N,A,B = map(int, input().split())
s = 0
x = 0
for i in range(N):
    t = i+1
    while t > 0:
        s += t % 10
        t = t//10
    if s>=A and s<=B:
        x += i+1
    s = 0

print(x)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
#define INF 1e18
#define NINF INT_MIN

#define nax 200005


void solve(){
	
	int n,q;
	cin>>n;
	map<int, int> m;
	int sum=0;
	rep(i,0,n){
		int x;
		cin>>x;
		m[x]++;
		sum+=x;
	}

	cin>>q;
	rep(i,0,q){
		int b,c;
		cin>>b>>c;
		if(m.find(b)!=m.end()){
			sum-=b*m[b];
			sum+=c*m[b];
			int temp = m[b];
			m.erase(b);
			m[c]+=temp;
		}
		cout<<sum<<endl;
	}

	
}	

signed main(){
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand (static_cast <unsigned> (time(0)));
    int t;
    // cin>>t;
    t=1;
    while(t--){
        solve();
    }
    return 0;
}

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

int main(){
  string s;
  cin >> s;
  string ans="";
  for(int i=0; i<s.length(); i++){
    if(i%2==0){
      ans+=s[i];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	int n, k, c; cin >> n >> k >> c;
	string s; cin >> s;
	vector<int> l(k);
	vector<int> ans;
	int p = 0, cnt = 0;
	while( p < n and cnt < k ){
		if( s[p] == 'o' ){
			l[cnt] = p;
			p += (c+1);
			++cnt;
		} else ++p;
	}
	reverse( s.begin(), s.end() );
	p = 0, cnt = 0;
	while( p < n and cnt < k ){
		if( s[p] == 'o' ){
			if( l[k-1-cnt] == n-1-p ) ans.push_back(n-p);
			p += (c+1);
			++cnt;
		} else ++p;
	}
	reverse( ans.begin(), ans.end() );
	for( auto k : ans ){
		cout << k << endl;
	}
}

Measured memory_bytes: 3448
#include<iostream>
using namespace std;
int main(){
 long long int n,d,i;
 long long sum=0;
  cin >> n >> d;
  for(i=0;i<n;i++){
  long long int x,y;
    cin >> x >> y;
    if(x*x+y*y<=d*d){
    sum++;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3560
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool inRange(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool inRange(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//



int main() {
	int N, M;
	cin >> N >> M;
	
	priority_queue< int, vector< int >, greater< int > > que;
	for (int i=0; i<N; ++i) {
		int A;
		cin >> A;
		que.push(A);
	}
	
	vector< pii > cnv;
	for (int i=0; i<M; ++i) {
		int B, C;
		cin >> B >> C;
		cnv.push_back(pii(C, B));
	}
	sort(cnv.begin(), cnv.end());
	reverse(cnv.begin(), cnv.end());
	
	lint ans = 0;
	int i = 0;
	while (!que.empty()) {
		int A = que.top(); que.pop();
		while (i < M && cnv[i].first <= A) ++i;
		if (i < M && cnv[i].second > 0) {
			A = cnv[i].first;
			cnv[i].second--;
			if (cnv[i].second == 0) ++i;
		}
		ans += A;
	}
	cout << ans << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 1784
a,b,c,k = [int(x) for x in input().strip().split()]

res=0
res+=min(k,a)
k-=min(k,a)

if k>0:
    k-=min(b,k)

if k>0:
    res-=min(k,c)
    k-=min(k,c)

print(res)

Measured memory_bytes: 9188
import java.util.*;
class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong(),y=sc.nextLong();
        long ans = 0;
        for(long i = x;i<=y;i*=2)ans++;
        System.out.println(ans);
    }
}


Measured memory_bytes: 35812
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);
 
int main(void){
    int n, m; cin >> n >> m;
    vi a(m);
    for(auto & e : a) cin >> e;

    int res = max(a[0] - 1, n - a[m - 1]);
    rep(i, m - 1){
        chmax(res, (a[i + 1] - a[i]) / 2);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3272
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define PI acos(-1)
#define sz 100010
#define RUN_FAST ios::sync_with_stdio(false);
using namespace std;

int main()
{
    RUN_FAST; cin.tie(nullptr);
    string s;
    cin >> s;
    if (s[2]==s[3] && s[4]==s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
const int N=5005;
const int mo=1000000007;
int n,A,B,f[N][N],g[N][N],h[N*2];
void F1(){
	f[1][1]=2;
	For(i,1,n) For(j,1,A-1){
		f[i][j+1]=(f[i][j+1]+f[i-1][j])%mo;
		f[i][1]=(f[i][1]+f[i-1][j])%mo;
	}
	int ans=1;
	For(i,1,n) ans=ans*2%mo;
	For(j,1,A-1) ans=(ans+mo-f[n][j])%mo;
	cout<<ans<<endl;
}
void F2(){
	f[0][0]=1;
	For(i,0,n+1){
		if (i) h[i]=(h[i]+h[i-1])%mo;
		f[i][1]=(f[i][1]+h[i])%mo;
		For(j,0,B){
			if (i&&j) g[i][j]=(g[i][j]+g[i-1][j-1])%mo;
			f[i][j]=(f[i][j]+g[i][j])%mo;
			if (j==B) continue;
			f[i+1][j+1]=(f[i+1][j+1]+f[i][j])%mo;
			h[i+2]=(h[i+2]+f[i][j])%mo;
			h[i+A+1]=(h[i+A+1]+mo-f[i][j])%mo;
			if (i+A+1<=n+1&&j+A+1<=n)
			g[i+A+1][j+A+1]=(g[i+A+1][j+A+1]+f[i][j])%mo;
		}
		//cout<<i<<' '<<j<<' '<<f[i][j]<<endl;
	}
	int ans=1;
	For(i,1,n) ans=2*ans%mo;
	For(j,1,B) ans=(ans+mo-f[n+1][j])%mo;
	cout<<ans<<endl;
}
/*
11:2
01:1
*/
int main(){
	scanf("%d%d%d",&n,&A,&B);
	if (A>B) swap(A,B);
	if (A==B) F1();
	else F2();
}
/*
>_<
*/


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

using LL = long long;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

const string YES = "Yes";
const string NO = "No";

void solve(long long H, long long N, std::vector<long long> A) {
  // solver code

  int sum = accumulate(A.begin(), A.end(), 0);

  if (sum >= H) {
    cout << YES << endl;
  } else {
    cout << NO << endl;
  }
}

int main() {
  long long H;
  scanf("%lld", &H);
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(H, N, std::move(A));
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	float a,b,l,x;
	int n,m;
	cin>>a>>b;
	int n1,n2,m1,m2;
	n1=a/0.08;
	float x1;
	x1=a/0.08;
	if(n1!=x1)
	n1++;
	n2=(a+1)/0.08;
	float x2=(a+1)/0.08;
	if(n2==x2)
	n2--;
	m1=b/0.1;
	x1=b/0.1;
	if(m1!=x1)
	m1++;
	m2=(b+1)/0.1;
	x2=(b+1)/0.1;
	if(m2==x2)
	m2--;
	
	if(m2<n1||n2<m1)
	{
		cout<<-1;
		return 0;
	}
	int ans1,ans2,ans3,ans4;
	ans1=INT_MAX;
	if(m1>=n1&&m1<=n2)
	ans1=min(m1,ans1);
	if(m2>=n1&&m2<=n2)
	ans1=min(ans1,m2);
	if(n1>=m1&&n1<=m2)
	ans1=min(n1,ans1);
	if(n2>=m1&&n2<=m2)
	ans1=min(n2,ans1);
	cout<<ans1;
	
}


Measured memory_bytes: 256
import sys

limit = 10 ** 5 * 2
sys.setrecursionlimit(limit)

def calc_depth(n):
    if children[n] == set():
        return 0

    depth_l = [calc_depth(child) for child in children[n]]
    depth_l.sort(reverse=True)

    return max(depth + (i+1) for (i, depth) in enumerate(depth_l))

N = int(input())

children = [set() for i in range(N + 1)]

for i in range(N - 1):
    a = int(input())
    children[a].add(i + 2)

ans = calc_depth(1)

# print(children)

print(ans)

Measured memory_bytes: 234664
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

const int MAX = 510000;
const ll MOD = 998244353;

ll 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;
  }
}

ll 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 n, ll t) {
  ll ret = 1;
  while (0 < t) {
    if (t % 2 == 0) {
      n *= n;
      n %= MOD;
      t >>= 1;
    } else {
      ret *= n;
      ret %= MOD;
      --t;
    }
  }
  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  int N, M, K;
  cin >> N >> M >> K;
  ll ans = 0;
  COMinit();

  REP(i, K + 1) {
    ll tmp = (COM(N - 1, i) * M % MOD) * modpow((M - 1), N - i - 1) % MOD;
    // cout << COM(N - 1, i) << " " << modpow((M - 1), N - i - 1) << endl;
    //    cout << ans << endl;
    ans = (ans + tmp) % MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 15592
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int main(){
	int n, l; cin >> n >> l; std::vector<int> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	
	int pos = -1;
	for(int i = 0; i < n - 1; i++){
		if(a[i] + a[i + 1] < l) continue;
		pos = i; break;
	}
	
	if(~pos){
		cout << "Possible" << endl;
		for(int i = 0; i < pos; i++){
			cout << i + 1 << endl;
		}
		
		for(int i = n - 1; i > pos; i--){
			cout << i << endl;
		}
	}else{
		cout << "Impossible" << endl;
	}
	return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;

using namespace std;

int x[100000];
int y[100000];
int black[2001][2001];
int white[2001][2001];
char c[100000];

/*
imosにおいて
(x1,y1)...........(x2,y2)
   |								 |
	 |								 |
   |								 |
   |								 |
(x1,y2)...........(x2,y2)
で構成される長方形の面積を求める
*/
int Square(int x1,int y1,int x2,int y2,bool B)
{
	int ret=0;
	int a,b,c;
	if(B==true)
	{
		if(y1>0)
		{
			a = black[x2][y1-1];
		}else{
			a=0;
		}
		if(x1>0)
		{
			b=black[x1-1][y2];
		}else{
			b=0;
		}
		if(y1>0&&x1>0)
		{
			c=black[x1-1][y1-1];
		}else{
			c=0;
		}
		ret = black[x2][y2]-a-b+c;
	}else{
		if(y1>0)
		{
			a = white[x2][y1-1];
		}else{
			a=0;
		}
		if(x1>0)
		{
			b=white[x1-1][y2];
		}else{
			b=0;
		}
		if(y1>0&&x1>0)
		{
			c=white[x1-1][y1-1];
		}else{
			c=0;
		}
		ret = white[x2][y2]-a-b+c;
	}
	return ret;
}

int main()
{
	int n,k;
	int M=0;
	int cnt=0;
	int xl,xr,yd,yu;
	
	cin>>n>>k;
	for(int i=0;i<2001;i++)
	{
		for(int j=0;j<2001;j++)
		{
			black[i][j]=0;
			white[i][j]=0;
		}
	}
	for(int i=0;i<n;i++)
	{
		cin>>x[i]>>y[i]>>c[i];
		x[i]%=(2*k);
		y[i]%=(2*k);
		if(c[i]=='B')
		{
			black[x[i]][y[i]]++;
		}else if(c[i]=='W'){
			white[x[i]][y[i]]++;
		}
	}
	//x方向の累積和
	for(int i=0;i<2*k;i++)
	{
		for(int j=1;j<2*k;j++)
		{
			black[j][i]=black[j][i]+black[j-1][i];
			white[j][i]=white[j][i]+white[j-1][i];
		}
	}
	//y方向の累積和
	for(int j=0;j<2*k;j++)
	{
		for(int i=1;i<2*k;i++)
		{
			black[j][i]=black[j][i]+black[j][i-1];
			white[j][i]=white[j][i]+white[j][i-1];
		}
	}
	//累積和チェック
	/*
	for(int j=0;j<2*k;j++)
	{
		for(int i=0;i<2*k;i++)
		{
			cerr<<black[i][j]<<" ";
		}
		cerr<<endl;
	}*/
	//x
	for(xl=0;xl<k;xl++)
	{
		//y
		for(yd=0;yd<k;yd++)
		{
			cnt=0;
			//初期位置白
			//白の数え上げ
			cnt += Square(xl,yd,xl+k-1,yd+k-1,false)+Square(xl+k,yd+k,2*k-1,2*k-1,false);
			if(xl>0)
			{
				cnt += Square(0,yd+k,xl-1,2*k-1,false);
			}
			if(yd>0)
			{
				cnt += Square(xl+k,0,2*k-1,yd-1,false);
			}
			if(xl>0&&yd>0)
			{
				cnt += Square(0,0,xl-1,yd-1,false);
			}
			//黒の数え上げ
			cnt += Square(xl+k,yd,2*k-1,yd+k-1,true)+Square(xl,yd+k,xl+k-1,2*k-1,true);
			if(xl>0)
			{
				cnt += Square(0,yd,xl-1,yd+k-1,true);
			}
			if(yd>0)
			{
				cnt += Square(xl,0,xl+k-1,yd-1,true);
			}
			//cerr<<"("<<xl<<","<<yd<<") ... "<<cnt<<endl;
			if(M<cnt)
			{
				M=cnt;
			}
			//初期位置黒
			cnt = n-cnt;
			if(M<cnt)
			{
				M=cnt;
			}
		}
	}
	cout<<M<<endl;
	return 0;
}

Measured memory_bytes: 32384
#include<iostream>
#include<vector>
using namespace std;
const int NMAX = 100000;
int dp[100000];

int main(){
  int n;
  cin >> n;
  
  vector<int> h(NMAX);
  for(int i=0; i<NMAX; i++){
    cin >> h.at(i); 
  }
  
  dp[0] = 0;
  dp[1] = abs(h[0]-h[1]);
  
  for(int i=2; i<n; i++){
    dp[i] = min(dp[i-2]+abs(h[i-2]-h[i]), dp[i-1]+abs(h[i-1]-h[i]));
  }

  cout << dp[n-1] << endl;
  
  return 0;
}


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

using namespace std;

#define foru(i, l, r) for(register int i = l; i <= r; i++)
#define ford(i, r, l) for(register int i = r; i >= l; i--)

typedef vector<int> vec;
vec trans(vec arr) {
  vec res(3);
  res[0] = (arr[1] + arr[2]) >> 1;
  res[1] = (arr[0] + arr[2]) >> 1;
  res[2] = (arr[0] + arr[1]) >> 1;
  sort(res.begin(), res.end());
  return res;
}

set<vec> st;
int check(vec arr) {
  return (arr[0] | arr[1] | arr[2]) & 1;
}

int main() {
  //  freopen("a.in", "r", stdin);
  //  freopen("a.out", "w", stdout);
  vec arr(3);
  scanf("%d%d%d", &arr[0], &arr[1], &arr[2]);
  sort(arr.begin(), arr.end());
  st.insert(arr);
  while (!check(arr)) {
    arr = trans(arr);
    if (st.count(arr)) return puts("-1"), 0;
    st.insert(arr);
  }
  printf("%d\n", (int)st.size() - 1);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);


int g[15][15];
const int INF = 1001001001;
const int di[] = { -1,0,1,0 };
const int dj[] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int main() {
	string s;
	cin >> s;
	int a = s[0] - '0', b = s[1] - '0',c = s[2] - '0', d = s[3] - '0';
	if (a + b + c + d == 7)printf("%d+%d+%d+%d=7\n", a, b, c, d);
	else if (a + b + c - d == 7)printf("%d+%d+%d-%d=7\n", a, b, c, d);
	else if (a + b - c + d == 7)printf("%d+%d-%d+%d=7\n", a, b, c, d);
	else if (a + b - c - d == 7)printf("%d+%d-%d-%d=7\n", a, b, c, d);
	else if (a - b + c + d == 7)printf("%d-%d+%d+%d=7\n", a, b, c, d);
	else if (a - b + c - d == 7)printf("%d-%d+%d-%d=7\n", a, b, c, d);
	else if (a - b - c + d == 7)printf("%d-%d-%d+%d=7\n", a, b, c, d);
	else if (a - b - c - d == 7)printf("%d-%d-%d-%d=7\n", a, b, c, d);
	return 0;
}


Measured memory_bytes: 256
require 'pp'

n = gets.to_i
a_n = gets.split.map(&:to_i)

a_n.sort!.reverse!

index = 0
seq = 0
arrived = Array.new(n, 0)
arrived[0] = a_n[0]
ans = 0
1.upto(n-1) do |i|
    arrived[i] = a_n[i]
    #pp arrived[index]
    ans += arrived[index]
    if i == 1
        seq = 0
        index += 1
    elsif seq == 0
        seq += 1
    else
        seq = 0
        index += 1
    end

    #pp ans
end

puts ans


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

#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr); cin.tie(nullptr);
#define int long long

using namespace std;

int32_t main() {
	fast
	string s;
	cin >> s;
	int n = s.back() - '0';
	if (n == 2 or n == 4 or n == 5 or n == 7 or n == 9) cout << "hon";
	else if (n == 0 or n == 1 or n == 6 or n == 8) cout << "pon";
	else cout << "bon" << endl;
}

Measured memory_bytes: 3608
import scala.io.StdIn._
object Main extends App {
  val sr = new StdinReader
  val n, m, q = sr.nextInt

  val arr = Array.ofDim[Int](n + 1, n + 1)
  (1 to m).foreach{i =>
    val l, r = sr.nextInt
    arr(l)(r) += 1
  }

  for {
    l <- (1 to n)
    r <- (l to n)
  } {
    arr(l)(r) = arr(l)(r - 1) + arr(l)(r)
  }

  val ans = Array.ofDim[Int](n + 1, n + 1)
  for {
    l <- (1 to n)
    r <- (l to n)
  } {
    ans(l)(r) = (l to r).map{i => arr(i)(r) - arr(i)(l - 1)}.sum
  }

  (1 to q).foreach{i =>
    val l, r = sr.nextInt
    println(ans(l)(r))
  }
}




class StdinReader {
  val is = System.in
  val buffer = new Array[Byte](1024 * 1024)
  var size = 0
  var pos = 0

  private def readByte: Byte = {
    if (pos >= size) {
      pos = 0;
      size = is.read(buffer);
    }
    if (size < 0) -1
    else {
      val ret = buffer(pos)
      pos += 1
      ret
    }
  }

  // support single byte char only
  def next: String = {
    @scala.annotation.tailrec
    def r(sb: StringBuilder, reading: Boolean): String = {
      readByte match {
        case b if ('!' <= b && b <= '~') => r(sb.append(b.asInstanceOf[Char]), true)
        case _ => if (reading) sb.toString else r(sb, false)
      }
    }
    r(new StringBuilder, false)
  }

  def nextInt: Int = {
    @scala.annotation.tailrec
    def r(i: Int, reading: Boolean): Int = {
      readByte match {
        case '-' => r(i * -1, true)
        case b if '0' <= b && b <= '9' => r(i * 10 + (b - '0'), true)
        case _ => if (reading) i else r(i, false)
      }
    }
    r(0, false)
  }
}

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

int main(){
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    const double dx = x1 - x2;
    const double dy = y1 - y2;
    printf("%.10f\n", sqrt(dx * dx + dy * dy));
    return 0;
}



Measured memory_bytes: 3216
package main

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

var (
	sc = bufio.NewScanner(os.Stdin)
	wtr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

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

func main() {
	sc.Split(bufio.ScanWords)

	n := scanInt()

	fmt.Println(float64((n+1)/2)/float64(n))
}


Measured memory_bytes: 640
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char) 
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
    
  token.parse().ok().expect("failed to parse token")
}

fn main() {
  let n: u8 = read();
  let s: String = read();
  println!("{}",
    s.chars().map(|c|((c as u8 - 65 + n) % 26 + 65) as char)
    .collect::<String>()
  );
}

Measured memory_bytes: 4476
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctype.h>
using namespace std;
#define dump(a) cout << (a) << '\n';
typedef long long Int;
Int mod = 1e9+7;
Int MOD = 998244353;

int main() {
    ios::sync_with_stdio(false);
    Int h, w, n;
    cin >> h >> w >> n;
    map<pair<Int, Int>, Int> mp;
    for (Int i = 0; i < n; i++) {
        Int a, b;
        cin >> a >> b;
        mp[make_pair(a, b)]++;
    }
    map<pair<Int, Int>, Int> p; 
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        Int x, y;
        y = (itr->first).first;
        x = (itr->first).second;
        for (Int i = max(2LL, y - 1); i <= min(h - 1, y + 1); i++) {
            for (Int j = max(2LL, x - 1); j <= min(w - 1, x + 1); j++) {
                p[make_pair(i, j)]++;
            }
        }
    }
    map<Int, Int> res;
    res[0] = (h - 2) * (w - 2) - (Int)p.size();
    for (auto itr = p.begin(); itr != p.end(); itr++) res[itr->second]++;
    for (Int i = 0; i < 10; i++) dump(res[i]);
    return 0;  
}

Measured memory_bytes: 62720
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main{
    static MyReader in = new MyReader();

    public static void main(String[] args){
        int N = in.i();
        String[] S = new String[N];
        for(int i = 0; i < N; i++){
            S[i] = in.s();
        }
        Arrays.sort(S);
        int max = 0;
        String[] T = new String[N];
        int size = 0;
        for(int i = 0; i < N; ){
            int count = 0;
            String tmp = S[i];
            while(i < N && S[i].equals(tmp)){
                count++;
                i++;
            }
            if(max == count){
                T[size++] = tmp;
            } else if (max < count){
                size = 1;
                T[0] = tmp;
                max = count;
            }                
        }
        for(int i = 0; i < size; i++){
            out.println(T[i]);
        }
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        ArrayList<Integer> li(){
            String[] ss = ss();
            ArrayList<Integer> li = new ArrayList<>();
            for(int j = 0; j < ss.length; j++) li.add(Integer.parseInt(ss[j]));
            return li;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


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

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

    int n, k, x, y;
    cin >> n >> k >> x >> y;

    if(n <= k){
        cout << n * x << endl;
    }else{
        cout << k * x + (n - k) * y << endl;
    }


    return 0;
}

Measured memory_bytes: 256
s = input("")
Q = int(input())
c = 0
before = []
after = []
for i in range(Q):
    t = input()
    if len(t) == 1:
        c += 1
    elif t[2] == "1":
        if c%2 == 0:
            before.append(t[4])
        else:
            after.append(t[4])
    else:
        if c%2 == 0:
            after.append(t[4])
        else:
            before.append(t[4])

if c%2 == 0:
    print("".join(before[::-1]),end="")
    print(s,end="")
    print("".join(after),end="")
else:
    print("".join(after[::-1]),end="")
    print(s[::-1],end="")
    print("".join(before),end="")

Measured memory_bytes: 67288
// Problem : I - Coins
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_i
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include <bits/stdc++.h>
using namespace std;
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define endl '\n'
#define vi vector<ll>
#define vb vector<bool>
#define mii map<ll, ll>
#define pii pair<ll, ll>
#define pb push_back
#define fi first
#define se second
#define m_p make_pair
#define vpii vector<pii>
#define vvi vector<vi>
#define vs vector<string>
#define all(x) x.begin(), x.end()
//Proof: 
//Complexity:
void print(vi v){
	ll n = v.size();
	for(ll i = 0;i<n;i++){
		cout<<v[i]<<" ";
	}
        cout<<endl;
}
ll power(ll a, ll b){
    ll res = 1;
    while(b!=0){
        if(b&1){
            res *= a; 
        }
        a = (a * a);
        b = (b / 2);
    }
    return res;
}
int main(){
    SPEED;
    ll n;
    cin>>n;
    vector<double> v(n + 1);
    for(ll i = 1;i<=n;i++)cin>>v[i];
    vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0.0));
    dp[1][1] = v[1];
    dp[1][0] = (1.0 - v[1]);
    for(ll i = 2;i<=n;i++){
    	dp[i][0] = dp[i - 1][0] * (1.0 - v[i]);
    }
    for(ll i = 2;i<=n;i++){
    	for(ll j = 1;j<=n;j++){
    		dp[i][j] += dp[i - 1][j - 1] * (v[i]) + dp[i - 1][j] * (1.0 - v[i]); 
    	}
    }
    // for(ll i = 0;i<=n;i++){
    	// for(ll j = 0;j<=n;j++)cout<<dp[i][j]<<" ";
    	// cout<<"\n";
    // }
    double d = 0.0;
    for(ll i = (n/2) + 1;i<=n;i++){
    	d += dp[n][i];
    }
    cout<<setprecision(12)<<d<<endl;
    return 0;
}

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

typedef long long LL;

const int kMaxN = 105;
const int kInf = 0x3f3f3f3f;

struct Edge {int to, cap, rev;};

int N;
int a[kMaxN];
int st, ed; 
LL sum;
vector<Edge> G[kMaxN];
int level[kMaxN];
int iter[kMaxN];

void AddEdge(int s, int t, int cap)
{
  G[s].push_back((Edge){t, cap, (int)G[t].size()});
  G[t].push_back((Edge){s, 0, (int)G[s].size() - 1});
}

void bfs(int s)
{
  memset(level, -1, sizeof level);
  queue<int> que;
  level[s] = 0;
  que.push(s);
  while (!que.empty()) {
    int v = que.front(); que.pop();
    for (int i = 0; i < (int)G[v].size(); ++i) {
      Edge &e = G[v][i];
      if (e.cap > 0 && level[e.to] < 0) {
        level[e.to] = level[v] + 1;
        que.push(e.to);
      }
    }
  }
}

int dfs(int v, int t, int f)
{
  if (v == t) return f;
  for (int &i = iter[v]; i < (int)G[v].size(); ++i) {
    Edge &e = G[v][i];
    if (e.cap > 0 && level[v] < level[e.to]) {
      int d = dfs(e.to, t, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}


LL GetMaxFlow(int s, int t)
{
  LL flow= 0;
  for (; ;) {
    bfs(s);
    if (level[t] < 0) return flow;
    memset(iter, 0, sizeof iter);
    int f;
    while ((f = dfs(s, t, kInf)) > 0) {
      flow += f;
    }
  }
}
void BuildG()
{
  st = N;
  ed = N + 1;
  for (int i = 0; i < N; ++i) {
    if (a[i] < 0) AddEdge(st, i, -a[i]);
    else AddEdge(i, ed, a[i]);
    // 1: 1 2 3 4
    // 0: 0 1 2 3

    // 2: 2 4 6 8
    // 1: 1 3 5 7
    for (int j = i + i + 1; j < N; j += i + 1) {
      AddEdge(i, j, kInf);
    }
  }
}

void Solve()
{
  BuildG();
  LL min_cut = GetMaxFlow(st, ed);
  LL ans = sum - min_cut;
  // printf("sum=%lld\tmin_cut=%lld\n", sum, min_cut);
  printf("%lld\n", ans);
}

int main()
{
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", a + i);
    if (a[i] > 0) sum += a[i];
  }
  Solve();
  return 0; 
}


Measured memory_bytes: 256
S = input()
cnt = 0
if S[0] == "A":
    for i in range(2, len(S)-1):
        if S[i] == "C":
            cnt += 1
    if cnt == 1:
        S = S.replace(S[0], "")
        S = S.replace("C", "")
        if S.islower():
            print("AC")
        else:
            print("WA")
    else:
        if S.islower():
            print("AC")
        else:
            print("WA")
else:
    print("WA")


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

int main()
{
	int c=0,n,str[5];
	while(cin >> n)
	{
		if(c) cout << endl; c=1;

		for(int i=0,k=10000; i<5; i++,k/=10)
		{
			str[i] = n/k;
			n %= k;
		}


		for(int j=0; j<2; j++)
		{
			for(int i=0; i<5; i++)
			{
				cout << (str[i]/5==j?'*':' ');
			}
			cout << endl;
		}
	
		for(int i=0; i<5; i++) cout << '='; cout << endl;
		
		for(int j=0; j<5; j++)
		{
			for(int i=0; i<5; i++)
			{
				cout << (str[i]%5==j?' ':'*');
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 852
//author: JainBot27
//Created on: 08/22/20
#pragma GCC optimize("Ofast")
#pragma GCC target("sse4,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;


#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ts to_string
#define ub upper_bound
#define lb lower_bound
#define ar array
#define all(x) x.begin(), x.end()
#define siz(x) (int)x.size()
#define FOR(x, y, z) for(int x = (y); x < (z); x++)
#define ROF(x, y, z) for(int x = (y-1); x >= (z); x--)
#define F0R(x, z) FOR(x, 0, z)
#define R0F(x, z) ROF(x, z, 0)
#define trav(x, y) for(auto&x:y)


const string nl = "\n";
using ll = int64_t;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using str = string;
using vpii = vector<pii>;
using vpll = vector<pll>;


template<class T> inline bool ckmin(T&a, T b) {return b < a ? a = b, 1 : 0;}
template<class T> inline bool ckmax(T&a, T b) {return b > a ? a = b, 1 : 0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
template<class A> str ts(complex<A> c) { 
    stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) { 
    str res = "{"; for(int i = 0;i < (int)v.size(); i++) res += char('0'+v[i]);
    res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
    str res = ""; for(int i = 0; i < b.size(); i++) res += char('0'+b[i]);
    return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) { 
    bool fst = 1; str res = "{";
    for (const auto& x: v) {
        if (!fst) res += ", ";
        fst = 0; res += ts(x);
    }
    res += "}"; return res;
}
template<class A, class B> str ts(pair<A,B> p) {
    return "("+ts(p.f)+", "+ts(p.s)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << ts(h); if (sizeof...(t)) cerr << ", ";
    DBG(t...); }


#ifdef D 
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

ll n, x, t;

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> x >> t;
    int w = n/x + (n%x!=0);
    cout << w  *  t << nl;
}
/*
 * Stuff I should try:
 * Is it Monotonic? -> Binary Search
 * Is N small? -> Bitsets or other exponential
 * Edge Cases? Look Carefully 
 * Can't figure anything out? Brute Force and see patterns
 * Try to prove greedies
 * Prefix Sums, Amortization, DP, Data Structures
*/


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=205;
const int inf=1e9;
char s[max_n];
int a[max_n][max_n];
int n;
vector<int> G[max_n];
bool flag;
int color[max_n];
void dfs(int u,int fa,int c){
    color[u]=c;
    for(auto v:G[u]){
        if(v==fa)continue;
        int nc=((c-1)^1)+1;
        if(color[v]){
            if(nc!=color[v]){
                flag=false;
                return;
            }
            continue;
        }
        dfs(v,u,nc);
    }
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf(" %s",s+1);
        for(int j=1;j<=n;j++){
            if(s[j]=='1'){
                a[i][j]=a[j][i]=1;
                G[i].push_back(j);
                G[j].push_back(i);
            }
            else a[i][j]=a[j][i]=inf;
        }
    }
    flag=true;
    dfs(1,0,1);
    if(flag==false)printf("-1\n");
    else{
        for(int i=1;i<=n;i++)a[i][i]=0;
        int ans=0;
        for(int k=1;k<=n;k++){
            for(int i=1;i<=n;i++){
                for(int j=1;j<=n;j++){
                    a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
                }
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<i;j++)ans=max(ans,a[i][j]);
        }
        printf("%d\n",ans+1);
    }
    return 0;
}

Measured memory_bytes: 768
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>

using namespace std;

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

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

//constant
const int INF = 1 << 29;
const double EPS = 1e-10;
const double PI = acos(-1.0);

//debug
#define dump(x)  cout << #x << " = " << (x) << endl;

int main() {
  long long int mod = 1000000007;
  long long int N, ans = 1;
  cin >> N;
  VI A(N);
  REP(i, N) cin >> A[i];
  if (N%2==0) {
    VI check(N/2+1, 0);
    REP(i, N) {
      if (check[A[i]/2] == 0) {
          ans = ans * 2 % mod;
      }else if (check[A[i]/2] == 2) {
          ans = 0;
          break;
      }
      check[A[i]/2]++;
    }
  } else {
    VI check(N/2+1, 0);
    REP(i, N) {
      if (A[i]/2 == 0) {
      } else if (check[A[i]/2] == 0) {
          ans = ans * 2 % mod;
      }else if (check[A[i]/2] == 2) {
          ans = 0;
          break;
      }
      check[A[i]/2]++;
    }
    if(check[0]>=2) ans = 0;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 768