akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<functional>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<utility>
#include<map>
#include<queue>

using namespace std;

#define LL long long
#define Linf (1ll<<60)
#define MOD 1000000007
const int dx[4] = { 1,-1,0,0 };
const int dy[4] = { 0,0,1,-1 };
bool OOA(int h, int w, int x, int y) {
	return (x >= h || y >= w || x < 0 || y < 0);
}

typedef pair<LL, pair<LL, LL>> trio;

int dp[100001][15]={};
string S;

int main() {
	cin >> S;
	int N=S.size();
	if(S[0]!='?')dp[0][S[0]-'0'] = 1;
	else for(int i=0; i<10; i++)dp[0][i]=1;
	for(int i=1; i<N; i++){
		for(int j=0; j<13; j++){
			if(S[i]!='?'){
				dp[i][(j * 10 + S[i] - '0') % 13] += dp[i - 1][j];
				dp[i][(j * 10 + S[i] - '0') % 13] %= MOD;
			}
			else{
				for(int k=0; k<10; k++){
					dp[i][(j * 10 + k) % 13] += dp[i - 1][j];
					dp[i][(j * 10 + k) % 13] %= MOD;
				}
			}
		}
	}
	cout << dp[N-1][5]%MOD << endl;
	return 0;
}



Measured memory_bytes: 6272
#include<bits/stdc++.h>
using namespace std;
int main() {
	string W;
	cin >> W;
	int ans = 0;
	string K;
	while (1) {
		cin >> K;
		if (K == "END_OF_TEXT")break;
		int n;
		n = K.size();
		for (int i = 0;i < n;i++) {
			if (K[i] >= 'A' && K[i] <= 'Z') {
				K[i] = K[i] + 32;
			}
		}
		if (K == W) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3176
#include <stdio.h>
main(){
  int a,b,c,x,y,z;
  scanf("%d %d %d",&a,&b,&c);
  if(a>b){
    x=a;
    a=b;
    b=x;
  }
   
  if(b>c){
    y=b;
    b=c;
    c=y;
  }
   
  if(a>b){
    z=a;
    a=b;
    b=z;
  }
  printf("%d %d %d\n",a,b,c);
   
  return 0;
}

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

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

use std::cmp::{max, min};
use std::collections::HashMap;


fn main() {
  let a = read::<i64>();
  let b = read::<i64>();
  let x = read::<i64>();

  if a <= x && x <= a + b {
    println!("YES");
  } else {
    println!("NO");
  }

}



Measured memory_bytes: 4352
from functools import reduce

def factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

def gcd_base(x, y):
    if x % y:
        return gcd_base(y, x%y)
    return y

def gcd(numbers):
    return reduce(gcd_base, numbers)

def lcm_base(x, y):
    res = (x * y) // gcd_base(x, y)
    return res #if res <= 1000000007 else 0 #1000000007を超える場合は0

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)

n = int(input())
a = [int(i) for i in input().split()]
print(lcm(a))


Measured memory_bytes: 6304
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}


int main() {
	double r;
	cin >> r;
	double ans = 2 * M_PI*r;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define LL long long
#define st first
#define nd second
#define endl '\n'
using namespace std;

const int MAXN=100005;
LL fac[MAXN],invfac[MAXN],mod=1e9+7,used[MAXN],n,a[MAXN],other;

LL binpow(LL x,LL y) {

	LL ret=1,tmp=x;
	while(y) {
		if(y&1)
			ret=(ret*tmp)%mod;
		tmp=(tmp*tmp)%mod;
		y/=2;
	}
	return ret;

}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=n+1;++i) {
		cin>>a[i];
		if(used[a[i]]!=0) {
			other=n+1-(i-used[a[i]]+1);
		}
		used[a[i]]=i;
	}
	fac[0]=1;
	for(int i=1;i<MAXN;++i)
		fac[i]=(fac[i-1]*i)%mod;
	for(int i=0;i<MAXN;++i)
		invfac[i]=binpow(fac[i],mod-2);
	for(int i=1;i<=n+1;++i) {
		LL x;
		x=(fac[n+1]*invfac[i])%mod;
		x=(x*invfac[n+1-i])%mod;
		if(other>=i-1) {
			LL y;
			y=(fac[other]*invfac[i-1])%mod;
			y=(y*invfac[other-(i-1)])%mod;
			//cout<<"wat "<<i<<" "<<x<<" "<<y<<" "<<fac[other]<<" "<<other<<endl;
			x=(x-y+mod)%mod;
		}
		cout<<x<<endl;
	}

}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define i_love_u_Phuong ios_base::sync_with_stdio(0); cin.tie(0);


using ll = long long;
using namespace std;
using ld = long double;
int n;
vector<int> a;



int main()
{
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
#endif // ONLINE_JUDGE
    i_love_u_Phuong;
    cin >> n;
    a = vector<int> (n);
    cin >> a[0];
    int sum=a[0];
    for(int i=1; i<n-1; ++i)
    {
        cin >> a[i];
        sum+=min(a[i-1],a[i]);
    }
    sum+=a[n-2];
    cout << sum;

    return 0;
}



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

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

    // solution comes here
    string S;
    cin >> S;

    ll N=S.size(), ans1=0, ans2=0;
    rep(i, N) (S[i] == '0' + i%2) ? ans1++ : ans2++;

    cout << min(ans1, ans2) << nl;
}

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

