akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 100000000000000
#define int long long int

vector<pair<int, int>> G[100010];
int L[100010];

void dfs(int V, int cost){
    L[V] = cost;
    rep(i, G[V].size()) {
        if(L[G[V][i].first] != INF2) continue;
        dfs(G[V][i].first, cost + G[V][i].second);
    }
}


signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    rep(i, N-1) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        G[a].push_back({b, c});
        G[b].push_back({a, c});
    }
    int Q, K;
    cin >> Q >> K;
    rep(i, 100010) L[i] = INF2;
    dfs(K - 1, 0);

    rep(i, Q) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        cout << L[x] + L[y] << endl;
    }

    return 0;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
#define PRINT(s) cout << s << endl;
#define FOR(i, a, b) for (unsigned int i = (a); i < (b); i++)
#define REP(i, n) FOR((i), 0, (n))

int main() {
    int a;
    cin >> a;
    PRINT(a + a * a + a * a * a);
}


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

mod = 10**9+7
ans = 0
for j in range(60):
    one_num = 0
    for i in A:
        if (i >> j) & 1:
            one_num += 1
    ans += one_num * (N - one_num) * 2**j
    ans %= mod
print(ans)

Measured memory_bytes: 124352
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()

# int(input())
# map(int, input().split())

from math import atan, degrees

a, b, x = map(int, input().split())

# 三角柱
w = x * 2 / (a * b)
if 0 <= w <= a:
    print(degrees(atan(b / w)))
    exit()

# 台形柱
h = x * 2 / (a ** 2) - b
print(degrees(atan((b - h) / a)))


Measured memory_bytes: 40368
#include <bits/stdc++.h>
using namespace std;
#define ll	    long long
#define vi      vector <ll>
#define vii     vector <pair<int,int>>
#define ii      pair<int,int>
#define loop(n)	for(int i=0;i<n;i++)
#define pb      push_back
const ll mod=1e9+7;
void fast();
ll gcd(ll a,ll b){
    if(!b)
        return a;
    return gcd(b,a%b);
}
int main()
{
    fast();
    ll a,b;
    cin>>a>>b;
    set<int>s;
    a=__gcd(a,b);
    for(ll i=2;i*i<=a;i++){
        if(a%i==0){
            while(a%i==0)
                a/=i;
            s.insert(i);
        }
    }
    if(a>1)
        s.insert(a);
    cout<<s.size()+1;
}
void fast(){
std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
/*

*/


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <tuple>
#include <utility>
using namespace std;

template<typename T>
struct CumSum{
private:
  size_t size;
  vector<T> data;
public:
  CumSum(vector<T> dat){
    size = dat.size();
    data.resize(size+1,0);
    for(size_t i = 0; i < size; ++i)
      data[i+1] = data[i] + dat[i];
  }
  T getsum(size_t l, size_t r){//0-indexed, [l,r)
    return data[r] - data[l];
  }
  T getsum(size_t r){//0-indexed, [0,r)
    return data[r];
  }
};

int main(){
  long long N, M;
  cin >> N >> M;
  vector<long long> A(N), B(M);
  map<long long,long long> B_;
  for(int i = 0; i < N; ++i) cin >> A[i];
  for(int i = 0; i < M; ++i) cin >> B[i], ++B_[B[i]];
  //A.push_back(1e9);
  sort(A.begin(), A.end());
  CumSum<long long> cs(A);
  long long ans = 0;
  for(auto e : B_){
    long long b, c;
    tie(b,c) = e;
    //cerr << b << " " << c << endl;
    long long t = 0;
    size_t l = 0;
    while(t <= A.back()){
      size_t r = lower_bound(A.begin(), A.end(), t+b) - A.begin();
      ans += (cs.getsum(l,r) - t*(r-l))*c;
      l = r;
      t += b;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 21164
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
#include <chrono>
#include <cstdlib>
#include <bitset>
using namespace std;

int main(){
    int a;
    string s;
    cin >> a >> s;
    if(a >= 3200) cout << s << endl;
    else cout << "red" << endl;
}


Measured memory_bytes: 256
n = int(input())
a = []
count = 0
while 1:
    if a.count(n):
        print(count+1)
        break
    else:
        a.append(n)
        count += 1
    if n % 2 == 0:
        n = n/2
    else:
        n = 3*n + 1


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,a,b;cin>>n>>a>>b;
  if(a>b||(n==1&&a!=b)){
    cout<<0<<endl;
    return 0;
  }
  ll mi=a*(n-1)+b;
  ll ma=a+(n-1)*b;
  cout<<ma-mi+1<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main() {
    int n, k;
    cin >> n >> k;
    int count = 0;
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        if(a >= k) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int gc(int a, int b) {
  if (a%b == 0) return(b);
  else return(gc(b, a%b));
}
int gcd(int a, int b, int c) {
  return gc(a, gc(b, c));
}
int main() {
  long long sum = 0;
  int K;
  cin >> K;
  for(int i=1; i<=K; i++) {
    for(int j=1; j<=K; j++) {
      for(int k=1; k<=K; k++) {
        sum += gcd(i,j,k);
      }
    }
  }
  cout << sum << endl;
}

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

int main() {
	int N;
	cin >> N;
	int sum = 0;
	int MIN = 101;
	for (int i = 0; i < N; i++) {
		int s;
		cin >> s;
		sum += s;
		if (s%10!=0) MIN = min(s, MIN);
	}
	if (MIN == 101) MIN = sum;
	cout << (sum % 10 != 0 ? sum : sum - MIN) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <vector>
#include <string.h>
using namespace std;

int main() {
	long long int N,m=0,a=0,r=0,c=0,h=0;
	long long int ans=0;
	string S[1000000];
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>S[i];
		if(S[i][0]=='M')m++;
		if(S[i][0]=='A')a++;
		if(S[i][0]=='R')r++;
		if(S[i][0]=='C')c++;
		if(S[i][0]=='H')h++;
	}
	ans=m*a*(r+c+h)+m*r*(c+h)+m*c*h+a*r*(c+h)+a*c*h+r*c*h;
	cout<<ans;
	}

Measured memory_bytes: 13184
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>

using namespace std;
typedef long long ll;

const ll INF = 1LL<<62;

string s, t;
int dp[3100][3100] = {0};

int main() {
  cin >> s >> t;
  
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < t.size(); j++) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
      }
      dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]);
      dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1]);
    }
  }
  
  string res = "";
  int i = (int) s.size(), j = (int) t.size();
  while(i > 0 && j > 0) {
    if (dp[i][j] == dp[i - 1][j]) {
      i--;
    } else if (dp[i][j] == dp[i][j - 1]) {
      j--;
    } else {
      i--; j--;
      res = s[i] + res;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 37120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int cnt = 0;
    for (int i = a; i <= b; ++i)
    {
        if (c % i == 0)
            cnt++;
    }
    cout << cnt << endl;
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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; }

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍


int main(){
	string s;cin>>s;
	ll a=0,b=0;
	rep(i,0,s.size()){
		if(s[i] == 'A' || s[i] == 'G' || s[i] == 'T' || s[i] == 'C'){
			b++;
		}
		else{
			if(a<b) a=b;
			b=0;
		}
	}
	if(a<b) a=b;
	cout << a << ednl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=(n);i<(int) N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=(int) n;i--)
#define p(s) cout<<(s)<<endl
#define DEBUG(x,y) cout<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl;
#define CK(n,a,b) ((a)<=(n)&&(n)<=(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf=1e9+7;

string s;
int n,a,b,c;
int main(){
	cin>>a>>b;

	p(2*b-a);

	return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        x: usize,
    }
    let mut x = x;
    loop {
        let mut is_prime = true;
        let target = (x as f64).sqrt() as usize;
        for i in 2..target + 1 {
            if x % i == 0 {
                is_prime = false;
                break;
            }
        }
        if is_prime {
            break;
        }
        x += 1;
    }
    println!("{}", x);
}


