akhauriyash/Code-Regression huggingface dataset:
from bisect import *
S = input()
mod = 10**9 + 7
A = []
B = []
C = []
X = []
q = 0
for i,s in enumerate(S):
    if s == 'A':
        A.append(i)
    elif s == 'B':
        B.append((i,0))
    elif s == 'C':
        C.append(i)
    else:
        X.append(i)
        B.append((i,1))
        q += 1

pow3 = [pow(3,q,mod),pow(3,max(0,q-1),mod),pow(3,max(0,q-2),mod),pow(3,max(0,q-3),mod)]
ans = 0
for b,flag in B:
    Al = bisect_left(A,b)
    Cr = (len(C) - bisect_right(C,b))
    Xl = bisect_left(X,b)
    Xr = (len(X) - bisect_right(X,b))
    ans += (Al*Cr%mod)*pow3[flag]%mod
    ans %= mod
    ans += (Al*Xr%mod + Xl*Cr%mod)*pow3[flag+1]%mod
    ans %= mod
    ans += (Xl*Xr%mod)*pow3[flag+2]%mod
print(ans)


Measured memory_bytes: 53212
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <bitset>
#include <cmath>

using namespace std;
using ll = long long;
// const ll mod =  998244353 ;
const ll mod =  1000000007 ;
const ll inf = 9;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())

template<typename T> void print_vec(vector<T> a) {int n = a.size();REP(i, n) {cout >> a[i]; if(i!=n-1) cout << " "; else cout << endl;}}
ll power(ll base, ll exponent){ if(exponent % 2){ return power(base, exponent - 1) * base % mod; }else if(exponent){ ll root_ans = power(base, exponent / 2); return root_ans * root_ans % mod; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
template<typename T> ll sum(T begin, T end) {return accumulate(begin, end, 0ll);}
template<typename T, typename F> ll sum(T begin, T end, F func) {return accumulate(begin, end, 0ll, func);}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

using Pair = pair<ll, ll>;

signed main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> l(n);
  REP(i, n) cin >> l[i];
  sort(all(l));
  ll ans = 0;
  REP(i, n) {
    REP_FROM(j, i+1, n) {
      auto lower = upper_bound(all(l), l[j] - l[i]);
      auto upper = lower_bound(all(l), l[j] + l[i]);
      ans += upper - lower;
      if(lower - l.begin() <= i && i < upper - l.begin()) ans--;
      if(lower - l.begin() <= j && j < upper - l.begin()) ans--;
      // cout << i << ":" << j << " " << lower - l.begin() << ":" << upper - l.begin() << endl;
      // cout << ans << endl;
    }
  }
  cout << ans / 3 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
const int N = 600+5;
//dp[u]: expected number need to be done, but not have been done
//for every edge from u->v, it is garantee that v>u
struct Edge{
    int v;
    int next;
};
int head[N]; Edge e[N*N]; int id = 0;
//f[i][j]: E[i] block edge start from j
double f[N][N];

double min(double a,double b){ return a>b?b:a; }

double max(double a,double b){ return a>b?a:b; }

void addEdge(int u,int v){
    id++;
    e[id].v = v; e[id].next = head[u];
    head[u] = id;
}

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i = 0; i < m; i++){
        int u,v;
        scanf("%d%d",&u,&v);
        addEdge(u,v);
    }
    f[n][0] = 0;
    for(int u = n-1; u >= 1; u--){
        int cnt = 0;
        double maxf = 0;
        double sum = 0;
        for(int i = head[u]; i; i = e[i].next){
            cnt++;
            int v = e[i].v;
            sum += f[v][0];
            maxf = max(maxf,f[v][0]);
            for(int j = u+1; j <= n; j++){
                if(j>=v) f[u][j] += f[v][j];
                else f[u][j] += f[v][0];
            }
        }
        f[u][0] = sum/(double)cnt + 1.0;
        f[u][u] = f[u][0];
        if(cnt>1) f[u][u] = min(f[u][u],(sum-maxf)/(double)(cnt-1)+1.0);
        for(int i = u+1; i <= n; i++) f[u][i] = f[u][i]/(double)cnt + 1.0;
    }
    double ans = f[1][0];
    for(int i = 1; i <= n; i++) ans = min(ans,f[1][i]);
    printf("%.9f\n",ans);
    return 0;
}


Measured memory_bytes: 4480
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstring>
#include <complex>
#include <queue>
#include <stack>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
  int n;
  string a,b,c;
  cin>>n>>a>>b>>c;
  int ans=0;
  rep(i,n){
    if(a[i]==b[i]&&b[i]==c[i]);
    else if(a[i]==b[i]||b[i]==c[i]||c[i]==a[i])ans++;
    else ans+=2;
  }
  cout<<ans<<endl;
}
	    


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>
#include <queue>
#include <stack>
#include <deque>
#include <cmath>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

template<typename Monoid>
struct SegmentTree {
    using T = typename Monoid::T;
    const size_t n;
    vector<T> t;

    void prop_to(std::size_t i) { t[i] = Monoid::op(t[i << 1], t[i << 1 | 1]); }

    SegmentTree(size_t n, const T& v = Monoid::identity()) : n(n), t(n << 1, v) {}
    template <class InputIt>
    SegmentTree(InputIt first, InputIt last) : n(distance(first, last)), t(n << 1, Monoid::identity()) {
        copy(first, last, begin(t) + n);
        for (size_t i = n; i > 0; i--) prop_to(i);
    }
    
