akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int n, m, q;
int func(vector<tuple<int, int, int, int>> &data, vector<int> &num, int res )
{
	int ans=0;
	if(num.size()==n){
		//check;
	//	rep(i,n){
	//		clog<<num[i]<<" ";
	//	}
		
		rep(i,q){
			if(num[get<1>(data[i])]-num[get<0>(data[i])]==get<2>(data[i])){
				ans+=get<3>(data[i]);
			}
		}
	//	clog <<" --> " <<ans<<endl;
	}else if(num.size()==0){
		for(int i=1;i<=m;i++){
			num.push_back(i);
			chmax(ans,func(data,num,ans));
			num.pop_back();
		}
	}else{
		for(int i=num.back();i<=m;i++){
			num.push_back(i);
			chmax(ans,func(data,num,ans));
			num.pop_back();
		}
	}
	return ans;

}
int main(){
	
	int ans=0;
	cin >>n>>m>>q;
	vector<tuple<int,int,int,int>>data(q);
	int a,b,c,d;
	rep(i,q){
		cin>>a>>b>>c>>d;
		a--;
		b--;
		data[i]=make_tuple(a,b,c,d);
	}
//	sort(all(data));
	vector<int>num;
	ans=func(data,num,0);
	cout<<ans<<endl;
}

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

using namespace std;

using ll = int_fast64_t;
constexpr ll llmax = INT_FAST64_MAX; // std::numeric_limits<int_fast64_t>::max()
constexpr ll llmin = INT_FAST64_MIN; // std::numeric_limits<int_fast64_t>::min()
using ull = uint_fast64_t;
constexpr ull ullmax = UINT_FAST64_MAX; // std::numeric_limits<uint_fast64_t>::max()

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define RFOR(i, b, e) for (int i = ((e) - 1); (b) <= i; --i)
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define RREP(i, N) for (int i = ((N) - 1); 0 <= i; --i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(N);
    scanInt(K);
    string S;
    cin >> S;
    S[K - 1] = tolower(S[K - 1]);
    cout << S << endl;
}


Measured memory_bytes: 256
from collections import defaultdict
mod = 998244353
N = int(input())
S = input()
colors = ['R', 'G', 'B']
invs = {'R':'GB', 'G':'BR', 'B':'RG'}
cnt = defaultdict(int)
ans = 1
for i in range(N*3):
    s = S[i]
    inv = invs[s]
    if cnt[inv] != 0:
        ans *= cnt[inv]
        ans%=mod
        cnt[inv]-=1
        continue
    flag = False
    for c in colors:
        if c == s:
            continue
        if cnt[c]:
            ans*=cnt[c]
            ans%=mod
            cnt[c]-=1
            cnt[c+s]+=1
            cnt[s+c]+=1
            flag = True
    if not flag:
        cnt[s]+=1
    ans%=mod
for i in range(1, N+1):
    ans*=i
    ans%=mod
print(ans)

    

Measured memory_bytes: 45184
#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字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    ll N; cin >> N;
    cout << 180*(N-2) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++) 
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "
int main(int argc, const char *argv[]){
    int h, w;
    cin >> h >> w;
    vector<vector<int>> dp(h,vector<int>(w,0)), hv(h,vector<int>(w,0)), wv(h,vector<int>(w,0));
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    rep(i,h){
        int start = 0;
        rep(j,w+1){
            if((j==w)||(s[i][j] == '#')){
                for(int k=start;k<j;k++){
                    hv[i][k] = j-start;
                }
                start = j+1;
            }
        }
    }


    rep(i,w){
        int start = 0;
        rep(j,h+1){
            if((j==h) || (s[j][i] == '#') ){
                for(int k=start;k<j;k++){
                    wv[k][i] = j-start;
                }
                start = j+1;
            }
        }
    }
    int ans=0;
    rep(i,h){
        rep(j,w){
            if(s[i][j] == '.'){
                ans = max(ans,hv[i][j]+wv[i][j]-1);
            }
        }
    }
    co(ans);
    return 0;
}

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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

// 降順ソート vector<int> v;
// sort(v.begin(),v.end(),greater<int>());

signed main() {
  int64_t x = 100;
  cin >> x;

  if(x==0) 
    cout << "1" << endl;
  else
    cout << "0" << endl;

  return 0;
}



