akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

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

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

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

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}

void solve() {
    //const i64 mod = 1'000'000'007;

    i64 N;
    cin >> N;

    vector<i64> d(N);
    rep(i,0,N) cin >> d[i];

    sort(begin(d),end(d));

    i64 l,r;
    {
        // 半分以上になるギリギリライン
        i64 lb = 0, ub = inf;
        while (ub - lb > 1) {
            i64 mid = (lb + ub) / 2;
            i64 cnt = 0;
            rep(i, 0, N) {
                if (d[i] > mid) ++cnt;
            }
            if (2 * cnt >= N) lb = mid;
            else ub = mid;
        }
        l=lb;
    }
    {
        // 半分を超えるギリギリライン
        i64 lb = 0, ub = inf;
        while (ub - lb > 1) {
            i64 mid = (lb + ub) / 2;
            i64 cnt = 0;
            rep(i, 0, N) {
                if (d[i] > mid) ++cnt;
            }
            if (2 * cnt > N) lb = mid;
            else ub = mid;
        }
        r=lb;
    }

    cout << l-r << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		//????????£?????????????????§????????????????????????
		 Scanner sc = new Scanner(System.in);

		 //??°?????????
		while(true){
		//x??????
		int x = sc.nextInt();
		//y??????
		int y = sc.nextInt();
		//?????¶???  ??????0????????°?????? x??¨y???0????????????
		if(x ==0 && y ==0){
			
			
			break;
		}
		//?????¶??? x???????????????????°?????????´???
		if(x < y){
			System.out.println(x + " " + y);
			}else{
				System.out.println(y + " " + x);
			}
			
		}
	}
}

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

int main(void){
    ll n,a,b; cin >> n >> a >> b;
    vector<ll>x(n);
    for(int i=0;i<n;i++) cin >> x[i];
    ll ans = 0;
    for(int i=0;i<n-1;i++){
        if((x[i+1]-x[i])*a<=b) ans+= (x[i+1]-x[i])*a;
        else ans += b;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a > mod)a %= mod;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	ll n,k;
	cin>>n>>k;
	ll o = (n/k)+1;
	ll ans = n;
	ans = min(ans,abs(o*k-n));
	ans = min(ans,abs((o+1)*k-n));
	if(o >= 1)ans = min(ans,abs((o-1)*k-n));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#include <cmath>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int N;
pi A[100000], B[100000];
int to[100000];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    rep(i,N) {
        cin >> A[i].first;
        A[i].second = i;
    }
    rep(i,N) {
        cin >> B[i].first;
        B[i].second = i;
    }
    sort(A, A+N);
    sort(B, B+N);
    rep(i,N) {
        if (A[i].first > B[i].first) {
            cout << "No" << endl;
            return 0;
        }
    }
    for (int i = 1; i < N; i++) {
        if (A[i].first <= B[i-1].first) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    rep(i,N) {
        to[A[i].second] = B[i].second;
    }
    int cnt = 0;
    int now = 0;
    while (true) {
        now = to[now];
        cnt++;
        if (now == 0) break;
    }
    if (cnt == N) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 2176
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

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

	bool sa = false;
	string t, u;
	for (int i = 0; i < s.length(); i++)
	{
		if (!sa)
		{
			if (s.substr(i, 1) == "A")
			{
				sa = true;
				u += s.substr(i, 1);
			}
		}
		else
		{
			u += s.substr(i, 1);
			if (s.substr(i, 1) == "Z")
			{
				t += u;
				u = "";
			}
		}
	}

	cout << t.length() << endl;
}

Measured memory_bytes: 904
use std::io::stdin;

fn main() {
    let mut n = {
        let mut buf = String::new();
        stdin().read_line(&mut buf);
        let mut i = buf.split_whitespace();
        i.next().unwrap().parse::<i64>().unwrap()
    };
    let mut name: Vec<u8> = Vec::new();
    while n != 0 {
        let c = (n - 1) % 26;
        n = (n - 1) / 26;
        name.push(b'a' +  c as u8);
    }
    name.reverse();
    let str: String = String::from_utf8(name).unwrap();
    println!("{}", str);
}


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

int main()
{
  int n, k;
  char s[20];
  list<int> L;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
  {
    scanf("%s", s);
    if (s[0] == 'i')
    {
      scanf("%d", &k);
      L.push_front(k);
    }
    else if (s[6] == 'F')
    {
      L.pop_front();
    }
    else if (s[6] == 'L')
    {
      L.pop_back();
    }
    else
    {
      scanf("%d", &k);
      for (list<int>::iterator it = L.begin(); it != L.end(); it++)
      {
        if (*it == k)
        {
          L.erase(it);
          break;
        }
      }
    }
  }
  int i = 0;
  for (list<int>::iterator it = L.begin(); it != L.end(); it++)
  {
    if (i++)
      cout << ' ' << *it;
    else
      cout << *it;
  }
  cout << endl;
}


Measured memory_bytes: 34404
use std::io::Read;
use std::collections::HashMap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    
    let mut iter = buf.lines();
    iter.next();
    
    let mut hm = HashMap::new();
    let mut count = 0;
    
    for l in iter {
        count += 1;
        let mut es = l.split_whitespace();
        es.next();
        for e in es {
            let mut val = 1;
            if let Some(&v) = hm.get(e) {
                val += v;
            }
            hm.insert(e, val);
        }
    }
    
    println!("{}", hm.values().filter(|&&v| v == count).count());
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<" ";}
#define dumpl(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
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; }

