akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

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

        int N = sc.nextInt();

        System.out.println(solve(N));

        sc.close();
    }

    static String solve(int N) {
        int oneDigit = N % 10;

        if (oneDigit == 3) {
            return "bon";
        } else if (oneDigit == 0 || oneDigit == 1 || oneDigit == 6 || oneDigit == 8) {
            return "pon";
        } else {
            return "hon";
        }
    }
}

Measured memory_bytes: 35796
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <algorithm>    // std::copy
#include <iterator>     // std::back_inserter
#include <set>
using namespace std;
 
int main(){
    string S;
    string T;
    cin >> S;
    cin >> T;

    int count = 0;
    for(int i = 0; i < 3 ; i++){
        if(S[i] == T[i]){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
N = input()
L = len(N)

dp = [[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)]
pp = [[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)]
dp[0][0][0][0] = 1

for i in range(L):
    pp, dp = dp, pp
    dp = [[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)]
    n = int(N[i])
    dp[0][0][0][1] += pp[0][0][0][1]
    dp[1][0][0][1] += pp[0][0][0][1] + pp[1][0][0][1]
    dp[0][1][0][1] += pp[0][0][0][1] + pp[0][1][0][1]
    dp[0][0][1][1] += pp[0][0][0][1] + pp[0][0][1][1]
    dp[1][1][0][1] += pp[1][0][0][1] + pp[0][1][0][1] + pp[1][1][0][1] * 2
    dp[1][0][1][1] += pp[1][0][0][1] + pp[0][0][1][1] + pp[1][0][1][1] * 2
    dp[0][1][1][1] += pp[0][1][0][1] + pp[0][0][1][1] + pp[0][1][1][1] * 2
    dp[1][1][1][1] += pp[1][1][0][1] + pp[1][0][1][1] + pp[0][1][1][1] + pp[1][1][1][1] * 3
    if n > 0:
        dp[0][0][0][1] += pp[0][0][0][0]
    if n > 3:
        dp[1][0][0][1] += pp[1][0][0][0] + pp[0][0][0][0]
        dp[1][1][0][1] += pp[1][1][0][0] + pp[0][1][0][0]
        dp[1][0][1][1] += pp[1][0][1][0] + pp[0][0][1][0]
        dp[1][1][1][1] += pp[1][1][1][0] + pp[0][1][1][0]
    if n > 5:
        dp[0][1][0][1] += pp[0][1][0][0] + pp[0][0][0][0]
        dp[1][1][0][1] += pp[1][1][0][0] + pp[1][0][0][0]
        dp[0][1][1][1] += pp[0][1][1][0] + pp[0][0][1][0]
        dp[1][1][1][1] += pp[1][1][1][0] + pp[1][0][1][0]
    if n > 7:
        dp[0][0][1][1] += pp[0][0][1][0] + pp[0][0][0][0]
        dp[1][0][1][1] += pp[1][0][1][0] + pp[1][0][0][0]
        dp[0][1][1][1] += pp[0][1][1][0] + pp[0][1][0][0]
        dp[1][1][1][1] += pp[1][1][1][0] + pp[1][1][0][0]
    if n == 0:
        dp[0][0][0][0] += pp[0][0][0][0]
    if n == 3:
        dp[1][0][0][0] += pp[1][0][0][0] + pp[0][0][0][0]
        dp[1][1][0][0] += pp[1][1][0][0] + pp[0][1][0][0]
        dp[1][0][1][0] += pp[1][0][1][0] + pp[0][0][1][0]
        dp[1][1][1][0] += pp[1][1][1][0] + pp[0][1][1][0]
    if n == 5:
        dp[0][1][0][0] += pp[0][1][0][0] + pp[0][0][0][0]
        dp[1][1][0][0] += pp[1][1][0][0] + pp[1][0][0][0]
        dp[0][1][1][0] += pp[0][1][1][0] + pp[0][0][1][0]
        dp[1][1][1][0] += pp[1][1][1][0] + pp[1][0][1][0]
    if n == 7:
        dp[0][0][1][0] += pp[0][0][1][0] + pp[0][0][0][0]
        dp[1][0][1][0] += pp[1][0][1][0] + pp[1][0][0][0]
        dp[0][1][1][0] += pp[0][1][1][0] + pp[0][1][0][0]
        dp[1][1][1][0] += pp[1][1][1][0] + pp[1][1][0][0]


print(sum(dp[1][1][1]))

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

int main(){
  int a,b;
  cin>>a>>b;
  
  int sum=0;
  
  for (int i=1;i<=b-a;i++){
    sum+=i;
  }
  
  cout<<sum-b<<endl;
  
  
}

  













Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr ll INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    ll N,M;cin >> N >> M;
    ll X[N],Y[N],Z[N],ans = 0;
    REP(i,N) cin >> X[i] >> Y[i] >> Z[i];
    REP(i,8){
        vector<ll> V;
        REP(j,N){
            ll tmp = 0;
            if(i & 1) tmp += X[j];
            else tmp -= X[j];
            if(i & 2) tmp += Y[j];
            else tmp -= Y[j];
            if(i & 4) tmp += Z[j];
            else tmp -= Z[j];
            V.pb(tmp);
        }
        sort ALL(V);
        reverse ALL(V);
        ll ret = 0;
        REP(j,M) ret += V[j];
        ans = max(ans,ret);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
"""
Union Find 木クラス
参考URL：https://note.nkmk.me/python-union-find/

parents
各要素の親要素の番号を格納するリスト
要素が根（ルート）の場合は-(そのグループの要素数)を格納する
例：
    parents[2] = 0 → 要素2の親は0
    parents[0] = -3 → 要素0は根であり、そのグループの要素数は3個
"""
class UnionFind():
    # 初期化（初期状態は全要素が根）
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # xの根を返す
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            # 経路圧縮も同時に行う
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # 要素xが属するグループと要素yが属するグループとを併合する
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        # 根が同じならx,yは既に同じグループ
        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    # 要素xが属するグループのサイズ（要素数）を返す
    def size(self, x):
        return -self.parents[self.find(x)]

    # 要素x, yが同じグループに属するかどうかを返す
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # 要素xが属するグループに属する要素をリストで返す
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    # すべての根の要素をリストで返す
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    # グループの数を返す
    def group_count(self):
        return len(self.roots())

    # {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    # print()での表示用
    # ルート要素: [そのグループに含まれる要素のリスト]を文字列で返す
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n, m = map(int, input().split())
u = UnionFind(n)
for i in range(m):
    a, b = map(int, input().split())
    u.union(a-1, b-1)

print(u.group_count() - 1)

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

typedef long long ll;

int main() {
    int a[4];
    rep(i,4)cin>>a[i];
    sort(a,a+4);
    int ans= 1000 * a[0] + 100 * a[1] + 10 * a[2] + a[3];
    if(ans==1479)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

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

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

using namespace std;

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}

int main() {
	int n, x;
	scanf("%d", &n);
	int ans = 0;
	for (int i = 0; ans != 1 && i < n; i++) {
		scanf("%d", &x);
		if (!ans) {
			ans = x;
			continue;
		}
		ans = gcd(ans, x);
	}
	cout << ans << endl;
	return 0;
}

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

const string check = "Hoshino";

int main()
{
	int n;
	string str;
	cin >> n;
	getline(cin,str);
	for(int loop=0;loop<n;loop++){
		getline(cin,str);
		for(unsigned i=0;i<str.size();i++){
			bool flag = true;
			for(unsigned j=0;j<check.size();j++){
				if(i+j < str.size()){
					if(str[i+j] != check[j])
						flag = false;
					else{
						if(j == check.size()-1 && flag)
							str[i+j] = 'a';
					}
				}
			}
		}
		cout << str << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

signed main(void)
{
    ll n;
    cin >> n;
    ll r = 0;
    vll a(n);
    rep(i, n) {
        cin >> a[i];
    }
    if (a.size() % 2 == 1) {
        mes(0);
        re0;
    }
    Sort(a);
    
    r = a[a.size()/2] - a[a.size()/2-1];
    
    mes(r);
    
    
    
    
}

Measured memory_bytes: 3996
import sys
input = sys.stdin.readline
 
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7

sum_A = sum(A)
ans = 0
for a in A[:-1]:
  sum_A -= a
  ans += a * sum_A

ans %= mod
print(ans)


Measured memory_bytes: 31468
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_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(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define inf 10000000000

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

    ll a, b, c;
    cin >> a >> b >> c;
    cout << ((c >= a && c <= b) ? "Yes" : "No") << endl;
}


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

int main() {
  int n, C;
  cin>>n>>C;
  int d[C][C], c[n][n];
  for (int i=0; i<C; i++) {
    for (int j=0; j<C; j++) {
      cin>>d[i][j];
    }
  }
  for (int i=0; i<n; i++) {
    for (int j=0; j<n; j++) {
      cin>>c[i][j];
      --c[i][j];
    }
  }
  int cost[3][C];
  for (int i=0; i<3; i++) {
    for (int j=0; j<C; j++) {
      cost[i][j] = 0;
    }
  }
  for (int i=0; i<n; i++) {
    for (int j=0; j<n; j++) {
      for (int k=0; k<C; k++) {
        cost[(i+j)%3][k] += d[c[i][j]][k];
      }
    }
  }
  int ans = 1e9;
  for (int c1=0; c1<C; c1++) {
    for (int c2=0; c2<C; c2++) {
      if (c1 == c2) {
        continue;
      }
      for (int c3=0; c3<C; c3++) {
        if (c2 == c3 || c3 == c1) {
          continue;
        }
        int sum_cost = 0;
        int new_c[3] = {c1, c2, c3};
        for (int i=0; i<3; i++) {
          sum_cost += cost[i][new_c[i]];
        }
        ans = min(sum_cost, ans);
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1280
def m(L,R):
 global c;c+=len(L)+len(R)
 T=[]
 for l in L[::-1]:
  while R and R[-1]>l:T+=[R.pop()]
  T+=[l]
 return R+T[::-1]
def d(A):s=len(A)//2;return m(d(A[:s]),d(A[s:])) if len(A)>1 else A
c=0
input()
print(*d(list(map(int,input().split()))))
print(c)


Measured memory_bytes: 63916
let n = Scanf.scanf " %d" (+) 0
let ws = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let s = Array.fold_left (+) 0 ws
let _ = Array.fold_left (fun (m, s1) w -> min m @@ abs @@ s1 + w - (s - (s1 + w)), s1 + w) (max_int, 0) ws |> fst |> Printf.printf "%d\n"

Measured memory_bytes: 384
// I'm a f*cking looser
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fasino ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
#define asc(A) sort(A.begin(),A.end())
#define dsc(A) sort(A.begin(),A.end(),greater<ll>())
#define input(A) for(auto &i:A) cin>>i;
signed main()
{
    fasino
    ll n,m,k;
    cin>>n>>m>>k;
    vector<ll> A(n),B(m);
    input(A);
    input(B);
    ll ans = 0,i=0,j=0;
    for(ll i=1;i<n;i++) A[i]+=A[i-1];
    for(ll i=1;i<m;i++) B[i]+=B[i-1];    
    for(ll i=0;i<=n;i++){
        ll cnt = 0, ko = k;
        if(i>0 and A[i-1]<=ko){
            ko -= A[i-1];
            cnt+=i;
        }
        ll p = upper_bound(B.begin(),B.end(),ko) - B.begin();
        cnt += p;
        ans = max(cnt,ans);
    }
    cout<<ans;
    return 0;
}

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

int main(){
    int n,k;
    cin>>n>>k;
    int ans=k;
    for (int i = 1; i < n; i++){
        ans=ans*(k-1);
    }
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 256
n,m = map( int,input().split() )
a = [ list(map(int,input().split())) for _ in range(n)]

a.sort()

c = 0
for i in range(n):
  x = min(m,a[i][1])
  c += x * a[i][0]
  m -= x
  if m == 0 :
    break

print(c)

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

using namespace std;

int main()
{
  	string s; cin>>s;
  	int cnt=0,ans=0;
  	for (int i=0;i<3;i++){
      if (s[i]=='R'){
      		cnt++;
        	ans=max(cnt,ans);
      } else {
        	cnt=0;
      }
    }
  	cout << ans << endl;
}


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


struct P{
	double x,y,z;
	P(double x,double y,double z):x(x),y(y),z(z){}
	P(){x=y=z=0;}
};
P operator - (const P &a){ return P(-a.x,-a.y,-a.z); }
P operator + (const P &a,const P &b){ return P(a.x+b.x,a.y+b.y,a.z+b.z); }
P operator - (const P &a,const P &b){ return a + (-b); }
double dot(const P &a,const P &b){ return a.x*b.x + a.y*b.y + a.z*b.z; }
double abs(const P &a){ return sqrt(dot(a,a)); }

int main(){
	int T; cin >> T;
	while(T--){
		P l; cin >> l.y >> l.z >> l.x;
		l.y /= l.x;
		l.z /= l.x;
		l.x = 1;
		int N; cin >> N;
		vector<P> p(N);
		for(int i = 0 ; i < N ; i++){
			cin >> p[i].x >> p[i].y >> p[i].z;
		}
		for(int i = 0 ; i < N ; i++){
			for(int j = 0 ; j < N ; j++){
				for(int k = 0 ; k < N ; k++){
					//if( i != 1 || j != 0 || k != 3 ) continue;
					if( i != j && j != k && k != i ){
						double a = abs(p[i]-p[j]);
						double b = abs(p[j]-p[k]);
						double c = abs(p[k]-p[i]);
						if( fabs(a) < 1e-9 ) continue;
						b /= a;
						c /= a;
						a = 1;
						if( fabs(l.x-a) > 1e-5 ) continue;
						if( fabs(l.y-b) > 1e-5 ) continue;
						if( fabs(l.z-c) > 1e-5 ) continue;
						cout << i+1 << " " << j+1 << " " << k+1 << endl;
						goto success;
					}
				}
			}
		}
		success:;
	}
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  st a, b;
  ci(a, b);
  a += b;
  int c = stoi(a);
  dl x = sqrt(c);
  int y = sqrt(c);
  if(x == y){
    co("Yes");
  }
  else{
    co("No");
  }
}


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

int main() {
	int n , k;
	cin >> n >> k ; 
	if(k>n)
		k = n;
	int h[n] = {0} , c[n] = {1000000000} ;
	for(int i = 0 ; i < n ; i++)
		c[i] = 1000000000 ;
	for(int i = 0 ; i < n ; i++)
		cin >> h[i] ;
	c[0] = 0;
	for(int i = 1 ; i < k ; i++)
		for(int j = 0 ; j < i ; j++)
			c[i] = min(c[i] , c[j] + abs(h[i]-h[j]));
	for(int i = k ; i < n ; i++)
		for(int j = 1 ; j <= k ; j++)
			c[i] = min(c[i] , c[i-j] + abs(h[i]-h[i-j]));			
	cout << c[n-1];
	return 0;
}

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b){
    return a*b/__gcd(a,b);
}

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

int main(){

    ll n, m; cin >> n >> m;
    vll k(m), p(m);
    vvll s(m);
    rep(i, m){
        cin >> k[i];
        ll in;
        rep(j, k[i]){
            cin >> in;
            s[i].push_back(in);
        }
    }
    rep(i, m) cin >> p[i];

    ll ans = 0;
    rep(bit, 1<<n){
        bitset<10> sw(bit);
        bool on = true;
        rep(i, m){
            ll cnt = 0;
            rep(j, s[i].size()){
                if(sw.test(s[i][j]-1)) cnt++;
            }
            if(cnt%2 != p[i]) on = false;
        }
        if(on) ans++;
    }

    cout<< ans << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>
#include <set>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

ll calc(vector<vector<ll>> &edges, vector<bool> &visited, ll nid, ll num_visited) {
  if (num_visited + 2 == edges.size()) return 1;
  ll res = 0;
  visited[nid] = true;
  for (auto next : edges[nid]) if (!visited[next]) {
    res += calc(edges, visited, next, num_visited + 1);
  }
  visited[nid] = false;
  return res;
}

int main()
{
  ll N, M;
  cin >> N >> M;
  vector<bool> visited(N+1, false);
  vector<vector<ll>> edges(N+1, vector<ll>());
  for (auto i = 0; i < M; i++) {
    ll a, b;
    cin >> a >> b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }

  cout << calc(edges, visited, 1, 0) << endl;

  return 0;
}


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

using namespace std;

int Sum10(int n);

int main()
{
    // 入力
    int n,k;
    cin >> n >> k;
    int ans;
    if (n%k==0){
        ans = 0;
    }else{
        ans = 1;
    }
    cout << ans <<endl;
    return 0;
}

int Sum10(int n){
    int sum = 0;
    while (n > 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}


Measured memory_bytes: 256
N = int(input())
T = []

for i in range(N):
    T.append(int(input()))

a = 1

def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)

for i in range(N):
    a = a * T[i] // gcd(a,T[i])

print(a)


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

const int mod = 998244353;
int h[401];
long long int p2[401];

vector<vector<long long int> > solve(int l,int r,int base){
	vector<vector<long long int> > res;
	res.resize(2);
	if(l>r){
		res[0].resize(1),res[1].resize(1);
		res[1][0]=1;
		return res;
	}
	int pos=l;
	for(int i=l;i<=r;i++)
		if(h[i]<h[pos])
			pos=i;
	auto ls=solve(l,pos-1,h[pos]),rs=solve(pos+1,r,h[pos]);
	res[0].resize(r-l+2);res[1].resize(r-l+2);
	for(int i=0;i<2;i++)
		for(int ii=0;ii<ls[i].size();ii++)
			for(int j=0;j<2;j++)
				for(int jj=0;jj<rs[j].size();jj++){
					if(i&&j)
						(res[1][ii+jj]+=ls[i][ii]*rs[j][jj])%=mod;
					else
						(res[0][ii+jj]+=ls[i][ii]*rs[j][jj])%=mod;
					(res[0][ii+jj+1]+=ls[i][ii]*rs[j][jj])%=mod;
				}
	for(int _=0;_<h[pos]-base;_++){
		for(int i=0;i<=r-l+1;i++){
			res[1][i]=(res[1][i]*p2[r-l+1-i]+res[0][i])%mod;
			res[0][i]=(res[0][i]*(p2[r-l+1-i]-1+mod))%mod;
		}
	}
	return res;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	p2[0]=1;
	for(int i=1;i<=400;i++)
		p2[i]=2*p2[i-1]%mod;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>h[i];
	auto res=solve(1,n,0);
	long long int ans=0;
	for(int i=0;i<=n;i++){
		if(i&1)	ans=(ans+mod-res[1][i])%mod;
		else	ans=(ans+res[1][i])%mod;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 384
result = 0
A = list()
for i in xrange(5):
    tmp = int(raw_input())
    A.append(tmp)
    result += int(tmp/10) * 10
min = 10
red_count = 0
for i in xrange(5):
    if A[i] % 10 == 0: red_count += 1
    elif min > A[i] % 10:
        min = A[i] % 10

if min == 10: print result
else: print (result+10*(4-red_count)+min)
    

Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back

typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ll, ll> l4;

const int maxn = 2e3+1;
const int N = maxn<<1;
int n;
char s[N];
int a[N];

ll d[maxn][maxn];
ll cost[2][maxn][maxn];
int pos[2][maxn];
int id[300];
const char color[3] = "WB";
int main()
{
  scanf("%d", &n);
  for (int i = 1; i <= 2*n; ++i)
    {
      scanf(" %c %d", s+i, a+i);
    }
  for (int i = strlen(color)-1; i >= 0; --i)
    id[color[i]] = i;
  for (int i = 1; i <= 2*n; ++i)
    pos[id[s[i]]][a[i]] = i;
  for (int c = 0; c < 2; ++c)
    for (int i = 1; i <= n; ++i)
      {
        for (int j = 1; j < i; ++j)
          if (pos[c][j] > pos[c][i])
            ++cost[c][i][0];
        for (int j = 1; j <= n; ++j)
          {
            cost[c][i][j] = cost[c][i][j-1] + (pos[1^c][j] > pos[c][i]);
          }
      }
  for (int i = 1; i <= n; ++i)
    {
      d[i][0] = cost[0][i][0] + d[i-1][0];
      d[0][i] = cost[1][i][0] + d[0][i-1];
    }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      d[i][j] = min(d[i-1][j] + cost[0][i][j], d[i][j-1] + cost[1][j][i]);
  printf("%lld\n", d[n][n]);
}


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

int main(){
  string S;
  cin >> S;
  
  bool ans = false;
  
  for(int i=0; i<2; i++){
    if(S[i] != S[i+1]){
      ans = true;
    }
  }
  
  if(ans == true){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

    

Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

def main():
    x, y = map(int, sys.stdin.readline().split())

    cnt = 0
    i = x
    while i <= y:
        cnt += 1
        i += i

    print(cnt)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
ll n, m, k, r, c, num, g, cnt[15];
ll dr[10] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
ll dc[10] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
//set<ll> v;
map<ll, ll> s;
int main()
{
	ll i, j, w, tr, tc;
	map<ll, ll>::iterator it;
//	freopen ("input.txt", "r", stdin);
	cin >> n >> m >> k;
	for (i = 0; i < k; i++) {
		scanf ("%lld %lld", &r, &c);
		for (j = 0; j < 9; j++) {
			tr = r + dr[j];
			tc = c + dc[j];
			if (tr < 2 || tr > n - 1 || tc < 2 || tc > m - 1) continue;
			num = tr * 1000000000 + tc;
			s[num]++;
		}
	}
	for (it = s.begin(); it != s.end(); it++) {
		num = it->second;
		cnt[num]++;
		g++;
	}
	cnt[0] = (n - 2) * (m - 2) - g;
	for (i = 0; i <= 9; i++) {
		printf("%lld\n", cnt[i]);
	}
    return 0;
}


Measured memory_bytes: 56448
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    int n;cin >> n;int cnt=0;
    rep(i,n){
        int k;cin >> k;
        if(i%2==0&&k%2==1)cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int t,a[100],i=0;
  cin>>t;
  while(i<t)
  {
  	cin>>a[i];
    i++;
  }
  int m=0,s=0,f=0;
  for(i=0;i<t;i++)
  {
    s=0;
    for(m=0;m<i;m++)
    {
    	s=s+a[m];
    }
    for(m=(i+1);m<t;m++)
    {
        s=s+a[m];
    }
    if(s<=a[i])
    {
      f=1;
      break;
    }
  }
  if(f==0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
from math import factorial,sqrt,ceil
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"

rows = [int(input()) for _ in range(6)]
n,a,b,c,d,e = rows
minvar = min(rows[1:])

ans = ceil(n/minvar) + 4

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


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

public static class P
{
    public static void Main()
    {
        string s = Console.ReadLine();
        var freq = s.GroupBy(x => x).Select(x => x.Count()).ToList();
        long res = 0;
        while (freq.Count != 1)
        {
            var a = freq.Min();
            freq.Remove(a);
            var b = freq.Min();
            freq.Remove(b);
            res += a + b;
            freq.Add(a + b);
        }
        if (res == 0) res = s.Length;
        Console.WriteLine(res);
    }
}



Measured memory_bytes: 18672
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        HashSet<String> set = new HashSet<String>();

        for (int i = 0; i < N; i++) {
            String A = sc.next();
            if (!set.contains(A)) {
                set.add(A);
            } else {
                set.remove(A);
            }
        }
        System.out.println(set.size());
        sc.close();

    }
}

Measured memory_bytes: 51692
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

long long modPow(long long x, long long n, long long mod = MODV){
    if(n == 0) return 1;
    if(n%2 == 0) return modPow(x*x%mod, n/2, mod)%mod;
    return x%mod * modPow(x%mod, n-1, mod)%mod;
}

int main(){
    Init();
    ll n; cin >> n;
    // nが偶数だったら入力値は奇数、nが奇数だったら入力値は偶数でなければいけない
    ll chk = (n%2 == 0) ? 1 : 0;

    // 入力処理
    map<ll, ll> cnt;
    rep(i, n){
        ll in; cin >> in;
        cnt[in]++;
    }

    ll exp = 0;
    for(auto p: cnt){
        // 偶奇が一致しない場合はループから脱出
        if(p.first%2 != chk){ n = -1; break; }
        // 奇数長の場合で"0"の数が1以外の時はループから脱出、一致するなら無視
        else if(p.first == 0 && p.second != 1){ n = -1; break;}
        else if(p.first == 0 && p.second == 1){ continue; }
        // 2回以上同じ数字が出てきてもダメ
        else if(p.first != 0 && p.second != 2) { n = -1; break;}
        else exp++;
    }

    if(n == -1) cout << 0 << endl;
    else cout << modPow(2, exp, MODV) << endl;
}

Measured memory_bytes: 4224
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    s = S()

    return s.replace(',', ' ')


print(main())


Measured memory_bytes: 5544
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N; cin >> N;
	int s[N];
	int sum = 0;
	rep(i, N) cin >> s[i];
	rep(i, N) sum += s[i];
	if (sum % 10 != 0) {
		cout << sum << endl;
		return 0;
	}
	sort(s, s + N);
	rep(i, N) {
		if (s[i] % 10 != 0) {
			cout << sum - s[i] << endl;
			return 0;
		}
	}
	cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

const int mod = 1000000007;
//const int mod = 998244353;

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

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

istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> frac, ifrac;
  combination(int n):frac(n+1), ifrac(n+1) {
    assert(n < mod);
    frac[0] = 1;
    for (int i = 1; i <= n; ++i) frac[i] = frac[i-1]*i;
    ifrac[n] = frac[n].inv();
    for (int i = n; i >= 1; --i) ifrac[i-1] = ifrac[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return frac[n]*ifrac[k]*ifrac[n-k];
  }
} c(1000000);

//head

int b, w;
mint ue = 1, migi = 1;
mint sum = 1;

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

  rep(i, b+w) {
    mint now = sum;
    sum *= 2;
    if(i >= w) {
      now += ue;
      ue *= 2;
      ue += c(i, i-w+1);
    }
    if(i >= b) {
      now -= migi;
      migi *= 2;
      migi += c(i, i-b+1);
    }
    cout << now/sum << '\n';
  }
}

Measured memory_bytes: 18616
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<unordered_set>
#include<unordered_map>
using namespace std;
int dfs(vector<vector<int>> &g,vector<int> &dist,int x){
	if(dist[x])
	    return dist[x];
	for(int y: g[x])
		dist[x] = max(dist[x],1 + dfs(g,dist,y));
	return dist[x];
}
int main(){
	int n,m,a,b;
	cin>>n>>m;
	vector<vector<int>> g(n+1);
	for(int i=0;i<m;i++){
		cin>>a>>b;
		g[a].push_back(b);
    }
    vector<int> dist(n+1,0);
    int ans=0;
	for(int i=1;i<=n;i++){
	    if(dist[i]==0)
		    ans = max(ans,dfs(g,dist,i));	
	}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 11152
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

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

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

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

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

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

ll gcd(ll  a,ll b){
    ll r;
    if(a < b){
        ll tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return b;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

ll wa(ll a,ll c,ll d,ll cd){
    ll t1 = (a-1)/c;
    ll t2 = (a-1)/d;
    ll t3 = (a-1)/cd;
    return  a-1-t1-t2+t3;
}

void solve() {
  ll n;
  cin >> n;
  vector<ll> d(n);
  rep(i,0,n) cin >> d[i];
  sort(d.begin(),d.end());
  double center = d[n/2]-d[n/2-1];
  cout << center << endl;

}
int main() {

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

	solve();

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

int main() {
  int n, m; cin>>n>>m;
  vector<pair<int, int>> ab;
  rep(i, m) {
    int a, b; cin>>a>>b;
    ab.emplace_back(a, b);
  }
  sort(ab.begin(), ab.end(), [](auto &a, auto &b){return (a.second < b.second);});

  int ans = 0;
  int cur = -1;
  rep(i, m) {
    if (cur <= ab[i].first) {
      ++ans;
      cur = ab[i].second;
    }
  }
  print(ans);

  return 0;
}


Measured memory_bytes: 1400
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int main(){

    string s;
    int a,b,c,d;
    cin >> s;
    int count = 0;

    for(int i = 0;i < s.length();i++){
        if(s[i] == '+'){
            count++;
        }else{
            count--;
        }
    }
    cout << count << endl;

    //cout <<  << endl;


    return 0;
}

Measured memory_bytes: 256
s = gets.chomp
t = gets.chomp
ts = t.size
ss = s.size

(ss-ts).downto(0) do |i|
  f = true
  for j in 0..ts-1
    if !(t[j] == s[i+j] || s[i+j] == "?")
      f = false
      break
    end
  end
  if f
    for j in 0..i-1
      print s[j] == "?" ? "a" : s[j]
    end
    print t
    for j in i+ts..ss-1
      print s[j] == "?" ? "a" : s[j]
    end
    exit
  end
end
puts "UNRESTORABLE"

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

using namespace std;

int main()
{
	int a,b,c; cin >> a>>b>>c;
	if (a == b) {
		if (a == c) {
			cout << "No" << endl;
		}
		else {
			cout << "Yes" << endl;
		}
	}
	else if(b==c){
		cout << "Yes" << endl;
	}
	else if (c == a) {
		if (c == b) {
			cout << "No" << endl;
		}
		else {
			cout << "Yes" << endl;
		}
	}
	else{
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {

    private static PrintWriter out;

    private static <T> void mprintln(T ... ar){
        for(T i: ar) out.print(i + " ");
        out.println();
    }

    public static void main(String[] args) throws FileNotFoundException{

        // Input from file
        // File inputFile = new File("JavaFile.txt");
        // File outputFile = new File("JavaOutputFile.txt");
        // FileReader fileReader = new FileReader(inputFile);
        // Here it ends

        MyScanner sc = new MyScanner();
        // MyScanner sc = new MyScanner(fileReader);

        out = new PrintWriter(new BufferedOutputStream(System.out)); // Output to console
        // out = new PrintWriter(new PrintStream(outputFile)); // Output to file

        getAns(sc);

        out.close();
    }

    /*
     *Don't use builtin function (Math.ceil)
     */

    static final long MOD = (long) (1e9 + 7);

    private static void getAns(MyScanner sc){
        int n = sc.ni();
        int[] ar = sc.niArr0(n);
        int ans = 0;

        for(int i = 1; i < n - 1; i++){
            if((ar[i] < ar[i - 1] && ar[i] > ar[i + 1]) || (ar[i] > ar[i - 1] && ar[i] < ar[i + 1])) ++ans;
        }

        out.println(ans);
    }

    static class MyScanner{
        BufferedReader br;
        StringTokenizer st;

        MyScanner(FileReader fileReader){
            br = new BufferedReader(fileReader);
        }

        MyScanner(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nn(){
            while(st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch(IOException e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine(){
            String ans = "";
            try {
                ans = br.readLine();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            return ans;
        }

        char nc(){
            return nn().charAt(0);
        }

        int ni(){
            return Integer.parseInt(nn());
        }

        long nl(){
            return Long.parseLong(nn());
        }

        double nd(){
            return Double.parseDouble(nn());
        }

        int[] niArr0(int n){
            int[] ar = new int[n];
            for(int i = 0; i < n; i++) ar[i] = ni();
            return ar;
        }

        int[] niArr1(int n){
            int[] ar = new int[n + 1];
            for(int i = 1; i <= n; i++) ar[i] = ni();
            return ar;
        }

        long[] nlArr0(int n){
            long[] ar = new long[n];
            for(int i = 0; i < n; i++) ar[i] = nl();
            return ar;
        }

        long[] nlArr1(int n){
            long[] ar = new long[n + 1];
            for(int i = 1; i <= n; i++) ar[i] = nl();
            return ar;
        }
    }
}

Measured memory_bytes: 21204
# -*- coding: utf-8 -*-
# ITP1_9_A
# 単語の検索

word_cnt = 0
chk_word = input().lower()

while 1:
    line = input()
    if line == "END_OF_TEXT":
        break
    for word in line.split():
        if word.lower() == chk_word:
            word_cnt += 1
print(word_cnt)



Measured memory_bytes: 5556
N, M = map(int, input().split())
A=[]
for j in range(M):
    s, c = map(int, input().split())
    A.append([s-1, str(c)])
if N == 1:
    b = 0
elif N == 2:
    b= 10
else:
    b = 100
ans=[]
for i in range(b, 1000):
    a = 0
    for j in range(M):
        x=str(i)
        if len(x) < N:
            break 
        if A[j][1] == x[A[j][0]]:
            a += 1
    if a == M:
        ans.append(i)
if ans == []:
    print(-1)
else:
    print(min(ans))

Measured memory_bytes: 40560
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

MOD = int(1e09) + 7

def main():
    N = cin.int()
    V = cin.mapInt()
    while len(V) >= 2:
        V.sort()
        V.append((V.pop(0) + V.pop(0)) / 2)
    print(V[0])
    return

if __name__ == "__main__":
    main()


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

vector<int> sw(int a,int b,vector<int> c){
  swap(c.at(a),c.at(b));
  return c;
}

int main() {
  int n;
  cin >> n;
  vector<int> p (n);
  for(int i=0; i<n; i++){
    cin >> p.at(i);
  }
  vector<int> asc;
  for(int i=0; i<n; i++){
    asc.push_back(i+1);
  }
  string ans = "NO";
  if(asc == p){
    ans = "YES";
  }
  else{
    for(int i=0; i<n-1; i++){
      for(int j=i+1; j<n; j++){
        if(asc == sw(i,j,p)){
          ans = "YES";
        break;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define SQ(a) (a)*(a)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define int long long
#define m 1000000007



int32_t main()
{
IOS
//#ifndef ONLINE_JUDGE
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
//#endif


int n;
cin>>n;
int y=n;
int sum=0;
int digit;
while(y)
{
digit=y%10;
sum+=digit;


	y=y/10;
}


if(n%sum==0)
{
	cout<<"Yes";
}
else
{
	cout<<"No";
}


//#ifndef ONLINE_JUDGE
	//cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n\n";
//#endif

return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long LL;
const int N=2e5;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int head[N],nxt[N],to[N];
int L[N],R[N],val[N];
inline void dfs(int k,int fa) {
	for (int i=head[k];i;i=nxt[i])
		if (to[i]!=fa) {
			dfs(to[i],k);
			L[k]=max(L[k],L[to[i]]-1);
			R[k]=min(R[k],R[to[i]]+1);
		}
}
bool check(int k) { return L[k]<=val[k]&&val[k]<=R[k]; }
inline void solve(int k,int fa) {
	if (!check(k)) val[k]-=2;
	if (!check(k)) puts("No"),exit(0);
	for (int i=head[k];i;i=nxt[i])
		if (to[i]!=fa) {
			val[to[i]]=val[k]+1;
			solve(to[i],k);
		}
}
int main()
{
	int n=gi(),i,tot=0,a,b,k;
	for (i=1;i<n;i++) {
		a=gi(),b=gi();
		to[++tot]=b,nxt[tot]=head[a],head[a]=tot;
		to[++tot]=a,nxt[tot]=head[b],head[b]=tot;
	}
	for (k=1;k<=n;k++) L[k]=0,R[k]=1e6;
	for (tot=gi();tot--;)
		k=gi(),L[k]=R[k]=gi();
	dfs(1,0);
	val[1]=R[1];
	solve(1,0);
	puts("Yes");
	for (k=1;k<=n;k++)
		printf("%d\n",val[k]);
	return 0;
}


Measured memory_bytes: 6656