Measured memory_bytes: 3680
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include<bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;

#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define ins insert
#define pi  3.14159265359
#define mod 1000000007
#define si(x) int(x.size())
#define FOOR(i, a, b)  for (int i=a; i<=(b); i++)
#define FOR(i, a)  for (int i=0; i<(a); i++)
#define FOORd(i,a,b)  for (int i = (b)-1; i >= a; i--)
#define FORd(i,a)  for (int i = (a)-1; i >= 0; i--)

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    vector<ll>x;
    vector<ll>y;
    ll s1,s2;
    if(a<0)s1=-1;
    else s1=1;
    if(b<0)s2=-1;
    else s2=1;
    if(s1==s2){
        x.push_back(a);
        x.push_back(b);
    }else{

     x.push_back(a);
        x.push_back(b);
    x.push_back(0);
    }
    if(c<0)s1=-1;
    else s1=1;
    if(d<0)s2=-1;
    else s2=1;
    if(s1==s2){
        y.push_back(c);
        y.push_back(d);
    }else{

        y.push_back(c);
        y.push_back(d);
      y.push_back(0);
    }
    ll maxx=LONG_MIN;
    for(int i=0;i<x.size();i++)
    {
        for(int j=0;j<y.size();j++)
        {
            maxx=max(maxx,x[i]*y[j]);
        }
    }

    cout<<maxx<<endl;


}



















Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0;i<n;i++)
#define rev(i, n) for(ll i=n-1;i>=0;i--)
#define forr(i, x, y) for(ll i=x;i<y;i++)
#define f first
#define s second
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vpii vector<pair<int,int>>

int main()
{
    ll n;
    cin>>n; 
    ll arr[n][3];
    rep(i,n){
        rep(j,3){
            cin>>arr[i][j];
        }
    }
    ll dp[n+1][3];
    rep(i,n+1){
        rep(j,3){
            dp[i][j]=0;
        }
    }
    

    for(int i=1;i<=n;i++){
       for(int j=0;j<3;j++){
           dp[i][j]=arr[i-1][j]+max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]);
       }
    }
    ll ans=max(dp[n][0],max(dp[n][1],dp[n][2]));
    cout<<ans<<endl;

}

Measured memory_bytes: 4992
module Main where

--import Utils 
import Control.Applicative

getInt :: IO Int
getInt = head <$> getInts

getInts :: IO [Int]
getInts = map read . words <$> getLine

main :: IO ()
main = do
  { [a , b] <- getInts
  ;putStrLn (unwords(map show [a * b , 2 * (a + b ) ])) 
  }


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