Measured memory_bytes: 4352
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 1000005;
 
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
ll modularExponentiation(ll x,ll n)
{
    int result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%MOD;
        x=(x*x)%MOD;
        n=n/2;
    }
    return result;
}
ll d, x, y;
void extendedEuclid(ll A, ll B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        extendedEuclid(B, A%B);
        ll temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}
ll modInverse(ll A)
{
    extendedEuclid(A,MOD);
    return (x%MOD+MOD)%MOD;   
}


int main()
{
    map<ll,ll> y;
    ll n;
    cin >> n;
    ll a[n];
    for(ll i=0;i<n;i++)    cin >> a[i];
    for(ll i=0;i<n;i++)
    {
        ll temp = a[i];
        ll cnt = 0;
        while(temp%2==0)   temp/=2,cnt++;
        y[2] = max(y[2],cnt);
        for(ll j=3;j*j<=temp;j+=2)
        {
            ll cnt = 0;
            while(temp%j==0)   temp/=j,cnt++;
            if(cnt>0)   y[j] = max(y[j],cnt);
        }
        if(temp!=1)   y[temp] = max(y[temp],1LL);
    }
    ll lcm = 1;
    
    for(auto X:y)
    {
        lcm = (lcm * modularExponentiation(X.ff,X.ss))%MOD;
    }
    ll ans = 0;
    for(ll i=0;i<n;i++)
    {
        ans = (ans + (lcm*modInverse(a[i]))%MOD)%MOD;
    }
    cout<<ans;
}

Measured memory_bytes: 896
#include <stdio.h>

int main() {
  int number_a, number_b;
  scanf("%d %d", &number_a, &number_b);
  if((number_a * number_b) % 2 == 0) {
    printf("Even\n");
  } else {
    printf("Odd\n");
  }
  return 0;
}


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

using namespace std;