signed main() {
	string s; cin >> s;
	int ans = 0;
	rep(i, 0, s.size() / 2) {
		int j = s.size() - 1 - i;
		if (s[i] == '('&&s[j] == ')')continue;
		if (s[i] == ')'&&s[j] == '(')continue;
		if (s[i] == 'w'&&s[j] == 'w')continue;
		if (s[i] == 'i'&&s[j] == 'i')continue;
		ans++;
	}
	if (s.size() % 2)ans += s[s.size() / 2] == '(' || s[s.size() / 2] == ')';
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3180
import java.util.*;
public class Main {

	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		int INF = Integer.MAX_VALUE/2;
		StringBuilder ans = new StringBuilder();
		Scanner sc = new Scanner(System.in);
		int D = Integer.parseInt(sc.next());
		int[] c = new int[26];
		Arrays.setAll(c, i -> Integer.parseInt(sc.next()));
		int[][] s = new int[D][26];
		for(int i = 0; i < D; i++)
			Arrays.setAll(s[i], x -> Integer.parseInt(sc.next()));
		sc.close();
		int[] con = new int[D];
		Map<Integer, TreeSet<Integer>> used = new HashMap<>();
		for(int i = 0; i < 26; i++) {
			used.put(i, new TreeSet<>());
			used.get(i).add(-1);
		}
		for(int d = 0; d < D; d++) {
			int max = -INF, now = 0;
			for(int i = 0; i < 26; i++) {
				int temp = 0;
				temp += s[d][i];
				for(int j = 0; j < 26; j++)
					if(i != j)
						temp -= c[j] * (d - used.get(j).last());
				if(max < temp) {
					max = temp;
					now = i;
				}
			}
			con[d] = now;
			used.get(now).add(d);
		}
		for(int i = 0; i < 26; i++)
			used.get(i).add(D);
		Random r = new Random();
		while(true) {
			int d = r.nextInt(D);
			for(int q = 0; q < 26; q++) {
				int temp = 0;
				temp -= s[d][con[d]];
				temp += s[d][q];
				temp -= c[con[d]] * (used.get(con[d]).ceiling(d) - d) * (d - used.get(con[d]).lower(d));
				temp += c[q] * (d - used.get(q).lower(d)) * (used.get(q).ceiling(d) - d);
				if(temp > 0) {
					con[d] = q;
					used.get(con[d]).remove(d);
					used.get(q).add(d);
				}
			}
			if(System.currentTimeMillis() - start > 1850)
				break;
		}
		for(int i : con)
			ans.append((i+1) + "\n");
		System.out.println(ans);
	}

}


Measured memory_bytes: 69320
#include <iostream>

int main(int argc, char const *argv[])
{
	int table[3],temp;
	std::cin >> table[0] >> table[1] >> table[2];

	if (table[0]>table[1]) {
		temp = table[0];
		table[0] = table[1];
		table[1] = temp;
	}
	if (table[1]>table[2]) {
		temp = table[1];
		table[1] = table[2];
		table[2] = temp;
	}
	if (table[0]>table[1]) {
		temp = table[0];
		table[0] = table[1];
		table[1] = temp;
	}

	std::cout << table[0] << " " << table[1] << " " << table[2] << std::endl;

	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
using namespace atcoder;
void Main()
{
    ll n, m;
    cin >> n >> m;

    vector<ll> a(m), b(m);
    rep(i, m) cin >> a[i] >> b[i];
    scc_graph g(n);
    rep(i, m) {
        g.add_edge(a[i], b[i]);
    }

    auto scc = g.scc();
    put(scc.size());
    for (auto v: scc) {
        cout << v.size();
        for (int x: v) {
            cout << " " << x;
        }
        cout << endl;
    }
}
signed main(){ Main();return 0;}

Measured memory_bytes: 47940
N,M,K = map(int,input().split())
mod = 998244353

if M == 1 and K == N-1:
    print(1)
    exit()

A = [0]*(K+1)
A[0] = (M*pow(M-1,N-1,mod)) % mod

for i in range(K):
    A[i+1] = (A[i]*(N-1-i)*pow(M-1,mod-2,mod)*pow(i+1,mod-2,mod)) % mod

ans = A[0]
for i in range(K):
    ans = (ans + A[i+1]) % mod

print(ans)

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

int main() {
  int N,Ans=0;
  cin>>N;
  for (int i = 1; i < N; i++){
    for (int j = 1; j*j<=N-i;j++){
      if((N-i)%j==0){if(j==sqrt(N-i)){Ans++;}else{Ans++;Ans++;}}
    }
  }
  cout<<Ans<<endl;
}


Measured memory_bytes: 3676
#include <iostream>
#include <math.h>
#include <iomanip>

int main() {
	int R;
	std::cin >> R;
	const double pi = acos(-1.0);
  	double answer = 2 * pi * R;
  	std::cout << std::setprecision(20) << std::fixed << answer << std::endl;
  	
  	return 0;
}

Measured memory_bytes: 3792
#include <stdio.h>
#define y 1000000007
int main(void){
  int n,m,i;
  long dog=1,mon=1,ans;
  scanf("%d%d",&n,&m);
  if (n-m>1||m-n>1){
    printf("0\n");
    return 0;
  }
  for (i=2;i<=n;i++) dog=(dog*i)%y;
  for (i=2;i<=m;i++) mon=(mon*i)%y;
  ans=dog*mon%y;
  if (n==m) ans=ans*2%y;
  printf("%ld\n",ans);
  return 0;
}

Measured memory_bytes: 128
//#pragma GCC optimize(3)
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<utility>
#include<iterator>
#include<iomanip>
using namespace std;
#define lowbit(x) x&(-x)
typedef long long ll;
typedef long double lb;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const int maxn = 100005;
int read();
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    std::vector<string> v(maxn);
    map<string,int> mp;
    string str;
    int n;
    cin>>n;
    for(int i = 0;i<n;i++)
    {
    	cin>>str;
    	sort(str.begin(),str.end());
    	v.at(i) = str;
    	mp[str]++;
    }
    ll ans = 0;
    for(int i = 0;i<n;i++)
    {
    	string s = v.at(i);
    	if(mp[s]>0)ans+=mp[s]-1;
    	mp[s]--;
    }
    cout<<ans<<endl;

    return 0;
}
inline int read()
{
	int x = 0,w = 0;
	char ch = 0;
	while(!isdigit(ch)){
		w |= (ch == '-');
		ch = getchar();
	}
	while(isdigit(ch)){
		x = (x<<3)+(x<<1)+(ch^48);
		ch = getchar();
	}
	return w?-x:x;
}


