akhauriyash/Code-Regression huggingface dataset:
S = input()

numlist = []
N = len(S)
for i in range(N):
    numlist.append(int(S[i]))

upper = numlist[0] * 10 + numlist[1]
lower = numlist[2] * 10 + numlist[3]

isMU = False
isML = False
if 0 < upper and upper <= 12:
    isMU = True
if 0 < lower and lower <= 12:
    isML = True

if isMU and not(isML):
    print("MMYY")
elif not(isMU) and isML:
    print("YYMM")
elif isMU and isML:
    print("AMBIGUOUS")
else:
    print("NA")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;
//const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
#define int long long
//template
int MOD;
int pw(int n,int k){
  if(k<0)return pw(n,k+MOD-1);
  int res=1;
  while(k){
    if(k&1)res*=n;res%=MOD;
    n*=n;n%=MOD;
    k>>=1;
  }
  return res;
}
std::vector<int> Factorial(4e3),Finverse(4e3);
void Cinit(){// limit is 5e6 /// write Cinit&pw /// this takes 792ms at AtCoder
  Factorial[0]=1;
  for(int i=1;i<4e3;i++)Factorial[i]=Factorial[i-1]*i%MOD;
  for(int i=0;i<4e3;i++)Finverse[i]=pw(Factorial[i],MOD-2);
}
int nCk(int n,int k){
  if(n<k)return 1;if(k<0)return 0;
  int res=Factorial[n];
  res*=Finverse[k];res%=MOD;
  res*=Finverse[n-k];res%=MOD;
  return res;
}
int d[3000][3000];//d[i][j]:pw(-i,j)
//main
signed main(){
  cin>>MOD;Cinit();
  std::vector<int> v(MOD),ans(MOD,0),w(MOD);
  for(int i=0;i<MOD;i++)w[i]=nCk(MOD-1,i);
  for(int i=0;i<3000;i++){
    d[i][0]=1;
    for(int j=1;j<3000;j++)d[i][j]=d[i][j-1]*(MOD-i)%MOD;
  }
  for(int i=0;i<MOD;i++)cin>>v[i];
  for(int i=0;i<MOD;i++){
    if(v[i]==0)continue;
    ans[0]++;
    for(int j=0;j<MOD;j++)ans[j]-=w[j]*d[i][MOD-1-j]%MOD;
    for(int j=0;j<MOD;j++)ans[j]+=MOD,ans[j]%=MOD;
  }
  for(int i=0;i<MOD;i++)cout<<ans[i]<<" ";cout<<endl;
}

/*
解説AC
いい感じに変数を調節するのではなく[x=iの時aそれ以外の時0]という式を足し合わせるというのは典型っぽいね
今回は1と0だけだったけど別に1以外でも解ける問題だったね
アイデア浮かんでさえしまえば実装は簡単な問題で面白い
*/


Measured memory_bytes: 70656
#include <bits/stdc++.h>
#define int llint
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define PI 3.1415926535897
#define EPS (1e-10)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


int H, W;
char S[410][410];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
int b, w;


bool judge(int y, int x){
	return 0 <= y && y < H && 0 <= x && x < W;
}


void dfs(int y, int x){
	char c = S[y][x];
	if(c == '.') b++;
	else w++;
	S[y][x] = '_';
	rep(i, 0, 4){
		int Y = y+dy[i];
		int X = x+dx[i];
		if(judge(Y, X) && S[Y][X] != '_' && S[Y][X] != c) dfs(Y, X);
	}
}


int solve(){
	int ans = 0;
	rep(i, 0, H){
		rep(j, 0, W){
			if(S[i][j] != '_') dfs(i, j);
			ans += b*w;
			b = 0;
			w = 0;
		}
	}
	return ans;
}


signed main(){
	cin >> H >> W;
	rep(i, 0, H)
		rep(j, 0, W) cin >> S[i][j];

	cout << solve() << endl;

	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define maxn 100005
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

template <class T>  inline void smax(T &x,T y){ x = max((x), (y)); }
template <class T>  inline void smin(T &x,T y){ x = min((x), (y)); }


typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

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

int main()
{
    i64 i , j , k , l , m , n ;

    i64 mx , a ;

    scanf("%lld %lld %lld",&n,&k,&a) ;

    i64 g = a ;
    mx = a ;

    for(i=2 ; i<=n ; i++)
    {
        scanf("%lld",&a) ;
        g = gcd(g,a) ;
        mx = max(mx,a) ;
    }

    if(k%g==0 && k<=mx) printf("POSSIBLE\n") ;
    else printf("IMPOSSIBLE\n") ;

    return 0 ;
}


Measured memory_bytes: 256
#include <iostream>
#include<map>
#include<vector>
#include<algorithm>
#include <stdio.h>
#include<set>
#include<string>
#include<math.h>
#include<cmath>
#include<iomanip>
#include<queue>
#include<stack>
#define ll long long
using namespace std;
long double pi = 3.14159265358979323846;
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);


