akhauriyash/Code-Regression huggingface dataset:
n = int(input())
s = input()
A = [chr(ord('a') + i) for i in range(26)]
B = []
for i in range(26):
  B.append(s.count(A[i]))
c = len(B)
ans = 1
for i in range(c):
  ans = ans*(B[i]+1)
print((ans-1)%(10**9+7))

Measured memory_bytes: 3188
def examC():
    N, K = LI()
    A = LI()
    for i,a in enumerate(A):
        if a==1:
            locate1 = i
            break
    ans = (N+K-3)//(K-1)
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()


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

int main() {
  int A, B;
  string C;
  cin >> A >> C >> B;
  
    if ( C == "+" ) {
      cout << A + B << endl;
  }

    else if ( C == "-" ) {
      cout << A - B << endl;
  }
}

Measured memory_bytes: 256
n=int(input())
s=input()

t=[0]*n
if s[0]=="W":
  t[0]=-1
else:
  t[0]=1
for i in range(1,n):
  if s[i]=="W":
    t[i]=-1+t[i-1]
  else:
    t[i]=1+t[i-1]
    
max1=max(t)
a=t.index(max1)

ans=0
ans+=s[:a].count("W")

ans+=s[a+1:].count("E")
print(ans)

  

Measured memory_bytes: 15436
c = [list(map(int,input().split())) for i in range(3)]

q1 = c[0][0] - c[0][1] == c[1][0] - c[1][1] == c[2][0] - c[2][1]
q2 = c[0][0] - c[0][2] == c[1][0] - c[1][2] == c[2][0] - c[2][2]
q3 = c[0][0] - c[1][0] == c[0][1] - c[1][1] == c[0][2] - c[1][2]
q4 = c[0][0] - c[2][0] == c[0][1] - c[2][1] == c[0][2] - c[2][2]

if q1 and q2 and q3 and q4 == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

vector<int> D;
vector<vector<int>> G;

class topological_sort{
public:
    int V;
    vector<int> vis, indeg, sorted;
    vector<vector<int>> edge;
    topological_sort(int v){
        V = v;
        vis.resize(v, 0);
        indeg.resize(v, 0);
        edge.resize(v);
    }
    
    void add(int from, int to){
        edge[from].push_back(to);
        indeg[to]++;
    }
    
    void bfs(int s){
        queue<int> q;
        q.push(s);
        vis[s] = 1;
        while (!q.empty()) {
            int f = q.front();
            q.pop();
            sorted.push_back(f);
            rep(i, edge[f].size()){
                int e = edge[f][i];
                indeg[e]--;
                if (indeg[e] == 0 && !vis[e]) {
                    vis[e] = 1;
                    q.push(e);
                }
            }
        }
    }
    
    void sort(){
        rep(i, V){
            if (indeg[i] == 0 && !vis[i]) {
                bfs(i);
            }
        }
    }
};
            


int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N, M;
    cin >> N >> M;
    vector<int> P(N);
    D.assign(N, -1);
    vector<pair<pair<int, int>, int>> E(N + M - 1);
    G.resize(N);
    topological_sort T(N);
    rep(i, N + M - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        P[b]++;
        E[i] = mp(mp(a, b), 1);
        G[a].pb(b);
        T.add(a, b);
    }
    T.sort();
    int root = -1;
    rep(i, N) if(P[i] == 0) root = i;
    D[root] = 0;
    rep(i, N) {
        for(int v: G[T.sorted[i]]) {
            D[v] = max(D[v], D[T.sorted[i]] + 1);
        }
    }
    
    vector<int> ans(N);
    ans[root] = 0;
    rep(i, N + M - 1) {
        if (D[E[i].first.first] + 1 == D[E[i].first.second]) {
            ans[E[i].first.second] = E[i].first.first + 1;
        }
    }
    
    
    rep(i, N) {
        output(ans[i]);
    }
    
    
    return 0;
}


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

int H,W;
char S[25][25];

int dp[25][25][25][25];

int solve(int x1,int y1,int x2,int y2){
  int &ret = dp[x1][y1][x2][y2];
  if( ret > -1 ) return ret;

  set<int> g;
  for(int x=x1;x<=x2;x++){
    for(int y=y1;y<=y2;y++){
      if( S[x][y] == 'X' ) continue;
      g.insert( solve(x1,y1,x-1,y-1) ^ solve(x+1,y1,x2,y-1) ^
                solve(x1,y+1,x-1,y2) ^ solve(x+1,y+1,x2,y2) );
    }
  }
  
  ret = 0;
  while( g.find( ret ) != g.end() ) ret++;
  return ret;
}

int main(){
  memset(dp,-1,sizeof(dp));
  cin >> H >> W;
  for(int i=1;i<=H;i++)
    for(int j=1;j<=W;j++)
      cin >> S[j][i];
  if( solve(1,1,W,H) ) cout << "First" << endl;
  else cout << "Second" << endl;
}

