akhauriyash/Code-Regression huggingface dataset:
/* C/C++ program to remove invalid parenthesis */
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long int

int main() 
{ 
   int r,c;
   cin>>r>>c;
   char mat[r][c];
   for(int i=0;i<r;i++)
     for(int j=0;j<c;j++)
       cin>>mat[i][j];
       int dp[r][c];
       dp[0][0]=1;
       bool s=1;
   for(int i=1;i<r;i++)
   {
       if(mat[i][0]=='.' && s)
         dp[i][0]=1;
       else{
         dp[i][0]=0;
         s=0;
       }
   }
   s=1;
   for(int i=1;i<c;i++)
   {
       if(mat[0][i]=='.' && s)
         dp[0][i]=1;
       else{
         dp[0][i]=0;
         s=0;
       }
   }
   for(int i=1;i<r;i++)
   {
      for(int j=1;j<c;j++)
      {
          if(mat[i][j]=='#')
          dp[i][j]=0;
          else if(mat[i-1][j]=='.' && mat[i][j-1]=='.')
          dp[i][j]=(dp[i-1][j]+dp[i][j-1]);
          else{
              if(mat[i-1][j]=='.')
               dp[i][j]=dp[i-1][j];
               else if(mat[i][j-1]=='.')
               dp[i][j]=dp[i][j-1];
               else
               dp[i][j]=0;
          }
          dp[i][j]=dp[i][j]%1000000007;
      }
   }
  /* for(int i=0;i<r;i++){
   for(int j=0;j<c;j++)
   cout<<dp[i][j]<<" ";
   cout<<endl;
   }
   cout<<endl;*/
   cout<<dp[r-1][c-1];
	return 0; 
} 


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define MAXN 100005
const int mod = 1e9 + 7;
using namespace std;

int main()
{
    string s,t;
    cin>>s>>t;
    int len_s = s.length();
    if(t.substr(0,len_s) == s) {
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3608
#include <stdio.h>
int n, m, r;
int a, b, c, e, f, z;
int k[9];
int p[8];
int q[8];
int x[8];
int y[8];
int d[200][200];
int main() {
	scanf("%d%d%d", &n, &m, &r);
	for (int i = 0; i < r; i++) {
		scanf("%d", p + i);
		p[i]--;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			d[i][j] = 100000000;
		}
	}
	for (int i = 0; i < n; i++)d[i][i] = 0;
	for (int i = 0; i < m; i++) {
		scanf("%d%d%d", &a, &b, &c);
		a--;
		b--;
		if (d[a][b] > c) {
			d[a][b] = c;
			d[b][a] = c;
			for (int j = 0; j < n; j++) {
				for (int k = 0; k < n; k++) {
					if (d[j][k] > d[j][a] + c + d[b][k]) {
						d[j][k] = d[j][a] + c + d[b][k];
					}
					if (d[j][k] > d[j][b] + c + d[a][k]) {
						d[j][k] = d[j][b] + c + d[a][k];
					}
				}
			}
		}
	}
	k[0] = 1;
	for (int i = 1; i <= r; i++) {
		k[i] = k[i - 1] * i;
	}
	z = 100000000;
	for (int i = 0; i < k[r]; i++) {
		f = i;
		for (int j = 0; j < r; j++) {
			q[j] = f / k[r - 1 - j];
			f %= k[r - 1 - j];
			y[j] = 0;
		}
		for (int j = 0; j < r; j++) {
			e = q[j];
			f = 0;
			while (e || y[f]) {
				if (!y[f])e--;
				f++;
			}
			x[j] = f;
			y[f]++;
		}
		f = 0;
		for (int j = 0; j < r - 1; j++) {
			f += d[p[x[j]]][p[x[j + 1]]];
		}
		if (z > f)z = f;
	}
	printf("%d\n", z);
}

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

using namespace std;

void solve() {
    int N, M;
    cin >> N >> M;
    vector<int> P(M), Y(M);
    vector<vector<int>> yd(N+1, vector<int>(0));
    for (int i = 0; i < M; i++)
    {
        cin >> P[i] >> Y[i];
        yd[P[i]].push_back(Y[i]);
    }
    for (int i = 0; i < N; i++)
    {
        sort(yd[i+1].begin(), yd[i+1].end());
    }
    for (int i = 0; i < M; i++)
    {
        cout << setfill('0') << setw(6) << P[i] << setfill('0') << setw(6) << (int)(lower_bound(yd[P[i]].begin(), yd[P[i]].end(), Y[i])-yd[P[i]].begin()) + 1 << endl;
    }
    
    

    
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 7808
import itertools
import copy
N, K = map(int, input().split())
A =list(map(int, input().split()))
ans=10**15
for c in itertools.product([0,1],repeat=N):
    a=copy.deepcopy(A)
    sm=0
    for i in range(1,N):
        if c[i]==1:
            if a[i]<=max(a[:i]):
                sm+=max(a[:i])-a[i]+1
                a[i]=max(a[:i])+1
    cnt=1
    for i in range(1,N):
        if max(a[:i])<a[i]:
            cnt+=1
    if cnt==K:
        ans=min(ans,sm)
print(ans)



Measured memory_bytes: 77480
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()

class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

    def __getitem__(self, i):
        return self._tree[i + self._n]

    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

    def add(self, i, v):
        self.update(i, self[i] + v)

    def sum(self, l, r):
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val)

def resolve():
    n, m = map(int, input().split())
    edges = []
    for _ in range(m):
        u, v, w = map(int, input().split())
        u -= 1; v -= 1
        edges.append((u, v, w))
    edges.sort()

    tree = SegmentTree([INF] * n, min, INF)
    tree.update(0, 0)
    for u, v, w in edges:
        tree.update(v, min(tree[v], tree.sum(u, v) + w))

    ans = tree[n - 1]
    if ans == INF:
        ans = -1
    print(ans)
resolve()

Measured memory_bytes: 86792
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define fi first
#define se second
#define inf (INT_MAX/2-1)
#define infl (1LL<<60)
#define vi vector<int>
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) begin(a),end(a)
#define y0 y5656
#define y1 y7878
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<": "<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<n;_++)cerr<<x[_]<<' ';cerr<<'\n',aaa
#define dbgs(x) cerr<<(#x)<<"[stl]: ";for(int _:x)cerr<<_<<' ';cerr<<'\n',aaa
#define dbgp(x) cerr<<(#x)<<": "<<x.fi<<' '<<x.se<<'\n',aaa
#define maxn 100000