int main()
{
	long double a, b;
	cin >> a >> b;
	if (a == 1 || b == 1)
		cout << "1";
	else
	cout << fixed << setprecision(0) << ceil(a / 2) * ceil(b / 2) + floor(a / 2) * floor(b / 2);
	return 0;
}

Measured memory_bytes: 256
import heapq

n = int(input())
A = [[int(i) for i in input().split()] for i in range(n)]
h = []
DP = {}
heapq.heappush(h,(0,0))
c = 0
while(len(DP)<n):
    tmp = heapq.heappop(h)
    if tmp[1] in DP:
        continue
    c += tmp[0]
    DP[tmp[1]] = 1
    for i,j in enumerate(A[tmp[1]]):
        if j > -1 and not i in DP:
            heapq.heappush(h,(j,i))
print(c)


Measured memory_bytes: 6084
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;

int main(void)

{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << ketasitei;

    string s,t;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    string u;
    cin>>u;
    
    cout<<a-(s==u)<<" "<<b-(t==u)<<endl;
	

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{	
		Scanner scan = new Scanner(System.in);
		long n , k , x , y;
		n = scan.nextLong();
		k = scan.nextLong();
		x = scan.nextLong();
		y = scan.nextLong();
		if (n >= k)
			System.out.println(k * x + (n - k) * y);
		else
			System.out.println(n * x);
	}
	
}





Measured memory_bytes: 8788
using System;

public class Program
{
	public static void Main(string[] args)
	{
		var ss = new StreamScanner();
		//---------------------------------
		//var x = ss.Next<int>();
		//var y = ss.Next<int>();
		for (int i = 1; i <= 10000; i++)
		{

			int num = ss.Next<int>();
			Console.WriteLine("Case " + i + ": " + num);
			if (num == 0)
			{
				break;
			}
		}




		/*
		//????????????int, double, string?????????????????£????????????
		int i = ss.Next<int>();
		double d = ss.Next<double>();
		string s = ss.Next<string>();

		//?????°???????????????????????¨?????????????????????????????????????????????????´???????
		int[] array = ss.Next<int>(10);
		*/
		//---------------------------------
	}
}



public class StreamScanner
{
	private readonly char[] _c = { ' ' };
	private int _index = -1;
	private string[] _input = new string[0];
	private readonly System.IO.StreamReader _sr = new System.IO.StreamReader(Console.OpenStandardInput());

	public T Next<T>()
	{
		if (_index == _input.Length - 1)
		{
			_index = -1;
			while (true)
			{
				string rl = _sr.ReadLine();
				if (rl == null)
				{
					if (typeof(T).IsClass) return default(T);
					return (T)typeof(T).GetField("MinValue").GetValue(null);
				}
				if (rl != "")
				{
					_input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
					break;
				}
			}
		}
		return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
	}

	public T[] Next<T>(int x)
	{
		var ret = new T[x];
		for (var i = 0; i < x; ++i) ret[i] = Next<T>();
		return ret;
	}

	public T[][] Next<T>(int x, int y)
	{
		var ret = new T[y][];
		for (var i = 0; i < y; ++i) ret[i] = Next<T>(x);
		return ret;
	}
}

Measured memory_bytes: 9932
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
const ll N=998244353;
void solve()
{
    ll a;
    cin>>a;
    cout<<a+a*a+a*a*a;
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, N);
  VEC(ll, a, N * 3);
  sort(all(a), greater<>());
  ll ans = 0;
  rep(i, 0, N) {
    ans += a[2 * i + 1];
  }
  print(ans);
}


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

using namespace std;

