akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  int N, A, B; cin >> N >> A >> B;
  
  if(A > B || (N == 1 && A != B)) {
    cout << 0 << endl;
    return 0;
  }
  
  cout << (B*N-B+A)-(A*N-A+B)+1 << endl;
}


Measured memory_bytes: 256
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(), &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!(usize);
    let q = get!();
    let mut tree = vec![vec![]; n];
    for _ in 1 .. n {
        let a = get!(usize)-1;
        let b = get!(usize)-1;
        tree[a].push(b);
        tree[b].push(a);
    }
    let mut values = vec![0_i64; n];
    for _ in 0 .. q {
        let p = get!(usize)-1;
        let x = get!();
        values[p] += x;
    }
    
    let mut stack = vec![];
    let mut ans = vec![0_i64; n];
    let mut visited = vec![false; n];
    stack.push((0_usize, false));
    visited[0] = true;
    let mut sum = 0;
    while let Some((p, v)) = stack.pop() {
        if v {
            sum -= values[p];
            continue;
        }
        stack.push((p, true));
        sum += values[p];
        ans[p] = sum;
        for &c in tree[p].iter() {
            if visited[c] {
                continue;
            }
            visited[c] = true;
            stack.push((c, false));
        }
    }
    for i in 0 .. n {
        if i > 0 {
            print!(" ");
        }
        print!("{}", ans[i]);
    }
    println!();
}

