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

#define int long long

using namespace std;

const int maxn = 1e5 + 10, mod = 1e9 + 7;
int dp[maxn][2], n;
vector<int> adj[maxn];

void dfs(int u = 1, int par = 0)
{
    dp[u][0] = dp[u][1] = 1;
    for (int v : adj[u])
        if (v != par)
        {
            dfs(v, u);
            (dp[u][0] *= dp[v][0] + dp[v][1]) %= mod;
            (dp[u][1] *= dp[v][0]) %= mod;
        }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin >> n;

    for (int i = 0, u, v; i < n - 1; i++)
        cin >> u >> v, adj[u].push_back(v), adj[v].push_back(u);
    dfs();

    cout << (dp[1][0] + dp[1][1]) % mod;

    return 0;
}


Measured memory_bytes: 14208
#include <iostream>
#include <string>
using namespace std;
int main() {
  int N, K;
  string S;
  cin >> N >> K >> S;
  K=K-1;
  if (S.at(K)=='A') {
    S.at(K)='a';
  }
  else if (S.at(K)=='B') {
    S.at(K)='b';
  }
  else if (S.at(K)=='C') {
    S.at(K)='c';
  }
  cout << S <<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        //int n = sc.nextInt();
        int flag = 0;
        for(int i=1;i<=5;i++){
            int x = sc.nextInt();
            if(x == 0)flag=i;
        }
        System.out.println(flag);
    }
}


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

const long long MOD = 1e9+7;

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

    long long ans = 1;
    vector<long long> cnt(3);
    for (int i = 0; i < n; i++) {
        long long a;
        cin >> a;

        long long c = 0;
        bool done = false;
        for (int j = 0; j < 3; j++) {
            if (cnt.at(j) == a) {
                c++;
                if (!done) {
                    cnt.at(j)++;
                    done = true;
                }
            }
        }

        ans *= c;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define lo long long 
#define inf 1000000000
#define md 1000000007
#define pb push_back
#define li 100005
using namespace std;
lo int n,A[li],cev,B[li];
set<lo int> s;
int main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&A[i]);
	for(int i=1;i<=n;i+=1){
		B[i]=A[i];
	}
	sort(B+1,B+n+1);
	for(int i=1;i<=n;i+=2){
		s.insert(B[i]);
	}
	for(int i=1;i<=n;i+=2){
		if(s.find(A[i])==s.end()) cev++;
	}
	printf("%lld\n",cev);
	return 0;
}



Measured memory_bytes: 4096
// 2020 05 02
// ABC166 B Trick or Treat
#include <algorithm>
#include <complex>
#include <string>
#include <deque>
#include <iostream>
#include <set>
#include <stack>
#include <string>
#include <queue>
#include <utility>
#include <vector>
#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() {
    int n, k;
    cin >> n >> k;
    vector<int> snuke(n, 0);
    for (int i = 0; i < k; i++) {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++) {
            int a;
            cin >> a;
            snuke[--a]++;
        }
    }
    int ans = 0;
   /* for(auto i : snuke) {
        cout << i << " ";
    }
    cout << endl;*/
    
    rep(i, n) {
        if(snuke[i] == 0) ans++;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3620
from collections import defaultdict
import heapq

V, E = map(int, input().split())

edges = defaultdict(list)

for _ in range(E):
    s, t, w = map(int, input().split())
    edges[s].append((t, w))
    edges[t].append((s, w))

in_tree = [False] * V
ans = 0
start = 0
in_tree[start] = True

q = [(w, start, t) for t, w in edges[start]]
heapq.heapify(q)

while q:
    w, s, t = heapq.heappop(q)
    if in_tree[s] == in_tree[t]:
        continue
    ans += w
    in_tree[t] = True
    for tt, w in edges[t]:
        heapq.heappush(q, (w, t, tt))

print(ans)




Measured memory_bytes: 44480
// All Heil Fire Lord Zuko

#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define PB push_back
#define debug(x) cerr << #x << " = " << x << endl

#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef long double ld;

const int N = 2 * 100 * 1000 + 19;

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int a, b;
    cin >> a >> b;
    if (a + b >= 10)
        cout << "error";
    else
        cout << a + b;
    return 0;
}



Measured memory_bytes: 256
n = [ input().split() for x in range(int(input()))]

curr = [0,0,0]
tf = 1

for t in n:
    plc = [int(x) for x in t]
    dif = plc[0]-curr[0] - (plc[1]-curr[1] + plc[2]-curr[2])
    if dif < 0 or dif % 2 != 0:
        tf = 0
        break

if tf:
    print("Yes")
else:
    print("No")

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
	is >> p.first >> p.second;
	return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
	os << p.first << " " << p.second;
	return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}