Measured memory_bytes: 16640
A,B=map(int,input().split())
S=input()
for s in S[:A]:
    if s not in "0123456789":
        print("No")
        exit()
if S[A]!="-":
    print("No")
    exit()
for s in S[A+1:]:
    if s not in "0123456789":
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-6;

using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	pair<int, int> c[100];
	for (int i = 0; i < n; ++i)
		scanf("%d %d", &c[i].first, &c[i].second);

	int d[100][100];
	for (int i = 0; i < 100; ++i)
		for (int j = 0; j < 100; ++j)
			d[i][j] = INT_MAX;
	for (int i = 0; i < 100; ++i)
		d[i][i] = 0;

	for (int k = 1; k < n; ++k)
		for (int i = 0; i < n-k; ++i)
			for (int j = i; j < i+k; ++j)
				d[i][i+k] = min(d[i][i+k]
			, d[i][j]+d[j+1][i+k] + c[i].first*c[j].second*c[j+1].first*c[i+k].second);

	printf("%d\n", d[0][n-1]);
	return 0;
}

Measured memory_bytes: 0
import qualified Data.ByteString.Char8 as BS

readString = map BS.unpack . BS.words

getString = readString <$> BS.getLine

calcDetail :: String -> Bool
calcDetail ss = a == b
  where
    (a, b) = splitAt (length ss `div` 2) ss

calc :: String -> Int
calc [s] = 0
calc (s1 : s2 : ss)
  | odd (length (s1 : s2 : ss)) = 1 + calc (s2 : ss)
  | calcDetail (s1 : s2 : ss) = 0
  | otherwise = 2 + calc ss

main = do
  [s] <- getString
  print $ length s - (calc (tail (reverse s)) + 1)


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);	
  	
  	string s;
  	cin >> s;
  	
  	int n = s.size();
    string rs = s;
  	reverse(all(rs));
  	int x =0;
  	int rn = n;
  	rep(i,n){
    	if(i>=rn-1){break;}
      	if(s[i]!=rs[i]) x++;
      	rn--;
    }
  	cout << x << endl;
  	return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict, deque

import heapq
import math


class Heapq:
    def __init__(self, arr, desc=False):
        if desc:
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)

    def pop(self):
        return heapq.heappop(self.hq) * self.sign

    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)

    def top(self):
        return self.hq[0] * self.sign

    def sum(self):
        return -sum(self.hq)


def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    heap = Heapq(A, True)

    for _ in range(M):
        a = heap.pop()
        heap.push(math.floor(a / 2))

    print(heap.sum())


if __name__ == '__main__':
    main()


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

