akhauriyash/Code-Regression huggingface dataset:
// sync

#include <algorithm>
#include <cstdio>
#include <cstring>

const int N = 2e5 + 52;

int n, k, a[N], l[N], p[N];
void rm(int x) { x[l][p] = x[p], x[p][l] = x[l]; }
int main() {
	scanf("%d%d", &n, &k);
	if (k == 1 || k == 2 * n - 1) return puts("No"), 0;
	puts("Yes");
	if (n == 2) return puts("1\n2\n3"), 0;
	for (int i = 0; i < 2 * n; i++) i[p] = i - 1, i[l] = i + 1;
	if (k == 2) {
		rm(a[n - 1] = 3);
		rm(a[n + 0] = 2);
		rm(a[n + 1] = 1);
		rm(a[n + 2] = 4);
	} else {
		rm(a[n - 1] = k - 1);
		rm(a[n + 0] = k + 0);
		rm(a[n + 1] = k + 1);
		rm(a[n + 2] = k - 2);
	}
	n = n * 2 - 1;
	for (int i = 1, c = 0 [l]; i <= n; printf("%d\n", a[i++]))
		if (!a[i]) a[i] = c, c = c[l];
}

Measured memory_bytes: 3712
def main():
    n, k = map(int, input().split())
    s = list(input())
    cnt = 0
    for i in range(n-1):
        if s[i] == s[i+1]:
            cnt += 1
    cnt += k*2
    ans = min(n-1, cnt)
    print(ans)

if __name__ == '__main__':
    main()

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

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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 200005

const int INF = 1e9+7;