int main()
{
    int n;
    cin >> n;
    vector<int> b(n - 1);
    rep(i, n - 1) cin >> b[i];
    int ans = 0;
    rep(i, n - 2) ans += min(b[i], b[i + 1]);
    ans += b[0];
    ans += b[n - 2];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <iomanip>
#include <numeric>


using namespace std;

typedef long long LL;
typedef unsigned int UI;

#define rSort(a) 		sort(a.rbegin(),a.rend())
#define Sort(a) 		sort(a.begin(),a.end())
#define Reverse(a) 		reverse(a.begin(),a.end())
#define Sum(a)  		accumulate(a.begin(), a.end(), 0)
#define REP(i, n) 		for(UI i = 0;i < n;i++)
#define REPR(i, n) 		for(UI i = n;i >= 0;i--)
#define FOR(i, m, n) 	for(UI i = m;i < n;i++)

static const LL MOD = 1e9 + 7;
static const LL INF = (LL)1 << 62;

LL N, K, s[60], dp[60][2];

int main(int argc, const char * argv[]) {

	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> K;
	REP(i, N) {
		LL a; cin >> a;
		REP(j, 50) if (a & (1ll << j))s[j]++;
	}
	reverse(s, s + 50);
	REP(i, 50) {
		if (K & (1ll << (50 - i - 1))) {
			dp[i + 1][0] = dp[i][0] * 2 + N - s[i];
			dp[i + 1][1] = dp[i][0] * 2 + s[i];
		}
		else dp[i + 1][0] = dp[i][0] * 2 + s[i];
		if(dp[i][1] > 0)dp[i + 1][1] = max(dp[i + 1][1], dp[i][1] * 2 + max(N - s[i], s[i]));
	}
	cout << max(dp[50][0], dp[50][1]) << endl;

	return 0;

}



Measured memory_bytes: 256
n,d=map(int,input().split())
w=[]
for i in range(n):
    l=[int(i) for i in input().split()]
    w.append(l)
ans=0
chk=set([int(i)**2 for i in range(0,401,1)])
for i in range(n-1):
    for j in range(i+1,n):
        cnt=0
        for k in range(d):
            cnt+=(w[i][k]-w[j][k])**2
        if cnt in chk:
            ans+=1
print(ans)

Measured memory_bytes: 38384
use proconio::input;
use std::collections::BTreeMap;
use superslice::*;

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    };
    // j - i = a[i] + a[j] (i < j) が条件より i + a[i] = j - a[j] (i < j)
    let mut l = vec![0_i64; n];
    let mut r = vec![0_i64; n];
    for (i, &a_i) in a.iter().enumerate() {
        l[i] = i as i64 + a_i;
        r[i] = i as i64 - a_i;
    }
    // l[i] = r[j] (i < j) となる (i, j) の個数
    let mut ml: BTreeMap<i64, Vec<usize>> = BTreeMap::new();
    let mut mr: BTreeMap<i64, Vec<usize>> = BTreeMap::new();
    for (i, (&l_i, &r_i)) in l.iter().zip(r.iter()).enumerate() {
        ml.entry(l_i).and_modify(|e| e.push(i)).or_insert(vec![i]);
        mr.entry(r_i).and_modify(|e| e.push(i)).or_insert(vec![i]);
    }
    let ans = ml
        .iter()
        .map(|(x, li)| {
            li.iter()
                .map(|&i| {
                    mr.get(&x)
                        .map(|lj| lj.len() - lj.upper_bound(&i))
                        .unwrap_or(0)
                })
                .sum::<usize>()
        })
        .sum::<usize>();
    println!("{}", ans);
}


Measured memory_bytes: 39400
/*input 
a
aa


*/


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

 
 
#define int long long int
#define rep(i,n) \
    for(int i = 0; i < n; i++)
#define rep2(i, a, b) \
    for(int i = a; i < b; i++)
#define all(c) \
    c.begin(), c.end()
#define init(arr, num) \
    memset(arr, num, sizeof(arr))

#define fast\
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inputFile \
    freopen("input.txt", "r", stdin); 
#define outputFile \
    freopen("output.txt", "w", stdout);
#define modM 1000000007
#define PI 3.1415926535897932
#define F first
#define S second  
#define pb push_back  
 
#ifdef gaviria
#define TRACE
#endif
#ifdef TRACE
#define trace(...) _f(#VA_ARGS, __VA_ARGS_)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
 
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int, int > ii;
typedef unordered_set<int> usi;
 
ll n,i,j,k,m, c=0;
int a[20][20];
stack <int> sol;