    void update(size_t i, const T& v) {
        t[i += n] = v;
        while (i >>= 1) prop_to(i);
    }
    T query(size_t l, size_t r) {
        T res = Monoid::identity();
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) res = Monoid::op(res, t[l++]);
            if (r & 1) res = Monoid::op(res, t[--r]);
        }
        return res;
    }
    T get(size_t i) { return t[i + n]; }
};

struct RMQ {
    using T = int;
    static T op(T a, T b) { return min(a, b); }
    static constexpr T identity() { return (1LL << 31) - 1; }
};

signed main() {
    int n, q;
    cin >> n >> q;
    SegmentTree<RMQ> seg(n);
    while (q--) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com) cout << seg.query(x, y + 1) << endl;
        else seg.update(x, y);
    }
    return 0;
}



Measured memory_bytes: 4400
// 自分でoperator実装するバージョン

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

class Point {
   private:
    int x, y;

   public:
    Point() {
        x = 0;
        y = 0;
    }
    Point(int x, int y) {
        this->x = x;
        this->y = y;
    }
    int getX() { return x; }
    int getY() { return y; }

    // 比較演算子のオーバーロード
    // 矛盾しないように'>'を定義したら'<='も定義する
    bool operator<(const Point& rhs) const;
    bool operator>=(const Point& rhs) const;
};

// メンバ演算子関数
bool Point::operator<(const Point& rhs) const {
    if (x < rhs.x) {
        return true;
    }
    if (x > rhs.x) {
        return false;
    }
    return y < rhs.y;
}
bool Point::operator>=(const Point& rhs) const {
    if (x >= rhs.x) {
        return true;
    }
    if (x < rhs.x) {
        return false;
    }
    return y >= rhs.y;
}

int main() {
    vector<Point> v;
    int n;

    cin >> n;
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        Point p(x, y);
        v.push_back(p);
    }

    // TODO:vをソートする
    sort(v.begin(), v.end());

    for (int i = 0; i < n; ++i) {
        cout << v[i].getX() << ' ' << v[i].getY() << endl;
    }
    return 0;
}


Measured memory_bytes: 3876
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		try (Scanner sc = new Scanner(System.in);) {
			int n = Integer.parseInt(sc.nextLine());
			String a = sc.nextLine();
			String[] b = a.split(" ");
			List<Integer> list = new ArrayList<>();

			for (int i = 0; i < b.length; i++) {
				list.add(Integer.parseInt(b[i]));
			}

			Collections.sort(list);

			System.out.println(list.get(list.size() - 1) - list.get(0));
		}
	}
}


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

int main(){
    int N, M, tmpa, tmpb;
    cin >> N >> M;
    
    vector<pair<long, long>> stu(N);
    vector<pair<long, long>> cp(M);
    for(int i=0; i<N; i++) {
        cin >> tmpa >> tmpb;
        stu[i] = make_pair(tmpa, tmpb);
    }
    for(int i=0; i<M; i++) {
        cin >> tmpa >> tmpb;
        cp[i] = make_pair(tmpa, tmpb);
    }

    long tmp;
    long res = 999999999999999999L;
    int resp = -1;
    for(int i=0; i<N; i++){
        res = 999999999999999999L;
        resp = -1;
        for(int j=0; j<M; j++){
            tmp =  abs(stu[i].first - cp[j].first) + abs(stu[i].second - cp[j].second);
            if(tmp < res) {
                res = tmp;
                resp = j+1;
            }
        }
        cout << resp << endl;
    }

}



Measured memory_bytes: 888
#include<cstdio>
using namespace std;
int n,a[10005],b[10005];
long long sum1,sum2,delta,qwq;
int main()
{
  scanf("%d",&n);
  for(int i=1;i<=n;i++) 
    scanf("%d",&a[i]),sum1+=a[i];
  for(int i=1;i<=n;i++) 
    scanf("%d",&b[i]),sum2+=b[i];
  if(sum1>sum2)  {printf("No");return 0;}
  delta=sum2-sum1;
  for(int i=1;i<=n;i++)
    if(b[i]>a[i])
      qwq+=(b[i]+1-a[i])/2;
  if(qwq>delta)  printf("No");
  else  printf("Yes");
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define mod 1000000007
#define FASTIO ios::sync_with_stdio(0); cin.tie(0);
#define REP(i,a,b) for(int i=a;i<b;i++)
#define maxx 100005
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

int main() {
    FASTIO
    int x;
    cin>>x;
    cout<<(x^1)<<endl;
    return 0;
}


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

int main(){
  string s;
  cin >> s;
  
  int max_val = 0;
  
  for(int i=0; i<s.size() ; i++){
    int count = 0;
    for(int j=i ; j<s.size(); j++){
      if(s[j] == 'A' || s[j] == 'C' || s[j] == 'G' || s[j] == 'T') count++;
      else break;
    }
    max_val = max(max_val, count);
  }
  cout << max_val << endl;
}

  

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int N,T,A;
  double tmp[1000];
  int H[1000];
  scanf("%d %d %d",&N,&T,&A);
  for(int i=0;i<N;i++){
    scanf("%d",&H[i]);
  }
  for(int i=0;i<N;i++){
    tmp[i]=T-H[i]*0.006;
  }
  double min=987654321;
  int cnt=-1;
  for(int i=0;i<N;i++){
    if(min>(tmp[i]-A>0?tmp[i]-A:A-tmp[i])){
      min=(tmp[i]-A>0?tmp[i]-A:A-tmp[i]);
      cnt=i;
    }
  }
  printf("%d",cnt+1);
}