Measured memory_bytes: 2728
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

#define bip(n) __builtin_popcount(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctz(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clz(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffs(n)//index of first one bit!!

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

//#define fi1 ifstream cin("input.txt")
//#define of1 ofstream cout("output.txt")
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	char noo[4];
	for(int i=0;i<4;i++)
		cin>>noo[i];
	for(int i=1;i<4;i++)
	{
		if(noo[i]==noo[i-1])
		{
			cout<<"Bad";
			return 0;
		}
	}
	cout<<"Good\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define teto(a, b) (((a)+(b)-1)/(b))
#define all(x) x.begin(), x.end()
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define dbg(msg, var) cerr << msg << " " << var << endl;

using namespace std;

const int MAX = 200010;
const ll MOD = 998244353;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ld EPS = 1e-7;

const int LOG = ceil(log2(MAX));

// End Template //

namespace seg {
    ll seg[2*MAX], lazy[2*MAX];
    int n;

    ll junta(ll a, ll b) {
        return (a+b)%MOD;
    }

    // soma x na posicao p de tamanho tam
    void poe(int p, ll x, int tam, bool prop=1) {
        seg[p] += x*tam;
        seg[p] %= MOD;
        if (prop and p < n) lazy[p] += x;
    }

    // atualiza todos os pais da folha p
    void sobe(int p) {
        for (int tam = 2; p /= 2; tam *= 2) {
            seg[p] = junta(seg[2*p], seg[2*p+1]);
            poe(p, lazy[p], tam, 0);
        }
    }

    // propaga o caminho da raiz ate a folha p
    void prop(int p) {
        int tam = 1 << (LOG-1);
        for (int s = LOG; s; s--, tam /= 2) {
            int i = p >> s;
            if (lazy[i]) {
                poe(2*i, lazy[i], tam);
                poe(2*i+1, lazy[i], tam);
                lazy[i] = 0;
            }
        }
    }

    void build(int n2) {
        n = n2;
        for (int i = n-1; i; i--) seg[i] = junta(seg[2*i], seg[2*i+1]);
        for (int i = 0; i < 2*n; i++) lazy[i] = 0;
    }

    ll query(int a, int b) {
        ll ret = 0;
        for (prop(a+=n), prop(b+=n); a <= b; ++a/=2, --b/=2) {
            if (a%2 == 1) ret = junta(ret, seg[a]);
            if (b%2 == 0) ret = junta(ret, seg[b]);
        }
        return ret;
    }

    void update(int a, int b, int x) {
        int a2 = a += n, b2 = b += n, tam = 1;
        for (; a <= b; ++a/=2, --b/=2, tam *= 2) {
            if (a%2 == 1) poe(a, x, tam);
            if (b%2 == 0) poe(b, x, tam);
        }
        sobe(a2), sobe(b2);
    }
};


int main()
{sws;

    int n, k, l, r;
    cin >> n >> k;
    vii S;

    seg::build(n+10);
    seg::update(1, 1, 1);
    for(int i=0;i<k;i++){
        cin >> l >> r;
        S.pb({l, r});
    }

    for(int i=1;i<=n;i++){
        ll val = seg::query(i, i);
        // cout << "i, val = " << i << " " << val << endl;
        for(auto s: S)
            seg::update(min(i+s.ff, n+1), min(i+s.ss, n+1), val);
    }

    cout << seg::query(n, n) << endl;


    return 0;
}

Measured memory_bytes: 9888
import java.util.Calendar;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int M1 = sc.nextInt();
		int D1 = sc.nextInt();
		int M2 = sc.nextInt();
		int D2 = sc.nextInt();
		int answer = 0;

		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, 2019);
		cal.set(Calendar.MONTH, M1 - 1);
		if (cal.getActualMaximum(Calendar.DATE) == D1) answer++;

		System.out.println(answer);
	}
}


Measured memory_bytes: 25424
N = int(input())
A = list(map(int, input().split()))


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors


