akhauriyash/Code-Regression huggingface dataset:
#ABC042_C
N, K = map(int, input().split())
D = list(map(int, input().split()))
while True:
    hantei = True
    for i in D:
        if str(i) in str(N):
            hantei = False
    if hantei==False:
        N+=1
    else:
        print(N)
        break

Measured memory_bytes: 9052
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

total=0
for i in range(N):
    if i<N-1:
        if A[i+1]==A[i]+1:
            total=total+B[A[i]-1]+C[A[i]-1]
        else:
            total+=B[A[i]-1]
    else:
        total+=B[A[i]-1]
print(total)

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

int main() {
  vector<char> c(6);
  for(int i=0;i<6;i++)
    cin>>c.at(i);
  if(c[0]==c[5] && c.at(1)==c.at(4) && c.at(2)==c.at(3))
    cout<<"YES";
  else cout<<"NO";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
const ll INF = LLONG_MAX;
using edge = std::vector<long long>;

bool warshall_floyd(
	long long V,
	long long E,
	std::vector<edge>& edges,
	std::vector<std::vector<long long>>& dist
) {
	for (long long i = 0; i < V; i++) dist[i][i] = 0;
	for (auto i : edges) dist[i[1]][i[2]] = i[0];
	for (long long k = 0; k < V; k++) {
		for (long long i = 0; i < V; i++) {
			if (dist[i][k] == LLONG_MAX) continue;
			for (long long j = 0; j < V; j++) {
				if (dist[k][j] == LLONG_MAX) continue;
				dist[i][j] = std::min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	return false;
}

int main() {
	ll n, m, r;
	cin >> n >> m >> r;
	vector<ll> v(r);
	for (ll i = 0; i < r; i++) {
		cin >> v[i];
		v[i]--;
	}
	vector<edge> edges(0);
	for (ll i = 0; i < m; i++) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		edges.push_back({c, a, b});
		edges.push_back({c, b, a});
	}
	m *= 2;
	vector<vector<ll>> dist(n, vector<ll>(n, INF));
	warshall_floyd(n, m, edges, dist);
	vector<ll> idx(r);
	for (ll i = 0; i < r; i++) idx[i] = i + 1;
	ll ans = INF;
	do {
		ll subans = 0;
		for (ll i = 0; i < r - 1; i++) {
			subans += dist[v[idx[i] - 1]][v[idx[i + 1] - 1]];
		}
		ans = min(ans, subans);
	} while (next_permutation(ALL(idx)));
	cout << ans << endl;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<vector<int>> sw(N+1);
  
  for (int i = 1; i <= M; i++) {
    int k;
    cin >> k;
    
    for (int j = 0; j < k; j++) {
      int s;
      cin >> s;
      sw[s].push_back(i);
    }
  }
  
  

  vector<int> p(M+1);
  for (int i = 1; i <= M; i++) {
    cin >> p[i];
  }
  

  
  int ans = 0;

  // N個のスイッチ bit 全探索
  for (int bit = 0; bit < (1 << N); bit++) {
    
    // 押された情報の初期化
    vector<int> num(M+1,0);
    
    
    // 押したスイッチごとにつながっている電球のスイッチ回数を+1
    for (int i = 0; i < N; i++) {
      
      if (bit & (1 << i)) {
        for (int j = 0; j < sw[i+1].size(); j++) {
          num[sw[i+1][j]]++;
        }
        
      }
    }

    bool cond = true;

    //　それぞれの電球が点灯するかのチェック
    for (int i = 1; i <= M; i++) {
      if (num[i] % 2 != p[i]) {
        cond = false;
        break;
      }
    }
    
    if (cond) ans++;
    
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3632
# import itertools
# import math


def solve(N, H):
    for i in range(N - 1):
        if H[i] < H[i+1]:
            H[i+1] -= 1
        elif H[i] > H[i+1]:
            return 'No'
    return 'Yes'


N = int(input())
# S = input()
# A, B = map(int, input().split())
H = list(map(int, input().split()))

# P = []
# S = []
# for i in range(N):
#     pp, ss  = map(int, input().split())
#     P.append(pp)
#     S.append(ss)

print(solve(N, H))


Measured memory_bytes: 14396
N,M,X=map(int,input().split())
CA=[list(map(int,input().split())) for i in range(N)]
ans=float("inf")
for i in range(2**N):
    ruikei=[0]*M
    onedan=0
    for j in range(N):
        if ((i>>j)&1):
            onedan+=CA[j][0]
            for k in range(1,M+1):
                ruikei[k-1]+=CA[j][k]
    #print(onedan)
    #print(ruikei)    
    kari=True    
    for j in ruikei:
        if j<X:
            kari=False
    if kari:
        ans=min(ans,onedan)
if ans==float("inf"):
    print(-1)
else:
    print(ans)
        


Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
bool cmp(long long a,long long b)
{return a>b;}
int main()
{
long n=0,i=0,ans=0;
cin>>n;
long long d[n+1];
for(i=0;i<n;i++)
{
cin>>d[i];
d[i]-=(i+1);
}
sort(d,d+n,cmp);
long long b=d[n/2];
for(i=0;i<n;i++)ans+=abs(d[i]-b);
cout<<ans;
return 0;
}

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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> f(m);
	for (int i = 0, k, a; i < n; i++) {
		cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> a;
			f[a - 1]++;
		}
	}
	int count = 0;
	for (int i = 0; i < m; i++)
		if (f[i] == n)
			count++;
	cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n; cin >> n;
	
	if(n == 1) cout << "Hello World" << endl;
	else {
		int a, b; cin >> a >> b;
		
		cout << a + b << endl;
	}
	
	
	return 0;
}


Measured memory_bytes: 256
//Vacant Seat

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define YN(flag) (flag?"Yes":"No")
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n;cin>>n;
    int right=0,left=n-1;
    int ra;
    cout<<right<<endl;
    string s;cin>>s;
    if(s=="Vacant")return 0;
    ra=(s=="Male"?0:1);
    cout<<left<<endl;
    cin>>s;
    if(s=="Vacant")return 0;
    while(true){
        int m=(right+left)/2;
        cout<<m<<endl;
        cin>>s;
        if(s=="Vacant")return 0;
        int ca=(s=="Male"?0:1);
        if((m-right)%2==0){
            if(ca==ra){
                right=m;
                ra=ca;
            }else{
                left=m;
            }
        }else{
            if(ca!=ra){
                right=m;
                ra=ca;
            }else{
                left=m;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3856
#include <bits/stdc++.h>
using namespace std;
int a[5];

int main() {
	for(int i = 1; i <= 3; i++) cin >> a[i];
	sort(a + 1, a + 4);
	int ans = a[3] * 10 + a[2] + a[1];
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
int main(){
    int N;
    cin >> N;
    rep(i,N){
        int ans = 0;
        for(int j=1;j < 100;j++){
            for(int k=j;k <100;k++){
                if(j*j + k*k + 1 + j*k + j + k > i+1) break;
                for(int l=k;l < 100;l++){
                    if(j*j + l*l + k*k + j*l + l*k + k*j > i +1) break;
                    if(j*j + l*l + k*k + j*l + l*k + k*j == i +1){
                        if(j == k && k == l){
                            ans++;
                        }else if(j == k || k == l || l == j){
                            ans += 3;
                        }else{
                            ans += 6;
                        }
                    }
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3632
import itertools
s = input()
cnt = 0
# 桁数
digits = len(s)
# 桁数 までのカウントをあらかじめいれておく
cntl = [0, 6, 42, 192, 732, 2538, 8334]
# 七五三 number
number = ["3", "5", "7"]
if digits < 3:
    print(0)
    exit()
for i in itertools.product(number, repeat=digits):
    if "3" in i and "5" in i and "7" in i:
        if int(''.join(i)) <= int(s):
            cnt += 1
print(cnt + cntl[digits - 3])


Measured memory_bytes: 3060
function Main(input) {
    input = input.split("\n");
  	var X = input[0].split(" ")[0]-0;
  	var Y = input[0].split(" ")[1]-0;
  	var p = input[1].split(" ").map(v=>v-0).sort((a,b)=>b-a).filter((v,i)=>i<X);
  	var q = input[2].split(" ").map(v=>v-0).sort((a,b)=>b-a).filter((v,i)=>i<Y);
  	var r = input[3].split(" ").map(v=>v-0).sort((a,b)=>b-a);
  	var ans = 0;
  	p.concat(q).concat(r).sort((a,b)=>b-a).forEach((v, i)=>{
  	    if(i<X+Y){
  	        ans += v;
  	    }
  	})
  	console.log(ans);

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 54604
N = int(input())

ans = 0
for i in range(1, N+1):
    if i % 2 == 0:
        continue

    counter = 0
    for j in range(1, i+1):
        if i % j == 0:
            counter += 1
    
    if counter == 8:
        ans += 1

print(ans)

Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static long n;

        static void Main(string[] args)
        {
            n = int.Parse(Console.ReadLine());
            int[] b = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int ans = b[0];
            int tmp = b[0];
            for (int i = 1; i < n - 1; i++) {
                ans += Math.Min(tmp, b[i]);
                tmp = b[i];
            }
            ans += tmp;
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13268
#include <stdio.h>

int main(){
    int mns,i,n,k;
    scanf("%d%d",&mns,&n);
    int amount=0;
    for(i=0;i<n;i++){
        scanf("%d",&k);
        amount+=k;
    }
    if(amount>=mns)
    printf("Yes\n");
    else
    {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 256
// D - People on a Line
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
int in(){int x;scanf("%d",&x);return x;}

#define TMAX 100000
vi R[TMAX+1], D[TMAX+1];
int dist[TMAX+1];

void dfs(int l, int d){
	if(dist[l] != INT_MAX) return;
	dist[l] = d;
	rp(c, 0, R[l].size()) dfs(R[l][c], d+D[l][c]);
}

bool solve(){
	int N=in(), M=in();
	if(!M) return true;

	int S = INT_MAX, E = 0;
	while(M--){
		int l=in(), r=in(), d=in();
		S = min(S, l), E = max(E, r);
		R[l].push_back(r), D[l].push_back( d);
		R[r].push_back(l), D[r].push_back(-d);
	}

	while(N) dist[N--] = INT_MAX;
	rp(l, S, E+1){
		dfs(l, 0);
		rp(c, 0, R[l].size()) if(D[l][c] != dist[R[l][c]]-dist[l]) return false;
	}
	return true;
}

int main(){
	puts(solve()?"Yes":"No");
}

Measured memory_bytes: 16384
import java.util.*;
public class Main {
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	// 整数の入力
	long n = sc.nextLong();
	long x = sc.nextLong();

	// 出力
	System.out.println(p(n,x));
    }

    private static long p(long n, long x){
	if(n == 0){
	    return 1;
	}

	long len_n1 = 4;
	for (long i = 1; i <= n-1; i++){
	    len_n1 *= 2;
	}
	len_n1 -= 3;

	if(x == 1){
	    return 0;
	}else if(x >= 2 && x <= 1 + len_n1){
	    return p(n -1, x -1);
	}else if(x == 2 + len_n1){
	    return p(n -1, len_n1) + 1;
	}else if(x >= 3 + len_n1 && x <= 2 + 2 * len_n1){
	    return p(n -1, len_n1) + 1 + p(n -1, x - len_n1 - 2);
	}else{
	    return p(n -1, len_n1) * 2 + 1;
	}
    }
}


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

using namespace std;

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

using ll = long long;
using pint = pair<int, int>;
using mint = map<int, int>;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

int main(){

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

    int m, k;
    cin >> m >> k;

    if(k >= powMod(2, m, LINF) or m == 1 and k == 1){
        ppp(-1);
        return 0;
    }
    if(m == 0 and k == 0){
        ppp("0 0");
        return 0;
    }
    if(m == 1 and k == 0){
        ppp("0 0 1 1");
        return 0;
    }

    vector<int> a(powMod(2LL, m, LINF));
    iota(a.begin(), a.end(), 0);

    for(auto x : a){
        if(x == k) continue;
        cout << x << sp;
    }
    cout << k << sp;

    reverse(a.begin(), a.end());
    for(auto x : a){
        if(x == k) continue;
        cout << x << sp;
    }
    cout << k << sp;
    cout << endl;


    return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise fixed(cout);cout<<setprecision(16);
using namespace std;

ostream& operator << (ostream &out, vector<int> &v) { for(auto a:v) out << a<<" "; out<<endl; }

int main()
{
  int n;
  cin >> n;
  int mx=0;
  int ans=0;
  int x;
  for(int i=0;i<n;i++){
    cin >> x;
    if(x>=mx){
      mx=x;
      ans++;
    }
  }
  cout <<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<algorithm>
#include<iomanip>
#include<typeinfo>
#include<complex>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(ll i = a;i < b; i++)
const long double PI = (acos(-1));

int main() {

	int n, ans;
	double t, a, mini = 100000;
	cin >> n >> t >> a;

	vector<double> h(n);
	rep(i, 0, n) {
		cin >> h[i];
		h[i] = t - h[i] * 0.006;
		h[i] = abs(a - h[i]);
		if (h[i] < mini) {
			mini = h[i];
			ans = i + 1;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
// B - Small and Large Integers
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int A,B,K; cin>>A>>B>>K;
	rp(i, A, min(B, A+K-1)+1) cout<<i<<endl;
	rp(i, max(B-K+1, A+K), B+1) cout<<i<<endl;
}

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

int main()
{
	string S; cin >> S;
	ll bitnum = S.length() - 1;
	ll ans = 0;
	rep(i,(1<<bitnum)) {
		//cout << "[" << i << "]" << endl;
		string tmp = "";
		int index = 0;
		rep(j,bitnum){
			tmp += S[index];
			if (i >> j & 0x01) {
				//cout << tmp << endl;
				ans += atoi(tmp.c_str());
				//cout << ans << endl;
				tmp = "";
				//cout << 1;
			}
			else {
				//cout << 0;
			}
			index++;
		}
		tmp += S[index];
		//cout << "tmp = " << tmp << endl;
		ans += atol(tmp.c_str());
		//cout << ans << endl;
		//cout << tmp << endl;
		//cout << endl;
	}
	cout << ans << endl;


}


Measured memory_bytes: 3632
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int hashs[200001]={0};
int main(){
    vector<int> arr;
    int n;
    scanf("%d",&n);
    for(int i=2;i<=n;i++){
        int x;
        scanf("%d",&x);
        hashs[x]++;
    }
    for(int i=1;i<=n;i++){
        printf("%d\n",hashs[i]);
    }
}


Measured memory_bytes: 2492
fn input_pair<T: std::str::FromStr + Copy> () -> (T, T) {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let arr: Vec<_> = s.trim().split_whitespace().flat_map(str::parse).collect();
    (arr[0], arr[1])
}

fn main() {
    let (a, b) = input_pair::<usize>();
    println!("{}", if a > 9 || b > 9 {
        format!("-1")
    } else {
        format!("{}", a * b)
    });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii  = pair<int,int>;
const int INF=1001001001;
const double PI = 3.141593;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define MOD 1000000007
#define EPS 10e-8
int gcd(int a,int b){return b?gcd(b,a%b):a;}    //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数

int main(){
    int n;
    cin >> n;
    if(n%2==0){
        cout << n / 2 - 1 << endl;
    }
    else{
        cout << n / 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
def input_int_list():
    return [int(thing) for thing in input().split(" ")]


A = [input_int_list() for i in range(3)]
N = int(input())
B_set = set([int(input()) for i in range(N)])
matrix = [[0,0,0] for _ in range(3) ]
for i in range(3):
    for j in range(3):
        if A[i][j] not in B_set:
            matrix[i][j] = A[i][j]
        else:
            matrix[i][j] = 0


def Yes():
    print("Yes")
    exit()


for i in matrix:
    if sum(i) == 0:
        Yes()
    else:
        pass
A=matrix
for i in range(3):
    if sum([A[j][i] for j in range(3)]) == 0:
        Yes()
if A[0][0]+A[1][1]+A[2][2]==0:
    Yes()

if A[0][2]+A[1][1]+A[2][0] == 0:
    Yes()

print("No")

Measured memory_bytes: 3188
import sys
readline = sys.stdin.buffer.readline
from math import factorial
n,m = map(int,readline().split())

def combinations_count(n,r):
    """組み合わせnCr"""
    return factorial(n) // (factorial(n-r)*factorial(r))
ans1 = 0
ans2 = 0
if n >= 2:
    ans1 = combinations_count(n,2)
if m >= 2:
    ans2 = combinations_count(m,2)

print(ans1+ans2)

Measured memory_bytes: 38384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))

#define INF 1000000000

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

int gcd(int a, int b)
{
	if (a < b)
		swap(&a, &b);

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

int lcm(int a, int b)
{
	return a*b/gcd(a, b);
}

void bubble_sort(int* p, int n)
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n - i - 1; j++)
		{
			if (p[j] > p[j + 1])
				swap(&p[j], &p[j + 1]);
		}
	}
}

int array_max(int* p, int n)
{
	int max = 0;
	for (int i = 0; i < n; i++)
	{
		if (p[i] > max)
			max = p[i];
	}
	return max;
}

int binary_search(int* p, int key, int n)
{
	int low = 0, high = n - 1;
	int middle;

	while (low <= high)
	{
		middle = (low + high) / 2;

		if (key == p[middle])
			return key;
		else if (key < p[middle])
			high = middle - 1;
		else if (key > p[middle])
			low = middle + 1;
	}
	return -1;
}

int main()
{
	int N, K;
	int X;
	//int a[100000];

	scanf("%d%d", &K,&X);

	if (K * 500 >= X)
		printf("Yes\n");
	else
		printf("No\n");

	/*
	for(int i = 0; i < N; i++)
		scanf("%d",&a[i]);
	*/

	//printf("%d", K);

}

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

int main() {
	char input[4] = {};
	cin >> input; 
	int n = 0;
	for (int i = 0; i < 3; i++) {
		if (input[i] == '1')n++;
	}

	cout << n << endl;

	return 0;
}

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

using namespace std;

int main(void){
    int N;
    cin>>N;
    long as[N];
    long apsum[2][N];
    for(int i = 0; i < N; i++){
        cin>>as[i];
        apsum[0][i]=0;
        apsum[1][i]=0;
    }
    apsum[0][0]=as[0];//頭から0までの部分列和
    for(int i = 1; i < N; i++){//1から最後までの部分列和
        apsum[1][1] += as[i];
    }
    long ans = abs(apsum[0][0]-apsum[1][1]);
    for(int i = 1; i < N-1; i++){
        apsum[0][i]=apsum[0][i-1]+as[i];
        apsum[1][i+1]=apsum[1][i]-as[i];
        long tmp = abs(apsum[0][i]-apsum[1][i+1]);
        ans = ans>tmp ? tmp : ans;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <algorithm>
#include <map>


using namespace std;


string S;
unsigned long long int K, L, cnt = 0, ans;

int chk(int x) {

	int aaa = 1;

	for (x; x < L - 1; x++) {
		if (S[x] == S[x + 1]) {
			aaa++;
		}
		else {
			break;
		}
	}
	aaa = aaa / 2;
	cnt += aaa;

	return x;
}


int main(void) {

	int tmp = 1;
	int tmp2 = 1;

	cin >> S;
	cin >> K;

	L = S.length();

	for (int i = 0; i < L - 1; i++) {
		if (S[i] == S[i + 1]) {
			i = chk(i);
		}
	}

	for (int i = L - 1; i > 0; i--) {
		if (S[i] == S[i - 1]) {
			tmp++;
		}
		else break;
	}
	for (int i = 1; i < L - 1; i++) {
		if (S[i] == S[i - 1]) {
			tmp2++;
		}
		else break;
	}


	
	if (tmp == L) {
		ans = L * K / 2;
	}
	else if (K == 1) {
		ans = cnt;
	}
	else if (S[0] == S[L - 1]) {
		if ((tmp + tmp2) % 2 == 0) {
			ans = cnt * K + K - 1;
		}
		else {
			ans = cnt * K;
		}
	}
	else {
		ans = cnt * K;
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  ll n,m;
  cin>>n>>m;
  ll k=n;
  ll j=m;
  if(abs(n-m)>=2) COUT(0);
  else{
    ll ans=1;
    while(n>0){
      ans*=n;
      ans%=MOD;
      n--;
    }
    while(m>0){
      ans*=m;
      ans%=MOD;
      m--;
    }
    if(k==j) {
      ans*=2;
      ans%=MOD;
    }
    COUT(ans);
  }
}


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

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	vector<vector<int> > edges(n);
	int k;
	cin >> k;
	for(int i = 0; i < n-1; i++){
		int a, b;
		cin >> a >> b;
		a--; b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	vector<vector<int> > dist(n, vector<int>(n, -1));
	for(int i = 0; i < n; i++){
		vector<pair<int,int> > bfs;
		int s = 0;
		bfs.push_back({i, 0});
		dist[i][i] = 0;
		while(s < (int)bfs.size()){
			int v = bfs[s].first;
			int d = bfs[s].second;
			s++;
			for(int w : edges[v]){
				if(dist[i][w] == -1){
					dist[i][w] = d+1;
					bfs.push_back({w, d+1});
				}
			}
		}
	}
	vector<pair<int,int> > cand;
	int dd = 0;
	if(k & 1){
		for(int i = 0; i < n; i++){
			for(int j : edges[i]){
				cand.push_back({i, j});
			}
		}
	} else {
		for(int i = 0; i < n; i++){
			cand.push_back({i, i});
		}
	}
	dd = k / 2;
	int best = 0;
	for(pair<int,int> a : cand){
		int keep = 0;
		for(int i = 0; i < n; i++){
			if(min(dist[a.first][i], dist[a.second][i]) <= dd){
				keep++;
			}
		}
		best = max(best, keep);
	}

	cout << n - best << '\n';
}

Measured memory_bytes: 16128
///-----Bismillahir Rahmanir Rahim-----///

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

///---FAST I/O---///
#define Boost() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

///---DATA TYPE---///
typedef long long ll;
typedef long long int lli;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

///---LOOP---///
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)

///---I/O---///
#define sf scanf
#define pf printf

///---OTHERS---///
#define pb push_back
#define all(c)		c.begin(),c.end()
#define MK make_pair
#define F first
#define S second
#define endl '\n'


///---INITIALIZATION---//
#define mem(a,b) memset(a, b, sizeof(a) )

///---CALCULATE---///
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

///---BIT OPERATION---///
inline bool checkBit(ll n, int i)
{
    return n&(1LL<<i);
}
inline ll setBit(ll n, int i)
{
    return n|(1LL<<i);;
}
inline ll resetBit(ll n, int i)
{
    return n&(~(1LL<<i));
}

///------String/Char Related Functions-----///
string makeintString(int x)
{
    stringstream ss;
    ss << x;
    string str = ss.str();
    ///cout<<str<<endl;
    return str;
}
string makellString(ll x)
{
    stringstream ss;
    ss << x;
    string str = ss.str();
    ///cout<<str<<endl;
    return str;
}
char cpp(char c)
{
    return static_cast<char>(c + 1);
}

///------------Sorting STL----------///
struct func
{
	//this is a sample overloading function for sorting stl
	bool operator()(pii const &a, pii const &b)
	{
		if(a.F==b.F)
			return (a.S<b.S);
		return (a.F<b.F);
	}
};

///---CONSTANT---///
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

int main()
{
    Boost();

    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        cout<<n*(n+1)/2<<endl;
    }
    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(void){
    int i=0;
  	long int H;
  	long int l=0;
  
	cin >> H;
  	cout << (long)(pow(2,floor(log2(H))+1)-1);
      
  	return 0;
}

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

#define ll long long

int main(void) {
  ll H, N;
  cin >> H >> N;

  ll res = 0;
  for (ll vi = 0; vi < N; vi++) {
    ll tmp;
    cin >> tmp;
    res += tmp;
  }

  if (H - res <= 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
/*input
1
1

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int a, b;
  cin >> a >> b;
  cout << (a > b ? "safe" : "unsafe") << endl;  

  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<ll, ll> mpii;
typedef unordered_map<ll, ll> umpii;

#define pb(v) push_back(v)
#define all(v) v.begin(), v.end()
#define upb(v, key) (upper_bound(all(v), key) - v.begin())
#define lob(v, key) (lower_bound(all(v), key) - v.begin())

ll inf = 1e9;
ll INF = inf * 1ll * inf;
ll mod = 1e9 + 7;
double eps = 1e-9;
const ld pi = ld(3.1415926535897932384626433832795);
ll dr[] = {-1, 0, 0, 1};
ll dc[] = {0, 1, -1, 0};

template <class TH>
void _dbg(const char *sdbg, TH h) { cerr << sdbg << '=' << h << endl; }
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a)
{
  while (*sdbg != ',')
    cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V)
{
  os << "[";
  for (auto vv : V)
    os << vv << ",";
  return os << "]";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P)
{
  return os << "(" << P.st << "," << P.nd << ")";
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)

/*...................................................*/

main()
{
  int n, i;
  cin >> n;
  vector<int> a(n);
  for(i = 0; i < n; i++)
  cin >> a[i];
  vector<int> dp(n, inf * 2);
  dp[0] = 0;
  int k = 2;
  for(i = 1; i < n; i++)
  for(int j = 1; j <= k && i >= j; j++)
  dp[i] = min(dp[i - j] + abs(a[i] - a[i - j]), dp[i]);
  cout << dp[n - 1];
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a,long long int b)
{
    while(a % b != 0)
    {
        long long int r = a % b;
        a = b;
        b = r;
    }
    return b;
}
long long int lcm(long long int a,long long int b)
{
    return a * (b /gcd(a,b));
}
int main()
{
    int n;
    cin >> n;
    long long int t,ans;
    cin >> t;
    ans = t;
    for(int i = 1;i < n;i++)
    {
        long long int T;
        cin >> T;
        ans = lcm(ans,T);
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <map>
#include <cstdio>
#include <vector>
#include <cstring>
#define pii pair<int,int>
#define s1 first
#define s2 second
#define N 200001
using namespace std;struct edge{int v,next;edge(){}edge(int _v,int _next){v=_v;next=_next;}}e[N<<1];int head[N],sz;
void init(){memset(head,-1,sizeof(head));sz=0;}void insert(int u,int v){e[++sz]=edge(v,head[u]);head[u]=sz;}
map<int,int> dp[N];vector<int> cc[N];int siz[N],n,c[N];long long ans[N];
void dfs(int u,int f)
{
	for(int i=head[u];~i;i=e[i].next)
	{
		if(e[i].v==f)continue;dfs(e[i].v,u);siz[u]+=siz[e[i].v];int tmp=siz[e[i].v];
		if(dp[e[i].v].count(c[u]))tmp-=dp[e[i].v][c[u]];cc[c[u]].push_back(tmp);
		if(dp[u].size()<dp[e[i].v].size())swap(dp[u],dp[e[i].v]);
		for(map<int,int>::iterator it=dp[e[i].v].begin();it!=dp[e[i].v].end();++it)dp[u][it->s1]+=it->s2;
	}dp[u][c[u]]=++siz[u];
}
int main()
{
	init();scanf("%d",&n);for(int i=1;i<=n;++i)scanf("%d",c+i);for(int i=1,u,v;i<n;++i)scanf("%d%d",&u,&v),insert(u,v),insert(v,u);
	dfs(1,1);for(int i=1;i<=n;++i)ans[i]=1ll*n*(n+1)/2;for(int i=1;i<=n;++i)cc[i].push_back(n-dp[1][i]);
	for(int i=1;i<=n;++i)for(int j=0;j<cc[i].size();++j)ans[i]-=1ll*cc[i][j]*(cc[i][j]+1)/2;for(int i=1;i<=n;++i)printf("%lld\n",ans[i]);putchar(10);return 0;
}

Measured memory_bytes: 73424
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <string>
#include <stack> 
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1e9;
#define put(n) cout<<(n)<<endl
#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()
#define pb(n) push_back(n)


int main(){
    deque<char> kakko;
    int N;
    string S;
    cin >> N;
    cin >> S;
    rep(i,N) kakko.push_back(S[i]);

    int cnt = 0; 
    rep(i,N){
        if(S[i] == '(') ++cnt;
        else {
            if(cnt > 0) --cnt;
            else kakko.push_front('(');
        }
    }

    rep(i,cnt) kakko.push_back(')');
    rep(i, kakko.size()) cout << kakko[i];
    cout << endl;
}


Measured memory_bytes: 256
from bisect import bisect_left

INF = 10 ** 11

a, b, q = map(int, input().split())
s = [-INF] + [int(input()) for _ in range(a)] + [INF]
t = [-INF] + [int(input()) for _ in range(b)] + [INF]
x = [int(input()) for _ in range(q)]

for e in x:
    si = bisect_left(s, e)
    ti = bisect_left(t, e)
    sl, sr = s[si-1], s[si]
    tl, tr = t[ti-1], t[ti]

    ans = INF
    ans = min(ans, e - min(sl, tl))
    ans = min(ans, max(sr, tr) - e)
    ans = min(ans, e - sl + tr - sl)
    ans = min(ans, e - tl + sr - tl)
    ans = min(ans, sr - e + sr - tl)
    ans = min(ans, tr - e + tr - sl)

    print(ans)


Measured memory_bytes: 16188
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl

using namespace std;

template<typename S,typename T>auto&operator<<(auto&o,pair<S,T>p){return o<<"{"<<p.fi<<","<<p.se<<"}";}
template<typename T>auto&operator<<(auto&o,set<T>s){for(auto&e:s)o<<e<<" ";return o;}
template<typename S,typename T,typename U>
auto&operator<<(auto&o,priority_queue<S,T,U>q){while(!q.empty())o<<q.top()<<" ",q.pop();return o;}
template<typename K,typename T>auto&operator<<(auto&o,map<K,T>&m){for(auto&e:m)o<<e<<" ";return o;}
template<typename T>auto&operator<<(auto&o,vector<T>v){for(auto&e:v)o<<e<<" ";return o;}
void ashow(){cout<<endl;}template<typename T,typename...A>void ashow(T t,A...a){cout<<t<<" ";ashow(a...);}
template<typename S,typename T,typename U>
struct TRI{S fi;T se;U th;TRI(){}TRI(S f,T s,U t):fi(f),se(s),th(t){}};
template<typename S,typename T,typename U>
auto& operator<<(auto& o,TRI<S,T,U>& t){return o<<"{"<<t.fi<<","<<t.se<<","<<t.th<<"}";}

typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef TRI<int, int, int> tri;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<string> vs;

const int MAX_N = 200005;

ll x[MAX_N], y[MAX_N];
ll val[MAX_N];
ll L, n;

ll calc(ll* d)
{
    int k = 0, l = n-1;
    int nw = L;
    ll init = 0;
    int left = 1;
    while(k <= l){
        if(left){
            init += d[k++] + (L-nw);
            nw = d[k-1];
        }else{
            init += nw + (L-d[l--]);
            nw = d[l+1];
        }
        left ^= 1;
    }
    val[0] = init;
    srep(i,1,n){
        // int k = (n-1+i)/2, l = k+1;
        val[i] = val[i-1] - d[i-1] + (d[(n+i-1)/2] - d[i-1]) - (L-d[(n+i)/2]);
    }
    // sar(val, n);
    return *max_element(val, val+n);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> L >> n;
    rep(i,n){
        cin >> x[i];
    }
    rep(i,n){
        y[i] = L-x[n-1-i];
    }
    // show(calc(y));
    cout << max(calc(x), calc(y)) << "\n";
    return 0;
}


Measured memory_bytes: 4992
n=int(input())
s=input()
ans=0
for i in range(1000):
	i=str(i)
	i=(3-len(i))*"0"+i
	r=0
	for j in range(n):
		if s[j]==i[r]:
			r+=1
		if r==3:
			break
	if r==3:
		ans+=1
print(ans)

Measured memory_bytes: 41068
#include <algorithm>
#include <cstdint>
#include <climits>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int64_t> a(n);
  int64_t sum = 0;
  int64_t ma = INT_MAX;
  int x = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += abs(a[i]);
    ma = min(ma, abs(a[i]));
    if (a[i] < 0)
      ++x;
  }
  if (x % 2 == 0) {
    cout << sum << endl;
  } else {
    cout << sum - 2 * ma << endl;
  }

  return 0;
}


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

#define ll long long
const ll MAX_N = 100001;
ll activities[MAX_N][4];
ll happiness[MAX_N][4];

void enableFastIO(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

void solve(){
	ll n;
  	cin>>n;
  	for(ll i = 1 ; i <= n ; i++)
      for(ll j = 1 ; j <= 3 ; j++)
        	cin>>activities[i][j];
  	happiness[1][1] = activities[1][1];
  	happiness[1][2] = activities[1][2];
  	happiness[1][3] = activities[1][3];
  	for(ll i = 2 ; i <= n ; i++){
      happiness[i][1] = activities[i][1] + max(happiness[i-1][2],happiness[i-1][3]);
      happiness[i][2] = activities[i][2] + max(happiness[i-1][3],happiness[i-1][1]);
      happiness[i][3] = activities[i][3] + max(happiness[i-1][1],happiness[i-1][2]);                                              
    }
  	cout<<max(max(happiness[n][1],happiness[n][2]),happiness[n][3]);
}

int main(){
    enableFastIO();
    ll t = 1;
    //cin>>t;
  	while(t--)
  	    solve();
  	return 0;
}


Measured memory_bytes: 6528
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(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

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    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()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def solve():
    n, m, k = MI()
    uf = UnionFind(n)

    friends = [0] * n
    for i in range(m):
        a, b = MI1()
        uf.union(a, b)
        friends[a] += 1
        friends[b] += 1
    # print(uf.__str__())
    # print(friends)

    blocks = [0] * n
    for i in range(k):
        c, d = MI1()
        if uf.same(c, d):
            blocks[c] += 1
            blocks[d] += 1

    # print(blocks)

    ans = [0] * n

    for i in range(n):
        ans[i] = uf.size(i) - 1 - blocks[i] - friends[i]
        # print(ans)

    print(' '.join(list(map(str, ans))))

if __name__ == '__main__':
    solve()


Measured memory_bytes: 19612
#include <bits/stdc++.h>
using namespace std;
int n, m, id;
vector<int> v(0);
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= sqrt(m); i++)
    {
        if (m % i == 0)
        {
            v.push_back(i);
            v.push_back(m / i);
        }
    }
    sort(v.begin(), v.end());
    id = upper_bound(v.begin(), v.end(), m / n) - v.begin();
    cout << v[id - 1] << endl;
    return 0;
}

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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll a, b, c;
string s;

int main() {
	cin>>a>>b;
	if(a>=b*2-1){
		p("YES");
	}else{
		p("NO");
	}
	return 0;
}


Measured memory_bytes: 764
import heapq

dic = {}
n, m = map(int, input().split())
for _ in range(n):
  a, b = map(int, input().split())
  if dic.get(a) is not None:
    dic[a].append(-b)
  else:
    dic[a] = [-b,]

ans = 0
bite = []
for i in range(1, m+1):
  if dic.get(i) is not None:
    #bite = bite + dic[i]
    for val in dic[i]:
      heapq.heappush(bite, val)
  if len(bite) > 0:
    #heapq.heapify(bite)
    ans += heapq.heappop(bite)
print(ans*-1)

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

class Solve {
private:
	int N;
	std::vector<std::string> str;
	std::array<int, 26> charMap;
	std::vector<bool> isFront{};
	std::vector<int64_t> num, weight;
	std::array<bool, 10> used{};

	int rc(int index, int64_t sum)
	{
		if (index == (int)num.size())
			return sum == 0;
		int count{};
		for (int i{}; i < 10; i++)
		{
			if (used[i]) continue;
			if (i == 0 && isFront[index]) continue;
			used[i] = true;
			num[index] = i;
			count += rc(index + 1, sum + i * weight[index]);
			num[index] = -1;
			used[i] = false;
		}
		return count;
	}

public:
	bool is_last_query{};
	Solve()
	{
		scanf("%d", &N);
		if (N == 0)
		{
			is_last_query = true;
			return;
		}
		for (auto& e: charMap) e = -1;
		str.resize(N);
		for (auto& e: str)
		{
			std::cin >> e;
			for (auto& f: e)
			{
				if (charMap[f - 'A'] < 0)
				{
					charMap[f - 'A'] = num.size();
					num.push_back(-1);
					weight.push_back(0);
				}
			}
		}
		for (int i{}; i < (int)str.size(); i++)
		{
			int64_t digit{1};
			for (int j{}; j < (int)str[i].size() - 1; j++)
				digit *= 10;
			for (int j{}; j < (int)str[i].size(); j++)
			{
				if (i + 1 != (int)str.size())
					weight[charMap[str[i][j] - 'A']] += digit;
				else
					weight[charMap[str[i][j] - 'A']] -= digit;
				digit /= 10;
			}
		}
		isFront.resize(num.size());
		for (auto& e: str)
			if (e.size() > 1)
				isFront[charMap[e.front() - 'A']] = true;
		printf("%d\n", rc(0, 0));
	}
};

int main()
{
	while (!Solve().is_last_query);

	return 0;
}


Measured memory_bytes: 3160
#include <stdio.h>
#define dr 2019

int main(){
  int i,j=0,k=1,c[2020]={};
  char s[200005];
  long m=0;
  scanf("%s",&s);
  for(i=0;s[i]!=0;i++);
  for(i--;i>=0;i--){
    j+=k*(s[i]-'0');
    j%=dr;
    c[j]++;
    k*=10;
    k%=dr;
  }
  c[0]++;
  for(i=0;i<2019;i++){
    m+=(long)(c[i]-1)*c[i]>>1;
  }
  printf("%ld",m);
  return(0);
}

Measured memory_bytes: 1880
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;

int main(){

	int N, K;
	string S;

	cin >> N >> K;
	cin >> S;

	for(int i = 0; i < N ; i++){
		if( i == K-1) {
			char a = S[i] - 'A' + 'a';
			cout << a;
		} else {
			cout << S[i];
		}
	}
	cout << endl;

	return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n;
    cin >> n;
    long long v[n][3], dp[n][3];
    memset(dp, 0, sizeof dp);
    for(int i=0; i<n; i++) {
        cin >> v[i][0] >> v[i][1] >> v[i][2];
    }
    dp[0][0] = v[0][0];
    dp[0][1] = v[0][1];
    dp[0][2] = v[0][2];
    long long ans = max(dp[0][0], max(dp[0][1], dp[0][2]));
    for(int i=1; i<n; i++) {
        for(int j=0; j<3; j++) {
            for(int k=0; k<3; k++) {
                if(j!=k)
                    dp[i][j] = max(dp[i][j], v[i][j]+dp[i-1][k]);
            }
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans << '\n';
    return 0;
}

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

int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
vector<P>list(n);
rep(i,n)
{int x,l;
cin >> x ;
cin >> l;
P p;
  //firstに、アームを一番右側に伸ばしたときの数字
  p.first=x+l;
  //secondに、アームを一番左側に伸ばした時の数字(かぶってはいけないので)
  p.second=x-l;
  list.at(i)=p;
}
sort(list.begin(),list.end());

int nowx=-1e9;
int ans=0;
rep(i,n)
{P p=list.at(i);
  if(nowx<=p.second)
  {ans++; nowx=p.first;}
}

cout << ans << endl;



}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

Measured memory_bytes: 1024
n = int(input())
nodes = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    nodes[a].append(b)
    nodes[b].append(a)
# print(nodes)

c = list(map(int, input().split()))
c.sort(reverse=True)
# print(c)

count = 0
answer = [0 for _ in range(n)]
for i in range(n):
  end = True
  for j in range(n):
    if len(nodes[j]) == 1:
      end = False
      nodes[nodes[j][0]].remove(j)
      nodes[j].pop()
      answer[j] = c.pop()
      count += answer[j]
  if end:
    break
print(sum(answer))

answer[answer.index(0)] = c.pop()
print(' '.join(map(str, answer)))


Measured memory_bytes: 48088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  int a, b;
  cin >> a >> b;
  cout << max({a + b, a - b, a * b}) << endl;
}

Measured memory_bytes: 256