Measured memory_bytes: 128
from collections import deque

if __name__ == '__main__':
    x = [(int)(x) if x.isdigit() else x for x in input().split()]
    
    y = deque()

    for tmp in x:
        if tmp == '+':
            a = y.pop()
            b = y.pop()
            y.append(a+b)
        elif tmp == '-':
            a = y.pop()
            b = y.pop()
            y.append(b-a)
        elif tmp == '*':
            a = y.pop()
            b = y.pop()
            y.append(a*b)
        else:
            y.append(tmp)

    print(y.pop())

Measured memory_bytes: 8092
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
#include<cstring>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <memory>
#include <numeric>
#include <type_traits>

using namespace std;

#define rep(i,n) for (int (i)=0;(i)<(n);i++)
typedef long long ll;
const int MAXV = 1e6;


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

Measured memory_bytes: 3520
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

typedef tuple<ll, ll, ll> T;

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,h;
    cin>>a>>b>>h;
    cout<<((a+b)*h)/2<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inf (int)(1e9)

signed main(){
	int N, K, RSP[3], i, j, k, l, ans = 0;
	scanf("%lld%lld", &N, &K);
	scanf("%lld%lld%lld", &RSP[0], &RSP[1], &RSP[2]);
	string T;
	cin >> T;
	vector<int> Tint(N);
	for(i = 0; i < N; i++){
		if(T[i] == 'r'){
			Tint[i] = 0;
		}
		if(T[i] == 's'){
			Tint[i] = 1;
		}
		if(T[i] == 'p'){
			Tint[i] = 2;
		}
	}
	for(i = 0; i < K; i++){
//		printf("i = %lld\n", i);
		int v[3] = {0, 0, 0};
		v[(Tint[i] + 2) % 3] = RSP[(Tint[i] + 2) % 3];
		int oldv[3];
		for(k = 0; k < 3; k++){
			oldv[k] = v[k];
		}
//		printf("(%lld, %lld, %lld)\n", v[0], v[1], v[2]);
		for(j = 1; i + K * j < N; j++){
//			printf("j = %lld\n", j);
			for(k = 0; k < 3; k++){
				v[k] = -inf;
				for(l = 0; l < 3; l++){
//					printf("(k, l) = (%lld, %lld)\n", k, l);
					if(k != l){
//						printf("oldv[l] = %lld\n", oldv[l]);
//						printf("Tint[i + K * j] = %lld\n", Tint[i + K * j]);
						v[k] = max(v[k], oldv[l] + ((k + 1) % 3 == Tint[i + K * j] ? RSP[k] : 0));
					}
//					printf("v[k] = %lld\n", v[k]);
				}
			}
			for(k = 0; k < 3; k++){
				oldv[k] = v[k];
			}
//			printf("(%lld, %lld, %lld)\n", v[0], v[1], v[2]);
		}
		ans += max(v[0], max(v[1], v[2]));
//		printf("ans[%lld] = %lld\n", i, ans);
	}
	printf("%lld\n", ans);
	return 0;
}

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

int main() {
  int N; cin >> N;
  int exists = 0;
  for (int i = 0; i <= 100; i += 4) {
    for (int j = 0; j <= 100; j += 7) {
      if (i + j == N) {
        exists = 1;
      }
    }
  }
  if (exists == 1) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
N=input()
a=[]
Z=[]
for i in range(int(N)):
    A=input()
    Z.append(A)
    a.append(A[0])
    a.append(A[-1])

del a[-1],a[0]

if len(Z) != len(set(Z)):
    print("No")
elif a[0::2] != a[1::2]:
    print("No")
elif a[0::2] == a[1::2]:
    print("Yes")


Measured memory_bytes: 3064
use std::env;
use std::io::*;
use std::str::*;
use std::mem;
use std::collections::HashMap;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}
fn read_char() -> char {
    let c = read::<String>();
    let c = c.chars().collect::<Vec<char>>();
    c[0]
}
fn read_String_Vec() -> Vec<char> {
    let S = read::<String>();
    S.chars().collect::<Vec<char>>()
}

fn vecchar_to_String(Vs: Vec<char>) -> String {
    let mut S = String::new();
    for i in 0..Vs.len() {
        S.push(Vs[i]);
    }
    S
}

/*
A : 65
Z : 90
a : 97
z : 122
*/

/*
let N = read::<i32>();
let S = read::<String>();
let S = read_String_Vec();
let C = read_char();
*/

/*
 .to_string() : * -> String
 &*S          : String -> &str
*/

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let mut matrix = Vec::new();
    let H = read::<i32>();
    let W = read::<i32>();
    for n in 0..H {
        let S = read::<String>();
        matrix.push(S.clone());
        matrix.push(S);
    }
    for n in 0..2*H {
        println!("{}", matrix[n as usize]);
    }


}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a;
  cin>>a;
  if(a==25){
    cout<<"Christmas\n";
  }else if(a==24){
    cout<<"Christmas Eve\n";
  }else if(a==23){
    cout<<"Christmas Eve Eve\n";
  }else if(a==22){
    cout<<"Christmas Eve Eve Eve\n";
  }
}


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

using namespace std;

