akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

ll a[4],b[4];
ll n;

int main(){
	cin.sync_with_stdio(false);
  rep(i,4)cin>>a[i];
  cin>>n;
  rep(i,4)b[i]=a[i];
  a[0]*=8;
  a[1]*=4;
  a[2]*=2;
  b[0]*=4;
  b[1]*=2;
  ll minc=*min_element(a,a+4);
  ll minc2=*min_element(b,b+4-1);
  cout<<(n/2)*minc+(n%2)*minc2<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,K,m,t,u,G[100],l,i,S;
  cin >> N >> K;
  i=0;
  while(i < N){
    G[i]=0;
    i++;
  }
  i=0;
  while(i < K){
    t=0;
    cin >> m;
    while(t < m){
    cin >> u;
    G[u-1]++;
    t++;
    }
    i++;
  }
  S=0;
  i=0;
  while(i < N){
    if(G[i]==0){
      S++;
    }
    i++;
  }
  cout << S <<endl;
}

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

using ll = long long;
using namespace std;

int main()
{
	ll n, w;
	cin >> n >> w;
	vector<int> val(n), weight(n);
	for (int i = 0; i < n; i++)
	{
		cin >> weight[i] >> val[i];
	}
	// vector<vector<ll>> dp(n + 1, vector<ll>(w + 1, 0));
	vector<ll> prev(w + 1, 0), curr(w + 1, 0);
	for (ll i = 1; i <= n; i++)
	{
		for (ll j = 1; j <= w; j++)
		{
			if (weight[i - 1] <= j)
			{
				curr[j] = max((val[i - 1] + prev[j - weight[i - 1]]), prev[j]);
			}
			else
			{
				curr[j] = prev[j];
			}
		}
		prev = curr;
		curr.clear();
		curr.resize(w + 1, 0);
	}
	cout << prev[w] << "\n";
}


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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
//m.emplace(x,0).fi->se++;
struct k{
  ll u=0;
  ll v=0;
  ll w=0;
};

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll l;cin>>l;
  bitset<25>a=l;
  ll n,m=0;
  buf=0;
  vector<struct k>r;
  rrep(i,25,0){
    if(judge&&a[i]){
      n=i+1;
      ll tmp=1;
      rep(j,0,n-1){
        r.push_back({n-j-1,n-j,tmp});
        r.push_back({n-j-1,n-j,0LL});
        m+=2;
        tmp*=2;
      }
      buf+=tmp;
      judge=false;
    }
    else if(a[i]){
      r.push_back({1LL,n-i,buf});
      ll p=pow(2,i);
      buf+=p;
      m++;
    }
  }
  cout<<n spa m<<endl;
  for(auto z:r){
    cout<<z.u spa z.v spa z.w<<endl;
  }

  return 0;
}

Measured memory_bytes: 256
N = int(input())
l = [-1] * N

print(0)
s = input()
if s=="Male":
    l[0] = 0
elif s=="Female":
    l[0] = 1
else:
    exit(0)

print(N-1)
s = input()
if s=="Male":
    l[N-1] = 0
elif s=="Female":
    l[N-1] = 1
else:
    exit(0)

left, right = 0, N-1
while right-left>1:
    mid = (left+right)//2

    print(mid)
    s = input()
    if s=="Male":
        l[mid] = 0
    elif s=="Female":
        l[mid] = 1
    else:
        exit(0)

    if (l[mid]==l[left] and (mid-left)%2) or (l[mid]!=l[left] and (mid-left)%2==0):
        left, right = left, mid
    else:
        left, right = mid, right


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

#ifndef INCLUDE_SEG_HPP
#define INCLUDE_SEG_HPP
#include <functional>
#include <algorithm>
#include <iterator>
namespace orislib {
namespace ds {
constexpr int uprt(int k, int i=1){
  return i < k ? uprt(k, i + i) : i;
}
template<typename T, int S>
struct SegT {
  typedef T seg_t;
  const seg_t OUT;
  static const int N = uprt(S);
  seg_t data[N * 2];
  std::function<seg_t(seg_t,seg_t)>ufunc;
  template<typename F>
  SegT(T initial, F f) : OUT(initial), ufunc(f) {std::fill(std::begin(data), std::end(data), initial);}
  void update(int x, seg_t&v){
    for (data[x+=N-1]=v;x;data[x]=ufunc(data[x+x+1],data[x+x+2]))x=x-1>>1;
  }
  void add(int x,seg_t&a){ update(x,data[x+N-1]+a); }
  seg_t query(int a=0,int b=N,int x=0,int l=0,int r=N){
    if (r<=a||b<=l) return OUT;
    if (a<=l&&r<=b) return data[x];
    return ufunc(query(a,b,x+x+1,l,l+r>>1),query(a,b,x+x+2,l+r>>1,r));
  }
};
}
}
#endif

using namespace orislib::ds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
//{{{ templates
#define TMPINL_(...) template<__VA_ARGS__>inline
#define TT_ TMPINL_(typename T)
#define TTF_ TMPINL_(typename T,typename F)
#define TTTS_ TMPINL_(typename T,typename...Ts)
#define TITS_ TMPINL_(size_t I=0,typename...Ts)
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type&x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type&x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TITS_ typename enable_if<I==tuple_size<tuple<Ts...>>::value-1,string>::type join(string s,tuple<Ts...>t){return to_string(get<I>(t));}
TITS_ typename enable_if<I<tuple_size<tuple<Ts...>>::value-1,string>::type join(string s,tuple<Ts...>t){return to_string(get<I>(t))+s+join<I+1>(s,t);}
TT_ string join(string s,T t){return to_string(t);}
TTTS_ string join(string s,T t,Ts...ts){return join(s,t)+s+join(s,ts...);}