int main(){
    int X,Y;
    cin >> X >> Y;

    for(int i=0; i<=X; i++){
        int j = X - i;
        if(i*4 + j*2 == Y){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}   

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

#define int long long

int dp[3006][3006];
#define mod 998244353
int a, b, c, d;
int f(int x, int y){
    if(dp[x][y] != -1)return dp[x][y];
    if(x == a){
        if(y == b){
            return dp[x][y] = 1;
        }
        else
            return dp[x][y] = (f(x, y - 1) * x) % mod;
    }
    else{
        if(y == b){
            return dp[x][y] = (f(x - 1, y) * y) % mod;
        }
        else{
            return dp[x][y] = (f(x, y - 1) * x + f(x - 1, y) * y - (((x-1) * (y - 1))%mod) * f(x - 1, y - 1)) % mod;
        }
    }
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    memset(dp, -1, sizeof(dp));
    cin >> a >> b >> c >> d;
    cout << (f(c, d) + mod) % mod << '\n';
}

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

int main() {
	long l,r,i,j,ans=2018,mod=2019;
	cin >> l >> r;
	for(i=l; i<=r; i++){
		if(i%mod==0){
			cout << 0; return 0;
		}
	}
	for(i=l; i<r; i++){
		for(j=i+1; j<=r; j++){
			ans=min(ans,(i*j)%mod);
			if(ans==0){
				cout << 0; return 0;
			} 
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
    int R,C,K; cin>>R>>C>>K;
    vector<int> r(K),c(K);
    vector<ll> v(K);
    vector<vector<ll>> f(R+1,vector<ll>(C+1));
    rep(i,K){
        cin>>r.at(i)>>c.at(i)>>v.at(i);
        f.at(r.at(i)).at(c.at(i))=v.at(i);
    }

    vector<vector<vector<ll>>> dp(R+1,vector<vector<ll>>(C+1,vector<ll>(4,0)));

    //1-index
    rep1(r,R){
        rep1(c,C){
            rep(k,4){
                dp[r][c][0] = max(dp[r][c][0],dp[r-1][c][k]);
                dp[r][c][1] = max(dp[r][c][1],dp[r-1][c][k]+f[r][c]);

                dp[r][c][k] = max(dp[r][c][k],dp[r][c-1][k]);
                if(k>0){
                    dp[r][c][k] = max(dp[r][c][k],dp[r][c-1][k-1]+f[r][c]);
                }
            }
        }
    }

    ll res = 0;
    rep(k,4)res = max(res,dp[R][C][k]);
    cout<<res<<endl;
}


Measured memory_bytes: 710068
#include<stdio.h>

int main(){
    int W, H;
    int x, y;
    int i, j, k;
    double surfW, surfH;
    double surfmin;
    int sum=0;

    scanf("%d %d %d %d", &W, &H, &x, &y);

    printf("%lf ", (double)W*(double)H/2.0);
    if(x+x==W && y+y==H){
        printf("1");
    }else{
        printf("0");
    }

    return 0;
}

Measured memory_bytes: 128
type ABC(stream:System.IO.TextReader) =
  member this.Scan3 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2]))

let iter f a = Seq.initInfinite id |> Seq.scan (fun acc -> fun _ -> f acc) a

let util = ABC(stdin)

let r, d, a = util.Scan3 int64


iter (fun x -> r * x - d) a
|> Seq.skip 1
|> Seq.take 10
|> Seq.iter (printfn "%d")


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

using namespace std;

const int N = 1e5 + 7;

const int inf = 1e9;

int a[N];
int dp[N];

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

	int n, k;

	cin >> n >> k;

	for(int i = 0; i < n; i++){
		cin >> a[i];
	}

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

	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n, k;
  cin >> n >> k;
  vll a(n);
  rep(i, n) {
    cin >> a[i];
  }

  rep(i, k) {
    vll sum_start(n);
    vll sum_end(n + 1);
    rep(i, n) {
      ll l = max(0ll, i - a[i]);
      ll r = min(n, i + a[i] + 1);
      sum_start[l]++;
      sum_end[r]++;
    }

    ll sum = 0;
    rep(i, n) {
      sum -= sum_end[i];
      sum += sum_start[i];
      a[i] = sum;
    }

    ll min_val = INF;
    rep(i, n) {
      chmin(min_val, a[i]);
    }

    if (min_val == n) {
      break;
    }
  }

  rep(i, n) {
    cout << a[i] << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 7948
#include <stdio.h>
 
int main(void){
  char n[3];
  scanf("%s",n);
  if((n[0] < n[1]) ||( n[0] < n[2])){
    n[0] += 1;
  }
  printf("%c%c%c\n",n[0],n[0],n[0]);
}

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

typedef long long ll;
ll n, k;
map <ll,bool> mp;

bool cool (ll x){
    while(x){
        if(mp[x%10]) return 0;
        x/=10;
    }
    return 1;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    for(ll i=1; i<=k; i++){
        ll x;
        cin>>x;
        mp[x]=1;
    }

    ll cur=n;
    while(1){
        if(cool(cur)){
            cout<<(ll)cur;
            return 0;
        }
        cur++;
    }


}


Measured memory_bytes: 256
#include <stdio.h>
#define H 500000
int A[H],n;

int left(int);
int right(int);
void build(void);
void max(int);
void print(void);

int main(){

  int i;

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  build();
  print();
  
  return 0;

}

void max(int i){
  int largest,tmp,l,r;

  l=left(i);
  r=right(i);

  if(l<=n && A[l]>A[i])  largest=l;
  else largest=i;
 
  if(r<=n && A[r]>A[largest])
    largest=r;

  if(largest!=i){
    tmp=A[largest];
    A[largest]=A[i];
    A[i]=tmp;
    max(largest);
  }

}


void build(){
  int i;
  for(i=n/2;i>0;i--){
    max(i);
  }

}


  int left(int i){
  
    return 2*i;
  }

  int right(int i){
  
    return (2*i)+1;
  }
  
  void print(){
    int i;
    for(i=1;i<=n;i++){
      printf(" %d",A[i]);
      
    }
 printf("\n");
  }

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

int main() {
  string s;
  cin >> s;
  if(s == "Sunny") {
    cout << "Cloudy";
  } else if(s == "Cloudy") {
    cout << "Rainy";
  } else {
    cout << "Sunny";
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<int,P> PP;

//vector<PP> v;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

//vector<vector<int>> vec(n, vector<int>(1));
int main()
{
	int n,m;
	cin >> n >> m;
	vector<vector<int>> vec(n, vector<int>(0));
	
	int a[m],b[m];
	rep(i,m){
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		vec[a[i]].push_back(b[i]);
	}
	int s,t;
	cin >> s >> t;
	s--;
	t--;
	priority_queue<PP, vector<PP>, greater<PP> > Q;
	Q.push(PP(0,P(s,0)));
	int e[n+1][5];
	fill((int*)e,(int*)(e+n),INF);
	while(!Q.empty()){
		PP pp = Q.top();
		int cost = pp.fi;
		int now = pp.se.fi;
		int step = pp.se.se;
		Q.pop();
//		cout << cost << " now " << now << " step " << step << endl;
		rep(i,vec[now].size()){
			int next = vec[now][i];
			int next_step = (step+1)%3;
			int next_cost = cost + (step+1)/3;
			if(e[next][next_step] > next_cost){
				e[next][next_step] = next_cost;
				//cout << e[next][next_step] <<" next "<<next << " next_step " << next_step <<endl;
			
				Q.push(PP(next_cost,P(next,next_step)));
			}
		}
	}
	if(e[t][0] != INF) cout << e[t][0] << endl;
	else cout << "-1" << endl;
	/*vector<set<int>> set_vec(n);
	rep(i,m){
		set_vec[b[i]].insert(a[i]);
	}
	// vector<vector<int>> miti(n, vector<int>(0));
	// rep(i,n){
		// auto itr =set_vec[i].begin();
		// rep(j,set_vec.size()){
			// int prev = set_vec[i][j];
			
	vector<set<int>> set_vec2(n);
	rep(i,n){
		auto itr =set_vec[i].begin();
		while(itr != set_vec[i].end()){
			cout << *itr << " " << i << endl;
			set_vec2[*itr].insert(i);
			itr++;
		}
	}
	vector<vector<int>> miti(n, vector<int>(0));
	rep(i,n){
		auto itr =set_vec2[i].begin();
		while(itr != set_vec2[i].end()){
			miti[*itr].push_back(i);
			itr++;
		}
	}
	rep(i,n){
		rep(j,miti.size()){
			cout << miti[i][j] << " ";
		}
		cout << " i " << i << endl;
	}*/
	
	return 0;
}


Measured memory_bytes: 8448
#include <stdio.h>
int main(void){
	int a,b,i,ele;
	char s[12];
	scanf("%d%d%s",&a,&b,s);
	if(s[a]!='-'){printf("No\n");return 0;}
	for(i=0;i<a+b;i++){
		if(i!=a){
			ele=s[i]-'0';
			if(ele<0||9<ele){printf("No\n");return 0;}
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Diagnostics;
using System.IO;

namespace AtCoder.ABC110 {
    class A {
        static void Main() => CustomMain();

        static void Solve() {
            var a = ReadIntArray();
            Array.Sort(a);
            Array.Reverse(a);

            WriteAnswer(a[0] * 10 + a[1] + a[2]);
        }

        static void CustomMain() {
#if DEBUG
            // ファイルからテストケースを読み込む
            global::Common.ChangeStdIn();
            // 時間計測
            var stopwatch = new Stopwatch();
            stopwatch.Start();
#endif
            // 出力高速化
            var streamWriter = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            Console.SetOut(streamWriter);
            // 回答
            Solve();
#if DEBUG
            stopwatch.Stop();
            Console.WriteLine(stopwatch.Elapsed);
#endif
            Console.Out.Flush();
        }

        static string ReadString() => Console.ReadLine().Trim();
        static int ReadInt() => int.Parse(ReadString());
        static long ReadLong() => long.Parse(ReadString());
        static float ReadFloat() => float.Parse(ReadString());
        static double ReadDouble => double.Parse(ReadString());

        static string[] ReadStringArray() => ReadString().Split(' ');
        static int[] ReadIntArray() => Array.ConvertAll(ReadString().Split(' '), int.Parse);
        static long[] ReadLongArray() => Array.ConvertAll(ReadString().Split(' '), long.Parse);
        static float[] ReadFloatArray() => Array.ConvertAll(ReadString().Split(' '), float.Parse);
        static double[] ReadDoubleArray() => Array.ConvertAll(ReadString().Split(' '), double.Parse);

        static T TypeConversion<T>(string s) {
            if (typeof(T) == typeof(int)) {
                return (T) Convert.ChangeType(int.Parse(s), typeof(T));
            } else if (typeof(T) == typeof(long)) {
                return (T) Convert.ChangeType(long.Parse(s), typeof(T));
            } else if (typeof(T) == typeof(double)) {
                return (T) Convert.ChangeType(double.Parse(s), typeof(T));
            } else {
                return (T) Convert.ChangeType(s, typeof(T));
            }
        }

        static void ReadMulti<T, U>(out T a, out U b) {
            var str = ReadStringArray();
            a = TypeConversion<T>(str[0]);
            b = TypeConversion<U>(str[1]);
        }

        static void ReadMulti<T, U, V>(out T a, out U b, out V c) {
            var str = ReadStringArray();
            a = TypeConversion<T>(str[0]);
            b = TypeConversion<U>(str[1]);
            c = TypeConversion<V>(str[2]);
        }

        static void WriteAnswer(object ans) => Console.WriteLine(ans);

        static bool IsOdd(long num) {
            return (num & 1) == 1;
        }

        static bool IsEven(long num) {
            return (num & 1) == 0;
        }
    }
}

Measured memory_bytes: 11220
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include<bitset>

using namespace std;
#define modd 1000000007


typedef pair<long long, long long> pl;



#define ll long long




/*
class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;
	vector <ll> gr;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) ,gr(sz_){
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};*/


long long N, M, K, a, b, c, d, e, H, W, L;
long long A[200005] = {};
long long B[500][500] = {};
long long C[205][205] = {};
long long D[200005] = {};
long long E[200005] = {};
bool f, ff;
string S[2];
set <long long>sll;
pl bufpl;
vector <long long>vl;
vector <pl>vpl;
vector <string> vs;
set<ll> llset;

/*struct ST
{
	long long Kati;
	int bangou;

	bool operator<(const ST& another) const
	{
		return Kati < another.Kati;//比較
	};

};



vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}


bool fs[2005][2005] = {};

int main() {


	cin >> S[0]>>S[1];

	if (S[0] < S[1]) {
		cout << '<' << endl;
	}
	else if(S[0]>S[1]){
		cout << '>' << endl;
	}
	else {
		cout << '=' << endl;
	}
	

	return 0;

}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define mod 1000000007
#define pii pair<int,int>
#define pll pair<long long,long long>
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define ll long long
#define lli long long int
#define vi vector<int>
#define vll vector<long long>
#define vp vector<pair<long long,long long>>
#define vpp vector<pair<pair<long long,long long>,long long>>
#define mp make_pair
typedef std::numeric_limits< double > dbl;
using namespace std;

const long MAX = 1e6+1;
long fact[MAX] = {0};

long factors(long n) 
{ 
    if (n == 1) 
        return 1; 
  
    long ans = 1; 
  
    // stores the smallest prime number 
    // that divides n 
    long dup = fact[n]; 
  
    // stores the count of number of times 
    // a prime number divides n. 
    long c = 1; 
  
    // reduces to the next number after prime 
    // factorization of n 
    long j = n / fact[n]; 
  
    // false when prime factorization is done 
    while (j != 1) { 
        // if the same prime number is dividing n, 
        // then we increase the count 
        if (fact[j] == dup) 
            c += 1; 
  
        /* if its a new prime factor that is factorizing n,  
           then we again set c=1 and change dup to the new  
           prime factor, and apply the formula explained  
           above. */
        else { 
            dup = fact[j]; 
            ans = ans * (c + 1); 
            c = 1; 
        } 
  
        // prime factorizes a number 
        j = j / fact[j]; 
    } 
  
    // for the last prime factor 
    ans = ans * (c + 1); 
  
    return ans; 
} 
int main()
{
	IOS;
	long n;
	cin>>n;
	fact[1] = 1;
	for(long i=2;i<MAX;i++)
	fact[i] = i;
	for(long i=4;i<MAX;i=i+2)
	fact[i] = 2;
	
	for(long i=2;i*i<MAX;i++)
	{
		if(fact[i]==i)
		{
			for(long j=i*i;j<MAX;j=j+i)
			{
				if(fact[j]==j)
				fact[j]=i;
			}
		}
	}
	
	long ans[MAX];
	ans[0]=0;
	for(long i=1;i<MAX;i++)
	{
		ans[i] = ans[i-1] + factors(i);
		
	}

	cout<<ans[n-1];
}

Measured memory_bytes: 19272
S = int(input())
p = 10**9 + 7

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 3* 10 ** 4   # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

part = 1
ans = 0
while S >= 3*part:
  ans += cmb(S-3*part+part-1, part-1, p)
  part += 1
  
print(ans % p)
  
  

Measured memory_bytes: 71168
# スペース区切りの整数の入力
input_val = input()

five_count = 0
seven_count = 0
for x in input_val:
    if x == '5':
        five_count += 1
        continue
    if x == '7':
        seven_count += 1

if five_count == 2 and seven_count == 1:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 2940
#include<stdio.h>
int main()
{
    long long int num, i, sum = 0;
    scanf("%lld", &num);

    for(i=1; i<=num; i++)
    {
        if(i % 5 == 0 && i%3 == 0)
        {
            continue;
        }
        else if(i % 5 == 0)
        {
            continue;
        }
        else if(i % 3 == 0)
        {
            continue;
        }
        else
        {
            sum = sum + i;
        }
    }

    printf("%lld", sum);

    return 0;
}


Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
const int maxm=2e5+5;
int a[maxm];
int b[maxm];
int c[maxm];
int d[maxm];
int n;
int ask(int left,int right){//计算d数组中left<=x<right的x的数量
    int st=0,ed=0;
    int l=1,r=n;
    while(l<=r){//st尽量向左扩展
        int mid=(l+r)/2;
        if(d[mid]>=left){
            st=mid;
            r=mid-1;
        }else{
            l=mid+1;
        }
    }
    l=1,r=n;
    while(l<=r){//ed尽量向右扩展
        int mid=(l+r)/2;
        if(d[mid]<right){
            ed=mid;
            l=mid+1;
        }else{
            r=mid-1;
        }
    }
    if(!st||!ed)return 0;//如果不能同时满足x>=left且x<right,则无解
    return ed-st+1;
}
signed main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        cin>>b[i];
    }
    int ans=0;
    for(int i=0;i<30;i++){
        int t=(1<<i);
        for(int j=1;j<=n;j++){
            c[j]=a[j]%(t*2);
            d[j]=b[j]%(t*2);
        }
        sort(c+1,c+1+n);
        sort(d+1,d+1+n);
        int cnt=0;
        for(int j=1;j<=n;j++){//枚举c
            cnt+=ask(t-c[j],t*2-c[j]);
            cnt+=ask(t*3-c[j],t*4-c[j]);
            cnt%=2;
        }
        if(cnt){
            ans+=(1<<i);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int A,B,C,X;
    cin>>A>>B>>C>>X;

    int ans=0;
    REP(i,A+1) REP(j,B+1) REP(k,C+1){
        if(500*i+100*j+50*k==X) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
from sys import setrecursionlimit
setrecursionlimit(10 ** 6)

*I, = open(0).read().split()
N, A, B, C = map(int, I[:4])
S = I[4:]

Cnt = {"A": A, "B": B, "C": C}

ans = [""] * N
def dfs(i):
    if i == N:
        print("Yes")
        print("\n".join(ans))
        quit()

    for L, R in (S[i], reversed(S[i])):
        if Cnt[R] > 0:
            Cnt[L] += 1
            Cnt[R] -= 1

            ans[i] = L
            dfs(i + 1)

            Cnt[L] -= 1
            Cnt[R] += 1


dfs(0)
print("No")

Measured memory_bytes: 115820
#include<stdio.h>

int main(void){

int x;

scanf("%d",&x);

if(400<=x&&x<=599){printf("8");}
if(600<=x&&x<=799){printf("7");}
if(800<=x&&x<=999){printf("6");}
if(1000<=x&&x<=1199){printf("5");}
if(1200<=x&&x<=1399){printf("4");}
if(1400<=x&&x<=1599){printf("3");}
if(1600<=x&&x<=1799){printf("2");}
if(1800<=x&&x<=1999){printf("1");}

return 0;
}


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

int main() {
  string S,T;
  int i = 0;
  cin >> S >> T;
  for(int j = 0; j < 3; j++){
    if(S.at(j) == T.at(j))
      i++;
  }
  cout << i;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
			int X = 0;
			int C = 0;
		int A = sc.nextInt();
		for(int i = 0; i < A; i++){
			int B = sc.nextInt();
			if(i == 0){
				C = B;
			}
			if(C <= B){
				X += 1;
				C = B;
			}
		}
		System.out.println(X);
	}
}	
		

Measured memory_bytes: 23252
/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
# define ll long long
# define int long long  //comment it out when MLE
//# define endl "\n"
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//# define m 163577857
//# define MOD 163577857
# define pi acos(-1)
# define fi first
# define se second
#define REP(i,n) for (int i = 1; i <= n; i++)
const ll mod = 998244353;
const int K = 2;
//typedef vector<vector<int> > matrix;
/*
int add(int a, int b,int mod) {
    a%=mod;
    b%=mod;
	a += b;
	if (a >= mod) a -= mod;
	if(a<0)
    {
        a += mod;
        a %= mod;
    }
	return a;
}

int mul(ll a, int b,int mod) {
    a%=mod;
    b%=mod;
	a *= b;
	a += mod;
	return a % mod;
}
int po(int a,int b,int mod)
{
    if(b==0)
        return 1;
    if(b%2==0)
        return po(mul(a,a,mod),b/2,mod);
    return mul(a,po(mul(a,a,mod),(b-1)/2,mod),mod);
}


ll fact[1000003];
ll inv[1000003];

void fact0()
{
	int i,j;
	fact[0]=1;
	for(i=1;i<=200000;i++)
	{
		fact[i]=i*fact[i-1]%mod;
	}
	inv[0]=1;
	inv[1]=1;
	ll p=mod;
	for (i=2; i<=200000; i++)
		inv[i] = (p - (p/i) * inv[p%i] % p) % p;

	for(i=2;i<=200000;i++)
	{
		inv[i]*=inv[i-1];
		inv[i]%=mod;
	}
}*/

signed main(){
   gok


 int n;
 cin>>n;
 map<int,int> mp;
 for(int i=2;i*i<=n;i++)
 {
     if(n%i==0)
     {
        int c=0;
         while(n%i==0)
         {
             c++;
             n/=i;
         }
         mp[i]=c;
     }
 }
 if(n>1)
    mp[n]=1;
 int an=0;
 for(auto ii:mp)
 {
     int y = ii.se;
     if(y>0){
         int st=1,cc=0;
     while(y>0)
     {
         y-=st;
         if(y<0)
            break;
         cc++;
         st++;
     }
     an += cc;
     }
 }
cout<<an;













	return 0;
}


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

int X[1500001] = {} , Y[1500001] = {} ;

int main(){
	
	int w,h ;
	
	while( cin >> h >> w ){
		if( w==0 && h==0 ) break ;
		
		int ans = 0 ;
		int x[1501] = {} , y[1501] = {} ;
		for( int i=0 ; i<h ; i++ ) cin >> y[i] ;
		for( int i=0 ; i<w ; i++ ) cin >> x[i] ;
		
		for( int i=0 ; i<1500001 ; i++ ){
			X[i] = 0 ;
			Y[i] = 0 ;
		}
		
		for( int i=0 ; i<w ; i++ ){
			int sum = 0 ;
			for( int j=i ; j<w ; j++ ){
				sum += x[j] ;
				X[sum]++ ;
			}
		}
		for( int i=0 ; i<h ; i++ ){
			int sum = 0 ;
			for( int j=i ; j<h ; j++ ){
				sum += y[j] ;
				Y[sum]++ ;
			}
		}
		
		for( int i=0 ; i<1500001 ; i++ ){
			ans += X[i] * Y[i] ;
		}
		
		cout << ans << endl ;
	}
	
return 0;
}

Measured memory_bytes: 12888
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n = int(input())
    xx = LI()
    m = int(input())
    aa = LI()
    line = [0] * 2020
    pos = [-1] * (n + 1)
    for a, x in enumerate(xx, 1):
        line[x] = a
        pos[a] = x
    for a in aa:
        if pos[a]==2019 or line[pos[a] + 1] != 0: continue
        line[pos[a]] = 0
        line[pos[a] + 1] = a
        pos[a] += 1
    for x in pos[1:]:
        print(x)

main()



Measured memory_bytes: 5632
# move all A's to the back whenever you see ABC i.e it becomes BCA
# Example ABCBCBC after operation it becomes BCBCBCA
# Count the consecutive no of BC and whenever u see a A add the count to answer that many moves required to move A to last
# if it's not A or any other string make cnt as 0
def main():
	s = input()
	cnt = 0
	prev =0
	ans = 0
	i = len(s)-1
	while i>=0:
		if s[i]=='C' and s[i-1]=='B':
			cnt = cnt+1
			i = i-2
		else:
			if s[i]=='A':
				ans = ans+cnt
			else:
				cnt = 0
			i = i-1
	print(ans)
if __name__=="__main__":
	main()

Measured memory_bytes: 73288
#!/usr/bin/env python3
import sys


def solve(N: int):
    count = {}
    for i in range(1, N+1):
        p = get_pair(i)
        key = p[0] + '_' + p[1]
        if not count.get(key):
            count[key] = 0
        count[key] += 1
    ans = 0
    for i in range(1, N+1):
        p = get_pair(i)
        key = p[1] + '_' + p[0]
        if count.get(key):
            ans += count[key]
    # print(ans if ans > 0 else 1)
    print(ans)
    return


def get_pair(n: int):
    nf = str(n)[0]
    nl = str(n)[len(str(n)) - 1]
    return [nf, nl]


# 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)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


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

int MOD = 1e9+7;

int main(){
    int n;
    cin >> n;
    vector<int> v(n+1, 0);
    for(int i = 2; i <= n; i++){
        int m = i;
        for(int j = 2; j*j <= m; j++){
            int t = 0;
            while(m%j == 0){
                t++;
                m /= j;
            }
            v[j] += t;
        }
        v[m]++;
    }
    long long ans = 1;
    for(int i = 2; i <= n; i++) (ans *= v[i]+1) %= MOD;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 2e5 + 100;
typedef long long ll;
ll Mod = 1e9 + 7;
ll a[N], sum[N];
int n;

int main() {
	
	cin >> n;
	for(int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
	}
	for(int i = n; i >= 1; i--) {
		sum[i] = (sum[i+1] + a[i]) % Mod;
	}
	
	ll ans = 0;
	for(int i = 1; i <= n; i++) {
		ans = (a[i]*sum[i+1]%Mod + ans) % Mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6360
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 *
 * AND WATCH OUT FOR OFF BY ONE!!!
 */

#include <bits/stdc++.h>
const bool unsyncedio=std::ios::sync_with_stdio(false);
using namespace std;
typedef unsigned int uint;
typedef long long ll;

#define fori(n) for(ll i=0; i<(n); i++)
#define forn(i, n) for(ll (i)=0; (i)<(n); (i)++)

int main() {
int n, k;
    cin>>n>>k;
    
    double ans=0.0;
    for(int i=1; i<=n; i++) {
        /* add prob of winning if dice shows i. */
        double p=1.0;
        int x=i;
        while(x<k) {
            p/=2;
            x*=2;
        }
        ans+=p;
    }
    ans/=n;
    cout<<setprecision(12)<<ans<<endl;

}



Measured memory_bytes: 256
#include<stdio.h>
int n;
int a[11][11];

int temp;
int main(void) {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		temp = i;
		while (temp > 9)
			temp /= 10;
		a[temp][i % 10]++;
	}

	int ans = 0;
	for (int i = 0; i <= 9; i++)
		for (int j = 0; j <= 9; j++)
			ans += a[i][j] * a[j][i];
	printf("%d", ans);
	return 0;
}


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

long long  v[100002], n, g, w, p;

int main()
{
  cin >> n >> g;
  for(int i = 1; i <= n; i++){
    cin >> w >> p;
    for(int j = g; j >= w; j--) v[j] = max(v[j - w] + p, v[j]);
  }
  cout << v[g];
  return 0;
}


Measured memory_bytes: 1024
MOD=10**9+7
N=int(input())

mat=[]
for i in range(2):
  mat.append(list(input()))
#print(mat)

dp=[1]+[0]*N
i=1
while i<N+1:
  if mat[0][i-1]==mat[1][i-1]:
    if i==1:
      dp[1]=3
    else:
      if mat[0][i-2]==mat[1][i-2]:
        dp[i]=2*dp[i-1]
        dp[i]%=MOD
      else:
        dp[i]=dp[i-1]
  else:
    if i==1:
      dp[1]=dp[2]=6
      i+=1
    else:
      if mat[0][i-2]==mat[1][i-2]:
        dp[i]=dp[i+1]=2*dp[i-1]
        dp[i]%=MOD
        dp[i+1]%=MOD
        i+=1
      else:
        dp[i]=dp[i+1]=3*dp[i-1]
        dp[i]%=MOD
        dp[i+1]%=MOD
        i+=1
  i+=1
        
#print(dp)
print(dp[-1])

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cstdio>

using namespace std;

#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)

class Point{
public:
  double x,y;
  
  Point(double x = 0, double y = 0): x(x),y(y){};
  
  Point operator + (Point p) {return Point(x+p.x,y+p.y);}
  Point operator - (Point p) {return Point(x-p.x,y-p.y);}
  Point operator * (double a) {return Point(a*x,a*y);}

  double own_dot(){return x*x+y*y;};
  double abs(){return sqrt(own_dot());}

  bool operator < (const Point &p) const {
    return x != p.x ? x < p.x : y < p.y;
  }
  bool operator == (const Point &p) const{
    return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
  }
};

struct Segment{Point p1,p2;};

double dot(Point a, Point b){
  return a.x*b.x+a.y*b.y;
}

//線分sに対する点pの射影
Point project(Segment s, Point p){
  Point base = s.p2 - s.p1;
  double t = dot(p-s.p1,base)/base.own_dot();
  return s.p1 + base*t;
}

//線分sを対象軸とした点pの線対称の点xを求める
Point reflect(Segment s, Point p){
  return p+(project(s,p)-p)*2.0;
}

Point in[3];
int main(){
  while(1){
    char c;

    for(int i = 0; i < 3; i++)
      if(i == 2) cin >> in[i].x >> c >> in[i].y;
      else if(!(cin >> in[i].x >> c >> in[i].y >> c)) return 0;

    Segment s;
    s.p1 = in[0];
    s.p2 = in[1];
    Point ans = reflect(s,in[2]);
    
    printf("%.6f %.6f\n",ans.x, ans.y);
  }
  return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long A, B, C; cin >> A >> B >> C;
  if(A%2==0 || B%2==0 || C%2==0){
    cout << 0 << endl;
  }
  else cout << min({A*B,B*C,C*A}) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
using namespace std;
int main(){
    //Seiranchan!
     string S;
     cin >> S;
    int ans=S.size()-2;

    cout << S[0] << ans << S[S.size()-1] << endl;
}


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

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

    char y[4 + 1] = {};
    ymd.copy(y,4);
    if(stoi(y) > 2019) {cout << "TBD" << endl; return 0;}
    if(stoi(y) < 2019) {cout << "Heisei" << endl; return 0;}

    char m[2 + 1] = {};
    ymd.copy(m,2,5);
    if(stoi(m) > 4) {cout << "TBD" << endl; return 0;}
    if(stoi(m) < 4) {cout << "Heisei" << endl; return 0;}

    char d[2 + 1] = {};
    ymd.copy(m,2,8);
    if(stoi(m) > 30) {cout << "TBD" << endl; return 0;}
    cout << "Heisei" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
  int x,a,b,i,j;
  int d[150];
  a,b = 0;
  scanf("%d", &x);
  d[0] = 0;
  for(i=1;i<150;i++){
    d[i] = i*i*i*i*i;
  }
  for(i=0;i<150;i++){
    for(j=0;j<150;j++){
      if(d[i] - d[j] == x){
        a = i;
        b = j;
        break;
      }else if(d[i] + d[j] == x){
        a = i;
        b = - j;
        break;
      }
    }
    if(a != 0 || b != 0)
      break;
  }
  printf("%d %d", a, b);
  return 0;
}

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

using lli = long long int;

using namespace std;

int main() {
    std::string S;
    cin >> S;

    const auto num_red = std::count(S.cbegin(), S.cend(), '0');
    const auto num_blue = S.size() - num_red;
    const auto ans = std::min<lli>(num_red, num_blue) * 2;

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 512