akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define pb push_back
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
#define skip continue
#define NAME "code"
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pii;
typedef long double ld;
 
void faster(){
  	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
	cout.tie(NULL);
}
 
const int MAXN = 2e5 + 1;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const ld PI = acos(-1);
 
ll n, x;

ll gcd(ll a, ll b){
	while(b){
		a %= b;
		swap(a, b);
	}
	return a;
}

int main(){
 
faster();

cin >> n >> x;

cout << 3ll * (n - gcd(n, x));


return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
auto constexpr infty<int> = 1'100'100'100;
template<>
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

namespace { // Graph Basics

template<typename WeightT>
struct Edge {
  int from, to;
  WeightT weight;
  Edge(int s, int d, WeightT w): from(s), to(d), weight(w) {}
};

template<typename WeightT>
bool
operator< (Edge<WeightT> const &lhs, Edge<WeightT> const &rhs) {
  if (lhs.weight != rhs.weight) {
    return lhs.weight < rhs.weight;
  } else if (lhs.from != rhs.from) {
    return lhs.from < rhs.from;
  }
  return lhs.to < rhs.to;
}

template<typename WeightT>
using Edges = std::vector<Edge<WeightT> >;

template<typename WeightT>
using AdjacencyList = std::vector<Edges<WeightT> >;

template<typename WeightT>
void
add_undir_edge(AdjacencyList<WeightT> &graph, int u, int v, WeightT w) {
  graph[u].emplace_back(u, v, w);
  graph[v].emplace_back(v, u, w);
}

} // namespace

namespace { // Dijkstra's algorithm

template<typename WeightT>
struct DijkstraResult {
  std::vector<WeightT> distance;
};

template<typename WeightT>
DijkstraResult<WeightT>
dijkstra_algorithm(AdjacencyList<WeightT> const &g, int start, WeightT inf) {
  int const N = g.size();
  std::vector<bool> done(N, false);
  std::vector<WeightT> dist(N, inf);
  using P = std::tuple<WeightT, int>;
  std::priority_queue<P, std::vector<P>, std::greater<P> > que;
  que.emplace(0, start);
  while (!que.empty()) {
    WeightT dist2u; int u; std::tie(dist2u, u) = que.top();
    que.pop();
    if (dist2u >= dist[u]) {
      continue;
    }
    dist[u] = dist2u;
    for (auto &&e : g[u]) {
      que.emplace(dist2u + e.weight, e.to);
    }
  }
  return {
    dist
  };
}

} // namespace

using namespace std;

using Graph = AdjacencyList<lli>;

void solve(Graph const &g) {
  auto const res = dijkstra_algorithm(g, 0, infty<lli>);
  REP(i, g.size()) {
    cout << (res.distance[i] % 2 == 0 ? 0 : 1) << '\n';
  }
}

int main() {
  // cout << fixed << setprecision(10);

  int N;
  cin >> N;
  Graph g(N);
  REP(i, N-1) {
    int U, V, W;
    cin >> U >> V >> W;
    add_undir_edge(g, --U, --V, (lli)W);
  }
  solve(g);
  return 0;
}


Measured memory_bytes: 9344
import sys
 
 
xx = 500000
f = [0, 1] * xx
 
i = 3
while i * i <= 2 * xx:
    if f[i] == 1:
        j = i * i
        while j <= 2 * xx:
            f[j] = 0
            j += i + i
    i += 2
 
f.pop(0)
f.pop(1)
 
for n in sys.stdin:
    i = int(n)
    if i < 2:
        print(0)
    else:
        print(sum(f[:i - 1]))

Measured memory_bytes: 24208
def insertionSort(A, N):
    for i in range(N):
        v = A[i]
        j = i -1
        while j >= 0 and A[j] > v:
             A[j+1] = A[j]
             j -= 1
        A[j+1] = v
        b = 0
        for i in A:
            b +=1
            if b == N:
                print(i, end ="")
            else:
                print(i, end =" ")
        print()
n = int(input())
a = [int(i) for i in input().split()]
insertionSort(a,n)


Measured memory_bytes: 5980
#include<stdio.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int MOD=1e9+7,MAX=1e6;
static inline char CH(void)
{
  static char buf[100000],*ptr1=buf,*ptr2=buf;
  return ptr1==ptr2&&(ptr2=(ptr1=buf)+fread(buf,1,100000,stdin),ptr1==ptr2)?EOF:*ptr1++;
}
static inline int IN(void)
{
  int x=0,f=0,c=CH();while(c<48||c>57){f^=c==45,c=CH();}
  while(c>47&&c<58){x=x*10+c-48,c=CH();}return f?-x:x;
}
typedef struct{int SPF[1000001];int Primes[78498];int sz;}Template;
Template P;
static inline int MPow(int a,int b){return b?1l*MPow(1l*a*a%MOD,b>>1)*(b&1?a:1)%MOD:1;}
static inline void ready(void)
{
  *P.SPF=1,*P.Primes=2,P.sz=1;
  rep(i,MAX/2)P.SPF[2*(i+1)]=2,P.SPF[2*(i+1)-1]=2*(i+1)-1;
  rep(i,MAX/2-1)
  {
    int x=2*(i+1)+1;if(P.SPF[x]==x){P.Primes[P.sz++]=x;}
    rep(j,P.sz){if(P.Primes[j]<=P.SPF[x]&&x*P.Primes[j]<=MAX)P.SPF[x*P.Primes[j]]=P.Primes[j];else break;}
  }
}
int main(void)
{
  int N=IN(),A=0,factor=0,invsum=0,lcm=1,x=0,box[1000001]={};ready();
  rep(i,N)
  {
    A=IN();invsum=(invsum+1l*MPow(A,MOD-2))%MOD;
    while(A>1)
    {
      factor=P.SPF[A];x=0;
      while(A%factor==0)A/=factor,x++;
      if(box[factor]<x)box[factor]=x; 
    }
  }
  rep(i,P.sz){if(box[P.Primes[i]])lcm=1l*lcm*MPow(P.Primes[i],box[P.Primes[i]])%MOD;}
  return printf("%ld\n",1l*lcm*invsum%MOD),0;
}

Measured memory_bytes: 9744
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define MAX 1e6
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

bool comp(ll a,ll b){
	return a > b;
}
int main() 
{
	ll x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	ll p[a],q[b],r[c];
	REP(i,0,a) cin>>p[i];
	REP(i,0,b) cin>>q[i];
	REP(i,0,c) cin>>r[i];

	sort(p,p+a,comp);
	sort(q,q+b,comp);
	sort(r,r+c,comp);

	ll sum = 0;
	vector<ll> v;
	REP(i,0,x){
		v.push_back(p[i]);
		sum += p[i];
	}
	REP(i,0,y){
		v.push_back(q[i]);
		sum += q[i];
	}
	sort(v.begin(),v.end());

	ll ind1 = 0;
	ll ind2 = 0;
	while(ind2 < c && ind1 < v.size()){
		if(r[ind2] > v[ind1]){
			sum = sum - v[ind1] + r[ind2];
			ind1++;
			ind2++;
		}
		else {
			break;
		}
	}
	cout<<sum<<endl;
	return 0;
}  


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

using namespace std;

typedef long long int ll;

const ll mod = 1e9 + 7;
const ll MAXN = 1e5 + 5;

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

  string s;
  cin >> s;
  ll n = s.length();
  vector < vector < ll > > dp(n, vector < ll >(13, 0));
  if(s[0] == '?'){
    for(int i = 0; i < 10; i++) dp[0][i] = 1;
  }else dp[0][s[0] - '0'] = 1;

  for(int i = 1; i < n; i++){
    if(s[i] == '?'){
      for(int d = 0; d < 10; d++){
        for(int j = 0; j < 13; j++){
          dp[i][(10 * j + d) % 13] += dp[i - 1][j];
          dp[i][(10 * j + d) % 13] %= mod;
        }
      }
    }else{
      ll a = s[i] - '0';
      for(int j = 0; j < 13; j++){
        dp[i][(10 * j + a) % 13] += dp[i - 1][j];
        dp[i][(10 * j + a) % 13] %= mod;
      }
    }
  }

  cout << dp[n - 1][5] << '\n';
}