num = int(N // 2 + 1)
cnt = {}
for i in range(1, N + 1):
    cnt[i] = 0
A.reverse()
B = []

for i, a in enumerate(A):
    i = N - i
    if i >= num:
        if a == 1:
            for p in make_divisors(i):
                cnt[p] = (cnt[p] + 1) % 2
            B.append(i)
    else:
        if cnt[i] != a:
            for p in make_divisors(i):
                cnt[p] = (cnt[p] + 1) % 2
            B.append(i)

print(len(B))
B = list(map(str, B))
print(' '.join(B))


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

int main(){
  long int N;
  cin >> N;
  long int tmp = trunc(sqrt(N));
  for(long int i = tmp; i>0; i--){
    if(N % i == 0){
   	tmp = N / i;
    cout << (tmp-1) + (i-1) << endl;
    return 0;
    }
  }
  cout << N - 1 << endl;
  return 0;
}

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

int main(){
	int a,b,c;
  	cin >> a >> b >> c;
  	int ma=max(max(a,b),max(b,c));
  	if(a%2==b%2 && b%2==c%2) cout << (ma*3-a-b-c)/2 <<endl;
  	else if(ma%2!=a%2 && ma%2!=b%2) cout << (ma*3-a-b-c)/2 << endl;
	else if(ma%2!=b%2 && ma%2!=c%2) cout << (ma*3-a-b-c)/2 << endl;
	else if(ma%2!=c%2 && ma%2!=a%2) cout << (ma*3-a-b-c)/2 << endl;
	else cout << ((ma+1)*3-a-b-c)/2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

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

    ll n, a, b;
    cin >> n >> a >> b;

    vector<ll> x(n);
    for(int i = 0; i < n; ++i) cin >> x[i];
    
    ll prev = x[0];
    ll res = 0;
    for(int i = 1; i < n; ++i){
        ll curr = x[i];
        ll dist = curr - prev;
        res += min(dist*a, b);

        prev = curr;
    }
    
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3988
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

def func():
    N = int(input())

    A = list(map(int, input().split()))
    P = [[(A[0], 0), (0, 0)] for i in range(2 ** (N + 1))]
    A = [0] * (2 ** N) + A

    for i in range(2 ** N + 1, 2 ** (N + 1)):
        if (A[i], i - 2**N) > P[i][0]:
            P[i][1] = P[i][0]
            P[i][0] = (A[i], i - 2**N)
        elif (A[i], i) > P[i][1]:
            P[i][1] = (A[i], i - 2**N)
        for j in range(N):
            piyo = i - 2 ** N
            if (piyo & (1 << j)) == 0:
                index = piyo + (1 << j) + 2 ** N
                for k in range(2):
                    if P[i][k] > P[index][0]:
                        P[index][1] = P[index][0]
                        P[index][0] = P[i][k]
                    elif P[i][k] > P[index][1] and P[i][k] != P[index][0]:
                        P[index][1] = P[i][k]
    ans = 0
    for i in range(2 ** N + 1, 2 ** (N + 1)):
        ans = max(ans, P[i][0][0] + P[i][1][0])
        print(ans)
    #print(P)

func()

Measured memory_bytes: 132428
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
int main()
{
    string S;
    cin >> S;
    vector<vector<lint>> dp(S.size(), vector<lint>(13, 0));
    if(S[0] == '?') {
        REP(i, 10) {
            dp[0][i] = 1;
        }
    } else {
        dp[0][S[0] - '0'] = 1;
    }
    FOR(i, 1, S.size()) {
        if(S[i] == '?') {
            REP(j, 13) {
                int y = 10*j;
                REP(k, 10) {
                    int x = y + k;
                    x = x % 13;
                    dp[i][x] = (dp[i][x] + dp[i-1][j]) % MOD;
                }
            }
        } else {
            REP(j, 13) {
                lint x = 10*j + (int)(S[i] - '0');
                x = x % 13;
                dp[i][x] = (dp[i][x] + dp[i-1][j]) % MOD;
            }
        }
    }
    cout << dp[S.size()-1][5] << endl;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  
  else if (A + B < C + D) {
    cout << "Right" << endl;
  }
  
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {

	int a[10002], b[10002], n=0, c;

	do {
		n += 2;
		scanf("%d %d", &a[n], &a[n+1]);
		if (a[n] <= a[n+1])
		{
			b[n] = a[n], b[n + 1] = a[n + 1];
		}
		else if(a[n] >= a[n + 1])
		{
			b[n + 1] = a[n], b[n] = a[n + 1];
		}


	} while ((a[n] != 0) || (a[n+1] != 0));
	c = n;
	for (n = 2; n <= (c - 2); n += 2)
	{
		printf("%d %d\n", b[n], b[n + 1]);
	}

	return 0;
}

Measured memory_bytes: 1824
#include<iostream>
#include<string>
#include<cctype>
#include<algorithm>
using namespace std;
typedef string::const_iterator Cursol;
int P, Q, R;
int tmp1[3] = { 2, 1, 0}, tmp2[3][3] = {{0,0,0},{0,1,1},{0,1,2}};
int tmp3[3][3] = {{0,1,2},{1,1,2},{2,2,2}};

int formula(Cursol &c){
  int ret ;
  if(*c == 'P') ret = P;
  else if(*c == 'Q') ret = Q;
  else if(*c == 'R') ret = R;
  else if(isdigit(*c)) ret = *c - '0';
  else if(*c == '-') return tmp1[formula(++c)];
  else if(*c == '('){
    ret = formula(++c);
    if(*c == '*') ret = tmp2[ret][formula(++c)];
    else if(*c == '+') ret = tmp3[ret][formula(++c)];
  }
  c++;
  return ret;
}
int main(){

  string s;
  Cursol c;

  while( cin >> s, s != "."){
    int ret = 0;
    for(P = 0 ; P < 3 ; P++ ){
      for(Q = 0 ; Q < 3 ; Q++ ){
        for(R = 0 ; R < 3 ; R++ ){
          c = s.begin();
          if( 2 == formula(c)) ret++;
        }
      }
    }
    cout << ret << endl;
  }
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
using namespace std;
const int N=200100;
int a[N];
int main(){
	int ans=0,l0=0,l1=0;
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n+1;i++){
		int a1=0,a2=a[i]-a[i-1];
		int r0=l0+max(a1,a2),r1=min(l0+min(a1,a2),l1+max(a1,a2));
		r0=max(r0,0);
		r1=max(r1,0);
		if(r1>a[i]){
			l0=l1=0;
			ans+=2;
		}
		else if(r0>a[i]){
			l0=r1;
			l1=0;
			ans++;
		}
		else{
			l0=r0;
			l1=r1;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

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

int n,W;
int v[105],w[105];
int dp[105][10005];

int main(){
  cin >> n >> W;
  rep(i,0,n){
    cin >> v[i+1] >> w[i+1];
  }
  rep(i,1,n+1) rep(j,0,W+1){
    int u = 0;
    if(j-w[i] >=0) u = dp[i][j-w[i]] + v[i];
    dp[i][j] = max(dp[i-1][j],u);
  }
  cout << dp[n][W] << endl;

  return 0;
}



Measured memory_bytes: 7036
/*
            _ _  ___            __ _ _  _       _     
 _   _  ___| | |/ _ \__      __/ _| | || |  ___| |__  
| | | |/ _ \ | | | | \ \ /\ / / |_| | || |_/ __| '_ \ 
| |_| |  __/ | | |_| |\ V  V /|  _| |__   _\__ \ | | |
 \__, |\___|_|_|\___/  \_/\_/ |_| |_|  |_| |___/_| |_|
 |___/                 

 */

#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 1000000000000000007
#define MAXN 300005


signed main(){
	fast
	int n, temp;
	cin>>n;
	vector<int> v, c;
	For(i, 0, n){
		cin>>temp;
		v.pb(temp);
	}
	For(i, 0, n){
		cin>>temp;
		c.pb(temp);
	}
	int ans =0;
	For(i, 0, n){
		if(v[i]>c[i]){
			ans+=(v[i]-c[i]);
		}
	}
	cout<<ans<<endl;
    return 0;
}
    



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

typedef long long ll;

int main() {
  int i, bit;
  char s[20];
  scanf("%s", s);

  int s_len = strlen(s);

  int a[20];

  for (i = 0; i < s_len; i++) {
    a[i] = s[i]-'0';
  }

  ll ans = 0;

  for (bit = 0; bit < (1<<(s_len-1)); bit++) {
    ll cur = a[0];
    for (i = 0; i < s_len-1; i++) {
      if ( (bit>>i) & 1 ) {
        ans += cur;
        cur = a[i+1];
      } else {
        cur *= 10;
        cur += a[i+1];
      }
    }
    ans += cur;
  }

  printf("%lld\n", ans);

  return 0;
}

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

using namespace std;

#define LL long long 
#define ULL unsigned LL
#define LD long double 

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s, t;
	cin>>s>>t;
	int ans = 1e9 + 2137;
	for(int i=t.size()-1; i<s.size(); i++) {
		int kt = 0;
		int w = 0;
		for(int j=(i-t.size()+1); j<=i; j++) {
			if(s[j] != t[kt++])
				w++;
		}
		ans = min(ans, w);
	}
	cout<<ans;
}


Measured memory_bytes: 3640
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef pair<double,double> P;
typedef complex<double> CP;
typedef long long ll;

string s;
string tmp;

int main(){
	getline(cin,s);
	bool f=false;
	rep(i,s.size()){
		if(s[i]==32||s[i]==','||s[i]=='.'){
			if(tmp.size()>=3&&tmp.size()<7){
				if(f) cout<<" ";
				cout<<tmp;
				f=true;
			}
			tmp.clear();
		}
		else{
			tmp+=s[i];
		}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1172
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
L = [LIST() for i in range(N-1)]

graph = defaultdict(list)
for u, v, w in L:
    graph[u-1].append((v-1, w))
    graph[v-1].append((u-1, w))

color = [0] * N
color[0] = 1

def dfs(node):
    for i, w in graph[node]:
        if color[i] == 0: # not visited
            if w % 2 == 0: # guusuu        
                color[i] = color[node]
            else:
                color[i] = color[node] * (-1)
            dfs(i)

dfs(0)
for c in color:
    if c == 1:
        print(0)
    else:
        print(1)

        


Measured memory_bytes: 108076
using System;
using System.Linq;
using System.Collections.Generic;


namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            MainStream();
        }
        static void MainStream()
        {
            Scan sc = new Scan();
            write wr = new write();

            int n = sc.intarr[0];
            string[] ss = new string[n];

            for (int i=0; i<n; i++)
            {
                ss[i] = Console.ReadLine();
            }

            int m = sc.intarr[0];
            string[] ts = new string[m];

            for (int i = 0; i < m; i++)
            {
                ts[i] = Console.ReadLine();
            }

            int max = -101;

            foreach(var word in ss)
            {
                //Console.WriteLine($"word:{word}");
                int count = 0;
                foreach (var s in ss)
                {
                    if(word == s)
                    {
                        count++;
                    }
                }
                foreach(var t in ts)
                {
                    if(word == t)
                    {
                        count--;
                    }
                }
                if(count < 0)
                {
                    count = 0;
                }
                max = Math.Max(max, count);
            }

            wr.wri(max);
        }


    }

    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => str.ToArray();


    }



    class write
    {
        public void wri<Type>(Type x)
        {
            Console.WriteLine(x);
        }
    }

    class Method
    {
        static public int max(params int[] nums)
        {

            int maxx = nums[0];
            for (int i = 1; i < nums.Length; i++)
            {
                maxx = Math.Max(maxx, nums[i]);
            }
            return maxx;
        }
    }
}


Measured memory_bytes: 13396
while True:
    try:
        a = input()
        b = 0
        c = 0
        for i in range(len(a)-2):
            if a[i]=='J':
                if a[i+1]=='O':
                    if a[i+2]=='I':
                        b+=1
            if a[i]=='I':
                if a[i+1]=='O':
                    if a[i+2]=='I':
                        c+=1
        print(b)
        print(c)
    except:
        break


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

int main() {
  int N;
  cin >> N;
  vector<string> blue(N);
  rep(i, 0, N) cin >> blue.at(i);

  int M;
  cin >> M;
  vector<string> red(M);
  rep(i, 0, M) cin >> red.at(i);

  auto calc = [&](string s) {
    int buf = 0;
    for (string t: blue) {
      if (t == s) buf++;
    }
    for (string t: red) {
      if (t == s) buf--;
    }
    return buf;
  };

  int Ans = 0;

  for (string t: blue) {
    Ans = max(Ans, calc(t));
  }

  cout << Ans << endl;
}


Measured memory_bytes: 3616
x,y = map(int, input().split())
a = 0
b = 0
flag = True
while flag:
    for a in range(x+1):
        for b in range(x+1):
            if x - a == b and y - 2*a == 4*b:
                flag = False
                break
            else:
                continue
    break

if flag:
    print("No")
else:
    print("Yes")

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int main() {
	LL n, k;
	cin >> n >> k;
	
	vector<pair<LL, LL>> v(n);
	inc(i, n) { cin >> v[i].FI >> v[i].SE; }
	sort(RALL(v));
	
	vector<LL> x, y;
	inc(i, v.size()) { (i == 0 || v[i].FI != v[i - 1].FI ? x : y).PB(v[i].SE); }
	sort(RALL(x));
	sort(RALL(y));
	
	vector<LL> sx(n + 1, -1e18), sy(n + 1);
	sx[0] = 0;
	inc(i, x.size()) { sx[i + 1] = sx[i] + x[i]; }
	inc(i, y.size()) { sy[i + 1] = sy[i] + y[i]; }
	
	LL ans = 0;
	incII(i, 0, k) { setmax(ans, sx[i] + sy[k - i] + 1LL * i * i); }
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 4340
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 100010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n);
    cins(all(a));
    bool ok = 1;
    if (a[0] != 0) ok = 0;
    ll now = 0,cnt = 0;
    rep(i,1,n){
        if (a[i] == 0 || a[i] == 1){
            now = a[i];
            continue;
        }
        if (a[i] > now+1) ok = 0;
        now = a[i];
    }
    ll stock = 0;
    now = 0;
    if (ok){
        rep(i,n){
            if (a[i] < now){
                cnt += stock;
                stock = a[i];
            }
            else if (a[i] == now){
                cnt += a[i];
            }
            else{
                stock = a[i];
            }
            now = a[i];
        }
        PRINT(cnt+now);
    }
    else PRINT(-1);
}    


Measured memory_bytes: 1792
arr1 = $stdin.gets.chomp.split(" ")
arr1.map! do |a_j|
 a_j.to_i
end
arr2 = $stdin.gets.chomp.split(" ")
arr2.map! do |a_j|
 a_j.to_i
end

x = arr1[0]*arr1[1] - (arr2[0]*arr1[1]+arr2[1]*arr1[0]-arr2[0]*arr2[1])
puts x

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int sum = 0;
 
  for(int i = 0; i < N; i++){
    
    
    int x, y;
    cin >> x >> y;
    
    sum += y - x + 1;
  }

  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
    string S;

    cin >> S;
    int R = 0, Rmax = 0;
    for (int i = 0; i < 3; i++) {
        if (S[i] == 'S') {
            Rmax = max(Rmax, R);
            R = 0;
        } else {
            R++;
        }
    }
    Rmax = max(Rmax, R);
    cout << Rmax << endl;
    return 0;
}


Measured memory_bytes: 3552
import java.util.Scanner;

class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int min = 1000;
        int max = 0;
        for (int i = 0; i < n; i++) {
            int a = scanner.nextInt();
            if (a < min) {
                min = a;
            }
            if (a > max) {
                max = a;
            }
        }
        System.out.println(max - min);
    }
}


