akhauriyash/Code-Regression huggingface dataset:
use proconio::input;
use std::collections::VecDeque;

fn main() {
    input! {
        n: usize,
        aa: [usize; n],
    }

    let mut deque = VecDeque::new();

    for (i, a) in aa.into_iter().enumerate() {
        if i % 2 == 0 {
            deque.push_back(a);
        } else {
            deque.push_front(a);
        }
    }

    let ans = if n % 2 == 0 {
        deque.iter().map(|&x| x.to_string()).collect::<Vec<_>>().join(" ")
    } else {
        deque.iter().rev().map(|&x| x.to_string()).collect::<Vec<_>>().join(" ")
    };
    
    println!("{}", ans);
}


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


int main() {

    string x; 
    for (int i = 0; i < 3; ++i) {
        cin >> x;
        char w = x[0] - 'a' + 'A';
        cout << w;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
    int N, K, result = 0, tmp;
    cin >> N >> K;
    vector<int> d(K), a(N);
    REP(i, N) {
        a[i] = 0;
    }
    REP(i, K) {
        cin >> d[i];
        REP(j, d[i]) {
            cin >> tmp;
            a[tmp-1]++;
        }
    }
    REP(i, N) {
        if (a[i] == 0) {
            result++;
        }
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
// int main(){
//     int s;
//     cin >> s;

// }

int main(){
    int N , L;
    int total  = 0;
    cin >> N >> L;
    for (int i = 1; i <N+1;i++){
        
        total += L+i-1;
    }
    if (L>0){
        total -= L;
    }
    else if(L+N-1 < 0){
        total -= L+N-1;
    }
    cout << total << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
                     
int main()
{
    std::string t;
    std::cin>>t;
    int n = t.size();
    std::vector<char> a,b;
    if(n%2==1){
        t.erase(t.begin() + n/2);
        n--;
    }
    for(int i=0;i<n/2;i++){
        a.push_back(*(t.begin()+i));
        b.push_back(*(t.end() - (i+1)));
    }
    int cnt = 0;
    for(int i=0;i<n/2;i++){
        if(a[i]!=b[i])cnt++;
    }
    std::cout<<cnt<<std::endl;
    /*
    for(int i=0;i<n/2;i++){
        std::cout<<a[i]<<" "<<b[i]<<std::endl;
    }
    */
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

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

#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()

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

	string s;
	cin >> s;
	int q;
	cin >> q;
	list<string> a, b;
	bool r = false;
	REP(i, q)
	{
		int t;
		cin >> t;
		if(t == 1){
			r ^= 1;
		}
		else{
			int f;
			string c;
			cin >> f >> c;
			f--;
			if(!(r ^ f)){
				a.push_front(c);
			}
			else{
				b.push_back(c);
			}
		}
	}

	string A = "", B = "";
	EACH(c, a) A += c;
	EACH(c, b) B += c;
	s = A + s + B;
 	if(r) reverse(ALL(s));

	cout << s << endl;

	return 0;
}


Measured memory_bytes: 10644
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define repeat(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(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 ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    if(N % 10 == 9){
        cout << "Yes" << endl;

    }else if(N / 10 == 9){
        cout << "Yes" << endl;
    }else cout << "No" << endl;

}

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

// definitions
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i, l, r) for (long long i = (l); i < (long long)(r); i++)
#define repb(i, r, l) for (long long i = (r); i > (long long)(l); i--)
#define pb push_back
#define mod1 998244353
#define mod 1000000007
#define MAX_CHAR 256

using namespace std;
typedef vector<long long> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef vector<tuple<long long , long long , long long> > vtup;
typedef deque <long long> dq;
typedef long long int lli;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;


// standard functions
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
} 
 


ll modexp(ll x, ll ex, ll modp) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x)%modp;
        ex >>= 1ll;
        x = (x * x)%modp;
    }
    return ans;
} 
 