/*
typedef __int128_t Int;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
  if (s) {
	__uint128_t tmp = value < 0 ? -value : value;
	char buffer[128];
	char *d = std::end(buffer);
	do {
	  --d;
	  *d = "0123456789"[tmp % 10];
	  tmp /= 10;
	} while (tmp != 0);
	if (value < 0) {
	  --d;
	  *d = '-';
	}
	int len = std::end(buffer) - d;
	if (dest.rdbuf()->sputn(d, len) != len) {
	  dest.setstate(std::ios_base::badbit);
	}
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
	if ('0' <= s[i] && s[i] <= '9')
	  ret = 10 * ret + s[i] - '0';
  return ret;
}
*/

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N; cin >> N;
	vector<int>A(N), B(N); rep(i, 0, N) { cin >> A[i] >> B[i]; }
	vector<pii>C(N);
	rep(i, 0, N) {
		C[i] = pii(A[i] + B[i], i);
	}
	sort(all(C));
	reverse(all(C));
	int ans = 0;
	rep(i, 0, N) {
		if (i % 2 == 0) {
			ans += A[C[i].second];
		}
		else {
			ans -= B[C[i].second];
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF 1e9  //
#define LINF 1e18  //
#define MOD (1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

//------------------------------------------------------

struct edge {
    ll to, cost, num;
};

ll n, m;

vector<edge> E[2001];

bool usedV[1001] = {};
bool usedE[2001] = {};
bool loop[2001] = {};


ll maxscore[1001] = {};

void bfs() {

    queue<ll> que;
    que.push(1);
    usedV[1] = true;

    while (!que.empty()) {

        for (auto& e : E[que.front()]) {

            if (loop[que.front()]) {
                loop[e.to] = true;
            }

            if (!usedV[e.to]) {
                usedV[e.to] = true;
                maxscore[e.to] = maxscore[que.front()] + e.cost;
                que.push(e.to);
            } else if (maxscore[e.to] < maxscore[que.front()] + e.cost) {
                maxscore[e.to] = maxscore[que.front()] + e.cost;
                que.push(e.to);
                if (usedE[e.num]) {
                    loop[e.to] = true;
                    loop[que.front()] = true;
                    e.cost = -LINF;
                }

            }
            usedE[e.num] = true;
        }

        que.pop();
    }

    if (loop[n]) {
        cout << "inf" << endl;
    } else {
        cout << maxscore[n] << endl;
    }
}

int main() {

    cin >> n >> m;

    repll(i, m) {
        ll a, b, c;
        cin >> a >> b >> c;
        E[a].push_back({b, c, i});
    }

    bfs();

    return 0;
}



Measured memory_bytes: 384
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::HashMap;

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

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

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

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

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

fn main() {
    input!{
        n: usize,
        arr: [u64; n],
    }
    let mut value = 1 as u64;
    let mut flg = true;
    for v in arr {
        if v == 0 {
            flg = true;
            value = 0;
            break;
        }
        let s = value.checked_mul(v);
        if let Some(x) = s {
            value = x;
        } else {
            flg = false;
        }
    }
    println!("{}", if flg && value <= 1000000000000000000 {value as i64} else { -1 });

}


Measured memory_bytes: 2788
#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(){
    int n, r;
    cin >> n >> r;

    if (n < 10) cout << r + 100 * (10 - n) << endl;
    if (n >= 10) cout << r << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include <initializer_list>
#include<unordered_set>
#include<map>
#include<cmath>
#include <iterator>
#include<stack>
#include<queue>
#include <iomanip>
#include<math.h>
#include <limits.h>
#include <numeric>
#include <functional>
#include<fstream>
#define ll long long

#define sondos ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;



   int main() {

       sondos

           string s; cin >> s; 
               int c = 0;
               string s1 = s;
           string s2 = s; 
       string s3 = s.substr(((s.length() + 1) / 2, (s.length()))), s4 = s.substr(0, ((s.length() - 1) / 2));
       string s9 = s3; ;
       
       
    reverse(s.begin(), s.end()); 
    if (s1 == s) c++; 


   string s0 =  s1.substr(0,((s1.length() - 1) / 2));
    reverse(s0.begin(), s0.end()); 
    if (s4 == s0)c++; 
    reverse(s3.begin(), s3.end());
    if (s9 == s3) c++; 
    if (c == 3) cout << "Yes ";
    else cout << "No "; 
        
            
           return 0;
   }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

char a[500],b[500];
int lena,dp[1010][1010],lenb;
inline int calc(string s){
	lenb=0;
	for (auto i:s) b[lenb++]=i;
	For(i,0,lena) For(j,0,lenb) dp[i][j]=1e9;
	dp[0][0]=0;
    for(int i=1; i<=lena; i++) dp[i][0] = i;
    for(int j=1; j<=lenb; j++) dp[0][j] = j;
    for(int i=1; i<=lena; i++)
        for(int j=1; j<=lenb; j++) 
        	if (a[i-1]==b[j-1]) dp[i][j] = dp[i-1][j-1];
            	else dp[i][j] = min(dp[i-1][j-1], min(dp[i][j-1], dp[i-1][j]))+1;
    return printf("%d\n",dp[lena][lenb]),dp[lena][lenb];
}

int ask;
inline int Query(string s){
	++ask;
	cout<<"? "<<s<<endl,fflush(stdout);
	return read();
}

const int N = 500;
int n,cnt,pos[N],tot[N][N],suf[N][N],pre[N][N];
char s[N],ans[N];
inline void solve(int u,int l,int r){
	if (l==r){
		For(i,1,cnt) if (tot[u][i]) ans[l]=s[i];
		return;
	}
	int mid=l+r>>1,S=0,S2=0,L=0;
	For(i,1,cnt) if (tot[u][i]){
		L=i;break;
	}
	vector<int>ans(cnt+1);
	ans[L]=tot[u][L],S=tot[u][L],S2=1;
	For(i,1,cnt) if (tot[u][i]&&i!=L){
		string s;
		For(j,1,mid) s=s+::s[L];
		For(j,1,n-mid) s=s+::s[i];
		ans[i]=(n-Query(s))-pre[u][L]-suf[u][i],S+=ans[i],++S2;
	}
	tot[u<<1][L]=(S-(r-mid))/S2;
	For(i,1,cnt) if (tot[u][i]) tot[u<<1^1][i]=ans[i]-tot[u<<1][L];
	For(i,L+1,cnt) if (tot[u][i]) tot[u<<1][i]=tot[u][i]-tot[u<<1^1][i];
	For(i,1,cnt){
		suf[u<<1][i]=suf[u][i]+tot[u<<1^1][i];
		suf[u<<1^1][i]=suf[u][i];
		pre[u<<1^1][i]=pre[u][i]+tot[u<<1][i];
		pre[u<<1][i]=pre[u][i];
	}
	solve(u<<1,l,mid),solve(u<<1^1,mid+1,r);
}
inline void init(){
	For(i,0,25) s[++cnt]='a'+i;
	For(i,0,25) s[++cnt]='A'+i;
	For(i,0,9) s[++cnt]='0'+i;
	For(i,1,cnt) pos[s[i]]=i;
	vector<int>ans(cnt+1);
	int mn=1000;
	For(i,1,cnt){
		string s;s=s+::s[i];
		ans[i]=Query(s),mn=min(mn,ans[i]);
	}
	n=mn+1;
	For(i,1,cnt) if (ans[i]==mn){
		string s;
		For(j,1,mn+1) s=s+::s[i];
		tot[1][i]=n-Query(s);
	}
	if (mn==0){
		For(i,1,cnt) if (tot[1][i]==1){
			cout<<"! "<<s[i]<<endl,fflush(stdout);
			exit(0);
		}
	}
}

int main(){
	//scanf("%s",a),lena=strlen(a);
	init(),solve(1,1,n);
	printf("! ");
	For(i,1,n) printf("%c",ans[i]);
	fflush(stdout);
}

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

using namespace std;

int n;
long long m;
int arr[100005];
long long sum[100005];

bool can(int x)
{
	long long cur=0;
	for(int i=0;i<n;i++)
	{
		int need=x-arr[i];
		int z=lower_bound(arr,arr+n,need)-arr;
		cur+=n-z;
	}
	return cur>=m;
}

long long get(int x)
{
	long long tot=0;
	long long ans=0;
	for(int i=0;i<n;i++)
	{
		int need=x-arr[i];
		int z=lower_bound(arr,arr+n,need)-arr;
		tot+=n-z;
		ans+=1LL*arr[i]*(n-z)+sum[n]-sum[z];
		//cout << arr[i] << " " << z << " " << sum[n]-sum[z] << endl;
	}
	//cout << x << " " << ans << " " << tot << endl;
	return ans-(tot-m)*x;
}

int main()
{
	cin >> n >> m;
	for(int i=0;i<n;i++)
		cin >> arr[i];
	sort(arr,arr+n); //reverse(arr,arr+n);
	for(int i=0;i<n;i++)
		sum[i+1]=arr[i]+sum[i];
	/*for(int i=1;i<=n;i++)
		cout << sum[i] << " ";
	cout << endl;*/
	int st=1,en=arr[n-1]*2,ans=0;
	while(st<=en)
	{
		int mid=(st+en)/2;
		if(can(mid))
		{
			ans=mid;
			st=mid+1;
		}
		else en=mid-1;
	}
	cout << get(ans) << endl;
}

Measured memory_bytes: 1408
MOD = 10 ** 9 + 7


def prepare(n):
    global MOD
    modFacts = [0] * (n + 1)
    modFacts[0] = 1
    for i in range(n):
        modFacts[i + 1] = (modFacts[i] * (i + 1)) % MOD

    invs = [1] * (n + 1)
    invs[n] = pow(modFacts[n], MOD - 2, MOD)
    for i in range(n, 1, -1):
        invs[i - 1] = (invs[i] * i) % MOD

    return modFacts, invs


N, M = map(int, input().split())
modFacts, invs = prepare(N + M)

A, B = (N, M) if N >= M else (M, N)

if A - 1 > B:
    cnt = 0
else:
    varA = modFacts[A] % MOD
    varB = modFacts[B] % MOD
    if A == B:
        varB *= 2
    cnt = (varA * varB) % MOD
print(cnt)


Measured memory_bytes: 42096
#include <iostream>
#include <vector>
int main() {
	int N;
	std::cin >> N;
	std::vector<int> p(N);
	for (int i = 0; i < N; i++) {
		std::cin >> p[i];
	}
	bool ju = false;
	for (int i = 0; i < N; i++) {
		if (i + 1 != p[i]) {
			ju = true;
			break;
		}
	}
	if (!ju) {
		std::cout << "YES" << std::endl;
		return 0;
	}
	for (int i = 0; i < N; i++) {
        if(i+1!=p[i]){
            for(int j = i+1; j < N; j++){
                std::swap(p[i],p[j]);
                bool ju = false;
                for (int i = 0; i < N; i++) {
                    if (i + 1 != p[i]) {
                        ju = true;
                        break;
                    }
                }
                if (!ju) {
                    std::cout << "YES" << std::endl;
                    return 0;
                }
                std::swap(p[i],p[j]);
            }
        }
	}
	std::cout << "NO" << std::endl;
	return 0;
}

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

int* mallocint(int si)
{
    return (int*) malloc(si * sizeof(int));
}

int* inputint(int n)
{
    int *ans = mallocint(n);
    for( int i = 0; i < n; i++ ) cin >> ans[i];
    return ans;
}

int main()
{
    int n, k;
    cin >> n >> k;
    int *p = inputint(n);
    vector<int> plist;
    for( int i = 0; i < n; i++ ) plist.push_back(p[i]);
    sort(plist.begin(), plist.end());

    int ans = 0;
    for( int i = 0; i < k; i++ ) ans += plist[i];

    cout << ans;        
    return 0;    
}

Measured memory_bytes: 3608
#include<stdio.h>  

long int f(long int x,long int p)
{
  long int y;
  y=(x/p)%2;
  
  return y;
}

int main(void)
{
  long int N,A[300001],i,j,k;
  scanf("%ld\n",&N);
  for(i=1;i<=N;i++){
    scanf("%ld",&A[i]);
  }
  long int t[61];
  t[0]=1;
  for(j=1;j<=60;j++){
    t[j]=2*t[j-1];
  }
  
  long int s[61],a[61],b[61];
  for(j=0;j<=60;j++){
    s[j]=0;
    for(i=1;i<=N;i++){
      s[j]=s[j]+f(A[i],t[j]);
    }
    a[j]=(s[j]*(N-s[j]))%1000000007;
    b[j]=a[j];
    if(j!=0){
      for(k=1;k<=j;k++){
        b[j]=(b[j]*2)%1000000007;
      }
    }
  }
  
  long int X;
  X=0;
  for(j=0;j<=60;j++){
    X=(X+b[j])%1000000007;
  }
  
  printf("%ld",X);
  
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int i_max(int arr[],int n){
    int MAX=arr[0];
   int  i1=0,i2=0;
    for (int i= 0;i<n;i++)
    {
        if (arr[i]>MAX)
        {
            MAX =arr[i];
            i1=i;
            i2=i;
        }
        else if (arr[i]==MAX)
        {
            i2=i;
        }
   }
    return max(i1,i2);
}
int i_min(long long int arr[],int n,int& i1,int& i2){
    long long int min=arr[0];
    i1=0;
    i2=0;
     for (int i= 0;i<n;i++)
     {
         if (arr[i]<min)
         {
             min =arr[i];
             i1=i;
             i2=i;
         }
         else if (arr[i]==min)
         {
             i2=i;
         }
    }
     return max(i1,i2);
}

int main (){
    // two magical lines to speed up IO
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >>n;
    int a[3]={0};
    a[2]=n%10;
    n/=10;
    a[1]=n%10;
    n/=10;
    a[0]=n%10;
    if (a[0]==a[2])
        cout << "Yes\n";
    else
        cout << "No\n";
    
}

  


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
ans = 0
color = 10001
cur = 0
for i in range(n):
    if a[i] != color and cur == 0:
        color = a[i]
        cur += 1
    elif a[i] != color and cur > 0:
        color = a[i]
        if cur % 2 == 0:
            ans += cur//2
        else:
            ans += (cur-1)//2
        cur = 1
    else:
        cur += 1
if cur % 2 == 0:
    ans += cur//2
else:
    ans += (cur-1)//2
print(ans)

Measured memory_bytes: 38384
use std::io;
use std::cmp;
use std::cmp::Ordering;

// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
struct State {
    cost     : i32,
    node     : i32,
    vismask  : i32
}

impl Ord for State {
    fn cmp(&self, other: &State) -> Ordering {
        other.cost.cmp(&self.cost)
    }
}

impl PartialOrd for State {
    fn partial_cmp(&self, other : &State) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}


fn main() {

    let n = read_t_in_line::<i32>()[0];
    let mut sums = vec![0 ; 100100];
    for _ in 0..n {
        let l_r = read_t_in_line::<i32>();
        let (l, r) = (l_r[0] as usize, l_r[1] as usize);
        sums[r + 1] -= 1;
        sums[l]     += 1;
    }
    
    let mut res = 0;
    for i in 0..sums.len()-1 {
        sums[i + 1] += sums[i];
        res += sums[i + 1];
    }
    println!("{}", res);
    

}


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

typedef long long ll;

const int INF = 101234567;

int main() {
    int N;
    int a_cnt = 0;
    int b_cnt = 0;
    int cnt = 0;
    int ans = 0;
    string s;
    cin >> N;

    for (int i = 0; i < N; i++) {
        cin >> s;
        if (s[0] == 'B') {
            b_cnt++;
        }

        if (s[s.size()-1] == 'A') {
            a_cnt++;
        }

        if (s[0] == 'B' && s[s.size()-1] == 'A') {
            cnt++;
        }

        for (int j = 1; j < s.size(); j++) {
            if (s[j-1] == 'A' && s[j] == 'B') {
                ans++;
            }
        }
    }


    b_cnt = b_cnt - cnt;
    a_cnt = a_cnt - cnt;
    if (cnt > 0) {
        ans += cnt-1;
    }

    if (cnt > 0 &&b_cnt > 0) {
        b_cnt--;
        ans++;
    }
    if (cnt > 0 && a_cnt > 0) {
        a_cnt--;
        ans++;
    }

    ans += min(b_cnt, a_cnt);

    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
          int[] a = Input.ScanIntArray();
          int[] res = new int[]{a[0]+a[1],a[0]-a[1],a[0]*a[1]};
          Console.WriteLine(res.Max());
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 13652
n, m = [int(i) for i in input().split(" ")]
a = [int(i) for i in input().split(" ")]
a = sorted(a)
q = []

for j in range(0, m):
    q.append([int(i) for i in input().split(" ")])

q = sorted(q, key=lambda k: k[1], reverse=True)

p = 0

for t in q:
    b, c = t
    pi = 0
    for i in range(b):
        if p + i < n and a[p + i] < c:
            a[p + i] = c
            pi += 1
        else:
            break
    p += pi

print(sum(a))

Measured memory_bytes: 27816
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n,m=map(int,input().split())\n"
"e=[]\n"
"for _ in range(m):\n"
"    a,b,c=map(int,input().split())\n"
"    e.append([a-1,b-1,-c])\n"
"M=10**18\n"
"d=[0]+[M]*~-n\n"
"k=0\n"
"v=0\n"
"while k<n*2:\n"
"    k+=1\n"
"    if k==n:v=d[-1]\n"
"    f=0\n"
"    for a,b,c in e:\n"
"        if d[b]>d[a]+c:\n"
"            d[b]=d[a]+c\n"
"            f=1\n"
"    if not f:\n"
"        break\n"
"if not v or v==d[-1]:\n"
"    print(-d[-1])\n"
"else:\n"
"    print('inf')\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

int main(){FIN;
	ll n; cin>>n;
    ll a[n];
    fore(i,0,n)cin>>a[i];
    __int128 res=1;
    __int128 maxi=1e18;
    fore(i,0,n){
    	if(a[i]==0){
        	cout<<0; return 0;
        }
    }
    fore(i,0,n){
    	res=res*a[i];
    	if(res>maxi){
    		cout<<-1;
    		return 0;
    	}
    }
    cout<<(ll)res;
	
	return 0;
}

Measured memory_bytes: 4432
#include <iostream>
#include <string>
#include <queue>
#include <utility>
#include <set>
using namespace std;
typedef pair<string,int> P;
int main() {
    string S;
    while(cin>>S,S[0]!='0') {
        set<string> ST;
        queue<P> Q;
        Q.push(P(S,0));
        string R,G,B;
        bool OK;
        while(!Q.empty()) {
            P p=Q.front();Q.pop();
            OK=true;
            for(int i=0;i<p.first.size()-1;i++) {
                string SS=p.first;
                if((p.first[i]=='r'&&p.first[i+1]=='g')||(p.first[i]=='g'&&p.first[i+1]=='r')) {
                        SS[i]=SS[i+1]='b';
                        if(ST.find(SS)==ST.end()){
                            Q.push(P(SS,p.second+1));
                            ST.insert(SS);
                        }
                        OK=false;
                }else if((p.first[i]=='r'&&p.first[i+1]=='b')||(p.first[i]=='b'&&p.first[i+1]=='r')) {
                        SS[i]=SS[i+1]='g';
                        if(ST.find(SS)==ST.end()){
                            Q.push(P(SS,p.second+1));
                            ST.insert(SS);
                        }
                        OK=false;
                }else if((p.first[i]=='g'&&p.first[i+1]=='b')||(p.first[i]=='b'&&p.first[i+1]=='g')) {
                        SS[i]=SS[i+1]='r';
                        if(ST.find(SS)==ST.end()){
                            Q.push(P(SS,p.second+1));
                            ST.insert(SS);
                        }
                        OK=false;
                }
            }
            if(OK) {cout<<p.second<<endl;break;}
        }
        if(!OK)cout<<"NA"<<endl;
    }
}

Measured memory_bytes: 2664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef string str;
const long long INF = INT64_MAX;

#define REP(i, n) for(ll i=0;i<n;i++)
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse((v).rbegin(), (v).rend())
#define FOLDL(src, dst, lambda) partial_sum((src).begin(), (src).end(), (dst).begin(), lambda)
#define FOLDR(src, dst, lambda) INV(src);partial_sum((src).begin(), (src).end(), (dst).begin(), lambda);INV(dst)
#define CUMSUML(src, dst) FOLDL(src, dst, [](auto a, auto b) {return a+b;})
#define CUMSUMR(src, dst) FOLDR(src, dst, [](auto a, auto b) {return a+b;})
#define DESC(v) sort((v).rbegin(), (v).rend())
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) ASC(v);erase(unique(v.begin(), v.end()), v.end())
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

void solve() {
    ll N;
    str S;
    cin >> N >> S;
    vll D(N) ,E(N), Es(N), W(N), Ws(N);
    for(int i=0;i<N;i++) (S[i] == 'E' ? E[i] : W[i]) = 1;
    CUMSUML(W, Ws);
    CUMSUMR(E, Es);
    ll ans = INF;
    for(int i = 0; i < N; i++) {
        ll w = (i == 0 ? 0 : Ws[i - 1]);
        ll e = (i == N - 1 ? 0 : Es[i + 1]);
        ans = min(ans, e+w);
    }
    cout << ans << endl;
}

int main() {
    FIO;
    solve();
    return 0;
}

Measured memory_bytes: 12436
#include <iostream>

using namespace std;

int main(){
	int N, M;
	cin >> N >> M;

	int *A = new int[N];
	int *B = new int[M];
	int *number_of_vote = new int[N];
	for(int i=0; i<N; i++){
		cin >> A[i];
		number_of_vote[i] = 0;
	}
	for(int j=0; j<M; j++) cin >> B[j];
	

	for(int j=0; j<M; j++){
		for(int i=0; i<N; i++){
			if(A[i] <= B[j]){
				number_of_vote[i]++;
				break;
			}
		}
	}

	int answer = 0;
	int max_number_of_vote =  0;
	for(int i=0; i<N; i++){
		if(number_of_vote[i] > max_number_of_vote){
			max_number_of_vote = number_of_vote[i];
			answer = i+1;
		}
	}

	cout << answer << endl;

	delete[] A;
	delete[] B;
	delete[] number_of_vote;
	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <queue>
#include <utility>
#include <vector>

#define MAX_NODE 10000
#define INF 1000000000

using namespace std;

struct Edge {
	int to, w;
};

typedef pair<int, int> P;

vector<Edge> adj[MAX_NODE];
int d[MAX_NODE];

void dijkstra(int n, int start) {
	priority_queue<P, vector<P>, greater<P> > heap;
	fill(d, d + n, INF);
	d[start] = 0;
	heap.push({0, start});

	while (!heap.empty()) {
 		P p = heap.top();
 		heap.pop();
 		int from = p.second;
 		if (d[from] < p.first)
 			continue;
 		for (int i = 0; i < adj[from].size(); i++) {
 			Edge e = adj[from][i];
	 		if (d[from] + e.w < d[e.to]) {
	 			d[e.to] = d[from] + e.w;
	 			heap.push( {d[e.to], e.to} );
	 		}
	 	}
	}
}

int main(){
	int n,u,k,c,v;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>u>>k;
		for(int j=0;j<k;j++){
			cin>>v>>c;
			adj[u].push_back({v,c});
		}
	}
	dijkstra(n,0);
	for(int i=0;i<n;i++){
		cout<<i<<" "<<d[i]<<"\n";
	}
	return 0;
}

Measured memory_bytes: 6312
N = int(input())
if N <= 104:
    print(0)
else:
    ki = []
    for i in range(105, N + 1):
        if i % 2 == 1:
            ki.append(i)
    yakusuu = []
    for i in ki:
        count = 0
        for j in range(1, i + 1):
            if i % j == 0:
                count += 1
        if count == 8:
            yakusuu.append(i)
    print(len(yakusuu))

Measured memory_bytes: 3060
#include <bits/stdc++.h>  // ver2.1.9
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define Pii pair<int,int>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lW,0,a.size()){Vout(a[lW]);}
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;
 
int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void uniq(Vi &v){sort(ALL(v)); v.erase(unique(ALL(v)),v.end());}  //  uniqのやつ
 
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
 
signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(16);
  int n,qw,er;
  cin >> n;
  vector<Pii> a(n);
  rep(i,0,n){
    cin >> qw >> er;
    a[i] = mp(qw,er);
  }
  
  Pii memo;
  int ct = 0;
  map<Pii,int> kind;
  rep(i,0,n){
    rep(j,i+1,n){
      memo = mp(a[i].first-a[j].first,a[i].second-a[j].second);
      kind[memo]++;
      memo = mp(a[j].first-a[i].first,a[j].second-a[i].second);
      kind[memo]++;
    }
  }
  int maxx=0;
  for (auto p : kind ) {
    auto k = p.first;
    auto v = p.second;
    maxx = max(maxx,v);
  }
  cout << n-maxx << endl;
  
  return 0;
}

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

#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main(){

    int x,y,z;
    cin >> x >> y >> z;

    cout << z << " " << x << " " << y << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rrep(i,n) REP(i,1,n+1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 500000;
const int inf = 1000000007;
const ll mod = 998244353;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

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


string s, t;
map <char, char> mp[2];
bool f[2][30], j = true;

int main() {

	cin >> s >> t;

	rep(i, s.size()) {
		if (f[0][s[i] - 'a']) {
			if (mp[0][s[i]] != t[i]) {
				j = false;
				break;
			}
		}
		else {
			mp[0][s[i]] = t[i];
			f[0][s[i] - 'a'] = true;
		}
	}

	rep(i, s.size()) {
		if (f[1][t[i] - 'a']) {
			if (mp[1][t[i]] != s[i]) {
				j = false;
				break;
			}
		}
		else {
			mp[1][t[i]] = s[i];
			f[1][t[i] - 'a'] = true;
		}
	}

	if (j)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 776
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

const MAX = int(1e+5)

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	pt := primeTable(MAX + 1)
	A := make([]int, MAX+1)
	for i := 0; i <= MAX; i++ {
		if i%2 != 0 && pt[i] && pt[(i+1)/2] {
			A[i] = 1
		}
	}
	S := make([]int, MAX+1)
	for i := 1; i <= MAX; i++ {
		S[i] = S[i-1] + A[i]
	}
	Q := sc.nextInt()
	for i := 0; i < Q; i++ {
		l, r := sc.nextInt(), sc.nextInt()
		fmt.Fprintln(wtr, S[r]-S[l-1])
	}
}

func primeTable(n int) map[int]bool {
	prime := make(map[int]bool)
	for i := 0; i <= n; i++ {
		prime[i] = true
	}
	prime[0] = false
	prime[1] = false
	for i := 2; i*i <= n; i++ {
		if !prime[i] {
			continue
		}
		for j := i + i; j <= n; j += i {
			prime[j] = false
		}
	}
	return prime
}


Measured memory_bytes: 6272
import math

def trial_division(target):
    dest = int(math.sqrt(target))
 
    for i in range(2,dest):
        if target % i == 0:
            return "NO"
    return "YES"
    
x = input()
x = int(x)

if trial_division(x) == "YES":
	print(int(x))
else:
	while trial_division(x) == "NO":
		x += 1
	else:
		print(x)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

void warshall_floyd(vvi &C){
	rp(k,0,C.size())
		rp(from,0,C.size())
			rp(to,0,C.size())
				C[from][to] = min(C[from][to], C[from][k]+C[k][to]);
}

int main(){
	int H,W; cin>>H>>W;
	vvi C(10, vi(10)), A(H, vi(W));
	rp(i,0,10) rp(j,0,10) cin>>C[i][j];

	warshall_floyd(C);

	int ans = 0;
	rp(h, 0, H) rp(w, 0, W){
		int a; cin>>a;
		if(a < 0) continue;
		ans += C[a][1];
	}
	cout<< ans <<endl;
}

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

using Edge = pair<int, int>;
using Graph = vector<vector<Edge> >;

Graph G;
vector<bool> color;

void dfs(int v, int p, bool c){
    color[v] = c;
    for(auto e : G[v]){
        if(e.first == p) continue;
        if(e.second & 1) dfs(e.first, v, !c);
        else dfs(e.first, v, c);
    }
}

int main(){
    int n;
    cin >> n;
    G.assign(n, vector<Edge>());
    for(int i = 0; i < n-1; i++){
        int u, v, w;
        cin >> u >> v >> w;
        u--, v--;
        G[u].push_back(Edge(v, w));
        G[v].push_back(Edge(u, w));
    }
    color.assign(n, -1);
    dfs(0, -1, 1);
    for(auto c : color) cout << c << endl;
}

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

int cnt[1000001];

multiset<lint> decomp(lint N){
    multiset<lint> res;
    lint num=N;
    for(int i=2;i*i<=num;i++){
        while(N%i==0) N/=i,res.insert(i);
        if(N==1) break;
    }
    if(N!=1) res.insert(N);
    return res; 
}

lint powmod(lint a,lint b){
  return b?powmod(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;
}

map<int,int> res;
set<int> apr;

int main(void){
    int N;
    cin >> N;
    int A[N];
    rep(i,N) cin >> A[i];
    rep(i,N){
        res.clear();
        multiset<lint> cmp=decomp(A[i]);
        while(!cmp.empty()){
            auto itr=cmp.begin();
            res[*itr]=cmp.count(*itr);
            apr.insert(*itr);
            cmp.erase(*itr);
        }
        while(!apr.empty()){
            auto itr=apr.begin();
            cnt[*itr]=max(cnt[*itr],res[*itr]);
            apr.erase(itr);
        }
    }
    lint lcm=1;
    for(int i=2;i<=1000000;i++) lcm=(lcm*powmod(i,cnt[i]))%MOD;
    lint ans=0;
    rep(i,N) ans=(ans+lcm*powmod(A[i],MOD-2))%MOD;
    cout << ans << endl;
}

Measured memory_bytes: 6088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll h,w,ans=0;
	cin>>h>>w;
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			char x;
			cin>>x;
			if(x=='#'){
				ans++;
			}
		}
	}
	cout << (ans==h+w-1? "Possible":"Impossible");
	// your code goes here
	return 0;
}

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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

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