int main()
{
    int N;
    cin >> N;
    int sum = 1;
    int md = 1e9 + 7;
    for (int i = 2; i <= N; i++) {
        sum = sum * 1LL * i % md;
    }
    cout << sum;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm> 
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include  <ctime>
#include <iomanip>
using namespace std;

#define ll                    long long int
#define ull                   unsigned long long int
#define loop(i,a,b)           for(int i=(int)a;i<(int)b;++i)
#define rloop(i,a,b)          for(int i=(int)a;i<=(int)b;++i)
#define loopl(i,a,b)          for(ll i=(ll)a;i<(ll)b;++i)
#define loopr(i,a,b)          for(int i=(int)a;i>=(int)b;--i)
#define count_1(n)            __builtin_popcountll(n)
#define pb                    push_back
#define eb                    emplace_back
#define ab(a)                 (a<0)?(-1*a):a
#define pc                    putchar
#define gc                    getchar
#define mset(a,b,c)           loop(i,0,b) a[i]=c
#define mp                    make_pair
#define itoc(c)               ((char)(((int)'0')+c))
#define all(p)                p.begin(),p.end()
#define max(x,y)              ((x>y)?x:y)
#define min(x,y)              ((x<y)?x:y)
#define mid(s,e)              (s+(e-s)/2)
#define vi                    vector<int>
#define vvi                   vector<vector<int>>
const ll MOD = 1000000007;

ll modpow(ll a, ll b, ll mod) { ll res = 1; for (; b; b >>= 1) { if (b & 1)res = res * a; res%=mod; a = a * a; a%=mod; }return res; }
//ll p(ll a, ll b) { ll res = 1; for (; b; b >>= 1) { if (b & 1)res = res * a;a = a * a; }return res; }

vector<int> parent(300000);
void bfs(vvi& g) {
    queue<int> p;
    p.push(0);
    while(!p.empty()) {
        int node = p.front();
        for(int i : g[node]) { if(parent[i]!=-1) continue; parent[i] = node; p.push(i); }
        p.pop();
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    /* code */
    int n,m; cin >> n >> m;
    vvi g(n);
    loop(i,0,n) parent[i] = -1;
    loop(i,0,m) { int x,y; cin >> x >> y; x--; y--; g[x].pb(y); g[y].pb(x); }
    bfs(g);
    int flag = 1;
    loop(i,1,n) if(parent[i] == -1) { flag = 0; break; }
    if(!flag) {
        cout << "No\n";
    }
    else {
        cout << "Yes\n";
        loop(i,1,n) cout << (parent[i] + 1) << "\n";
    }
    /* end code */
}

Measured memory_bytes: 10836
import sys
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache
sys.setrecursionlimit(10**6)
@lru_cache(maxsize=None)
def rec(v):
    res=0
    for nv in graph[v]:
        res=max(res,rec(nv)+1)
    return res
def main():
    n,m=map(int,input().split())
    XY=[tuple(map(int,input().split())) for i in range(m)]
    global graph
    graph=[[]for _ in range(n)]
    for x,y in XY:
        graph[x-1].append(y-1)
    ans=0
    for v in range(n):
        ans=max(ans,rec(v))
    print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 150728
#include<stdio.h>
#include<string.h>
 
#define M 1000000
#define L 14
 
char H[M][L];
 
int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if( ch == 'T') return 4;
}
 
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}
 
int h1(int key){ return key % M;}
int h2(int key){ return 1 + key % (M - 1);}
 
int find(char str[]){
  long long trip;
  int i = 0;
  long long sum = getKey(str);
 
  while(1){
    trip = (h1(sum)+ i * h2(sum)) % M;
    if(strcmp(H[trip], str) == 0) return 1;
    if(H[trip][0] == '\0') return 0;
    i++;
  }
  return 0;
}
 
void insert(char str[]){
  int  i = 0;
  long long ago;
  long long sum = getKey(str);
 
  while(1){
    ago = (h1(sum)+ i * h2(sum)) % M;
    if(H[ago][0] == '\0' || strcmp(H[ago],str) == 0){
      strcpy(H[ago], str);
      break;
    }
    i++;
  }
}
 
int main(){
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);
    if ( com[0] == 'i' ){
      insert(str);
    } else {
      if (find(str)){
    printf("yes\n");
      } else {
    printf("no\n");
      }
    }
  }
  return 0;
}

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

using namespace std;

#define fr(i,s,e) for(i=s;i<e;i++)