ll nCrModp(ll n, ll r, ll p) 
{ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; 
    for (ll i = 1; i <= n; i++) 
    { 
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
}
 
bool isPrime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true;  
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
 
vl countFreq(ll arr[], ll n) 
{ 
    unordered_map<ll, ll> mp; 
    vector <ll> v;
    
    for (ll i = 0; i < n; i++) 
        mp[arr[i]]++; 
   
    for (auto x : mp) 
        v.pb(x.second);
    
    return v;
}

ll binarySearch(ll arr[], ll l, ll r, ll x) 
{ 
    while (l <= r) 
    { 
        ll m = l + (r - l) / 2; 
        if (arr[m] == x) 
            return m; 
        if (arr[m] < x) 
            l = m + 1; 
        else
            r = m - 1; 
    }
    return -1; 
}

const ll MAXSIEVE=(1e3);
ll spf[MAXSIEVE];
void sieve() 
{ 
    spf[1] = 1; 
    for (ll i=2; i<MAXSIEVE; i++) 
        spf[i] = i; 

    for (ll i=4; i<MAXSIEVE; i+=2) 
        spf[i] = 2; 
  
    for (ll i=3; i*i<MAXSIEVE; i++) 
    { 
        if (spf[i] == i) 
        { 
            for (ll j=i*i; j<MAXSIEVE; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
}

// code beigns in main
int main()
{
    
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t=1;
    // cin >> t;
    
    while(t--)
    {
        ll n;
        cin >> n;

        ll arr[n-1];
        ll count[n];
        clr(count);
        rep(i,0,n-1)
        {
            cin >> arr[i];
            count[arr[i]-1]++;
        }

        rep(i,0,n)
        cout <<  count[i] << endl;
    }
}



Measured memory_bytes: 6768
n = int(input())
s = input()
li = []
a = s[1:].count("E")
li.append(a)

for i in range(n-1):
    if s[i] == "E" and s[i+1] == "E":
        a -= 1
        li.append(a)
    elif s[i] == "W" and s[i+1] == "W":
        a += 1
        li.append(a)
print(min(li))

Measured memory_bytes: 15564
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stdio.h>
#include <math.h>

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define repm(i, a, b) for(int i = (a); i >= (b); i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int n = (c + b-1)/b;
    int m = (a + d-1)/d;

    if(n <= m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define lld long long int
typedef pair<int,int> P;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
bool mat[500][500];
bool used[500][500];
int h,w;
bool inLimit(int x,int y)
{
	if(x>=0 && x<h && y>=0 && y<w)
	{
		return true;
	}
	else
	{
		return false;
	}
}
bool valid(int ci,int cj,int d)
{
	int ni = ci + dx[d];
	int nj = cj + dy[d];
	if(!inLimit(ni,nj))
	{
		return false;
	}
	if(mat[ci][cj]==mat[ni][nj])
	{
		return false;
	}
	return true;
	
}
int main()
{
	//int h,w;
	cin>>h>>w;
	vector<string>ss;
	for(int i=0;i<h;i++)
	{
		string s;
		cin>>s;
		ss.push_back(s);
	}
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			if(ss[i][j]=='#')
			{
				mat[i][j] = 1;
			}
			else if(ss[i][j]=='.')
			{
				mat[i][j] = 0;
			}
		}
	}
	lld ans = 0 ;
	lld b=0,wt=0;
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			if(used[i][j])
			{
				continue;
			}
			b = 0;
			wt = 0;
			queue<P>Q;
			Q.push(P(i,j));
			used[i][j] = true;
			while(!Q.empty())
			{
				P p = Q.front();
				Q.pop();
				int ci = p.first;
				int cj = p.second;
				if(mat[ci][cj]==1)
				{
					b++;
				}
				else
				{
					wt++;
				}
				for(int d=0;d<4;d++)
				{
					if(!valid(ci,cj,d))
					{
						continue;
					}
					int ni = ci + dx[d];
					int nj = cj + dy[d];
					if(used[ni][nj])
					{
						continue;
					}
					used[ni][nj] = true;
					Q.push(P(ni,nj));
				}
			}
			ans += (b*wt);
		}
	}
	cout<<ans<<"\n";
}


Measured memory_bytes: 896
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int mod=1e9+7;
int main()
{
	int n,m;
	cin>>n>>m;
	if(n>m)swap(n,m);
	if(n==m)
	{
		LL ans=1;
		for(int i=1;i<=n;i++)ans=ans*i%mod*i%mod;
		cout<<ans*2%mod<<endl;
	}
	else if(n==m-1)
	{
		LL ans=1;
		for(int i=1;i<=n;i++)ans=ans*i%mod*i%mod;
		cout<<ans*m%mod<<endl;
	}
	else cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ n, k ] <- readInts
	print $ if k == 1
		then 0
		else ( n - ( k - 1 ) ) - 1

Measured memory_bytes: 380
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
using namespace std;
int main(){
	long long int n,a[1000];
	a[0]=2;a[1]=1;
	cin>>n;
	if(n==1){
		cout<<1<<endl;
		return 0;
	}
	for(int i=2;i<n;i++){
		a[i]=a[i-1]+a[i-2];
		//cout<<"a="<<a[i]<<endl;
	}
	cout<<a[n-2]+a[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int gcd_(int a,int b){
  if(!b) return a;
  return gcd_(b,a%b);
}
int main(){
    int n;
    cin>>n;
    ll ans=0;
    rep(i,n)rep(j,n)rep(k,n){
        ans+=gcd_(i+1,gcd_(j+1,k+1));
    }
    cout<<ans;
}

Measured memory_bytes: 3632
N = gets.to_i
H = Hash.new{0}
A = gets.split.map{|i|
    i = i.to_i
    H[i] += 1
    i
}
sum = H.inject(0){|r, i|
    r + i[1] * (i[1] - 1) / 2
}
C = Hash.new{|h, k|
    v = H[k]
    sum - v * (v - 1) / 2 + (v - 1) * (v - 2) / 2
}
A.each{|i|
    puts C[i]
}


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

double deviation(vector<int> data) { // 配列データを渡して標準偏差を返すメソッド
    double sum = 0; // 平均を求める
    for (int x : data) {
        sum += x;
    }
    double ave = sum / data.size(); 

    double dispersion = 0; // 分散を求める
    for (int x : data) {
        dispersion += (x - ave) * (x - ave);
    }
    dispersion /= data.size();

    double dev = sqrt(dispersion); // 標準偏差は分散の正の平方根
    return dev;
}

int main() {
    vector<double> result; // 結果を出力するための配列
    while (1) { // 無条件ループ
        int n;
        scanf("%d", &n);
        if (n == 0) { // 0が入力されたときループを抜ける
            break;
        } else {
            vector<int> s(n); // データを配列に格納
            for (int i = 0; i < n; i++) {
                scanf("%d", &s.at(i));
            }
            result.push_back(deviation(s)); // データの標準偏差を記録
        }
    }
    for (double x : result) {
        printf("%lf\n", x);
    }
    // int n = 5;
    // vector<int> s(n);
    // s.at(0)=70, s.at(1)=80, s.at(2)=100, s.at(3)=90, s.at(4)=20;
    // double x = deviation(s);
    // printf("%lf\n", x);
}


Measured memory_bytes: 3268
#include <iostream>
#ifdef TEST_NUMAHHA
#include <fstream>
#endif
using namespace std;



int main(void) {
  int A, B;
  char ans[8];

#ifdef TEST_NUMAHHA
std::ifstream in("input.txt");
std::cin.rdbuf(in.rdbuf());
#endif

  cin >> A;
  cin >> B;

  if(1==A && 1==B) sprintf(ans,"Yes");
  else if(1==A && 3==B) sprintf(ans,"Yes");
  else if(3==A && 1==B) sprintf(ans,"Yes");
  else if(3==A && 3==B) sprintf(ans,"Yes");
  else sprintf(ans,"No");
  cout <<ans<< '\n';

  
#ifdef TEST_NUMAHHA
  printf("press Enter!\n");
  getchar();
#endif  
  return 0;
}

Measured memory_bytes: 256
import sys
N = int(input())
S = []
for i in range(N):
    a = int(input())
    S.append((a,i))
S.sort()
T = [0]*(N)
for i in range(N):
    T[S[i][1]] = i
if N == 1:
    print(0)
    sys.exit()
ans = 0
for i in range(0,N,2):
    if T[i]%2:
        ans += 1
print(ans)

Measured memory_bytes: 20568
package main

import "fmt"

func main() {
	var all int
	fmt.Scanf("%d", &all)

	takoyaki := make([]int, all)
	for i := 0; i < all; i++ {
		fmt.Scanf("%d", &takoyaki[i])
	}

	result := 0
	for i, baseT := range takoyaki {
		for j, t := range takoyaki {
			if i >= j {
				continue
			}
			product := baseT * t
			result += product
		}
	}
	fmt.Println(result)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<int> ans(n-k);
    for(int i = k; i < n; i++){
        if(a[i] > a[i-k]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 4776
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:1024000000")
#pragma warning( disable : 6031)
#pragma warning( disable : 4244)
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef vector<ll> vll;
typedef vector<vector<long long>> vvll;
typedef tuple<int, int, int> tiii;
const long long mod = int(1e9) + 7;
const double eps9 = 1e-9;



int main() {
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
	int n;
	cin >> n;
	string s;
	cin >> s;
	map<int, set<int>> pos;
	for (int i = 0; i < n; i++)
		pos[s[i]].insert(i);
	int res = 0;
	for (int i = 0; i < 1000; i++)
	{
		stringstream ss;
		ss << setfill('0') << setw(3) << i;
		string sc = ss.str();
		bool found = true;
		int last_pos = -1;
		for (int j = 0; j < 3; j++)
		{
			if (!pos.count(sc[j]))
			{
				found = false;
				break;
			}
			set<int>& cur_pos = pos[sc[j]];
			set<int>::iterator new_pos;
			if (j > 0 && sc[j] == sc[j - 1])
				new_pos = cur_pos.upper_bound(last_pos);
			else
				new_pos = cur_pos.lower_bound(last_pos);
			if (new_pos == cur_pos.end())
			{
				found = false;
				break;
			}
			last_pos = *new_pos;
		}
		if (found)
			res++;

	}
	cout << res;
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int A,B,K;
    cin >> A >> B >> K;
    rep(i,0,K){
        if(i % 2 == 0){
        A /= 2;
        B += A;
        }else{
      B /= 2;
        A += B;

        }

  
    }
    cout << A << " " << B << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d,x,y;
	cin>>a>>b>>c>>d;
	if(c%b==0)
	x=c/b;
	else
	x=c/b+1;
	if(a%d==0)
	y=a/d;
	else
	y=a/d+1;
	if(x<=y)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ff          first
#define ss          second
#define ll         	long long int
#define pb          push_back
#define ar 			array
#define mp 			make_pair
#define f(i,n)   	for(ll i =0;i<n;i++)
#define inf 		INT_MAX
#define pll 		pair<ll, pair<ll,ll>>
const ll INF = 1e18;
void init(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE 
		freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#endif
}
ll mod = 998244353;
void solve(){
	
	ll N,S;
	cin>>N>>S;
	vector<ll> A(N);
	for(ll i = 0;i<N;i++){
		cin>>A[i];
	}

	vector<vector<ll>> dp(N+1,vector<ll>(S+1 , 0));
	dp[0][0] = 1;
	for(ll i = 0;i<N;i++){

		for(ll j = 0; j<=S;j++){
			dp[i+1][j] += 2*dp[i][j];
			dp[i+1][j] %= mod;

			if(j + A[i] <= S){
				dp[i+1][j+A[i]] += dp[i][j];
				dp[i+1][j+A[i]] %= mod;
			}
		}
	}
	cout<<dp[N][S]<<endl;

}
int main(){
	init();
	ll t = 1;
	//cin>>t;
	for(ll i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}


Measured memory_bytes: 73656
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

typedef struct card {
  char suit;
  int value;
} Card;

Card L[MAX / 2 +1], R[MAX/2 + 1];

void merge(Card A[], int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for(i = 0; i < n1; i++) L[i] = A[left + i];
  for(i = 0; i < n2; i++) R[i] = A[mid + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for(k = left; k < right; k++) {
    if(L[i].value <= R[j].value) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(Card A[], int left, int right) {
  int mid;
  if(left + 1 < right) {
    mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int partition(Card A[], int p, int r) {
  int i, j;
  Card t, x;
  x = A[r];
  i = p - 1;
  for(j = p; j < r; j++) {
    if(A[j].value <= x.value) {
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i + 1];
  A[i + 1] = A[r];
  A[r] = t;
  return i + 1;
}

void quickSort(Card A[], int p, int r) {
  int q;
  if( p < r) {
    q = partition(A, p, r);
    quickSort(A, p, q - 1);
    quickSort(A, q + 1, r);
  }
}

int main() {
  int n, i, v;
  Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for(i = 0; i < n; i++) {
    scanf("%s %d", S, &v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A, 0, n);
  quickSort(B, 0, n-1);

  for(i = 0; i < n; i++) {
    if(A[i].suit != B[i].suit) stable = 0;
  }

  if(stable == 1) printf("Stable\n");
  else printf("Not stable\n");

  for(i = 0; i < n; i++) {
    printf("%c %d\n", B[i].suit, B[i].value);
  }

  return 0;
}



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

int main(){
    string s;
    cin >> s;
    if (s[0] != s[1] && s[1] != s[2] && s[2] != s[0]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
arr = [[0 for i in range(4)] for j in range(13)]

for i in range(n):
	nums = list(input().split(" "))
	card = int(nums[1]) -1
	if nums[0] == "S":
		arr[card][0] = 1
	elif nums[0] == "H":
		arr[card][1] = 1
	elif nums[0] == "C":
		arr[card][2] = 1
	elif nums[0] == "D":
		arr[card][3] = 1

for y in range(4):
	for x in range(13):
		if arr[x][y] != 1 and y == 0:
				print("S" + " " + str(x+1))
		elif arr[x][y] != 1 and  y == 1:
				print("H" + " " + str(x+1))
		elif arr[x][y] != 1 and  y == 2:
				print("C" + " " + str(x+1))
		elif arr[x][y] != 1 and  y == 3:
				print("D" + " " + str(x+1))


Measured memory_bytes: 5612
#include <bits/stdc++.h>
#define pb push_back
#define ers erase
#define ins insert
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
#define kill(x) return cout << x, 0;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;


const ld Pi = 3.14159265359;
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll MAXN = 2e5 + 10;
const ll INF = 1e18;
ll n, dp[MAXN][3], a[MAXN], b[MAXN], c[MAXN];

int main(){
	IOS;
	cin >> n;
	for (int i = 1; i <= n; i++){
		cin >> a[i] >> b[i] >> c[i];
	}
	dp[1][0] = a[1], dp[1][1] = b[1], dp[1][2] = c[1];
	for (int i = 2; i <= n; i++){
		dp[i][0] = max(dp[i - 1][1] + a[i], dp[i - 1][2] + a[i]);
		dp[i][1] = max(dp[i - 1][0] + b[i], dp[i - 1][2] + b[i]);
		dp[i][2] = max(dp[i  - 1][0], dp[i - 1][1]) + c[i];
		
	}
	cout << max({dp[n][0], dp[n][1], dp[n][2]});
	
	
	
	
	return 0;
}






/*
     ,---,           ___                 ,--,
    '  .' \        ,--.'|_             ,--.'|                             ,--,
   /  ;    '.      |  | :,'            |  | :                           ,--.'|    ,---.        ,---,
  :  :       \     :  : ' :            :  : '                 .--.--.   |  |,    '   ,'\   ,-+-. /  |
  :  |   /\   \  .;__,'  /    ,--.--.  |  ' |     ,--.--.    /  /    '  `--'_   /   /   | ,--.'|'   |
  |  :  ' ;.   : |  |   |    /       \ '  | |    /       \  |  :  /`./  ,' ,'| .   ; ,. :|   |  ,"' |
  |  |  ;/  \   \:__,'| :   .--.  .-. ||  | :   .--.  .-. | |  :  ;_    '  | | '   | |: :|   | /  | |
  '  :  | \  \ ,'  '  : |__  \__\/: . .'  : |__  \__\/: . .  \  \    `. |  | : '   | .; :|   | |  | |
  |  |  '  '--'    |  | '.'| ," .--.; ||  | '.'| ," .--.; |   `----.   \'  : |_|   :    ||   | |  |/
  |  :  :          ;  :    ;/  /  ,.  |;  :    ;/  /  ,.  |  /  /`--'  /|  | '.'\   \  / |   | |--'
  |  | ,'          |  ,   /;  :   .'   \  ,   /;  :   .'   \'--'.     / ;  :    ;`----'  |   |/
  `--''             ---`-' |  ,     .-./---`-' |  ,     .-./  `--'---'  |  ,   /         '---'
                            `--`---'            `--`---'                 ---`-'
*/




Measured memory_bytes: 7680
#include <iostream>

int main(int argc, char *argv[]) {
	int result = 0;
	int number_of_childs;

    std::cin >> number_of_childs;

	for (int i = 1; i < number_of_childs + 1; i++) {
		result = result + i;
	}
	std::cout << result << std::endl;

	return 0;
}


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

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


Measured memory_bytes: 3072
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using int64 = int64_t;

using P = pair<int, int>;

constexpr int64 MOD = 1000000007;

struct edge {
    int u, v;
    edge() {}
    edge(int u, int v): u(u), v(v) {}
};

struct query {
    int vertex, color, num;
    query() {}
    query(int vertex, int color, int num): vertex(vertex), color(color), num(num) {}
};

int N, M, Q;

vector<edge> graph;
int color[101010];
int num[101010];
int mark[101010];
vector<query> queries[11];

vector<int> proc;

int main() {
    cin >> N >> M;
    for (int j = 0; j < M; ++j) {
        int a, b;
        cin >> a >> b;
        graph.emplace_back(a, b);
    }

    cin >> Q;

    for (int j = 0; j < Q; ++j) {
        int v, d, c; cin >> v >> d >> c;
        queries[10-d].emplace_back(v, c, j);
    }

    fill(color, color+N+1, 0);
    fill(num, num+N+1, -1);

    for (int n = 0; n < 10; ++n) {
        for (query q : queries[n]) {
            if (q.num > num[q.vertex]) {
                color[q.vertex] = q.color;
                num[q.vertex] = q.num;
                mark[q.vertex] = n;
            }
        }
        sort(begin(graph), end(graph), [&](const edge& a, edge& b) -> bool {
            return min(num[a.u], num[a.v]) < min(num[b.u], num[b.v]);
        });
        for (edge& e : graph) {
            if (num[e.u] > num[e.v] && mark[e.u] == n) {
                color[e.v] = color[e.u];
                num[e.v] = num[e.u];
                mark[e.v] = n+1;
            }
            if (num[e.u] < num[e.v] && mark[e.v] == n) {
                color[e.u] = color[e.v];
                num[e.u] = num[e.v];
                mark[e.u] = n+1;
            }
        }
    }
    for (query q : queries[10]) {
        if (q.num > num[q.vertex]) {
            color[q.vertex] = q.color;
            num[q.vertex] = q.num;
        }
    }

    for (int j = 1; j <= N; ++j) {
        cout << color[j] << endl;
    }

    return 0;
}


Measured memory_bytes: 4596
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }
using namespace std;

struct BinaryIndexedTree {
    int n;
    vector<int> bit;

    BinaryIndexedTree(int size) {
        n = size;
        bit.resize(size+1, 0);
    }

    void add(int i, int x) {
        while (i <= n) {
            bit[i] += x;
            i += i & -i;
        }
    }

    int sum(int i) {
        int s = 0;
        while (i > 0) {
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }

    int getSum(int i, int j) {
        return sum(j) - sum(i);
    }
};

int n, a[200010];
map<ll, ll> m;

int main() {
    int n;
    cin >> n;
    rep(i, n) {
        cin >> a[i];
        m[a[i]];
    }

    ll k = 1;
    for (auto &x: m) x.second = k++;
    rep(i, n) a[i] = m[a[i]];

    BinaryIndexedTree tree(n);
    ll ans = 0;
    rep(i, n) {
        ans += i - tree.sum(a[i]);
        tree.add(a[i], 1);
    }
    cout << ans << endl;
}



Measured memory_bytes: 16744
H, W = gets.chomp.split(" ").map(&:to_i)
ch, cw = gets.chomp.split(" ").map(&:to_i)
dh, dw = gets.chomp.split(" ").map(&:to_i)

map = []
H.times do |i|
  map.push(gets.chomp.chars)
end

H.times do |i|
  map[i] = ["#", "#"] + map[i] + ["#", "#"]
end

map = [["#"] * (W + 4), ["#"] * (W + 4)] + map + [["#"] * (W + 4), ["#"] * (W + 4)]

move = [[-1, 0], [1, 0], [0, -1], [0, 1]]
warp = [
  [-2, -2], [-2, -1], [-2, 0], [-2, 1], [-2, 2],
  [-1, -2], [-1, -1], [-1, 1], [-1, 2],
  [0, -2], [0, 2],
  [1, -2], [1, -1], [1, 1], [1, 2],
  [2, -2], [2, -1], [2, 0], [2, 1], [2, 2],
]

ch += 1
cw += 1
dh += 1
dw += 1

map[ch][cw] = "0"
go = [[ch, cw]]

while !go.empty?
  (H * W).times do |i|
    break if go[i].nil?
    now_h, now_w = go[i]
    move.each do |h, w|
      if map[now_h + h][now_w + w] == "."
        go.push([now_h + h, now_w + w])
        map[now_h + h][now_w + w] = map[now_h][now_w]
      end
    end
  end

  warp_xy = []
  go.each do |i, j|
    warp.each do |wh, ww|
      if map[i + wh][j + ww] == "."
        map[i + wh][j + ww] = (map[i][j].to_i + 1).to_s
        warp_xy.push([i + wh, j + ww])
      end
    end
  end

  if map[dh][dw] != "."
    p map[dh][dw].to_i
    return
  end

  go = warp_xy
end

p (-1)


Measured memory_bytes: 107800
import sys
sys.setrecursionlimit(10**9)
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))

from heapq import heappop, heappush
def dijkstra(start, goal, N, edges,
             get_route = False,
             start_distance=0,
             plus_func=lambda D,d: D+d):
    '''
    goal: int or list or set
    edges: list or dict
        edges[x] = {(y0, distance0),...}
    '''
    q = [(start_distance, start)]
    done = set()
    if isinstance(goal, int):
        goal_set = {goal}
    else:
        goal_set = set(goal)
    ret = [None]*N
    predecessor = [None]*N
    minimum = [None]*N

    while q:
        D, x = heappop(q)
        if x in done:
            continue
        elif x in goal_set:
            ret[x] = D
            goal_set.remove(x)
            if len(goal_set) == 0:
                # return ret
                break
        done.add(x)
        for y, d in edges[x]:
            if not y in done:
                m = minimum[y]
                p = plus_func(D, d)
                if m is None or m > p:
                    heappush(q, (p, y))
                    minimum[y] = p
                    predecessor[y] = x
    return D
    # if get_route:
    #     return ret, predecessor
    # else:
    #     return ret

H, W = inpl()
S = [input() for _ in range(H)]
N = H*W
edges = [set() for _ in range(N)]
dots = []
i = -1
for h in range(H):
    for w in range(W):
        i += 1
        if S[h][w] != '.':
            continue
        dots.append(i)
        if w < W-1 and S[h][w+1] == '.':
            edges[i].add((i+1,1))
            edges[i+1].add((i,1))
        if h < H-1 and S[h+1][w] == '.':
            edges[i].add((i+W,1))
            edges[i+W].add((i,1))
M = len(dots)
ans = 0
for m in range(M-1):
    s = dots[-1]
    dots.pop()
    d = dijkstra(s, dots, N, edges)
    if d > ans:
        ans = d
print(ans)

Measured memory_bytes: 66652
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char **argv) {
    string s;

    cin >> s;

    s.erase(s.begin() + 4);
    s.erase(s.begin() + 6);

    if (stol(s) <= 20190430) {
        cout << "Heisei" << endl;
    }
    else {
        cout << "TBD" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var xa, ya, ra, xb, yb, rb float64
		fmt.Scan(&xa, &ya, &ra, &xb, &yb, &rb)
		distance := math.Sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya))
		if rb+distance < ra {
			fmt.Println(2)
		} else if ra+distance < rb {
			fmt.Println(-2)
		} else if rb+ra >= distance {
			fmt.Println(1)
		} else {
			fmt.Println(0)
		}
	}
}



Measured memory_bytes: 1176
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
P aa[200001];
int main(){
 int a,b;
 cin>>a>>b;
 for(int i=0;i<a;i++){
   int x,y;
   cin>>x>>y;
   aa[i]=P(x,0);
   aa[i+a]=P(y,1);
 }
 sort(aa,aa+2*a);
 int res=0;
 for(int i=2*a-1;i!=-1;i--){
   if(b<=0)break;
   if(aa[i].second==0){
     res+=((b-1)/aa[i].first+1);
     b-=((b-1)/aa[i].first+1)*aa[i].first;
     break;
   }
   else{
     res++;
     b-=aa[i].first;
   }
 }
 cout<<res<<endl;
 return 0;


}


Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
ll comb(ll n,ll r){
  ll res=1;
  for(ll i=n-r+1;i<=n;i++)res*=i;
  for(ll i=1;i<=r;i++)res/=i;
  return res;
}
int main(){
  ll n,p;cin>>n>>p;
  vl a(n);
  ll one=0;
  ll two=0;
  rep(i,n){
    cin>>a[i];
    if(a[i]%2==0)two++;
    else one++;
  }
  ll ans=0;
  if(p==1){
    if(one==0){
      cout<<0<<endl;
      return 0;
    }
    ans+=std::pow(2,one-1);
    rep(i,two)ans*=2;
  }
  if(p==0){
    if(one==0)ans+=1;
    else ans+=std::pow(2,one-1);
    rep(i,two)ans*=2;
  }
  cout<<ans<<endl;
}
  

Measured memory_bytes: 256
#include <cstdio>

int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	int flag = 0;
	for(int i = 1;i <= 3;i++) if(a * b * i & 1) flag = 1;
	if(flag) printf("Yes");
	else printf("No"); 
	return 0;
} 

Measured memory_bytes: 128
#[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, 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!{
        h: usize,
        w: usize,
        a: [chars;h]
    }
    // println!("{:?}", a);
    let mut can = true;
    for i in 0..h {
        for j in 0..w {
            if i+1 > h-1 || j+1 > w-1{
                continue;
            }
            if a[i][j]=='.' && a[i][j+1]=='#' && a[i+1][j]=='#' && a[i+1][j+1]=='#' {
                can = false;
            }
            if a[i][j]=='#' && a[i][j+1]=='#' && a[i+1][j]=='#' && a[i+1][j+1]=='.' {
                can = false;
            }
            if a[i][j]=='#' && a[i][j+1]=='#' && a[i+1][j]=='#' && a[i+1][j+1]=='#' {
                can = false;
            }
        }
    }
    if can {
        println!("Possible");
    }else{
        println!("Impossible");
    }
}

Measured memory_bytes: 4352
#include<stdio.h>
int main()
{
    char s[4];
    int i, j = 0, k,l=0;
    scanf("%s",&s);
    for(i=1; i<=3; i++)
    {
        if(s[0] == s[i])
        {
            j = 1;
            k = i;
        }
    }
    if(j == 1)
    {
        if(k == 1)
        {
            if(s[2] == s[3] && s[2] != s[0])
                l = 1;
        }
        else if(k == 2)
        {

            if(s[1] == s[3] && s[1] != s[0])
                l = 1;
        }
        else if(k == 3)
        {

            if(s[1] == s[2] && s[1] != s[0])
                l = 1;
        }

    }
    if(j == 1 && l == 1)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <queue>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1LL<<60
#define pb push_back
#define mp make_pair

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

struct edge {
	int from,to;
	int cost;

	edge(int t,int c) : to(t),cost(c) {}
	edge(int f,int t,int c) : from(f),to(t),cost(c) {}

	bool operator<(const edge &e) const {
		return cost < e.cost;
	}
};

vector<edge> G[100005];
ll d[100005];
bool used[100005];

void dijkstra(int s,int n) {
	priority_queue<P,vector<P>,greater<P> > que;
	fill(d,d+n,INF);

	d[s] = 0;
	que.push(P(0,s));

	while(que.size()) {
		P p = que.top();
		que.pop();

		int v = p.second;
		if(d[v] < p.first) continue;

		rep(i,G[v].size()) {
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}

int main() {
	int n, m, c;
	cin >> n >> m >> c;

	ll sum = 0;
	rep(i, m) {
		int a, b, d;
		cin >> a >> b >> d;

		a--;
		b--;
		sum += d;

		G[a].push_back(edge(b, d));
		G[b].push_back(edge(a, d));
	}

	dijkstra(0, n);

	vector<pair<ll, int> > v(n);
	rep(i, n) {
		v[i].first = d[i];
		v[i].second = i;
	}

	sort(v.begin(), v.end());
	memset(used, 0, sizeof(used));

	ll ans = INF;
	rep(i, v.size()) {
		int j = v[i].second;
		used[j] = true;

		rep(k, G[j].size()) {
			if(used[G[j][k].to]) {
				sum -= G[j][k].cost;
			}
		}

		ans = min(ans, d[j] * c + sum);
	}

	cout << ans << endl;

	return 0;
}

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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll ai, ao, at, aj, al, as, az;
  cin >> ai >> ao >> at >> aj >> al >> as >> az;
  ll t = 0;
  t += (ai / 2) * 2;
  t += ao;
  t += (aj / 2) * 2;
  t += (al / 2) * 2;
  ll bi = ai % 2;
  ll bj = aj % 2;
  ll bl = al % 2;
  if (bi + bj + bl == 3) {
    t += 3;
  }else if ((bi == 1 && bj == 1 && al >= 2) ||
	    (bj == 1 && bl == 1 && ai >= 2) ||
	    (bl == 1 && bi == 1 && aj >= 2)) {
    t += 1;
  }


  cout << t << endl;

  return 0;
}



Measured memory_bytes: 256
n, p = map(int, input().split())
a = list(map(int, input().split()))


def biscuits():
    dp = [[[0 for i in range(2)] for j in range(n+1)] for i in range(n+1)]

    for i in range(n+1):
        dp[i][0][0] = 1

    for i in range(1, n+1):
        for j in range(i+1):
            for k in range(2):
                if j > 0:
                    dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-a[i-1] % 2]
                else:
                    dp[i][j][k] = dp[i-1][j][k]

    ans = 0
    for j in range(n+1):
        ans += dp[n][j][p % 2]

    return ans


def main():
    print(biscuits())


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <iostream>

using namespace std;

int main(){

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int ans;
    if (b < c || d < a){
        ans = 0;
    }else{
        int m1 = max(a, c);
        int m2 = min(b, d);
        ans = m2 - m1;
    }
    
    cout << ans << endl;

    return 0;
}

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

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

  ll aCnt = 0;
  ll cnt  = 0;
  int z   = 1;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A') {
      if (z == 3) {
        aCnt = 1;
      } else {
        aCnt++;
      }
      z = 2;
    } else if (s[i] == 'B') {
      if (i != 0 && s[i - 1] != 'A') { aCnt = 0; }
      z = 3;
    } else if (s[i] == 'C') {
      if (i >= 1 && s[i - 1] == 'B' && s[i - 2] == 'A') {
        cnt += aCnt;
        s[i] = 'A';
      } else {
        aCnt = 0;
      }
      z = 1;
    }
  }
  cout << cnt << endl;
}

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

#define ll long long int
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define repm(i, a, n) for (ll i = a; i >= n; i--)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define mod (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vb vector<bool>
#define vs vector<string>
#define vii vector<vector<int>>
#define vllll vector<vector<ll>>
#define ALL(a) (a).begin(), (a).end()

int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};

void print(bool f)
{
    cout << (f ? "Yes" : "No") << endl;
}

void Print(bool f)
{
    cout << (f ? "YES" : "NO") << endl;
}

int main(void)
{
    ll n, k, input;
    cin >> n >> k;
    vll d(10);
    rep(i, 0, k) cin >> input, d[input] = 1;

    for (int i = n;; i++)
    {
        int tmp = i;
        bool f = true;
        while (tmp != 0)
        {
            if (d[tmp % 10])
            {
                f = false;
                break;
            }
            tmp /= 10;
        }
        if (f)
            return cout << i << endl, 0;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const ll MAX = 3e3+5;
const ll INF=1e15;

ll a[MAX];
ll dp[MAX][MAX];

ll calc(ll l,ll r,int flg)
{
    if(l>r)
        return 0;
    if(l==r)
    {
        if(flg)
            return a[l];
        else return 0;    
    }
    if(l==r-1)
    {
        if(flg)
            return max(a[l],a[r]);
        else return min(a[l],a[r]);    
    }
    if(dp[l][r]!=-INF)
        return dp[l][r];
        
    ll &sum1=dp[l][r];
    sum1=0;
    if(flg)
    {
        sum1+=max(a[l]+calc(l+1,r,0),a[r]+calc(l,r-1,0));
    }
    else
    {
        sum1+=min(calc(l+1,r,1),calc(l,r-1,1));
    }
    return sum1;
        
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    ll sum=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            dp[i][j]=-INF;
    for(int i=0;i<n;i++)
    {    
        cin>>a[i];
        sum+=a[i];
    }
    
    ll val=calc(0,n-1,1);
    //cout<<val<<endl;
    cout<<val-(sum-val)<<endl;
    
        
}

Measured memory_bytes: 71040
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n, m;
    std::cin >> n >> m;
    std::vector<std::vector<std::pair<int, int>>> g(n);
    std::vector<std::pair<int, int>> vs(n, std::make_pair(0, 0));
    for (int i = 0; i < m; i++) {
        int u, v, s;
        std::cin >> u >> v >> s;
        --u; --v;
        g[u].emplace_back(v, s);
        g[v].emplace_back(u, s);
    }

    auto verify = [&](int a) {
        constexpr int inf = std::numeric_limits<int>::max() / 2;
        std::deque<int> q { 0 };
        std::vector<int> val(n, inf);
        val[0] = a;
        while (!q.empty()) {
            auto v = q.front();
            q.pop_front();
            for (auto to : g[v]) {
                if (val[to.first] < inf) {
                    if (val[to.first] + val[v] == to.second) continue;
                    return false;
                } else {
                    val[to.first] = to.second - val[v];
                    q.emplace_back(to.first);
                }
            }
        }
        return std::all_of(val.begin(), val.end(), [](auto k) { return k > 0; });
    };

    std::deque<int> q { 0 };
    vs[0].first = 1;
    while (!q.empty()) {
        auto v = q.front();
        q.pop_front();
        for (auto to : g[v]) {
            if (vs[to.first].first) {
                auto nxt = to.second - vs[v].second;
                if (vs[to.first].first == -vs[v].first && vs[to.first].second == nxt) continue;
                if (vs[to.first].first == -vs[v].first || (vs[to.first].second - nxt) % 2) {
                    std::cout << 0 << std::endl;
                    return 0;
                }
                std::cout << (verify((vs[to.first].second - nxt) / 2 * -vs[to.first].first) ? 1 : 0) << std::endl;
                return 0;
            } else {
                vs[to.first] = std::make_pair(-vs[v].first, to.second - vs[v].second);
                q.emplace_back(to.first);
            }
        }
    }

    int r = std::numeric_limits<int>::max(), l = 0;
    for (int i = 0; i < n; i++) {
        if (vs[i].first > 0) l = std::max(l, -vs[i].second);
        else r = std::min(r, vs[i].second);
    }

    std::cout << (r > l ? r - l - 1 : 0) << std::endl;

    return 0;
}


Measured memory_bytes: 7936