Measured memory_bytes: 13648
#include <stdio.h>
#include <math.h>

/* {1,2,3} -> ... -> {3,2,1} */
int next_permutation(int arr[],int n) {
	int target;
	int i;
	int temp;
	for (i = n - 2; i >= 0; i--) {
		if (arr[i] < arr[i + 1]) break;
	}
	if (i < 0) return 0;
	target = i;

	for (i = 0; target + i + 1 < n - i - 1; i++) {
		temp = arr[target + 1 + i];
		arr[target + 1 + i] = arr[n - 1 - i];
		arr[n - i - 1] = temp;
	}

	for (i = target + 1; i < n; i++) {
		if (arr[i] > arr[target]) break;
	}
	temp = arr[i];
	arr[i] = arr[target];
	arr[target] = temp;
	return 1;
}

int main(void) {
	int N;
	int x[8], y[8];
	int i;
	int order[8];
	int count = 0;
	double sum = 0;
	if (scanf("%d", &N) != 1) return 1;
	if (N < 2 || 8 < N) {
		puts("out of range");
		return 2;
	}
	for (i = 0; i < N; i++) {
		if (scanf("%d%d", &x[i], &y[i]) != 2) return 1;
		order[i] = i;
	}

	do {
		for (i = 1; i < N; i++) {
			int p = order[i - 1], c = order[i];
			sum += sqrt((x[c] - x[p]) * (x[c] - x[p]) + (y[c] - y[p]) * (y[c] - y[p]));
		}
		count++;
	} while (next_permutation(order, N));
	printf("%.15f\n", sum / count);
	return 0;
}


Measured memory_bytes: 128
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

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