int main(){
	int n; string s; cin>>n>>s;
	vector<int> r, w;
	for(int i = 0; i<n ; i++){
		if (s[i]=='R')
		r.push_back(i);
		else
		w.push_back(i);
	}
	int c = 0, i = 0, j  = r.size() - 1;
	while(i< w.size()&&j>=0){
		if(w[i]<r[j]){
			i++;
			j--;
			c++;
		}
		else
		break;
	}
	cout<<c;
}


Measured memory_bytes: 4772
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
int state,n=read(),m=read();
ll ans;

struct yuu{
ll a[3];
void duit(){
  for (int i=0;i<3;++i) read(a[i]);
  }
bool operator <(const yuu &h) const{
  ll sum1=0,sum2=0;
  for (int i=0;i<3;++i){
    int t=state&(1<<i)?1:-1;
    sum1+=a[i]*t;
    sum2+=h.a[i]*t;
    }
  return sum1>sum2;
  }
}koyume[1010];

ll work(){
int i,j,k;ll res=0;
sort(koyume+1,koyume+n+1);
for (i=1;i<=m;++i){
  for (j=0;j<3;++j){
    int t=state&(1<<j)?1:-1;
    res+=koyume[i].a[j]*t;
    }
  }return res;
}

int main(){
int i,j;
for (i=1;i<=n;++i) koyume[i].duit();
for (i=0;i<8;++i) state=i,ans=max(ans,work());
write(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>

#include <cmath>
#include <iomanip>

using namespace std;
typedef long long ll;
const double PI=3.14159265358979;

int main(){
  double a,b,x;
  cin >> a >> b >> x;
  
  x/=a;

  double ans;
  if(x<(a*b*0.5)){
    double r=2*x/b;
    ans=atan(b/r);
  }else{
    double r=(2*x-a*b)/a;
    ans=atan((b-r)/a);
  }

  cout << fixed << setprecision(10);
  cout << 180*ans/PI << endl;
  
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    string t;
    cin >> t;
    rep(i,t.size()){
        if(t[i] == '?'){
            t[i] = 'D';
        }
    }
    cout << t << endl;
}

Measured memory_bytes: 3720
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define alll(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}cout<<endl;}


pair<ll, ll> findnear(ll x, const vector<ll> &s, ll l, ll r){
    if (r - l <= 1) {
        return make_pair(l, r);
    }
    ll mid = (r + l )/2;
    if(s[mid] <= x) return findnear(x, s, mid, r);
    else return findnear(x, s, l, mid);
}

int main() {
    ll a,b,q;
    cin>>a>>b>>q;
    vector<ll> s(a),t(b),x(q);
    rep(i, a) cin>>s[i];
    rep(i, b) cin>>t[i];
    rep(i, q) cin>>x[i];
    unordered_map<ll,ll> ms, mt;

    ll ii=0;
    ll jj=0;
    auto mins=s[ii];
    auto mint=t[jj];
    while(1){
        if (ii >= a || jj >=b ) {
            break;
        }
        mins=s[ii];
        mint=t[jj];
        auto diff = abs(mins - mint);
        ms[mins] = ms[mins] == 0 ? diff : min(diff, ms[mins]);
        mt[mint] = mt[mint] == 0 ? diff : min(diff, mt[mint]);
        if (mins<mint) {
            ii++;
        }else jj++;
    }
    while( ii < a){
        mins=s[ii];
        mint=t[jj - 1];
        auto diff = abs(mins - mint);
        ms[mins] = ms[mins] == 0 ? diff : min(diff, ms[mins]);
        mt[mint] = mt[mint] == 0 ? diff : min(diff, mt[mint]);
        ii++;
    }

    while( jj < b){
        mins=s[ii - 1];
        mint=t[jj];
        auto diff = abs(mins - mint);
        ms[mins] = ms[mins] == 0 ? diff : min(diff, ms[mins]);
        mt[mint] = mt[mint] == 0 ? diff : min(diff, mt[mint]);
        jj++;
    }

    for(auto xx : x)
    {
            pair<ll, ll> p1 = findnear(xx, s, 0, s.size()-1);
            pair<ll, ll> p2 = findnear(xx, t, 0, t.size()-1);
            auto aa = abs(s[p1.first] - t[p2.first]) + min(abs(xx - s[p1.first]),abs(xx- t[p2.first]));
            auto bb = abs(s[p1.first] - t[p2.second]) + min(abs(xx - s[p1.first]),abs(xx- t[p2.second]));
            auto cc = abs(s[p1.second] - t[p2.first]) + min(abs(xx - s[p1.second]),abs(xx- t[p2.first]));
            auto dd = abs(s[p1.second] - t[p2.second]) + min(abs(xx - s[p1.second]),abs(xx- t[p2.second]));
        pr(min(min(aa,bb),min(cc,dd)));
    }
}



Measured memory_bytes: 13732
h, w, a, b = map(int, input().split())
s = [[1 for _ in range(a)] + [0 for _ in range(w-a)] for _ in range(b)]
for _ in range(h-b):
  s.append([0 for i in range(a)] + [1 for i in range(w-a)])
for i in range(h):
  print(''.join(list(map(str, s[i]))))

Measured memory_bytes: 11892
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long h,m,h2,m2,an=0,k;
    cin>>h>>m>>h2>>m2>>k;
    an+=abs(h-h2)*60;
    an-=m;
    an+=m2;
    an-=k;
    if(an<0)
    {
        an=0;
    }
    cout<<an<<endl;

}