inline void fast_io(){ios::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
inline int puts(const string&s){ return puts(s.c_str()); }
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;

int main()
{
  SegT<int, 100000> seg(INT_MAX, [](int a, int b){return min(a, b);});
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < q; i++){
    int a, b, c;
    cin >> a >> b >> c;
    if (a) cout << seg.query(b, c + 1) << endl;
    else seg.update(b, c);
  }
  return 0;
}

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

#define print cout <<
#define printl(s) cout << s << endl;
#define rep(i,n) for (int i = 0; i < (n); ++i)

template <typename T>
vector<T> getValues(int num){
    vector<T> values(num);
    for(int i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

int main(){
    string S, T;
    cin >> S >> T;
    if(S.size()+1!=T.size()){
      printl("No");
      return 0;
    }
    rep(i,S.size()){
      if(S.at(i)!=T.at(i)){
        printl("No");
        return 0;
      }
    }
    printl("Yes");
}


Measured memory_bytes: 3576
s = input()
n = len(s)
a = [i for i in s]
for i in range(2**(n-1)):
  b = []
  for j in range(n):
    b.append(a[j])
    if j > 2:
      break
    if (i >> j) & 1:
      b.append("+")
    else:
      b.append("-")
  if eval("".join(b)) == 7:
    b.append("=7")
    print("".join(b))
    exit()

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("caitui.inp", "r", stdin);
    long long int n, w;
    long long int i, j;

    //stack<int> kq;
    cin >> n >> w;
    long long int m[n + 100], v[n + 100];
    long long int f[n + 10][w + 10];
    for (i = 1; i <= n; i++)
    {
        cin >> m[i] >> v[i];
    }
    for (j = 0; j <= w; j++)
    {
        f[0][j] = 0;
    }
    for (i = 0; i <= n; i++)
    {
        f[i][0] = 0;
    }
    for (i = 1; i <= n; i++)
    {
        for (j = 1; j <= w; j++)
        {
            if (m[i] <= j)
            {
                f[i][j] = max((f[i - 1][j - m[i]] + v[i]), (f[i - 1][j]));
            }
            else
            {
                f[i][j] = f[i - 1][j];
            }
        }
    }
    cout << f[n][w] << endl;
    /*
    int j = w;
    for (int i = n; i > 0; i--)
    {
        if (f[i][j] != f[i - 1][j])
        {
            kq.push(i);
            j = j - m[i];
        }
    }
    while (!kq.empty())
    {
        cout << kq.top() << " ";
        kq.pop();
    }
    return 0;*/
}


Measured memory_bytes: 81024
#include<iostream>
using namespace std;
const int N=2e5+10,mod=1e9+7;
int f[N],nxt[N],a[N],nw[N],n;
void add(int &x,int y) {x+=y;if(x>=mod) x-=mod;}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=n;i>=1;i--)
		nxt[i]=nw[a[i]],nw[a[i]]=i;
	f[1]=1;
	for(int i=1;i<n;i++)
	{
		add(f[i+1],f[i]);
		if(nxt[i]!=i+1) add(f[nxt[i]],f[i]);
	}
	cout<<f[n]<<endl;
}


