akhauriyash/Code-Regression huggingface dataset:
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

use std::collections::BTreeSet;

fn check(
    u: usize,
    goal: usize,
    edge: &Vec<BTreeSet<usize>>,
    checked: &mut BTreeSet<usize>,
) -> bool {
    if checked.contains(&u) {
        return false;
    }
    if u == goal {
        return true;
    }

    checked.insert(u);

    for v in &edge[u] {
        if check(*v, goal, &edge, checked) {
            return true;
        }
    }
    false
}

fn main() {
    let nm: Vec<usize> = read_vec();
    let n = nm[0];
    let m = nm[1];
    let ab: Vec<Vec<usize>> = read_vec2(m);
    let mut edge: Vec<BTreeSet<usize>> = vec![BTreeSet::new(); n];

    for tmp in &ab {
        let a = tmp[0] - 1;
        let b = tmp[1] - 1;
        edge[a].insert(b);
        edge[b].insert(a);
    }

    let mut ans: usize = 0;
    for tmp in &ab {
        let a = tmp[0] - 1;
        let b = tmp[1] - 1;

        edge[a].remove(&b);
        edge[b].remove(&a);
        let mut checked = BTreeSet::new();
        if !check(a, b, &edge, &mut checked) {
            ans += 1;
        }
        edge[a].insert(b);
        edge[b].insert(a);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#maspyさんのやつ

from functools import lru_cache

n = int(input())
k = int(input())

@lru_cache(None)
def f(n, k):
    assert n >= 0 #例外処理
    if n < 10:
        if k == 0:
            return 1 #0しかない数 = 0
        elif k == 1:
            return n #k = 1ならn個分存在している
        return 0 #k >= 2のときは、0を返す
    
    q, r = divmod(n, 10)
    res = 0
    
    if k >= 1:
        #1の位が0でないとき
        res += f(q, k-1) * r
        res += f(q-1, k-1) * (9 - r)
    #１の位が0
    res += f(q, k)
    return res

print(f(n, k))

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

#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define FORN(i, m, n) for(int (i) = (m); (i) <= (n); (i)++)
#define FORR(i, m, n) for(int (i) = (m); (i) >= (n); (i)--)
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> Vec;

const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	int x, y;
	cin >> x >> y;
	int prise = 0;
	if(x == 1 && y == 1){
		prise = 10;
	}else{
		if(x == 1) prise += 3;
		else if(x == 2) prise += 2;
		else if(x == 3) prise += 1;
		if(y == 1) prise += 3;
		else if(y == 2) prise += 2;
		else if(y == 3) prise += 1;
	}

	co(prise*100000);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <set>

using namespace std;


// Union-Find
class UnionFind {
private:
	// parents[i] >= 0 なら i の親
	// parents[i] < 0 で、根。abs(parents[i])がその木に属する頂点数
	vector<int> parents;
	int n_root;

public:
	UnionFind();
	UnionFind(int n) {
		parents.assign(n, -1);
		n_root = n;
	}
	~UnionFind() {
		parents.clear();
	};

	int find(int x) {
		if (parents[x] < 0) {
			return x;
		} else {
			return parents[x] = find(parents[x]);
		}
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);

		if (x == y) {
			return;
		}

		if (size(x) < size(y)) {
			swap(x, y);
		}

		parents[x] += parents[y];
		parents[y] = x;
		n_root--;
		return ;
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}

	// xが属する集団のサイズ
	int size(int x) {
		return -parents[find(x)];
	}

	// いくつの集団があるか
	int get_n_root() {
		return n_root;
	}
};

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

	int x, y, z;
	UnionFind uf(n);

	set<int> known;
	for (int i = 0; i < m; i++) {
		cin >> x >> y >> z;
		x--;
		y--;

		uf.unite(x, y);

		if (x == y) {
			known.insert(x);
		}
	}

	set<int> known_root;
	vector<int> v_known(known.begin(), known.end());
	for (auto a: v_known) {
		known_root.insert(uf.find(a));
	}

	int ans = uf.get_n_root() - known_root.size();
	cout << ans << endl;

	return 0;
}


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