Measured memory_bytes: 21844
use std::collections::VecDeque;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut graph = vec![vec![]; n];
    for _ in 0..m {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        graph[a].push(b);
    }

    let bfs = |start: usize, ans: &mut Vec<usize>, min_length: &mut usize| {
        let mut dist = vec![(n, n); n];
        dist[start] = (0, start);
        let mut queue = VecDeque::new();
        queue.push_back(start);
        while let Some(v) = queue.pop_front() {
            for &next in graph[v].iter() {
                if dist[next].0 > dist[v].0 + 1 {
                    dist[next].0 = dist[v].0 + 1;
                    dist[next].1 = v;
                    queue.push_back(next);
                } else if next == start {
                    let mut a = vec![];
                    let mut cur = v;
                    a.push(cur);
                    while cur != start {
                        cur = dist[cur].1;
                        a.push(cur);
                    }
                    if *min_length > a.len() {
                        *min_length = a.len();
                        *ans = a;
                    }
                }
            }
        }
    };
    let mut min_length = n + 1;
    let mut ans: Vec<usize> = vec![];
    for start in 0..n {
        bfs(start, &mut ans, &mut min_length);
    }

    if ans.is_empty() {
        println!("-1");
    } else {
        println!("{}", ans.len());
        for ans in ans.into_iter() {
            println!("{}", ans + 1);
        }
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define REP(i, N) for(int i = 0; i < N; ++i)
#define REEP(i, N) for(int i = N - 1; i >= 0; --i)
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,m,n) for(int i = m; i < n; ++i)
#define RFOR(i,m,n) for(int i = n - 1; i >= m; --i)
#define CIN(a) cin >> a
#define CIN2(a, b) cin >> a >> b
#define CIN3(a, b, c) cin >> a >> b >> c
#define COUT(a) cout << a << endl
#define COUT2(a, b) cout << a << " " << b << endl
#define COUT3(a, b, c) cout << a << " " << b << " " << c << endl
#define pb push_back
#define PB push_back
#define VINT(v, n) vector<int> v(n); REP(i, n) { v[i] = 0 }
#define VINT2(v, n, m) vector<vector<int> > v(n, vector<int>(m)); REP(i, n) { REP(j, m) { v[i][j] = 0 } }
#define VCHAR(v, n) vector<char>v(n)
#define KIRIAGE(a, b) a += (b - a % b) % b
#define CEIL(c, a, b) if(a % b == 0) { c = a / b;} else { c = a / b + 1;}
#define sp(n) setprecision(n)
#define INF 1000000000
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef long long ll;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
	int N;
	CIN(N);
	COUT(N * (N + 1) / 2);
}


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