Measured memory_bytes: 3328
#include<iostream>
using namespace std;
    int main(void){
    int a,b,c;
    int count_a=0,count_b=0;
    char x;
    while(cin >> a >> x >> b >> x >>c){
        if(a*a + b*b == c*c) count_a++;
        else if(a == b) count_b++;
    }
    cout << count_a << endl;
    cout << count_b << endl;
}


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

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        m: usize,
        e: [(usize1, usize1); m],
    }
    let inf = 301;
    let mut d = vec![vec![inf; n]; n];
    for (a, b) in e {
        d[a][b] = 1;
    }
    for i in 0..n {
        d[i][i] = 0;
    }
    for k in 0..n {
        for i in 0..n {
            for j in 0..n {
                d[i][j] = std::cmp::min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    let mut ans = String::new();
    for i in 0..n {
        for j in 0..n {
            if d[i][j] < inf && d[j][i] < inf {
                ans.push_str(&(j + 1).to_string());
                ans.push(' ');
            }
        }
        ans.pop();
        ans.push('\n');
    }
    print!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 7100
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
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 main(){
  ll s;
  cin >> s;
  ll x1,y1,x2,y2,x3,y3;
  x1=0,y1=0,x2=pow(10,9),y2=1;
  if(s==1e+18)x3=0,y3=1e+09;
  else{
    x3 = 1e+09-s%(ll)1e+09;
    y3 = s/1e+09+1;
  }
  cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
  return 0;
}


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

using namespace std;

int main() {
    int n;  cin >> n;
    string s;   cin >> s;
    int ans = 0;
    for (int i = 1; i < n; i++) {
        int cnt = 0;
        for (char c = 'a'; c <= 'z'; c++) {
            bool r = false, l = false;

            for (int j = 0; j < i; j++) {
                if (s[j] == c)
                    l = true;
            }
            for (int j = i; j < n; j++) {
                if (s[j] == c)
                    r = true;
            }

            if (l && r)
                cnt++;
        }
        ans = max(cnt, ans);
    }

    cout << ans << endl;
    return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define hash dhsjakhd
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

ll n,m,T,k,d;
const ll big = 1000000007;



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   // freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,e;
    ll ans = 0;
    string s;
    cin >> s;
    a = 0;
    for(int c1 = 0; c1 < s.length(); c1++){
        if(s[c1] == 'B')a++;
        if(s[c1] == 'W')ans += a;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 720
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)

using namespace std;
typedef long long ll;

const int INF = 100000;

int main() {
  int n;
  cin >> n;
  vector<int> b(n - 1);
  rep(i, n - 1) cin >> b[i];

  vector<int> a(n);
  a[0] = a[1] = b[0];
  REP(i, 1, n - 1) {
    if (b[i] < b[i - 1]) a[i] = b[i];
    a[i + 1] = b[i];
  }
  ll ans = 0;
  rep(i, n) ans += a[i];
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using vec = vector<int>;
using vec2 = vector<vector<int>>;

int main(){
    int x, y;
    bool ans = false;
    cin >> x >> y;
    rep(i, x+1){
        if(2*i + 4*(x-i) == y){
            ans = true;
            break;
        }
    }
    if(ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3616
#[allow(unused_imports)]
use std::cmp;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use proconio::derive_readable;
use proconio::fastout;
#[allow(unused_imports)]
use num::Integer;
#[allow(unused_imports)]
use itertools::Itertools;

#[fastout]
fn main() {
  input! {
    n: usize,
    mut ss: [String; n],
  }
  ss.sort();
  ss.dedup();

  println!("{}", ss.len());
}


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

const int inf = 1LL << 50;

int n, m, L;
vector<int> K, S, sum;
vector<vector<int>> memo;

int calc(int a, int b){
    return (sum[K[b] + 1] - sum[K[a]]) / L;
}

int rec(int li, int ri){
    if(memo[li][ri] != inf) return memo[li][ri];
    
    int ni = max(li, ri) + 1;

    if(ni == n - 1){
        return memo[li][ri] = calc(li, ni) + calc(ri, ni);
    }

    return memo[li][ri] = min(rec(li, ni) + calc(ri, ni), rec(ni, ri) + calc(li, ni));
}

signed main(void){
    cin >> n >> m >> L;
    K = vector<int>(n), S = vector<int>(m);
    for(auto & e : K) cin >> e, e--;
    for(auto & e : S) cin >> e;

    sort(begin(K), end(K));

    sum = vector<int>(m + 1);
    sum[0] = 0;
    rep(i, m){
        sum[i + 1] = sum[i] + S[i];
    }

    memo = vector<vector<int>>(n, vector<int>(n, inf));

    cout << rec(0, 0) << endl;

	return 0;
}

Measured memory_bytes: 35828
from collections import defaultdict

class UnionFind(object):
  def __init__(self, n=1):
    self.par = [i for i in range(n)]
    self.rank = [0 for _ in range(n)]
    self.size = [1 for _ in range(n)]
  def find(self, x):
    if self.par[x] == x:
      return x
    else:
      self.par[x] = self.find(self.par[x])
      return self.par[x]
  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x != y:
      if self.rank[x] < self.rank[y]:
        x, y = y, x
      if self.rank[x] == self.rank[y]:
        self.rank[x] += 1
      self.par[y] = x
      self.size[x] += self.size[y]
  def is_same(self, x, y):
    return self.find(x) == self.find(y)
  def get_size(self, x):
    x = self.find(x)
    return self.size[x]


N, M = map(int,input().split())

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

z = []
for i in range(M):
  t, s = map(int,input().split())
  z.append((t,s))

uf = UnionFind(N)

for i in range(M):
  uf.union(z[i][0]-1, z[i][1]-1) #1というのは0番目のため1を引く。

#c = defaultdict(int)
ans = 0
for i in range(N):
  if uf.is_same(i, P[i]-1):
    ans += 1
print(ans)

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

int main() {
    int n;cin>>n;
    map<int,int> c;
    for (int i=0;i<n;i++) {
        int a;cin>>a;c[a]++;
    }
    int f=1;
    ll ans=1;
    int mod=1e9+7;
    for (int i=n-1;i>0;i-=2)
        f&=c[i]==2,ans=ans*2%mod;
    if (n%2)
        f&=c[0]==1;
    if (f)
        cout<<ans<<endl;
    else
        cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 4096
def factorize(n):
    ## 素因数分解
    # arr = factorize(20)
    # arr == [[2, 2], [5, 1]]
    
    result = []
    tmp = n
    for k in range(2, int(n ** 0.5) + 1):
        cnt = 0
        while tmp % k == 0:
            cnt += 1
            tmp //= k
        if cnt > 0:
            result.append([k, cnt])
    if tmp != 1:
        result.append([tmp, 1])
    return result

def divisorize(n):
    ## 約数
    # arr = factorize(20)
    # arr == [2, 4, 5, 10, 20]
    f = factorize(n)
    divisors = [1]
    for k in range(len(f)):
        num_divisors = len(divisors)
        for i in range(1, f[k][1] + 1):
            for j in range(num_divisors):
                divisors.append(divisors[j] * f[k][0] ** i)
    return sorted(divisors)

x = int(input())
a = 0
d = divisorize(x)
flg = False
while True:
    for dd in d:
        b = a - dd
#         print(a, dd, b)
        try:
            if a ** 5 - b ** 5 == x:
                flg = True
                break
        except:
            pass
    if flg:
        break
    a += 1
print(a, b)

Measured memory_bytes: 79252
#include<stdio.h>
int main(){
int j,m,r,f,n,total;
int test[50][3]={{0}};
n=0;
while(1){
  scanf("%d %d %d",&m,&f,&r);
  test[n][0]=m;
  test[n][1]=f;
  test[n][2]=r;
++n;
if(m==-1&&f==-1&&r==-1) break;
}
for(j=0;j<n-1;j++){
  total=test[j][0]+test[j][1];
  if(test[j][0]==-1 || test[j][1]==-1){
    printf("%c\n",'F');
  }else if(total>=80 && test[j][2]==-1){
    printf("%c\n",'A');
  }else if(65<=total && total<80){
    printf("%c\n",'B');
  }else if(50<=total && total<65){
    printf("%c\n",'C');
  }else if(total<50 && total>=30){
    if(total<50&&total>=30&&test[j][2]>=50){
       printf("%c\n",'C');
}else {
  printf("%c\n",'D');
}
  }else{
     printf("%c\n",'F');
  }
}
  return 0;
}


Measured memory_bytes: 2068
#include <math.h>

#include <algorithm>
#include <bitset>
#include <iostream>
#include <sstream>
#include <vector>

using namespace std;

void dfs(int x, int y, vector<vector<int>>& field) {
  if (0 <= x && x < field.size() && 0 <= y && y < field[0].size()) {
    if (field[x][y] == 0) {
      return;
    }
  } else {
    return;
  }

  field[x][y] = 0;
  for (int dx = -1; dx <= 1; dx++) {
    for (int dy = -1; dy <= 1; dy++) {
      dfs(x + dx, y + dy, field);
    }
  }
  return;
}

int main() {
  vector<int> ans_v;
  for (int k = 0; k < 100; k++) {
    int w, h;
    cin >> w >> h;
    if (w == 0) {
      break;
    }

    vector<vector<int>> field(h, vector<int>(w));
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> field[i][j];
      }
    }
    int ans = 0;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (field[i][j] == 1) {
          dfs(i, j, field);
          ans++;
        }
      }
    }

    ans_v.push_back(ans);
  }

  for (int i = 0; i < ans_v.size(); i++) {
    cout << ans_v[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 3240
using System;

class Program
{
    static void Main()
    {
        string[] example = { "Yes", "No" };
        string result = string.Empty;
        string[] str = Console.ReadLine().Split(' ');
        int a = int.Parse(str[0]);
        int b = int.Parse(str[1]);
        int c = int.Parse(str[2]);

        if (a < b && b < c)
        {
            result = example[0];
        }
        else
        {
            result = example[1];
        }

        Console.WriteLine("{0}", result);
    }
}

Measured memory_bytes: 9052
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;

const int maxN = 1e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b){return !b ? a : gcd(b, a % b);}
ll modP(ll a, ll b) {return (!b ? 1 : (modP(a, b / 2) * modP(a, b / 2) * (b % 2 ? a : 1)) % MOD);}

int n, i, dp[3][maxN], a, b, c;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (i = 1; i <= n; i++){
		cin >> a >> b >> c;
		dp[0][i] = max(dp[1][i - 1], dp[2][i - 1]) + a;
		dp[1][i] = max(dp[0][i - 1], dp[2][i - 1]) + b;
		dp[2][i] = max(dp[1][i - 1], dp[0][i - 1]) + c;
	}
	cout << max(max(dp[0][n], dp[1][n]), dp[2][n]) << endl;
	return 0;
}



Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#define min(x, y) (x > y ? y : x)
#define LIMITED 1000000007
using namespace std;

/* 
W = 1
 pat = 1 (0)
W = 2
 pat = 2 (1)
W = 3
 pat = 3 (1)
W = 4
 pat = 5 (2,1)
W = 5
 pat = 8 (3,2)
W = 6
 pat = 13 (5,3,4)
W = 7
 pat = 21 (8,5,6)  
W = 8
 pat = 34 (13,8,10,9)
*/
int sum[9] = {0, 1, 2, 3, 5, 8, 13, 21, 34};
int pat[9][7] = {
    {0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0},
    {1, 0, 0, 0, 0, 0, 0},
    {1, 1, 0, 0, 0, 0, 0},
    {2, 1, 2, 0, 0, 0, 0},
    {3, 2, 2, 3, 0, 0, 0},
    {5, 3, 4, 3, 5, 0, 0},
    {8, 5, 6, 6, 5, 8, 0},
    {13, 8, 10, 9, 10, 8, 13},
};

long long anstable[100][8] = {0};

void calc_dp(int H, int W)
{
    anstable[0][0] = 1;
    for (int i = 1; i <= H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (j != 0)
            {
                anstable[i][j] = anstable[i - 1][j - 1] * pat[W][j - 1] + anstable[i-1][j] * (sum[W] - pat[W][j] - pat[W][j-1]) + anstable[i-1][j+1] * pat[W][j];
            }
            else
            {
                anstable[i][j] = anstable[i-1][j] * (sum[W] - pat[W][j]) + anstable[i-1][j+1] * pat[W][j];
            }
            anstable[i][j] %= LIMITED;
            //printf("i%d j%d :%d\n",i,j,anstable[i][j]);
        }
    }
}

int main()
{
    int H, W, K;
    cin >> H >> W >> K;

    calc_dp(H, W);

    cout << anstable[H][K-1] << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
char in[10];
vector<pair<int,int> >g[120];
int ijk[120][1<<6];
int v[120][1<<6];
int ca[10];
int main(){
	int a,b,c,d;
	while(scanf("%d%d%d%d",&a,&b,&c,&d),a){
		for(int i=0;i<a;i++)scanf("%d",ca+i);
		int s=a+b;
		int t=a+b+1;
		for(int i=0;i<=t;i++){
			g[i].clear();
			for(int j=0;j<(1<<a);j++){
				ijk[i][j]=999999999;
				v[i][j]=0;
			}
		}
		for(int i=0;i<d;i++){
			scanf("%s",in);
			int from,to;
			if(in[0]=='H')from=s;
			else if(in[0]=='D')from=t;
			else if(in[0]=='C')from=in[1]-'1';
			else{
				int at=1;int tmp=0;
				while(in[at]){
					tmp*=10;tmp+=in[at]-'0';at++;
				}
				tmp--;from=tmp+a;
			}
			scanf("%s",in);
			if(in[0]=='H')to=s;
			else if(in[0]=='D')to=t;
			else if(in[0]=='C')to=in[1]-'1';
			else{
				int at=1;int tmp=0;
				while(in[at]){
					tmp*=10;tmp+=in[at]-'0';at++;
				}
				tmp--;to=tmp+a;
			}
			int val;scanf("%d",&val);
	//		printf("%d %d %d\n",from,to,val);
			g[from].push_back(make_pair(to,val));
			g[to].push_back(make_pair(from,val));
		}
		priority_queue<pair<int,pair<int,int> > >Q;
		Q.push(make_pair(0,make_pair(s,0)));
		ijk[s][0]=0;
		while(Q.size()){
			int cost=-Q.top().first;
			int at=Q.top().second.first;
			int bit=Q.top().second.second;
			Q.pop();
			if(v[at][bit])continue;
			v[at][bit]=1;
			for(int i=0;i<g[at].size();i++){
				int to=g[at][i].first;
				int co=g[at][i].second;
				if(to<a){
					if(bit&(1<<to))continue;
					if(!v[to][bit+(1<<to)]&&ijk[to][bit+(1<<to)]>cost+co){
						ijk[to][bit+(1<<to)]=cost+co;
						Q.push(make_pair(-cost-co,make_pair(to,bit+(1<<to))));
					}
				}else{
					if(!v[to][bit]&&ijk[to][bit]>cost+co){
						ijk[to][bit]=cost+co;
						Q.push(make_pair(-cost-co,make_pair(to,bit)));
					}
				}
			}
		}
		int ret=999999999;
	//	for(int i=0;i<=t;i++)for(int j=0;j<(1<<a);j++)printf("%d %d: %d\n",i,j,ijk[i][j]);
		for(int i=0;i<(1<<a);i++){
			if(ijk[t][i]>99999999)continue;
			int val=ijk[t][i]*c;
			for(int j=0;j<a;j++)if(i&(1<<j))val-=ca[j];
			ret=min(ret,val);
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string s;
    cin>>n;
    cin>>s;
    long long int cnt1 = 0,cnt2 = 0,cnt3 = 0;
    for (int i = 0;i<n;i++){
        if (s[i]=='R')cnt1++;
        else if (s[i]=='G')cnt2++;
        else cnt3++;
    }
    long long int ans = cnt1*cnt2*cnt3;
    for (int i = 0;i<n;i++){
        for (int j = i;j<n;j++){
            int k = 2*j-i;
            if (k>=n)continue;
            else if (s[i]!=s[j] && s[i]!=s[k] && s[j]!=s[k])ans--;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3612
// C - Guess The Number
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(int)(n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> s(m), c(m);
    rep(i, m) cin >> s[i] >> c[i];
    rep(i, 1000){
        string str = to_string(i);
        if(str.size() != n) continue;
        bool ok = true;
        rep(j, m){
            if(str[s[j]-1] != c[j]+'0') ok = false;
        }
        if(ok){
            cout << str << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3676
//https://beta.atcoder.jp/contests/agc029/tasks/agc029_b
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};


int main(){
    int N;
    cin>>N;
    int ret=0;
    map<LL,int> cnt;
    for(int i:range(N)){
        LL a;
        cin>>a;
        cnt[a]++;
    }
    LL sum = 1<<30;
    vector<LL> ord;
    for(auto &it:cnt)ord.push_back(it.first);
    //reverse(ALL(ord));
    while(sum>0){
        for(auto &it:ord){
            if(it<sum){
                LL a=it;
                LL b=sum-it;
                if(cnt.count(b)==0)continue;
                int k;
                if(a==b){
                    k = cnt[a]/2;
                }
                else{
                    k = min(cnt[a],cnt[b]);
                }
                cnt[a]-=k;
                cnt[b]-=k;
                ret+=k;
                //cout<<a<<" "<<b<<" "<<k<<endl;
            }
        }
        sum>>=1;
    }
    cout<<ret<<endl;

    return 0;
}

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

int main(void){
    int a,b,k;
    cin >> a >> b >> k;
    for(int i=max(a,b);0<=i;i--){
        if(a%i == 0 && b%i == 0){
            k--;
        }
        if(k == 0){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long
#define mod 1000000007
#define do double
#define loop(i,n) for(int i=0;i<n;i++)
#define lop(a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define mkp make_pair

typedef vector <int> vi;
typedef map <int,int> mii;
typedef set <int> si;
typedef pair <int,int> pii;
typedef unordered_map <int,int> um;
typedef unordered_set <int> us;
typedef multiset <int> ms;
typedef vector < pair <int,int> > vpii;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n,k;
  cin>>n>>k;
  int h[n],dp[n]={};
  loop(i,n) 
  {
    cin>>h[i];
  }
   for(int i=1;i<n;i++)
   {
     int x=INT_MAX;
     for(int j=1;j<=k;j++)
     {
        if(i-j>=0)
        x=min(x,dp[i-j]+abs(h[i]-h[i-j]));
     }
     dp[i]=x;
   }
  cout<<dp[n-1]<<"\n";
}

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  l=list(S())

  for i in range(2):
    for j in range(2):
      for k in range(2):
        a=b=c=''
        if i==0:
          a='+'
        else:
          a='-'
        if j==0:
          b='+'
        else:
          b='-'
        if k==0:
          c='+'
        else:
          c='-'
        x=l[0]+a+l[1]+b+l[2]+c+l[3]
        ans=eval(x)

        if ans==7:
          return x+'=7'

print(main())


Measured memory_bytes: 5416
#include<bits/stdc++.h>
using namespace std;
int a[202020];
int main()
{
  int N; scanf("%d", &N);
  for(int i=0; i<N; ++i) scanf("%d", a+i);
  int ptr = 0;
  int xed = 0;
  long long ans = 0;
  for(int i=0; i<N; ++i)
  {
    //xed = [i, ptr) xored 
    while( ptr<N && (xed^a[ptr]) == (xed+a[ptr]) ) xed += a[ptr++];
    ans += ptr-i;
    xed ^= a[i];
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 1024
package main
 
import "fmt"
 
func main(){
  var a,b,x int 
  fmt.Scanf("%d %d %d",&a,&b,&x)
  if a>x || a+b<x {
   fmt.Println("NO")
  } else if   a+b-x>=0{
    fmt.Println("YES")
  } else {
    fmt.Println("NO")
  }
 
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

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

int n;
ii arr[250005]; //(x,y) is easier to think
int w[505][505];
bool away[505][505];

void dfs(int i,int j){
	rep(z,0,4){
		int x=i+dx[z],y=j+dy[z];
		
		if (x<0 || n<=x || y<0 || n<=y) continue;
		
		if (w[x][y]>w[i][j]+(away[x][y]?0:1)){
			w[x][y]=w[i][j]+(away[x][y]?0:1);
			dfs(x,y);
		}
	}
}

void print(){
	rep(x,0,n){
		rep(y,0,n) cout<<w[x][y]<<" ";
		cout<<endl;
	}
	
	cout<<endl;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	
	rep(x,0,n*n){
		int t;
		cin>>t;
		t--;
		
		arr[x]=ii(t/n,t%n);
	}
	
	rep(x,0,n){
		rep(y,0,n){
			w[x][y]=MIN(x+1,y+1,n-x,n-y);
		}
	}
	
	//print();
	
	ll ans=0;
	rep(x,0,n*n){
		//cout<<arr[x].fi<<" "<<arr[x].se<<endl;
	
		away[arr[x].fi][arr[x].se]=true;
		w[arr[x].fi][arr[x].se]--;
		dfs(arr[x].fi,arr[x].se);
	
		ans+=w[arr[x].fi][arr[x].se];
		
		//print();
	}
	
	cout<<ans<<endl;
}


Measured memory_bytes: 28044
#include <stdio.h>
int main(void) {
    int a, b, divd, mod;
    double divf;
    scanf("%d %d", &a, &b);
    divd = a / b;
    mod = a % b;
    divf = (double) a / b;
    printf("%d %d %.5f\n", divd, mod, divf);
    return 0;
}

Measured memory_bytes: 640
using System;
class Program
{
    static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        int a = int.Parse(str[0]);
        int b = int.Parse(str[1]);
        int d = a / b;
        int r = a % b;
        double f = (double)a / b;
        Console.WriteLine("{0} {1} {2:F5}", d, r, f);
    }
}


Measured memory_bytes: 19988
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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

int main(){
    cin>>N;
    int p[N];
    rep(i,N)cin>>p[i];
    sort(p,p+N);
    out(p[N/2]-p[N/2-1]);
    
    
}


Measured memory_bytes: 640
import math

def solve(a,b,c,d,e,f):
	x = - (d*(f**2+e**2-b**2-a**2) + b*(-f**2-e**2) + b**2*f + a**2*f + d**2*(b-f) + c**2*(b-f)) / (c*(2*f-2*b) - 2*a*f + 2*b*e + d*(2*a-2*e))
	y = (c*(f**2+e**2-b**2-a**2) + a*(-f**2-e**2) + b**2*e + a**2*e + d**2*(a-e) + c**2*(a-e)) / (c*(2*f-2*b) - 2*a*f + 2*b*e + d*(2*a - 2*e))
	r = math.hypot(x-a, y-b) 
	return x,y,r

n = int(input())
for _ in range(n):
	a,b,c,d,e,f = map(float, input().split())
	x,y,r = solve(a,b,c,d,e,f)
	print("{:.3f} {:.3f} {:.3f}".format(x, y, r))

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

        int main() {
          int N;
          cin>> N; 
            vector<int> A(N);
       		for (int i = 0; i < N; i++) {
    			cin >> A.at(i);
  	    	}
           sort(A.begin(), A.end() );
           cout << A.at(N/2) - A.at(N/2-1)<< endl;
        }

Measured memory_bytes: 640
a,b = map(int,input().split())

ans = [["." for i in range(100)] for j in range(100)]

for i in range(100):
    for j in range(50):
        ans[i][j] = "#"

a-=1
b-=1

ind = 0
while True:
    loop = min(a,25)
    for i in range(loop):
        ans[ind][i*2] = "."
    a-=loop
    ind += 2
    if a == 0:
        break

ind = 0
while True:
    loop = min(b,25)
    for i in range(loop):
        ans[ind][51+i*2] = "#"
    b-=loop
    ind += 2
    if b == 0:
        break

print("100 100")
for i in range(100):
    for j in range(99):
        print(ans[i][j],end="")
    print(ans[i][-1])


Measured memory_bytes: 4468
N,K=map(x->parse(Int,x),split(readline()))
A=Array{Int}(0)
now=0
nc=0
for c=chomp(readline())
	c=parse(Int,c)
	if now==c
		nc+=1
	else
		push!(A,nc)
		now=c
		nc=1
	end
end
push!(A,nc)
if now==0
	push!(A,0)
end
ans=0
now=0
for i=1:length(A)
	now+=A[i]
	if i-2K>=1
		now-=A[i-2K]
	end
	ans=max(ans,now+(i%2==0&&i-2K>=1 ? A[i-2K] : 0))
end
println(ans)


Measured memory_bytes: 136956
def popcount(n):
    return bin(n).count('1')
    
N=int(input())
X=input()
xl=list(X)
X=int(X,2)
a=popcount(X)
#1が減った時
if a==1:
    xd=0
else:
    xd=X%(a-1)
#1が増えたとき
xi=X%(a+1)

for i in range(N):
    if xl[i]=='1':
        if a==1:
            print(0)
            continue
        else:
            k=pow(2,N-1-i,a-1)
            x=(xd-k)%(a-1)
    else:
        k=pow(2,N-1-i,a+1)
        x=(xi+k)%(a+1)
    count=1
    while x!=0:
        x%=popcount(x)
        count+=1
    print(count)

Measured memory_bytes: 10840
while true
    n = gets.to_i
    m = gets.to_i
    break if [n, m] == [0, 0]
    h = Hash.new{|h, k| h[k] = []}
    m.times{
        a, b = gets.chomp.split.map(&:to_i)
        h[a] << b
        h[b] << a
    }
    friend = h[1].dup
    h[1].each{|x| h[x].each{|y| friend << y}}
    friend.delete(1)
    puts friend.uniq.length
end


Measured memory_bytes: 6992
n = int(input())
strList = []
timeList = []
for x in range(n):
    s, t = map(str, input().split())
    strList.append(s)
    timeList.append(int(t))
x = input()
id = strList.index(x)
if timeList.count == id: print(0)
else: print(sum(timeList[id + 1:]))

Measured memory_bytes: 3060
from collections import deque

n, q = list(map(int, input().split()))
Q = deque()
[Q.append(deque([])) for _ in range(n)]

for i in range(q):
    query = list(map(int, input().split()))
    t = query[1]

    # enqueue
    if query[0] == 0:
        Q[t].append(query[2])

    # front
    elif query[0] == 1:
        if Q[t]:
            print(Q[t][0])

    # dequeue
    else:
        if Q[t]:
            Q[t].popleft()



Measured memory_bytes: 14540
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    string s; cin >> s;
    ll sec = 1;
    char cur = s[0];
    for (int i=1; i<s.size(); ++i) {
        if (s[i] != cur) { sec++; cur = s[i];}
        else continue;
    }
    cout << sec - 1 << endl;
    return 0;
}

Measured memory_bytes: 512
import sys

import numpy as np
MOD = 10 ** 9 + 7
def cumprod(a, p):
  l = len(a); sql = int(np.sqrt(l) + 1)
  a = np.resize(a, sql ** 2).reshape(sql, sql)
  for i in range(sql - 1): a[:, i+1] *= a[:, i]; a[:, i+1] %= p
  for i in range(sql - 1): a[i+1] *= a[i, -1]; a[i+1] %= p
  return np.ravel(a)[:l]

def make_tables(n=10 ** 9, r=5 * 10 ** 6, p=MOD):
  fac = np.arange(r + 1); fac[0] = 1; fac = cumprod(fac, p)
  ifac = np.arange(r + 1, 0, -1); ifac[0] = pow(int(fac[-1]), p - 2, p)
  ifac = cumprod(ifac, p)[n::-1]
  n_choose = np.arange(n + 1, n - r, -1); n_choose[0] = 1;
  n_choose[1:] = cumprod(n_choose[1:], p) * ifac[1:r+1] % p
  return fac, ifac, n_choose

fac, ifac, n_choose = make_tables(r=10**5)

def choose(n, r, p=MOD):
  # if r > n or r < 0: return 0
  return fac[n] * ifac[r] % p * ifac[n-r] % p

n, k, *a = map(int, sys.stdin.read().split())
a.sort()

def main():
  res = 0
  res = (a[k-1:] * choose(np.arange(k - 1, n), k - 1) % MOD).sum() % MOD
  res -= (a[:n-(k-1)] * choose(np.arange(n-1, k-2, -1), k-1) % MOD).sum() % MOD
  res %= MOD
  print(res)
    
if __name__ == '__main__':
  main()


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

using namespace std;

const int N=1e5;
int n,k;
int arr[N];
int mem[N];

int solve(int i){
    if(i==n-1)
        return 0;
    if(mem[i]!=-1) return mem[i];
    int ret=1000000000;
    for(int j=1;j<=k;++j){
        ret=min(ret,j+i<=n-1?solve(i+j)+abs(arr[i]-arr[i+j]):1000000000);
    }
    return mem[i]=ret;
}

int main() {
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;++i)
        scanf("%d",arr+i);
    memset(mem,-1,sizeof mem);
    printf("%d",solve(0));
    return 0;
}


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

using namespace std;

const int N = 1e5 + 10;
const int mod = 1e9 + 7;

int n, m, cnt, a[N], b[N];
int tmpx[N], tmpy[N], c1, c2;

struct node {
	int x, y;
	bool operator < (const node &T) const {
		return x == T.x ? y > T.y : x < T.x;
	}
}A[N];

struct Fenwick_Tree {
	int s[N];
	void update(int x, int y) {for(; x <= c2; x += x & -x) (s[x] += y) %= mod;}
	int query(int x) {int res = 0; for(; x; x -= x & -x) (res += s[x]) %= mod; return res;}
}T;

void Init() {
	int x; priority_queue<int, vector<int>, greater<int>> q;
	cin >> n >> m;
	for(int i = 1; i <= n; ++ i) cin >> x, q.push(x);
	for(int i = 1; i <= m; ++ i) cin >> b[i]; n = 0;
	while(!q.empty()) {
		int k = q.top(), pos = lower_bound(b + 1, b + m + 1, k) - b; q.pop();
		if(k <= b[1] || k >= b[m] || b[pos] == k) continue;
		A[++ cnt].x = b[pos] - k; A[cnt].y = k - b[pos - 1];
		tmpx[++ c1] = A[cnt].x, tmpy[++ c2] = A[cnt].y;
	}
	sort(tmpx + 1, tmpx + c1 + 1), sort(tmpy + 1, tmpy + c2 + 1);
	c1 = unique(tmpx + 1, tmpx + c1 + 1) - tmpx - 1;
	c2 = unique(tmpy + 1, tmpy + c2 + 1) - tmpy - 1;
	for(int i = 1; i <= cnt; ++ i) {
		A[i].x = lower_bound(tmpx + 1, tmpx + c1 + 1, A[i].x) - tmpx;
		A[i].y = lower_bound(tmpy + 1, tmpy + c2 + 1, A[i].y) - tmpy;
	}
	sort(A + 1, A + cnt + 1);
}

void Solve() {
	int ans = 1;
	for(int i = 1; i <= cnt; ++ i) {
		if(A[i].y == A[i - 1].y && A[i].x == A[i - 1].x) continue;
		int now = T.query(A[i].y - 1) + 1;
		(ans += now) %= mod;
		T.update(A[i].y, now);
	}
	cout << ans << endl;
}

// $$f[i] = (\sum_{j = 1}^{i - 1} f[j]) + 1$$;

int main() {
#ifdef ylsakioi
	freopen("f.in", "r", stdin);
	freopen("f.out", "w", stdout);
#endif
	Init();
	Solve();
	return 0;
}


Measured memory_bytes: 2680
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
    string s;
    cin >> s;
    int q;
    cin >> q;
    string t;
    rep(qi,q) {
        int ty;
        cin >>ty;
        if (ty == 1) {
            swap(s,t);
        } else {
            int f; char c;
            cin >> f >> c;
            if (f == 1) {
                t += c;
            } else {
                s += c;
            }
        }
    }
    reverse(t.begin(), t.end());
    t += s;
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 1128
def main():
    K = int(input())
    visited = [False]*K

    r = 0
    for i in range(1, K+1):
        r = r*10 + 7
        r %= K
        if r == 0:
            print(i)
            exit()

        if visited[r]:
            print(-1)
            exit()
        
        visited[r] = True
    
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 16736
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
using namespace std;


#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>



int main() {
	ll n, m;
	cin >> n >> m;
	vector<ll> s(n);
	ll sum = 0;
	REP(i, n) {
		cin >> s[i];
		sum += s[i];
	}
	sort(ALL(s), greater<ll>());
	bool ok = true;
	REP(i, m) {
		if (s[i] * 4 * m < sum)ok = false;
	}
	cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
   int main(){
   	int a,b,c;
	cin>>a>>b>>c;
	if(a==b){
		if(a!=c){
			cout<<"Yes"<<endl;
			return 0;
		}
		else{
			cout<<"No"<<endl;
			return 0;
		}
	}
	else if(a==c){
		cout<<"Yes"<<endl;
			return 0;
	}
	else if(b==c){
		cout<<"Yes"<<endl;
			return 0;
	}
	else{
		cout<<"No"<<endl;
			return 0;
	}
    return 0;
 }

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

int main(){

    long long int A,B;
    cin >> A >> B;

    long long int GCD,LCM;

    GCD = __gcd(A,B);

    LCM = A / GCD * B;

    cout << LCM << endl;

    return 0;
}

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


int main() {
    vi x(3); rep(i,3) cin >> x[i];
    sort(ALL(x));
    int z = x[2] * 10 + x[1] + x[0];
    cout << z << endl;
    return 0;
}


Measured memory_bytes: 256