int main() {
    int mn=INT_MAX;
    int n,i,x,t=0,res=0;
    cin>>n>>x;
    int m[n];
    fr(i,0,n)
   { cin>>m[i];
    
   // fr(i,0,n){
    t=t+m[i];
    mn=min(mn,m[i]);
    }
    t=x-t;
   res= n+(t/mn);
   cout<<res;
return 0;
}


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

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if (A == C) {
		if (B >= D)cout << D - C << endl;
		else cout << B - C << endl;
	}
	else {
		if (A < C) {
			if (B <= C)cout << 0 << endl;
			else {
				if (D <= B)cout << D - C << endl;
				else cout << B - C << endl;
			}
		}
		else {
			if (D <= A)cout << 0 << endl;
			else {
				if (D <= B)cout << D - A << endl;
				else cout << B - A << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
X = list(map(int,input().split()))
X_s = sorted(X)
l1 = X_s[N//2 - 1]
l2 = X_s[(N//2)+1 - 1]
for i in X:
	if i <= l1:
		print(l2)
	else:
		print(l1)

Measured memory_bytes: 25620
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu) FUNC(printe) FUNC(printe0);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    string t; cin >> t;
    int n = t.size();
    vector<int> accs(n + 2);
    for(int i = n - 1; i >= 0; i--){
        accs[i] = accs[i + 2] + (t[i] == '1');
    }
    ll ans = 0;
    int idx = 0;
    // int size = n;
    for(int i = 0; i < n; i++){
        ans += accs[idx];
        bool done = false;
        while(idx < (int)t.size()){
            if(t[idx] - '0' == 0){
                idx++;
                // size--;
                done = true;
                break;
            }
            // ans += (size - 1) - idx;
            ans += (t.size() - 1) - idx;
            idx += 2;
        }
        if(!done){
            t.pop_back();
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 4064
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1000000009;
const ll LINF = 1e18;

vector<int> to[100001];

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  queue<int> q;
  vector<int> dist(n, INF);
  vector<int> pre(n, -1);
  q.push(0);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int u : to[v]) {
      if (dist[u] != INF) continue;
      dist[u] = dist[v] + 1;
      pre[u] = v;
      q.push(u);
    }
  }

  cout << "Yes" << endl;
  for (int i = 0; i < n; ++i) {
    if (i == 0) continue;
    int ans = pre[i];
    ++ans;
    cout << ans << endl;
  }
}


Measured memory_bytes: 10180
#include<stdio.h>
#include<algorithm>
typedef long long int llint;
using namespace std;
int main(){
    llint n,c;
    scanf("%lld%lld",&n,&c);
    llint x[n],v[n];
    for(int i=0;i<n;i++)
        scanf("%lld%lld",&x[i],&v[i]);
    llint r[n],l[n];
    llint r2[n],l2[n];
    r[0]=max(v[0]-x[0],0ll);
    r2[0]=max(v[0]-2*x[0],0ll);
    llint cal=v[0];
    for(int i=1;i<n;i++){
        cal=cal+v[i];
        r[i]=max(r[i-1],cal-x[i]);
        r2[i]=max(r2[i-1],cal-2*x[i]);
    }
    l[n-1]=max(v[n-1]-c+x[n-1],0ll);
    l2[n-1]=max(v[n-1]-2*c+2*x[n-1],0ll);
    cal=v[n-1];
    for(int i=n-2;i>=0;i--){
        cal=cal+v[i];
        l[i]=max(l[i+1],cal-c+x[i]);
        l2[i]=max(l2[i+1],cal-2*c+2*x[i]);
    }
    llint ans=0;
    ans=max(ans,r[n-1]);
    ans=max(ans,l[0]);
    for(int i=0;i<n-1;i++){
        ans=max(ans,l2[i+1]+r[i]);
        ans=max(ans,l[i+1]+r2[i]);
    }
    printf("%lld\n",ans);
}

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

int main() {
  int N,M = 0;
  bool a = true;
  
  cin >> N;//1900
  
  while(a){
      M = N - 1000;
      N = M;//900
    //   cout << M << endl;
      if(0 > N || N == 0){
          cout << abs(M) << endl;
          a = false;
      }
  }
  
  


}


Measured memory_bytes: 3528
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main()
{
    char s[10];
    scanf("%s", s);
    if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3])
        printf("Yes\n");
    else if (s[0] == s[2] && s[2] != s[1] && s[1] == s[3])
        printf("Yes\n");
    else if (s[0] == s[3] && s[3] != s[1] && s[1] == s[2])
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()
T1 = []
T2 = []
if N%2 == 1:
  print("No")
else:
  for i in range(int(N/2)):
    T1.append(S[i])
  for i in range(int(N/2),N):
    T2.append(S[i])
  if T1 == T2:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 3060
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>

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

using namespace std;

typedef long long ll;

const ll INF=1LL<<61;

const char *C="()*+-&^|0123456789";

int idx;
string s;
bool flag;

ll number(){
	ll a=0;
	while(idx<s.length() && isdigit(s[idx])) a=10*a+(s[idx++]-'0');
	return a;
}

ll expr(){
	vector<ll> a;
	vector<char> op;
	bool first=true;
	while(idx<s.length() && s[idx]!=')'){
		if(!first){
			if(!strchr("*+-&^|",s[idx])) flag=false;
			op.push_back(s[idx]);
			idx++;
		}
		first=false;

		if(idx==s.length()){
			flag=false;
			return 0;
		}

		if('1'<=s[idx] && s[idx]<='9'){
			a.push_back(number());
		}
		else if(s[idx]=='('){
			idx++;
			a.push_back(expr());
			if(idx==s.length() || s[idx]!=')') flag=false;
			idx++;
		}
		else{
			flag=false;
		}
	}

	if(a.size()!=op.size()+1) flag=false;

	if(!flag) return 0;

	while(!op.empty()){
		if(count(op.begin(),op.end(),'*')>0){
			int i=find(op.begin(),op.end(),'*')-op.begin();
			a[i]*=a[i+1];
			a.erase(a.begin()+i+1);
			op.erase(op.begin()+i);
			continue;
		}
		if(count(op.begin(),op.end(),'+')+count(op.begin(),op.end(),'-')>0){
			int i=min(find(op.begin(),op.end(),'+')-op.begin(),find(op.begin(),op.end(),'-')-op.begin());
			if(op[i]=='+') a[i]+=a[i+1];
			else           a[i]-=a[i+1];
			a.erase(a.begin()+i+1);
			op.erase(op.begin()+i);
			continue;
		}
		if(count(op.begin(),op.end(),'&')>0){
			int i=find(op.begin(),op.end(),'&')-op.begin();
			a[i]&=a[i+1];
			a.erase(a.begin()+i+1);
			op.erase(op.begin()+i);
			continue;
		}
		if(count(op.begin(),op.end(),'^')>0){
			int i=find(op.begin(),op.end(),'^')-op.begin();
			a[i]^=a[i+1];
			a.erase(a.begin()+i+1);
			op.erase(op.begin()+i);
			continue;
		}
		if(count(op.begin(),op.end(),'|')>0){
			int i=find(op.begin(),op.end(),'|')-op.begin();
			a[i]|=a[i+1];
			a.erase(a.begin()+i+1);
			op.erase(op.begin()+i);
			continue;
		}
	}
	return a[0];
}

bool is_valid(const string &s){
	idx=0;
	::s=s;
	flag=true;
	expr();
	if(idx<s.length()) flag=false;
	return flag;
}

ll eval(const string &s){
	idx=0;
	::s=s;
	flag=true;
	return expr();
}

vector<string> next_valid_expr(const string &s){
	int n=s.length();
	vector<string> res;
	rep(i,n+1) rep(j,18) {
		string t=s.substr(0,i)+C[j]+s.substr(i,n-i);
		if(is_valid(t)) res.push_back(t);
	}
	rep(i,n){
		string t=s.substr(0,i)+s.substr(i+1,n-i-1);
		if(is_valid(t)) res.push_back(t);
	}
	return res;
}

int main(){
	while(1){
		int n;
		string s; cin>>n>>s;
		if(n==0) break;

		ll ans=-INF;
		vector<string> S=next_valid_expr(s);
		if(n%2==1){
			rep(i,S.size()) ans=max(ans,eval(S[i]));
		}
		else{
			rep(i,S.size()){
				ll tmp=INF;
				vector<string> T=next_valid_expr(S[i]);
				rep(j,T.size()) tmp=min(tmp,eval(T[j]));
				ans=max(ans,tmp);
			}
		}
		cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 1252
n = int(input())
nbase = n+0
if n % 2 == 1:
    ans = 0
else:
    ns = 0
    while n != 0:
        n = n//5
        ns += 1

    nsa = ns - 1
    ans = 0
    for i in range(nsa,0,-1):
        o = nbase//(5**i)
        ans += o//2

print(ans)

Measured memory_bytes: 38384
#include<cstdio>
#define inf 2000000000
int n,k;
int h[100002]={100000},f[100002]={};
int min(int a,int b)
{
	return a<b? a:b;
}
int max(int a,int b)
{
	return a>b? a:b;
}
int abs(int x)
{
	return x<0? -x:x;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&h[i]);
	for(int i=2;i<=n;i++)
	{
		f[i]=inf;
		for(int j=max(i-k,1);j<i;j++)
			f[i]=min(f[i],f[j]+abs(h[i]-h[j]));
	}
	printf("%d",f[n]);
	return 0;
}

Measured memory_bytes: 896
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
 
struct line
{
	ll a, b;
	  line(ll m, ll c)
	{
		a = m;
		b = c;
	}
	ll operator[] (int x)
	{
		return a * x + b;
	}
	double operator*(line const &o)
	{
		return double(b - o.b) / (o.a - a);
	}
};
 
int main()
{
	cin.tie(0);
	cin.sync_with_stdio(0);
 
	int n;
	ll c;
	cin >> n >> c;
	
	vector<ll> h(n);
	for(auto& x: h)
	  cin >> x;
	
	vector<ll> dp(n);
	
	deque<line> d;
	d.emplace_back(-2*h[0], dp[0] + h[0] * h[0]);
	for(int i = 1; i < n; ++i) {
	  auto x = h[i];
	  while(d.size() > 1 && d[0][x] >= d[1][x])
	    d.pop_front();
	  dp[i] = d.front()[x] + (x * x + c);
	  auto l = line(-2*x, dp[i] + x * x);
	  while(d.size() > 1 && (d.back() * d[d.size() - 2u]) >= (l * d[d.size() - 2u]))
	    d.pop_back();
	  d.emplace_back(l);
	}
	
	cout << dp.back();
}

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

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)

#define si(d)  scanf("%d",&d)
#define sll(d) scanf("%lld",&d)
#define pin(d) printf("%d\n",d)
#define pln(d) printf("%lld\n",d)
#define nl 	   printf("\n")

#define ll  long long
#define ull unsigned long long

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define vi      vector<int>
#define pii     pair<int,int>
#define piii    pair<pair<int,int>,int>
#define all(v)  v.begin(), v.end()

#define chalne_de continue
int mod = 1000000007;
const int N = 1000005;

// gcd
ll gcd(ll a , ll b)
{
    if ( b == 0)
    return a;
    return gcd( b, a % b);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int x = max(a,c);
    int y = min(b,d);
    cout << max(y - x,0) ;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(final String[] args) {
    final Scanner scanner = new Scanner(System.in);

    final int A = scanner.nextInt();
    final int B = scanner.nextInt();
    final int C = scanner.nextInt();
    final int K = scanner.nextInt();

    if (A >= K) {
      System.out.println(K);
      return;
    }

    if (A + B < K) {
      System.out.println(A - (K - (A + B)));
    } else {
      System.out.println(A);
    }
  }
}


Measured memory_bytes: 35760
#include <stdio.h>

char a[510][510];

int main() {

	int N;

	scanf("%d", &N);

	int i, j;

	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) {
			scanf(" %c", &a[i][j]);
		}
	}

	int c = 0;
	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) {
			if (a[j][i] == '.') { 
				c++;
				break;
			}
		}
	}

	int impossible = 0;
	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) {
			if (a[i][j] == '.') { impossible++; }
		}
	}

	int ans = 114514;

	if (impossible==N*N) { printf("-1\n"); }
	else { 
		int x;
		for (i = 0; i < N; i++) {
			x = 0;
			for (j = 0; j < N; j++) {
				if (a[i][j] == '.') { x++; }
			}
			int cnt = 0;
			for (j = 0; j < N; j++) {
				if (a[j][i] == '#') { cnt++; }
			}
			if (cnt == 0) {
				x++;
			}
			if (ans > x) {
				ans = x;
			}
		}
		printf("%d\n", c + ans);
	}

	return 0;
}

