akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int a,b;
string s;
int main(void){
    cin>>a>>b>>s;
    for(int i=0;i<a+b+1;i++){
        if(i==a){
            if(s[i]!='-'){
                cout<<"No"<<endl;
                return 0;
            }
        }else{
            if(s[i]=='-'){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define MOD 1e9+7;
using namespace std;
using ll = long long;

int main() {
	int n;
	cin >> n;
	int a, eve = 0, add = 0;
	rep(i,n) {
		cin >> a;
		if (a % 2 == 0) eve++;
		else add++;
		if (add >= 2) {
			add -= 2;
			eve++;
		}
		while (eve >= 2) eve--;
	}
	if (add == 0 && eve == 1) cout << "YES";
	else cout << "NO";
	return 0;
}


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

int main() {
	int n, m;							//調査時間n、トンネル内の台数mを定義
	cin >> n >> m;

	int x = m;							//トンネル内の最大台数xを定義
	int y = 0;							//トンネル内の0以下台数yを定義

	for (int i = 0; i < n; i++) {
		int in, out;					//入口in、出口outを定義
		cin >> in >> out;
		m = m + in - out;				//[トンネル内の台数]＝[トンネル内の台数]＋[入って来た台数]ー[出て行く台数]
		x = max(x, m);
		y = min(y, m);
	}

	if (y < 0) cout << 0 << endl;
	else cout << x << endl;

	return 0;
}



Measured memory_bytes: 3068
//D
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>

using namespace std;

#define MAX 300002

int n;

vector<long long int> v;

long long int M[MAX];
long long int MM[MAX];

priority_queue<long long int, vector<long long int>, greater<long long int> > q;
priority_queue<long long int> qq;

int main(){
	cin >> n;
	for (int i = 0; i < 3 * n; i++){
		int a;
		scanf("%d", &a);
		v.push_back(a);
	}
	memset(M, -1, sizeof(M));
	memset(MM, -1, sizeof(MM));
	int cnt = 0;
	long long int cur = 0;
	for (int i = 0; i < v.size(); i++){
		cnt++;
		cur += v[i];
		if (cnt == n)M[i] = cur;
		if (cnt <= n){
			q.push(v[i]);
			continue;
		}
		if (q.top() < v[i]){
			cur -= q.top();
			q.pop();
			q.push(v[i]);
		}
		else{
			cur -= v[i];
		}
		M[i] = cur;
	}
	cnt = 0;
	cur = 0;
	for (int i = v.size() - 1; i >= 0; i--){
		cnt++;
		cur += v[i];
		if (cnt == n)MM[i] = cur;
		if (cnt <= n){
			qq.push(v[i]);
			continue;
		}
		if (qq.top() > v[i]){
			cur -= qq.top();
			qq.pop();
			qq.push(v[i]);
		}
		else{
			cur -= v[i];
		}
		MM[i] = cur;
	}
	long long int ans = LLONG_MIN;
	for (int i = 0; i + 1 < v.size(); i++){
		if (M[i] != -1 && MM[i + 1] != -1){
			ans = max(ans, M[i] - MM[i + 1]);
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 11628
#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
long long int INF = 3e18;
double Pi = 3.1415926535897932384626;
 
vector<ll> G[550010];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
 
 
ll mod = 998244353;
 
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 

ll fact[800005],rfact[800005];
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[800000] = rui(fact[800000],mod - 2);
    for(ll i=800000; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}

 
ll n,m,num,sum,a,b,c,d,e,g,h,w,i,j,q,r,l;
ll k,ans;
ll x[500005],y[500005],z[500005];

char s[500005];

int main(){
    cin >> n;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i * j == n){
                a ++;
            } 
        }
    }
    Yes(a >= 1);
    return 0;
}











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

void solve(long long N, std::vector<std::string> S)
{
    set<string> merchandise;
    for (long long i = 0; i < N; i++)
    {
        merchandise.insert(S[i]);
    }

    cout << merchandise.size() << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<std::string> S(N);
    for (int i = 0; i < N; i++)
    {
        std::cin >> S[i];
    }
    solve(N, std::move(S));
    return 0;
}


Measured memory_bytes: 25168
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
int f(int i,int j,vector<int> D){
  if(i==0) return D[j];
  return D[j]-D[i-1];
}
int solve(vector<int>& h,vector<int>& w){
  int n = h.size();
  int m = w.size();
  map<int,int> tbl;
  vector<int> H(n),W(m);
  H[0] = h[0];
  W[0] = w[0];
  for(int i=1;i<n;++i) H[i]=H[i-1]+h[i];
  for(int i=1;i<m;++i) W[i]=W[i-1]+w[i];
  for(int i=0;i<n;++i)
    for(int j=i;j<n;++j)
      tbl[f(i,j,H)]++;

  int ans=0;
  for(int i=0;i<m;++i)
    for(int j=i;j<m;++j)
      ans+=tbl[f(i,j,W)];

  return ans;
}
int main(){
  int n,m;
  while(cin>>n>>m,n||m){
    vector<int> h(n),w(m);
    for(int i=0;i<n;++i) cin >> h[i];
    for(int i=0;i<m;++i) cin >> w[i];
    cout<<solve(h,w)<<endl;
  }
  return 0;
}

Measured memory_bytes: 19080
N, M = map(int, input().split())

H = list(map(int, input().split()))

road = [[] for _ in range(N)]

for _ in range(M):
    a, b = map(int, input().split())
    road[a-1].append(H[b-1])
    road[b-1].append(H[a-1])

ans = 0
for i in range(N):
    if not road[i]:
        ans += 1
    elif H[i] > max(road[i]):
        ans += 1

print(ans)

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

int n;
int x[25], y[25], r[25], c[25];
vector<int> onaji[4];

bool ishogan(int i, int j){ // iがjの上か
  return i < j && (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]) < (r[i]+r[j])*(r[i]+r[j]);
}

unordered_map<bitset<24>, int > po;

bool cantake(bitset<24> jotai, int num){
  bool tmp = true;
  for(int i=0;i<n;i++)if(jotai[i] && ishogan(i, num))tmp=false;
  return tmp && jotai[num];
}

int dfs(bitset<24> jotai){
  int ans = 0;
  for(int iro=0;iro<4;iro++){
    for(int i=0;i<onaji[iro].size();i++)for(int j=i+1;j<onaji[iro].size();j++){
      if(cantake(jotai, onaji[iro][i]) && cantake(jotai, onaji[iro][j])){
        jotai.reset(onaji[iro][i]);
        jotai.reset(onaji[iro][j]);
        if(po.find(jotai) != po.end()){
          ans = max(ans, 2+po[jotai]);
        }
        else ans = max(ans, 2+dfs(jotai));
        jotai.set(onaji[iro][i]);
        jotai.set(onaji[iro][j]);
      }
    }
  }
  po[jotai] = ans;
  return ans;
}

int main(){
  while(1){
    scanf("%d", &n);
    if(n==0)break;
    for(int i=0;i<n;i++){
      scanf("%d%d%d%d", &x[i], &y[i], &r[i], &c[i]);
      c[i]--;
    }
    for(int i=0;i<4;i++)onaji[i] = vector<int>();
    po = unordered_map<bitset<24>, int > ();

    for(int i=0;i<n;i++){
      onaji[c[i]].push_back(i);
    }
bitset<24> tmp;
for(int i=0;i<24;i++)tmp.set(i);
printf("%d\n", dfs(tmp));

  }
  return 0;
}



Measured memory_bytes: 43944
import java.util.*;

public class Main{
	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int K = sc.nextInt();

		int result = Math.min(A, K) - Math.max(0, (K-(A + B)));
		
		System.out.println(result);
		sc.close();
	}
}

Measured memory_bytes: 35716
N, L = map(int, input().split())

x = [L+i-1 for i in range(1, N+1)]
x_abs = [abs(L+i-1) for i in range(1, N+1)]
min_index = x_abs.index(min(x_abs))

x.remove(x[min_index])

print(sum(x))


Measured memory_bytes: 2940
from collections import Counter

N, M = map(int, input().split())
A = list(map(int, input().split()))
cum = [0]*(N+1)
cum[0] = 0
for i in range(1, N+1):
    cum[i] = cum[i-1] + A[i-1]

cum = [cum[i]%M for i in range(N+1)]
cnt = Counter(cum)
ans = 0
for k, v in cnt.items():
    ans += v*(v-1)//2
print(ans)

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

using namespace std;

const int N = 100005;

int a[N], deg[N], q[N], d[N];

int main() {
    int n, k;
    scanf("%d%d", &n, &k);

    for (int i = 1; i <= n; i++) {
        scanf("%d", a+i);
        if (i > 1 && a[i] != i) deg[a[i]]++;
    }

    int ans = n-1;

    if (a[1] != 1) ans++;

    int res = 0;

    if (a[1] != 1) res++;

    int head = 0, tail = -1;

    for (int i = 2; i <= n; i++) if (deg[i] == 0) q[++tail] = i;

    while (head <= tail) {
        int u = q[head];
        head++;

        if (d[u] == k-1 && a[u] != 1) {
            res++;
        }

        if (a[u] != 1) {
            deg[a[u]]--;
            if (d[u] < k-1) d[a[u]] = max(d[a[u]], d[u]+1);

            if (deg[a[u]] == 0) q[++tail] = a[u];
        }
    }

    ans = min(ans, res);

    printf("%d", ans);

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;

const int M = 100002;
long long fact[M+1];
long long invfact[M+1];

int N;
pair<int,int> f() {
	vector<int> a(N+1);
	for (int i = 1; i <= N+1; ++ i) {
		int x;
		cin >> x;
		if (a[x]) return {a[x], i};
		a[x] = i;
	}
	throw 1;
}
long long comb(int n, int r) {
	return fact[n] * invfact[r] % mod * invfact[n-r] % mod;
}
long long modpow(int n, int m) {
	if (m == 0) return 1;
	if (m == 1) return n;
	long long r = modpow(n, m/2);
	r = r * r % mod;
	if (m % 2 == 1) return r = r * n % mod;
	return r;
}
int main() {
	fact[0] = 1;
	for (int i = 1; i <= M; ++ i) fact[i] = fact[i-1] * i % mod;
	for (int i = 0; i <= M; ++ i) invfact[i] = modpow(fact[i], mod-2);

	cin >> N;
	auto p = f();
	int x = p.first - p.second + N;
	for (int k = 1; k <= N+1; ++ k) {
		long long r = comb(N+1, k);
		if (x >= k-1) (r += mod - comb(x, k-1)) %= mod;
		cout << r << endl;
	}
}


Measured memory_bytes: 2808
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let k: usize = read();

    let mut s: Vec<usize> = vec![0; n+1];
    for i in 0..n {
        s[i+1] = s[i] + (i+1)
    }

    let mut ans: usize = 0;
    for i in k..n+1 {
        ans += (s[n] - s[n-i]) - s[i-1] + 1
    }

    println!("{}", (ans+1) % (10*10*10*10*10*10*10*10*10 + 7));
}


Measured memory_bytes: 3556
unittest
{
	assert( [ "111" ].parse.expand.solve == 111 );
	assert( [ "112" ].parse.expand.solve == 222 );
	assert( [ "750" ].parse.expand.solve == 777 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	return tuple( n );
}

auto solve( long n )
{
	return [ 111, 222, 333, 444, 555, 666, 777, 888, 999 ].find!( ( a, b ) => b <= a )( n ).front;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
long long h;
long long n;
cin>>h>>n;
long long a[n];
for(int i=0;i<n;i++){
    cin>>a[i];
}
long long sum=0;
for(int i=0;i<n;i++){
    sum+=a[i];
}
if(sum>=h){
    cout<<"Yes"<<endl;
}
else {
    cout<<"No"<<endl;
}
    return 0;
}

Measured memory_bytes: 1024
x, n = gets.split(" ").map(&:to_i)
nums = gets.split(" ").map(&:to_i).slice(0,n)

result = x
if nums.include?(x) then
    for d in 1..100 do
        if !nums.include?(x-d)
            result = x-d
            break
        elsif !nums.include?(x+d)
            result = x+d
            break
        end
    end
end

puts result


Measured memory_bytes: 14380
/* Author : Harshit Jain a.k.a. iharshit009 */
#include <bits/stdc++.h>
#define vi               vector<int>
#define pb(x)            push_back(x)
#define all(x)           x.begin(), x.end()
#define sortall(x)       sort(all(x))
#define sortrev(x)       sort(all(x), greater<int>())
#define debug(x)         cout << '>' << #x << ':' << x << endl;
#define int              long long
#define ld               long double
#define endl 			 "\n";
#define mp 				 make_pair
#define pii 			 <int, int>
#define lb 				 lower_bound
#define ub				 upper_bound
#define len(a)           int((a).size())
#define prec(n)          fixed<<setprecision(n)
#define cnt(n)           __builtin_popcountll(n)
#define pi               pair<int, int>
const int mod = 1000000007;
using namespace std;
using namespace std::chrono;
// const int N = 1e5 + 5; 
// int n;
// int a[N];



int32_t main(){
auto start = high_resolution_clock::now(); // starting clock
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t;
t = 1;
// cin >>t;
while(t--){

int n;
cin >> n;
if(n >= 30){
	cout << "Yes" << endl;
}

else{
	cout << "No" << endl;
}







}
auto stop = high_resolution_clock::now(); // stop clock
auto duration = duration_cast<microseconds>(stop - start);  // printing duration
cerr << "Time taken by function: " << duration.count() << " milliseconds" << endl; 
return 0;
}

Measured memory_bytes: 3656
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)


int solve(int x) {
  for (int i = 1; ; ++i) {
    x -= i;
    if (x <= 0)
      return i;
  }
}

int main() {
  int x;
  cin >> x;
  cout << solve(x) << endl;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 998244353
#define fi first
#define se second
#define pii pair<int,int>
#define int long long
#define endl '\n'
#define pll pair<long long,long long>
//#define LONGLONG_MAX 10000000000000000
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;
        
}
vector<vector<int>>v;
int a[100005];
map<pii,int>m;
void dfs(int i,int par,int j){
    int x=1;
    for(auto k:v[i]){
        if(k==par)continue;
        if(x==j)x++;
        if(m.find({i,k})!=m.end())a[m[{i,k}]]=x;
        else a[m[{k,i}]]=x;
        dfs(k,i,x);
        x++;
    }
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    v.resize(n);
    for(int i=0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        x--;y--;
        //edge.push_back({x,y});
        m[{x,y}]=i;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        ans=max(ans,(long long)v[i].size());
    }
    dfs(0,-1,-1);
    cout<<ans<<endl;
    for(int i=0;i<n-1;i++)cout<<a[i]<<endl;
    return 0;
}

Measured memory_bytes: 14976
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
const int maxn = 1e5+10;
int main()
{
   int n;
   scanf("%d",&n);
   int js=0;
   int f=0;
   for(int i=0;i<n;i++)
   {
       int x,y;
       scanf("%d%d",&x,&y);
       if(x==y)
       {
           js++;
       }
       else js=0;
       if(js==3)
       {
           f=1;
       }
   }
   if(js==3)f=1;
   if(f)printf("Yes\n");
   else printf("No\n");
   return 0;
}


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

using namespace std;

const int N = 5e5+5;

int n;
int q;
int ar[N];
int ans[N];
int last[N];
vector < pair < int , int > > Q[N];

long long s;
long long e;
long long val;
long long segtree[N << 2];

void update(int P , int L , int R){
     if(L > e || R < s){
        return;
     } else if(s <= L && R <= e) {
        segtree[P] += val;
        return;
     }
     int mid = (L + R) >> 1;
     update( (P << 1) | 0 , L , mid + 0);
     update( (P << 1) | 1 , mid + 1 , R);
     segtree[P] = segtree[P << 1] + segtree[P << 1 | 1];
}

long long query(int P , int L , int R){
    if(L > e || R < s){
        return 0;
    } else if(s <= L && R <= e){
        return segtree[P];
    } else {
        int mid = (L + R) >> 1;
        long long a = query( (P << 1) | 0 , L , mid + 0);
        long long b = query( (P << 1) | 1 , mid + 1 , R);
        return a + b;
    }
}

int main(){
    scanf("%d%d" , &n , &q);
    for(int i = 1; i <= n; i++){
        scanf("%d" , &ar[i]);
    }
    for(int i = 1; i <= q; i++){
        int l , r;
        scanf("%d%d" , &l , &r);
        Q[r].push_back({l , i});
    }
    for(int i = 1; i <= n; i++){
        if(last[ar[i]]){
            s = last[ar[i]];
            e = last[ar[i]];
            val = -1;
            update(1 , 1 , n);
        }
        last[ar[i]] = i;
        s = i;
        e = i;
        val = 1;
        update(1 , 1 , n);
        for(int j = 0; j < Q[i].size(); j++){
            s = Q[i][j].first;
            e = i;
            ans[Q[i][j].second] = query(1 , 1 , n);
        }
    }
    for(int i = 1; i <= q; i++){
        printf("%d\n" , ans[i]);
    }
}


Measured memory_bytes: 39484
/*
  AOJ 0151
  Title:Grid
  @kankichi573
*/
#include <stdio.h>
int max(int x,int y) 
{
return  (((x)>(y))?(x):(y));
}
int n;
char grid[255][256];
int max_ren(int sx,int sy,int xoffs,int yoffs,int limit)
{
  int i,j,ren=0,max_=0;

  for(i=sx,j=sy;i<limit && i>=0 && j<limit && j >= 0 ;i+=xoffs,j+=yoffs)
    {
    if(grid[i][j]=='1')
      {
	ren++;
	if(ren>max_)
	  max_=ren;
      }
    else
      ren=0;
    }
  return(max_);
}
int solve()
{
  int i,ret;

  ret=0;
  for(i=0;i<n;i++)
    {
      ret=max(ret,max_ren(0,i,1,0,n));
      ret=max(ret,max_ren(0,i,1,1,n));
      ret=max(ret,max_ren(0,i,1,-1,n));
    }
  for(i=0;i<n;i++)
    {
      ret=max(ret,max_ren(i,0,0,1,n));
      ret=max(ret,max_ren(i,0,1,1,n));
    }
  for(i=0;i<n;i++)
    ret=max(ret,max_ren(i,n-1,1,-1,n));
  return(ret);
}
main()
{
  int  i;

  while(scanf("%d",&n) && n)
    {
      for(i=0;i<n;i++)
	scanf("%s",&grid[i][0]);
      printf("%d\n",solve());
    }
  return(0);
}

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

int main() {
	std::string a, b;

	while (std::cin >> a) {
		std::cin >> b;
		std::vector<std::vector<int>> memo(a.size() + 1, std::vector<int>(b.size() + 1, 0));
		int max = 0;
		for (auto apos = 1; apos <= a.size(); ++apos) for (auto bpos = 1; bpos <= b.size(); ++bpos){
			if (a[apos - 1] == b[bpos - 1]) {
				memo[apos][bpos] = memo[apos - 1][bpos - 1] + 1;
				if (memo[apos][bpos] > max)
					max = memo[apos][bpos];
			}
		}
		std::cout << max << std::endl;
	}
}


Measured memory_bytes: 65728
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   

int main(){
    std::ios::sync_with_stdio(false);
    ll n,a,b;
    cin>>n>>a>>b;
    //cout<<a*b<<endl;
    //return 0;
    if(n>a*b){
    	cout<<-1<<endl;
    	return 0;
    }
    if(n<a+b-1){
    	cout<<-1<<endl;
    	return 0;
    }
    ll i=a+b-1;
    ll previ=a,j;
    ll flag=1;
    while(flag){
    	if(i>=n){
    		flag=0;
    		i=n;
    	}
    	//i=n;
    	j=i;
    	while(j>previ){
    		cout<<j<<" ";
    		j--; 
    	}
    	previ=i;
    	i+=b-1;

    }
    rep(i,a){
    	cout<<i+1<<" ";
    }

    return 0;  
    
}



Measured memory_bytes: 2176
#include<stdio.h>
#include<stdlib.h>

int compare(const void *a,const void *b){
  return *(int*)b-*(int*)a;
}



int main(){
	
	int N,K,A[200000],i,num[200001],ans=0;
	
	scanf("%d",&N);
	scanf("%d",&K);
	
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	
	for(i=0;i<N+1;i++){
		num[i]=0;
	}
	
	for(i=0;i<N;i++){
		num[A[i]]++;
	}
	
	qsort(num,N,sizeof(int),compare);
	
	for(i=K;i<N+1;i++){
		
		ans+=num[i];
	}
	
	printf("\n%d\n\n",ans);
	
	
	
	return 0;
}

Measured memory_bytes: 2556
//k_tourist
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define mx 500005
#define non __builtin_popcount
#define ml map<ll, ll> 
#define uml unordered_map<ll, ll>
#define ms map<string , ll> 
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define pl pair<ll, ll>
#define vl vector<ll>
#define vll vector<pl>
#define tpl pair<ll, pl>
#define vlll vector<tpl>
#define vs vector<string>
#define pb push_back
#define mk make_pair
#define M_PI 3.14159265358979323846
#define endl '\n'
#define fst ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%I64d",&x)
#define inf ((ll)1e18 + 1)
#define bs binary_search
#define pq priority_queue
#define ub upper_bound
#define lb lower_bound
#define pow powr
#define sp(a) setprecision(a)
#define rep(i,a,b)  for (i=(a);i<(b);i++)
#define nrep(i,a,b) for (i=(a);i>(b);i--)
using namespace std;
using namespace __gnu_pbds;  

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>  ordered_set;
 
ll powr(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

void flag(ll fl){

	if(fl)
	cout<<"NO";
	else
	cout<<"YES";
}


vl gr[mx];
ll vis[mx], n, dp[mx];

void graph(ll n, ll m){

    ll i, j;

    rep(i, 1, n+1)
    {
        vis[i]= 0;
        gr[i].clear();
    }

    while(m--){

        ll x, y;
        cin>>x>>y;
        gr[x].pb(y);
        // gr[y].pb(x);
    }
}

ll lon(ll i){

	if(!gr[i].size())
	return 1;

	if(dp[i] != -1)
	return dp[i];

	ll j, ans= 1;

	for(ll kk: gr[i])
	ans= max(ans, lon(kk) +1);

	return dp[i]= ans;
}

void bta_de_yarr(){

	ll i, j, fl=0, ans, m;

	cin>>n>>m;

	graph(n, m);

	ans= 0;

	rep(i, 1, n+1)
	dp[i]= -1;

	rep(i, 1, n+1){

		ans= max(ans, lon(i));
	}
	
	ans--;
	cout<<ans;
	// flag(fl);
	cout<<endl;
}

int main(){
    fst

	// freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
	ll t;
    t= 1;
	//cin>>t;
    while(t--){
        bta_de_yarr();
    }
    return 0;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Measured memory_bytes: 23680
#include<stdio.h>
int main() {
	int max=0, min=1000000,maxnum=0,minnum=0;
	int n;
	int s[100005];
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &s[i]);
		if (max < s[i])max = s[i];
		if (min > s[i])min = s[i];
	}
	if (max - min >= 2) { printf("No"); return 0; }
	
	for (int i = 0; i < n; i++) {
		if (max == s[i])maxnum++;
		if (min == s[i])minnum++;
	}
	if (max == min && (n - maxnum + 1 <= max && max <= n - maxnum + maxnum / 2 || max + 1 == n)) { printf("Yes"); return 0; }
	else if (max == min ) { printf("No"); return 0; }

	if (n - maxnum + 1 <= max && max <= n - maxnum + maxnum / 2) { printf("Yes"); return 0; }
	else {
		printf("No");
	}
}


Measured memory_bytes: 512
/*input
10000 1 1
*/

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

int main() {
    int D, T, S;
    cin >> D >> T >> S;
    if (S*T >= D) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 3632
#include<stdio.h>
int i,j,a,b,c[1001],d[1001],e[1001][100000],f=-1;
int main(void)
{
	scanf("%d %d",&a,&b);
	for(i=0;i<=a;i++){
		for(j=0;j<=b;j++){
			e[i][j]=-1;
		}
	}
	for(i=0;i<a;i++){
		scanf("%d %d",&c[i],&d[i]);
	}
	e[0][0]=0;
	for(i=0;i<a;i++){
		for(j=0;j<=b;j++){
			if(e[i][j]!=-1){
			if(e[i][j]+c[i]>e[i+1][j+d[i]] && j+d[i]<=b){
				e[i+1][j+d[i]]=e[i][j]+c[i];
			}
			if(e[i][j]>e[i+1][j]){
				e[i+1][j]=e[i][j];
			}
			}
		}
	}
	for(i=0;i<=a;i++){
		for(j=0;j<=b;j++){
			if(f<e[i][j]){
				f=e[i][j];
			}
		}
	}
	printf("%d\n",f);
	return 0;
}

Measured memory_bytes: 40200
import numpy as np

a, b, h, m = map(int, input().split())


hun_deg = m * 6

ji_deg = h * 30 + 30 * m / 60

hun_x = b * np.cos(hun_deg * np.pi / 180)
hun_y = b * np.sin(hun_deg * np.pi / 180)

ji_x = a * np.cos(ji_deg * np.pi / 180)
ji_y = a * np.sin(ji_deg * np.pi / 180)

out = np.sqrt((hun_x-ji_x)**2 + (hun_y-ji_y)**2)

print(out)


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

Measured memory_bytes: 171400
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
long long fac(ll a){
    long long ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
int main(){
    int n;cin >> n;
    vl v(n);
    rep(i,n)cin >> v[i];
    ll ans=0;
    rep(i,n-1){
        if(v[i]==i+1&&v[i+1]==i+2){
            swap(v[i],v[i+1]);
            ans++;
        }
    }
    rep(i,n){
        if(v[i]==i+1)ans++;
    }
    cout << ans << endl;
}

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

int main() {
  	long long x, happiness = 0;
  	cin >> x;
  	while(x >= 500) {
      	x -= 500;
      	happiness += 1000;
    }
  	while(x >= 5) {
        //cout << x << " " << happiness << endl;
      	x -= 5;
      	happiness += 5;
    }
  	cout << happiness << endl;
  	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    LL n,a,b;
    cin >> n >> a >> b;
    LL ans = n / (a + b) * a;
    ans += min(a, n % (a+b));
    cout << ans << endl;
}

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

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

int main() {
	int n;
	int a[100000] = {};
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		a[x - 1]++;
	}
	int b, t;
	for (b = 0, t = 100000 - 1; b < t; ) {
		while (a[b] < 2 && b < t) b++;
		while (a[t] < 2 && b < t) t--;
		if (b < t) {
			int m = min(a[b], a[t]) - 1;
			a[b] -= m;
			a[t] -= m;
			n -= 2 * m;
		} else {
			n -= a[b] / 2 * 2;
		}
	}
	cout << n << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    ll x;
    cin>>x;
    ll ans=x/11;
    ll cnt=0;
    if(ans*11==x);
    else if(ans*11+6>=x) ++cnt;
    else if(ans*11+11>=x) cnt=2;
    cout<<ans*2+cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))
B = list(accumulate(A))
S = B[-1]

ans = float('inf')
for i in range(N-1):
  x = B[i]
  y = S - x
  ans = min(ans, abs(x - y))

print(ans)

Measured memory_bytes: 24172
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int a[9];
int n;

int main()
{
	cin >> n;
	for (int i = 0;i < n;i++) {
		int t;
		cin >> t;
		if (1 <= t && t <= 399)	a[0]++;
		if (400 <= t && t <= 799)	a[1]++;
		if (800 <= t && t <= 1199)	a[2]++;
		if (1200 <= t && t <= 1599)	a[3]++;
		if (1600 <= t && t <= 1999)	a[4]++;
		if (2000 <= t && t <= 2399)	a[5]++;
		if (2400 <= t && t <= 2799)	a[6]++;
		if (2800 <= t && t <= 3199)	a[7]++;
		if (3200 <= t)	a[8]++;
	}

	int sum = 0;
	for (int i = 0;i < 8;i++) {
		if (a[i]) sum++;
	}
	
	if (sum) {
		cout << sum << " " << sum + a[8] << endl;
	}
	else {
		cout << 1 << " " << a[8] << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define substr(s,f,t) (s.substr(f-1,t-f+1))
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;cin>>n;
  vi num(n);
  int fl=100;
  ll ma=0;
  ll po;
  bool mifl=false;
  for(int i=0;i<n;i++){
    cin>>num[i];
    if(i==0){
      if(num[i]<0){fl=-1;mifl=true;ma=abs(num[i]);po=0;}
      else {fl=1;mifl=false;ma=abs(num[i]);po=0;}
    }else{
      if(num[i]<0){
	if(fl<0){
	  if(ma<abs(num[i])){
	    ma=max(ma,abs(num[i]));po=i;
	  }
	}else if(fl>0){
	  fl=0;
	  if(ma<abs(num[i])){
	    ma=-num[i];
	    mifl=true;
	    po=i;
	  }
	}else{
	  if(ma<abs(num[i])){
	    ma=-num[i];
	    mifl=true;po=i;
	  }
	}
      }else{
	if(fl<0){
	  fl=0;
	  if(ma<abs(num[i])){
	    ma=abs(num[i]);
	    mifl=false;po=i;
	  }
	}else if(fl>0){
	  if(ma>num[i]){
	  ma=max(ma,num[i]);
	  po=i;
	  }
	}else{
	  if(ma<abs(num[i])){
	    ma=abs(num[i]);po=i;
	    mifl=false;
	  }
	}
      }
    }
  }
  if(fl>0){
    cout<<n-1<<endl;
    for(int i=0;i<n-1;i++)
      cout<<i+1<<" "<<i+2<<endl;
  }else if(fl<0){
    cout<<n-1<<endl;
    for(int i=n-1;i>0;i--){
      cout<<i+1<<" "<<i<<endl;
    }
  }else{
    cout<<2*n-1<<endl;
    if(mifl){
      for(int i=0;i<n;i++){
	cout<<po+1<<" "<<i+1<<endl;
      }
    for(int i=n-1;i>0;i--){
      cout<<i+1<<" "<<i<<endl;
    }
     
    }else{
      for(int i=0;i<n;i++){
	cout<<po+1<<" "<<i+1<<endl;
      }
 for(int i=0;i<n-1;i++)
      cout<<i+1<<" "<<i+2<<endl;
    }
  }
  return 0;
}

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




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define drep(i,n) for (int i = (n)-1; i >= 0; i--)
#define sz(x) int((x).size())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
int dsum(int x) {
  int res = 0;
  while (x) {
    res += x%10;
    x /= 10;
  }
  return res;
}
int main() {
  int n;
  cin>>n;
  int ans = 1e9;
  for (int i=1;i<=n-1;i++) ans = min(ans, dsum(i)+dsum(n-i));
  cout << ans << endl;
  return 0;
}

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

int calc(int i, int a){
  if(i % 2 == 1) a *= 2;
  return a/10+a%10;
}

int main(){
int n,m,a[10],dp[100000][10];
 string str;
 cin >> n >> str >> m;
 for(int i=0;i<m;i++) cin >> a[i];
 fill(dp[0],dp[100000],0);
 reverse(str.begin(),str.end());

 if(str[0] != '*') dp[0][str[0]-'0'] = 1;
 else for(int i=0;i<m;i++) dp[0][a[i]] = 1;

 for(int i=1;i<n;i++){
   for(int j=0;j<10;j++){
     if(str[i] == '*') for(int k=0;k<m;k++) dp[i][(calc(i,a[k])+j)%10] += dp[i-1][j];
     else dp[i][(calc(i,str[i]-'0')+j)%10] += dp[i-1][j];
   }
 }
 cout << dp[n-1][0] << endl;
}

Measured memory_bytes: 5236
#include<iostream>
#include<cstdio>
using namespace std;
char grade(int m, int f, int r){
    int t = m + f;
    char ch;
    if(m == -1 || f == -1)ch='F';
        else if(80<=t)ch='A';
        else if(65<=t && t<80)ch='B';
        else if(50<=t && t<65)ch='C';
        else if(30<=t && t<50 ){
            if(50<=r)ch='C';
            else if(r<50)ch='D';
        
    }
        else if(t<30)ch='F';
    
    return ch;
} 
int main(){
    int m,f,r;
      while(1){
        cin >> m >> f >> r;
        if(m==-1 && f==-1 && r==-1)break;
        cout << grade(m,f,r) << endl;
    }
    return 0;
}



Measured memory_bytes: 3084
#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;
const long long inf=(long long)(1e12);
vector<vector<long long> >G;
vector<long long>dp;
vector<long long>points;
int n;
long long fun(int mask)
{
    if(dp[mask]!=-inf) return dp[mask];
    int i,j,k;
    long long ans=-inf;
    for(i=mask+1;i<(1<<n);i++)
    {
        if(((mask&i)==mask) && ((i&(~mask))!=0))
        ans=max(ans,points[i&(~mask)]+fun(i));
    }
    dp[mask]=ans;
    return ans;
}
void pre_compute()
{
    points.resize(1<<n);
    for(int i=0;i<(1<<n);i++)
    {
        points[i]=0;
        for(int j=0;j<n;j++)
        {
            if(i&(1<<j))
            for(int k=j+1;k<n;k++)
                if(i&(1<<k)) points[i]+=G[j][k];
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int i,j;
    cin>>n;
    vector<long long>tmp(n);
    G.resize(n,tmp);
    for(i=0;i<n;i++)    for(j=0;j<n;j++)    cin>>G[i][j];
    pre_compute();
    dp.resize((1<<n),-inf);
    dp[(1<<n)-1]=0;
    for(i=0;i<n;i++) dp[1<<i]=0;
    cout<<fun(0);
}


Measured memory_bytes: 1280
import sys
import copy
import  math
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, k = na()
li = []
for i in range(n):
    a, b = na()
    li.append((a, b))
ct = 0
for a, b in sorted(li, key=itemgetter(0)):
    ct += b
    if ct >= k:
        ans = a
        break
print(ans)


Measured memory_bytes: 19548
#B - AcCepted
S=str(input())
#print(S[0].isupper())
#print(S[1])
length=len(S)
cnt=0
flg=1
ans="WA"
if S[0]=='A' and S.count('C')==1:
    #S[0].replace('A','a')

    ans="AC"
    for i in range(1,length):
        if S[i].isupper() and S[i]!='C':
            ans="WA"
            break
        elif S[i]=='C':
            if i<2 or i>(length-2):
                ans="WA"
                break
print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include <iomanip>
#include<math.h>

#define rep0(i,N) for(int i=0;i<N;i++)
#define rep1(i,a,N) for(int i=0+a;i<N;i++)
#define lint long long int
#define SIZE 1000005

using namespace std;

int main(){
	double n;
	lint a[SIZE];
	cin>>n;
	rep0(i,pow(2,n))
		cin>>a[i];
	int nn=n;
	rep1(j,1,nn+1){
		rep0(i,pow(2,n-j)){
			if(a[i*2]==a[i*2+1])
				a[i]=a[i*2];
			else
				a[i]=abs(a[i*2]-a[i*2+1]);
		}
	}
	cout<<a[0];
return 0;
}

Measured memory_bytes: 2304
#include <stdio.h>

void era_name(int year, int month, int day);

int main(void)
{
    int year;
    int month;
    int day;
    while ((scanf("%d %d %d", &year, &month, &day)) != EOF) {
        era_name(year, month, day);
    }
    return 0;
}

void era_name(int year, int month, int day)
{
    int myear = year - 1867;
    int tyear = year - 1911;
    int syear = year - 1925;
    int hyear = year - 1988;
    int date = year * 10000 + month * 100 + day;
    if (date <= 18680907) {
        printf("pre-meiji\n");
    } else if (date <= 19120729) {
        printf("meiji %d %d %d\n", myear, month, day);
    } else if (date <= 19261224) {
        printf("taisho %d %d %d\n", tyear, month,day);
    } else if (date <= 19890107) {
        printf("showa %d %d %d\n", syear, month, day);
    } else {
        printf("heisei %d %d %d\n", hyear, month, day);
    }
}

Measured memory_bytes: 1036
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N, K = list(map(int, sys.stdin.readline().split()))

a = list(range(1, N+1, 2))
if len(a) >= K:
    print('YES')
else:
    print('NO')


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

struct data {
	int node_id;
	vector<llong> edge;
	vector<llong> col;
	set<int> used;

	data() = default;
};

int main() {
	llong N;
	vector<data> nodes;
	vector<lpair> edges;

	cin >> N;
	nodes.resize(N+1);
	edges.resize(N-1);
	for (int i = 0; i < N-1; ++i) {
		llong a, b;
		cin >> a >> b;
		nodes[a].edge.push_back(b);
		nodes[b].edge.push_back(a);

		nodes[i+1].node_id = i+1;
		edges[i] = lpair(a, b);
	}
	nodes[N].node_id = N;

	llong m_id = 0, m_size = 0;
	for (int i = 1; i <= N; ++i) {
		sort(ALL(nodes[i].edge));
		nodes[i].col.resize(nodes[i].edge.size(), inf<llong>);

		if (nodes[i].edge.size() > m_size) {
			m_size = nodes[i].edge.size();
			m_id = i;
		}
	}

	int col_size = m_size;
	queue<int> que;
	que.push(m_id);
	while (que.size()) {
		data &now = nodes[que.front()];
		que.pop();
		if (now.used.size() == now.edge.size()) continue;

		int next_col = 1;
		for (int i = 0; i < now.edge.size(); ++i) {
			if (now.col[i] != inf<llong>) continue;

			data &next = nodes[now.edge[i]];
			int next_id = lower_bound(ALL(next.edge), now.node_id) - next.edge.begin();

			while (now.used.count(next_col) || next.used.count(next_col)) {
				++next_col;
			}

			now.col[i] = next_col;
			next.col[next_id] = next_col;
			now.used.insert(next_col);
			next.used.insert(next_col);

			que.push(next.node_id);
		}
	}

	cout << col_size << endl;
	for (auto &res: edges) {
		cout << nodes[res.first].col[lower_bound(ALL(nodes[res.first].edge), res.second) - nodes[res.first].edge.begin()] << endl;
	}


	return 0;
}

Measured memory_bytes: 28672
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: i64,
    v: [i64; 5],
  }
  let m = v.iter().min().unwrap();
  let ans = (n + m - 1) / m + 4;

  puts!("{}\n", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N, A, B;
  cin >> N;
  int count = 0;
  for(int i = 0; i < N; i++){
    cin >> A >> B;
    if(A == B)count++;
    else count = 0;
    if(count == 3){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3628
from collections import deque

swap = [[1, 4], [0, 2, 5], [1, 3, 6], [2, 7], [0, 5], [1, 4, 6], [2, 5, 7], [3, 6]]

def bfs():
    ia = list(range(8))
    count = {
        str(ia): 0
    }
    q = deque()
    q.append([ia, 0])
    while q:
        a, c = q.popleft()
        i = a.index(0)
        for j in swap[i]:
            na = a.copy()
            na[i], na[j] = na[j], na[i]
            if str(na) not in count:
                count[str(na)] = c + 1
                q.append([na, c+1])

    return count

if __name__ == '__main__':
    count = bfs()
    while True:
        try:
            a = list(map(int, input().split()))
            print(count[str(a)])
        except:
            break

Measured memory_bytes: 10520
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <string>
#include <queue>
#include <omp.h>
#include <fstream>   // ifstream, ofstream
typedef int64_t ll;
using namespace std;
const ll INF=1e16;
const double EPS=1e-8;
const ll mod = 1000000007;

int64_t powm(int64_t a,int64_t b){//a^bを求める
	if(b==0){
		return 1;
	}else{
		int64_t temp = powm(a,b/2);
		temp = temp * temp;
		if(b%2==1){
			temp = temp * a;
		}
		return temp;
	}
}

int main(){
	ll n;
	cin>>n;
	ll ans=0;
	for(ll i1=1;i1<=5;i1++){
		if(i1%2==0){
			continue;
		}
		if(n>=pow(10,i1)-1){
			ans += pow(10,i1)-pow(10,i1-1);
		}else if(n>=pow(10,i1-1)){
			ans += n - pow(10,i1-1)+1;
		}
	}
	cout<<ans<<endl;


}


Measured memory_bytes: 256
N = int(input())
X = list(map(int, input().split()))

import math, statistics

X_mean = statistics.mean(X)

X_mean_l = math.floor(X_mean)
X_mean_h = math.ceil(X_mean)

ans_l = 0
ans_h = 0

for i in range(N):
    ans_l += (X[i] - X_mean_l)**2
    ans_h += (X[i] - X_mean_h)**2

if ans_l < ans_h:
    print(ans_l)
else:
    print(ans_h)
    

Measured memory_bytes: 5276
N = int(input())
from itertools import product

l = []
for i in range(3,10):
    ll = list(product(["3","5","7"],repeat = i))
    lll = list(map(list,ll))
    llll = list(map("".join, lll))
    lllll = list(map(int,llll))
    l.append(lllll)

x = []
for s in l:
    x.extend(s)
x.sort()
count = 0
for i in x:
    if i <= N and len(set(list(str(i)))&set(["3","5","7"]))==3:
        count += 1

print(count)

Measured memory_bytes: 13428