func main() {
	defer stdout.Flush()
	n := readInt()
	a := make([]int, n)
	for i := range a {
		a[i] = readInt()
	}
	m := make(map[int64]int)
	var s int64 = 0
	m[s]++
	for i := range a {
		s = s + int64(a[i])
		m[s]++
	}
	var ans int64
	for _, v := range m {
		if 1 < v {
			var x int64
			if v%2 == 0 {
				x = int64(v/2) * int64(v-1)
			} else {
				x = int64(v) * int64((v-1)/2)
			}
			ans += x
		}
	}
	println(ans)
}

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


Measured memory_bytes: 13824
#include <vector>
    #include <string>
    #include <tuple>
    #include <iostream>
    #include <sstream>
    #include <algorithm>
    #include <set>
    #include <map>
    #include <cmath>
    #include <numeric>
    #include <queue>

    #define ll long long
    #define ld long double

    using namespace std;

    vector<ll> vert;

    ll getComp(ll v) {
        if(vert[v] == v) {
            return v;
        } else {
            return vert[v] = getComp(vert[v]);
        }
    }

    void edg(ll a, ll b) {
        a = getComp(a);
        b = getComp(b);
        vert[a] = b;
    }

    vector<vector<ll>> mat;

    ll dx[]{0, 1, 0, -1};
    ll dy[]{1, 0, -1, 0};

    bool isValid(ll x, ll y, ll n, ll m) {
        return x >= 0 && x < n && y >= 0 && y < m;
    }

    int main() {
        ll n, m;cin >> n >> m;cout << ((n == m) ? "Yes" : "No");
    }


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

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

  int n; cin >> n;
  vector<int> a(n+2);
  for(int i = 1; i <= n; i++){
    cin >> a[i];
  }
  a[0] = a[n+1] = 0;

  int sum = 0;
  for(int i = 1; i <= n+1; i++){
    sum += abs(a[i] - a[i-1]);
  }

  for(int i = 1; i <= n; i++){
    int res = abs(a[i-1] - a[i+1]) - (abs(a[i] - a[i-1]) + abs(a[i] - a[i+1]));
    cout << sum + res << endl;
  }

  return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;