Measured memory_bytes: 36984
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	ll N, M; cin >> N >> M;
	vector<ll> K(M);
	vector<vector<ll>> S(M);
	for (ll i = 0; i < M; ++i)
	{
		cin >> K[i];
		S[i].resize(K[i]);
		for (ll j = 0; j < K[i]; ++j)
		{
			cin >> S[i][j];
			--S[i][j];
		}
	}
	vector<ll> P(M);
	for (ll i = 0; i < M; ++i) cin >> P[i];

	ll res{0};
	for (ll bits = 0; bits < (1 << N); ++bits)
	{
		bool ok = true;
		for (ll m = 0; m < M; ++m)
		{
			ll s{0};
			for (ll i = 0; i < K[m]; ++i)
			{
				if (bits & (1 << S[m][i])) ++s;
			}
			if (s%2 != P[m])
				ok = false;
		}
		if (ok) ++res;
	}
	std::cout << res << std::endl;
}


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

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Run(args));
        }
        private static long Run(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            var ret = 0L;
            for (long i = 1; i < N; i++)
            {
                ret += i;
            }

            return ret;
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>

using namespace std;

const int kInfinity = 0x3F3F3F3F;
const int kNil = -1;
const int kMaxV = 10010;

template <class T>
struct Edge {
  using w_type = T;
  Edge(int u, int v, w_type w): u(u), v(v), w(w) { }
  int u, v;
  w_type w;
  bool operator<(const Edge<T> & rhs) const {
    if (w != rhs.w) { return w < rhs.w; }
    if (u != rhs.u) { return u < rhs.u; }
    return v < rhs.v;
  }
};

template <class Edge>
decltype(auto) Prim(vector<Edge> & edges,
                 typename vector<Edge>::size_type node_num,
                 typename vector<Edge>::size_type root) {
  using size_type = typename vector<Edge>::size_type;
  using const_it = typename vector<Edge>::const_iterator;
  using w_type = typename Edge::w_type;

  bitset<kMaxV> bs;
  vector<vector<Edge>> adjacency(node_num, vector<Edge>());
  for (const auto & e: edges) {
    adjacency[e.u].push_back(e);
  }
  vector<w_type> key(node_num, kInfinity);
  vector<int> parent(node_num, kNil);
  key[root] = 0;

  using Pair = pair<size_type, w_type>;
  auto compare = [](const Pair & x, const Pair & y) {
    return y.second < x.second || (!(x.second < y.second) && y.first < x.first);
  };
  priority_queue<Pair, vector<Pair>, decltype(compare)> que(compare);
  que.emplace(root, 0);

  while (!que.empty()) {
    auto top_no = que.top().first;
    auto top_key = que.top().second;
    que.pop();
    bs.set(top_no);
    for (const auto & e: adjacency[top_no]) {
      if (!bs.test(e.v) && e.w < key[e.v]) {
        key[e.v] = e.w;
        parent[e.v] = e.u;
        que.emplace(e.v, e.w);
      }
    }
  }

  auto weight_sum = accumulate(key.begin(), key.end(), 0);
  return weight_sum;
}

int main(int argc, char const *argv[]) {
  vector<Edge<int>> edges;
  unsigned V, E, r;
  cin >> V >> E;
  for (unsigned i = 0; i < E; ++i) {
    unsigned u, v;
    unsigned w;
    cin >> u >> v >> w;
    edges.emplace_back(u, v, w);
    edges.emplace_back(v, u, w);
  }
  cout << Prim(edges, V, 0) << endl;
  return 0;
}

Measured memory_bytes: 10436
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	a=a+b+c;
	if(a>=22) cout<<"bust";
	else cout<<"win";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define ll long long
#define rep(i, a, b) for(int i = a; i <= b; i++)
void read(int &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
void read(ll &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
using namespace std;
const int maxn = 3010, mod = 1e9 + 7;
int n;
char s[maxn];
ll dp[maxn][maxn];
int main()
{
    read(n);
    scanf("%s", s + 2);
    dp[1][1] = 1;
    rep(i, 2, n) {
        if(s[i] == '<') {
            dp[i][1] = 0;
            rep(j, 2, i) dp[i][j] = (dp[i][j - 1] + dp[i - 1][j - 1]) % mod;
        }
        else {
            dp[i][i] = 0;
            for(int j = i - 1; j; j --) dp[i][j] = (dp[i][j + 1] + dp[i - 1][j]) % mod;
        }
    }
    ll ans = 0;
    rep(i, 1, n) ans = (ans + dp[n][i]) % mod;
    printf("%lld\n", ans);
    return 0;
}

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

int main(int argc, char const *argv[]) {
    double a, b, C;
    cin >> a >> b >> C;

    double S, L, h, c, rad;
    double PI = acos(-1);
    rad = (C * PI) / 180.0;

    S = (a * b * sin(rad)) / 2.0;
    c = sqrt((a * a) + (b * b) - (2 * a * b * cos(rad)));
    L = a + b + c;
    h = b * sin(rad);
    printf("%lf\n%lf\n%lf\n", S, L, h);
}



Measured memory_bytes: 3480
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
#define nl '\n'
#define eb emplace_back
#define f(i,start,n) for(int i=start; i<=n; i++)


int main()
{
    FASTIO;
    
        int n; cin >> n;
        string s; cin >> s;
        int l = s.end()-  s.begin();
        if(l<=n){
            cout << s << nl;
        }
        else{
            cout << s.substr(0, n) << "...\n";
        }
    

    return 0;
}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define MAXN 105
#define MAXM 1005
#define INF  0x3f3f3f3f
int dist[MAXN][MAXN];
int a[MAXM], b[MAXM], c[MAXM];
int n, m;
int main(){
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= m; ++i)
        scanf("%d%d%d", &a[i], &b[i], &c[i]);

    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
            if(i==j)
                dist[i][j] = 0;
            else
                dist[i][j] = INF;

    for(int i = 1; i <= m; ++i){
        dist[a[i]][b[i]]=min(dist[a[i]][b[i]],c[i]);
        dist[b[i]][a[i]]=min(dist[b[i]][a[i]],c[i]);
    }

    for(int k = 1; k <= n; ++k)
        for(int i = 1; i <= n; ++i)
            for(int j = 1; j <= n; ++j)
                dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
    int ans=m;
    for(int i = 1; i <= m; ++i){
        bool flag = false;
        for(int j = 1; j <= n; ++j) 
            if(dist[j][a[i]]+c[i]==dist[j][b[i]]) 
                flag = true;
        if(flag==true)
            ans--;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 256
use proconio::*;

fn floor_sum(n: i64, m: i64, mut a: i64, mut b: i64) -> i64 {
    let mut ans = 0;
    if a >= m {
        ans += (n - 1) * n * (a / m) / 2;
        a %= m;
    }
    if b >= m {
        ans += n * (b / m);
        b %= m;
    }

    let y_max = (a * n + b) / m;
    let x_max = y_max * m - b;
    if y_max == 0 {
        return ans;
    }
    ans += (n - (x_max + a - 1) / a) * y_max;
    ans += floor_sum(y_max, a, m, (a - x_max % a) % a);
    return ans;
}

#[fastout]
fn main() {
    input! {
        t:usize
    }
    for _ in 0..t {
        input! {n:i64,m:i64,a:i64,b:i64}
        println!("{}", floor_sum(n, m, a, b));
    }
}


Measured memory_bytes: 4704
def main():
  input()
  in_a = list(map(int, input().split()))
  leaves = [0] * len(in_a)
  leaves[-1] = in_a[-1]

  if in_a[0] > 1:
    print(-1)
    return

  for i in range(len(in_a)-2, -1, -1):
    leaves[i] = leaves[i+1] + in_a[i]

  node = 1
  total = 1
  
  for i in range(1, len(in_a)):
    n = (node - in_a[i-1]) * 2

    if n < in_a[i]:
        print(-1)
        return

    node = min(n, leaves[i])
    total += node

  print(total)

if __name__ == '__main__':
  main()
    


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

using ll = long long;
using Field = vector<vector<ll>>;
using Graph = vector<vector<ll>>;
using VI = vector<int>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VC = vector<char>;
using PI = pair<int, int>;

#define FOR(i, s, n) for (int i = s; i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

const long long INF = 1LL<<60;
const int MOD = 1000000007;

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

ll N;
VL w;
VVL dp;
VL cost;
VVL K;

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

    cin >> N;

    w.resize(N + 1);
    cost.resize(N + 1);

    REP(i, N) { cin >> w[i];}

    for (int i = 1; i <= N; i++) {
        cost[i] = cost[i - 1] + w[i - 1];
    }

    dp.assign(N+1, VL(N+1, INF));
    K.assign(N+1, VL(N+1));

    REP(i, N + 1) {
        dp[i][i] = 0;
        K[i][i] = i;
    }

    for (int len = 1; len < N; len++) {
        for (int l = 0; l + len < N; l++) {
            int r = l + len;
            
            for (int m = K[l][r-1]; m <= K[l + 1][r]; m++) {

                if (dp[l][r] > dp[l][m] + dp[m+1][r] + cost[r + 1] - ((len>0)?cost[l]:0)) {
                    dp[l][r] = dp[l][m] + dp[m+1][r] + cost[r + 1] - ((len>0)?cost[l]:0);
                    K[l][r] = m;
                }
                
                
            }
        }
    }

    cout << dp[0][N-1] << endl;



    return 0;
}


Measured memory_bytes: 253424
using System;
using System.Linq;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    string S=Console.ReadLine();
      char[] Schar=S.ToCharArray();
      bool flg=false;
      for(int i=0;i<3;i++){
        if(Schar[i]==Schar[i+1]){
          flg=true;
          break;
        }
      }
      if(flg){
        Console.WriteLine("Bad");
      }else{
        Console.WriteLine("Good");
      }
  }
  }
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

VI win[101010];

int solve(int x){
  vector<int> v;
  rep(i,win[x].size()){
    v.push_back(solve(win[x][i]));
  }

  sort( all(v) , greater<int>() );

  ll res = 0;
  rep(i,v.size()){
    res = max(res, i + v[i] + 1);
  }
  return res;
}


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

  int a;
  rep(i,n-1){
    cin >> a, a--;
    win[a].push_back(i+1);;
  }
  
  cout << solve(0) << endl;
  return 0;
}


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

typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
 
using namespace std;

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

    vector<string> s(n);
    REP(i,n){
        cin >> s[i];
    }
    REP(i,n)cerr << s[i] << endl;
    
    int ans = 0;

    REP(A,n){
        int f = 1;
        REP(i,n){
            REP(j,n){
                //cerr  <<  (i+A)%n << " "<< s[(i+A)%n][j] << " " << s[j][(i+A)%n] << endl;
                if(s[(i+A)%n][j] != s[(j+A)%n][i]){
                    f = 0;
                    break;
                }
            }
            if(f == 0)break;
        }
        if(f == 1) ans += n;
    }

    

    cout << ans << endl;
    
    return 0;
}
//g++ -std=c++14 code1.cpp


Measured memory_bytes: 384
x, n = [int(i) for i in input().split()]
flag = [0 for i in range(105)]
if (n != 0):
    p = [int(i) for i in input().split()]

    for i in p:
        flag[i] = 1



for i in range(100):
    if x-i >=0:
        if flag[x-i] == 0:
            ans = x-i
            break
    else:
        ans = -1
        break

    if flag[x+i] == 0:
        ans = x+i
        break
    
print(ans)



Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

const int N = 100000;
ll vals[N+100];
int sz = 0;

void compute(ll v, int p, int l) {
  if (sz >= N) return;
  if (l == 0) {
    vals[sz++] = v;
    return;
  }
  for (int d = max(0, p - 1); d <= min(9, p + 1); d++) {
    compute(v * 10 + d, d, l - 1);
  }
}

void prec() {
  for (int len = 1; sz < N; len++) {
    for (int d = 1; d <= 9; d++) {
      compute(d, d, len - 1);
      if (sz >= N) break;
    }
  }
}

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  prec();
  int k; cin >> k;
  cout << vals[k - 1] << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF = 1e18+18;
const ll MAX = 100005;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;