#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int n;
    cin>>n;
    cout<<n*32<<endl;
    return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main(){
#ifdef CIN
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif

	int a,b,c;
	int i, j;

	j = 0;

	cin >> a >> b >> c;

	for (int i = a; i <= b; i++)
	{
		if (c % i == 0) j++;
	}

	cout << j << endl;


	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;
#define INF 1e18LL

const ll MAX = 1000000000000000000; //1e18

int main(){
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if(k % 2 != 0){
        cout << b - a << endl;
    }else{
        cout << a - b << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  string s;
  cin >> s;
  int ans = 7;
  if(s == "MON") ans -= 1;
  else if(s == "TUE") ans -= 2;
  else if(s == "WED") ans -= 3;
  else if(s == "THU") ans -= 4;
  else if(s == "FRI") ans -= 5;
  else if(s == "SAT") ans -= 6;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}

int main() {
  int n;
  cin >> n;
  char s[n];
  cin >> s;
  int mi=0;
  REP(i,n) {
    if(i>0&&s[i]=='E') {
      mi++;
    }
  }
  int temp=mi;
  REP(i,n-1) {
    if(s[i]=='W') temp++;
    if(s[i+1]=='E') temp--;
    mi=min(mi,temp);
  }
  cout << mi << endl;
  return 0;
}


Measured memory_bytes: 3924
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) stable_sort(a.begin(), a.end())
#define rsort(a) stable_sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0)
#define join(a, d) accumulate(a.begin() + 1, a.end(), a[0], [](string s, string t) {return s + d + t;})
#define all(a) a.begin(), a.end()
// #define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

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

  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, 0, N) cin >> A[i];
  array<int, 8> rate{0, 0, 0, 0, 0, 0, 0, 0};
  int max_ = 0;
  for (auto a : A) {
    if (a > 3199) ++max_;
    else if (a > 2799) rate[7] = 1;
    else if (a > 2399) rate[6] = 1;
    else if (a > 1999) rate[5] = 1;
    else if (a > 1599) rate[4] = 1;
    else if (a > 1199) rate[3] = 1;
    else if (a > 799) rate[2] = 1;
    else if (a > 399) rate[1] = 1;
    else rate[0] = 1;
  }
  cout << max(1, sum(rate)) << ' ' << sum(rate) + max_ << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi = acos(-1);
#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    ll n; cin >> n;
    vector<ll> A(n);
    // 初期位置と目的位置を結びつける
    vector<pair<ll, ll>> v(n);
    REP(i, n) {
        cin >> A[i];
        v[i] = {A[i], i};
    }
    sort(v.begin(), v.end());
    // 目標位置と初期位置の偶奇が異なる要素数を数える
    ll cnt = 0;
    REP(i, n) {
        // 目標位置と初期位置の偶奇が異なる
        if (i % 2 != v[i].second % 2) {
            ++cnt;
        }
    }
    cout << cnt/2 << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include<time.h>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include<cassert>
#include<cctype>
#include<iterator>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MOD 1000000007
#define INF 1<<30
#define INFTY 1000000000000000001LL
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Graph=vector<vector<ll> >;//int と P
// g++ -o a a.cpp -Wall -lm -std=c++14
int main(){
    int k;
    cin>>k;
    queue<ll>que;
    for(int i=1;i<10;i++)que.push(i);
    rep(i,k-1){
        ll s=que.front();
        que.pop();
        for(int j=-1;j<=1;j++){
            ll add=(s%10)+j;
            if(add>=0&&add<=9)que.push(s*10+add);
        }
    }
    cout<<que.front()<<endl;
}

Measured memory_bytes: 5164
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,x,y;
    while(cin>>n>>k>>x>>y)
    {
        unsigned long long sum=0;
        int temp=0;

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


        cout<<sum<<endl;

    }
    return 0;
}


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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    int sum=0;
    int ok=0;
    rp(i,n){
        cin >> a.at(i);
        sum += a.at(i);
    }
    if(sum%(4*m)==0){
        rp(i,n){
            if(a.at(i)>=sum/(4*m)){
                ok++;
            }
        }
    }
    else{
        rp(i,n){
            if(a.at(i)>sum/(4*m)){
                ok++;
            }
        }
    }
    if(ok>=m) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(){
    int a,b,c; cin >> a >> b >> c;
    int x = a;
    bool flag = true;
    rep(i,b){
        if(x%b == c){
            cout << "YES" << endl;
            flag = false;
            break;
        }
        x += a;
    }
    if(flag){
        cout << "NO" << endl;
    }
}





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


int main(){
	int N, X;
	cin >> N >> X;
	int rest = X;
	int mass[N];
	int minimo;
	int resp = N;
	for (int i = 0; i < N; ++i)
	{
		cin >> mass[i];
		rest-=mass[i];
		minimo = mass[0];
	}
	for (int i = 1; i < N; ++i)
	{
		minimo = min(mass[i], minimo);
	}
	resp+=rest/minimo;
	cout << resp;
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> ans(10001);
    rep(i,101)rep(j,101)rep(k,101){
        if(i==0||j==0||k==0) continue;
        int x=i*i+j*j+k*k+i*k+k*j+j*i;
        if(x<=10000) ans[x-1]++;
    }
    rep(i,n){
        cout << ans[i] << endl;
    }
    
}