Measured memory_bytes: 3624
#include<stdio.h>
int main()
{
    int a,b,m,n,i,j,k,l;
    scanf("%d",&n);

    a=n/100;
    b=n%100;

      if((a>=1 && a<=12) && (b>=1 && b<=12))
        printf("AMBIGUOUS\n");
        else if(a>=1 && a<=12)
        printf("MMYY\n");
    else if(b<=12 && b>=1)
        printf("YYMM\n");

    else
        printf("NA\n");

    return 0;
}


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

using namespace std;

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

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n, m;
	cin >> n >> m;

	vector<int> c(n), t(n);
	for (int i = 0; i < n; i++) {
		cin >> c[i] >> t[i];
	}

	int cost = INT_MAX;
	for (int i = 0; i < n; i++) {
		if (t[i] <= m && cost > c[i]) {
			cost = c[i];
		}
	}

	cout << (cost == INT_MAX ? "TLE" : to_string(cost)) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(150) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N;
  Vec(P,lli,N,0);
  Vec(Q,lli,10000,0);
  rep(i,0,N)cin >> P[i];
  rep(i,0,N)Q[P[i]]++;
  Sort(P);
  rep(i,1,10000)Q[i]+=Q[i-1];
  rep(i,0,N)rep(j,i+1,N){
    A=abs(P[i]-P[j]);
    B=P[i]+P[j];
    sum+=Q[B-1]-Q[A];
    if(A<P[i]&&P[i]<B)sum--;
    if(A<P[j]&&P[j]<B)sum--;
  }
  Out(sum/3);
}

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

int main() {
  string s,t;
  cin>>s>>t;
  map<char,int>sn,tn;
  for(int i=0;i<s.size();i++){
    sn[s[i]]++;
    tn[t[i]]++;
  }
  vector<int>si,ti;
  for(auto p:sn){
    si.push_back(p.second);
  }
  for(auto p:tn){
    ti.push_back(p.second);
  }
  sort(si.begin(),si.end());
  sort(ti.begin(),ti.end());
  if(si==ti)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 3896
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


A = [LI() for _ in range(3)]
N = I()
flag = [[0]*3 for _ in range(3)]

for i in range(N):
    b = I()
    for j in range(3):
        for k in range(3):
            if A[j][k] == b:
                flag[j][k] = 1

for i in range(3):
    if flag[i][0] == flag[i][1] == flag[i][2] == 1 or flag[0][i] == flag[1][i] == flag[2][i] == 1:
        print('Yes')
        exit()

if flag[0][0] == flag[1][1] == flag[2][2] == 1 or flag[0][2] == flag[1][1] == flag[2][0] == 1:
    print('Yes')
    exit()

print('No')


Measured memory_bytes: 61716
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <bitset>
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a,n) for(ll i=n;i>=a;i--)
#define elif else if
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF = 1e+17;
const ll MODcdf = 998244353;
bool pairCompare(const P& firstElof,const P& secondElof){
    return firstElof.first<secondElof.first;
}
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n,cap[5];cin>>n;
    rep(i,0,5)cin>>cap[i];
    ll lst=INF;
    rep(i,0,5)lst=min(lst,cap[i]);
    ll ans=4;
    if(n%lst==0)ans+=n/lst;
    else ans+=n/lst+1;
    cout<<ans<<endl;
}


Measured memory_bytes: 888
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let n: i64 = s.trim().parse().unwrap();

    println!(
        "{}",
        (1..=n)
            .filter(|&e| !(e % 5 == 0 || e % 3 == 0))
            .sum::<i64>()
    );
}