int main(){
    int N;
    cin>>N;
    vector<int> A(N);
    rep(i, N){
        cin>>A[i];
    }
    ll Sum=100*100*100;
    rep(i, 100){
        int p=i+1;
        ll PSum=0;
        rep(i, N){
            PSum+=(p-A[i])*(p-A[i]);
        }
        Sum=min(Sum, PSum);
    }
    cout<<Sum<<endl;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  int cnt = 0;
  rep2(i, a, b+1) {
    string wk = to_string(i);
    if (wk[0]==wk[4] && wk[1]==wk[3]) {
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    string t; cin >> t;
    set<string> s;
    int K; cin >> K; K--;
    int n = t.size();
    int cnt = 0;
    rep(i, 5) {
        rep(j, n-i) {
            string x;
            rep(k,i+1) x += t[j+k];
            s.insert(x);
            cnt++;
        }
    }
    auto it = s.begin(); rep(i,K) it++;
    cout << *it;
}


Measured memory_bytes: 1664
#E
N,T=map(int,input().split())
A=[0 for i in range(N+1)]
B=[0 for i in range(N+1)]
for i in range(1,N+1):
    A[i],B[i]=map(int,input().split())

dp1=[[0 for i in range(6001)] for j in range(N+1)]
dp2=[[0 for i in range(6001)] for j in range(N+2)]

for i in range(1,N+1):
    for j in range(T+1):
        if j>=A[i]:
            dp1[i][j]=max(dp1[i-1][j],dp1[i-1][j-A[i]]+B[i])
        else:
            dp1[i][j]=dp1[i-1][j]

for i in range(N,0,-1):
    for j in range(T+1):
        if j>=A[i]:
            dp2[i][j]=max(dp2[i+1][j],dp2[i+1][j-A[i]]+B[i])
        else:
            dp2[i][j]=dp2[i+1][j]

ans=0
for i in range(1,N+1):
    for j in range(T):
        ans=max(ans,dp1[i-1][j]+dp2[i+1][T-1-j]+B[i])
print(ans)

Measured memory_bytes: 355368
#include<bits/stdc++.h>
using namespace  std;
#define pb push_back
//#define int long long int
int gcd(int a,int b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}
int lcm(int a,int b)
{
    return a/gcd(a,b)*b;
}
main()
{
    int count=0;
    string s,k;
    cin>>s>>k;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]!=k[i])
        {
            count++;
        }
    }
    cout<<count<<endl;


}



Measured memory_bytes: 3852
#include <bits/stdc++.h>
//#include <iostream>
using namespace std;
int main() {
  long long int N, Y;
  long long int i,j,k;
  scanf("%lld%lld", &N, &Y);

  for (i = 0; i <= N; i++) {
    for (j = 0; j <= N-i; j++) {
      k = N - i - j;
      //cout << i << " " << j << " " << k << endl;
      if ((i*10000) + (j * 5000) + (k*1000) == Y) {
        cout << i << " " << j << " " << k << endl;
        return 0;
      }
    }
  }
  printf("-1 -1 -1\n");

}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
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; }
const ll MOD = 1e9+7;

int N;
int A[22][22];
vector<ll> B[22];
ll DP[22][1LL << 22];

ll pop_count(ll bit){
    ll ret = 0;
    REP(i,N){
        if((bit >> i) & 1)
            ret++;
    }
    return ret;
}

void dfs(int v, ll bit){
    if(v == N){
        int num = pop_count(bit);
        B[num].push_back(bit);
        return;
    }
    dfs(v+1, bit);
    dfs(v+1, bit | (1LL << v));
}