Measured memory_bytes: 384
import sys
import collections

n = int(input())
a = collections.Counter(list(map(int, sys.stdin.readline().split())))

q = [0, 0]
for v, k in a.items():
    if k >= 4:
        q.append(v)
    if k >= 2:
        q.append(v)
q.sort()
print(q[-1]*q[-2])

Measured memory_bytes: 18728
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
	if(abs(a-b)==1) return (ll)1;
	if(a==0) return b;
	return gcd(b%a,a);
}
int main()
{
	int T;cin>>T;
	ll a,b,c,d;
	while(T--)
	{
		cin>>a>>b>>c>>d;
		if(b>d || b>a) 
		{
			cout<<"No"<<endl;
			continue;
		}
		ll x=(a-c)/b;
		if(x*b!=a-c) x++;
		a-=x*b;
		if(a<0) 
		{
			cout<<"No"<<endl;
			continue;
		}
		if(gcd(b,d)+c>=b) 
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

ll A[3010][3010];
ll dp[3010][3010][4];

int main(){
  ll r,c,k;
  cin>>r>>c>>k;
  

  rep(i,3010){
    rep(j,3010) A[i][j]=0;
  }
  
  ll x,y,z;
  rep(i,k){
    cin>>x>>y>>z;
    A[x][y]=z;
  }
  
  rep(i,3010){
    rep(j,3010){
      rep(k,4) dp[i][j][k]=0;
    }
  }
  
  for(int i=1;i<=r;i++){
    for(int j=1;j<=c;j++){
      for(int k=0;k<=3;k++){
        if(A[i][j]==0){
          if(k==0) dp[i][j][k]=max(max(max(dp[i-1][j][0],dp[i][j-1][k]),
                                   max(dp[i-1][j][1],dp[i-1][j][2])),dp[i-1][j][3]);
          else dp[i][j][k]=dp[i][j-1][k];
        }
        else{
          if(k==0) dp[i][j][k]=max(max(max(dp[i-1][j][0],dp[i][j-1][k]),
                                   max(dp[i-1][j][1],dp[i-1][j][2])),dp[i-1][j][3]);
          else if(k==1) dp[i][j][k]=max(max(max(dp[i][j-1][k],dp[i][j-1][k-1]+A[i][j]),
                                        max(dp[i-1][j][0],dp[i-1][j][1])+A[i][j]),
                                        max(dp[i-1][j][2],dp[i-1][j][3])+A[i][j]);
          else dp[i][j][k]=max(dp[i][j-1][k],dp[i][j-1][k-1]+A[i][j]);
        }
      }
    }
  }
  ll ans=0;
  rep(i,4){
    ans=max(ans,dp[r][c][i]);
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 357496
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

int main() {
	ios_base::sync_with_stdio( false );

	char a, b;
	cin >> a >> b;
	string x( b - '0', a );
	string y( a - '0', b );
	cout << min( x, y ) << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	string S;
	cin >> S;
	int Z = S.size();
	int p = 0;
	int m = 0;
	rep(i, Z) {
		if (S[i] == '+') {
			p++;
		}
		else {
			m++;
		}
	}
	cout << p - m << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi atan(1.0)*4
#define pb(x) push_back(x)
#define in(x) insert(x)
#define fl(x,y) for(ll i=x;i<y;i++)
#define vi vector<long long>
#define vs  vector<string>
#define vp(vi,x) cin>>x; vi.pb(x);
string en="\n";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define clr clear()
#define sqr(a) (a*a)
#define mk make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
/*bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
*/
//bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int main()
{
    ll a,b,c,t,n,p,q,r,y,yy,sum,ct=0,flag=0;
    string s,s1,s2,s3;
    set<ll>st;
    char ch;
    map<ll,ll>mp;
    deque<char>d1,d2,d3;
    vector<ll>v,vv,vz;
    cin>>s;
    ct=0;
    for(ll i=0;i+1<s.size();i++)
    {
       if(s[i]!=s[i+1]) ct++;
    }
    cout<<ct<<endl;
}






Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,y;
	cin>>x>>y;
	if(x%y==0)
	{
		cout<<-1;		
	}
	else
	{
		for(int i=x*2;true;i+=x)
		{
			if(i%y!=0)
			{
				cout<<i;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define fi first
#define se second

#define INF 2147483600

#define END {cout<<"Impossible"<<endl; return 0;}

int main(){
  int n;
  cin>>n;
  vector<int> vec(n);
  rep(i,n)scanf("%d", &vec[i]);

  vector<int> cnt(101,0);
  rep(i,n) cnt[vec[i]]++;
  sort(all(vec));

  int mx = vec[n-1]; // max element 木の直径

  rep(i,mx/2) if(cnt[i]!=0) END;

  if(mx%2==0){ //中心はひとつ
    if(cnt[mx/2]!=1) END;
  } else {
    if(cnt[mx/2]!=0 || cnt[mx/2+1]!=2) END;
  }

  for(int i=mx/2+1; i<=mx; i++) if(cnt[i]<2) END;

  cout<<"Possible"<<endl;

  return 0;
}


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

using namespace std;
typedef long long ll;


int main()
{ 
    int a, b ,k ;
    cin >> k >> a >> b;
    int t = b/k;
    t *= k;
    if(t >= a)
    cout << "OK";
    else cout << "NG";
 return 0;
}


Measured memory_bytes: 3536
#include <iostream>

using namespace std;

int main(void)
{
    int A, B;

    cin >> A >> B;

    if(A==B){
        cout << "Draw" << endl;
    }

    else if(A==1){
        cout << "Alice" << endl;
    }
    
    else if(B==1){
        cout << "Bob" << endl;
    }

    else if(A > B){
        cout << "Alice" << endl;
    }

    else{
        cout << "Bob" << endl;
    }

    return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> mul(n + 1, 0);
  rep(i, n) mul[i + 1] = mul[i] + a[i];
  for (int i = k + 1; i <= n; i++) {
    ll mul1 = mul[i] - mul[i - k];
    ll mul2 = mul[i - 1] - mul[i - 1 - k];
    if (mul1 > mul2) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 6392
import math
import string
import collections
from collections import Counter
from collections import deque


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n = int(input())
h = readints()
dp = [10**9]*(2*n)
dp[0] = 0
for i in range(1, n):
    dp[i] = min(dp[i], dp[i-1]+abs(h[i]-h[i-1]))
    if i > 1:
        dp[i] = min(dp[i], dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])


Measured memory_bytes: 14740
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double

int main() {
    ll N;
    cin >> N;
    int Q;
    cin >> Q;
    set<pair<ll, ll>> tate, yoko;
    tate.insert({-1, N-2});
    yoko.insert({-1, N-2});
    ll ans = (N-2)*(N-2);
    for (int q = 0; q < Q; q++) {
        int t, x;
        cin >> t >> x;
        if (t == 1) {
            pair<ll, ll> p = {x, -1};
            auto it = tate.lower_bound(p);
            it--;
            ans -= (*it).second;
            tate.insert({x, (*it).second});
            if ((*it).first == -1) {
                yoko.erase(yoko.begin());
                yoko.insert({-1, x-2});
            }
        }
        if (t == 2) {
            pair<ll, ll> p = {x, -1};
            auto it = yoko.lower_bound(p);
            it--;
            ans -= (*it).second;
            yoko.insert({x, (*it).second});
            if ((*it).first == -1) {
                tate.erase(tate.begin());
                tate.insert({-1, x-2});
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 16136
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    long long int n;
    cin >> n;
    long long int d;
    cin >> d;
    long long int ans = 0;
    for (long long int i = 0; i < n; i++)
    {
        double x;
        cin >> x;
        double y;
        cin >> y;
        double dist = sqrt(x * x + y * y);
        if (dist <= d)
        {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3840
package main

import "fmt"

func main() {
	var n, m int
	var s string
	fmt.Scan(&n, &m, &s)

	ans := make([]int, 0)
	for n-m >= 0 {
		ok := false
		for i := m; i > 0; i-- {
			k := n - i
			if s[k] == '0' {
				ans = append(ans, i)
				n = k
				ok = true
				break
			}
		}
		if !ok {
			fmt.Println(-1)
			return
		}
	}

	if n != 0 {
		ans = append(ans, n)
	}

	for i := len(ans) - 1; i >= 0; i-- {
		if i > 0 {
			fmt.Printf("%d ", ans[i])
		} else {
			fmt.Println(ans[i])
		}
	}
}


Measured memory_bytes: 6724
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
    int N = sc.nextInt();
    int[] home = new int[N];
    int max = 0;
    for(int i=0; i<N; i++){
      home[i] = sc.nextInt();
      if(i>0)max = Math.max(max, Math.abs(home[i] - home[i-1]));
      else ;
    }
    max = Math.max(max, (home[0] + K - home[N-1]));
    System.out.print( K - max);
  }
}

Measured memory_bytes: 82372