Measured memory_bytes: 2160
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll quick_m(int k)
{
    ll sum=5,ans=1;
    while(k)
    {
        if(k&1)
            ans*=sum;
        k=k>>1;
        sum=sum*sum;
    }
    return ans;
}
int main()
{
    ll n;
    cin>>n;
    if(n%2)
        cout<<0;
    else
    {
        ll ans=0;
        n=n/2;
        for(ll i=1; ; i++)
        {
            ll p=quick_m(i);
            if(p>n)
                break;
            ans+=n/p;
        }

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


Measured memory_bytes: 256
#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(){
  char s;
  cin >> s;
  if(isupper(s)) cout << "A" << endl;
  else cout << "a" << endl;
}

Measured memory_bytes: 3624
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>

using namespace std;

int main(void) {
	char S[1001];
	int len, w;

	scanf("%s", S);
	scanf("%d", &w);
	len = strlen(S);

	for (int i=0; i < len; i += w) {
		printf("%c", S[i]);
	}
	printf("\n");


	return 0;
}









Measured memory_bytes: 128
#include <bits/stdc++.h>
#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 _GLIBCXX_DEBUG
#define V vector<int>
#define ll long long
using namespace std;

pair<int, int> p;

int main() {
    // pairをつかう？
    int n; cin >> n;
    int a[n];
    rep(i, 0, n) cin >> a[i];
    vector<pair<int, int>> v(n);
    rep(i, 0, n){
        v[i].first = a[i];
        v[i].second = i+1;
    }

    sort(v.begin(), v.end());
    rep(i, 0, n){
        cout << v[i].second << " ";
    }
    cout << endl;
}


Measured memory_bytes: 2048
s = input()

ans1 = 0
ans2 = 0

for i in range(len(s)):
    if i%2==0:
        if s[i]=='0':
            ans1+=1
        else:
            ans2+=1
    else:
        if s[i]=='1':
            ans1+=1
        else:
            ans2+=1

print(min(ans1,ans2))

Measured memory_bytes: 39536
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define ld          long double
#define endl        "\n"

const int mod = 1e9+7;

inline int add(int a, int b) { int res = a + b; if(res >= mod) res -= mod;  return res; }
inline int sub(int a, int b) { int res = a - b; if(res < 0) res += mod; return res;}
inline int mul(int a, int b) { return (a * b)%mod; }

const int N = 55;
int n, m;
int dep[N];
int fa[N];
int path[22];
vector<int> g[N];

void rec(int u) {
    for(int v : g[u]) if(v != fa[u]) {
        fa[v] = u;
        dep[v] = dep[u] + 1;
        rec(v);
    }
}

void solve() {
    cin >> n;
    for(int i=1; i<n; i++) {
        int u, v; cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    rec(1);
    cin >> m;
    for(int i=0; i<m; i++) {
        int u, v; cin >> u >> v;
        if(dep[u] < dep[v]) swap(u, v);
        while(dep[u] > dep[v]) {
            path[i] |= (1LL << (u - 1));
            u = fa[u];
        }   // Now, both u & v at same level, so find LCA
        while(u != v) {
            path[i] |= (1LL << (u - 1)) | (1LL << (v - 1));
            u = fa[u], v = fa[v];
        }
    }
    int ans = 0;
    for(int i=0; i < (1LL << m); i++) {
        int cnt = 0, white = 0;
        int msk = 0;
        for(int j=0; j<m; j++) if(i & (1LL << j)) cnt++, msk |= path[j];
        for(int j=0; j<n; j++) if(msk & (1LL << j)) white++;
        //ans += (cnt%2 ? -1 : 1) * (1LL << (n - white - 1));
        if(cnt%2) ans -= (1LL << (n - white - 1));
        else ans += (1LL << (n - white -1 ));
    }
    cout << ans << endl;
}

signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(12);

    int T = 1;
    //cin >> T;

    while(T--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		System.out.println((int) Math.ceil((double)(n - 1) / (k - 1)));
	}
}


Measured memory_bytes: 50088
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <cmath>
#include <bitset>
#include <queue>
#include <set>
#include <numeric>
#include <unordered_set>

using namespace std;

#define ef emplace_front
#define eb emplace_back
#define mp make_pair
#define MOD 1000000007

typedef long double f80;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef float f32;
typedef double f64;
typedef long double f80;
typedef unordered_set<int> usi;
typedef set<int> si;

ll gcd(ll a, ll b){
	if (!b)return a;
	return gcd(b,a%b);
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);
	
	ll a,b;
	cin>>a>>b;
	cout<<a/gcd(a,b)*b;
}

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

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

    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    cout << s1[0] << s2[1] << s3[2] << "\n";

    return 0;
}


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

using namespace std;

long long cnt[10][10];