using namespace std;

int v[maxn+5], d[maxn+5];
queue<int> qu;

int main () {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n, k; cin >> n >> k;
  int i, j, z;
  for (i = 1; i <= n; i++) cin >> v[i];
  fill(all(d), inf); d[1] = 0; qu.push(1);
  while (!qu.empty()) {
    i = qu.front(); qu.pop();
    for (j = i+1; j <= min(i+k, n); j++)
      if (d[j] > d[i]+abs(v[j]-v[i])) {
        d[j] = d[i]+abs(v[j]-v[i]);
        qu.push(j);
      }
  }
  cout << d[n];
  return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>

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

using namespace std;
int N, K, h[100001];
int dp[100001];
int main(void){
    cin >> N >> K;
    rep(i,N){
        scanf("%d",&h[i+1]);
        dp[i+1] = INF;
    }

    dp[1] = 0;
    for(int i=1;i<=N;i++) for(int j=i+1;j<=min(i+K,N);j++) dp[j] = min(dp[j], dp[i]+abs(h[i]-h[j]));

    cout << dp[N] << endl;
    return 0;
}



Measured memory_bytes: 1024
#include <stdio.h>

int gcd(int x,int y);

int main(void){

  int x,y;

  scanf("%d%d",&x,&y);
  printf("%d\n",gcd(x,y));

  return 0;
}

int gcd(int x,int y){

  int tmp,r;
  
  if(x<y){
    tmp = x;
    x = y;
    y = tmp;
  }

  r = x%y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }

  return y;

}



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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

int main() {
    int N, X, T;
    cin >> N >> X >> T;
    int a = (N + X - 1) / X;
    cout << a * T << endl;
}

Measured memory_bytes: 3616
#include <cstdio>
#include <vector>
#include <string>

using namespace std;

#define null -1

struct node{

    int parent, left, right;

};

node T[100005];
int Depth[100005];

void setDepth( int u, int p ){

    Depth[u] = p;

    if( T[u].right != null ){

        setDepth( T[u].right, p );

    }

    if( T[u].left != null ){

        setDepth( T[u].left, p + 1 );

    }

}

//??????????????¢??°

void print( int n){

    int i, j;

    for( i = 0; i < n; i++ ){

        printf("node %d: parent = %d, depth = %d, ", i, T[i].parent, Depth[i] );

        if( T[i].parent == null ) printf("root, ");
        else if( T[i].left == null ) printf("leaf, ");
        else printf("internal node, ");

        printf("[");

        j = T[i].left;

        while( j != null ){

            printf("%d", j );

            j = T[j].right;

            if( j == null ) break;

            printf(", ");

        }


        printf("]\n");

    }

}


int main(){

    int n, i, num, dim, j, bfr, l, root, v;

    scanf("%d", &n);

    for( i = 0; i < n; i++ ){

        T[i].left = null;
        T[i].right = null;
        T[i].parent = null;

    }

    for( i = 0; i < n; i++ ){

        scanf("%d %d", &num, &dim );

        for( j = 0; j < dim; j++ ){

            scanf("%d", &bfr);

            if( j == 0 ) T[num].left = bfr;
            else T[l].right = bfr;

            l = bfr;

            T[bfr].parent = num;

        }

    }

    for( i = 0; i < n ; i++ ){

        if( T[i].parent == null ) root = i;

    }



    setDepth( root, 0);

    print(n);

}

Measured memory_bytes: 7280
S = input()
Q = int(input())
Query = [input().split() for i in range(Q)]

mode = True  # True: Normal False: Reverse
pre = []
aft = []
for query in Query:
    if query[0] == '1':
        # モードを反転
        mode = not mode
    else:
        if (mode and (query[1] == '1')) or (not mode and (query[1] == '2')):
            pre.append(query[2])
        else:
            aft.append(query[2])
    
ans = ''.join(pre[::-1]) +  S + ''.join(aft)
    
if not mode:
    ans = ans[::-1]
 
print(ans)