int main(){

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


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <set>
#include <tuple>

using namespace std;
typedef vector<int>VI;
typedef long long LL;

#define IOSWORK ios::sync_with_stdio(0); cin.tie(0)
#define FOR(x, b, e) for(int x = b; x<= (e); x++)
#define FORD(x, b, e) for(int x = b; x>= (e); x--)
#define REP(x, n) for(int x = 0; x<(n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define VAR(v, n) typeof(n) v = (n)
#define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define SCAN_INT(n) scanf("%i",&n)
#define SCAN_P_INT(n,m) scanf("%i %i",&n,&m)
#define PRINT_P_INT(n,m) printf("%i %i\n",n,m);
#define PRINT_INT(n) printf("%i\n",n)

#define PB push_back
#define ST first
#define ND second
#define INF 1000000000


#define MAXSIZE

int n;
int main(){
    scanf("%i",&n);

    bool instnieje = false;

    while(n){
        if(n%10==9)
            instnieje=true;
        n/=10;
    }
    if(instnieje)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int cnt[100010];
ll ans;

int main() {
    ios_base::sync_with_stdio(0);
    int n; cin >> n;
    for (int i=0;i<n;i++) {
        int x; cin >> x;
        cnt[x]++; ans += x;
    }

    int q; cin >> q;
    while (q--) {
        int b, c; cin >> b >> c;
        ans += 1LL*(c-b)*cnt[b];
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << ans << endl;
    }
}


Measured memory_bytes: 3980
e1,e2,e3,e4=map(int,input().split())

if e1==e2 and e3==e4:
    print("yes")
elif e1==e3 and e2==e4:
    print("yes")
elif e1==e4 and e2==e3:
    print("yes")
else:
    print("no")


Measured memory_bytes: 5596
n=int(input())
s=input()
col={'R','G','B'}
r,g,b=[0]*n,[0]*n,[0]*n
rc,gc,bc=0,0,0
ans=0
for i in range(n-1,-1,-1):
    if (s[i]=='R'): rc+=1
    elif (s[i]=='G'): gc+=1
    elif (s[i]=='B'): bc+=1
    r[i],g[i],b[i]=rc,gc,bc
for i in range(n):
    for j in range(i+1,n):
        if s[i]!='R' and s[j]!='R' and s[i]!=s[j]:
            if j+j-i<n and s[j+j-i]=='R':
                ans+=r[j]-1
            else: ans+=r[j]
        elif s[i]!='G' and s[j]!='G' and s[i]!=s[j]:
            if j+j-i<n and s[j+j-i]=='G':
                ans+=g[j]-1
            else: ans+=g[j]
        elif s[i]!='B' and s[j]!='B' and s[i]!=s[j]:
            if j+j-i<n and s[j+j-i]=='B':
                ans+=b[j]-1
            else: ans+=b[j]
        #print(ans,i,j)
print(ans)


Measured memory_bytes: 68792
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
int main() {
  cout << fixed << setprecision(30);
  ll n,a,b;
  cin>>n>>a>>b;
  ll dim=b-a;
  if(dim%2==0)putout(dim/2);
  else{
    ll x=n-b;
    ll y=a-1;
    ll ans1=(1+2*y+dim)/2;
    ll ans2=(1+2*x+dim)/2;
    putout(min(ans1,ans2));
  }
}

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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  int x; cin >> x;
  if (x < 600) cout << 8 << endl;
  else if (x < 800) cout << 7 << endl;
  else if (x < 1000) cout << 6 << endl;
  else if (x < 1200) cout << 5 << endl;
  else if (x < 1400) cout << 4 << endl;
  else if (x < 1600) cout << 3 << endl;
  else if (x < 1800) cout << 2 << endl;
  else if (x < 2000) cout << 1 << endl;
}

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

using namespace std;

int main(){

	int a, b, c;
	map <int, int> mp;
	cin >> a >> b >> c;
	mp[a]++;
	mp[b]++;
	mp[c]++;
	if (mp[5] == 2 && mp[7] == 1) {
		cout << "YES\n";
	} else {
		cout << "NO\n";
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	const int M = 1000000007;
	int n = int.Parse(ReadLine());
	int[] t = ReadIntArray();
	int[] a = ReadIntArray();

	int curr = 0;
	for (int i = 0; i < n; i++)
	{
	    int h = t[i];
	    if (h <= curr)
	    {
		t[i] *= -1;
	    }
	    curr = h;
	}

	curr = 0;
	for (int i = n-1; i >= 0; i--)
	{
	    int h = a[i];
	    if (h > curr)
	    {
		if (t[i] < 0)
		{
		    if (a[i] > -t[i])
		    {
			WriteLine(0);
			return;
		    }
		    t[i] = a[i];
		}
		else if (t[i] != a[i])
		{
		    WriteLine(0);
		    return;
		}
		curr = h;
	    }
	    else
	    {
		if (t[i] < 0)
		{
		    t[i] = -Math.Min(-t[i], h);
		}
	    }
	}

	long ans = 1;
	for (int i = 0; i < n; i++)
	{
	    int h = t[i];
	    if (h < 0)
	    {
		ans = ans * (-h) % M;
	    }
	}

	WriteLine(ans);
    }
}


Measured memory_bytes: 34228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ちゃんと考えてわかって実装 */

int main(void){
    int n;
    cin >> n;
    map<string, int> s;
    int ans = 0;
    for(int i=0; i<n; i++){
        string kkk;
        cin >> kkk;
        if(s[kkk] == 0){
            ans += 1;
            s[kkk] += 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 19252
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;

typedef pair<int,int> P;
typedef pair<P,int> Node; 
typedef pair<int,Node> State;
const int INF = 1e+8;
int dx[4] = {+1,0,-1,0};
int dy[4] = {0,+1,0,-1};

int w, h;
int s[31][31];
int c[4];

int command(int c, int dir){
	return (dir + c) % 4;
}

int dijkstra(){
	int sx=0, sy=0, dir=0;
	
	int d[4][31][31];
	for(int i=0 ; i < 4 ; i++ ){
		for(int j=0 ; j < 31 ; j++ ){
			for(int k=0 ; k < 31 ; k++ ){
				d[i][j][k] = INF;
			}
		}
	}
	priority_queue< State , vector<State> , greater<State> > q;
	d[0][0][0] = 0;
	Node start( P(0,0) , 0 );
	q.push( State(0,start) );
	
	int res = INF;
	while( !q.empty() ){
		int cost = q.top().first;
		int x = q.top().second.first.first;
		int y = q.top().second.first.second;
		int dir = q.top().second.second;
		q.pop();
		
		if( x == w-1 && y == h-1 ){
			res = cost;
			break;
		}
		
		for(int i=0 ; i < 4 ; i++ ){
			int next_dir = command( dir , i );
			int mx = x + dx[next_dir];
			int my = y + dy[next_dir];
			int next_cost;
			
			if( i == s[y][x] ){
				next_cost = cost;
			}else{
				next_cost = cost + c[i];
			}
			
			if( mx < 0 || my < 0 || mx >= w || my >= h ) continue;
			
			Node next( P(mx,my) , next_dir );
			if( next_cost < d[next_dir][my][mx] ){
				d[next_dir][my][mx] = next_cost;
				q.push( State( next_cost , next ) );
			}
		}
	}
	return res;
}

int main(){
	while( cin >> w >> h , w || h ){
		for(int y=0 ; y < h ; y++ ){
			for(int x=0 ; x < w ; x++ ){
				cin >> s[y][x];
			}
		}
		for(int i=0 ; i < 4 ; i++ ){
			cin >> c[i];
		}
		cout << dijkstra() << endl;
	}
}

Measured memory_bytes: 1028
#include<stdio.h>

int main(void){

	int x,y;
	x=1;
	y=1;
	while(x!=0||y!=0){
		scanf("%d %d",&y,&x);
		if(x!=0||y!=0){
			if(x<y){	
				printf("%d %d\n",x,y);
			}
			else{
				printf("%d %d\n",y,x);
			}
		}
	}
	return 0;
}

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



int main(){
	int N,K;
	cin>>N>>K;
	int ans = 1;
	for(int i=0;i<N;i++){
		ans=min(ans*2,ans+K);
	}
	
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
typedef unsigned u32;
typedef long long s64;
typedef unsigned long long u64;
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
template<class Type> Type read() {
	Type a;
	bool b;
	unsigned char c;
	while(c=getchar()-48, (c>9)&(c!=253));
	for(a=(b=c==253)?0:c; (c=getchar()-48)<=9; a=a*10+c);
	return b?-a:a;
}
int (*rd)()=read<int>;

const int N=105;
int n, m, k;
u32 P, inv[N], pw[N][N*N], ipw[N][N*N], com[N][N], f[N][N], g[N][N];
void trans() {
	for(int i=0; i<=n; ++i)
		for(int j=0; j<=m; ++j) {
			g[i][j]=0;
			for(int b=0; b<=j; ++b) g[i][j]=(g[i][j]+(u64)f[i][b]*com[j][b])%P;
		}
	for(int i=0; i<=n; ++i)
		for(int j=0; j<=m; ++j) {
			f[i][j]=0;
			for(int a=0; a<=i; ++a) f[i][j]=(f[i][j]+(u64)g[a][j]*com[i][a])%P;
		}
}
int main() {
	n=rd(), m=rd(), k=rd(), P=rd();
	pw[0][0]=1;
	for(int i=1; i<=k; ++i) {
		pw[i][0]=1;
		for(int j=1; j<=n*m; ++j) pw[i][j]=(u64)pw[i][j-1]*i%P;
	}
	inv[1]=1;
	for(int i=2; i<=k; ++i) inv[i]=(u64)(P-P/i)*inv[P%i]%P;
	ipw[0][0]=1;
	for(int i=1; i<=k; ++i) {
		ipw[i][0]=1;
		for(int j=1; j<=n*m; ++j) ipw[i][j]=(u64)ipw[i][j-1]*inv[i]%P;
	}
	for(int i=0; i<=n||i<=m; ++i) {
		com[i][0]=com[i][i]=1;
		for(int j=1; j<i; ++j) com[i][j]=(com[i-1][j-1]+com[i-1][j])%P;
	}
	f[0][0]=1;
	for(int t=1; t<=k; ++t) {
		for(int i=0; i<=n; ++i)
			for(int j=0; j<=m; ++j)
				f[i][j]=(u64)f[i][j]*pw[t][(n-i)*(m-j)]%P*ipw[k-t+1][i*j]%P;
		trans();
		if(k==t) break;
		for(int i=0; i<=n; ++i)
			for(int j=0; j<=m; ++j)
				f[i][j]=(u64)(i+j&1?P-f[i][j]:f[i][j])*pw[k-t+1][i*j]%P*ipw[k-t][i*j]%P;
		trans();
		for(int i=0; i<=n; ++i)
			for(int j=0; j<=m; ++j)
				f[i][j]=(u64)(i+j&1?P-f[i][j]:f[i][j])*pw[k-t][i*j]%P*ipw[t][(n-i)*(m-j)]%P;
	}
	printf("%u\n", f[n][m]);
	return 0;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define pii pair<int, int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,n,0)
#define ALL(c) ((c).begin(),(c).end())
#define PB(a) push_back(a)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a,b) make_pair(a,b)
#define MT(...) make_tuple(__VA_ARGS__)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define PW(n) (1LL<<(n))
using namespace std;
template <class T> inline bool CHMIN(T& a, T b) { if(a>b) { a=b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if(a<b) { a=b; return 1; } return 0; }
template <class T> inline void SORT(T& a) { sort(ALL(a)); }
template <class T> inline void REV(T& a) { reverse(ALL(a)); }
template <class T> inline void UNI(T& a) { SORT(a); a.erase(unique(ALL(a)),a.end()); }
template <class S, class T> ostream& operator<<(ostream& os, const pair<S,T> a) {
  return os << a.first << ' ' << a.second;
}
const int MOD = 1000000007;
// const int INF = 0x3f3f3f3f3f3f3f3f;
// const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

/* 基本要素 */
using D = double; // 座標値の型 doubleかlong double
using P = complex<D>; // Point
using L = pair<P,P>;  // Line
using VP = vector<P>;
const double EPS = 1e-8;  // 許容誤差
const double INF = 1e12;
#define X real()
#define Y imag()
#define LE(n,m) ((n)<(m)+EPS) // n <= m ?
#define GE(n,m) ((n)+EPS>(m)) // n >= m ?
#define EQ(n,m) (abs((n)-(m))<EPS)

namespace std {
  istream& operator >> (istream& is, P& p) {
    int F, S;
    is >> F >> S;
    p = P(F,S);
    return is;
  }
}

// 内積
D dot(P a, P b) {
  return (conj(a)*b).X;
}
// 外積
D cross(P a, P b) {
  return (conj(a)*b).Y;
}
// 点aから見た、点bから点cへの方向
int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b,c) > 0) return +1;  // counter clockwise
  if (cross(b,c) < 0) return -1;  // clockwise
  if (dot(b,c) < 0) return +2;  // c--a--b on line
  if (norm(b) < norm(c)) return -2; // a--b--c on line or a==b
  return 0;                     // a--c--b on line or a==c or b==c
}

P p0, p1, p2;
int q;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> p0 >> p1 >> q;
  REP(i,q) {
    cin >> p2;
    int c = ccw(p0,p1,p2);
    if (c == 1) cout << "COUNTER_CLOCKWISE" << endl;
    else if (c == -1) cout << "CLOCKWISE" << endl;
    else if (c == 2) cout << "ONLINE_BACK" << endl;
    else if (c == -2) cout << "ONLINE_FRONT" << endl;
    else if (c == 0) cout << "ON_SEGMENT" << endl;
  }

  return 0;
}


Measured memory_bytes: 3224
#include <stdio.h>
#include <math.h>

double r[1001];
double theta[1001];

/* i+1番目の角度および原点からの半径を求める*/
void init_r_theta()
{
        r[1] = 1;
        theta[1] = 0;

        for ( int i = 2 ; i < 1001 ; i++ ) {
                theta[i] = theta[i-1] + atan( 1 / r[i-1] );
                r[i] = sqrt( r[i-1] * r[i-1] + 1 );
        }
}

int main()
{
        int num;

        init_r_theta();
        while ( scanf( "%d", &num ) == 1 ) {
                if ( num == -1 ) { break; }
                printf( "%.2lf\n", r[num] * cos( theta[num] ) );
                printf( "%.2lf\n", r[num] * sin( theta[num] ) );
        }
        return 0;
}



Measured memory_bytes: 2124
use std::io;

fn main() {
  let stdin = io::stdin();
  let mut buf = String::new();

  loop {
    buf.clear();
    stdin.read_line(&mut buf).unwrap();
    let mut iter = buf.trim().split_whitespace();
    let a = iter.next().unwrap().parse::<i32>().unwrap();
    let bin = iter.next().unwrap();
    let b = iter.next().unwrap().parse::<i32>().unwrap();

    if bin == "?" { break; }
    let ans = match bin.as_ref() {
      "+" => Some(a + b),
      "-" => Some(a - b),
      "*" => Some(a * b),
      "/" => Some(a / b),
      _ => None,
    };
    println!("{}", ans.unwrap());
  }
}



Measured memory_bytes: 5024
#include<bits/stdc++.h>
using namespace std;
const int N=609,inf=1e9;

int n,m,a[N*N],b[N*N];
vector<int>e[N];
double dp[N],ans;

double cal(int p)//p点出发期望最大的点被挡住时的期望
{
    for(int i=1;i<=n;i++)dp[i]=0;
    for(int i=n-1;i>=1;i--){
        int len=e[i].size();
        if(p==i&&len==1){dp[i]=inf;continue;}
        double t=1.0/(len-(p==i)),mx=0;
        for(auto v:e[i]){
            mx=max(mx,(dp[v]+1)*t);
            dp[i]+=(dp[v]+1)*t;
        }
        if(p==i)dp[i]-=mx;
    }
    return dp[1];
}

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>a[i]>>b[i];
        e[a[i]].push_back(b[i]);
    }
    ans=cal(0);
    for(int i=1;i<=n;i++)
        ans=min(ans,cal(i));
    cout<<fixed<<setprecision(10)<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 2816
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        k: usize,
    }
    if k > (n - 1) * (n - 2) / 2 {
        println!("-1");
        return;
    }
    let m = (n - 1) * (n - 2) / 2 - k;
    println!("{}", n + m - 1);
    for u in 2..n + 1 {
        println!("1 {}", u);
    }
    let mut count = 0;
    for v in 2..n + 1 {
        for u in 2..v {
            if count < m {
                println!("{} {}", u, v);
                count += 1;
            }
        }
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<vector>
#include<cmath>
#include<queue>
#include<map>
#include<set>

using namespace std;

int read()
{
	int ans=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return ans*f;
}

int t1,t2;
string s1,s2;

int main()
{
	int temp=read();
	cin>>s1>>s2;
	int len=s1.length()+s2.length();
	for(int i=1;i<=len;++i)
		if(i%2)
			printf("%c",s1[t1++]);
		else
			printf("%c",s2[t2++]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 2000000
int main ()
{
	int i,max,min,num,kawase[MAX];
	scanf("%d",&num);
	//??????????????°??????????????£????????????
	for(i=0;i<num;i++)
	{
	scanf("%d",&kawase[i]);
	}
	for(i=1;i<num;i++){
		//????????????
		max=kawase[1]-kawase[0];
		min=kawase[0];
		for(i=1;i<=num-1;i++){
		//??????????????§?????????????????§????????£??????
		if(max<kawase[i]-min){
			max=kawase[i]-min;
		}
		//????????§???????????????????°???????????????¨????????????????????¨??????????????¨???
			if(min>kawase[i]){
				min=kawase[i];
			}
		}
	}
	printf("%d\n",max);
	return 0;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

	int n, m;

	cin >> n >> m;

	while(m--){
        int x;

        cin >> x;

        n -= x;
	}

	if(n >= 0) cout << n << endl;
	else cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 3664
import java.util.*;

public class Main {
    static Scanner sc=new Scanner(System.in);
    static int W;
    static int ans1;
    static int ans2;
    static int c;
    public static void main(String[] args){
        c=1;
        while(true){
            W=Integer.parseInt(sc.nextLine());
            if(W==0)break;
            int N=Integer.parseInt(sc.nextLine());
            run(N);
            c++;
        }
    }
    static void run(int N){
        ans1=0;
        ans2=0;
        int[] p=new int[N+1];
        int[] w=new int[N+1];
        for(int i=1;i<=N;i++){
            String[] s=sc.nextLine().split(",");
            p[i]=Integer.parseInt(s[0]);
            w[i]=Integer.parseInt(s[1]);
        }
        int[][] dp=new int[N+1][W+1];
        for(int i=0;i<N+1;i++){
            for(int j=0;j<W+1;j++){
                dp[i][j]=-1;
            }
        }
        dp[0][0]=0;
        for(int i=1;i<=N;i++){
            for(int j=0;j<=W;j++){
                if(dp[i-1][j]!=-1){
                    if(dp[i][j]<dp[i-1][j])dp[i][j]=dp[i-1][j];
                    if(j+w[i]<=W){
                        dp[i][j+w[i]]=Math.max(dp[i][j+w[i]], dp[i-1][j]+p[i]);
                    }
                }
            }
        }
        for(int i=0;i<=W;i++){
            if(ans1<dp[N][i]){
                ans1=dp[N][i];
                ans2=i;
            }
        }
        System.out.println("Case "+c+":");
        System.out.println(ans1);
        System.out.println(ans2);
    }
}

Measured memory_bytes: 33084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    double r, g; cin >> r >> g;
    /*
    (r+ans)/2 = g
    ans = 2g - r
    */

   cout << 2*g - r << endl;
}

Measured memory_bytes: 256
def solve(n,num_list,s):
    ans = 0
    # Vはループを確認する際に回ったかどうかをチェックする
    V = [False for _ in range(n)]
    
    # sorted_num_listでは数列の最終的なゴールを確認する
    sorted_num_list = sorted(num_list)

    # ゴールのインデックスを確認する
    T = [None for _ in range(10000+1)]
    for i in range(n):
        T[sorted_num_list[i]] = i

    # 全ての要素に対して
    for i in range(n):

        # Vが埋まっていれば前ループの要素サイクルで移動済みなので無視
        if V[i]:
            continue

        cur = i
        
        # Sは サイクル内のバリューの合計
        S = 0

        # mはサイクルの最小値
        m = 10000

        # anはサイクルの要素数
        an = 0

        # ここからサイクルごとのループに入る
        while True:
            V[cur] = True
            an += 1
            v = num_list[cur]
            m = min(m,v)
            S += v
            cur = T[v]
            if V[cur]:
                break
        ans += min(S + (an - 2)*m,m+S+(an+1)*s)
    return ans

# 移動先をリストとしてバリューをインデックスにして保管するやり方をマスターすべし，


if __name__ == "__main__":
    n = int(input())
    num_list = list(map(int,input().split()))
    s = min(num_list)
    ans = solve(n,num_list,s)
    print(ans)


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

using namespace std;

typedef long long ll;
bool prime[10000000];



int main() {
  ll s;
  cin >> s;

  const ll v = 1e9;

  ll x = (v - s % v) % v;
  ll y = (s + x) / v;

  cout << "0 0 1000000000 1 "<<x<<" "<<y<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rp(i,n) for(int i=1;i<=(int)n;i++)
int main() {
int n;cin>>n;
int a=n%500;
cout<<(n/500)*1000+(a/5)*5<<endl;
}


Measured memory_bytes: 256
import bisect

n = int(input())
l = list(map(int,input().split()))
l.sort()

count = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        k = bisect.bisect_left(l, l[i] + l[j])
        count += k - j - 1
print(count)


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

using namespace std;
int n, m ,x;
vector<long long int> H(100001, 0);
vector<vector<pair<long long int, long long int>>> root(100001);
vector<long long int> dist(100001, LLONG_MAX);
vector<long long int> high(100001, 0);
bitset<100001> used;

void Dijkstra(long long int start = 1){
    priority_queue< tuple<long long int, long long int, long long int>, vector<tuple<long long int, long long int, long long int>>, greater<tuple<long long int, long long int, long long int>> > que;
    que.push(make_tuple(0, start, x));
    while(!que.empty()){
        long long int d, t, h;
        tie(d, t, h) = que.top(); que.pop();
        if(used[t]) continue;
        used[t] = true, dist[t] = d, high[t] = h;
        for(auto e : root[t]){
            long long int cost = d + e.first, nh = h - e.first;
            if(nh > H[e.second]) cost += nh - H[e.second], nh = H[e.second];
            if(nh < 0) cost += abs(0 - nh), nh = 0;
            if(dist[e.second] <= cost) continue;
            que.push(make_tuple(cost, e.second, nh));
        }
    }
}


int main(int argc, const char * argv[]) {
    cin >> n >> m >> x;
    for(int i = 0; i < n; ++i) cin >> H[i + 1];
    for(int i = 0; i < m; ++i){
        long long int a, b, c;
        cin >> a >> b >> c;
        if(H[a] >= c) root[a].emplace_back(c, b);
        if(H[b] >= c) root[b].emplace_back(c, a);
    }
    
    Dijkstra();
    if(dist[n] == LLONG_MAX) cout << -1 << endl;
    else cout << dist[n] + ((high[n] == H[n]) ? 0 : H[n] - high[n]) << endl;
    
    return 0;
}


Measured memory_bytes: 35788
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A + B < C + D){
    cout << "Right" << endl;
  }
  else if (A + B == C + D){
    cout << "Balanced" << endl;
  }
  else { 
    cout << "Left" << endl;
  }
}


Measured memory_bytes: 256
n = gets.to_i
nums = gets.split.map(&:to_i).sort.reverse
sum_a = 0
sum_b = 0

(1..n).each do |i|
  if (i%2).zero?
    sum_b += nums[i-1]
  else
    sum_a += nums[i-1]
  end
end

puts sum_a - sum_b

Measured memory_bytes: 1788
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> dat(h);

    REP(i, h){
        cin >> dat[i];
    }

    int black = 0;
    REP(i, h)
        REP(j, w)
            if(dat[i][j] == '#') black++;


    int ans = 0;
    IFOR(y, 0, (1<<h)-1){
        IFOR(x, 0, (1<<w)-1){
            int cum = 0;
            vector<vector<bool>> nutta(h, vector<bool>(w, false));
            REP(i, h){
                if((y>>i)&1){
                    REP(k, w){
                        if(nutta[i][k]) continue;
                        nutta[i][k] = true;
                        if(dat[i][k] == '#')
                            cum++;
                    }
                }
            }
            REP(j, w){
                if((x>>j)&1){
                    REP(k, h){
                        if(nutta[k][j])
                            continue;
                        nutta[k][j] = true;
                        if(dat[k][j] == '#') cum++;
                    }
                }

            }
            if(black - cum == k)
                ans++;
        }
    }

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

Measured memory_bytes: 3184
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

const int INF = 1 << 30;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> grid(H);
    for (auto& g : grid) {
        cin >> g;
    }
    int ans = INF;
    rep(mask, 0, 1 << (H - 1)) {
        vector<vector<int>> group(H, vector<int>(W, -1));
        int now_group = 0;
        rep(i, 0, H - 1) {
            rep(j, 0, W) {
                group[i][j] = now_group;
            }
            if ((mask >> i) & 1) {
                ++now_group;
            }
        }
        rep(j, 0, W) {
            group[H - 1][j] = now_group;
        }
        ++now_group;
        vector<int> cnt(now_group, 0);
        bool is_ok = true;
        rep(i, 0, H) {
            if (grid[i][0] == '0') {
                continue;
            }
            ++cnt[group[i][0]];
            if (cnt[group[i][0]] > K) {
                is_ok = false;
                break;
            }
        }
        if (!is_ok) {
            continue;
        }
        int now_ans = __builtin_popcount(mask);
        is_ok = true;
        rep(i, 1, W) {
            vector<int> now_cnt(now_group, 0);
            rep(j, 0, H) {
                if (grid[j][i] == '0') {
                    continue;
                }
                ++now_cnt[group[j][i]];
            }
            bool over = false;
            rep(j, 0, now_group) {
                if (cnt[j] + now_cnt[j] > K) {
                    over = true;
                    break;
                }
            }
            if (over) {
                ++now_ans;
                cnt = now_cnt;
                rep(j, 0, now_group) {
                    if (now_cnt[j] > K) {
                        is_ok = false;
                        break;
                    }
                }
            } else {
                rep(j, 0, now_group) {
                    cnt[j] += now_cnt[j];
                    now_cnt[j] = 0;
                }
            }
        }
        if (is_ok) {
            chmin(ans, now_ans);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

Vec pn;

bool isPrime(ll n){
	if(n == 1) return false;
	for(ll i : pn){
		if(i * i > n) return true;
		if(n % i == 0) return false;
	}
	return true;
}

void init(ll n = 2e5){
	pn.pb(2);
	REP(num, 3, n) if(isPrime(num)) pn.pb(num);
}

VecP primeFactorization(ll n){
	VecP res;

	for(ll i : pn){
		ll cnt = 0;
		while(n % i == 0){
			n /= i;
			cnt++;
		}
		if(cnt) res.pb({i, cnt});
		if(n < i * i) break;
	}
	if(n != 1) res.pb({n, 1});

	return res;
}

Vec divisorEnumeration(ll n){
	auto v = primeFactorization(n);

	Vec res, a, b, cp;
	res.pb(1);
	for(auto p : v){
		cp.resize(res.size());
		copy(all(res), cp.begin());
		a.resize(res.size());
		repn(k, p.sc){
			ll t = pow(p.fs, k);
			rep(i, a.size()) a[i] = cp[i] * t;
			res.insert(res.end(), all(a));
		}
	}

	sort(all(res));
	return res;
}

int main(void){
	init();
	ll n;
	cin >> n;
	Vec a(n);
	rep(i, n) cin >> a[i];

	unordered_multiset<ll> st;
	rep(i, n) st.insert(a[i]);

	ll ans = 0;
	rep(i, n){
		st.erase(st.find(a[i]));
		auto v = divisorEnumeration(a[i]);
		bool flg = true;
		for (ll j : v){
			if(st.find(j) != st.end()){
				flg = false;
				break;
			}
		}
		if (flg) ans++;
		st.insert(a[i]);
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 13732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n, a;
    cin >> n >> a;
    n -= n/500*500;
    if(n > a) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
/*  Bismillahir Rahmanir Rahim  */
 
#include <bits/stdc++.h>
 
using namespace std;
 
bool ask(long long val){
	cout << "? " << val << endl;
	char c;
	cin >> c;
	if(c == 'Y') return 1;
	else return 0;
}
 
int main(){
	long long n = 1e9;
	if(ask(n)){
		long long cur = 0;
		long long ans = 1;
		while(1){
			cur = (cur * 10) + 9;
			if(ask(cur)){
				cout << "! " << ans << endl;
				return 0;
			}
			ans = (ans * 10);
		}
	}
	long long lo = 1;
	long long hi = 9;
	for(long long i = 1; i <= 9; ++i){
		lo *= 10;
		hi *= 10;
		hi += 9;
		if(ask(lo) == false) break;
	}
	long long ret = -1;
	while(lo <= hi){
		long long mid = (lo + hi) / 2;
		if(ask(mid)) ret = mid, hi = mid - 1;
		else lo = mid + 1;
	}
	cout << "! " << ret / 10LL << endl;
	return 0;
}

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

typedef long long ll;
using namespace std;

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

	ll n; cin >> n;
    vector<ll> a(n);

	for (ll i = 0;i < n;i++){
		cin >> a[i];
	}	

	sort(a.begin(),a.end());

	ll ans = 0;

	vector<ll> tmp(n);
	tmp[0] = a[n-1];
	for (ll i = 1;i < n-1;i++){
		if(i%2 == 0){
			tmp[i] = a[n-1-i/2];
			ans += abs(tmp[i] - tmp[i-1]);
		}else{
			tmp[i] = a[(i+1)/2 - 1];
			ans += abs(tmp[i] - tmp[i-1]);
		}
		//cout <<  ans <<  endl;
	}

	//ans += abs(tmp[0]-a[(n-2)/2]);
	
	ll s = abs(tmp[0] - a[(n-1)/2]);
	ll t = abs(tmp[n-2] - a[(n-1)/2]);
	if(s > t) ans += s;
	else ans += t;

	ll ans2 = 0;
	reverse(a.begin(),a.end());
	tmp[0] = a[n-1];
	for (ll i = 1;i < n-1;i++){
		if(i%2 == 0){
			tmp[i] = a[n-1-i/2];
			ans2 += abs(tmp[i] - tmp[i-1]);
		}else{
			tmp[i] = a[(i+1)/2 - 1];
			ans2 += abs(tmp[i] - tmp[i-1]);
		}
		//cout <<  ans <<  endl;
	}

	//ans += abs(tmp[0]-a[(n-2)/2]);
	
	s = abs(tmp[0] - a[(n-1)/2]);
	t = abs(tmp[n-2] - a[(n-1)/2]);
	if(s > t) ans2 += s;
	else ans2 += t;

	cout << max(ans,ans2) << endl;

	return 0;

}


Measured memory_bytes: 1792
import sys
input = sys.stdin.readline
from collections import deque

K = int(input())

D = [-1]*K

q = deque()
q.append(1)
D[1] = 1
while q:
    p = q.pop()
    n1 = (p*10)%K
    if D[n1] == -1 or D[n1] > D[p]:
        D[n1] = D[p]
        q.append(n1)
    n2 = (p+1)%K
    if D[n2] == -1:
        D[n2] = D[p] + 1
        q.appendleft(n2)
print(D[0])

Measured memory_bytes: 6004
s = input()
le = len(s)
list_a = []
list_z = []
dif = 0
for i in range(le):
	if s[i] == 'A':
		list_a.append(i)
	elif s[i] == 'Z':
		list_z.append(i)
print(int(list_z[-1])-int(list_a[0])+1)

Measured memory_bytes: 11172
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N = lread();
    auto A = aryread();
    auto ans = new long[](N);
    foreach (i; 0 .. N)
    {
        if (i & 1)
        {
            ans[0] -= A[i];
        }
        else
        {
            ans[0] += A[i];
        }
    }

    foreach (i; 1 .. N)
        ans[i] = 2 * A[i - 1] - ans[i - 1];

    ans.map!text().join(' ').writeln();

}


Measured memory_bytes: 9800
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
#define int long long;
bool is_prime(long long n);
using namespace std;
signed main()
{
    long long X, p;
    cin >> X;
    p = X;
    while (!is_prime(p))
        p++;
    cout << p << endl;
    return 0;
}
bool is_prime(long long x)
{
    if(x<=1)
        return false;
    for(long long i=2;i*i<=x;i++)
        if(x%i==0)
            return false;
    return true;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons;

immutable int inf = 10^^9 + 7;
int N, W;
int[] v, w;

void main() {
    scan(N, W);

    int vi, wi;
    auto v = new int[](N);
    auto w = new int[](N);

    foreach (i ; 0 .. N) {
        scan(vi, wi);
        v[i] = vi;
        w[i] = wi;
    }

    auto dp = new int[](N * 100 + 1);
    dp[] = inf;
    dp[0] = 0;

    foreach (i ; 0 .. N) {
        foreach_reverse (j ; v[i] .. N * 100 + 1) {
            dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
        }
    }

    foreach_reverse (j ; 0 .. N * 100 + 1) {
        if (dp[j] <= W) {
            writeln(j);
            return;
        }
    }
}


void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg ; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

Measured memory_bytes: 2420
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
#t = [int(input()) for _ in range(d)]

TYPES = 26
history = [-1] * TYPES
satisfaction_level = [0] * (d+1)

def last(day, i, local_history):
    if local_history[i] == -1:
        return 0
    else:
        return local_history[i]

def satisfaction(day, typ):
    # コンテスト実施記録を更新
    local_history = list(history)
    local_history[typ] = day
    # 満足度の減少
    decrease = sum((c[i]*(day-last(day,i,local_history)) for i in range(TYPES)))
    value = s[day-1][typ] - decrease + satisfaction_level[day-1]
    return value

#for day, typ in enumerate(t):
#    print(satisfaction(day+1, typ-1))

for day in range(1, d+1):
    # 貪欲法
    greedy = max([(i+1, satisfaction(day, i)) for i in range(TYPES)], key=lambda x: x[1])
    history[greedy[0]-1] = day
    satisfaction_level[day] = greedy[1]
    print(greedy[0])


Measured memory_bytes: 9456
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <functional>
#define MOD 1000000007

int i,j;

struct edge {
    int to;
    int cost;
};

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

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
    return a.second > b.second;
}

int main(void) {
    int n,m;
    cin >> n >> m;
    vector<ll> a;
    for(i=0;i<n;i++){
        ll tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    sort(a.begin(),a.end());
    vector<pair<ll,ll>> pp;
    for(i=0;i<m;i++){
        int tb,tc;
        cin >> tb >> tc;
        pp.push_back(make_pair(tb,tc));
    }
    sort(pp.begin(),pp.end(),compare_by_b);
    
    vector<pair<ll,ll>> ppp;
    int num=0;
    for(i=0;i<m;i++){
        ppp.push_back(pp[i]);
        num += pp[i].first;
        if(num>n){
            break;
        }
        
    }
    
    for(i=0;i<ppp.size();i++){
        for(j=0;j<ppp[i].first;j++){
            a.push_back(ppp[i].second);
        }
    }
    
    sort(a.begin(),a.end(),greater<ll>());
    ll ans=0;
    for(i=0;i<n;i++){
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7020
#include <iostream>
using namespace std;
int main(int argc, const char * argv[])
{
    int d,n,ans=1;
    cin>>d>>n;
    for(int i=0;i<d;i++)
        ans*=100;
    ans=(n+(n-1)/99)*ans;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <utility>
using namespace std;

int A, B, C, D;

int main(){
	cin >> A >> B >> C >> D;
	
	if(A+B > C+D){
		cout << "Left" << endl;
	} else if(A+B < C + D){
		cout << "Right" << endl;
	} else if(A+B == C+D){
		cout << "Balanced" << endl;
	}

}



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

using Int = int;
using namespace std;

#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; };
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; };
template<class T> T th(T &a, const T &b, T (*f)(const T &, const T &)){ a = f(a, b); }
#define anth(a, b) th(a, b, ant)
#define onth(a, b) th(a, b, ont)

int main(){
	int n, m, k;
	cin >> n >> m >> k;
	std::vector<std::pair<int, int>> uf(n);
	std::vector<int> count(n);
	RC(i, n) uf[i].first = i;
	RC(i, n) uf[i].second = 1;
	RC(i, n) count[i] = -1;
	RC(i, m){
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		--count[a];
		--count[b];
		while(uf[a].first != uf[uf[a].first].first) uf[a].first = uf[uf[a].first].first;
		while(uf[b].first != uf[uf[b].first].first) uf[b].first = uf[uf[b].first].first;
		if(uf[a].first != uf[b].first){
			uf[uf[a].first].second += uf[uf[b].first].second;
			uf[uf[b].first].first = uf[a].first;
		}
	}
	RC(i, k){
		int c, d;
		cin >> c >> d;
		--c;
		--d;
		while(uf[c].first != uf[uf[c].first].first) uf[c].first = uf[uf[c].first].first;
		while(uf[d].first != uf[uf[d].first].first) uf[d].first = uf[uf[d].first].first;
		if(uf[c].first == uf[d].first){
			--count[c];
			--count[d];
		}
	}

	RC(i, n){
		int a = i;
		while(uf[a].first != uf[uf[a].first].first) uf[a].first = uf[uf[a].first].first;
		cout << count[i] + uf[uf[a].first].second << " \n"[i == n - 1];
	}
}


Measured memory_bytes: 2048
def dfs(s, N):
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        ret += dfs(s + c, N)
    return ret

def main():
    N = int(input())
    print(dfs('0', N))

main()


Measured memory_bytes: 3060
import itertools
import collections

n = int(input().split()[0])
s_list = []

for _ in range(n):
    s = input().split()[0]
    s_list.append(s)

target_list = [s[0] for s in s_list if s[0] in list('MARCH')]
counter = collections.Counter(target_list)
c = 0

if len(set(target_list)) < 3:
    ans = 0
else:
    p_list = itertools.combinations(set(target_list), 3)

    for p in p_list:
        c += counter[p[0]] * counter[p[1]] * counter[p[2]]
    ans = c
print(c)


Measured memory_bytes: 10880
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

#define rep(i, n) for(int i=0;i<n;i++)

using namespace std;
int main() {
	string s;
	cin >> s;

	if (s[0] == '9' || s[1] == '9')
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256