akhauriyash/Code-Regression huggingface dataset:
////////////////////////////////////////////////////////////////
//
//    (☝ ՞ਊ ՞)☝ << Be accept!!
//
//    C++ format for competitive professional v1.0
//
//    need gcc & boost::c++
//
////////////////////////////////////////////////////////////////
#define BOOST
#define CGCC
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#ifdef BOOST
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;//cpp_int
#endif
#define rep(i,n) for(int i = 0;i < n;i++)
using ll = long long;
using namespace std;
#ifdef CGCC
#pragma once
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
int inline setup(void) {//set
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	return 0;
}
int lenght(char* str){//getcharlengh
	int i = 0;
	while (str[i]) {
		i++;
	}
	return i;
}
int gcd(long long a, long long b) {
	if (a < b)return gcd(b, a);
	long long r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
#define DEBUG
int main(int argc, const char* argv[]) {
	setup();
		
	string s, t, u;
	int a, b;
	cin >> s >> t >> a >> b >> u;
	if (s == u) {
		cout << a - 1 << endl << b << endl;
	}
	else {
		cout << a << endl << b - 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

class dijkstra(object):
    def __init__(self, start, n, E, INF=1e10):
        self.INF = INF
        self.start = start
        self.n = n
        self.V = [0 for _ in range(n + 1)]
        self.E = E
        self.d = [INF for _ in range(n + 1)]
        self.d[start] = 0

    def run(self):
        Q = [[i, self.d[i]] for i in range(1, self.n + 1)]

        while(len(Q) > 0):
            Q.sort(key=lambda x: x[1], reverse=True)
            u = Q.pop()[0]
            for v, l in self.E[u].items():
                if self.d[v] > self.d[u] + l[0]:
                    self.d[v] = self.d[u] + l[0]
                    self.V[v] = u
            Q = [[x[0], self.d[x[0]]] for x in Q]

    def count_path(self):
        def find_path(i, Qv):
            Qv[i] += 1
            if i != self.start:
                self.E[i][self.V[i]][-1] += 1
                self.E[self.V[i]][i][-1] += 1
                Qv = find_path(self.V[i], Qv)
            return Qv

        Qv = [0 for _ in range(self.n + 1)]
        for i in range(1, self.n + 1):
            if i == self.start or Qv[i] > 0:
                continue
            Qv = find_path(i, Qv)

        return self.E

n, m = map(int, input().split())
E_list = [list(map(int, input().split())) for _ in range(m)]
E = defaultdict(dict)
for j in range(m):
    a, b, c = E_list[j]
    E[a][b] = [c, 0]
    E[b][a] = [c, 0]
for i in range(1, n + 1):
    D = dijkstra(i, n, E)
    D.run()
    E = D.count_path()
ans = 0
for v in E.values():
    for v2 in v.values():
        if v2[-1] == 0:
            ans += 1
print(ans // 2)


Measured memory_bytes: 4160
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if ((a * 100 + b * 10 + c) % 4 == 0)
	{
		cout << "YES";
	}
	else
	{
		cout << "NO";
	}
	return 0;
}

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

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

template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> S(H);
    REP(i, H) { cin >> S[i]; }

    int ans = iINF;
    REP(ss, 1 << (H - 1)) {
        bool gok = true;
        int N = 0;
        vector<int> ord(H, 0);
        REP(i, H - 1) {
            if (!((ss >> i) & 1)) {
                ord[i + 1] = ord[i];
            } else {
                ord[i + 1] = ord[i] + 1;
                N += 1;
            }
        }

        int add = 0;
        vector<int> nums(N + 1, 0);
        REP(w, W) {
            vector<int> one(N + 1, 0);
            bool ok = true;
            REP(h, H) {
                one[ord[h]] += S[h][w] - '0';
                nums[ord[h]] += S[h][w] - '0';
                if (one[ord[h]] > K) gok = false;
                if (nums[ord[h]] > K) ok = false;
            }
            if (!ok) {
                add += 1;
                nums = one;
            }
        }
        if (gok) chmin(ans, N + add);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::Integer;
#[allow(unused_imports)]
use proconio::derive_readable;
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::*;

fn solve(cycle: Vec<i64>, k: usize) -> i64 {
    let m = cycle.len();
    let total: i64 = cycle.iter().sum();
    let mut dp = vec![vec![0; m]; m];
    for i in 0..m {
        for j in 1..m {
            dp[i][j] = dp[i][j - 1] + cycle[(i + j) % m];
        }
    }
    let mut ret = -(1i64 << 60);
    if total < 0 || k < m {
        for i in 0..m {
            for j in 1..cmp::min(m, k + 1) {
                ret = cmp::max(ret, dp[i][j]);
            }
        }
    } else {
        let base = total * (k / m - 1) as i64;
        for i in 0..m {
            for j in 1..m {
                ret = cmp::max(ret, base + dp[i][j]);
            }
        }
        let base = total * (k / m) as i64;
        for i in 0..m {
            for j in 0..=k % m {
                ret = cmp::max(ret, base + dp[i][j]);
            }
        }
    }
    ret
}

#[fastout]
fn main() {
    input! {
        n: usize,
        k: usize,
        p: [Usize1; n],
        c: [i64; n],
    }
    let mut ans = -(1i64 << 60);
    let mut used = vec![false; n];
    for i in 0..n {
        if used[i] {
            continue;
        }
        let mut j = i;
        let mut cycle = vec![];
        loop {
            cycle.push(c[j]);
            used[j] = true;
            j = p[j];
            if j == i {
                break;
            }
        }
        ans = cmp::max(ans, solve(cycle, k))
    }

    println!("{}", ans);
}


Measured memory_bytes: 197704
#include <iostream>
#include <string>
#include<algorithm>
#include<vector>
using namespace std;

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

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

	int answer = v[v.size() / 2] - v[v.size() / 2 - 1];

	cout << answer << endl;
}

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

int main() {
	int A, B; cin >> A >> B; int ans = 1;
	for (int pos = B / A; pos > 1; pos--)
		if (B % pos == 0) {
			ans = pos; break;
		}
	cout << ans << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;
int main(){
	int n,a[100010],count=0,count2=0;
	cin>>n;
	REP(i,n){
		cin>>a[i];
	}
	sort(a,a+n,greater<int>());
	for(int i=0;i<n;i++){
		if(i%2==0){
			count+=a[i];
		}
		else{
			count2+=a[i];
		}
	}
	cout<<count-count2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct linklist *list;
struct linklist{
	int key;
	list next;
	list back;
};

list head;
list tail;

void init(void){
	head = (list)malloc(sizeof(*head));
	tail = head;
	tail->next = NULL;
}

void insert(int k){
	list x;
	x = (list)malloc(sizeof(*x));
	x->next = head;
	x->key = k;
	x->back = NULL;
	head->back = x;
	head = x;
//	printf("insert\n");
	return;
}

void delete(int k){
	list x;
	list ins;
	x = head;
//	printf("delete\n");
	if(head->key==k){
		head = head->next;
		head->back = NULL;
		free(x);
		return;
	}
	while(x->next!=tail){
		if((x->next)->key==k){
			ins = x->next;
			x->next = ins->next;
			ins->next->back = x;
			free(ins);
			return;
		}else{
			x = x->next;
		}
	}
	return;
}

void deleteFirst(void){
	list ins;
	ins = head;
	head = head->next;
	head->back = NULL;
	free(ins);
	return;
}

void deleteLast(void){
	list x;
	list ins;
	x = tail;
	tail = tail->back;
	tail->next = NULL;
	free(x);
	return;
}

int main(int argc, char argv[]){
	int n;
	char command[20] = "\0";
	int d;
	list x;

	init();

	scanf("%d",&n);

	int i,j;
	for(i=0;i<n;i++){
		scanf("%s %d",command,&d);
		if(!strcmp(command,"insert"))insert(d);
		else if(!strcmp(command,"delete"))delete(d);
		else if(!strcmp(command,"deleteFirst"))deleteFirst();
		else if(!strcmp(command,"deleteLast"))deleteLast();
		else printf("The command does not exist.\n");
//		printf("%s %d\n",command,d);

/*		j=0;
		x = head;
		if(x!=NULL)printf("%d",x->key);
		x = x->next;
		while(x != NULL&&j<22){
			printf(" ");
			printf("%d",x->key);
			x = x->next;
			j++;
		}
		printf("\n");
*/	}

	x = head;
	if(x!=tail)printf("%d",x->key);
	x = x->next;
	while(x != tail){
		printf(" ");
		printf("%d",x->key);
		x = x->next;
	}
	printf("\n");

	return 0;
}

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

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

int main() {
  int n; cin>>n;
  vector<int> v(n);
  int sum=0;
  rep(i,n){
    cin>>v.at(i);
    sum+=v.at(i);
  }
  int i=0,s=0;
  int ans;
  while(i<n){
    s+=v.at(i);
    
    if(2*s==sum){
      ans=0;
      break;}
    if(2*s>sum){ 
      ans=min(2*s-sum,v.at(i)*2-2*s+sum);
      break;
    }
    i++;
  }
  cout<<ans;
  
}
      

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <queue>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

class top_k {
private:
  const size_t size;
  int64_t sum;
  std::priority_queue<int, std::vector<int>, std::greater<int>> que;

public:
  top_k(size_t size_): size(size_), sum(0) { }

  int64_t fold() const {
    return sum;
  }

  void push(int value) {
    sum += value;
    que.push(value);
    if (que.size() > size) {
      sum -= que.top();
      que.pop();
    }
  }

};

constexpr int64_t inf = (int64_t(1) << 60);

int main() {
  int X, Y, Z;
  std::cin >> X >> Y >> Z;
  int N = X + Y + Z;
  std::vector<int> A(N), B(N), C(N);
  for (int i = 0; i < N; ++i) {
    std::cin >> A[i] >> B[i] >> C[i];
    B[i] -= A[i];
    C[i] -= A[i];
  }
  std::vector<int> order(N);
  std::iota(order.begin(), order.end(), 0);
  std::sort(order.begin(), order.end(), [&](int i, int j) {
    return B[i] - C[i] > B[j] - C[j];
  });
  top_k top_b(Y), top_c(Z);
  std::vector<int64_t> sum_b(N + 1), sum_c(N + 1);
  for (int i = 0; i < N; ++i) {
    top_b.push(B[order[i]]);
    sum_b[i + 1] = top_b.fold();
  }
  for (int i = N - 1; i >= 0; --i) {
    top_c.push(C[order[i]]);
    sum_c[N - i] = top_c.fold();
  }
  int64_t max = -inf;
  for (int i = 0; i < N; ++i) {
    if (i + 1 >= Y && N - i - 1 >= Z) {
      chmax(max, sum_b[i + 1] + sum_c[N - i - 1]);
    }
  }
  std::cout << max + std::accumulate(A.cbegin(), A.cend(), int64_t(0)) << '\n';
  return 0;
}


Measured memory_bytes: 3964
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

vector<ll> par(1000000);
vector<ll> rnk(1000000);

void init(ll n){
  rep(i, n){
    par.at(i) = i;
    rnk.at(i) = 0;
  }
}

ll root(ll x){
  if(par.at(x) == x){
    return x;
  }
  else{
    par.at(x) = root(par.at(x));
    return par.at(x);
  }
}

bool same(ll x, ll y){
  if(root(x) == root(y)){
    return true;
  }
  else{
    return false;
  }
}

void unite(ll x, ll y){
  x = root(x);
  y = root(y);
  if(x == y){
    return;
  }
  if(rnk.at(x) < rnk.at(y)){
    par.at(x) = y;
  }
  else{
    par.at(y) = x;
    if(rnk.at(x) == rnk.at(y)){
      rnk.at(x)++;
    }
  }
}

int main()
{
    ll N, M;
    cin >> N >> M;
    init(2*N);
    vector<ll> X(M), Y(M), Z(M);
    rep(i, M){
        cin >> X.at(i) >> Y.at(i) >> Z.at(i);
        X.at(i)--;
        Y.at(i)--;
        if(Z.at(i) % 2 == 0){
            unite(X.at(i), Y.at(i));
            unite(X.at(i)+N, Y.at(i)+N);
        }
        else{
            unite(X.at(i), Y.at(i)+N);
            unite(X.at(i)+N, Y.at(i));
        }
    }
    set<ll> con;
    rep(i, 2*N){
        con.insert(root(i));
    }
    cout << sz(con)/2 << endl;
}

Measured memory_bytes: 30276
#include<iostream>
using namespace std;
using ll=long long;
int main(){
  ll n;
  cin>>n;
  ll c[26]={};
  for(int i=1;i<=26;i++){
    cin>>c[i];
  }
  ll s[n][26]={};
  for(int j=0;j<n;j++){
    for(int i=0;i<26;i++){
      cin>>s[j][i];
    }
  }
  ll ans=0;
  for(int i=0;i<n;i++){
    ll max=0;
    for(int j=0;j<26;j++){
      if(s[i][j]>max){
        max=s[i][j];
        ans=j+1;
      }
    }
    cout<<ans<<endl;
    max=0;
  
  }
  return 0;
}

Measured memory_bytes: 3708
#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 count = 0;
	while (A%2==0 &&B%2==0 && C%2==0)
	{
		int a = A / 2, b = B / 2, c = C / 2;
		
		A = b + c;
		B = a + c;
		C = a + b;

		count++;
		if (count>1000000)
		{
			cout << -1 << endl;
			return 0;
		}
	}
	cout << count << endl;
}

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

using namespace std;

int main() {
    string s, t; cin >> s >> t;
    size_t res = t.size();
    for (size_t i = 0; i <= s.size() - t.size(); ++i) {
        size_t diff = 0;
        for (size_t j = 0; j < t.size(); ++j) {
            if (t[j] != s[i + j]) {
                diff++;
            }
        }
        res = min(res, diff);
    }
    cout << res << endl;
}

Measured memory_bytes: 3132
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;

	VI H(N);
	REP(i, N) {
		cin >> H[i];
	}
	REP(i, N - 1) {
		if (H[i] > H[i + 1]) {
			H[i]--;
			continue;
		}
		if (i != 0) {
			if (H[i] == H[i + 1]) {
				if (H[i - 1] < H[i]) {
					H[i]--;
				}
			}
		}
		else if (H[i] == H[i + 1]) {
			H[i]--;
		}
	}
	FOR(i, 1, N) {
		if (H[i - 1] > H[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}



Measured memory_bytes: 1024
#include<stdio.h>
#include<map>
#include<string.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
int n,lal,sl;
char s[105],la[105];
const int p1=1e9+7,p2=1e9+9;
long long g1,g2;
struct nod{
	long long h1,h2;
	bool operator <(const nod x)const{
		if (h1==x.h1) return h2<x.h2;
		return h1<x.h1;
	}
};
std::map<nod,bool> q;
int main(){
	scanf("%d",&n);
	scanf("%s",la+1);
	lal=strlen(la+1);
	fo(i,1,lal){
		g1=(g1*253+la[i])%p1;
		g2=(g2*257+la[i])%p2;
	}
	q[(nod){g1,g2}]=1;
	fo(t,2,n){
		scanf("%s",s+1);
		g1=g2=0;
		sl=strlen(s+1);
		fo(i,1,sl){
			g1=(g1*253+s[i])%p1;
			g2=(g2*257+s[i])%p2;			
		}
		if (q[(nod){g1,g2}]){
			printf("No\n");
			return 0;
		}
		if (la[lal]!=s[1]){
			printf("No\n");
			return 0;			
		}
		q[(nod){g1,g2}]=1;//!!!!
		lal=sl;
		fo(i,1,lal) la[i]=s[i];
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int n,x;
        cin>>n>>x;
        if(n==0 && x==0)break;
        int ans=0;
        for(int a=1;a<=n;a++)
            for(int b=a+1;b<=n;b++)
                for(int c=b+1;c<=n;c++){
                    if(a+b+c!=x)continue;
                    ans++;
                }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3068
#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)
using namespace std;
typedef long long ll;


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

  int N; cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];

  ll ans = 0;
  ll sum = 0;
  int right = 0;

  rep(left, N) {
    while(right < N && (sum ^ A[right]) == sum + A[right]) {
      sum += A[right];
      right++;
    }

    ans += right - left;
    sum -= A[left];
  }

  cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define taskname "gridcompo"
using namespace std;

int tt, nT = 1;
int A, B;
char c[101][101];

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);	cout.tie(nullptr);
    if (ifstream("test.inp"))
    {
        freopen("test.inp", "r", stdin);
        #ifdef CHECKING
            freopen(taskname".out", "w", stdout);
        #else
            freopen("test.out", "w", stdout);
        #endif //CHECKING
    }
    else if (ifstream(taskname".inp"))
    {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }

    cin >> A >> B;
    for (int i = 1; i <= 50; ++i)
        for (int j = 1; j <= 100; ++j) c[i][j] = '#';
    for (int i = 51; i <= 100; ++i)
        for (int j = 1; j <= 100; ++j) c[i][j] = '.';
    --A;    --B;
    for (int i = 1; i <= 50; i += 2)
    {
        if (!A) break;
        for (int j = 1; j <= 100; j += 2)
        {
            c[i][j] = '.';
            if (!--A) break;
        }
    }
    for (int i = 100; i > 50; i -= 2)
    {
        if (!B) break;
        for (int j = 1; j <= 100; j += 2)
        {
            c[i][j] = '#';
            if (!--B) break;
        }
    }
    cout << "100 100\n";
    for (int i = 1; i <= 100; ++i)
    {
        for (int j = 1; j <= 100; ++j) cout << c[i][j];
        cout << '\n';
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>

using namespace std;

int main(){
	int N, M;
	while(cin >> N >> M){
		vector<int> visit(N, 0);
		deque<int> res;
		vector<vector<int>> g(N);
		for(int i=0;i<M;i++){
			int a, b; cin >> a >> b;
			--a; --b;
			g[a].push_back(b);
			g[b].push_back(a);
			if(i == 0) {
				res.push_back(a);
				res.push_back(b);
				visit[a] = 1;
				visit[b] = 1;
			}
		}
		while(true){
			bool ok = true;
			int src = res.front();
			for(int nxt : g[src]){
				if(!visit[nxt]){
					ok = false;
					res.push_front(nxt);
					visit[nxt] = 1;
					break;
				}
			}
			if(ok) break;
		}
		while(true){
			bool ok = true;
			int src = res.back();
			for(int nxt : g[src]){
				if(!visit[nxt]){
					ok = false;
					res.push_back(nxt);
					visit[nxt] = 1;
					break;
				}
			}
			if(ok) break;
		}
		cout << res.size() << endl;
		cout << res.front()+1;
		for(int i=1;i<res.size();i++) cout << " " << res[i]+1;
		cout << endl;
	}
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
using ii = pair<int, int>;

int exp1(const string& s, int& i, int r);
int exp2(const string& s, int& i, int r);
int exp1(const string& s, int& i, int r) {
    int acc = exp2(s, i, r);
    while (i < r && s[i] != ')') {
        if (s[i] == '+') {
            acc += exp2(s, ++i, r);
        } else if (s[i] == '-') {
            acc -= exp2(s, ++i, r);
        } else assert(0);
    }
    return acc;
}
int exp2(const string& s, int& i, int r) {
    if (s[i] == '(') {
        int ret = exp1(s, ++i, r);
        assert(s[i++] == ')');
        return ret;
    }
    if (isdigit(s[i])) return s[i++] - '0';
    assert(0);
}
bool is_valid(const string& s, int i, int r) {
    int acc = 0;
    for (int j = i; j < r; j++) {
        if (s[j] == '(') acc++;
        if (s[j] == ')') acc--;
        if (acc < 0) return false;
    }
    return acc == 0;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;
    vector<int> num, idx, op_idx;
    op_idx.push_back(-1);
    vector<char> ops;
    REP(i, s.size()) {
        if (isdigit(s[i])) {
            num.push_back(s[i] - '0');
            idx.push_back(i);
        }
        if (s[i] == '+' || s[i] == '-') {
            ops.push_back(s[i]);
            op_idx.push_back(i);
        }
    }
    op_idx.push_back(s.size());

    auto valid = [&](int i) { return 0 <= i && i < s.size(); };

    constexpr ii DMY = {1e17, 1e17};
    int m = num.size();
    vector<vector<ii>> dp(m, vector<ii>(m, DMY));
    function<ii(int, int)> dfs = [&](int i, int j) {
        if (dp[i][j] != DMY) return dp[i][j];
        if (i == j) return dp[i][j] = {num[i], num[i]};
        int mi = 1e18, ma = -1e18;
        int l_idx = idx[i];
        int r_idx = idx[j];
        if (is_valid(s, l_idx, r_idx + 1)) {
            mi = ma = exp1(s, l_idx, r_idx + 1);
        }
        for (int k = i; k < j; k++) {
            if (k != i && valid(idx[k] - 1) && s[idx[k] - 1] == '(') continue;
            if (k != j - 1 && valid(idx[k + 1] + 1) && s[idx[k + 1] + 1] == ')') continue;
            ii l = dfs(i, k);
            ii r = dfs(k + 1, j);
            if (ops[k] == '+') {
                mi = min(mi, l.fi + r.fi);
                ma = max(ma, l.se + r.se);
            } else {
                assert(ops[k] == '-');
                mi = min(mi, l.fi - r.se);
                ma = max(ma, l.se - r.fi);
            }
        }
        return dp[i][j] = {mi, ma};
    };
    dfs(0, m - 1);
    cout << dp[0][m - 1].se << endl;
}


Measured memory_bytes: 3340
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int K = int.Parse(str[1]);
		int[]A = new int[N];
		string[] str2 = Console.ReadLine().Split();
		for(var i=0;i<N;i++){
			A[i] = int.Parse(str2[i]);
		}
		long[]B = new long[N+1];
		for(var i=1;i<N+1;i++){
			B[i] = B[i-1] + A[i-1] + 1;
		}
		double ans = 0;
		for(var i=K;i<N+1;i++){
			ans = Math.Max(ans,B[i]-B[i-K]);
		}
		Console.WriteLine(ans/2);
	}
}

Measured memory_bytes: 28636
// https://atcoder.jp/contests/abc080/tasks/abc080_d
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, C;
    cin >> N >> C;
    vector<vector<pair<int, int>>> v(C);
    vector<int> dp(100001);

    REP(i, N) {
        int a, b, c;
        cin >> a >> b >> c;
        v[c - 1].push_back({a, b});
    }
    REP(i, C) {
        sort(ALL(v[i]));
        map<int, int> mp;
        for (auto &x : v[i]) {
            if (mp[x.first] > 0) {
                mp[x.first]--;
                dp[x.first]++;
            } else {
                dp[x.first - 1]++;
            }
            dp[x.second]--;
            mp[x.second]++;
        }
    }

    REP(i, 100000) dp[i + 1] += dp[i];
    cout << *max_element(ALL(dp)) << endl;

    return 0;
}


Measured memory_bytes: 6132
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6+69;
int m,n;
int x,y,z;
int a[MAXN];
struct vl{
	int x,y;
	bool operator<(vl t)const {
		if(x==t.x)return y<t.y;
		return x<t.x;
	}
};
signed main(){																																																																																						ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	string s,t;
	cin>>n;
	cin>>s;
	if(n%2==1){
		cout<<"No";
		return 0;
	}
	if(s.substr(0,n/2)==s.substr(n/2,n)){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	
	
}

Measured memory_bytes: 3668
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C;
string S,T;
ll ans;
ll x[1000000];
ll y[1000000];
ll v[1000000];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
int main() {
	cin>>S;
	if(S.size()==2){
		if(S[0]=='0' || S[1]=='1'){
			cout<<-1<<endl;
			return 0;
		}
		cout<<1<<" "<<2<<endl;
		return 0;
	}
	if(S[0]=='0' || S[S.size()-1]=='1' || S[S.size()-2]=='0'){
		cout<<-1<<endl;
		return 0;
	}
	rep(i,1,S.size()/2){
		if(S[i]!=S[S.size()-i-2]){
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<1<<" "<<2<<endl;
	ll count=2;
	rep(i,1,S.size()/2){
		if(S[i]=='1'){
			rep(j,count,i+2){
				cout<<count<<" "<<j+1<<endl;
			}
			count=i+2;
		}
	}
	rep(i,count,S.size()){
		cout<<count<<" "<<i+1<<endl;
	}
	return 0;
}


Measured memory_bytes: 1664
//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#define eb(i,j) emplace_back((i),(j))
#include <bits/stdc++.h>
using namespace std;
//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;
const int mod = 1000000009;

int n,m,a[301][301],lo,hi,mid;

bool ok(int mx){
    vi sid(n+1,0);
    vi cancel(m+1,0);

    while(true){
        vi npert(m+1,0);
        REP(i,n) npert[ a[i][sid[i]] ]++;

        // cerr << lo << " " << hi << " " << mid << "   " ;
        // REP(i,m) cerr << npert[i] << " ";
        // cerr << endl; 

        auto mxitr = max_element(npert.begin(),npert.end());

        if ( *mxitr <= mx) break;
        cancel[ distance(npert.begin(), mxitr)]++;
        REP(i,n){
            while( cancel[a[i][sid[i]]] ) sid[i]++;
            if (sid[i] >= m) return false;
        }
    }

    return true;
}


int main(){
    I(n); I(m);
    REP(i,n) REP(j,m) { I(a[i][j]); a[i][j]--; }

    lo = 0;
    hi = n;
    while (lo + 1 < hi){
        mid = (lo + hi)/2;
        if (ok(mid)){
            hi = mid;
        } else {
            lo = mid;
        }
    }
    cout << hi << endl;

}

Measured memory_bytes: 640
#include<iostream>
#include<string>
using namespace std;
string s;
int i,l;
int main()
{
	cin>>s;
	l=s.length();
	for (i=0;i<=l-1;i++)
	  if (i%2==0) cout<<s[i];
	cout<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int N; cin >> N;
  vi a(N); REP(i,N) cin >> a[i];

  map<int,int> cnt;
  REP(i,N) {
    cnt[a[i]]++;
  }

  SORT(a);
  a.erase(unique(ALL(a)),a.end());

  int ans = 0;
  for (int X : a) {
    ans = max(ans, cnt[X-1]+cnt[X]+cnt[X+1]);
  }

  cout << ans << endl;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<int>x(n),y(n);
    rep(i,n)cin>>x[i];
    y=x;
    sort(x.begin(),x.end());
    rep(i,n){
        if(y[i]<x[x.size()/2]){
            cout<<x[x.size()/2]<<endl;
        }
        else{
            cout<<x[x.size()/2-1]<<endl;
        }
    }
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
typedef long long ll;
int main(void)
{
	string str;
	cin >> str;
	reverse(str.begin(), str.end());
	cout << str << endl;
}


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

std::string s;
int a, b;
bool ok = true;

int main() {
  std::cin >> a >> b;
  std::cin >> s;
  for (int i = 0; i < a + b + 1; i++) {
    if (i == a) {
      if (s[i] == '-') {
        continue;
      }
      else {
        ok = false;
        break;
      }
    }
    if ((int)s[i] - (int)'0' < 0 || (int)s[i] - (int)'0' > 9) {
      ok = false;
      break;
    }
  }
  if (ok)
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;
}

Measured memory_bytes: 256
#include<stdio.h>
void swap(int *a,int *b){
  int work;
  work=*a;
  *a=*b;
  *b=work;
}

int main(){
  int i,j,n,c=0,flag;
  int a[100];
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);
  flag=1;
 
  while(flag){
   
    flag=0;
    for(j=n-1;j>0;j--){
      if(a[j]<a[j-1]){
	swap(&a[j],&a[j-1]);
	flag=1;
	c++;
      }
    }
  }
 for(i=0;i<n-1;i++) printf("%d ",a[i]);
 printf("%d\n",a[n-1]);
 printf("%d\n",c);
  
  
  return 0;
}



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

int main() {
    int x;
    int c = 1;
    while(1) {
       cin >> x;
       if(x == 0) break;
       cout << "Case " << c << ": " << x << endl;
       c++;
    }   
    return 0;
}


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

int input;

bool month(int a) {
  return (a >= 1 && a <= 12);
}

int main() {
  bool b, a;
  cin >> input;
  b = month(input / 100);
  a = month(input % 100);
  if(b && a) {
    cout << "AMBIGUOUS" << endl;
  } else if(b) {
    cout << "MMYY" << endl;
  } else if(a) {
    cout << "YYMM" << endl;
  } else {
    cout << "NA" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int min(int a,int b){return a>b ? b : a;}
int main(void){
   int n;
   char s[50][50] = {""};
   scanf("%d", &n);
   for (int i = 0; i < n; i++) {
      scanf("%s", s[i]);
   }
   for (int k = 0; k < 26; k++) {
      char chara = 'a' + k;
      int min_char = 1000;
      for (int i = 0; i < n; i++) {
         int cnt = 0;
         for (int j = 0; j < 50; j++) {
            if (chara - s[i][j]  == 0) {
               cnt++;
            }
         }
         min_char = min(min_char,cnt);
      }
      for (int i = 0; i < min_char; i++) {
         printf("%c",'a'+k);
      }
   }
}


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

typedef long long ll;
const int mod = 1000000007;
const int MAX_N = 100005;

ll fact[MAX_N];         // 階乗
ll ifact[MAX_N];        // 階乗の逆元

// x^nを求める繰り返し二乗法(累乗の高速化)
// フェルマーの小定理より、逆元を計算するときに用いる。
ll mod_pow(ll x, int n){
    if(n == 0)      return 1;

    ll res = 1;
    while(n > 0){
        if(n & 1)   res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }

    return res;
}

// 階乗とその逆元テーブルを(0-n)まで埋める
void table(int n){
    fact[0] = 1;    // i^0 = 1;
    for(int i = 1; i <= n; ++i){
        fact[i] = fact[i - 1] * i % mod;
    }

    // フェルマーの小定理を利用して、右端の逆元を求める
    // 階乗の(mod-2)乗
    ifact[n] = mod_pow(fact[n], mod - 2);

    // 逆元の性質を利用して、テーブルを埋める
    for(int i = n; i >= 1; --i){
        ifact[i - 1] = ifact[i] * i % mod;
    }
}

// nCrを求める
ll combination(int n, int r){
    if(n < 0 || r < 0 || n < r)     return 0;

    return (ll)fact[n] * ifact[r] % mod * ifact[n - r] % mod;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, id1 = 0, id2 = 0;
    cin >> n;
    vector<int> a(n+1), cnt(n+1, 0);
    for(int i = 0; i < n+1; ++i){
        cin >> a[i];
        ++cnt[a[i]];
        
        if(cnt[a[i]] == 2)      id2 = i;   
    }
    for(int i = 0; i < n+1; ++i){
        if(a[i] == a[id2]){
            id1 = i;
            break;
        }
    }
    
    table(n+2);
    
    // 重複している数字をxとして、xの左にある数字の個数
    // a = [...x.....x...]
    int num1 = id1;
    // xの右側にある数字の個数
    int num2 = n - id2;

    // 重複している数字：x
    for(int i = 1; i <= n+1; ++i){        // 数字をi個取る
        ll res = (ll)(combination(n + 1, i) - combination(num1 + num2, i - 1) + 2 * mod) % mod;
        
        cout << res << "\n";
    }
}

Measured memory_bytes: 3584
A,B,C,D,E,F = map(int, input().split())
f = list(input())
for i in range(len(f)):
    if f[i] == "E":
        A,B,C,D,E,F = D,B,A,F,E,C
    elif f[i] == "N":
        A,B,C,D,E,F = B,F,C,D,A,E
    elif f[i] == "S":
        A,B,C,D,E,F = E,A,C,D,F,B
    elif f[i] == "W":
        A,B,C,D,E,F = C,B,F,A,E,D

print(A)
        
        

Measured memory_bytes: 7704
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N, M;
        cin >> N >> M;
        //ll T = 1900;
        //ld ans = (N-M) * T + 2 * M * T * (powl(0.5, M) - N * powl(0.5, M*N+M));
        ll ans = intpow(2, M)  * (M * 1900 + (N-M) * 100);
        //ll x = round(ans);
        cout << ans << endl;
}

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

const int MOD = 998244353;

int put(int a, int b)
{
	int ans = 1;
	while (b) {
		if (b & 1)
			ans = 1LL * ans * a % MOD;
		a = 1LL * a * a % MOD;
		b /= 2;
	}
	return ans;
}

const int NMAX = 2e6;
int fact[NMAX], invfact[NMAX];

void precalc()
{
	fact[0] = 1;
	for (int i = 1; i < NMAX; i++)
		fact[i] = 1LL * i * fact[i - 1] % MOD;
	invfact[NMAX - 1] = put(fact[NMAX - 1], MOD - 2);
	for (int i = NMAX - 1; i >= 1; i--)
		invfact[i - 1] = 1LL * invfact[i] * i % MOD;
}

int comb(int a, int b)
{
	if (a < b || b < 0)
		return 0;
	return 1LL * fact[a] * invfact[b] % MOD * invfact[a - b] % MOD;
}

int main()
{
	ios_base::sync_with_stdio(0);
	precalc();

	int N, M;

	cin >> N >> M;

	int ans = 0;

	for (int nri = 0; nri <= min(N, M); nri++) {
		/// sunt nri impare
		int left = 3 * M - nri;
		if (left % 2 == 1)
			continue;
		left /= 2;
		int modurii = comb(N, nri);
		int modurip = comb(N + left - 1, N - 1);
		ans = (ans + 1LL * modurii * modurip) % MOD;
	}

	for (int toomuch = 2 * M + 1; toomuch <= 3 * M; toomuch++) {
		int moduri = comb(N + 3 * M - toomuch - 2, N - 2);
		ans = (ans - 1LL * moduri * N) % MOD;
	}

	if (ans < 0)
		ans += MOD;

	cout << ans << '\n';


	return 0;
}

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

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

    int count;
    if(S[0] == 'o') count++;
    if(S[1] == 'o') count++;
    if(S[2] == 'o') count++;

    cout << 700 + count*100 << endl;
}

Measured memory_bytes: 256
use std::io;

fn input(s: &mut String) -> bool{
    match io::stdin().read_line(s){
        Err(_) => false,
        Ok(_) => true,        
    }
}

fn main(){
    let mut s = String::new();
    let mut ans : i32 = 0;
    if input(&mut s) == false{
        println!("ng\n");
    }
    for c in s.chars() {
        if c == '-' {
            ans -= 1;
        } else if c == '+' {
            ans += 1;
        }
    }
    println!("{}",ans);
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int K, S;
    cin >> K >> S;
    int count=0;
    for(int i=0;i<=K;i++) {
      for(int j=0;j<=K;j++) {
        int k = S - i - j;
        if(0<=k && k<=K){count++;}
      }
    }
    cout << count << endl;
}

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

int main() {
  string s;
  cin >> s;
  int t = 0;
  for (auto e : s) t += e - '0';
  int n = s.size(), h = s.front() - '0', r = h + (n - 1) * 9;
  cout << r - (r != t) << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, t, x, y):
    ct = 0
    cx = 0
    cy = 0
    for i in range(N):
        r = t[i] - ct - abs(cx - x[i]) - abs(cy - y[i])
        if r < 0 or r & 1:
            return NO
        ct = t[i]
        cx = x[i]
        cy = y[i]
    return YES


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    t = [int()] * (N)  # type: "List[int]"
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        t[i] = int(next(tokens))
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    print(solve(N, t, x, y))

if __name__ == '__main__':
    main()


Measured memory_bytes: 11636
#include <bits/stdc++.h>
#define int long long
using namespace std;

class Pair
{
    public:
    int x; ;
    int h;
    
};

bool comp(Pair &a, Pair &b)
{
    return a.x<b.x;
}


signed main()
{
    ios_base::sync_with_stdio(0);
	int n; cin>>n;
	int d; cin>>d;
	int a; cin>>a;
	
	Pair arr[n];
	for(int i=0;i<n;i++)
	{
	    cin>>arr[i].x>>arr[i].h;
	}
	sort(arr,arr+n,comp);

	
	
	vector<Pair>vec;
	int start=0;
	int end=0;
	
	int ans=0;
	int destruction=0;
	for(int i=0;i<n;i++)
	{   
	    
	    while(end>start&&!(arr[i].x>=vec[start].x-d && arr[i].x<=vec[start].x+d ))
	    {
	        destruction=destruction-(vec[start].h)*a;
	        start++;
	    }
	    
	    arr[i].h-=destruction;
	    
	
	   if(arr[i].h>0)
	   {
	      
	      int quo=arr[i].h/a;
	      int rem=arr[i].h%a;
	      int cnt=quo;
	      if(rem>0)  cnt=quo+1;
	      
	      Pair temp;
	      temp.x=arr[i].x+d;
	      temp.h=cnt;
	      
	      vec.push_back(temp);
	      destruction+=(temp.h)*a;
	      end++;
	   }
	   
	   
	   
	   
	    
	}
	
	
    for(int i=0;i<end;i++)
    {
        ans+=vec[i].h;
       // cout<<vec[i].x<<" "<<vec[i].h<<endl;
    }
    
       
        
    cout<<ans<<endl;
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 9200
N,A,B,C,D=[int(i) for i in input().split()]
ul = [A + D*i for i in range(N)]
dl = [A + C*i for i in range(N)]
ur = [B + D*i for i in range(N)][::-1]
dr = [B + C*i for i in range(N)][::-1]
res = False
for i in range(N):
    if (dl[i]<= ur[i] and ur[i]<=ul[i]) or (dl[i]<=dr[i] and dr[i]<=ul[i]):
        res=True
print("YES" if res else "NO")


Measured memory_bytes: 102748
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	int n,i,j;
	ll m;
	scanf("%d %lld",&n,&m);
	int a[n];
	for(i=0;i<n;++i)		
	{
		scanf("%d",&a[i]);
		a[i]--;
	}
	int dest[64][n];
	for(i=0;i<n;++i)
	{
		dest[0][i]=a[i];
	}
	for(i=1;i<64;++i)
	{
		for(j=0;j<n;++j)
		{
			dest[i][j] = dest[i-1][dest[i-1][j]];	
		}	
	}
	int curr = 0;
	for(i=0;i<64;++i)
	{
		if(((1ll<<i)&m)!=0)
		{
			curr = dest[i][curr];
		}
	}
	printf("%d",curr+1);
}

Measured memory_bytes: 54568
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

# AB = sorted(AB, key=lambda x: x[1]-x[0]) # B-Aが小さい順にソート
AB = sorted(AB, key=lambda x: x[1]) # B-Aが同じ値の時はBが小さい順に並び替え
t = 0

for i in range(N):
    if t <= AB[i][1] - AB[i][0]: # B-A以下のとき
        t += AB[i][0]
        continue
    else:
        print('No')
        break
else:
    if t <= AB[N-1][1]:
        print('Yes')
    else:
        print('No')



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

int main(){
    int n; cin >> n;
    vector<int> v(n);
    rep(i, n-1){
        int x; cin >> x;
        v.at(--x)++;
    }
    rep(i, n) cout << v.at(i) << endl;
    return 0;
}


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;

map<int, int> n_mat={{1,2}, {2,5}, {3,5}, {4,4}, {5,5}, {6,6},{7,3},{8,7},{9,6}};

int main(){
  int N, M;cin>>N>>M;
  vi A;
  for (int i=0;i<M;++i){int a;cin>>a;A.push_back(a);}

  vi u(10,-1);
  for (int i=2;i<=7;++i){
    for(int m=0;m<M;++m){
      if(n_mat[A[m]]==i) u[i]=max(u[i], A[m]);
    }
  }

  vvi dp(N+10, vi(10, -1));
  dp[0]=vi(10,0);

  for (int i=0;i<=N;++i){
    for (int j=2;j<=7;++j){
      if(u[j]==-1) continue;
      int p=10-u[j];
      dp[i][p]++;dp[i][0]++;
      dp[i+j]=max(dp[i], dp[i+j]);
      dp[i][p]--;dp[i][0]--;
    }
  }

  for (int i=1;i<10;++i){
    for (int j=0;j<dp[N][i];++j){cout << 10-i;}
  }
  return 0;
} 

Measured memory_bytes: 896
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define gcd __gcd
#define lcm(a, b) ((a) * (b) / gcd((a), b))
#define all(x) x.begin(), x.end()
#define rep(i, x, n) for (ll i = x; i < n; i++)
#define fastio() ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0)
#define endl '\n'

typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> ii;
typedef vector<pair<int, int> > vii;

template <class T> inline T RD(T &a) {T x; cin >> x; return a = x;}

signed main()
{
//	freopen("CASTEL.inp", "r", stdin); freopen("CASTEL.out", "w", stdout);
    fastio();

    int k, a, b; cin >> k >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK";
            return 0;
        }
    }
    cout << "NG";
    return 0;
}


Measured memory_bytes: 3688
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7
const string SPACE = " ";

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

	}
	ll r;
	r = b%a;
	if (r == 0)return a;
	else return gcd(r, a);

}
//最大公約数

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//最小公倍数

ll MAX(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
//MAX

ll MIN(ll a, ll b) {

	if (a < b)return a;
	else return b;

}
//MIN

bool func(ll p) {

	if (p == 1)return false;
	else if (p == 2)return true;
	else {

		bool flag = true;
		for (int i = 2; i <= sqrt(p); i++) {

			if (p%i == 0) {

				flag = false;
				break;

			}

		}
		return flag;

	}

}
//素数判定,素数=true,合成数=false

int main() {

	string S;
	cin >> S;

	if (S == "zyxwvutsrqponmlkjihgfedcba")cout << -1 << endl;
	else if (S.size() == 26) {

		for (int i = 24; i >= 0; i--) {

			if (S[i] < S[i + 1]) {

				char yan = S[i];
				S.erase(S.begin() + i, S.end());
				bool flag[26];
				for (int j = 0; j < 26; j++)flag[j] = false;
				for (int j = 0; j < S.size(); j++) {

					flag[S[j] - 'a'] = true;

				}
				for (int j = yan - 'a' + 1; j < 26; j++) {

					if (!flag[j]) {

						S.push_back((char)('a' + j));
						break;

					}
				}

				break;

			}

		}
		cout << S << endl;

	}
	else {

		bool flag[26];
		for (int i = 0; i < 26; i++)flag[i] = false;
		for (int i = 0; i < S.size(); i++) {

			flag[S[i] - 'a'] = true;

		}
		for (int i = 0; i < 26; i++) {

			if (!flag[i]) {

				S.push_back((char)('a' + i));
				break;

			}

		}
		cout << S << endl;

	}

	return 0;
}

Measured memory_bytes: 256