using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define ll long long 
#define endl '\n'
#define inf INT_MAX

int main()
{
	set<int>s;
	int a, b, c;
	
	cin>> a >> b >> c;
	s.insert(a);
	s.insert(b);
	s.insert(c);
	if(s.size() == 2) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
//============================================================================
// Name        : abc132_c.cpp
// Author      : abb
// Version     :
// Copyright   : [Your copyright notice]
// Description : Hello World in C++, Ansi-style
//============================================================================

/*
 C - Divide the Problems

 実行時間制限: 2 sec / メモリ制限: 1024 MB

 配点 : 300 点

 問題文
 高橋君は、 N 個の競技プログラミング用の問題をつくりました。
 それぞれの問題には 1 から N の番号がついており、問題 i の難易度は整数 d_i で表されます(大きいほど難しいです)。
 高橋君はある整数 K を決めることで、

 ・難易度が K 以上ならば「 ARC 用の問題」
 ・難易度が K 未満ならば「 ABC 用の問題」

 という風に、これらの問題を二種類に分類しようとしています。
 「ARC 用の問題」と「ABC 用の問題」が同じ数になるような整数 K の選び方は何通りあるでしょうか。

 制約

 ・2 <= N <= 10^5
 ・N は偶数である。
 ・1 <= d_i <= 10^5
 ・入力は全て整数である。
 */
#pragma GCC optimize ("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

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

	int n;
	cin >> n;
	vector<int> d(n);
	for (int i = 0; i < n; ++i) {
		cin >> d[i];
	}
	sort(d.begin(), d.end());

	int size = d.size();
	// k 以上が難しいことにするので、差が0でない限り分けられる
	int ans = d[size / 2] - d[size / 2 - 1];

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
n=int(input())
a=list(map(int,input().split()))
num=[0]
num1=0
for i in range(n):
    num1+=a[i]
    num.append(num1)
num.sort()
num2=[]
cnt=0
num3=num[0]
for i in range(1,n+1):
    if num3!=num[i]:
        if cnt!=0:
            num2.append(cnt)
        num3=num[i]
        cnt=0
    else:
        cnt+=1
if cnt!=0:
    num2.append(cnt)
ans=0
for i in range(len(num2)):
    ans+=((num2[i]+1)*num2[i])//2
print(ans)


Measured memory_bytes: 30856
#include <iostream>
using namespace std;
typedef long long ll;
ll D[128];
int main() {
  ios::sync_with_stdio(false);
  ll X;
  cin >> X;
  int N = 120;
  for (ll i=0; i<=N; i++) {
    D[i] = i * i * i * i * i;
  }
  for (int i=-N; i<=N; i++) {
    ll a = (i < 0) ? -D[-i] : D[i];
    for (int j=-N; j<=N; j++) {
      ll b = (j < 0) ? -D[-j] : D[j];
      if (a - b == X) {
        cout << i << ' ' << j << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#include<cstdio>
#define el "\n"
#define sp " "
typedef long long ll;

main()
{
	ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll a,b,n;
cin>>a>>b>>n;
if(a%b==0)
cout<<(a/b)*(min(n,b-1));
else
cout<<(a*min(n,b-1))/b;


}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
const long double eps = 1e-10;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; cin >> n;
    VI ans(26, INF);
    FOR(i, 0, n) {
        string s; cin >> s;
        VI cnt(26);
        for (char c : s)++cnt[c - 'a'];
        FOR(j, 0, 26)chmin(ans[j], cnt[j]);
    }

    FOR(i, 0, 26)FOR(j, 0, ans[i])cout << char('a' + i);
    cout << "\n";
}


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

using namespace std;
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;
typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,a,b) for (ll i=(a); i<(b); i++)
typedef pair<ll,ll> PLL;
// }}}

signed main() {
    string s;
    cin>>s;
    ll b=0, ans=0;
    for(auto c: s){
        if (c=='B')
            b++;
        else
            ans += b;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
int n;
const int N= 1e6+5;
int32_t main()
{
    IOS;
    int a, b;
    cin>>a>>b;
    cout<<a*b<<endl;
    return 0;
}


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

#define N 150
int inf=99999999;
int e[N][N];
int mark[N];
int m;
void init(int n)
{
    for(int i=0; i<=n; i++)
        for(int j=0; j<=n; j++)
        {
            if(i==j)e[i][j]=0;
            else
                e[i][j]=inf;
        }
}

void floyd(int n)
{
    for(int i=0; i<=n; i++)
        for(int j=0; j<=n; j++)
            for(int k=0; k<=n; k++)
            {
                    if(e[j][k]>e[j][i]+e[i][k])
                    {
                        e[j][k]=e[j][i]+e[i][k];
                    }
            }
}

int main()
{
    while(scanf("%d",&m),m!=0)
    {
        int n=-1;
        int a,b,c;
        init(150);
        memset(mark,0,sizeof(mark));
        while(m--)
        {
            scanf("%d%d%d",&a,&b,&c);
            e[a][b]=e[b][a]=c;
            if(a>n)n=a;
            if(b>n)n=b;
            mark[a]=1;
            mark[b]=1;
        }

        floyd(n);
        int ans1,ans2;
        ans1=ans2=inf;
        for(int i=0; i<=n; i++)
        {
            int sum=0;
            if(mark[i]==1)
            {

                for(int j=0; j<=n; j++)
                {
                    if(mark[j]==1&&e[i][j]!=inf)
                    {
                        sum+=e[i][j];
                    }
                }
            }
            if(sum<ans2)
            {
                ans2=sum;
                ans1=i;
            }
        }
        printf("%d %d\n",ans1,ans2);
    }
    return 0;
}

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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

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

  vector<int> count(26, 0);

  for (char c : s) {
    count.at(int(c) - 97)++;
  }
  for (int i = 0; i < 26; i++) {
    if (count.at(i) == 0) {
      cout << char(i + 97) << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}


Measured memory_bytes: 512
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from fractions import gcd

a, b, c, d = map(int, readline().split())
print((b - a + 1) - (b // c + b // d) + ((a - 1) // c + (a - 1) // d) + b // (c * d // gcd(c, d)) - (a - 1) // (c * d // gcd(c, d)))


Measured memory_bytes: 5052
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define repr(i, a, n) for (ll i = n - 1; (ll)a <= i; i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 + 99);
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
template <typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T>
T mpow(T a, T n)
{
    T res = 1;
    for (; n; n >>= 1)
    {
        if (n & 1)
            res = res * a;
        a = a * a;
    }
    return res;
}

//cin.tie(0);ios::sync_with_stdio(false);

signed main()
{
    cin.tie(0);ios::sync_with_stdio(false);
    ll n, ans = 0;
    cin >> n;

    multiset<ll> se;
    vector<ll> tpow(31, 1);
    rep(i, 1, 31)
    {
        tpow[i] = tpow[i - 1] * 2;
    }

    rep(i, 0, n)
    {
        ll x;
        cin >> x;
        se.insert(x);
    }

    while(!se.empty())
    {
        ll now=*(--se.end());
        ll need = *ub(all(tpow), now) - now;
        se.erase(se.lb(now));
        auto itr = se.lb(need);

        if(itr==se.end())continue;

        if (need == *itr)
        {
            se.erase(itr);//
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 9600
#include <iostream>
#include <sstream>
#include <cstdio>
#include<stack>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  string s;
  cin>>s;
  stack<int> p1,p2,s3;
  int i=1,tmp=0,sum=0,tmps,cnt=0;
  for(;i<s.length()+1;i++){
    if(s[i-1]=='\\')p1.push(i);
    else if(s[i-1]=='/'&&!p1.empty()){
      tmp=p1.top();
      p1.pop();
      p2.push(i-tmp);
      s3.push(tmp);
    }
  }
  while(!p1.empty())p1.pop();
  while(!p2.empty()){
    tmp=s3.top();
    tmps=p2.top();
    s3.pop();
    p2.pop();
    if(!p2.empty()&&tmp<=s3.top()){
      tmps+=p2.top();
      p2.pop();
      p2.push(tmps);
      s3.pop();
      s3.push(tmp);
    }
    else {
      p1.push(tmps);
      sum+=tmps;
      cnt++;
    }
  }
  cout<<sum<<endl;
  cout<<cnt;
  while(!p1.empty()){
    cout<<" ";
    tmp=p1.top();
    p1.pop();
    cout<<tmp;
    if(p1.empty())break;

  }
  cout<<endl;
  return 0;
}



Measured memory_bytes: 3288
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s, t; cin >> s >> t;

    bool res = true;
    for(int i=0; i<s.size(); i++)
    {
        if(s[i] == t[i]) res = true;
        else{res = false; break;}
    }
    if(res) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



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

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

        int hindo_e[100000];
        int hindo_o[100000];
        for(int i=0; i<100000; i++) hindo_e[i]=hindo_o[i]=0;
        for(int i=0; i<n; i+=2) hindo_e[v[i]]+=1;
        for(int i=1; i<n; i+=2) hindo_o[v[i]]+=1;

        int i1, h1, h2;

        h1=0; h2=0;
        for(int i=0; i<100000; i++){
                if(hindo_e[i]>h1){
                        h2=h1;
                        h1=hindo_e[i];
                        i1=i;
                }
                else if(hindo_e[i]>h2){
                        h2=hindo_e[i];
                }
        }
        int ei1=i1, eh1=h1, eh2=h2;

        h1=0; h2=0;
        for(int i=1; i<100000; i++){  
                if(hindo_o[i]>h1){
                        h2=h1;
                        h1=hindo_o[i];
                        i1=i;
                }
                else if(hindo_o[i]>h2){
                        h2=hindo_o[i];
                }
        }
        int oi1=i1, oh1=h1, oh2=h2;

        int res;
        if(ei1!=oi1) res=eh1+oh1;
        else res=max(eh1+oh2, eh2+oh1);

        int ans=n-res;
        cout<<ans<<endl;

        return 0;
}


Measured memory_bytes: 1408
#include <iostream>
using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main()
{
	ll H, W; cin >> H >> W;
	char C[100][100];
	rep(i, 0, H) {
		rep(j, 0, W) {
			cin >> C[i][j];
		}
	}
	rep(i, 0, H) {
		rep(j, 0, W) {
			cout << C[i][j];
		}
		cout << endl;
		rep(j, 0, W) {
			cout << C[i][j];
		}
		cout << 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;
typedef long long ll;
typedef pair <double,double> P;

int main() {
  int h,w,k;
  cin>>h>>w>>k;
  char s[305][305];
  int ans[305][305];
  rep(i,h) rep(j,w) cin>>s[i][j];
  int cnt=0;
  int num=1;
  rep(i,h) {
    bool flag=false;
    rep(j,w) {
      if (s[i][j]=='#') flag=true;
    }
    if (flag==false) {
      cnt++;
      continue;
    }
    bool b=true;
    if (s[i][0]=='#') b=false;
    rep(j,w) {
      ans[i][j]=num;
      rep(l,cnt+1) {
	ans[i-l][j]=num;
      }
      if (j+1<=w-1&&s[i][j+1]=='#'&&b) b=false;
      else if (j+1<=w-1&&s[i][j+1]=='#') num++;
    }
    num++;
    cnt=0;
  }
  rep(i,cnt) {
    rep(j,w) {
      ans[h-1-i][j]=ans[h-1-cnt][j];
    }
  }
  rep(i,h) {
    rep(j,w) {
      cout<<ans[i][j]<<' ';
    }
    cout<<endl;
  }
  return 0;
}





Measured memory_bytes: 1152