Measured memory_bytes: 42396
#include <bits/stdc++.h>
#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 sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    string s;cin>>s;
    int n=s.size();
    ll res=0;
    
    for(int i=0;i<(1<<(n-1));i++){
        ll buf=0;
        ll bufsum=0;
        rep(j,n){
            ll t=s[j]-'0';
            buf=10*buf+t;
            if(j==n-1)continue;
            if((i&(1<<j))>=1){
                bufsum+=buf;
                buf=0;
            }
        }
        bufsum+=buf;
        res+=bufsum;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3596
#include<cstdio>
#define mod (1000000007)
int a[110000],n;
int check()
{
	if(n&1)
	{
		if(a[0]!=1) return 0;
		for(int i=2;i<n;i+=2)
		if(a[i]!=2) return 0;
		return 1;
	}
	for(int i=1;i<n;i+=2)
	if(a[i]!=2) return 0;
	return 1;
}
int main()
{
	int x;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&x),a[x]++;
	long long ans=check();
	if(ans)
	for(int i=1;i<=n/2;i++) ans*=2,ans%=mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <stack>
#include <queue>

int main(){
	std::stack<int> switching_rail;
	std::queue<int> out_number;
	int in_number;
	//Input
	while(std::cin >> in_number){
		if(in_number == 0){
			out_number.push(switching_rail.top());
			switching_rail.pop();
		}else{
			switching_rail.push(in_number);
		}
	}
	//Output
	while(!out_number.empty()){
		std::cout << out_number.front() << std::endl;
		out_number.pop();
	}
	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  ll a; cin >> a;
  string s; cin >> s;
  int b = (s[0] - '0') * 100 + (s[2] - '0') * 10 + (s[3] - '0');
  a *= b;
  a /= 100;
  cout << a << endl;

  return 0;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000007
#define EPS 1E-12

string s;

int main()
{
  getline(cin, s);

  rep(i, s.size()){
    if(s.substr(i, 5) == "apple"){ s.replace(i, 5, "peach");  continue; }
    if(s.substr(i, 5) == "peach"){ s.replace(i, 5, "apple");  continue; }
  }

  cout << s << endl;

  return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <map>
using namespace std;
int main(){
	long long n,m,tong=0;
	map<long long, long long> a;
	cin>>n;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		a[x]++;
		tong+=x;
	}
	cin>>m;
	while(m--){
		int c,b;
		cin>>b>>c;
		tong-=a[b]*b;
		tong+=a[b]*c;
		a[c]+=a[b];
		a[b]=0;
		cout<<tong<<endl;
	}
}

Measured memory_bytes: 9032
#include<bits/stdc++.h>
#define INF 1000000007
using namespace std;
struct sakura
{
    long long x;
    long long y;
}
ball[222222];
long long x[222222];
long long y[222222];
long long maxn[222222];
long long minl[222222];
long long n,ans,ans1,ans2,bmax,bmin,rmax,rmin;
inline bool cmp(sakura xx,sakura yy){ return xx.x<yy.x; }
int main()
{
    scanf("%lld",&n);
    bmax=rmax=-1;bmin=rmin=INF;
    for(register int i=1;i<=n;++i)
    {
        scanf("%lld%lld",&x[i],&y[i]);
        if(x[i]>y[i]) swap(x[i],y[i]);
        ball[i].x=x[i];ball[i].y=y[i];
        bmax=max(bmax,y[i]);
        bmin=min(bmin,y[i]);
        rmax=max(rmax,x[i]);
        rmin=min(rmin,x[i]);
    }
    ans1=(bmax-bmin)*(rmax-rmin);
    bmin=rmin;sort(ball+1,ball+n+1,cmp);
    ans2=INF;maxn[1]=minl[1]=ball[1].y;
    for(register int i=2;i<=n;++i)
    {
        maxn[i]=max(maxn[i-1],ball[i].y);
        minl[i]=min(minl[i-1],ball[i].y);
        if(i!=n) ans2=min(ans2,max(maxn[i],ball[n].x)-min(minl[i],ball[i+1].x));
    }
    ans2*=(bmax-bmin);ans=min(ans1,ans2);
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 10240
#include <bits/stdc++.h>
using namespace std;
#define INF_LL 1LL << 39
#define INF 100000000
#define MOD 1000000007LL
#define ll long long
#define all(x) x.begin(), x.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define prique priority_queue
#define PI acos(-1)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef vector<ll> poly;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};
template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
struct edge {
    int to, cost;
};

signed main() {
    int n, q;
    cin >> n >> q;
    vector<pair<pair<int, int>, int>> l(n);
    vi s(n), t(n), x(n);
    set<int> d;
    map<int, int> m;
    rep(i, n) cin >> l[i].first.first >> l[i].first.second >> l[i].second;
    sort(all(l), [](auto &x, auto &y) { return x.second < y.second; });
    rep(i, n) {
        s[i] = l[i].first.first;
        t[i] = l[i].first.second;
        x[i] = l[i].second;
    }
    rep(i, q) {
        int a;
        cin >> a;
        d.insert(a);
        m[a] = i;
    }
    vi ans(q, -1);
    rep(i, n) {
        set<int>::iterator it = d.lower_bound(s[i] - x[i]);
        while(it != d.end() && *it < t[i] - x[i]) {
            ans[m[*it]] = x[i];
            d.erase(it);
            it = d.lower_bound(s[i] - x[i]);
        }
    }
    rep(i, q) { cout << ans[i] << endl; }
}


Measured memory_bytes: 26112
use std::io;
use std::str::FromStr;

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn input_vec() -> Vec<u64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn main() {
    let (n, m) = input_tuple();
    let mut flag = vec![0; m as usize];
    for _ in 0..n {
        let v = input_vec();
        let k = v[0];
        for i in 1..(k+1) {
            flag[v[i as usize] as usize - 1] += 1;
        }
    }
    // println!("{:?}", flag);
    let mut count = 0;
    for f in flag {
        if f == n {
            count += 1;
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

#define YesNo(b) ((b) ? "Yes" : "No")
#define YESNO(b) ((b) ? "YES" : "NO")

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;


int f(int A, int B, int /*C*/, int K)
{
    if (K <= A)
    {
        return K;
    }
    K -= A;
    if (K <= B)
    {
        return A;        
    }
    K -= B;
    
    return A - K;
}

int main()
{
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    
    int ans = f(A,B,C,K);
    cout << ans << endl;
}

Measured memory_bytes: 3596
# ABC148 C
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
from fractions import gcd
def lcm(x, y):
    """
    xとyの最小公倍数を求める。

    Parameters
    ----------
    x,y : int
        自然数

    Returns
    -------
        最小公倍数：int

    """
    return (x * y) // gcd(x, y)

a,b=nm()
print(lcm(a,b))

Measured memory_bytes: 5072
#include<bits/stdc++.h>
using namespace std;
int Min(int x,int y){
	return x<y?x:y;
}
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	if(k==0){
		printf("%lld\n",n*(long long)n);
		return 0;
	}
	long long ans=0;
	int cnt;
	for(int i=k+1;i<=n;i++){
		cnt=n/i;
		ans=ans+(n-cnt*k-Min(n%i,k-1));
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int r = sc.nextInt();

		int innerRate = 0;
		if (n >= 10) {
			innerRate = r;
		} else {
			innerRate = r + (100 * (10 - n));
		}

		System.out.println(innerRate);

		sc.close();
	}
}


Measured memory_bytes: 21972
# coding=utf-8


def direction_vector(p1: list, p2: list)->list:
    return [p2[0]-p1[0], p2[1]-p1[1]]


def cross_product(v1: list, v2: list)->float:
    return v1[0]*v2[1] - v1[1]*v2[0]


if __name__ == '__main__':
    while True:
        try:
            points_receive = list(map(float, input().split()))
        except EOFError:
            break

        points_list = [[points_receive[2*i], points_receive[2 * i + 1]] for i in range(4)]
        p1_to_p2 = direction_vector(points_list[0], points_list[1])
        p2_to_p3 = direction_vector(points_list[1], points_list[2])
        p3_to_p1 = direction_vector(points_list[2], points_list[0])
        p1_to_pp = direction_vector(points_list[0], points_list[3])
        p2_to_pp = direction_vector(points_list[1], points_list[3])
        p3_to_pp = direction_vector(points_list[2], points_list[3])
        cp1 = cross_product(p1_to_p2, p1_to_pp)
        cp2 = cross_product(p2_to_p3, p2_to_pp)
        cp3 = cross_product(p3_to_p1, p3_to_pp)

        if cp1 > 0 and cp2 > 0 and cp3 > 0:
            print('YES')
        elif cp1 < 0 and cp2 < 0 and cp3 < 0:
            print('YES')
        else:
            print('NO')

Measured memory_bytes: 5608
#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;

int main(){
    int n;
    double ans;
    ans = 0;
    cin >> n;
    vector<int> vec(n);
    for(int i = 0; i < n; i++){
        cin >> vec.at(i);
        ans = ans + 1.0 / vec.at(i);
    }
    ans = 1.0 / ans;
    cout << setprecision(20) << ans << endl;
    return 0;  
}

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

using namespace std;

int main() {
	int n; cin >> n;
	vector<int> a(n);
	for (int& e : a) cin >> e;
	long long ans = 0;
	int l = 0, r = 0, sumx = 0, sump = 0;
	while (r < n) {
		sumx ^= a[r], sump += a[r];
		++r;
		while (l < n && sumx != sump) {
			sumx ^= a[l], sump -= a[l];
			++l;
		}
		ans += r - l;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4032
M = 10**9 + 7
n, a, b = map(int, input().split())
r = pow(2, n, M) - 1
f = c = 1
for i in range(b):
  f = f * (i + 1) % M
  c = c * (n - i) % M
  if a != i + 1 != b:
    continue
  r -= c * pow(f, M - 2, M)
print(r % M)


Measured memory_bytes: 3060
S = input()
A = S[0]+S[1]
B = S[2]+S[3]
A = int(A)
B = int(B)
if (A >= 1) & (A <=12 ) & (B >= 1) & (B <= 12):
    print("AMBIGUOUS")
elif (A >= 1) & (A <= 12) & (B >= 13) & (B <= 99):
    print("MMYY")
elif (A >= 1) & (A <= 12) & (B == 0):
    print("MMYY")
elif (A >= 13) & (A <= 99) & (B >= 1) & (B <= 12):
    print("YYMM")
elif (A == 0) & (B >= 1) & (B <= 12):
    print("YYMM")
else:
    print("NA")

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

int main()
{
    int H, W;
    cin >> H >> W;

    int N;
    cin >> N;

    vector<int> order;
    for (int i = 0; i < N; i++)
    {
        int count;
        cin >> count;
        for (int j = 0; j < count; j++)
            order.push_back(i+1);
    }

    vector<vector<int>> grid(H, vector<int>(W));
    for (int h = 0; h < H; h++)
        if (h % 2 == 0)
        {
            for (int w = 0; w < W; w++)
            {
                grid[h][w] = order.back();
                order.pop_back();
            }
        }
        else
        {
            for (int w = W-1; w >= 0; w--)
            {
                grid[h][w] = order.back();
                order.pop_back();
            }
        }

    for (int h = 0; h < H; h++)
    {
        for (int w = 0; w < W; w++)
            cout << grid[h][w] << " ";
        cout << endl;
    }
}


Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

struct UF {
  vector<int> par; // parent
  vector<int> sizes;
  UF(int n) : par(n), sizes(n, 1) {
    for (int i = 0; i < n; ++i) {
      par[i] = i;
    }
  }
  int root(int x) {
    if (x == par[x]) {
      return x;
    }
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return;
    }
    if (sizes[x] < sizes[y]) {
      swap(x, y);
    }
    par[y] = x;
    sizes[x] += sizes[y];
    sizes[y] = 0;
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return sizes[root(x)];
  }
};

int n, m;
vvi g;

bool bipartite_graph(int s) {
  vi color(n, 0);
  color[s] = 1;
  deque<int> stk;
  stk.push_back(s);
  while (!stk.empty()) {
    int u = stk.front();
    stk.pop_front();
    for (int v : g[u]) {
      if (color[v] > 0) {
        if (color[u] == color[v]) {
          return false;
        }
        continue;
      }
      color[v] = 3 - color[u];
      stk.push_back(v);
    }
  }
  return true;
}

set<int> roots;

int main() {
  scanf("%d %d", &n, &m);
  g.resize(n);
  UF uf(n);
  {
    int u, v;
    rep (i, m) {
      scanf("%d %d", &u, &v);
      u -= 1;
      v -= 1;
      g[u].push_back(v);
      g[v].push_back(u);
      uf.unite(u, v);
    }
  }
  rep (i, n) {
    roots.insert(uf.root(i));
  }
  ll bocchi = 0;
  ll bipartite = 0;
  ll other = 0;
  for (int u : roots) {
    if (uf.size(u) == 1) {
      bocchi += 1;
    } else if (bipartite_graph(u)) {
      bipartite += 1;
    } else {
      other += 1;
    }
  }

  ll ans = 0;
  ans += bocchi * (bocchi + 2 * (n - bocchi));
  ans += 2 * bipartite * bipartite;
  ans += other * (other + 2 * bipartite);
  printf("%lld\n", ans);

  return 0;
}


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

int main() { 
  int n;
  cin >> n;
  vector<ll> h(n);
  rep(i, n){
    cin >> h[i];
  }
  for(int i = n-1; i> 0; i--){
    //cout << h[i-1] << " " << h[i] << endl;
    if(h[i-1] > h[i]){
      h[i-1]--;
      if(h[i-1] > h[i]){
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;

}


Measured memory_bytes: 4032
n=int(input())
R=sorted([list(map(int,input().split())) for i in range(n)], key=lambda R: -R[1])
B=sorted([list(map(int,input().split())) for i in range(n)])
ans=0
for c,d in B:
  for a,b in R:
    if a<c and b<d:
      R.remove([a,b]);ans+=1
      break
print(ans)

Measured memory_bytes: 9132
import sys
MOD = 10**9 + 7
# import io, os
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def input():
    return sys.stdin.readline()[:-1]

def main():
    s = input()
    t = input()
    for k in range(len(s)-len(t),-1,-1):
        f = 1
        for i in range(len(t)):
            if s[k+i] != "?":
                if s[k+i] != t[i]:
                    f = 0
                    break
        if f == 1:
            print(s[:k].replace("?","a") + t + s[k+len(t):].replace("?","a"))
            exit()
    print("UNRESTORABLE")
if __name__ == '__main__':
    main()


Measured memory_bytes: 61804
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main() {
  // input
  int N;
  map<long long, long long> nums;
  cin >> N;
  vector<long long> S(N+1, 0);
  for (int i = 1; i <= N; i++) {
    int tmp;
    cin >> tmp;
    S.at(i) = tmp + S.at(i-1);
  }

  // solve
  for (int i = 0; i <= N; i++) {
    nums[S.at(i)]++;
  }

  long long ans {0};
  for (auto it : nums) {
    long long num = it.second;
    ans += num * (num - 1) / 2;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 16788
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	
	static ArrayList<Integer> list = new ArrayList<Integer>();
	static boolean[] num = new boolean[150000];
	
	static void prime(int n) {
		for(int i=2; i*n<150000; i++) {
			num[n * i] = false;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		for(int i=2; i<150000; i++) {
			num[i] = true;
		}
		num[0] = false;
		num[1] = false;
		for(int i=2; i<150000; i++) {
			if(num[i]) {
				list.add(i);
				prime(i);
			}
		}
		
		while(sc.hasNext()) {
			int N = sc.nextInt();
			int P = sc.nextInt();
			if(N == -1 && P == -1) break;
			
			ArrayList<Integer> M = new ArrayList<Integer>();
			int k = 0;
			while(list.get(k) <= N) k++;
			for(int i=k; i<k+P; i++) {
				for(int j=i; j<k+P; j++) {
					M.add(list.get(i) + list.get(j));
				}
			}
			Collections.sort(M);
			System.out.println(M.get(P - 1));
		}
	}
}


Measured memory_bytes: 67216
#include <cstdio>
#include <cstdint>
#include <vector>
#include <map>
#include <string>
#include <algorithm>

int main() {
  std::map<std::string, std::vector<int>> index;
  while (true) {
    char buf[32];
    int p;
    if (scanf("%s %d", buf, &p) == EOF) break;
    index[buf].push_back(p);
  }

  for (auto &p: index) {
    printf("%s\n", p.first.c_str());
    auto v=p.second;
    std::sort(v.begin(), v.end());
    for (size_t i=0; i<v.size(); ++i)
      printf("%d%c", v[i], i+1<v.size()? ' ':'\n');
  }
}



Measured memory_bytes: 2904
#include <cstdio>
#include <cmath>
using namespace std;

int main() {
  double a, b, C;
  scanf("%lf %lf %lf", &a, &b, &C);
  printf("%.6f\n", a * b * sin(M_PI*C/180) / 2);
  printf("%.6f\n", a + b + sqrt(pow(a,2)+pow(b,2)-2*a*b*cos(M_PI*C/180)));
  printf("%.6f\n", b * sin(M_PI*C/180));
  return 0;
}


Measured memory_bytes: 2800
#include<bits/stdc++.h>
#include<vector>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define CEVCOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define M map<int , int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>
int main(void){

  int N;  cin >> N;
  V p(N + 1); for(int i = 1 ; i <= N ; i++)	cin >> p[i];

  int ans = 0;
  for(int i = 1 ; i <= N - 1 ; i++){
    if(p[i] == i){
      swap(p[i] , p[i + 1]);
      ans += 1;
    }
  }
  if(p[N] == N){
    swap(p[N - 1] , p[N]);
    ans += 1;
  }

  SCOUT(ans) << endl;
  
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp std::make_pair
#define pb push_back
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::set<int> si;
typedef std::string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
str s;
int main(){
  cin>>s;
  int ss=s.size();
  int ac=0,bc=0,cc=0;
  rep(i,ss){
    if(s[i]=='a') ac++;
    else if(s[i]=='b') bc++;
    else cc++;
  }
  int dis1=std::abs(ac-bc);
  int dis2=std::abs(ac-cc);
  int dis3=std::abs(cc-bc);    
  if(dis1<2&&dis2<2&&dis3<2) prin("YES");
  else prin("NO");
  
  return 0;
}


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

using namespace std;

int main (void) {
    int N, A, B;
    cin >> N >> A >> B;
    vector<int> X(N);
    for ( int i = 0; i < N; i++ ) cin >> X.at(i);

    long long ans = 0;
    for ( int i = 0; i < N-1; i++ ) {
        int dist = X.at(i+1) - X.at(i);
        long long walk_cost = (long long)A * dist;
        long long tele_cost = B;
        if ( walk_cost < tele_cost ) ans += walk_cost;
        else ans += tele_cost;
    }

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


Measured memory_bytes: 3692
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  map<int,int> cnt;
  for(int x:a) ++cnt[x];
  int f=1;
  pii mn=*cnt.begin();
  if(mn.Y>2) f=0;
  int t=cnt.size();
  reps(i,1,t) if(cnt[i+mn.X]<2) f=0;
  if(t-(mn.Y==1)!=mn.X) f=0;
  cout<<(f?"Possible":"Impossible")<<endl;
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;

const double INF=10000000000000;
int n;
int num[16];
double to[16];
double s[16];
double dp[1<<16][16];
double ans=INF;
int r[16];
int ansr[16]; 

void dfs(int x,double t,double w,int bit,int root[16],int k){
	if(t>dp[bit][x])return;
	if(bit==(1<<n)-1 && ans>t){
		ans=t;
		for(int i=0;i<n;i++){
			ansr[i]=root[i];
		}
	}
	else{
		for(int i=0;i<n;i++){
			if(!(bit>>i & 1)){
				double v=2000.0/(70.0+w);
				double ct=t+(fabs(to[x]-to[i])/v);
				double nw=w+s[i]*20;
				root[k]=num[i];
				if(dp[bit | 1<<i][i]>ct){
					dp[bit | 1<<i][i]=ct;
					dfs(i,ct,nw,(bit | 1<<i),root,k+1);
				}
			}
		}
	}
}

int main(void){
	cin >> n;
	for(int i=0;i<(1<<16)-1;i++){
		for(int j=0;j<16;j++){
			dp[i][j]=INF;
		}
	}
	for(int i=0;i<n;i++){
		cin >> num[i] >> to[i] >> s[i];
	}
	for(int i=0;i<n;i++){
		r[0]=num[i];
		dfs(i,0,s[i]*20,1<<i,r,1);
	}
	for(int i=0;i<n;i++){
		if(i!=0)cout << " ";
		cout << ansr[i];
	}
	cout << endl;
    return 0;
}

Measured memory_bytes: 9420
#include <iostream>
using namespace std;
int main(){
  int e,y;
  cin >>e>>y;
  if(e==0){
    if(y<=1911){
      cout <<"M"<<y-1867<<endl;
    }
    if((y>=1912)&&(y<=1925)){
      cout <<"T"<<y-1911<<endl;
    }
    if((y>=1926)&&(y<=1988)){
      cout <<"S"<<y-1925<<endl;
    }
    if(y>=1989){
      cout <<"H"<<y-1988<<endl;
    }
  }
  if(e==1){
    cout <<y+1867<<endl;
  }else if(e==2){
    cout <<y+1911<<endl;
  }else if(e==3){
    cout <<y+1925<<endl;
  }else if(e==4){
    cout <<y+1988<<endl;
  }
  return 0;
}



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

int main(){
int a,b;
cin >> a >> b;
if(a > 0 && b > 0){
    cout << "Positive" << endl;
}
else if(a < 0 && b < 0 ){
    if((a - b +1)% 2 == 1 || (a - b +1)% 2 == -1){
        cout << "Negative" << endl;
    }
    else{
        cout << "Positive"<< endl;
    }
}
else{
    cout << "Zero" << endl;
}
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;

int a[26][26];

int main()
{
    string s,t;
    cin >> s >> t;
    int n = s.size();
    for(int i = 0; i < n; i++){
        a[t[i]-'a'][s[i]-'a']++;
    }
    bool ans = true;
    for(int i = 0; i < 26; i++){
        int cnt = 0;
        for(int j = 0; j < 26; j++){
            if(a[i][j]){
                cnt++;
            }
        }
        if(cnt > 1){
            ans = false;
            break;
        }
    }
    for(int i = 0; i < 26; i++){
        int cnt = 0;
        for(int j = 0; j < 26; j++){
            if(a[j][i]){
                cnt++;
            }
        }
        if(cnt > 1){
            ans = false;
            break;
        }
    }
    
    if(ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 776
#include<stdio.h> 
int main() 
{ 
  int n,x[1000],cnt=0,i; 
  scanf("%d",&n); 
  for(i=1;i<=n;i++) 
  { 
    scanf("%d",&x[i]); 
  } 
  for(i=1;i<=n;i++) { 
   if((x[i])%2!=0&& i%2!=0) 
   { 
     cnt++; 
   }  
  }
   printf("%d\n",cnt); 
   return 0; 
  
}

Measured memory_bytes: 1700
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9;

int main(){
  string s,t;
  cin>>s>>t;
  int cnt(0);
  for (int i(0);i<3;i++){
    if (s[i]==t[i]) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


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

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

    double a[N];
    double b[N];

    for (int i = 0; i < N; i++){
        cin >> a[i];
        b[i] = 1 / a[i];
    }

    double sum = 0;
    
    for (int i = 0; i < N; i++){
        sum += b[i];
    }
    double answer = 1 / sum;

    cout << fixed;
    cout << answer << setprecision(100) << endl;
}


Measured memory_bytes: 256
import sys
import bisect

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = sorted(list(map(int, input().split())))
    if n == 2:
        print(*A[::-1])
        exit()

    idx = bisect.bisect_left(A, A[-1] // 2)
    if abs(A[-1] - A[idx] - A[-1] // 2) > abs(A[-1] - A[idx - 1] - A[-1] // 2):
        idx -= 1

    print(A[-1], A[idx])


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 62704
import heapq
from itertools import accumulate
inf = float('inf')

def dijkstra(ad_lst, n, s):
    costs = [inf for i in range(n+1)]
    costs[s], Q = 0, []
    heapq.heappush(Q, [costs[s], s])

    while(Q != []):
        c, u = heapq.heappop(Q)
        for v, c in ad_lst[u].items():
            if costs[u] + c < costs[v]:
                heapq.heappush(Q, [costs[u] + c, v])
                costs[v] = costs[u] + c

    return costs

n,m,s,t, = map(int, input().split())

route_y = {i: {} for i in range(n+1)}
route_s = {i: {} for i in range(n+1)}
for i in range(m):
    u, v, a, b = map(int, input().split())
    route_y[u][v] = a
    route_y[v][u] = a
    route_s[u][v] = b
    route_s[v][u] = b

cost_y = dijkstra(route_y, n, s)
cost_s = dijkstra(route_s, n, t)
result = list(accumulate([y+s for y,s in zip(cost_y, cost_s)][::-1], min))
yen = 10**15
[print(yen-result[i]) for i in range(n-1, -1, -1)]


Measured memory_bytes: 111460
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let mut s = read::<String>().chars().collect::<Vec<_>>();
    s.dedup();
    println!("{}", s.len() - 1);
}

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

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


Measured memory_bytes: 2708
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
using namespace std;

int main() {
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    rep(i, 0, n) {
        cin >> s[i];
    }
    sort(s.begin(), s.end());
    rep(i, 0, n) {
        cout << s[i];
    }
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int a, b, c;
	scanf("%d %d %d" ,&a ,&b ,&c);
	if (a <= b && b <= c) 		printf("%d %d %d\n", a , b , c);
	else if (a <= c && c <= b ) printf("%d %d %d\n", a , c , b);
	else if (b <= a && a <= c ) printf("%d %d %d\n", b , a , c);
	else if (b <= c && c <= a ) printf("%d %d %d\n", b , c , a);
	else if (c <= a && a <= b ) printf("%d %d %d\n", c , a , b);
	else						printf("%d %d %d\n", c , b , a);

	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<math.h>
using namespace std;

int main(){
    int n;
    cin>>n;
    for(int i=0; i<n; i++){
        bool base[3]={};
    int out=0;
        int ans=0;
    string str;
    while(out!=3){
        cin>>str;
        if(str=="HIT"){
            if(base[2])ans++;
            base[2]=false;
            swap(base[1],base[2]);
            swap(base[1],base[0]);
            base[0]=1;
        }
        if(str=="HOMERUN"){
            for(int i=0; i<3; i++){
                if(base[i])ans++;
                base[i]=false;
            }
            ans++;

        }
        if(str=="OUT")out++;
    }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3124
#include<iostream>

using namespace std;

void print(int a[],int n)
{
    for(int i=0;i<n;i++)
        {
            cout<<a[i];
            if(i!=n-1)
                cout<<" ";
        }
    cout<<endl;
}

int main()
{
    int n,i,j,v;
    int a[100];
    cin>>n;
    for(i=0;i<n;i++)
    {

        cin>>a[i];
    }
    print(a,n);
    for(i=1;i<n;i++)
    {
        v=a[i];
        for(j=i-1;j>=0;j--)
        {
            if(a[j]>v)
            {
                a[j+1]=a[j];
            }
            else
                break;
        }
        a[j+1]=v;
        print(a,n);

    }
    return 0;

}

Measured memory_bytes: 3088
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n;
    cin >> n;
    string s[n];
    for (int i=0; i<n; i++){
        cin >> s[i];
        s[i]+=s[i];
    }

    string t[n];
    int ans=0;       
    for (int i=0; i<n; i++){
      int flg=0;
        for (int j=0; j<n; j++){
            t[j]=s[j].substr(i,n);
        }
        for (int j=0; j<n; j++){
            for (int k=0; k<n; k++){
                if (t[j][k]!=t[k][j]){
                    flg=1;
                }
            }
        }
        if (flg==0){
            ans+=n;
        }
 
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

    protected static String process(String data) {
        StringBuilder sb = new StringBuilder();
        final String[] lines = splitForLines(data);

        final int[] split = split(lines[0]);
        final int rows = split[0];
        final int columns = split[1];

        final int[][] matrix = new int[rows][columns];
        final String[] matrixLines = Arrays.copyOfRange(lines, 1, 1 + rows);
        for (int i = 0; i < matrixLines.length; i++) {
            final int[] array = split(matrixLines[i]);

//            for (int j = 0; j < array.length; j++) {
//                matrix[i][j] = array[j];
//            }
            System.arraycopy(array, 0, matrix[i], 0, array.length);
        }

        final int[] vector = new int[columns];
        final String[] vectorLines = Arrays.copyOfRange(lines, 1 + rows, lines.length);
        for (int i = 0; i < vectorLines.length; i++) {
            vector[i] = Integer.parseInt(vectorLines[i]);
        }

        final int[] result = multiply(matrix, vector);

        for (int i : result) {
            sb.append(i).append('\n');
        }

        return sb.toString();
    }

    static int[] multiply(int[][] matrix, int[] vector) {
        int[] result = new int[matrix.length];

        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[i].length; j++) {
                result[i] += matrix[i][j] * vector[j];
            }
        }

        return result;
    }

    private static String readAll(InputStream is) {
        InputStreamReader r = null;
        BufferedReader br = null;

        try {
            r = new InputStreamReader(is);
            br = new BufferedReader(r);
            StringBuilder sb = new StringBuilder();
            String s;

            while ((s = br.readLine()) != null) {
                sb.append(s).append('\n');
            }

            return sb.toString();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                }
            }
            if (r != null) {
                try {
                    r.close();
                } catch (IOException e) {
                }
            }
        }
    }

    private static String[] splitForLines(String lines) {
        return lines.split("\\n");
    }

    private static int[] split(String s) {
        final String[] s0 = s.split(" ");
        int[] ia = new int[s0.length];

        for (int i = 0; i < s0.length; i++) {
            ia[i] = Integer.parseInt(s0[i]);
        }

        return ia;
    }

    public static void main(String[] args) {
        System.out.print(process(readAll(System.in)));
    }
}

Measured memory_bytes: 25888
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Rep(i, N) for(int i = 0; i < N; i++)
const int LLINF = 1LL << 60;
const int mod = 1e9 + 7;

int calc(int * sum, int n) {
  //cout << "Hello" << endl;
  int ret = 0;
  int a = 1, b = n - 1;
  while(a <= b) {
    (ret += (sum[b] - sum[a - 1]) * (b - a + 1)) %= mod;
    a++, b--;
  }
  return ret;
}

signed main()
{
  int N, M;
  int X[100005], Y[100005];
  int sum1[100005] = {0};
  int sum2[100005] = {0};
  
  cin >> N >> M;

  Rep(i, N) cin >> X[i];
  Rep(i, M) cin >> Y[i];
  
  Rep(i, N - 1) sum1[i + 1] += X[i + 1] - X[i] + sum1[i];
  Rep(i, M - 1) sum2[i + 1] += Y[i + 1] - Y[i] + sum2[i];
  cout << (calc(sum1, N) * calc(sum2, M)) % mod << endl;

  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000001
//0=48,A=65,a=97

int main() {
    ll n;cin >> n;
    ll a,b;cin >> a >> b;
    if(a%2 == b%2){
        cout << (b-a)/2 << endl;
        return 0;
    }

    else{
        cout << (b-a-1)/2 + min(a-1,n-b)+1 << endl;
    }

    return 0;
}

Measured memory_bytes: 3624
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        int[] s = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
        int n = s[0];
        int k = s[1];
        int[] a = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();

        int ans = (n - 1) / (k - 1);
        if ((n - 1) == ans * (k - 1))
        {
            Console.WriteLine((n - 1) / (k - 1));
        }
        else
        {
            Console.WriteLine((n - 1) / (k - 1) + 1);
        }
    }
}

Measured memory_bytes: 19808