int main() {
    int N, L;

    cin >> N >> L;

    int sum = 0;
    int min_diff = 9999999;
    int min_val = 999999;

    for(int i = 0; i < N; i++) {
        sum += L + i;
        if(abs(L+i) <= min_diff) {
            min_diff = abs(L + i);
            min_val = L + i;
        }
        
    }

    cout << sum - (min_val)<< endl;
}

Measured memory_bytes: 256
N=int(input())
s=[]
for k in range(N):
    s.append([None]*10)
    l=input()
    for j in range(10):
        s[k][j]=l[j]
    s[k].sort()
s.sort()
a=0
r=0
for i in range(N-1):
    if s[i]==s[i+1]:
        r+=1
    elif r!=0:
        a+=r*(r+1)//2
        r=0
a+=r*(r+1)//2
print(a)

Measured memory_bytes: 102360
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100005
#define maxn 	  200005
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int cost[maxn];
int dp[maxn];
int main()
{
	int n;
	cin >> n;
	int k;
	cin >> k;
	for (int i=0 ; i<n ; i++) cin >> cost[i];
	//memset(dp,INT_MAX,sizeof(dp));
	for (int i=1 ; i<=n ; i++)
	dp[i] = INT_MAX;
	dp[0] = 0;
	for (int i=0 ; i<n ; i++)
	{
		for (int j=i+1 ; j<= i+k ; j++)
		{
			if(j<n)
			{
				dp[j] = min(dp[j] , dp[i] + abs(cost[j] - cost[i]));
			}
		}
	}
	cout << dp[n-1] << endl;
	return 0;
}


Measured memory_bytes: 4420
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;

int main() {
  int a,b,c,d,e,k;
  cin>>a>>b>>c>>d>>e>>k;
  if(e-a<=k) cout<<"Yay!"<<endl;
  else cout<<":("<<endl;
  return 0;
}


Measured memory_bytes: 764
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int64, int64> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

const int N = 1 << 17;
vector<ii> a[N];
vector<ii> dp[N];

bool DFS(int u, int parent, int64 bound) {
  vector<ii> child;
  for (auto& it : a[u]) {
    int v = it.first;
    if (v == parent) continue;
    if (!DFS(v, u, bound)) return false;
    child.push_back(it);
  }
  dp[u].clear();
  if (child.empty()) {
    dp[u] = {{0, 0}};
  } else {
    assert(child.size() == 2);
    int x = child[0].first, y = child[1].first;
    int64 upx = child[0].second, upy = child[1].second;
    if (dp[x].size() > dp[y].size()) {
      swap(x, y);
      swap(upx, upy);
    }
    for (auto& it : dp[x]) {
      auto pos = lower_bound(dp[y].begin(), dp[y].end(),
                             ii{bound - (it.second + upx + upy) + 1, 0});
      if (pos == dp[y].begin()) continue;
      pos = prev(pos);
      dp[u].push_back({it.first + upx, pos->second + upy});
      dp[u].push_back({pos->second + upy, it.first + upx});
    }
    sort(dp[u].begin(), dp[u].end());
    vector<ii> A;
    for (auto& it : dp[u]) {
      if (A.empty() || A.back().second > it.second) {
        A.push_back(it);
      }
    }
    dp[u] = move(A);
    if (dp[u].empty()) return false;
  }
  // cout << "dp " << u << endl;
  // for (auto& it : dp[u]) {
  //   cout << it.first << " " << it.second << endl;
  // }
  return true;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int x, y;
    int64 z;
    x = i;
    scanf("%d%lld", &y, &z);
    --y;
    a[x].push_back({y, z});
    a[y].push_back({x, z});
  }
  int64 low = 0, high = 1LL << 34;
  while (low != high) {
    int64 mid = (low + high) / 2;
    // cout << "-----" << mid << "-----" << endl;
    if (DFS(0, -1, mid)) {
      high = mid;
    } else {
      low = mid + 1;
    }
  }
  printf("%lld\n", high);
  return 0;
}


Measured memory_bytes: 37952
def dist(a,b):
    return min(abs(a-b),24-abs(a-b))
from itertools import groupby, accumulate, product, permutations, combinations
from copy import copy
def solve():
    N = int(input())
    D = list(map(int, input().split()))
    c = [0]*13
    for i in range(N):
        c[D[i]]+=1
    choices = []
    dicided = [0]
    if c[12]>1:
        return 0
    if c[12]==1:
        dicided.append(12)
    if c[0]>0:
        return 0
    for i in range(1,12):
        if c[i]>2:
            return 0
        if c[i]==1:
            choices.append([i,24-i])
        if c[i]==2:
            dicided.append(i)
            dicided.append(24-i)
    ans = 0
    for p in product([0,1],repeat=len(choices)):
        lis = copy(dicided)
        for i in range(len(choices)):
            lis.append(choices[i][p[i]])
        m = 24
        for i in range(len(lis)):
            for j in range(len(lis)):
                if i!=j:
                    m = min(m,dist(lis[i],lis[j]))
        ans = max(ans,m)
    return ans
print(solve())

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


class Prime():
    def __init__(self, n):
        self.M = m = int(math.sqrt(n)) + 10
        self.A = a = [True] * m
        a[0] = a[1] = False
        self.T = t = []
        for i in range(2, int(math.sqrt(m)) + 1):
            if not a[i]:
                continue
            t.append(i)
            for j in range(i*i,m,i):
                a[j] = False

    def is_prime(self, n):
        return self.A[n]