int main(){
    int r;
    cin>>r;
    if(r<1200){
        cout<<"ABC"<<endl;
    }else if(r<2800){
        cout<<"ARC"<<endl;
    }else{
        cout<<"AGC"<<endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
//https://hk-cnyali.com/2018/02/07/AGC007-C-Pushing-Balls/
int main()
{
	ll n;
	double a,x;
	scanf("%lld%lf%lf",&n,&a,&x);
	double ans=0;
	ll m=2*n;
	while(m){
		ans+=(2*a+(m-1)*x)*1.0/2;
        a=((m+2)*a+5*x)*1.0/m;
        x=(m+4)*x*1.0/m;
        m-=2;
	}
	printf("%.10f",ans);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;



int main(){
    char a;
    cin >> a;
    char b = a + 1;
    cout << b << endl;
}

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

int64_t calc_digit(int64_t n)
{
  int ans = 0;
  while(n != 0)
  {
    ans++;
    n /= 10;
  }
  return (ans);
}

int main()
{
  int64_t N, ans = 11, i = 1;

  cin >> N;
  while (i * i <= N)
  {
    if (N % i == 0)
      ans = min(max(calc_digit(i), calc_digit(N / i)), ans);
    i++;
  }
  cout << ans << endl;
}

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

void Main()
{
	int N;
  	cin >> N;
	int rN = floor(sqrt(N));
  	rep(i, rN+1){
    	rep(j, N+1){
          if (N == i*j && i<10 && j <10){
				cout << "Yes" << endl;
            	return;
          }
       } 
    }
  	cout << "No" << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);
	Main();
  	return 0;
}




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

using namespace std;

long long sieve_size;
bitset<1000009> bs;

void sieve(long long upperbound, vector<long long> &primes){
    sieve_size = upperbound;
    bs.set();
    bs[0] = bs [1] = 0;
    for(long long i = 2; i <= sieve_size; i++)
        if(bs[i]) {
            for (long long j = i*i; j <= sieve_size; j+=i)
                bs[j] = 0;
            primes.push_back(i);
        }
}

bool isPrime(long long n, vector<long long> &primes) {
    if(n <= sieve_size) return bs[n];
    auto upp = (long long)sqrt(n);
    for (int i = 0;primes[i] <= upp and i <(int)primes.size(); ++i)
        if(n % primes[i] == 0) return false;
    return true;
}

int main(){
    ios::sync_with_stdio(false);
    vector<long long> v;
    sieve(55565, v);
    int n;
    cin>>n;
    vector<long long> ans;
    for(int i=0;i*5+1<=55555;++i){
        if(isPrime(5*i+1,v)){
            ans.push_back(5*i+1);
            if((int)ans.size()==n) break;
        }

    }
    for(auto x:ans) cout<<x<<" ";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <cassert>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using W = V<V<T>>;

template <class T> struct Fenwick {
	int n;
	V<T> seg;
	Fenwick(int _n = 0) : n(_n), seg(n + 1) {}
	// 在第i个元素上+x
	void add(int i, T x) {
		i++;
		while (i <= n) {
			seg[i] += x;
			i += i & -i;
		}
	} 
	//  [0,i)的sum
	T sum(int i) {
		T s = 0;
		while (i > 0) {
			s += seg[i];
			i -= i & -i;
		}
		return s;
	} 
	// [a, b)的sum
	T sum(int a, int b) { return sum(b) - sum(a); } 
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n, q;
	cin >> n >> q;
	
	Fenwick<ll> fw(n);
	
	for (int i = 0; i < n; ++i) {
		ll a;
		cin >> a;
		fw.add(i, a);
	}
	
	for (int i = 0; i < q; ++i) {
		int t;
		cin >> t;
		if (t == 0) {
			int p;
			ll x;
			cin >> p >> x;
			fw.add(p, x);
		}
		else {
			ll l, r;
			cin >> l >> r;
			cout << fw.sum(l, r) << '\n';
		}
	}
	
	return 0;
}

Measured memory_bytes: 8256
#include <iostream>
#include <iomanip>
#include <vector>
#include <unordered_map>

using namespace std;
 
int main()
{
    int N,K,Q;
    cin >> N >> K >> Q;
    unordered_map<int, int> A;

    for (int i=0; i<Q; i++) {
        int temp;
        cin >> temp;
        // cout << "temp:" << temp << endl;
        auto itr = A.find(temp);
        if (itr != A.end()) {
            A[temp]++;
        } else {
            A[temp]=1;
        }
        // cout << "A[temp]:" << A[temp] << endl;
    }

    for (int i=1; i<=N; i++) {
        int success = 0;

        auto itr = A.find(i);
        if (itr != A.end()) {
            success = A[i];
        } else {
            success = 0;
        }
        // cout << i << " " << K << " " << success << " " << Q << endl;
        if (0 < K+success-Q) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <map>
#include <climits>
#include <bitset>
using namespace std;
#define MATH_PI 3.14159265358979323846
int main(){
	ios::sync_with_stdio(false);
	vector<int> arrNums;
	int nCount, nAdd, iSum=0,iIn,i;
	cin >> nCount>>nAdd;
	for (i = 1; i <= nCount; ++i){
		cin >> iIn;
		arrNums.push_back(iIn);
	}
	sort(arrNums.begin(), arrNums.end());
	for (i = nCount - 1; i >= nCount - nAdd; --i){
		iSum += arrNums[i];
	}
	cout << iSum << endl;
endapp:
	//system("pause > nul");
	return 0;
}

Measured memory_bytes: 384
N = int(input())
S = "0"+input()
lr = [0]
lg = [0]
lb = [0]
for j in range(1,N+1):
  if S[j] == "R":
    i = j-1
    lr.append(lr[i]+1)
    lg.append(lg[i])
    lb.append(lb[i])
  if S[j] == "G":
    i = j-1
    lr.append(lr[i])
    lg.append(lg[i]+1)
    lb.append(lb[i])
  if S[j] == "B":
    i = j-1
    lr.append(lr[i])
    lg.append(lg[i])
    lb.append(lb[i]+1)

cnt = 0
mcnt = 0
for i in range(1,N+1):
  s = S[i]
  for j in range(1,N-i+1): 
    #Rパターン
    if s == "R":      
      if S[i+j] == "R":
        continue
      else:
        if i+j <= N and i-j >=0:
          if (S[i+j] == "B" and S[i-j] == "G") or (S[i+j] == "G" and S[i-j] == "B"):
            mcnt += -1 
        if S[i+j] == "G":
          cnt += lb[i-1]
        if S[i+j] == "B":
          cnt += lg[i-1]
    #Gパターン
    if s == "G":      
      if S[i+j] == "G":
        continue
      else:
        if i+j <= N and i-j >=0: 
          if (S[i+j] == "B" and S[i-j] == "R") or (S[i+j] == "R" and S[i-j] == "B"):
            mcnt += -1 
        if S[i+j] == "R":
          cnt += lb[i-1]
        if S[i+j] == "B": 
          cnt += lr[i-1]   
    #Bパターン
    if s == "B":      
      if S[i+j] == "B":
        continue
      else:
        if i+j <= N and i-j >=0: 
          if (S[i+j] == "G" and S[i-j] == "R") or (S[i+j] == "R" and S[i-j] == "G"):
            mcnt += -1 
        if S[i+j] == "R":
          cnt += lg[i-1]
        if S[i+j] == "G": 
          cnt += lr[i-1]  
print(cnt+mcnt)

Measured memory_bytes: 74684
#include <iostream>

using namespace std;
int main() {
    int K;
    int A, B;
    cin >> K;
    cin >> A >> B;
    for (int i=A; i<=B; i++) {
        if (i % K == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG"<< endl;
    return 0;
}



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

using namespace std;

#define fore(i, s, e) for(int i = s; i < e; i++)


typedef long long ll;

const int N = 3500;

int n;
int a[N];

ll dp[2][N][N];

ll calc(int i, int j, int k) {
    if(j > k) return 0;
    ll &r = dp[i][j][k];
    if(r != -1) return r;
    ll res = 0;
    res = max(a[j] - calc((i + 1) % 2, j + 1, k), a[k] - calc((i + 1) % 2, j, k - 1));
    // cout << i << " " << j << " " << k << "  " << res << endl;
    return r = res;
}

int main() {
    cin >> n;
    fore(i, 0, n) cin >> a[i];
    memset(dp, -1, sizeof dp);
    cout << calc(0, 0, n - 1) << endl;
}

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

typedef long long ll;
#define mod 1000000007

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

void solve(){
    int n;
    cin>>n;
    vector<vector<int>> dp(n+1, {0, 0, 0}), a(n, {0, 0, 0});
    for(int i = 0; i < n; i++){
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    for(int i = 1; i <= n; i++){
        dp[i][0] = max((dp[i-1][1] + a[i-1][1]), (dp[i-1][2] + a[i-1][2]));
        dp[i][1] = max((dp[i-1][0] + a[i-1][0]), (dp[i-1][2] + a[i-1][2]));
        dp[i][2] = max((dp[i-1][1] + a[i-1][1]), (dp[i-1][0] + a[i-1][0]));
    }
    cout<<*max_element(dp[n].begin(), dp[n].end());
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    // pre();
    while (t--)
        solve();

    return 0;
}

Measured memory_bytes: 14176
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  string s;
  cin>>s;
  int n=s.size();

  if(n%2==0){
    cout << (s[0]==s[n-1]?"First":"Second") << endl;
  }

  if(n%2==1){
    cout << (s[0]!=s[n-1]?"First":"Second") << endl;
  }

}

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

string s;
bool ch = 0;

int main() {
  cin >> s;
  for(int i = 0; i < 3; ++i)
    if(s[i] == s[i + 1]) ch = 1;
  if(!ch)
    cout << "Good" << endl;
  else
    cout << "Bad" << endl;
  return 0;
}

Measured memory_bytes: 256
from heapq import*
import sys
r=sys.stdin.readline
def g(n,E,S,G):
 F=[1e7]*-~n;F[S]=0;H=[(0,S)]
 while H:
  c,u=heappop(H)
  if u==G:return c
  for f,v in E[u]:
   if c+f<F[v]:t=c+f;F[v]=t;heappush(H,(t,v))
 return-1
def s(n,k):
 E=[[]for _ in[0]*-~n]
 for _ in[0]*k:
  f=r()
  if'0'==f[0]:print(g(n,E,*map(int,f[2:].split())))
  else:c,d,e=map(int,f[2:].split());E[c]+=[(e,d)];E[d]+=[(e,c)]
for e in iter(r,'0 0\n'):s(*map(int,e.split()))


Measured memory_bytes: 6308
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadLong;

            if (N % 2 != 0)
            {
                Console.WriteLine(0);
                return;
            }

            var ans = 0L;
            for (int i = 0; i < 26; i++)
            {
                var d = 10L * (long)Pow(5, i);
                ans += N / d;
            }
            Console.WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


Measured memory_bytes: 11220
#include <cstdio>
#include <cstring>

char s[101], t[8];

int main()
{
    scanf("%s", s);
    int n = strlen(s);
    if (n < 7) {
        puts("NO");
    } else {
        bool found = false;
        t[7] = '\0';
        for (int i = 0; i <= 7 && i <= n && !found; ++ i) {
            int tot = 0;
            for (int j = 0; j < i; ++ j) {
                t[tot ++] = s[j];
            }
            for (int j = 0; j < 7 - i; ++ j) {
                t[tot ++] = s[n - (7 - i) + j];
            }
            found |= strcmp(t, "keyence") == 0;
        }
        puts(found ? "YES" : "NO");
    }
}


Measured memory_bytes: 128
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
n=int(input())

d=make_divisors(n)


count=0
ans=[]
for i in d:
    pair=n//i
    count=(pair-1)+(i-1)
    ans.append(count)

print(min(ans))

Measured memory_bytes: 3552
import sys
input = sys.stdin.buffer.readline

def main():
	N = int(input())
	p = list(map(int,input().split()))
	nl = [0]*N
	for i,num in enumerate(p):
		nl[num-1] = i+1
	nl.reverse()
	
	class BinaryIndexedTree:
		
		# 初期化
		def __init__(self, size, default):
			self.size = size
			self.default = default
			self.BIT = [default]*(self.size+1)
 
		# function(max, min, plus, minus, etc...)
		def BIT_segfunc(self, x, y):
			return x+y
 
		def BIT_query(self, idx):
			ret = self.default
			while idx > 0:
				ret = self.BIT_segfunc(ret, self.BIT[idx])
				idx -= idx&(-idx)
			return ret
 
		# update
		def BIT_update(self, idx, x):
			while idx <= self.size:
				self.BIT[idx] = self.BIT_segfunc(self.BIT[idx], x)
				idx += idx&(-idx)
			return
 
		def BIT_range(self, x, y):
			return self.BIT_query(y)-self.BIT_query(x)
 
		# BIT確認用
		def BIT_print(self):
			print(self.BIT)
			
		def BIT_search(self, x):
			i = 0
			s = 0
			step = 1<<(self.size.bit_length()-1)
			while step:
				if i+step <= self.size and s + self.BIT[i+step] < x:
					i += step
					s += self.BIT[i]
				step >>= 1
			return i+1
	
	BIT = BinaryIndexedTree(N, 0)
	ans = 0
	for i,num in enumerate(nl):
		l = BIT.BIT_query(num)
		BIT.BIT_update(num, 1)
		r = i-l
		a = BIT.BIT_search(l-1) if l >= 2 else 0
		b = BIT.BIT_search(l) if l >= 1 else 0
		d = BIT.BIT_search(l+2) if r >= 1 else N+1
		e = BIT.BIT_search(l+3) if r >= 2 else N+1
		ret = 0
		if b != 0:
			ret += (b-a)*(d-num)
		if d != 0:
			ret += (e-d)*(num-b)
		ans += ret*(N-i)
	print(ans)
	
if __name__ == "__main__":
	main()

Measured memory_bytes: 53256
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=float('inf')

N=INT()
G=[[0]*N for i in range(N)]
for i in range(N):
    l=LIST()
    u=l[0]
    l=l[2:]
    for v in l:
        G[u-1][v-1]=1

for i in range(N):
    print(*G[i])



Measured memory_bytes: 6400
#include <iostream>
#define ll long long
using namespace std;

int main()
{
	ll k, a, b;
	cin >> k >> a >> b;

	ll ret = 0;
	if (b - a <= 2) {
		ret = k + 1;
	}
	else {
		ll surplusOperation = k - (a - 1);
		if (surplusOperation < 0) {
			ret = k + 1;
		}
		else {
			if (surplusOperation % 2 == 1) {
				ret = 1;
			}
			ret += (surplusOperation / 2) * (b - a) + a;
		}
	}

	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
hs = list(map(int, input().split()))

max_ = 0
point = 0
while point <= n-2:
    j = point
    count = 0
    while hs[j] >= hs[j+1]:
        j += 1
        count += 1
        if j == n-1:
            break
    
    if count > max_:
        max_ = count
    
    point = j+1
print(max_)

Measured memory_bytes: 14252
#include <stdio.h>
 
int fact(long n){
    if(n==0){
        return 1;
    }else{
        return (n*fact(n-1))%1000000007;
    }
}
 
int main(void){
int a;scanf("%d",&a);
    printf("%d\n",fact((long)a));
    return 0;
}

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

int main() {
	string S;
	cin >> S;
	int N = S.size();

	vector<string> a(N/2);
	vector<string> b(N/2);

	for (int i = 0; i < (N-1)/2; i++) {
		a.at(i) = S.at(i);
	}

	for (int j = ((N + 3) / 2) - 1; j < N; j++) {
		b.at(j- (((N + 3) / 2) - 1)) = S.at(j);
	}

	bool x = true;

	for (int i = 0; i < N/2; i++) {
		if (a.at(i) != b.at(i)) {
			x = false;
		}
	}
	if (x == true) cout << "Yes" << endl;
	if (x == false) cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
int main() {
    std::cin.tie(nullptr); std::ios::sync_with_stdio(false);

    int N, K;
    std::string S;
    std::cin >> N >> K;
    std::cin >> S;
    std::vector<int> counts;//直立、逆立ちを交互にカウント。0を許して直立始まり直立終わり
    counts.reserve(N);//push_back高速化
    int count = 1;
    if (S.front() == '0')counts.push_back(0);//直立始まり
    for (int i = 1; i < N; i++) {
        if (S[i - 1] == S[i])++count;
        else {
            counts.push_back(count);
            count = 1;
        }
    }
    counts.push_back(count);
    if (S.back() == '0')counts.push_back(0);//直立終わり

    int size = counts.size();
    std::vector<int> sum(size + 1, 0);//累積和
    int tmp = 0;
    for (int i = 0; i < size; i++) {
        tmp += counts[i];
        sum[i + 1] = tmp;
    }
    sum.push_back(sum.back());
    int ans = 0;
    for (int i = 0; i < size; i += 2)
        ans = std::max(ans, sum[std::min(i + 2 * K + 1, size)] - sum[i]);

    std::cout << ans << std::endl;
}

Measured memory_bytes: 1616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[33]={0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){
	int k;
	cin>>k;
	cout<<a[k]<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n,flag = 0;
    scanf("%d",&n);
    do{
        if(n % 10 == 7){
            flag = 1;
            break;
        }
        n /= 10;
    }while(n >= 7);
    
    if(flag == 1) printf("Yes\n");
    else printf("No\n");
    
    return 0;
}


Measured memory_bytes: 1644
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int, int>;
     
const int MOD = 1e9 + 7;


int main(){
   int n;
   cin >> n;
   int res = 0;
   rep(i, n){
      int a;
      cin >> a;
      if(i % 2 == 1)continue;
      if(a % 2 == 1)res++;
   }
   cout << res << endl;
}


Measured memory_bytes: 3632
fn main() {
    let n = read::<u32>();
    let numbers = read_vec::<u32>();
    for num in numbers.iter() {
        if num % 2 != 0 {
            continue;
        }

        if num % 3 != 0 && num % 5 != 0 {
            println!("DENIED");
            return;
        }
    }

    println!("APPROVED");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 2172
#include<bits/stdc++.h>
using namespace std;
long long n,h,maxn;
string st;
int main()
{
    cin>>n;
    cin>>st;
    for(int i=0;i<st.size();i++)
    {
        if(st[i]=='D')	h--;
        else h++;
        if(h>maxn)	maxn=h;
    }
    cout<<maxn<<endl;
    return 0;
}

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

int main(){
    int n,max1=0,max2=0,idx;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(max1<a[i]){
            max2=max1;
            max1=a[i];
            idx=i;
        }
        else if(max2<a[i]){
            max2=a[i];
        }
    }
    for(int i=0;i<n;i++){
        if(i!=idx){
            cout<<max1<<"\n";
        }else{
            cout<<max2<<"\n";
        }
    }
    
    return 0;
}


Measured memory_bytes: 2432
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect
import itertools


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = inputs[0]
    target = S
    while len(target) > 0:
        n = len(target)
        candidate1 = target[n-5:]
        candidate2 = target[n-6:]
        candidate3 = target[n-7:]
        if candidate1 == 'dream' or candidate1 == 'erase':
            target = target[:n-5]
        elif candidate2 == 'eraser':
            target = target[:n-6]
        elif candidate3 == 'dreamer':
            target = target[:n-7]
        else:
            return 'NO'
    return 'YES'


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


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

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  int c = b/k;
  if (c*k >= a)
  cout << "OK" << endl;
  else
  cout << "NG" << endl;
}


Measured memory_bytes: 3600
n=int(input())
val= input()
a = val.split()
l = list(map(int, a))
s=0
max_ =0
for i in range(len(l)):
    if max_ < l[i]:
        max_ = l[i]
    if l[i]<max_:
        k =max_-l[i]
        s = s +k
print(s)

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

vector<bool> IsPrime;
vector<int> Primes;
vector<int> Counter;

void sieve(size_t max) {
    if(max + 1 > IsPrime.size()) { // resizeで要素数が減らないように
        IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保
    }
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i = 2; i * i <= max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i])                   // iが素数ならば
            for(size_t j = 2; i * j <= max; ++j) // (max以下の)iの倍数は
                IsPrime[i * j] = false;          // 素数ではない
}

void getPrimes(size_t max) {
    sieve(max);
    for(int i = 2; i <= max; i++) {
        if(IsPrime[i]) {
            Primes.push_back(i);
        }
    }
}

void factCount(int n) {
    for(int i = 0; i < Primes.size() && Primes[i] <= n; i++) {
        // cout << n << "%" << Primes[i] << ": " << n % Primes[i] << endl;
        while(true) {
            if(n % Primes[i] == 0) {
                Counter[Primes[i]]++;
                n /= Primes[i];
            } else
                break;
        }
    }
}

int main() {
    int n;
    ll mod = 1e9 + 7, ans = 1;
    cin >> n;
    getPrimes(n);

    // rep(i, Primes.size()) { cout << "prime" << i << ": " << Primes[i] <<
    // endl; }

    Counter.resize(n + 1);

    for(int i = 2; i <= n; i++) {
        factCount(i);
    }

    // rep(i, Counter.size()) { cout << "num" << i << ": " << Counter[i] <<
    // endl; }

    for(int i = 0; i <= n; i++) {
        ans = (ans * (Counter[i] + 1)) % mod;
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59


int main(){
  ll i,j;
  ll n;
  cin>>n;
  ll a[n],b[n];
  for(i=0;i<n;i++) cin>>a[i];
  for(i=0;i<n;i++) cin>>b[i];
  
  ll c[n];
  ll ans=0;
  for(i=0;i<30;i++){
    for(j=0;j<n;j++){
      c[j]=b[j]&((1<<(i+1))-1);
    }
    sort(c,c+n);
    ll p;
    ll q=0;
    for(j=0;j<n;j++){
      p=a[j]&((1<<(i+1))-1);
      q+=upper_bound(c,c+n,(1<<(i+2))-1-p)-lower_bound(c,c+n,(1<<(i+1))+(1<<i)-p);
      q+=upper_bound(c,c+n,(1<<(i+1))-1-p)-lower_bound(c,c+n,(1<<i)-p);
      q%=2;
    }
    if(q&1) ans+=(1<<i);
  }
  cout<<ans<<endl;


  return 0;
}

Measured memory_bytes: 4992
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		sc.close();

		int temp;

		temp = x;
		x = y;
		y = temp;

		temp = x;
		x = z;
		z = temp;
		System.out.println(x + " " + y + " " + z);
	}
}

Measured memory_bytes: 21716
import sys
sys.setrecursionlimit(10**6)
N,M = map(int,input().split())

class Union_Find():

    def __init__(self,n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rank = [0]*(n+1)

    def find_root(self,x):
        if self.root[x]<0:
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]

    def unite(self,x,y):
        x = self.find_root(x)
        y = self.find_root(y)

        if x==y:
            return
        elif self.rank[x]>self.rank[y]:
            self.root[x]+=self.root[y]
            self.root[y]=x
        else:
            self.root[y]+=self.root[x]
            self.root[x]=y

            if self.rank[x]==self.rank[y]:
                self.rank[y]+=1

    def same(self,x,y):
        return self.find_root(x)==self.find_root(y)

    def cnt(self,x):
        return -self.root[self.find_root(x)]

G=Union_Find(N)
ans=0
for i in range(M):
    a,b=map(int,input().split())
    G.unite(a,b)

for i in range(1,N+1):
    ans = max(ans,G.cnt(i))
print(ans)

Measured memory_bytes: 81688
#include <bits/stdc++.h>
using namespace std;
int main () {
  long x;
  cin >> x;
  long ans;
  if(x % 11 == 0) ans = 2 * (x / 11);
  else if (x % 11 < 7) ans = 2 * (x / 11) + 1;
  else if (x % 11 < 11) ans = 2 * (x / 11) + 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <tuple>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <map>
#include <queue>

using namespace std;
#define PI       3.14159265358979323846
#define MOD 1000000007

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef complex<double> P;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;

struct edge {
	int to;
	LL d;
	edge(int _to, LL _d) : to(_to), d(_d) {}
};

using graph = vector<vector<edge> >;

struct state {
	LL d;
	int v;
	state(LL _d, int _v) : v(_v), d(_d) {}
	bool operator<(const state& right)const {
		return d == right.d ? v < right.v : d < right.d;
	}
	bool operator>(const state& right)const {
		return d == right.d ? v > right.v : d > right.d;
	}
};

LL dp1[100005];
LL dp2[100005];
LL d1[100005];
LL d2[100005];

void calc(graph g, int s, LL *d, LL *dp) {
	priority_queue<state, vector<state>, greater<state>> q;
	q.push(state(0LL, s));
	d[s] = 0;
	dp[s] = 1;
	while (!q.empty()) {
		state tmp = q.top();
		q.pop();
		auto tv = tmp.v;
		auto td = tmp.d;
		if (td > d[tv])continue;
		REP(i, g[tv].size()) {
			if (td + g[tv][i].d < d[g[tv][i].to]) {
				d[g[tv][i].to] = td + g[tv][i].d;
				dp[g[tv][i].to] = dp[tv];
				q.push(state(d[g[tv][i].to], g[tv][i].to));
			}
			else if (td + g[tv][i].d == d[g[tv][i].to]) {
				dp[g[tv][i].to] = (dp[g[tv][i].to]+dp[tv])%MOD;
			}
		}
	}
}

int main() {
	memset(d1, 0x77, sizeof(d1));
	memset(d2, 0x77, sizeof(d2));
	int n, m, s, t;
	scanf("%d%d%d%d", &n, &m, &s, &t);
	s--, t--;
	graph g(n);
	REP(i, m) {
		int u, v, d;
		scanf("%d%d%d", &u, &v, &d);
		u--, v--;
		g[u].PB(edge(v, d));
		g[v].PB(edge(u, d));
	}
	calc(g, s, d1, dp1);
	calc(g, t, d2, dp2);

	LL ret = (dp1[t] * dp1[t]) % MOD;
	// meet on point
	REP(i, n) {
		if (2 * d1[i] == d1[t]) {
			LL tmp = dp1[i];
			tmp = (tmp*dp1[i]) % MOD;
			tmp = (tmp*dp2[i]) % MOD;
			tmp = (tmp*dp2[i]) % MOD;
			ret = (ret + MOD - tmp) % MOD;
		}
	}
	// meet on edge
	REP(i, n) {
		if (2 * d1[i] >= d1[t])continue;
		REP(j, g[i].size()){
			if (2 * d2[g[i][j].to] >= d2[s])continue;
			if (d1[i] + d2[g[i][j].to] + g[i][j].d == d1[t]) {
				LL tmp = dp1[i];
				tmp = (tmp*dp1[i]) % MOD;
				tmp = (tmp*dp2[g[i][j].to]) % MOD;
				tmp = (tmp*dp2[g[i][j].to]) % MOD;
				ret = (ret + MOD - tmp) % MOD;
			}
		}
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 28304
from collections import Counter
S = input()
P = [0] * (len(S)+1)
mod = 2019
d = 1
for i in range(len(S), 0, -1):
    P[i-1] = int(S[i-1])*d + P[i]
    P[i-1] = P[i-1] % mod
    d *= 10
    d = d % mod

P = Counter(P)
ans = 0
for p in P.values():
    ans += p*(p-1)//2
print(ans)

Measured memory_bytes: 16544
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  int N; cin >> N;
  vector<int> A(N);
  for (auto& a : A) { cin >> a; }
  set<int> s(A.begin(), A.end());
  auto ans = s.size();
  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256