void solve() {
    int n; cin >> n;
    if (n < 10) { cout << n; return; }
    int mul = 1;
    for (int i = 1; i <= n; i++) {
        if (mul * 10 <= i) mul *= 10;
        int first = i / mul, last = i % 10;
        cnt[first][last]++;
    }
    long long ans = 0;
    for (int first = 0; first < 10; first++) {
        for (int last = first; last < 10; last++) {
            if (first == last)
                ans += cnt[first][last] * cnt[last][first];
            else
                ans += cnt[first][last] * cnt[last][first] * 2;
        }
    }
    cout << ans;
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;

struct Graph
{
    int n;
    vector<vector<int>> g;
    
    Graph(int n) : n(n){
        g.resize(n);
    }
    
    void init(int n_){
        n = n_;
        g.resize(n_);
    }
    
    void add_edge(int from, int to){
        g[from].push_back(to);
    }
};

struct SCCD    //StronglyConnectedComponentsDecomposition
{
    vector<vector<int>> g;
    vector<vector<int>> rg;
    int n;
    vector<bool> used;
    vector<int> cmp;
    vector<int> vs;
    
    SCCD(Graph &g_){
        n = g_.n;
        g.resize(n);
        rg.resize(n);
        for(int u = 0; u < n; u++) for(int v : g_.g[u]){
            g[u].push_back(v);
            rg[v].push_back(u);
        }
        used.resize(n);
        cmp.resize(n);
    }
    
    void dfs(int u){
        used[u] = true;
        for(int v : g[u]){
            if(!used[v]) dfs(v);
        }
        vs.push_back(u);
    }
    
    void rdfs(int u, int k){
        used[u] = true;
        cmp[u] = k;
        for(int v : rg[u]){
            if(!used[v]) rdfs(v, k);
        }
    }
    
    int decomposition(){
        fill(used.begin(), used.end(), false);
        for(int i = 0; i < n; i++){
            if(!used[i]) dfs(i);
        }
        fill(used.begin(), used.end(), false);
        int k = 0;
        for(int i = n - 1; i >= 0; i--){
            if(!used[vs[i]]){
                rdfs(vs[i], k);
                k++;
            }
        }
        return k;
    }
};

int b[100002];

bool BipartiteGraph(Graph &g, int i){
    queue<int> que;
    b[i] = 1;
    que.push(i);
    while(que.size()){
        int u = que.front();
        que.pop();
        for(int v : g.g[u]){
            if(b[u] == b[v]){
                return false;
            }
            if(b[v] == 0){
                b[v] = 3 - b[u];
                que.push(v);
            }
        }
    }
    return true;
}

int main()
{
    ll n, m;
    cin >> n >> m;
    Graph g(n);
    for(int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;
        u--; v--;
        g.add_edge(u, v);
        g.add_edge(v, u);
    }
    SCCD scc(g);
    ll k = scc.decomposition();
    bool l[100002]{0};
    ll s[100002]{0};
    for(int i = 0; i < n; i++) s[scc.cmp[i]]++;
    ll t[3]{0};
    for(int i = 0; i < n; i++){
        if(l[scc.cmp[i]]) continue;
        l[scc.cmp[i]] = true;
        if(s[scc.cmp[i]] == 1) t[2]++;
        else if(BipartiteGraph(g, i)) t[1]++;
        else t[0]++;
    }
    ll ans = n * n - (n - t[2]) * (n - t[2]) + (k - t[2]) * (k - t[2]) + t[1] * t[1];
    cout << ans << endl;
}

Measured memory_bytes: 22140
#include <stdio.h>
#include <string.h>
#define lop(i, n) for(i=0; i<n; i++)

int main()
{
	int n, m, i, cor=0, pen=0;
	int f[100000]={0};
	int p[100000];
	char s[2];
	
	scanf("%d %d", &n, &m);
	
	lop(i, m){
		scanf("%d %s", &p[i], s);
		if(f[p[i]]!=-1 && strcmp(s,"WA")==0){
			f[p[i]]++;
		}
		else if(f[p[i]]!=-1 && strcmp(s,"AC")==0){
			cor++; pen+=f[p[i]]; f[p[i]]=-1;
		}
		else{
			continue;
		}
	}
	
	printf("%d %d", cor, pen);
	
return 0;
}

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

typedef long long LL;

void chmin(LL &x, LL y){ x = min(x, y); }

int main(){
	const LL INF = 1LL << 60;
	ios::sync_with_stdio(false);

	int n, k;
	cin >> n >> k;
	vector<LL> hs(n + 1);
	for(int i = 1; i <= n; ++i){
		cin >> hs[i];
	}

	vector<vector<LL>> dp1(k + 1, vector<LL>(n + 2, INF)), dp2;
	dp1[0][0] = 0;
	for(int x = 1; x <= n; ++x){
		dp2.assign(k + 1, vector<LL>(n + 2, INF));
		for(int y = 0; y <= k; ++y)
		for(int z = 0; z < x; ++z){
			if(y < k){ chmin(dp2[y + 1][z], dp1[y][z]); }
			chmin(dp2[y][x], dp1[y][z] + max(hs[x] - hs[z], 0LL));
		}
		dp1.swap(dp2);
	}
	LL ans = INF;
	for(const auto &v : dp1){
		chmin(ans, *min_element(v.begin(), v.end()));
	}
	cout << ans << '\n';
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 1e6+200;
int main(){
   string s;
   cin>>s;
   ll sum = 0,numb = 0;
   for(ll i=0;i<s.length();i++){
     if(s[i] == 'W'){
       numb++;
       sum += (i+1) - numb;
     }
   }
   cout<<sum<<endl;
   return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstring>

using namespace std;


int main(){


string str;
int n;
int cou = 0;

cin >> str;

n = sizeof(str);

if(str[0] != 'C') cou++;
if(str[1] != 'O') cou++;
if(str[2] != 'D') cou++;
if(str[3] != 'E') cou++;
if(str[4] != 'F') cou++;
if(str[5] != 'E') cou++;
if(str[6] != 'S') cou++;
if(str[7] != 'T') cou++;
if(str[8] != 'I') cou++;
if(str[9] != 'V') cou++;
if(str[10] != 'A') cou++;
if(str[11] != 'L') cou++;
if(str[12] != '2') cou++;
if(str[13] != '0') cou++;
if(str[14] != '1') cou++;
if(str[15] != '6') cou++;


 cout << cou << endl;

}


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

int main() {
    int p; cin >> p;
    int a[p]; for (int i = 0; i < p; i++) cin >> a[i];
    int ans[p];
    memset(ans, 0, sizeof(ans));
    for (int i = 0; i < p; i++) ans[0] += a[i];
    ans[p-1] -= a[0];
    for (int i = 1; i < p; i++) {
        int pw = 1;
        for (int j = 0; j < p; j++) {
            ans[p-1-j] -= a[i] * pw;
            pw = pw * i % p;
        }
    }
    for (int i = 0; i < p; i++) cout << (ans[i] % p + p) % p << ' ';
    cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

//#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

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; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    int n; cin >> n;
    vint a(n - 1);vin(a);
    vint ans(n, 0);
    rfor(x, a) {
        ans[x - 1]++;
    }
    rfor(c, ans) {
        print(c);
    }

    return 0;
}



Measured memory_bytes: 4840
#!/usr/bin/python3

n, m = [int(_) for _ in input().split()]
ab = []
for i in range(m):
    a, b = [int(_) for _ in input().split()]
    ab.append((a, b))

ab.sort(reverse=True)
x = ab[0][0]
ans = 1
for i in ab:
    if i[1] <= x:
        x = i[0]
        ans += 1

print(ans)


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

using namespace std;

int main() {
//    ios::sync_with_stdio(false);
//    cin.tie(nullptr);
    long long n;
    cin >> n;
    long long ans = 1e18;
    for (long long i = 1; i * i <= n; i++) {
        if (i * (n / i) == n) {
            ans = min(ans, i + n / i);
        }
    }
    cout << ans - 2;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//dp[l][r]->(x-y)in the range l to r both inclusive

int main()
{
  int n;
  cin>>n;
  vector<long long> v(n);
  for(long long &x:v)
  cin>>x;
  vector<vector<long long>> dp(n,vector<long long>(n,INT_MIN));
  for(int l=n-1;l>=0;l--)
  {
      for(int r=l;r<n;r++)
      {
          if(l==r)
          dp[l][r]=v[l];
          else
          dp[l][r]=max(v[l]-dp[l+1][r],v[r]-dp[l][r-1]);
      }
  }
  cout<<dp[0][n-1]<<endl;
  return 0;
}













Measured memory_bytes: 70784
#include <iostream>
using namespace std;
int main() {
	int  x;
		char p;
		int y;
		char q;
		int z;


	cin >> x>>p>>y>>q>>z;
	if (x <= 2018)
		cout << "Heisei";
	else
		if (x >= 2020)
			cout << "TBD";
		else
			if (y <= 4)
				cout << "Heisei";
			else
				cout << "TBD";
			


}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,a,b,c,d,e;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	n=0;
	if(a<b&&a<c){
		n=a;
	}
	else if(b<a&&b<c){
		n=b;
	}
	else{
		n=c;
	}
	if(d<e){
		n=n+d;
	}
	else{
		n=n+e;
	}
	n=n-50;
	printf("%d\n",n);
	return 0;
}


Measured memory_bytes: 2056
import math
n = int(input())
li = [int(input()) for i in range(n)]
cnt = 0
def shell_sort(li, n):
    m = math.floor(math.log(2*n+1, 3))
    G = [round((3**i-1)/2) for i in range(m, 0, -1)]
    for i in range(m):
        insertionSort(li, n, G[i])
    return m, G
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i-g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j-g
            cnt += 1
        A[j+g] = v

m, G = shell_sort(li, n)

print(m)
strG = [str(i) for i in G]
print(' '.join(strG))
print(cnt)
for i in li:
    print(i)


Measured memory_bytes: 45588
#include <iostream> 
#include <cstdio>

using namespace std;

#define For(i , a , b) for (int i = a , _b = b ; i <= _b ; ++i)
#define Ford(i , a  ,b) for (int i = a , _b = b : i >= _b ; --i)
#define Rep(i , n) for (int i = 0 , _n = n ; i < _n ; ++i)
#define sz(A) ((int)A.size())
#define LL(x) (x << 1)
#define RR(x) ((x << 1) | 1)

typedef pair<int , int> pt;

const int maxn = 100000 + 123;
int n, m;
int x[maxn];

void ReadData() {
	cin >> n >> m;
	For(i,1,m) {
		int a,b; cin >> a >> b;
		x[a] ^= 1;
		x[b] ^= 1;
	}

	if (x[1]) {
		cout << "NO" << endl;
		return;
	}
	For(i,2,n) if (x[i] != x[1]) {
		cout << "NO" << endl;
		return;
	}

	cout << "YES" << endl;
}


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

	return 0;

}			

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

using namespace std;

#define pb push_back
#define mp make_pair
#define lli long long int
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define mii map<lli,lli>
#define msi map<string,lli>
#define pii pair<lli,lli> 
#define vi vector<lli> 
#define vvi vector< vector<lli> >
#define sz(x) (lli)x.size()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX1 998244353
#define MAX2 1000000007
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define input(data,n,command) for(lli i=0;i<n;i++){lli tmp;cin>>tmp;data.pb(tmp);command}
#define sort_asc(a) sort(a.begin(),a.end());
//#define sort_desc(a) sort(a.begin(),a.end(),greater<lli>());
#define display(a) for(lli i = 0 ;i<a.size();i++){cout<<a[i]<<" ";} cout<<endl;
#define rep(i,a,b) for(lli i = a;i < b;i++)
#define endl "\n"

//Written By MUDIT BHARDWAJ...
/*--------------------------------------------------------------------*/
//vector<pair<lli,lli>>adj[300010];

lli solve()
{
    //start from here
    lli n;
    cin>>n;
    string s;
    cin>>s;
    lli start = 0,end = n-1;
    lli ans = 0;
    while(start <= end)
    {
    	if((s[start] == 'W')&&(s[end] == 'R'))
    	{
    		swap(s[start],s[end]);
    		start++;
    		end--;
    		ans++;
    	}
    	else if(s[start] == 'W')
    	{
    		if(s[end] == 'W')
    		{
    			end--;
    		}
    	}
    	else if(s[end] == 'R')
    	{
    		if(s[start] == 'R')
    		{
    			start++;
    		}
    	}
    	else if((s[start] == 'R')&&(s[end] == 'W'))
    	{
    		start++;
    		end--;
    	}
    }
    cout<<ans;
    return 0;
}

int main()
{
    ios
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    lli T=1;
    //cin>>T;
    while(T--)
    {
        solve();
    }
    return 0;
}
/*-----------------------------------------------------------------------*/

Measured memory_bytes: 3760
import sys
s= input()

a = s[0]
b = []
count = 0
for i in range(3):
    if s[i+1] == a:
        count += 1
    else:
        b.append(i+1)

if count == 1:
    if s[b[0]] == s[b[1]]:
        print("Yes")
    else:
        print("No")
else:
    print("No")
    







                                        




    




        


    







        



Measured memory_bytes: 3060
//
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define MOD 1000000007
#define PI 3.14159265
#define EPS 1e-9
#define Pi acos(-1.0)
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;

/*CODE START HERE*/

int n, a, b;
int aux, sum, temp;

int main(){
    ios::sync_with_stdio(0);
    cin >> n >> a >> b;
    sum = 0;
    forr(i,1,n+1){
        aux = i;
        temp = 0;
        while(aux){
            temp += aux%10;
            aux/=10;
        }

        if(temp>=a && temp<=b){
            sum += i;
        }
    }
    cout << sum << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)


void solve(long long N, std::vector<long long> h){
    h.push_back(0LL);
    ll i=0, j=0, cnt = 0;
    while(1){
        while(i<N && h[i]==0)
            i++;
        if(i == N)
            break;
        
        j=i;
        while(h[j]>0)
            j++;
        for(ll k=i; k<j; k++){
            h[k]--;
        }
        cnt ++;
    }
    cout << cnt << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> h(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&h[i]);
    }
    solve(N, std::move(h));
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
    int i, ans = 0;
    char s[4];

    scanf("%s", s);
    for(i = 0; i < 3; i++) {
        if(s[i] == '1') {
            ans++;
        }
    }

    printf("%d", ans);
    return 0;
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

template<class T>
inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
};

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
};