void solve() 
{ 
 string a;
 string b;

 cin>>a>>b;

if(b.size()==a.size()+1&&b.substr(0,a.size())==a)
cout<<"Yes";
else cout<<"No";
   
} 
 
 
 
 
signed main()
{
 
    // inputFile;
    fast;
    int T = 1;
//cin >> T;
int h=T;
    while(T--){
//cout<<"Case #"<<(h-T)<<": ";
        solve();
cout<<endl;
     
        
        
 
    }
    
    
    return 0;
 
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

#define inCI(v, l, r) ((l) <  (v) && (v) <= (r))
#define inCD(v, l, r) ((l) <  (v) && (v) <  (r))

LL n, m, dp[303][303][303], MOD = 1e9 + 7;

int main() {
	cin >> n >> m;
	n += 2;
	vector<vector<int>> ma(n + 1, vector<int>(4, -1));
	vector<vector<int>> mi(n + 1, vector<int>(4, n + 1));
	inc(i, m) {
		int l, r, x;
		cin >> l >> r >> x;
		l += 2;
		r += 2;
		l--;
		setmax(ma[r][x], l);
		setmin(mi[r][x], l);
	}
	
	dp[2][1][0] = 1;
	inc(i, n) {
	inc(j, i) {
	inc(k, j) {
		int c = ma[i + 1][3];
		int d = mi[i + 1][2];
		int a = ma[i + 1][2];
		int b = mi[i + 1][1];
		if(inCI(j, a, b) && inCI(k, c, d)) { (dp[i + 1][j][k] += dp[i][j][k]) %= MOD; }
		if(inCI(i, a, b) && inCI(k, c, d)) { (dp[i + 1][i][k] += dp[i][j][k]) %= MOD; }
		if(inCI(i, a, b) && inCI(j, c, d)) { (dp[i + 1][i][j] += dp[i][j][k]) %= MOD; }
	}
	}
	}
	
	LL ans = 0;
	inc(j, n) {
	inc(k, j) {
		(ans += dp[n][j][k]) %= MOD;
	}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 215552
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		int[] table = new int[17];
		for (int i = 1; i <= table.length; i++) table[i - 1] = i * i;
		int M = 300;
		int[] dp = new int[M];
		dp[0] = 1;
		for (int i = 0; i < table.length; i++) {
			for (int j = 0; j < M; j++) {
				if (j + table[i] < M) dp[j + table[i]] += dp[j];
			}
		}
		for (;;) {
			int n = sc.nextInt();
			if (n == 0) return;
			System.out.println(dp[n]);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 25908
# ITP1_11_A: Dice 1

class Dice
    def initialize(labels)
      pips  = [:top, :front, :right, :left, :back, :bottom]
      @pips = Hash[ *pips.zip(labels).flatten ]
    end

    def roll_to(direction)
      rotate case direction
      when 'N'
        {
          :top    => :back,
          :back   => :bottom,
          :bottom => :front,
          :front  => :top
        }
      when 'S'
        {
          :top    => :front,
          :front  => :bottom,
          :bottom => :back,
          :back   => :top
        }
      when 'E'
        {
          :top    => :right,
          :right  => :bottom,
          :bottom => :left,
          :left   => :top
        }
      when 'W'
        {
          :top    => :left,
          :left   => :bottom,
          :bottom => :right,
          :right  => :top
        }
      end
    end

    def pip_of(side)
      @pips[side]
    end

  private
    # This assumes that the +dests+ are ordered properly.
    def rotate(dests)
      top = @pips[:top]
      dests.keys.reverse_each do |src|
        @pips[ dests[src] ] = @pips[src]
      end
      @pips[ dests[:top] ] = top
      self
    end
end

labels = gets.chomp.split.map &:to_i
directions = gets.chomp.split('')

dice = Dice.new labels
directions.each do |direction|
  dice.roll_to direction
end

puts dice.pip_of(:top)

Measured memory_bytes: 8728
# F - Three Variables Game

N, A, B, C = map(int, input().split())
S = [''] * N
for i in range(N):
    S[i] = input()

ansArr = []
ans = 'Yes'
for i in range(N):
    s = S[i]
    if s=='AB':
        if A==1 and B==1 and i<N-1:
            if S[i+1].count('A')==1:
                A += 1
                B -= 1
                ansArr.append('A')
            else:
                A -= 1
                B += 1
                ansArr.append('B')               
        elif A <= B:
            A += 1
            B -= 1
            if B < 0:
                ans = 'No'
                break
            ansArr.append('A')
        else:
            A -= 1
            B += 1
            ansArr.append('B')
    elif s =='AC':
        if A==1 and C==1 and i<N-1:
            if S[i+1].count('A')==1:
                A += 1
                C -= 1
                ansArr.append('A')
            else:
                A -= 1
                C += 1
                ansArr.append('C')   
        elif A <= C:
            A += 1
            C -= 1
            if C < 0:
                ans = 'No'
                break
            ansArr.append('A')
        else:
            A -= 1
            C += 1
            ansArr.append('C')
    else:
        if B==1 and C==1 and i<N-1:
            if S[i+1].count('B')==1:
                B += 1
                C -= 1
                ansArr.append('B')
            else:
                B -= 1
                C += 1
                ansArr.append('C')  
        elif B <= C:
            B += 1
            C -= 1
            if C < 0:
                ans = 'No'
                break
            ansArr.append('B')
        else:
            B -= 1
            C += 1
            ansArr.append('C')

print(ans)
if ans=='Yes':
    for a in ansArr:
        print(a)


Measured memory_bytes: 16988
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vs){
  for (const T& v : vs) os << v << " ";
  return os;
}

int main() {
  int N; cin >> N;
  string S; cin >> S;

  vector<bool> flags(S.size());
  flags[0] = false;
  char prev = S[0];
  bool last = false;
  int L = 0, R = 0;
  for (int i = 1; i < S.size(); ++i) {
    if (S[i] == prev) {
      last = !last;
    }
    flags[i] = last;
    prev = S[i];

    if (last) ++R;
    else      ++L;
  }

  if (S[0] == 'W' || S.back() == 'W') {
    cout << 0 << endl;
    return 0;
  }
  if (L + 1 != R) {
    cout << 0 << endl;
    return 0;
  }

  LL sum = 1;
  LL cnt = 0;
  for (bool flag : flags) {
    if (flag) {  // R
      sum = (sum * cnt) % kMod;
      --cnt;
    } else {  // L
      ++cnt;
    }
  }

  for (LL i = 1; i <= N; ++i) {
    sum = (sum * i) % kMod;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3724
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
vector<int>dp;
vector<vector<int> > chi;
int find(int i){
    int len = 0 ;
    if(dp[i]!=-1)return dp[i];
    for(auto x:chi[i]){
        len=max(len,find(x)+1);
    }
    dp[i]=len;
    return dp[i];
}
int main(){
    int n, m ;
    cin>>n>>m;
    chi.resize(n+1);
    dp.resize(n+1,-1);
    for(int i = 0 ; i < m ; i ++ ) {
        int a, b;
        cin>>a>>b;
        chi[a].push_back(b);
    }int ans=0;
    for(int i = 1 ; i <= n ; i++ ){
            dp[i]=find(i);
            ans=max(ans,dp[i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 11108
// E - Coprime
#include <bits/stdc++.h>
using namespace std;
#define rpd(i,s,e,d) for(int i=(s);i<(int)(e);i+=(d))

int sum_array(vector<int> &C, int start, int end, int step){
	int c = 0;
	rpd(i, start, end, step) c += C[i];
	return c;
}

int main(){
	int MAX_A = 1000000 + 1;
	int N; cin>>N;
	vector<int> C(MAX_A, 0);
	int g = 0;
	rpd(i, 0, N, 1){
		int a; cin>>a;
		C[a]++;
		g = gcd(g, a);
	}
	int t = 0;
	if(sum_array(C, 2, MAX_A, 2) > 1) t = 1;
	else
		rpd(i, 3, MAX_A, 2) if(sum_array(C, i, MAX_A, i) > 1){ t = 1; break; }
	if(t == 1 && g > 1) t = 2;
	cout<< vector<string>{"pairwise","setwise","not"}[t] <<" coprime\n";
}


Measured memory_bytes: 7180
// 解説を見た

#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>

using namespace std;
using ll = long long;
const ll INF = 1e9;

int main() {
    int N, M;
    vector<int> balls(N, 1);
    bool isred[N];
    cin >> N >> M;

    isred[0] = true;
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;

        if (isred[x]) isred[y] = true;
        balls[x]--;
        balls[y]++;
        if (balls[x] == 0) isred[x] = false;
    }

    int ans = 0;
    for (int i = 0; i < N; i++) if(isred[i]) ans++;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 16896
import java.util.*;

class Main{
    static int N = 100000;
    static int[] L = new int[N+1];
    static int[] R = new int[N+1];
    static int num;
    static int[] nums = new int[N+1];

    static int left(int i){
        if(L[i] != -1)return L[i];
        if(i == 0){
            L[i] = 0;
            return 0;
        }
        L[i] = gcd(nums[i-1], left(i-1));
        return L[i];
    }
    static int right(int i){
        if(R[i] != -1)return R[i];
        if(i == num-1){
            R[i] = 0;
            return 0;
        }
        R[i] = gcd(nums[i+1], right(i+1));
        return R[i];
    }
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        num = sc.nextInt();

        for(int i = 0; i < num; i++){
            nums[i] = sc.nextInt();
        }

        for(int i = 0; i <= num; i++){
            L[i] = -1;
            R[i] = -1;
        }

        int ans = 0;
        for(int i = 0; i < num; i++){
            //i番目以外の公約数
            int gcd = gcd(left(i),right(i));
            if(gcd > ans)ans = gcd;
        }

        System.out.println(ans);

    }

    static int gcd(int a, int b){
        if(b == 0)return a;
        if(a == 0)return b;
        return gcd(b, a % b);
    }
}

Measured memory_bytes: 75268
//start of jonathanirvings' template v3.0.3 (BETA)

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

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

int n;
int a[105];

int main()
{
  scanf("%d",&n);
  REP(i,n) scanf("%d",&a[i]);
  int risan = 1;
  REP(i,n) risan *= 3;
  int ganjil = 1;
  REP(i,n)
  {
    if (a[i] % 2 == 0) ganjil *= 2;
  }
  printf("%d\n",risan - ganjil);
  return 0;
}










Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iterator>
using namespace std ;
long long int power(long long int x,long long int y) ;
long long int power(long long int x,long long int y)
{ if(y==0)
   return 1 ;
   long long int z=power(x,y/2) ;
   if(y%2==0)
   return z*z ;
   else return x*z*z ; }


int main()
 { long long int t,n,m,count,i,j,x,a,b,sum,bal,e,o,y,k,z,temp,q,c,d,x1,x2,y1,y2 ;
    cin>>x>>y>>z ;
    cout<<z<<" "<<x<<" "<<y ;
    return 0 ; }


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

int main() {
   int a;
   string s;
   cin >> a >> s;
   if(a >= 3200){
       cout << s;
   }else{
       cout << "red";
   }
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    ll a[100010], b[100010];
    cin >> N >> K;
    vector< pair<ll, ll> > pairs(N);

    rep(i,0,N){
        cin >> a[i] >> b[i];
    }
    rep(i,0,N){
        pairs[i] = make_pair(a[i], b[i]);
    }
    sort(pairs.begin(), pairs.end());
    ll cnt = 0;
    rep(i,0,N){
        cnt += pairs[i].second;
        if(cnt >= K){
            print(pairs[i].first);
            return 0;
        }
    }

}


Measured memory_bytes: 3456
#include<iostream>

using namespace std;

int serch(int A[],int n,int key){
	int i = 0;
	A[n] = key;
	while(A[i]!=key)i++;
	return i!=n;
}
int main(){
	int i,n,A[10000+1],q,key,sum=0;
	
	cin >> n;
	
	for(int i=0; i<n; i++)cin >> A[i];
	
	cin >> q;
	for(int i=0; i<q; i++){
		cin >> key;
		if(serch(A,n,key))sum++;
	}
	cout << sum << endl;
	
	return 0;
}


Measured memory_bytes: 3140
from collections import defaultdict
s = input()
t = input()
dic = defaultdict(lambda : None)
revdic = defaultdict(lambda : None)
for x, y in zip(s, t):
    if dic[x] == None and revdic[y] == None:
        dic[x] = y
        revdic[y] = x
    elif dic[x] != y or revdic[y] != x:
        print('No')
        quit()
print('Yes')


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

const int maxn = 100 * 1000 + 10;
int n, sz[maxn];
vector <int> adj[maxn];
bool ans;

void dfs(int v, int papa) {
    if (ans)
        return;
    sz[v] = 1;
    int o = 0, tmp = 0;
    bool f = 1;
    for (int u: adj[v])
        if (u != papa) {
            dfs(u, v);
            sz[v] += sz[u];
            o += (sz[u] % 2);
        }
    if (o > 1)
        ans = 1;
}

int main() {
    cin >> n;
    for (int i = 0, a, b; i < n - 1; i++) {
        cin >> a >> b;
        adj[--a].push_back(--b);
        adj[b].push_back(a);
    }
    dfs(0, -1);
    cout << (((n % 2) || ans)? "First\n": "Second\n");
    return 0;
}

Measured memory_bytes: 9536
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import bisect
import sys
import logging
import heapq
logging.basicConfig(level=logging.DEBUG)

input = sys.stdin.readline

setrecursionlimit(1000000)

MOD = 10**9+7

def main():
    A,B=[int(x) for x in input().split()]

    max_gcd=gcd([A,B])
    P=prime_factor(max_gcd)
    P2=set(P)
    print(len(P2)+1)

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass

def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            if i**2 == n:
                continue
            ass.append(n//i)
    return ass #sortされていない

def prime_factor(n):
    ass = []
    for i in range(2,int(n**0.5)+1):
        while n % i==0:
            ass.append(i)
            n = n//i
    if n != 1:
        ass.append(n)
    return ass

main()

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

int main() {
    int n, ans = 0;
    cin >> n;
    long long int a[n], b[n], sum_a = 0, sum_b = 0, sum_less = 0;
    vector<long long int> over;
    for(int i = 0; i < n; ++i) cin >> a[i], sum_a += a[i];
    for(int i = 0; i < n; ++i) {
        cin >> b[i];
        sum_b += b[i];
        if(a[i] < b[i]) ans++, sum_less += b[i] - a[i];
        else over.push_back(a[i] - b[i]);
    }
    if(sum_a < sum_b) {
        cout << -1 << '\n';
        return 0;
    }
    if(sum_less == 0) {
        cout << 0 << '\n';
        return 0;
    }
    sort(over.rbegin(), over.rend());
    for(int i = 0; i < over.size(); ++i) {
        sum_less -= over[i];
        ans++;
        if(sum_less < 0) break;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 2680
import java.util.Scanner;

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

		for(int i=0; i<s.length(); i++){
			if(s.charAt(i)=='p') p++;
		}

		int ans = s.length()/2 - p;

		System.out.println(ans);
	}
}

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

typedef long long ll;

int main(){
    int n;  cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    
    cout << a[n/2]-a[n/2-1] << endl;
    return 0;
}

Measured memory_bytes: 3716
import sys
input = sys.stdin.readline

N = int(input().strip())
H = [int(x) for x in input().strip().split()]

G = [0] * N
ans = 0
while H != G:
    ans += 1
    f = False
    for n in range(N):
        if f:
            if G[n] == H[n]:
                break
            else:
                G[n] += 1
        else:
            if G[n] != H[n]:
                G[n] += 1
                f = True
            else:
                continue

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
typedef long long int ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n, cur(0);
    cin >> n;
    rep(i, 1, n + 10)
    {
        cur = (cur * 10 + 7) % n;
        if (!cur)
            return cout << i, 0;
    }
    cout << -1;
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    string s;
    cin >> s;
    int n = s.size();

    if(n == 1) {
        cout << s[0] - '0' << endl;
        return 0;
    }

    ll ans = 0;
    for(int b = 0; b < (1 << (n-1)); b++) {
        ll cnt = s[0] - '0';
        for(int i = 0; i <= n-2; i++) {

            ll x = s[i+1] - '0'; 

            if(b & (1 << (i))) {
                ans += cnt;
                cnt = x;
            }
            else {
                cnt = 10*cnt + x; 
            }
        }
        ans += cnt;
    }

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

Measured memory_bytes: 256
import sys
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

D = []

miCount = 0
miSum = 0

P = []

if sum(A) < sum(B):
    print(-1)
    sys.exit(0)

for i in range(N):
    d = A[i] - B[i]
    D.append(d)
    if d < 0:
        miSum += d
        miCount += 1
    elif d > 0:
        P.append(d)


P.sort(reverse=True)
pCount = 0
for p in P:
    if miSum >= 0:
        break
    pCount += 1
    miSum += p

print(pCount + miCount)



Measured memory_bytes: 18356
#include <bits/stdc++.h>
using  namespace  std;
using ll=long long;
int main(){
  int n;
  cin>>n;
  vector<string> b(n);
  for(int i=0;i<n;i++)cin>>b.at(i);
  int m;
  cin>>m;
  vector<string> r(m);
  for(int i=0;i<m;i++)cin>>r.at(i);
  for(int i=0;i<m;i++){
    for(int j=0;j<b.size();j++){
      if(r.at(i)==b.at(j)){
     b.at(j)="00";
        break;
      }
    }
  }
int count=1,ans=0;
b.erase(remove(b.begin(),b.end(),"00"),b.end());
sort(b.begin(),b.end());
if(b.size()==1){
    cout<<1<<endl;
    return 0;
}
for(int i=1;i<b.size();i++){
    if(b.at(i-1)==b.at(i))count++;
   else count=1;
    ans=max(ans,count);
  }
cout<<ans<<endl;  
}


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

using namespace std;

using LL = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
using vll = vector<LL>;
using LD = long double;

#define ALL(v) v.begin(), v.end()
#define endl '\n'
#define SYNC ios_base::sync_with_stdio(false); cin.tie(NULL); cerr.tie(NULL);
#define REP(i , n) for(int i =0 ; i < n ;i++)
#define REPN(i , n) for(int i = 1; i <= n ; i++)
#define cot(x) cerr << #x << " " << x << " ";
#define cotd(x) cerr << #x << " " << x << endl;
#define her 	cerr << " here \n"; 
#define pp push_back
#define fi first 
#define se second
#define un(x) x.erase(unique(ALL(x)), x.end())

template<typename T > void check(T & a, const T & b) { if (a >= b) { a %= b; } }
template<typename T>T gcd(T u, T v) { if (u == v)return u; if (u == 0)return v; if (v == 0)return u; if (~u & 1) { if (v & 1) return gcd(u >> 1, v); else return gcd(u >> 1, v >> 1) << 1; }if (~v & 1)return gcd(u, v >> 1); if (u > v)return gcd((u - v) >> 1, v); return gcd((v - u) >> 1, u); }
LL mulmod(LL a, LL b, const LL & m) { LL q = (LL)(((LD)a*(LD)b) / (LD)m); LL r = a*b - q*m; if (r>m)r %= m; if (r<0)r += m; return r; }
template <typename T, typename S>T expo(T e, S n) { T x = 1, p = e; while (n) { if (n & 1)x = x*p; p = p*p; n >>= 1; }return x; }
template <typename T>T powerL(T e, T n, const T & m) { T x = 1, p = e; while (n) { if (n & 1)x = mulmod(x, p, m); p = mulmod(p, p, m); n >>= 1; }return x; }

const int N = (int)1e5 + 10; 
int n, m, col[N];
vector<vi> g; 

int dfs(int u , int & ans){
	int nodes = 1; 
	for(auto & v : g[u]){
		if(!col[v]){
			col[v] = -col[u]; 
			nodes += dfs(v, ans);
		}
		else if(col[v] == col[u])
			ans = false; 
	}
	return nodes; 
}

int main(){
	SYNC; 
	cin >> n >> m; 
	g.resize(n + 1);

	REP(i , m){
		int u , v; cin >> u >> v; 
		u--; v--; 
		g[u].pp(v); g[v].pp(u); 
	}

	LL ans = 0; int leaf = 0, x = 0, y = 0;

	for(int i = 0; i < n; i++){
		if(!col[i]){
			col[i] = 1;
			int bi = 1; 
			int no = dfs(i , bi); 
			if(no == 1)leaf++; 
			else if(bi)x++; 
			else y++; 
		}
	}

	ans = ( 2 * leaf * 1LL * n) - (leaf * 1LL * leaf); 
	ans += (2 * x * 1LL * x) + (2 * x * 1LL * y) + ( y * 1LL * y ); 	
	cout << ans << endl; 

	return 0; 
}

Measured memory_bytes: 9984
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n;
    cin >> n;
    vector<int> a(n+2);
    a[0] = 0, a[n+1] = 0;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    vector<int> dist(n+1);
    for(int i = 0; i <= n; ++i) dist[i] = abs(a[i+1] - a[i]);
    int sum = accumulate(dist.begin(), dist.end(), 0);
    for(int i = 1; i <= n; ++i){
        int res = sum - dist[i-1] - dist[i] + abs(a[i+1] - a[i-1]);
        cout << res << "\n";
    }
}

Measured memory_bytes: 2048
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  																						   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
																													   
const int INF = 1000000001;																						   
const float PI = 3.14;	
const int mod = 1e9+7;																							   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra																													   																				   list<int>::iterator it;																								   
																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS//////////////////////////////////////////////////////


///////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	int x;
	cin >> x;
	if(x == 7 || x == 5 || x == 3){
		cout << "YES" << endl;
	}
	else cout << "NO" << endl;
	
	
	

						
	return 0;
}


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

// TYPEDEF
// ----------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;
typedef queue<ll> qll;

// REPEAT
// ----------------------------------------
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++);
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl;

// UTIL
// ----------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())

// DEBUG
// ----------------------------------------
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

// BIT FLAG
// ----------------------------------------
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

// CONST
// ----------------------------------------
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI=3.14159265358979323846; // or M_PI
constexpr int MOD = 1000000007;


void Main() {
    ll n;
    cin >> n;

    COUT(n * (n - 1) / 2);
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}

/*

3 2
*/


Measured memory_bytes: 3624