int main(){
    cin >> N;
    REP(i,N){
        REP(j,N){
            int a;
            cin >> a;
            A[i][j] = a;
        }
    }

    dfs(0, 0);

    DP[0][0] = 1;
    REP(i,N){
        //for(int s = 0; s < (1LL << N); s++){
        for(auto&& s : B[i]){
            //ll num = pop_count(s);
            //if(i != num) continue;
            REP(j,N){
                if((s >> j) & 1) continue;
                if(A[i][j] == 0) continue;
                DP[i+1][s | (1 << j)] += DP[i][s];
                DP[i+1][s | (1 << j)] %= MOD;
            }
        }
    }

    ll ans;
    ans = DP[N][(1LL << N) - 1];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 344864
# D
N = 10**5
primes = set([])
is_prime = [True]*(N+2)
is_prime[0] = False
is_prime[1] = False
for i in range(2, N+2):
    if is_prime[i]:
        primes.add(i)
        for j in range(2, N//i+1):
            is_prime[j*i] = False
    
# like-2017
cnt = [0]*(N+2)
for i in range(1, N+2):
    cnt[i] += cnt[i-1]
    if is_prime[i] and is_prime[(i+1)//2]:
        cnt[i] += 1
#print(cnt[:100])
    
Q = int(input())
for _ in range(Q):
    l,r = map(int, input().split())
    print(cnt[r]-cnt[l-1])

Measured memory_bytes: 9772
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <chrono> //1e+9で割る auto end= chrono::system_clock::now()-st;  cout<<end.count()%1e+9<<endl;
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef long double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)

ll N,K;
ll a[5000];
bool dp[5001];

bool need(ll x){
	if(a[x]>=K) return 1;
	memset(dp,0,sizeof(dp));
	dp[0]=1;
	rep(i,N){
		if(i==x) continue;
		rrep(j,max(K-a[i],0LL)){
			if(dp[j]){
				dp[j+a[i]]=1;
			}
		}
	}
	for(ll i=max(0LL,K-a[x]);i<K;i++){
		if(dp[i]) return 1;
	}
	return 0;
}

int main()
{
	cin>>N>>K;
	rep(i,N) cin>>a[i];
	sort(a,a+N);
	ll lb=-1,ub=N;
	while(ub-lb>1){
		ll mid=(ub+lb)/2;
		if(need(mid)) ub=mid;
		else lb=mid;
	}
	cout<<ub<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int INF=1e9+7;
int dp[200005],ch[200005],cv[200005],ans[67108864];
void solve(int l,int r){
	if(l==r){
		dp[l]=min(dp[l],dp[l-1]+1);
		return;
	}
	int mid=(l+r)>>1;
	solve(l,mid);
	int cur=0;
	for(int k=mid+1;k<=r;k++){
		cur^=ch[k];
		ans[cur]=INF;
		rep(j,26)ans[cur^(1<<j)]=INF;
	}
	cur=0;
	ans[0]=min(ans[0],dp[mid]);
	for(int k=mid;k>=l;k--){
		cur^=ch[k];
		ans[cur]=min(ans[cur],dp[k-1]);
	}
	cur=0;
	for(int k=mid+1;k<=r;k++){
		cur^=ch[k];
		dp[k]=min(dp[k],ans[cur]+1);
		rep(j,26)dp[k]=min(dp[k],ans[cur^(1<<j)]+1);
	}
	solve(mid+1,r);
}
int main(){
	ios::sync_with_stdio(false); 
	string S;
	cin>>S;
	int n=S.length();
	rep(k,n)ch[k+1]=1<<S[k]-'a';
	dp[0]=0;
	rep1(k,n)dp[k]=INF;
	solve(1,n);
	cout<<dp[n]<<'\n';
	return 0; 
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  string ans;
  
  if(a + b == d + c) ans = "Balanced";
  else if(a + b > d + c) ans = "Left";
  else if(a + b < d + c) ans = "Right";
  else {
    cout << "unknown" << endl;
    return 0;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

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

    REP(i, n+1) {
        if((ll)(i*1.08) == n) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>

const int N = 200050;

inline int readInt() {
  int ans = 0, c, f = 1;
  while (!isdigit(c = getchar()))
    if (c == '-') f *= -1;
  do ans = ans * 10 + c - '0';
  while (isdigit(c = getchar()));
  return ans * f;
}

int n, A[N];

int main() {
  n = readInt();
  for (int i = 1; i <= n; ++i)
    A[readInt()] = i;
  int ans = 0;
  for (int i = 1, j = 0; i <= n; ++i)
    ans = std::max(ans, j = (A[i] > A[i - 1] ? j + 1 : 1));
  printf("%d\n", n - ans);
  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    //input
    int a,b;
    cin>>a>>b;
    string s1,s2;
    string s;
    s1="";
    rep(i,b){
        if(i==0){
            s=to_string(a);
        }
        s1+=s;
    }
    s2="";
    rep(i,a){
        if(i==0){
            s=to_string(b);
        }
        s2+=s;
    }
    if(a<=b){
        cout<<s1<<endl;
    }else{
        cout<<s2<<endl;
    }
}

Measured memory_bytes: 3688
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
#mod = 10**9 + 7
#mod = 9982443453
mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
ans = 0
for i in range(1,n):
    if A[i-1] > A[i]:
        sa = A[i-1] - A[i]
        ans += sa
        A[i] += sa
print(ans)


Measured memory_bytes: 35296
#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);

  ll n, k;
  cin >> n >> k;
  cout << k * (ll)pow(k - 1, n - 1) << endl;
}


Measured memory_bytes: 512
N, _ = map(int, input().split())
KA = [list(map(int, input().split())) for _ in range(N)]
ans = set()
for i, ka in enumerate(KA):
  a = set(ka[1:])
  if not i:
    ans = a
  else:
    ans = ans & a
    
print(len(ans))

Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    ll n, k;
    cin >> n >> k;
    VL a(n);
    REP(i,n){
        a[i] = (in() + k - 1) % k;
    }
    VL s(n + 1);
    REP(i,n) s[i + 1] = (s[i] + a[i]) % k;
    ll ans = 0;
    map<int, int> cnt;
    cnt[0] = 1;
    REP(i,n){
        // cout << s[i + 1] << " " << cnt[s[i + 1]] << endl;
        ans += cnt[s[i + 1]];
        cnt[s[i + 1]]++;
        if (i - k + 2 >= 0) cnt[s[i - k + 2]]--;
    }
    if (k == 1) ans = 0;
    cout << ans << endl;
    return 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int X, N; cin >> X >> N;
  vector<int> p(N); REP(i, N) cin >> p[i];
  if(N == 0) {
    cout << X << endl;
  } else {
    sort(all(p));
    int res = 0;
    for(int i = 0; i < N; ++i) {
      if(p[i] == X) {
        res = i;
        break;
      }
    }
    int a = 0;
    int b = 0;
    // 右へ
    for(int i = res; i < N; ++i) {
      if(i == N - 1) {
        a = p[i] + 1;
        break;
      }
      if(abs(p[i] - p[i + 1]) != 1) {
        a = p[i] + 1;
        break;
      }
    }
    // 左へ
    for(int i = res; i >= 0; --i) {
      if(i == 0) {
        b = p[i] - 1;
        break;
      }
      if(abs(p[i] - p[i - 1]) != 1) {
        b = p[i] - 1;
        break;
      }
    }

    int A = abs(X - a);
    int B = abs(X - b);
    if(A > B) {
      cout << b << endl;
    } else if(A < B) {
      cout << a << endl;
    } else if(A == B) {
      cout << min(a, b) << endl;
    }
  }
}


Measured memory_bytes: 3628
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    for(int i = 0; i <= n / 4; ++i){
        for(int j = 0; j <= (n - 4 * i) / 7; ++j){
            if(4 * i + 7 * j == n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 632
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	ll n, m;
	cin >> n >> m;
	if(n % 3 == 0 || m % 3 == 0){
		cout << 0 << endl;
		return 0;
	}
	ll ans = 1e18;
	for(ll i = max(1LL, (n / 2) - 100); i <= min(n - 1, (n / 2) + 100); i++){
		for(ll j = 1; j < m; j++){
			ll a = 1LL * i * j;
			ll b = 1LL * (n - i) * j;
			ll c = 1LL * (m - j) * n;
			ans = min(ans, max({abs(a - b), abs(a - c), abs(b - c)}));
		}
	}
	swap(n, m);
	for(ll i = max(1LL, (n / 2) - 100); i <= min(n - 1, (n / 2) + 100); i++){
		for(ll j = 1; j < m; j++){
			ll a = 1LL * i * j;
			ll b = 1LL * (n - i) * j;
			ll c = 1LL * (m - j) * n;
			ans = min(ans, max({(ll)abs(a - b), (ll)abs(a - c), (ll)abs(b - c)}));
		}
	}
	ans = min(ans, min(m, n));
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();
      	String[] ss = new String[2*100000];
        int[] sss = new int[2*100000];
        String[] tt = new String[2*100000];
        int[] ttt = new int[2*100000];
      	Set<String> se = new HashSet<String>();
      	Set<String> se2 = new HashSet<String>();
      for(int i = 0; i< S.length() ; i++){
        se.add(S.substring(i,i+1));
      }
      for(int i = 0; i< T.length() ; i++){
        se2.add(T.substring(i,i+1));
      }
      int i = 0;
      for(String value : se){
	  	ss[i] = value;
        int count = 0;
        for(int j = 0; j < S.length(); j++){
        	if(Objects.equals(ss[i],S.substring(j,j+1)))
            {
            count++;
            }
        }
        sss[i] = count;
        ++i;
      }
      
      int ii = 0;
      for(String value : se2){
	  	tt[ii] = value;
        int count = 0;
        for(int j = 0; j < T.length(); j++){
        	if(Objects.equals(tt[ii],T.substring(j,j+1)))
            {
            count++;
            }
        }
        ttt[ii] = count;
        ++ii;
      }
      Arrays.sort(sss);
      Arrays.sort(ttt); 
      
      if(Arrays.equals(sss,ttt)){
      System.out.println("Yes");
      } else{
      System.out.println("No");
      }
    }
}

Measured memory_bytes: 140088
#include <iostream>
using namespace std;
		   
int main()
{
	int max = 1000000;
	bool* pt;
	pt = new bool[max];
	pt[1] = false;
	pt[2] = true;
	for (int i = 3; i < max; i++)
	{
		pt[i] = true;
		if (i % 2 == 0) { pt[i] = false; continue; }
		else {
			for (int l = 3; l*l <= i; l+=2)
			{
				if (i%l == 0) { pt[i] = false; break; }
			}
		}
	}
	while (1)
	{
		int a, d, n, c=0;
		cin >> a >> d >> n;
		if (a == 0&&d==0&&n==0)break;
		for (int i = a;; i += d)
		{
			if (pt[i] == true) { c++; }
			if (c == n) { cout << i << endl; break; }
		}
	}
	return 0;
}

Measured memory_bytes: 2156
// aribon2-2_f
#include <iostream>
#include <vector>

using namespace std;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define COUT(x) cout << x << endl

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

int W, H;
vector<vector<int>> C;

void dfs(int h, int w){
    C[h][w] = 0;
    REP(i, 8){
        int nh = h + dx[i];
        int nw = w + dy[i];
        if (C[nh][nw] == 0) continue;
        dfs(nh, nw);
    }
}

int main() {

    while (true){
        cin >> W >> H;
        if (W == 0 && H == 0) return 0;

        C.assign(H+2, vector<int>(W+2, 0));
        REP(i, H) REP(j, W){
            cin >> C[i+1][j+1];
        }

        int ans = 0;
        REPN(i, 1, H+1) REPN(j, 1, W+1){
            if (C[i][j] == 0) continue;
            dfs(i, j);
            ans++;
        }

        COUT(ans);
    }
}



Measured memory_bytes: 3204
import sys
import numpy as np

N, L = list(map(int, input().split()))

# 味
LL = np.arange(L,L+N)

m = abs(LL[0])

for i in range(N):
    if abs(m) > abs(LL[i]):
        m = LL[i]

print(np.sum(LL)-m)


Measured memory_bytes: 21116
#include <iostream>
#include <stdio.h>
#include <math.h>

int isPrime( int x ) {
    if ( x == 1 ) return 0;
    if ( x == 2 ) return 1;
    if ( x % 2 == 0 && x != 2 ) {
        return 0;
    }
    
    for (int i = 3; i <= sqrt(x); i+=2) {
        if ( x % i == 0 ) return 0;
    }
    return 1;
}

int main() {
    int n, num;
    int sum = 0;
    scanf("%d", &n);
    
    for ( int i = 0; i < n; i++ ) {
        scanf("%d", &num);
        sum += isPrime( num );
    }
    printf("%d\n", sum);
    
    return 0;
}

Measured memory_bytes: 3180
N, X = gets.split.map(&:to_i)

@p = [1]; (1 .. N).each{|n| @p[n] = 2*@p[n - 1] + 1}
@l = [1]; (1 .. N).each{|n| @l[n] = 2*@l[n - 1] + 3}

def f(n, x)
  return x <= 0 ? 0 : 1 if n == 0
  return f(n - 1, x - 1) if x <= @l[n - 1] + 1
  @p[n - 1] + 1 + f(n - 1, x - @l[n - 1] - 2)
end

puts f(N, X)

Measured memory_bytes: 1788
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
using ll = long long;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define rep(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288

int main(){
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc *bufio.Scanner

const BufferSize = 1024

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

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	d := nextInt()
	w := 2*d + 1
	ans := n / w
	if n%w > 0 {
		ans++
	}

	_, _ = fmt.Fprintf(writer, "%d", ans)
}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 640
#include<stdio.h>
#define LEN 4

int main(void)
{
	int n;
	int arr[LEN];
	int a, b, c, d;
	int i;

	scanf("%d", &n);
	for (i = 0; i <= 3; i++) {
		arr[i] = n % 10;
		n = n / 10;
	}
	d = arr[0];
	c = arr[1];
	b = arr[2];
	a = arr[3];

	if (a + b + c + d == 7) {
		printf("%d+%d+%d+%d=7\n", a, b, c, d);
	}
	else if (a + b + c - d == 7) {
		printf("%d+%d+%d-%d=7\n", a, b, c, d);
	}
	else if (a + b - c + d == 7) {
		printf("%d+%d-%d+%d=7\n", a, b, c, d);
	}
	else if (a + b - c - d == 7) {
		printf("%d+%d-%d-%d=7\n", a, b, c, d);
	}
	else if (a - b + c + d == 7) {
		printf("%d-%d+%d+%d=7\n", a, b, c, d);
	}
	else if (a - b + c - d == 7) {
		printf("%d-%d+%d-%d=7\n", a, b, c, d);
	}
	else if (a - b - c + d == 7) {
		printf("%d-%d-%d+%d=7\n", a, b, c, d);
	}
	else if (a - b - c - d == 7) {
		printf("%d-%d-%d-%d=7\n", a, b, c, d);
	}
	return 0;
}

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

struct edge{ int to; int w;};
const int MAXN = 1e5;
vector<vector<edge>> to(MAXN);
vector<int> color(MAXN, -1); // 0 or 1

bool comp(edge e1, edge e2){
	return e1.to < e2.to;
}


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

	rep(i,n-1){
		int u,v,w;
		cin >> u >> v >> w;
		u--; v--;
		to[u].push_back(edge{v,w});
		to[v].push_back(edge{u,w});
	}
	
	vector<int> color(n,-1); // 0 or 1
	queue<pair<edge,int>> que;
	color[0] = 0;
	que.push(make_pair(edge{0,0},-1));
	
	while(!que.empty()){
		auto q = que.front();
		que.pop();
		if(q.second!=-1){
			if(q.first.w % 2 == 0){
				color[q.first.to] = color[q.second];
			}
			else{
				color[q.first.to] = color[q.second] ^ 1;
			}
		}
		for( auto v : to[q.first.to]){
			if(color[v.to] == -1) que.push(make_pair(v,q.first.to));
		}
	}

	
	rep(i,n) cout << color[i] << endl;
	return 0;
}


Measured memory_bytes: 7168
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    a_min = a[0]
    a_max = a[-1]

    total = 0
    for num in a:
        total += num
    
    print(a_min, a_max, total)


if __name__ == "__main__":
    main()

Measured memory_bytes: 8720
import Data.Bits
import Control.Monad

solve :: Int -> [[Int]] -> [Int] -> Int
solve n xss ps = length $ filter id $ map (\b -> step xss ps b) [0..2^n-1]
    where
        step :: [[Int]] -> [Int] -> Int -> Bool
        step [] [] b = True
        step (xs:xss) (p:ps) b = (res (tail xs) p) && (step xss ps b)
            where
                res xs p = (foldl step' 0 xs) `rem` 2 == p
                step' :: Int -> Int -> Int
                step' acc x
                    | (shiftR b (x-1)) .&. 1 == 1 = acc + 1
                    | otherwise = acc

main = do
    [n,m] <- map read . words <$> getLine :: IO [Int]
    xss <- replicateM m (map read . words <$> getLine) :: IO [[Int]]
    ps <- map read . words <$> getLine :: IO [Int]
    print $ solve n xss ps

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long a,b,x;
scanf("%lld %lld %lld",&a,&b,&x);
if(a>0)
{
printf("%lld",(b/x)-(a-1)/x);
}
else
{
printf("%lld",(b/x)+1);
}}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
const ll INF = 1e9;
//プロトタイプ宣言
void faster(void);
ll gcd(auto , auto);
ll get_digent(auto);
ll POW(auto , auto);

int main(){
  faster();
  ll ans=0,n,od=0,ev=0;
  cin >> n;
  vl odd(1e5),even(1e5);
  rep(i,n/2){
    cin >> od >> ev;
    odd[od]++;
    even[ev]++;
  }
  ll mode_odd=0,mode_even=0,temp1=0,temp2=0;
  //最頻値をそれぞれ求める
  rep(i,1e5){
    if(temp1 < odd[i]){
      temp1 = odd[i];
      mode_odd = i;
    }
    if(temp2 < even[i]){
      temp2 = even[i];
      mode_even = i;
    }
  }
  sort(odd.rbegin(),odd.rend());
  sort(even.rbegin(),even.rend());
  //書き直さないものを、書き換えないものを全体から引くことで求める
  if(mode_even == mode_odd) cout << min(n - odd[1] - even[0] , n - odd[0] - even[1]) << endl;
  //最頻値が異なるとき、それに合わせてやればよい
  else cout << n - odd[0] - even[0] << endl;
}








































//以下、ライブラリ

void faster(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

ll gcd(auto a, auto b) {
  return (b ? gcd(b, a%b) : a);
} //ユークリッドの互除法

ll get_digent(auto x){
  string s;
  s = to_string(x);
  ll digent = s.size();
  return digent;
} //桁数取得

ll POW(auto x,auto y){
  if(y==0) return 1;
  if(y%2 == 1){
    ll temp = POW(x,y-1);
    return (temp*x);
  }
  else{
    ll temp = POW(x,y/2);
    return temp*temp;
  }
} //べき乗計算

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

int main() {
    int N;
    cin >> N;
    int d[N];
    rep(i, N) cin >> d[i];

    sort(d, d + N);
    cout << d[N/2] - d[N/2-1] << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N, K;
    cin >> N >> K;
    unordered_set<lint> digits;
    range(i, 0, K) {
        lint num;
        cin >> num;
        digits.emplace(num);
    }
    // cout << digits << "\n";
    range(i, N, N * 100 + 1) {
        bool okay = true;
        lint cur_num = i;
        while (cur_num) {
            lint lsd;
            lsd = cur_num % 10, cur_num /= 10;
            if (digits.count(lsd)) okay = false;
        }
        if (okay) {
            cout << i << "\n";
            return 0;
        }
    }
}

Measured memory_bytes: 256