def main():
    rr = []

    pr = Prime(10**11)

    while True:
        n,p = LI()
        if n < 0 and p < 0:
            break
        t = []
        i = n
        while len(t) < p:
            i += 1
            if pr.is_prime(i):
                t.append(i)

        u = []
        for i in range(p):
            for j in range(i,p):
                u.append(t[i]+t[j])
        u.sort()
        rr.append(u[p-1])

    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 11532
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rush() int T;scanf("%d",&T);while(T--)
#define mm(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define pf(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define p_f(a) printf("%d ",a)
#define pyn(a) if(a)puts("Yes");else puts("No");
#define fi first
#define se second
#define db double
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const db eps=1e-9;
int n;
ll sum;
int main()
{
    sc(n);
    sum+=n/500*1000;
    sum+=(n%500)/5*5;
    pf(sum);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int A,B,T;
    cin >> A >> B >>T;
    cout << (T/A)*B << endl;



}


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

using namespace std;

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    int n, x, t;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    int maxi = 0;
    long long ans = 0;
    for(int i = 0; i < n; i++){
        ans += max(maxi - v[i], 0);
        maxi = max(v[i], maxi);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3972
#include<bits/stdc++.h>
using namespace std;
#define int long
using pi=pair<int,int>;
signed main(){
    int n;
    cin>>n;
    map<string,int> m;
    while(n--){
        string s;
        cin>>s;
        ++m[s];
    }
    cout << m.size();
}

Measured memory_bytes: 19260
#include <iostream>
#include <array>
#include <iterator>

int main(){
	int length,width;

	while(std::cin >> width >> length){
		std::array<int, 256> crossing = {0}; //16*16
		
		if(width == 0 && length == 0) break;

		int construction;
		std::cin >> construction;

		for(int i = 0; i < construction; ++i){
			int con_length, con_width;
			std::cin >> con_width >> con_length;
			crossing[con_width + (width * (con_length - 1)) - 1] = -1; //construction = -1
		}

		crossing[0] = 1; //start
		
		int cros_num = 0;
		for(auto itr = crossing.begin(); itr != crossing.end(); ++itr){

			if(*itr != -1){ //not crossing

				//considering left crossing
				if(cros_num % width != 0){ //no left
					--itr;
					if(*itr != -1){ //left not construction
						int buf = *itr;
						++itr;
						*itr += buf; //plus left
					}else{
						++itr;
					}
				}
				//considering down crossing
				if(cros_num >= width){ //no down
					itr -= width;
					if(*itr != -1){ //down not construction
						int buf = *itr;
						itr += width;
						*itr += buf; //plus down
					}else{
						itr += width;
					}
				}
			
			}
			++cros_num;
			
			if(cros_num == length * width){
				std::cout << *itr << std::endl;	
				break;
			}
		}

	}
	return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> G(N);
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    --A;
    --B;
    G[A].push_back(B);
    G[B].push_back(A);
  }
  vector<bool> used(N);
  deque<int> path;
  path.push_back(0);
  path.push_back(G[0][0]);
  used[0] = true;
  used[G[0][0]] = true;
  for (;;) {
    int s = path.front();
    int ss = -1;
    for (int v: G[s]) {
      if (!used[v]) {
        ss = v;
        break;
      }
    }
    if (ss == -1) {
      break;
    }
    path.push_front(ss);
    used[ss] = true;
  }
  for (;;) {
    int t = path.back();
    int tt = -1;
    for (int v: G[t]) {
      if (!used[v]) {
        tt = v;
        break;
      }
    }
    if (tt == -1) {
      break;
    }
    path.push_back(tt);
    used[tt] = true;
  }
  cout << path.size() << endl;
  for (auto v: path) {
    cout << (v + 1) << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 6656
import java.util.Scanner;

public class Main {

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

    char[] array = S.toCharArray();
    System.out.println(resolve(array));
  }

  private static String resolve(char[] array) {
    StringBuilder sb = new StringBuilder();
    for (char c : array) {
      if (c != 'B') {
        sb.append(c);
      } else if (sb.length() != 0) {
        sb.deleteCharAt(sb.length() - 1);
      }
    }

    return sb.toString();
  }
}


Measured memory_bytes: 26924
#include <stdio.h>


int main()
{
    int i,j,k,n,m,p;
    char buf[10];
    fgets(buf,sizeof(buf),stdin);
    sscanf(buf,"%d",&n);
    for (i=0;i<n;i++){
        scanf("%d",&p);
        //printf("%d",p);
        int *ones;
        scanf("%d",&m);
        //printf("%d",m);
        ones = malloc(m*sizeof(int));
        for (j=0;j<m;j++){
            scanf("%d",&k);
            //printf("%d",k);
            ones[j] = (k-1);
        }
        //printf("%d",ones[0]);
        for (j=0;j<n;j++){
            int inside = 0;
            if (j==(n-1)){
                for (k=0;k<m;k++){
                    if (j==ones[k]) inside = 1;
                }
                if (inside==1) printf("1\n");
                else printf("0\n");
            }
            else{
                for (k=0;k<m;k++){
                    if (j==ones[k]) inside = 1;
                }
                if (inside==1) printf("1 ");
                else printf("0 ");
            }
        }
        free(ones);
    }
    return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = (int)1e9+7;
const double PI = 3.14159265359;

ll sum(ll n, ll k){
	ll ans = 0;
	for(int i=k;i<=n;i++){
		ans = (ans + i * (n - i + 1) + 1) % MOD;
	}
	return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n,k;
	cin>>n>>k;
	
	cout<<sum(n,k)+1;
	
	
	
	return 0;
}
































Measured memory_bytes: 3648
#include<cstdio>

double date[4][2];

int main()
{
	while(true)
	{
	for(int i=0;i<4;i++)
	{
		for(int j=0;j<2;j++)
		{
			if(scanf("%lf",&date[i][j])==EOF)goto end;
		}
	}
	if((date[0][0]>date[3][0]||date[1][0]<date[2][0])||(date[0][1]>date[3][1]||date[1][1]<date[2][1]))
	{
		printf("NO\n");
	}
	else printf("YES\n");


	}

end:
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define N 50
using namespace std;
typedef long long ll;
bool used[N];
  
ll SumD(ll a,ll d,ll n){return (n*(2*a+(n-1)*d))/2;}
  
bool mark(ll n){
  bool res=1;
  for(ll i=1;i*i<=N;i++)res&=!used[i],used[i]=1;
  return res;
}
  
int main(){
  while(1){
    ll n,m,p[21];
    cin>>n>>m;
    if(!n&&!m)break;
    for(int i=0;i<m;i++)cin>>p[i];
    sort(p,p+m);
    
    ll sum=0,cnt=0;
    for(int i=0;i<m;i++){
      sum+=SumD(p[i],p[i],n/p[i]);
      cnt+=n/p[i];
      memset(used,0,sizeof(used));
      for(int j=0;j<i;j++){
    ll lcm=(p[i]/__gcd(p[i],p[j]))*p[j];
    if(!mark(lcm))continue;
    sum-=SumD(lcm,lcm,n/lcm);
    cnt-=(n/lcm);
      }
    }
    printf("%.8f\n",(1.0*SumD(1,1,n)-sum)/max(1LL,(n-cnt)));
  }
  return 0;
}

Measured memory_bytes: 3256
#include <stdio.h>
#include <string.h>
int A[1500];
void Answer(void);
int main(void){
	int i,j,n,m;
	char str[1000],*line;

	for( ; ; ){
		fgets(str,sizeof(str),stdin);
		sscanf(str,"%d",&m);
		if(m==0) break;
		for(j=0;j<m;j++){
			fgets(str,sizeof(str),stdin);
			line = strtok(str," ");
			sscanf(line,"%d",&n); A[0]=n;
			for(i=1;i<3;i++){
				line = strtok(NULL," ");
				sscanf(line,"%d",&n); A[i]=n;	
			}
			Answer();
		}
	} 
	return 0;
}			

void Answer(void){
	if(A[0]==100 || A[1]==100 || A[2]==100 || (A[0]+A[1])/2>=90 || 
			(A[0]+A[1]+A[2])/3>=80)
		printf("A\n");
	else if((A[0]+A[1]+A[2])/3>=70 || (A[0]+A[1]+A[2])/3>=50 && A[0]>=80 ||
			(A[0]+A[1]+A[2])/3>=50 && A[1]>=80)
		printf("B\n");
	else
		printf("C\n");
}

Measured memory_bytes: 596
#include<stdio.h>
int main()
{
    int c, i;
    char a[255], b[255];
    scanf("%s", a);
    scanf("%s", b);
    for ( i = 0; i < 9; i++)
    {
        if (a[i] != b[i])
        {
            c = c + 1;            
        }
    }
    if (c > 2)
    {
        printf("No");
    }
    else
    {
        printf("Yes");
    }
    return 0;
}

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

int main(void){
    int n;
    cin >> n;
    int a[n],sum = 0;
    for(int i = 0;i < n;i++)cin >> a[i];
    for(int i = 0;i < n;i++)sum += a[i];
    sort(a,a+n);
    for(int i = 0;i < n;i++){
        if(sum % 10 != 0)break;
        
        if(a[i] % 10 != 0)sum -= a[i];
    }
    if(sum % 10 == 0)cout << 0 << endl;
    else cout << sum << endl;
}

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

int n, b, sum, a[25], c[25];
int main() {
	int i;
	cin >> n;
	for(i=1; i<=n; i++) cin >> a[i];
	for(i=1; i<=n; i++) cin >> b, sum += b;
	for(i=1; i<=n; i++) cin >> c[i];
	for(i=2; i<=n; i++) {
		if(a[i] - a[i-1] == 1) sum += c[a[i-1]];
	}
	cout << sum;
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    if (N < (1 << (i + 1))) {
      cout << (1 << i) << endl;
      break;
    }
  }
  
  return 0;

}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for D - Teleporter
	var N, K int
	fmt.Scan(&N, &K)

	sc.Split(bufio.ScanWords)
	A := make([]int, N)

	for i := 0; i < N; i++ {
		A[i] = nextInt()
	}

	B := make(map[int]int, N)
	C := make([]int, 0)
	D := make([]int, 0)
	var temp int = 1
	var numBefore, numAfter int
	var count int
	var flag int
	for {
		B[temp]++
		count++
		if flag == 0 && B[temp] > 1 {
			numBefore = count
			flag = 1
		}

		if flag == 1 && B[temp] > 2 {
			numAfter = count
			break
		}

		if flag == 1 {
			C = append(C, A[temp-1])
		} else {
			D = append(D, A[temp-1])
		}
		temp = A[temp-1]
	}

	if K < numBefore {
		fmt.Println(D[K-1])
	} else {
		fmt.Println(C[(K-numBefore)%(numAfter-numBefore)])
	}

}


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

void push(int);
int pop(void); 
int main(void){
	int  x, y, n;
	char ch[100];
	while(scanf("%s",ch)!=EOF){
		if(ch[0]=='+'){
			x=pop();
			y=pop();
			push(x+y);
		}
		else if(ch[0]=='-'){
			y=pop();
			x=pop();
			push(x-y);
		}
		else if(ch[0]=='*'){
			x=pop();
			y=pop();
			push(x*y);
		}else{
			n = atoi(ch);
			push(n);
		}
	}
	printf("%d\n", pop());
	return 0;
} 
int S[100];
int top; 
void push(int x){
	if(top>=100-1){
	}
	++top;
	S[top] = x;
}
int pop(void){
	if(top==0){
	}
--top;
return S[top+1];
}

Measured memory_bytes: 1852
#include <bits/stdc++.h>
//#include <math>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
// #define fore(i,a) for(auto &i:a)
// #define all(x) (x).begin(),(x).end()
// #pragma GCC optimize ("-O3")
// using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
// typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
// template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
// template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
 
using namespace std;
 
int main(void)
{
  long int n,s;
  cin>>n>>s;
  
  rep(x,0,n+1){
    rep(y,0,n-x+1){
      int z=(s-(10000*x+5000*y))/1000;
      int m=(s-(10000*x+5000*y))%1000;
      if(z==n-x-y && m==0){
        cout<<x<<" "<<y<<" "<<z<<endl;
        return 0;
      }
      
    }
  }
  
  cout<<"-1 -1 -1"<<endl;
  
  return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N,T;
  cin>>N>>T;
  vector<int>c;
  for(int i=0;i<N;i++){
    int cost,time;
    cin>>cost>>time;
    if(time<=T)c.push_back(cost);
  }
  if(c.size()==0){
    cout<<"TLE"<<endl;
    return 0;
  }
  sort(rng(c));
  cout<<c[0]<<endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
//constexpr int MOD=1000000007;
constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    lint X,N;
    cin >> X >> N;
    lint P[N];
    rep(i,N) cin >> P[i];
    set<int> num;
    for(int i=-100;i<=200;i++) num.insert(i);
    rep(i,N) num.erase(P[i]);
    int ans=INF;
    int dis=INF;
    while(!num.empty()){
        int n=*num.begin();
        num.erase(n);
        if(llabs(n-X)<=dis){
            if(llabs(n-X)<dis) ans=n,dis=llabs(n-X);
            else ans=min(ans,n);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
def main():
    a, b = list(map(int, input().split()))
    def factorization(num):
        result = set()
        count = 0
        temp = num
        for i in range(2, int(num ** 0.5) + 1):
            if temp % i == 0:
                count = 0
                while temp % i == 0:
                    count += 1
                    temp /= i
                result.add(i)
        if temp != 1:
            result.add(int(temp))
        if result == []:
            result.add(num)
        return result
    print(len(factorization(a) & factorization(b)) + 1)



if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
char c;
int main()
{
	cin >>c;
	cout <<(char)(c+1);
	return 0;
}

Measured memory_bytes: 256
N,M=map(int, input().split())
H=list(map(int, input().split()))
flag=[1]*N


for i in range(M):
    A,B=map(int, input().split())
    if H[A-1]>H[B-1]:
        flag[B-1]=0
    elif H[A-1]<H[B-1]:
        flag[A-1]=0
    else:
        flag[A-1]=0
        flag[B-1]=0
print(sum(flag))

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

typedef long long ll;

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

    for(int i=1; i<=3500; i++) for(int j=1; j<=3500; j++)
    {
        ll p = 1LL*n*i*j;
        ll q = 4LL*i*j - n*i - n*j;

        if(q > 0 && p % q == 0)
        {
            cout << i << ' ' << j << ' ' << p/q << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
// written by IftekharMd.Shishir   :)   12.4.2020

#include<bits/stdc++.h>

#define ll          long long int
#define ull         unsigned long long int
#define f(i,n)      for(i=0;i<n;i++)
#define F(i,n)      for(i=n;i>=0;i--)
#define fa(i,a,b)   for(i=a;i<b;i++)
#define Fa(i,a,b)   for(i=a;i>=b;i--)
#define vec         vector<long long int>
#define que         queue<long long int>        //a.push(x)   a.pop()    a.back()    a.front()
#define pb(x)       push_back(x)
#define pob()       pop_back()
#define sor(a)      sort(a.begin(),a.end())
#define rev(a)      reverse(a.begin(),a.end())  // string or array reverse
#define ins(a,x)    insert(a.begin(),x)         // push in front
#define points(x)   fixed<<setprecision(x)
#define done        return 0

/*----------[ string to integer ]--------------
string str;  int x=0;
stringstream demo(str);
demo >> x;
cout<< x <<endl;
*/

/*----------[ integer to string ]--------------
string name;  int x=345;
stringstream demo;
demo << x;
name=demo.str();
cout<< name <<endl;
*/
using namespace std;

int main()
{
    ll i,n,s=0,j,k;
    cin>>n;
    fa(i,1,n+1){
        fa(j,1,n+1){
            fa(k,1,n+1){
                s+=(__gcd(i,__gcd(j,k)));
            }
        }
    }
    cout<<s<<endl;
    done;
}


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

using namespace std;

using ll = long long;
using db = double;
using vi = vector<int>;
#define pb push_back
#define fir first
#define sec second 

const int maxn = 306; 
const ll mod = 1000000007; 
int f[maxn][maxn][maxn]; 
ll n, m; 
vector<pair<int,int>> e[maxn]; 

struct data {
	int a[4]; 
	int & operator[](int x) {
		return a[x]; 
	}
	data() {}
	data(int i, int j, int k) {
		a[1] = i; a[2] = j; a[3] = k; 
	}
}a; 

bool check(data a, int x) {
	for (auto p : e[x]) {
		if (a[p.fir] < p.sec) return false; 
		if (p.fir < 3 && a[p.fir+1] >= p.sec) return false; 
	}
	return true; 
}

void ud(int &a, int b) { a=(a+b)%mod; }

int main() {
	cin>>n>>m;
	for (ll i = 1; i <= m; ++i) {
		ll l, r, x; 
		cin>>l>>r>>x; 
		e[r].pb({x,l}); 
	}
	memset(f, 0, sizeof(f)); 
	f[0][0][0] = 1; 
	int ans = 0; 
	for (int i = 0; i <= n; ++i) 
		for (int j = 0; j <= i; ++j) 
			for (int k = 0; k <= j; ++k) {
				if (i == n) ud(ans, f[i][j][k]); 
				else if (f[i][j][k] > 0) {
					a = data(i+1,j,k); 
					if (check(a,i+1)) ud(f[i+1][j][k], f[i][j][k]); 
					a = data(i+1,i,k); 
					if (check(a,i+1)) ud(f[i+1][i][k], f[i][j][k]); 
					a = data(i+1,i,j); 
					if (check(a,i+1)) ud(f[i+1][i][j], f[i][j][k]); 
				}
			}
	cout<<ans<<endl; 
	return 0;
}


Measured memory_bytes: 112128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	string S;
	cin >> S;
	if (S[S.length() - 1] == 's') {
		cout << S << "es" << endl;
	} else {
		cout << S << "s" << endl;
	}
}


Measured memory_bytes: 3624
import java.util.Scanner;
public class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
           int i=0;
        while((int)(Math.pow(2,i))<=n)
        {
            i++;
        }
        i--;
        System.out.println((int)(Math.pow(2,i)));
    }
}
        

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

int main(){
  int r, g, b;
  cin >> r >> g >> b;
  
  int c = 10*g + b;
  string re;
  
  if(c%4 == 0){
    re = "YES";
  } else {
    re = "NO";
  }
  
  cout << re << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define rint register int 
using namespace std;
inline ll read(){ll w=1,s=0;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=s*10+ch-'0';ch=getchar();}return w*s;}
ll n,A[1000010],X;
ll Sum[1000010],differ[1000010];
int main()
{
	n=read();X=read();
	for(rint i=1;i<=n;++i) A[i]=read(),Sum[i]=A[i]+Sum[i-1];
	differ[1]=differ[2]=5;
	for(rint i=3;i<=n+100;++i) differ[i]=differ[i-1]+2;
	ll ans=8e18;
	for(rint k=1;k<=n;++k)
	{
		ll res=1ll*k*X;
		for(rint i=n,j=1;i>0&&res<ans;i=max(i-k,0),j++)
		{
			res+=1ll*(Sum[i]-Sum[max(i-k,0)])*differ[j];
		}
	//	cout<<k<<" "<<res<<"\n";
		ans=min(ans,res); 
	}cout<<ans+1ll*n*X<<"\n";
	return 0;
}



Measured memory_bytes: 9984
s=1000
ret=-1000
x,n=map(int,input().split())
if n==0:
	print(x)
	exit()
p=list(map(int,input().split()))
p=set(p)
for i in range(-101,202):
	if i not in p:
		if s>abs(x-i):
			s=abs(x-i)
			ret=i
print(ret)


Measured memory_bytes: 9192
n = (int)(input())
a = list(map(int, input().split()))

# 部下の数を入れるリスト
sub_num = []
for i in range(n+1):
    sub_num.append(0)

#
for i in range(n-1):
    index = a[i]
    sub_num[index] += 1

for i in range(1, n+1):
    print("{}".format(sub_num[i]))

Measured memory_bytes: 32232
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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")
    };
}


#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    ($arg:expr) => (println!("{:?}",$arg));
}


#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}


fn main() {
    input!{
        n:i32
    }

let mut ret = 0;
for i in 1..n+1{
    if(i.to_string().len() % 2 == 1){
        ret += 1;
    }
}
   
   println!("{}",ret);


}


Measured memory_bytes: 4352
def ex(x):
    while x%2==0 and x>2:
        x/=2
    if x==2:
        return 0
    else:
        return 1
a,b,c = map(int, input().split())
count = 0
if not ex(a)==ex(b)==ex(c)==0:
    while a%2==0 and b%2==0 and c%2==0:
        temp_a = a
        temp_b = b
        temp_c = c
        a = temp_b/2 + temp_c/2
        b = temp_a/2 + temp_c/2
        c = temp_a/2 + temp_b/2
        count+=1
        if ex(a)==ex(b)==ex(c)==0 or a==b==c:
            count = -1
            break
    print(count)
else:
    print("-1")

Measured memory_bytes: 3064