int main()
{
    long long int k, x;
    cin >> k >> x;

    for(long long int i = x-(k-1); i <= x+(k-1); i++)
    {
        if(i != x-(k-1)) cout << " ";
        cout << i;
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = list(input())
Q = int(input())


#セグメント木
#次の2つの処理をO(log N)で実施することができる
# s, tが与えられた時、区間[s, t)の最小値を求める
# i, xが与えられた時、a_iの値をxに変更する

# INIT = 10 ** 18 #初期値 答えに関係ないもの
MAX_N = 10 ** 6 #与えられる要素数の最大

data = [0] * (2 * MAX_N - 1) #MAX_Nで初期化

#ここに機能をもたせる
def func(vl, vr):
    return (vl | vr)

def init(n_):
    #簡単のため要素数を2のべき乗に
    n = 1
    while n < n_:
        n *= 2
    return n

n = init(N)

def update(k, a): #k番目の値をaに変更 0-index
    # B[a] = k
    k += n - 1
    data[k] = (1 << a)
    while k > 0: #登りながら更新
        k = (k - 1)//2
        data[k] = func(data[k * 2 + 1], data[k * 2 + 2])

def query(a, b, k = 0, l = 0, r = n):
    if r <= a or b <= l:
        return 0
    if a <= l and r <= b:
        return data[k]
    else:
        vl = query(a, b, k * 2 + 1, l, (l + r)//2)
        vr = query(a, b, k * 2 + 2, (l + r)//2, r)
        return func(vl, vr)

def initialize(A): #リストAを与えて初期化する
    for i, a in enumerate(A):
        data[i + n - 1] = (1 << (ord(a) - 97))
        # B[a] = i
    for i in range((2 * n - 3)//2, -1, -1):
        data[i] = func(data[i * 2 + 1], data[i * 2 + 2])

# def index(a): #要素aがもとのどこに保存されているかを返す関数
#     return B[a]

# def value(index): #indexが与えられた時、index番目の値を得る
#     return data[index + n - 1]

#初期値の入力
initialize(S)

# print (data)

#クエリの数
# Q = int(input())
for _ in range(Q):
    a, b, c = map(str, input().split())
    if a == '1':
        update(int(b) - 1, (ord(c) - 97))
    else:
        tmp = query(int(b) - 1, int(c))
        count = 0
        for j in range(26):
            if (tmp >> j) & 1 == 1:
                count += 1
        # print (tmp)
        print (count)
# print (data)

Measured memory_bytes: 112808
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n ; cin >> n ;
	map<ll,ll> m ;
	for(int i=1;i<=n;i++){
		ll tmp = i ;
		for(int j=2;j<=tmp;j++){
			while(tmp%j==0){
				m[j]++ ;
				tmp /= j ;
			}
		}
	}
//	cout << -1 << endl ;
	ll ans = 1 ;
	for(auto &p:m){
		ans = ans*(p.second+1)%mod ;
	}
	cout << ans << endl ;
}


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

int main()
{
    int N, K;
    cin >> N >> K;
    int d, A;
    int sunuke[N] = {0};
    for (int i = 0; i < K; i++) {
        cin >> d;
        for (int j = 0; j < d; j++) {
            cin >> A;
            sunuke[A - 1]++;
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (sunuke[i] == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
bool upper(char n){
return(n>=65&&n<97);}
int main(){

string a;
getline(cin,a);
int len=a.length();
if(upper(a[0]))
cout<<a[0];
for(int i=0;i<len;++i){
if (upper(a[i])&&a[i-1]==' ')
cout<<a[i];
}}

Measured memory_bytes: 256
inmap=input()

odd = {'0':0, '1':0}
ev = {'0':0, '1':0}
for i, tile in enumerate(inmap):
    if i % 2:
        odd[tile] += 1
    else:
        ev[tile] += 1

print(min( ev['0'] + odd['1'] , ev['1'] + odd['0'] ))


Measured memory_bytes: 3188
<?php
// fscanf(STDIN, "%d", $n);
// $a = explode(" ", fgets(STDIN));
// $a = array_map('intval', $a);
// $b = explode(" ", fgets(STDIN));
// $b = array_map('intval', $b);

// $str = fgets(STDIN);
// $arr = explode("n", $str);
// var_dump($arr); 
// $array = str_replace('\n', ' ', fgets(STDIN));
// $array = explode(' ', $array);
// print_r($array);

fscanf(STDIN, "%d", $x);
if ($x >= 400 && $x <= 599) {
    echo 8;
} elseif ($x >= 600 && $x <= 799) {
    echo 7;
} elseif ($x >= 800 && $x <= 999) {
    echo 6;
} elseif ($x >= 1000 && $x <= 1199) {
    echo 5;
} elseif ($x >= 1200 && $x <= 1399) {
    echo 4;
} elseif ($x >= 1400 && $x <= 1599) {
    echo 3;
} elseif ($x >= 1600 && $x <= 1799) {
    echo 2;
} elseif ($x >= 1800 && $x <= 1999) {
    echo 1;
}



// [$L, $R, $d] = fscanf(STDIN, "%d%d%d");
// $ans = 0;
// for ($i = $L; $i <= $R; $i++) {
//     if ($i % $d === 0) {
//         $ans++;
//     }
// }

// echo $ans;


Measured memory_bytes: 16112
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
   int a,b;
   cin>>a;
   cin>>b;
  for (int i=-9500;i<=9500;i++)
    if ((a+i)/2.0==b)
  {
      cout << i << endl;
      break;
  }

}


Measured memory_bytes: 256
def resolve():
    N = int(input())
    A = list(map(int, input().split(" ")))
    cnt = 0
    while True:
        for i in range(N):
            if A[i] % 2 != 0:
                print(cnt)
                return
        for i in range(N):
            A[i] = A[i] // 2
        cnt += 1

            

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 38640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
class Range {
    using T = long long;
    class Iterator {
        T val, step, diff;
    public:
        Iterator(T v, T s, T d): val(v), step(s), diff(d) {}
        T operator*() { return val + diff; }
        bool operator!=(const Iterator &itr) { return step > 0 ? val < itr.val : val > itr.val; }
        Iterator operator++() { val += step; return *this; }
    };
    Iterator _begin, _end;
public:
    Range(T b, T e, T s, T d): _begin(b, s, d), _end(e, s, d) {
        if (s < 0) { _begin = Iterator(e - 1, s, d); _end = Iterator(b - 1, s, d); }
    }
    Range(T b, T e, T s): Range(b, e, s, 0) {}
    Range(T b, T e): Range(b, e, 1, 0) {}
    Range(T e): Range(0, e, 1, 0) {}
    Iterator begin() { return _begin; }
    Iterator end() { return _end; }
};
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin, n;
    vector<P> s[2];
    for (ll i : Range(n)) {
        string st;
        cin, st;
        int depth = 0;
        int mx = 0;
        for (auto &c : st) {
            if (c == '(')
                depth++;
            else
                depth--;
            chmin(mx, depth);
        }
        if (depth >= 0) {
            s[0].emplace_back(mx, depth);
        } else {
            s[1].emplace_back(mx - depth, -depth);
        }
    }
    sort(s[0].rbegin(), s[0].rend());
    sort(s[1].begin(), s[1].end());

    int depth = 0;
    for (ll i : Range(2)) {
        for (auto &ss : s[i]) {
            dump(depth, ss.first, ss.second);
            if (i == 1) {
                ss.second = -ss.second;
                ss.first += ss.second;
            }
            int mx = depth + ss.first;
            if (mx < 0) {
                print("No");
                return 0;
            }
            depth += ss.second;
        }
    }
    print((depth == 0) ? "Yes" : "No");
    return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> vec(N, 0);
  
  for (int i = 0; i < M; i++){
    int a, b;
    cin >> a >> b;
    for (int j = 0; j < N; j ++){
    if ( (a == j+1) || (b == j+1) ){
      vec.at(j) +=1;
    }
    }
        }
        
  
  
  for ( int k = 0; k < N; k ++){
  
  cout <<  vec.at(k)  << endl;
  }
  
  
  
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
int main(void){
  int n;
  while(cin >> n && n){
    pair<double,string> v[55];
    for(int i = 0; i < n; i++){
      int p,a,b,c,d,e,f,s,m;
      cin >> v[i].second >> p >> a >> b >> c >> d >> e >> f >> s >> m;
      v[i].first = -(s*m*f - p)/(double)(a+b+c+(d+e)*m);
    }
    sort(v,v+n);
    for(int i = 0; i < n; i++){
      cout << v[i].second << endl;
    }
    cout << "#" << endl;
  }
}

Measured memory_bytes: 1220
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
	int a=0,b=0,q,i,j,k,kind=-1,pNum;
	char str[1001],meirei[10],tmp[1000];
	char print_str[]="print",reverse_str[]="reverse",replace_str[]="replace";
	
	scanf("%s",str);
	scanf("%d",&q);
	//puts("--以下命令--");
	
	for(i=0;i<q;i++){
		scanf("%s",meirei);
		scanf("%d %d",&a,&b);
		if(strcmp(print_str,meirei)==0){
			for(j=a;j<=b;j++){
				printf("%c",str[j]);
			}
			printf("\n");
			//puts("\nprint終");
		}
		if(strcmp(reverse_str,meirei)==0){
			//printf("tmp:");
			for(j=a;j<=b;j++){
				tmp[j-a]=str[j];
				//printf("%c",tmp[j-a]);
			}//printf("\n");
			pNum=b-a+1;
			k=0;
			for(j=b;j>=a;j--){
				str[j]=tmp[k];
				k++;
			}
			//puts("reverse終了");
		}
		if(strcmp(replace_str,meirei)==0){
			//puts("replaceします");
			scanf("%s",tmp);
			pNum=strlen(tmp);
			//printf("len=%d",pNum);
			for(j=a;j<=b;j++){
				str[j]=tmp[j-a];
			}
			//puts("replace終了");
		}
		
		
		a=0;b=0;
	}
	
	
return 0;
}

Measured memory_bytes: 584
#include<iostream>
#include<cstdio>
using namespace std;
const int N = 1e5+100;
const int mod = 1e9+7;
int n,m,x[N],y[N];
int main()
{
	cin>>n>>m;
	for (int i = 0; i < n; i++)
		scanf("%d",&x[i]);
	for (int i = 0; i < m; i++)
		scanf("%d",&y[i]);

	long long ansx = 0;
	for (int i = 0; i < n; i++)
	{
		int cnt = i - (n-1-i);
		long long temp = (1LL * cnt * x[i]) % mod;

		ansx = (ansx + temp) % mod;
	}

	long long ansy = 0;
	for (int i = 0 ;i < m; i++)
	{
		int cnt = i - (m-1-i);
		long long temp = (1LL * cnt * y[i]) % mod;

		ansy = (ansy + temp) % mod;
	}

	long long ans = ansx * ansy;
	ans = ans%mod;
	cout<<ans<<endl;
}

Measured memory_bytes: 4448
def main(x):
    a = False
    if 'A' in x:
        if 'B' in x:
            if len(x) == 3:
                a = True
    return a

if __name__ == "__main__":
    x = input()
    v = main(x)
    if v:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 2940
import java.util.Scanner;

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

        while(true)
        {
            String input = sc.next();
            String[] binput = input.split("");
            int iinput[] = new int[binput.length];
            int sum=0;

            if(input.equals("0")) break;

            int i;
            for(i=0; i<binput.length; i++)
            {
                iinput[i] = Integer.parseInt(binput[i]);
                sum += iinput[i];
            }

            System.out.println(sum);
        }
        sc.close();
    }
}



Measured memory_bytes: 27280
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long X,A,B;
    cin>>X;
    for(long long i=0;i<10000;i++){
    for(long long j=-65;j<10000;j++){
    A=i*i*i*i*i;
    B=j*j*j*j*j;
    if(A-B==X){
    cout<<i<<" "<<j<<endl;
    goto as;}}}
    as:
    cout<<endl;}


Measured memory_bytes: 3528
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;

ll answer = -1;
int n,m,q;
vector<int>a(55),b(55),c(55),d(55);
   
void dfs(vector<int>A){
    if(A.size() == n){
        ll tmpanswer = 0;
        REP(i,q){
            if(A[b[i]-1]-A[a[i]-1]==c[i]){
                tmpanswer += d[i];
            }
        }
        answer = max(answer,tmpanswer);
    }
    else{
        FOR(i,A[A.size()-1],m+1){
            A.push_back(i);
            dfs(A);
            A.pop_back();
        }
    }
}
int main(){
    vector<int>A;
    cin >> n >> m >> q;
    REP(i,q){
       cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    A.push_back(1);
    dfs(A);
    cout << answer << endl;
    
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm> 
using namespace std;


int main() {
	int a, b, s, cun = 0;
	string S;

	cin >> a >> b;
	cin >> S;
	if (S.size() == a + b + 1) {
		for (int i = 0; i < a + b + 1; i++) {
			if (i == a) {
				if (S[i] == '-') {
					cun++;
				}
			} else {
				s = S[i] - '0';
				if (0 <= s && s <= 9) {
					cun++;
				}
			}
		}
	}

	if (cun == a + b + 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 384
M=998244353
N,S=gets.split.map(&:to_i)
A=gets.split.map(&:to_i)

dp=[0]*(S+1)
dp[0]=1
A.each.with_index do |a,i|
  S.downto(0) do |s|
    dp[s]+=dp[s]
    dp[s]+=dp[s-a] if 0<=s-a
    dp[s]%=M
  end
end
p dp[S]


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

typedef long long LL;
#define int LL

const int MAXN = 2e5;

int n, m;
int a[MAXN | 1], b[MAXN | 1], ans[MAXN | 1];
int fset[MAXN | 1], size[MAXN | 1];

inline int read() {
	register int x = 0, v = 1;
	register char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') v = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * v;
}

int find(int x) {
	return fset[x] == x ? x : fset[x] = find(fset[x]);
}

int merge(int x, int y) {
	x = find(x);
	y = find(y);
	size[y] += size[x];
	fset[x] = y;
}

signed main() {
	n = read();
	m = read();
	for (int i = 1; i <= m; ++i) {
		a[i] = read();
		b[i] = read();
	}
	for (int i = 1; i <= n; ++i) fset[i] = i, size[i] = 1;
	int tot = n * (n - 1) / 2;
	for (int i = m; i >= 1; --i) {
		int foo1 = find(a[i]), foo2 = find(b[i]);
		ans[i] = tot;
		if (foo1 == foo2) continue;
		tot = tot - size[foo1] * size[foo2];
		merge(a[i], b[i]);
	}
	for (int i = 1; i <= m; ++i) printf("%lld\n", ans[i]);
	return 0;
}



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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rrep(i,a,b) for (int i = a; i >= b; i--)



int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int te=1;
	//cin>>te;
	while(te--){
        ll x;
        cin>>x;

        int te=360;
        while(te%x!=0){
                te += 360;
        }
        ll ans = te/x;
        cout<<ans<<endl;

	}
	return 0;
}


Measured memory_bytes: 3648
S = input()
A = S[:2]
B = S[2:]
if A[0] == "0":
    A = A[1]

if B[0] == "0":
    B = B[1]

A = int(A)
B = int(B)

ans = "NA"

if A > 0 and B > 0:
    if A < 13 and B < 13:
        ans = "AMBIGUOUS"
    elif A >= 13 and B <= 12:
        ans = "YYMM"
    elif A <= 12 and B >= 13:
        ans = "MMYY"
        
elif A == 0 and 1 <= B <= 12:
    ans = "YYMM"

elif 1<= A <= 12 and B == 0:
    ans = "MMYY"

print(ans)


Measured memory_bytes: 3064
a = gets.to_s.to_i
s = a.to_s.chars
n = s.size
head = s.first.to_i
tail = s.last.to_i

count_one = -> i,j,len {
  return 0 if i != j
  return 1 if len < n
  return 1 if tail >= j
  return 0
}

middle = -> {
  s[1..-2].join.to_i
}

count_just = -> i,j {
  return count_one[i,j,n] if n == 1
  return 0 if head < i
  return middle[] + 1 if head == i && tail >= j
  return middle[] if head == i && tail < j
  return 10 ** (n - 2)
}

count_less = -> i,j,len {
  return count_one[i,j,len] if len == 1
  return 10 ** (len - 2)
}

count = -> i,j {
  ans = 0
  1.upto(n-1) do |len|
    ans += count_less[i,j,len]
  end
  ans += count_just[i,j]
  ans
}

dp = Hash.new(0)

1.upto(9) do |i|
  1.upto(9) do |j|
    key = i * 10 + j
    dp[key] = count[i, j]
  end
end

ans = 0
1.upto(9) do |i|
  1.upto(9) do |j|
    ans += (dp[i*10+j] * dp[i+j*10])
  end
end

pp ans
      
        
        


Measured memory_bytes: 14592
#include <atcoder/all>
#include <bits/stdc++.h>

#define INF 1e9
using namespace std;
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    int N,M; cin >> N >> M;
    atcoder::dsu d(N);
    REP(_,M) {
        int a,b; cin >> a >> b;
        --a; --b;
        d.merge(a,b);
    }
    auto g = d.groups();
    cout << g.size()-1 << endl;
}

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

Measured memory_bytes: 9100
#include <stdio.h>          // printf(), scanf()

#define MAX_N 200000
#define min(a, b) ((a) < (b) ? a : b)
#define max(a, b) ((a) > (b) ? a : b)

int
main(int argc, char** argv)
{
	int r;
	int n, i;

	int maxv = -1000000000;
	int minv = 0;
	
	scanf("%d", &n);
	scanf("%d", &minv);
	for (i = 1; i < n; ++i)
	{
		scanf("%d", &r);
		maxv = max(maxv, r - minv);
		minv = min(minv, r);
	}

	printf("%d\n", maxv);
	return 0;
}

Measured memory_bytes: 596
N,W = map(int,input().split())
p=[[0]*(W+100) for _ in range(N+10)]
for i in range(N):
    w,v= map(int,input().split())
    for j in range(W+1):
        if j>=w:
            p[i+1][j] = max(p[i][j],p[i][j-w]+v)
        else:
            p[i+1][j]=p[i][j]
print(p[N][W])

Measured memory_bytes: 120984
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<sstream>

using namespace std;
using ll = long long;

const int INF = 1001001001;
const int MOD = 1000000007;


int main(){
    int n, k;
    cin >> n >> k;

    vector<int> d(k);
    vector<int> have(n);
    for (int i = 0;i < k;i++){
        cin >> d[i];
        for (int j = 0;j < d[i];j++){
            int tmp;cin >> tmp;
            have[tmp-1]++;
        }
    }
    int cnt = 0;
    for (int i = 0;i < n;i++){
        if (have[i] == 0){
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
 
int n,a,b,t,ans=1;
 
int main()
{
    scanf("%d%d",&n,&a);
    for(int i=1;i<n;i++)
    {
        scanf("%d",&b);
        if(t){if((t==1 && a>b) || (t==2 && a<b)){ans++;t=0;}}
        else t=a==b?0:(a>b)+1;
        a=b;
    }
    
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>#De
#define DIM 107
#define INF 1000000007
using namespace std;

long long n,k,a[DIM],used[100007];
int main()
{
    cin>>n>>k;
    for(int i = 1; i <= n; ++i)
        cin>>a[i];
    for(int i = 1; i <= k; ++i)
        for(int j = 1; j <= n; ++j)
            if(i>=a[j] && used[i-a[j]]==0) used[i] = 1;

    if(used[k]) cout<<"First"<<endl;
    else cout<<"Second"<<endl;

    return 0;
}


Measured memory_bytes: 1024
# ウニみたいなグラフを作って、頂点1以外の2つの頂点を結ぶごとに最短距離2のペアが1減る
# これを書けば行ける。　無理なときは無理。

N, K = map(int, input().split(" "))

max_edge_count = (N-1)*(N-2)//2
if max_edge_count < K:
    print(-1)
    exit()

edges = []

for i in range(2, N+1):
    edges.append((1, i))

count = max_edge_count - K
for i in range(2, N+1):
    for j in range(i+1, N+1):
        if count == 0:
            print(len(edges))
            for edge in edges:
                print(*edge)
            exit()
        edges.append((i, j))
        count -= 1

print(len(edges))
for edge in edges:
    print(*edge)

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

using namespace std;
typedef long long ll;

int main(){
	int N;
	cin >> N;
	vector<int> A;
  	for(int i = 0; i < N; i++){
    	int a;
      	cin >> a;
      	A.push_back(a);
    }
  	ll sum = 0;
  	for(int i = 1; i < N; i++){
      	int diff = A[i] - A[i-1];
    	if(diff < 0){
        	A[i] += (-diff);
          	sum += (-diff);
        }
    }
  	cout << sum << endl;
}

Measured memory_bytes: 4232
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#include <stack>
#include <queue>
#include <algorithm>
#include <vector>
#include <list>
using namespace std;

typedef pair<int,int> P;
typedef long long lint;

int n;
double th=M_PI*60/180;
struct point {double x,y; };
void get_input() {
    scanf("%d",&n);
}

/*
点(a,b)?原点逆??旋?x度的旋?公式是：
 -              -     - -
| cos(x) -sin(x) | * | a |
| sin(x)  cos(x) |   | b |
 -              -     - -
*/


void koch(int depth,point beg,point end) {
    if(depth==0) return;
    point s,t,u;
    s.x=(2*beg.x+end.x)/3;
    s.y=(2*beg.y+end.y)/3;
    t.x=(beg.x+2*end.x)/3;
    t.y=(beg.y+2*end.y)/3;
    u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
    u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;

    koch(depth-1,beg,s);
    printf("%.8f %.8f\n",s.x,s.y);
    koch(depth-1,s,u);
    printf("%.8f %.8f\n",u.x,u.y);
    koch(depth-1,u,t);
    printf("%.8f %.8f\n",t.x,t.y);
    koch(depth-1,t,end);

}

void solve() {
    point a,b;
    a.x=0; a.y=0;
    b.x=100; b.y=0;

    printf("%.8f %.8f\n",a.x,a.y);
    koch(n,a,b);
    printf("%.8f %.8f\n",b.x,b.y);
}

void display_output() {

}

int main() {
#ifdef debug
    freopen("in.txt","r",stdin);
#endif
    get_input();
    solve();
    display_output();
}

Measured memory_bytes: 2824
using System;

namespace ABC050C
{
    class Program
    {
        static readonly uint MOD = 1000000007;

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int[] chk = new int[(N + 1) / 2];

            chk[0] = ((N + 1) % 2) + 1;
            for (int i = 1; i < chk.Length; i++)
            {
                chk[i] = 2;
            }
            // END Initialize

            string[] bufs = Console.ReadLine().Split(' ');
            for (int i = 0; i < N; i++)
            {
                int num = int.Parse(bufs[i]);
                if (num % 2 == N % 2)
                {
                    Console.WriteLine(0);
                    return;
                }

                num /= 2;
                if (chk[num] <= 0)
                {
                    Console.WriteLine(0);
                    return;
                }

                chk[num]--;
            }
            // END check


            uint res = 1;
            for (int i = 0; i < N / 2; i++)
            {
                res = (res << 1) % MOD;
            }

            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 16608
use proconio::input;

fn calc(a: &[(i64, i64)], dx: i64, dy: i64) -> usize {
    let mut set = std::collections::BTreeSet::new();
    a.into_iter().for_each(|&p| { set.insert(p); });

    let mut ans = 0;

    while !set.is_empty() {
        let (x, y) = *set.iter().next().unwrap();
        set.remove(&(x, y));
        (1..).take_while(|&d| set.remove(&(x + d * dx, y + d * dy))).for_each(|_| {});
        (1..).take_while(|&d| set.remove(&(x + d * dx, y + d * dy))).for_each(|_| {});
        ans += 1;
    }

    ans
}

fn main() {
    input! {
        n: usize,
        a: [(i64, i64); n]
    }

    let mut ans: usize = 999;
 
    if n == 1 {
        ans = 1;
    }

    for i in 0..n {
        for j in i+1..n {
            let (x1, y1) = a[i];
            let (x2, y2) = a[j];
            ans = std::cmp::min(ans, calc(&a, x2 - x1, y2 - y1));
        }
    }

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


Measured memory_bytes: 2156
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void) {
	string s;
	cin >> s;
	if (s[0] == '7' || s[1] == '7' || s[2] == '7')
		cout << "Yes";
	else
		cout << "No";

	return 0;
}

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

int main()
{
	string s,t;
	cin >> s >> t;
	int n = s.size();int m = t.size();
	int ans = t.size();
	for(int i = 0;i<n-m+1;i++)
	{
		int cnt = 0;
		for(int j = 0;j<m;j++)
		{
			if(s[i+j]!=t[j])
			{
				cnt++;
			}
		}
		ans = min(cnt,ans);
	}
	cout<<ans<<endl;

}


Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  ll N,A[100007],B[100007];
  cin >> N;
  rep(i,N){
    cin >> A[i] >> B[i];
  }
  ll T=0;
  rrep(i,N){
    T+=(B[i]-((A[i]+T)%B[i]))%B[i];
  }
  cout << T << endl;
}

Measured memory_bytes: 1792
/*author: hyperion_1724
  date: 
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(int i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define fi first
#define se second
#define endl '\n'
#define trav(x,A) for(auto &x:A)
#define veci vector<int>
#define vecl vector<long long>
#define FORI(a,b,c) for(int a=b;a<c;a++)
#define FORD(a,b,c) for(int a=b;a>c;a--)
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

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

	READV(A);
	READV(B);
	READV(C);
	READV(D);
	ll lcm=(C*D)/__gcd(C,D);
	ll ans=(B/C)-((A-1)/C)+(B/D)-((A-1)/D)-(B/lcm)+((A-1)/lcm);
	cout<<B-A+1-ans<<endl;

	return 0;
}

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

void swap(int& a, int& b) {
	int tmp = a;
	a = b;
	b = tmp;
}

void calcGCD(int& gcd, const int a_, const int b_) {
	int a = a_;
	int b = b_;
	int r = a % b;
	if(r == 0) {
		gcd = b;
	} else {
		a = r;
		if(a < b) {
			// swap to set a >= b
			swap(a, b);
		}
		calcGCD(gcd, a, b);
	}
}

void calcLCM(int& lcm, const int gcd, const int a, const int b) {
	lcm = (int)((double)a * b / gcd);
}

int main(){
	int a, b;
	while(cin >> a >> b) {
		if(a < b) {
			swap(a, b);
		}
		int gcd;
		int lcm;
		calcGCD(gcd, a, b);
		calcLCM(lcm, gcd, a, b);
		cout << gcd << " " << lcm << endl;
	}
	return 0;
}

Measured memory_bytes: 3032
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int t = n%10;
	if( t==3 ) cout<<"bon";
	else if( t==0 || t==1 || t==6 || t==8 ) cout<<"pon";
	else cout<<"hon";
}



Measured memory_bytes: 3636
#include <stdio.h>
    int main(void){
      int a[] = {0, 0, 0};
      int b[] = {0, 0, 0};
      int count[] = {0, 0, 0, 0};
      int path[] = {0,0,0,0,0,0};
      int n = 0;
      
      for(int i = 0; i < 3; i++){
        
        scanf("%d %d\n", &a[i], &b[i]);
        path[n] = a[i];
        path[n+1] = b[i];
        n += 2; 
      }
     
      for(int j = 0; j < 6; j++){
        switch(path[j]){
        case 1:
          count[0]++;
          break;
        case 2:
          count[1]++;
          break;
        case 3:
          count[2]++;
          break;
        case 4:
          count[3]++;
          break;      
        }
      }
      
      if(count[0] == 1 && count[3] == 1 && count[1] == 2 && count[2] == 2){
        printf("YES\n");
      }else{
        printf("NO\n");
      }
     
      return 0;
     
    }

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	}
}

class Solver {
	int N;
	int cnt;
	int R;
	int G;

	public void init() {
		N = 0;
		cnt = 0;
		R = 0;
		G = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		R = Integer.parseInt(strArr[0]);
	}

	public boolean hasNext() {
		// return cnt < N;
		return cnt < 1;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
		G = Integer.parseInt(str);
	}

	public void solve() {
		int ans = (G - R) * 2 + R;
		System.out.println(ans);
	}
}


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

const int inf = 1012345678;

int main()
{
	vector<int> time(5);
	cin >> time[0] >> time[1] >> time[2] >> time[3] >> time[4];
	vector<int> next_time(5);
	int index = 0;
	int max_diff = 0;
	//次の注文ができる時刻を取得
	for (int i = 0; i < 5; i++)
	{
		if (time[i] % 10 == 0)
		{
			next_time[i] = time[i];
		}
		else
		{
			next_time[i] = time[i] - (time[i] % 10) + 10;
		}

		if ((next_time[i] - time[i]) > max_diff)
		{
			max_diff = next_time[i] - time[i];
			index = i;
		}

	}

	int best_time = 0;

	for (int i = 0; i < 5; i++)
	{
		if (index == i)
		{
			best_time += time[i];
		}
		else
		{
			best_time += next_time[i];
		}
	}

	cout << best_time << "\n";
	return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))
    sum_sunuke = 0
    sum_arai = sum(A)
    diffs = []
    for i in range(N - 1):
        sum_sunuke += A[i]
        sum_arai -= A[i]
        diffs.append(abs(sum_sunuke - sum_arai))
    print(min(diffs))


if __name__ == '__main__':
    main()


Measured memory_bytes: 101376
#include <iostream>
using namespace std;
int main (){
    long long int N;
    cin >> N;
    long long int dist;
    long long int min=__INT_MAX__;
    for (long long int i = 1; i*i <= N; i++){
        if(N%i==0){
            dist=i+N/i;
            if(dist<min) min=dist;
        }
    }
    dist-=2;
    cout << dist << "\n";

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl ("\n")

int main()
{
    int a, b;
    cin >> a >> b;
    long long x = 0ll, y = 0ll;
    for(int i = 0;i < a;i++)
    {
        y *= 10;
        y += b;
    }
    for(int i = 0;i < b;i++)
    {
        x *= 10;
        x += a;
    }
    cout << max(x, y);
    return 0;
}


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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){ a=max(a,b);}

VI eratos ( int n){
	vector<bool> prime(n+10);
	prime[2] = true; prime[0] = prime[1] = false;
	for(int i = 3; i <= n; i += 2) prime[i] = true, prime[i+1] = false;
	int limit = (int)sqrt((double)n) + 1;
	for(int i = 3; i <= limit; i += 2){
		if(!prime[i]) continue;
		for(int j = i * i, k = i * 2; j <= n; j += k) prime[j] = false;
	}
	VI v;
	rep(i, n+1) if(prime[i]) v.push_back(i);
	return v;
}
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	auto pr = eratos(55555);
	
	VI ans;
	for(auto x: pr) if(x%5==1) ans.push_back(x);
	//dbg(sz(ans));
	rep(i, n) cout << ans[i] <<" "; cout<<"\n";
	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int main(void)
{
  int n;
  cin >> n;
  vector<int> last(20,-1);
  int limit = -1;
  LL answer = 0;
  REP(i,n) {
    int x;
    cin >> x;
    REP(j, 20) {
      if((x >> j)&1) {
        limit = max(limit, last[j]);
        last[j] = i;
      }
    }
    answer += i-limit;
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 256