Measured memory_bytes: 3664
s = input()
cnt_b = 0
cnt_w = 0
i = 1
for l in s:
    if i % 2 == 1:
        if l == '1':
            cnt_b += 1
        else:
            cnt_w += 1
    else:
        if l == '1':
            cnt_w += 1
        else:
            cnt_b += 1
    i += 1
print(min(cnt_b, cnt_w))


Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
int n,K,cnt,ans;
int fir[101010],nxt[101010],to[101010],dep[101010],fa[101010];
priority_queue<pair<int,int> > q;
bool d[101010];
void add(int x,int y)
{
	nxt[++cnt]=fir[x];fir[x]=cnt;
	to[cnt]=y;
}
void dfs(int x)
{
	for(int i=fir[x];i;i=nxt[i])
	{
		dep[to[i]]=dep[x]+1;
		q.push(make_pair(dep[to[i]],to[i]));
		dfs(to[i]);
	}
}
void update(int x)
{
	d[x]=1;
	for(int i=fir[x];i;i=nxt[i])
	if(!d[to[i]])
		update(to[i]);
}
int main()
{
	scanf("%d%d",&n,&K);
	for(int i=1;i<=n;i++)
		scanf("%d",&fa[i]);
	if(fa[1]!=1) ans++;
	for(int i=2;i<=n;i++)
	add(fa[i],i);
	dfs(1);
	while(!q.empty())
	{
		int x=q.top().second;q.pop();
		if(d[x]) continue;
		if(dep[x]<=K) break;
		int md=dep[x]-K+1;
		ans++;
		while(dep[x]>md) x=fa[x];
		update(x);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 7924
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<ll, int> mp;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	int a[212345]; for (int i = 0; i < n; i++) cin >> a[i];
	int array[512345];
	int left = 212345, right = left + 1;
	for (int i = 0; i < n; i++) {
		if (i % 2 == (n - 1) % 2) {
			array[left--] = a[i];
		}
		else {
			array[right++] = a[i];
		}
	}
	for (int i = left + 1; i < right; i++) {
		cout << array[i] << " ";
	}
	return 0;
}

Measured memory_bytes: 4864
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
using namespace std;

int main()
{
    int i, n, minn = 1e9,num=0;
    int a[200010];
    scanf("%d",&n);
    for(i = 0;i < n; i++)
    {
        scanf("%d",&a[i]);
    }
    for(i = 0;i < n;i++)
    {
        minn = min(minn,a[i]);
        if(minn == a[i])
            num++;
    }
    printf("%d\n",num);
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;

const int MAX = 100;



int main() {
	int N;
	int ans = 0;
	vector<pair<int, int>> red;
	vector<pair<int, int>> blue;

	cin >> N;

	for (int i = 0; i < N; i++) {
		int x, y;
		cin >> x >> y;
		red.push_back(make_pair(x, y));
	}
	for (int i = 0; i < N; i++) {
		int x, y;
		cin >> x >> y;
		blue.push_back(make_pair(x, y));
	}

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

	for (int i = 0; i < blue.size(); i++) {
		int m = -1;
		int n = -1;

		for (int j = 0; j < red.size(); j++) {
			if (blue[i].first > red[j].first && blue[i].second > red[j].second) {
				if (red[j].second > m) {
					m = red[j].second;
					n = j;
				}
			}
		}
		if (n != -1) {
			ans++;
			red.erase(red.begin() + n);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int i,j;
	int h1=0,h2=0,h3=0;
	
	for(i=1;i<=10;i++){
		scanf("%d\n",&j);
		if(j>=h1){
			h3=h2;
			h2=h1;
			h1=j;
		}
		else if(j>=h2){
			h3=h2;
			h2=j;
		}
		else if(j>=h3){
			h3=j;
		}
	}
	printf("%d\n%d\n%d\n",h1,h2,h3);
	return 0;
}

Measured memory_bytes: 1032
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


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

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)








int main() {
    ll n, h, w;
    cin >> n >> h >> w;
    cout << (n - h + 1) * (n - w + 1) << endl;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    s = input()
    
    # + or - を入れる位置は間なので-1する
    n = len(s) - 1
    
    for i in range(1<<n):    #2**nと同じ
        ans = s[0]
        for j in range(n):
            #iはどこに＋を挿入するか jはsのこと
            if (i >> j & 1) :
                ans += "+"
            else:
                ans += "-"
            
            ans += s[j+1]
        if eval(ans) == 7:
            print(ans+"=7")
            break

Measured memory_bytes: 8972
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;

void main(){
	long n, a, b;
	{
		long[] tmp = readln.chomp.split.map!(to!long).array;
		n = tmp[0], a = tmp[1], b = tmp[2];
		}
	long[] xs = readln.chomp.split.map!(to!long).array;
	
	BigInt ans = 0;
	long p = xs[0];
	foreach(x; xs){
		BigInt q;
		q = x - p;
		q *= a; 
		if(q > b) ans += b;
		else ans += q;
		p = x;
		debug writeln("(", ans, ")");
		}
	
	ans.writeln;
	
	}

Measured memory_bytes: 4788
#include "bits/stdc++.h"

using namespace std;

int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

string check(int a,int b,int c,int d){
    if(a+b+c+d==7){
        return to_string(a)+"+"+to_string(b)+"+"+to_string(c)+"+"+to_string(d)+"=7";
    }else if(a+b+c-d==7){
        return to_string(a)+"+"+to_string(b)+"+"+to_string(c)+"-"+to_string(d)+"=7";
    }else if(a+b-c+d==7){
        return to_string(a)+"+"+to_string(b)+"-"+to_string(c)+"+"+to_string(d)+"=7";
    }else if(a-b+c+d==7){
        return to_string(a)+"-"+to_string(b)+"+"+to_string(c)+"+"+to_string(d)+"=7";
    }else if(a-b-c+d==7){
        return to_string(a)+"-"+to_string(b)+"-"+to_string(c)+"+"+to_string(d)+"=7";
    }else if(a-b+c-d==7){
        return to_string(a)+"-"+to_string(b)+"+"+to_string(c)+"-"+to_string(d)+"=7";
    }else if(a+b-c-d==7){
        return to_string(a)+"+"+to_string(b)+"-"+to_string(c)+"-"+to_string(d)+"=7";
    }else if(a-b-c-d==7){
        return to_string(a)+"-"+to_string(b)+"-"+to_string(c)+"-"+to_string(d)+"=7";
    }else{
        return "None";
    }
}

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

  string ABCD;
  cin>>ABCD;

  char A=ABCD[0];
  char B=ABCD[1];
  char C=ABCD[2];
  char D=ABCD[3];

  cout<<check(ctoi(A),ctoi(B),ctoi(C),ctoi(D))<<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(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<vector<mint>> dp(n+1, vector<mint>(k+10, 0));

  dp[0][0] = 1;
  rep(i, n) {
    for(int sum_c = 0; sum_c <= k; ++sum_c) {
      if(sum_c-a[i] >= 1) dp[i+1][sum_c] += dp[i][sum_c]-dp[i][sum_c-a[i]-1];
      else dp[i+1][sum_c] += dp[i][sum_c];
    }
    for(int sum_c = 0; sum_c < k; ++sum_c) dp[i+1][sum_c+1] += dp[i+1][sum_c];
  }
  cout << dp[n][k].x << endl;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define ifr(a, value) insert(a.begin(), value)
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define szz(v) ((int)(v).size())  
#define vi vector<int>
#define vll vector<ll>
#define str string
#define fr(i, j, k) for(i = j; i < k; i++)
#define bk(i, j, k) for(i = j; i >= k; i--)
#define frit(a, it) for(__typeof((a).begin()) it = a.begin(); it != a.end(); ++it)
#define mem(ptr)  memset(ptr, 0, sizeof ptr)        // use fill() for value other than 0 //
#define rtn return 
#define clk fprintf(stderr, "\nTIME = %lf\n", 1.0 * clock()/CLOCKS_PER_SEC)
#define nl "\n"
#define inf 1LL<<61
#define dbg(x) (cerr << #x << ": " << x << "\n")
const long long mod = 1e9+7;

ll gcd(ll a,ll b) { return b==0 ? a : gcd(b, a%b); }   // no need to swap a, b, it auto. happens after first call //
ll expo(ll x, ll y){ ll res = 1; x = x % mod;  while (y > 0) { if (y & 1)res = (res*x) % mod; y = y>>1;x = (x*x) % mod;}return res;}
void matmul(ll a[][2], ll b[][2]) { ll tmp[2][2]; for(int i=0; i<2; i++) { for(int j=0; j<2; j++) { tmp[i][j] = 0; for(int k=0; k<2; k++) tmp[i][j] = (tmp[i][j] + a[i][k]*b[k][j]) % mod; }} for(int i=0; i<2; i++) for(int j=0; j<2; j++) a[i][j] = tmp[i][j]; }
ll fibo(int n)    // returns nth fibonacci number, also S(n) = f(n+2)-1
{ if(n == 0) return 0; else if(n == 1) return 1; ll T[2][2] = { {0, 1} , {1, 1} }; ll res[2][2] = { {1, 0}, {0,1} }; n--; while(n) { if(n & 1) matmul(res, T); n >>= 1; matmul(T, T); } return res[1][1]; }

void NO() {
	puts("-1");
	exit(0);
}

int main()
{
   // ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;
	scanf("%d", &n);
	ll answer = 0;
	vector<int> in(n);
	for(int & x : in) scanf("%d", &x);
	if(in[0]) NO();
	for(int i = 1; i < n; ++i) if(in[i] > in[i-1] + 1) NO();
	map<int, int> mapka;
	for(int i = 0; i < n; ++i)
    {
 //       dbg(i); dbg(in[i]); dbg(in[i]-i); 
		mapka[in[i]-i] = in[i];
    }
/*    map <int, int> :: iterator it;
    for(it = mapka.begin(); it != mapka.end(); ++it)
    {
        cout << it->ff << " " << it->ss << nl;
    } */
    
	for(pair<int,int> p : mapka) 
    {
//        dbg(p.ff); dbg(p.second);
        answer += p.second;
    }
	printf("%lld\n", answer);
    return 0;
}

/* Errichto : Let (x, y) denote using an operation to make the x-th number equal to y, what requires (x-1,y-1).

For every (x,y) in the input we also need (x-1,y-1), (x-2, y-2) and so on. The goal is to count different pairs created this way. Imagine a grid. For every (x,y) mark all cells from (x,y) diagonally to (x-y,0). For every (x-y,0) achieved this way we want to know the size of the diagonal from that place and this is what we need the map for.   
*/ ///////////////

Measured memory_bytes: 10368
#include <iostream>

using namespace std;
typedef long long ll;

const int MAXN=50;

int N,P;
int A[MAXN];

int main() {
        cin >> N >> P;
        for (int i=0; i<N; i++)
                cin >> A[i];

        int even=0,odd=0;
        for (int i=0; i<N; i++) {
                if (A[i]%2) odd++;
                else even++;
        }

        if (odd == 0 && P == 1)
                cout << "0\n";
        else if (odd == 0 && P == 0)
                cout << (1LL << even) << "\n";
        else
                cout << (1LL << even)*(1LL << (odd-1)) << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbgvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

const int MOD = 1000000007;

ll modadd(ll x, ll y) {
	ll xp = x % MOD;
	if (x < 0) x += MOD;
	ll yp = y % MOD;
	if (y < 0) y += MOD;
	return (x + y) % MOD;
}

ll modsub(ll x, ll y) {
	return modadd(x, -y);
}

ll modmul(ll x, ll y) {
	return x * y % MOD;
}

// power(mod) x^n
ll modpow(ll x, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = modmul(res, x);
		x = modmul(x, x);
		n >>= 1;
	}
	return res;
}

// inverse(mod) x^(-1)
ll inv(ll x) {
	return modpow(x, MOD - 2);
}

ll moddiv(ll x, ll y) {
	return modmul(x, inv(y));
}

// factorial(mod) n!
ll fact(ll n) {
	ll res = 1;
	while (n > 1) {
		res = modmul(res, n);
		n--;
	}
	return res;
}

int main () {
	int N; cin >> N;
	cout << fact(N) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#define mp make_pair
#include <iostream>
const LL INF=10000000000000000;


#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

LL POW(LL x, LL y)
{
    LL ans = 1;
    LL base = x;
    while (y)
    {
        if (y & 1)
        {
            ans *= base;
        }
        base = base * base;
        y = y >> 1;
    }
    return ans;
}

int main()
{
    fastinput;
    LL n,i,j,k,t,temp;
    LL x;
    LL num_books,num_algo;
    cin>>num_books>>num_algo>>x;
    n=num_books;
    LL limit=POW(2,num_books);
    LL minima=INF;
    LL skill[num_books][num_algo];
    LL cost[num_books];
    //////////////////////
    for(i=0;i<num_books;i++)
    {
        cin>>cost[i];
        for(j=0;j<num_algo;j++)
        {
            cin>>skill[i][j];
        }
    }
    //debug(limit);
    /////////////////////////
    LL one=1;
    for(i=0;i<limit;i++)
    {
        //debug(i);
        LL total=0;
        bool fulfilled=true;
        vector<LL> now(num_algo+1,0);
        for(j=0;j<num_books;j++)
        {
            LL testing=one<<j;
            //debug(testing);
            LL status=(i)&(testing);
            //debug(status);
            if(status!=0)
            {
                //debug(j);
                total+=cost[j];
                for(t=0;t<num_algo;t++)
                {
                    now[t]+=skill[j][t];
                }
            }
        }

        for(t=0;t<num_algo;t++)
        {
            if(now[t]<x)
            {
                fulfilled=false;
                break;
            }
        }

        if(fulfilled)
        {
           minima=min(minima,total); 
        }
       // part;

        
    }

    if(minima==INF)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<minima<<endl;
    }
    

    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector <int> a(n), b(n);
    for(int i = 0; i < n; ++i)cin >> a[i];
    for(int i = 0; i < n; ++i)cin >> b[i];
    int x  =0;
    for(int i = 0; i < n; ++i)x += max(0, a[i] - b[i]);
    
    cout << x << '\n';
}

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

ans=a[0]
c=1
i=1
while c<n-1:
    ans+=a[i]
    c+=1
    if c>=n-1:
        break
    else:
        ans+=a[i]
        c+=1
    i+=1
print(ans)

Measured memory_bytes: 31748
using System;
using System.Linq;

class Aoj
{
	public static void Main()
	{
		var inputs = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
		Console.WriteLine("{0} {1}",
			inputs[0] * inputs[1],
			inputs[0] * 2 + inputs[1] * 2);
	}
}

Measured memory_bytes: 5940
import java.util.Scanner;
public class Main {
   public static void main(String[] args){
     Scanner scanner = new Scanner(System.in);
     for(int i=1;i>0; i++){
          int x = scanner.nextInt();
          int y = scanner.nextInt();
          if(x==0&&y==0)break;
          if(x>=y){
              System.out.println(y+" "+x);
          }else{
              System.out.println(x+" "+y);
          }     
   }   
}
}

Measured memory_bytes: 35576
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

INF = 1<<29
N  = int_raw()
tree = [[] for _ in range(N)]
for _ in range(N-1):
    a,b,w = ints_raw()
    a = a-1
    b = b-1
    tree[a].append((b,w))
    tree[b].append((a,w))

def main():
    colors = [-1]*N
    colors[0]=1
    qu = deque()
    qu.append((0,0,-1))
    while len(qu)!=0:
        cur = qu.popleft()
        if cur[0]%2 == 0:
            colors[cur[1]]=0
        else:
            colors[cur[1]]=1
        for e in tree[cur[1]]:
            if e[0] ==cur[2]:
                continue
            qu.append([cur[0]+e[1],e[0],cur[1]])
    for c in colors:
        print (c)      
            
main()


Measured memory_bytes: 76832
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

class Pg
{
    static void Main()
    {
        var rd = new Reader();
        rd.Read()
            .Select(x =>
            new Regex(@"@(?<int>\d)(?<char>.)").Replace(x, y 
            => new string(y.Groups["char"].Value[0]
             , int.Parse(y.Groups["int"].Value))))
            .ToList().ForEach(Console.WriteLine);
    }
}
class Reader
{
    internal IEnumerable<string> Read()
    {
        string line;
        while (!string.IsNullOrEmpty(line = Console.ReadLine()))
            yield return line;
    }
}


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

using namespace std;

#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define F first
#define S second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rep(i,j,k) for(int i=j;i<k;i++)
#define repb(i,j,k) for(int i=j;i>=k;i--)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

const ll inf = 1e10;
const ll mod = 1e9 + 7;


signed main(){
	IOS;
	ll a,b,n;
	cin>>a>>b;
	if(a % 2 == 0 or b%2 == 0){
		cout<<"No"<<endl;
	}
	else{
		cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 764
import heapq
import sys

class rode():
    def __init__(self,x,y):
        self.x = x
        self.y = y
    def __lt__(self, other):
        return self.y < other.y
    def __gt__(self, other):
        return other > self
    def __le__(self, other):
        return not(other > self)
    def __ge__(self, other):
        return not(self > other)

n,m = map(int,input().split())
da = [[] for i in range(n)]
for i in range(m):
    l,r,c = map(int,input().split())
    da[l-1].append([r-1,c])
for i in range(1,n):
    da[i].append([i-1,0])
pq=[]
ju = [False for i in range(n)]
ju[0] = True
for i in da[0]:
    heapq.heappush(pq, rode(i[0],i[1]))
while(len(pq)):
    now = heapq.heappop(pq)
    if now.x == n-1:
        print(now.y)
        sys.exit()
    if ju[now.x]:
        continue
    ju[now.x] = True
    for i in da[now.x]:
        if ju[i[0]]:
            continue
        heapq.heappush(pq,rode(i[0],now.y+i[1]))
print(-1)


Measured memory_bytes: 93600
#include<bits/stdc++.h>
#define ll long long
using namespace std;
/*const int N=1e5+5;
int*/


int main(){
	int n;
	ios::sync_with_stdio(false);cin.tie(0);
	int h,w;
	cin>>h>>w>>n;
	if(h<w){int t=h;h=w;w=t;
	}	
	cout<<(n+h-1)/h;	
		

	return 0;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define R register
#define ll long long
#define mp make_pair
#define pii pair<int, int>
using namespace std;

template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = ch == '-', ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}

char s[2];

int main() {
    scanf("%s", s);
    printf("%c\n", s[0] + 1);
    return 0;
}

Measured memory_bytes: 256
kazu = int(input())
nums = list(map(int, input().split()))
count = 0
flg = True
while flg:
  for i in range(kazu):
    if nums[i] % 2 == 1:
      flg = False
      break
    else:
      nums[i] /= 2
  count += 1
count -= 1
print(count)
      

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

int main()
{
    int h, w;
    int i, j, count = 0, p, q;
    
    cin >> h >> w;
    
    char s[60][60];
    
    for(i = 0; i < h; i ++) {
        cin >> s[i];
    }
    
    for(i = 0; i < h; i++) {
        for(j = 0; j < w; j++) {
            
            if(s[i][j] == '#') {
                cout << '#';
            } else {
                
                for(p = -1; p <= 1; p++) {
                    for(q = -1; q <= 1; q++) {
                        
                        if(s[i+p][j+q] == '#') {
                            count++;
                        }
                    }
                }
                
                cout << count;
                
                count = 0;
            }
        }
        
        cout << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc174/tasks/abc174_e
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)
ll mod = 1000000000;
int main()
{
    ll S;
    cin >> S;
    ll x = (mod - S % mod)% mod;
    ll y = (S + x) / mod;
    cout << "0 0 1000000000 1 " << x << " " << y << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
   int a,b,c,X,ans=0;
   scanf("%d %d %d %d",&a,&b,&c,&X);

   for(int i=0;i<=a;i++){
       int x=500*i;
       if(x>X) break;
       
       for(int j=0;j<=b;j++){
           int y=100*j;
           if(y>X) break;
           
           for(int f=0;f<=c;f++){
               int z=50*f; 
               if(x+y+z==X){
                   ans++;
                   break;
               }
           }

        
       }   
   
   }printf("%d\n",ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector <int> pw(n), se(n);
	for (int i = 0; i < n; i++) {
		pw[i] = (s[i] == 'W');
		if(i > 0) {
			pw[i] += pw[i - 1];
		}
	}
	for (int i = n - 1; i >= 0; i--) {
		se[i] = (s[i] == 'E');
		if(i < n - 1) {
			se[i] += se[i + 1];
		}
	}
	int ans = MOD;
	for (int i = 0; i < n; i++) {
		ans = min(ans, pw[i] + se[i] - 1);
	}
	cout << ans;
}


Measured memory_bytes: 2948
from collections import deque
n = int(input())
ans = deque()
for i in range(n):
    t = input().split()
    op = t[0]
    if op == "insert":
        ans.appendleft(t[1])
    elif op == "delete":
        try:
            ans.remove(t[1])
        except ValueError:
            pass
    elif op == "deleteFirst":
        ans.popleft()
    elif op == "deleteLast":
        ans.pop()

print(" ".join(ans))



Measured memory_bytes: 69740
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

typedef pair<int, int> pInt;

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

	vector<pInt> power(m);
	for(int i=0; i<m; i++)
		cin >> power[i].first >> power[i].second;

	int c,l,cnt;
	c = l = cnt = 0;
	while(l != n) {
		c = l+1;
		
		for(int i=0; i<m; i++)
			if(power[i].first <= c && c <= power[i].second)
				if(l < power[i].second)
					l = power[i].second;
		
		if(l < c) {
			cout << "Impossible" << endl;
			return EXIT_SUCCESS;
		}
		
		++cnt;
	}
	
	cout << cnt << endl;
	return EXIT_SUCCESS;
}

Measured memory_bytes: 1200
#! python3
# matrix_multiplication.py

n, m, l = [int(x) for x in input().split(' ')]

mat1 = [[int(x) for x in input().split(' ')] for i in range(n)]
mat2 = [[int(x) for x in input().split(' ')] for j in range(m)]

rst_mat = [[0 for k in range(l)] for i in range(n)]

for i in range(n):
    for k in range(l):
        for j in range(m):
            rst_mat[i][k] += mat1[i][j] * mat2[j][k]

for i in range(n):
    print(' '.join([str(x) for x in rst_mat[i]]))


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

using namespace std;

typedef long long LL;

#define fin "\n"


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

template <typename T>
inline void chmin(T &l,T r){l=min(l,r);}

template <typename T>
inline void chmax(T &l,T r){l=max(l,r);}

template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
typedef vector<int> V;
typedef vector<V> VV;

int main(){
    int N,M;
    cin>>N>>M;
    VV d(N,V(N,1e8));
    V a(M),b(M),c(M);
    REP(i,N)d[i][i]=0;
    
    REP(i,M){
        cin>>a[i]>>b[i]>>c[i];a[i]--,b[i]--;
        d[a[i]][b[i]]=c[i];
        d[b[i]][a[i]]=c[i];
    }
    REP(k,N)REP(i,N)REP(j,N)chmin(d[i][j],d[i][k]+d[k][j]);
    int res=0;
    REP(i,M){
        int ans=1;
        REP(j,N)REP(k,N)if(j!=k)
            if(d[j][k]==d[j][a[i]]+d[b[i]][k]+c[i])ans=0;
        res+=ans;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef complex<double> xy_t;
typedef vector<lint> poly;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

const lint mod = 1e9+7;
const lint INF = mod;
const int MAX = 30010;

int main(){
    lint t1, t2, a1, a2, b1, b2;
    scanf("%lld%lld%lld%lld%lld%lld", &t1, &t2, &a1, &a2, &b1, &b2);
    lint v1=a1-b1, v2=a2-b2;
    lint d=v1*t1+v2*t2;
    if(d<0) v1=-v1, v2=-v2, d=-d;
    if(d==0) {
        printf("infinity\n");
        return 0;
    }
    if(v1>0){
        printf("%d\n", 0);
        return 0;
    }
    
    lint ans=((-v1*t1)/d+1)*2-1;
    if(-v1*t1%d==0) --ans;
    printf("%lld\n", ans);
}

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

int main() {
	// your code goes here
	int n,m;
	
	cin>>n>>m;
    int arr[n+1];
    memset(arr,0,sizeof(arr));
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        if(a==1||a==n)
        {
            arr[b]++;
            //cout<<a<<b<<endl;
        }
        if(b==1||b==n)
        {
            //cout<<a<<b<<endl;
            arr[a]++;
            
        }
    }
        int flag=0;
        for(int i=0;i<n;i++)
        if(arr[i]==2)
        flag=1;
        if(flag)
        cout<<"POSSIBLE"<<endl;
        else 
        cout<<"IMPOSSIBLE"<<endl;
	
	return 0;
}


Measured memory_bytes: 1024
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(A[K-1])


Measured memory_bytes: 2940
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        StringBuilder A = new StringBuilder(N);
        StringBuilder B = new StringBuilder(N);
        StringBuilder C = new StringBuilder(N);
        A.append(sc.next());
        B.append(sc.next());
        C.append(sc.next());
        sc.close();
        
        int cnt = 0;
        for (int i=0; i<N; i++) {
            if (A.charAt(i)==B.charAt(i) & A.charAt(i)==C.charAt(i)) {
                //non
            } else if (A.charAt(i)!=B.charAt(i) & A.charAt(i)!=C.charAt(i) & B.charAt(i)!=C.charAt(i)) {
                cnt+=2;
            } else {
                cnt++;
            }
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 24020
using System;
using System.Collections.Generic;
using static Exter;
using System.Linq;
#if DEBUG
#else
using console = System.Console;
#endif

public class App
{
    public static void Main(string[] args)
    {
        int n = readarr[0];
        var arr = readarr;
        int[] rl = new int[n-1];
        int[] lr = new int[n-1];
        rl[0] = arr[0];
        lr[n-2] = arr[n-1];
        for(int i = 1;i<n-1;i++)
            rl[i] = Gcd(rl[i-1],arr[i]);
        for(int i = n-3;i>=0;i--)
            lr[i] = Gcd(lr[i+1],arr[i+1]);
        rl = new int[]{0}.Concat(rl).ToArray();
        lr = lr.Concat(new int[]{0}).ToArray();
        cout = rl.Zip(lr,(a,b)=>
        {
            if(a==0)
                return b;
            if(b==0)
                return a;
            return Gcd(a,b);
        }).Max();
    }
}
public static class Exter
{
    public static void rep(int loop,Action<int> act)
    {
        for(int i=0;i<loop;i++)
            act(i);
    }
    public static int ToInt(this string v)=>int.Parse(v);
    public static int Max(params int[] p)=>p.Max();
    public static long Max(params long[] p)=>p.Max();
    public static int Min(params int[] p)=>p.Min();
    public static long Min(params long[] p)=>p.Min();
    public static int Gcd(int a, int b)=>a > b ? GcdRecursive(a, b) : GcdRecursive(b, a);
    private static int GcdRecursive(int a, int b)=>b == 0 ? a : GcdRecursive(b, a % b);
    public static object cout
    {
        set
        {
            console.Write(value.ToString());
            console.WriteLine();
            
        }
    }
    public static void ToCout<t>(this IEnumerable<t> v)
    {
        cout = string.Join(",",v);
    }
    public static int[] readarr
    {
        get 
        {
            preadarr = console.ReadLine().Split().Select(s=>int.Parse(s)).ToArray();
            return preadarr;
        }
    }
    public static int[] preadarr;
}


#if DEBUG
public static class console
{
    static int cursorLine = 0;
    static readonly string[] cin = new string[]
    {
                "2",
"24 16"
    };
    static public string ReadLine()
    { 
        return cin[cursorLine++];
    }
    static public void WriteLine()
    {
        Console.WriteLine();
    }
    static public void WriteLine<T>(T input)
    {
        Console.WriteLine(input);
    }
    static public void Write<T>(T input)
    {
        Console.Write(input);
    }
    static public void WriteLine(string s,params object[] arr)
    {
        Console.WriteLine(s,arr);
    }
}
#endif

Measured memory_bytes: 31324