const ll MAX = 1e6+5;

// エラトステネスの篩
struct Sieve {
  ll n;
  vl f, primes;
  Sieve(ll n = 1): n(n), f(n+1) {
    f[0] = f[1] = -1ll;
    for (ll i = 2; i <= n; i++) {
      if (f[i]) continue;
      primes.pb(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i; // jの最小の素因数
      }
    }
  }

  bool isPrime(int x) { return f[x] == x; }

  // 素因数分解
  vl factorList(ll x) {
    vl res;
    while (x != 1ll) {
      res.pb(f[x]);
      x /= f[x];
    }
    return res;
  }

  vpl factor(ll x) {
    vl fl = factorList(x);
    if (fl.size() == 0) return {};

    vpl res(1, PLL(fl[0], 0));

    for (int p: fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }

    return res;
  }
};

const ll MOD = 1e9+7;

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

  int N;
  cin >> N;

  Sieve sieve(N+1);
  map<ll, ll> mp;

  rep(i, 1, N+1) {
    auto fl = sieve.factorList(i);
    for (auto ele: fl) {
      mp[ele]++;
    }
  }

  ll ans = 1;
  for (auto pi: mp) {
    ans *= (pi.second+1);
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
};


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

int main() {
    float a,b;
    int ans;
    cin >> a >> b;
    for (int m = 0;m<=100;m++) {
        if (a+b > 2*(m-1) && 2*m >= a+b){
            ans = m;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3680
#include <iostream>
using namespace std;
int main(){
    int N;
    long long temp;
    cin>>N;
    for(int i=0;i<N;++i){
        cin>>temp;
        if((temp&1)==1) {
            cout << "first" << endl;
            return 0;
        }
    }
    cout<<"second"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstring>

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORN(i, a, b) for (int i = a; i <= b; i++)
#define P(s) cout << s << endl
#define PC(condition, _true, _false) if (condition) _true; else _false;

using namespace std;
//
// Created by karayuu on 2019-3-28.
//

/**
 * 配列の要素を表示します.(1 2 3 4 5)のような感じ.
 *
 * @param a 表示したい配列
 * @param n 配列の要素数
 */
void printArray(const int a[], int n) {
    FOR(i, 0, n) {
        if (i != 0) {
            cout << " ";
        }
        cout << a[i];
    }
    cout << endl;
}

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

    int a[1000] = {0};
    FOR(i, 0, n) {
        cin >> a[i];
    }

    printArray(a, n);

    FOR(i, 0, n) {
        //a[0]は無視する
        if (i == 0) continue;

        //a[i]を入れておく
        int v = a[i];
        //探索する一番最後のオリジン
        int o = i - 1;

        //a[0]よりは右にあり,右のほうが大きかったとき
        while (o >= 0 && a[o] > v) {
            //右と入れ替える
            swap(a[o],a[o + 1]);
            o--;
        }

        FOR(j, 0, n) {
            if (j != 0) {
                cout << " ";
            }
            cout << a[j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 3108
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
using namespace std;

int main(void){
    int n;
    double x[4],y[4],a,b,c,d,det;
    cin >> n;
    rep(j,n) {

    
    //入力を多少簡略化
    for(int i=0;i<4;i++) {
        cin >> x[i] >> y[i];
    }
    //(x1,y1)(x2,y2)を結ぶax+by=p の係数
    a = y[0]-y[1];  b = x[1]-x[0];
    //(x3,y3)(x4,y4)を結ぶcx+dy=q の係数
    c = y[2]-y[3];  d = x[3]-x[2];
    //係数についての行列式
    det = a*d-c*b;
    if(fabs(det) < 0.0000000001) cout << "YES" << endl;
    else cout << "NO" << endl;
    }
}


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

typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define mp make_pair

const int N = 210;
int n, L, a[N];

int main(){
    while(~scanf("%d %d", &n, &L)){
        int sum = 0;
        for(int i=1; i<=n; i++){
            a[i] = L + i - 1;
            sum += a[i];
        }
        int d = abs(a[1]);
        int ans = sum - a[1];
        for(int i=2; i<=n; i++){
            if(abs(a[i]) < d){
                d = abs(a[i]);
                ans = sum - a[i];
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  ll k;
  cin >> n >> k;

  map<int, ll> mp;
  rep(i, 1, 100001) mp[i] = 0;

  rep(i, 0, n) {
    int a, b;
    cin >> a >> b;
    mp[a] += b;
  }

  ll acc = 0;
  for (auto m : mp) {
    acc += m.second;
    if (acc >= k) {
      cout << m.first << endl;
      break;
    }
  }
}


Measured memory_bytes: 6528
/* Author - xorier4104 */

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>


using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define MOD 			(int) 1e9+7
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define mem(a,b)        memset(a,(b),sizeof(a))
#define max(a,b)        ((a)>(b) ? (a):(b))
#define min(a,b)        ((a)<(b) ? (a):(b))
#define abs(a)          ((a)>0 ? (a):(-(a)))
#define sq(a) 			((a)*(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)

int main(){ FastIO;

	int n,sum=0;
	cin>>n;
	while(n>4){
		if(n>=500){
			sum+=1000;
			n-=500;
		}
		else if(n>=5 && n<500){
			sum+=5;
			n-=5;
		}
	}
	cout<<sum<<endl;

return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

def abc080_c_np():
    N = int(readline())  # 他店の数
    # 他店の営業パターン：店→日付→営業01
    F = np.zeros((N, 10), dtype=np.int8)
    for i in range(N): F[i] = readline().split()
    # 他店と何回重なると利益がどうなるか：店→重複回数→利益
    P = np.zeros((N, 11), dtype=np.int32)
    for i in range(N): P[i] = readline().split()
    ans = -10**12  # 最悪 100 * -10**7

    # bit全探索
    from itertools import product
    for mask in product(range(2), repeat=10):
        if mask.count(1) == 0: continue
        profit = 0
        mask_np = np.array(mask, np.int8)
        for i in range(N):
            # 他店iの営業パターンと、自店の営業パターンmaskと、の要素積は、重複する営業日
            overlap = np.logical_and(F[i,:], mask_np).sum()
            profit += P[i, overlap]
        ans = max(profit, ans)
    print(ans)

abc080_c_np()

Measured memory_bytes: 14436
K = int(input())
A = list(map(int, input().split()))

def main():
    mi = ma = 2
    for a in A[::-1]:
        if mi % a:
            mi += a - (mi % a)
        ma += (a - 1) - (ma % a)
        if ma < mi:
            print(-1)
            return
    print(mi, ma)

main()


Measured memory_bytes: 14252