int main() {
  int N, K;
  cin >> N >> K;

  cout << (N >= K * 2 - 1 ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.IO;
    using System.Text;

    class Program
    {

        static void Main()
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);
            int d = int.Parse(input[3]);
            while (true)
            {
                c = c - b;
                if (c <= 0)
                {
                    Console.WriteLine("Yes");
                    return;
                }
                a = a - d;
                if(a <= 0)
                {
                    Console.WriteLine("No");
                    return;
                }
            }
        }
    }

Measured memory_bytes: 17764
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

vector<int> g[111];

int dep[111],dgr[111];
void dfs(int x,int f,int d)
{
	dep[x]=d;
	dgr[d]=max(dgr[d],(int)g[x].size()-(f!=0));
	for(auto v:g[x])if(v!=f)
		dfs(v,x,d+1);
}

int n,mx[111];
int main()
{
	get1(n);
	for(int i=1,u,v;i<n;i++)
	{
		get2(u,v);
		g[u].pb(v);
		g[v].pb(u);
	}
	for(int i=1;i<=n;i++)
	{
		dfs(i,0,1);
		mx[i]=*max_element(dep+1,dep+n+1);
	}
	int v=*min_element(mx+1,mx+n+1),v1=0,v2=0;
	for(int i=1;i<=n;i++)if(mx[i]==v)
	{
		if(!v1)v1=i;
		else v2=i;
	}
	memset(dgr,0,sizeof(dgr));
	dfs(v1,v2,1);
	dfs(v2,v1,1);
	LL ans=1;
	if(v2){mx[v1]--;ans++;}
	for(int i=1;i<mx[v1];i++)
		ans*=dgr[i];
	if(!v2)
	{
		for(int j=1;j<=n;j++)if(mx[j]==mx[v1]+1)
		{
			memset(dgr,0,sizeof(dgr));
			LL cur=1;
			dfs(v1,j,1);dfs(j,v1,1);
			for(int i=1;i<mx[v1];i++)cur*=dgr[i];
			ans=min(ans,cur*2);
		}
	}
	printf("%d %lld\n",mx[v1],ans);
	return 0;
}

Measured memory_bytes: 256
S = input()
if S == 'SAT':
  print(1)
elif S == 'FRI':
  print(2)
elif S == 'THU':
  print(3)
elif S == 'WED':
  print(4)
elif S == 'TUE':
  print(5)
elif S == 'MON':
  print(6)
else:
  print(7)

Measured memory_bytes: 2940