akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
  int k, ans = 0;std::cin >> k;
  int num[201];
  for(int i=0;i<=200;i++) num[i] = 0;
  for(int i=k;i>0;i--){
    num[i] += (k/i)*(k/i)*(k/i);
    for(int j=2;j*j<=i;j++){
      if(i%j!=0) continue;
      num[j] -= num[i];
      if(j*j!=i) num[i/j] -= num[i];
    }
    if(i!=1) num[1] -= num[i];
    ans += num[i] * i;
  }
  std::cout << ans << '\n';
}



Measured memory_bytes: 3164
import sys
import math
#from queue import *
#import random
#sys.setrecursionlimit(int(1e6))
input = sys.stdin.readline
 
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
    return(int(input()))
def inara():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
################################################################
############ ---- THE ACTUAL CODE STARTS BELOW ---- ############

s=insr()

for i in range(0,len(s),2):
	if s[i]=='L':
		print("No")
		exit(0)

for i in range(1,len(s),2):
	if s[i]=='R':
		print("No")
		exit(0)

print("Yes")


Measured memory_bytes: 9084
#include <iostream>
#include <math.h>
using namespace std;
 
int main(void){
    int H1,M1,H2,M2,K;
  	scanf("%d%d%d%d%d",&H1,&M1,&H2,&M2,&K);
	int hoge1,hoge2;
  	hoge1 = H1*60+M1;
  	hoge2 = H2*60+M2;
  	int time;
  	if(hoge1<hoge2){
      time = hoge2-hoge1;
    }else{
    	time = 24*60+hoge2-hoge1;
    }
	printf("%d",time-K);
}

Measured memory_bytes: 3244
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
int ispal(string s)
{
    ll flag=1,i,n;
    n=s.length();
    for(i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-1-i])
        {
            
        flag=0;
        break;
        }
    }
    return flag;
}
int main()
{
       string s,a,b;
       cin>>s;
       ll len;
       len=s.length();
       ll i,j,fl1=0,fl2=0,fl3=0;
       for(i=0;i<(len-1)/2;i++)
       {
           a.pb(s[i]);
       }
       for(i=(len+3)/2-1;i<len;i++)
       {
           b.pb(s[i]);
       }
       fl1=ispal(a);
       fl2=ispal(b);
       fl3=ispal(s);
      // cout<<b;
      // cout<<fl3<<fl2<<fl1;
       if(fl1+fl2+fl3==3)
       cout<<"Yes\n";
       else
       cout<<"No\n";
        
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define MAX_N 200010
long long inv[MAX_N];
long long factorial[MAX_N];
long long inv_factorial[MAX_N];

void get_inv(){
    for (int i = 1; i < MAX_N; i++) {
        if (i == 1) inv[i] = 1;
        else {
            inv[i] = (mod - (mod / i) * inv[mod % i]) % mod;
            if (inv[i] < 0) inv[i] += mod;
        }
    }
}
void get_factorial(){
    factorial[0] = 1; inv_factorial[0] = 1;
    for (int i = 1; i < MAX_N; i++) {
        factorial[i] = factorial[i-1] * i;
        factorial[i] %= mod;
        inv_factorial[i] = inv_factorial[i-1] * inv[i];
        inv_factorial[i] %= mod;
    }
}

long long combination(int n, int r) {
    if (n < r) return 0;
    long long ret = factorial[n] * inv_factorial[r];
    ret %= mod;
    ret *= inv_factorial[n-r];
    return ret % mod;
}

long long modpow(int n, int r) {
    long long ret = 1; long long tmp = (long long) n;
    while (r != 0) {
        if (r % 2) ret *= tmp;
        tmp *= tmp; tmp %= mod; ret %= mod;
        r /= 2;
    }
    return ret;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    get_inv(); get_factorial();
    int n, k; cin >> n >> k;
    vector<long long> a(n);
    vector<long long> acc(n+1, 0);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    for (int i = 0; i < n; i++) {
        acc[i+1] = acc[i] + a[i];
    }
    long long ans = 0;
    for (int i = 1; i < n; i++) {
        long long fxsum = (acc[n] - acc[i]) - (acc[n-i]);
        fxsum %= mod;
        long long curr = fxsum * combination(max(0, i-1), max(0, k-2)) % mod;
        ans = (ans + curr) % mod;
    }
    cout << ans << "\n";
    return 0;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;


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

    rep2(i,a,b){
        if(i<=a+k-1||i>=b-k+1)cout<<i<<endl;;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;
const long INF = 1e9;
const long MOD = 1e9 + 7;
#define repi(i, n, init) for (int i = init; i < int(n); i++)

int main()
{
    int n, m;
    cin >> n >> m;
    if (m <= n)
    {
        cout << 0 << endl;
        return 0;
    }
    vector<int> x(m);
    repi(i, m, 0)
    {
        cin >> x[i];
    }
    sort(x.begin(), x.end());
    repi(i, m, 1)
    {
        x[i - 1] = abs(x[i] - x[i - 1]);
    }
    sort(x.begin(), x.end()-1);
    int ans = 0;
    repi(i, m - 1 - n + 1, 0)
    {
        ans += x[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
#define MP make_pair
#define PB push_back
#define SZ(a) ((int)a.size())
typedef long long ll;

int N, a;
deque<int> q;

int main () {
        cin >> N;
        fo(i, 0, N) {
                cin >> a;
                if (i&1) q.push_front(a);
                else q.push_back(a);
        }
        if (N&1) {
                while (q.size()) printf("%d ", q.back()), q.pop_back();
        } else {
                while (q.size()) printf("%d ", q.front()), q.pop_front();
        }
        return 0;
}


Measured memory_bytes: 2944
import java.util.Scanner;

public class Main{
	
	public static int max(int x, int y) {
		if(x > y)
			return x;
		else return y;
	}
	
	public static int longest(String x, String y) {
		int[][] results = new int[x.length()+1][y.length()+1];
		int max = 0;
		for(int i = 0; i <= x.length(); i++) {
			for(int j = 0; j <= y.length(); j++) {
				if(i == 0 || j == 0)
					results[i][j] = 0;
				else if(x.charAt(i-1) == y.charAt(j-1))
					results[i][j] = results[i-1][j-1] + 1;
				else results[i][j] = max(results[i-1][j], results[i][j-1]);
				if(results[i][j] > max)
					max = results[i][j];
			}
		}
		return max;
	}
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int limit = in.nextInt();
		for(int i = 0; i < limit; i++) {
			System.out.println(longest(in.next(), in.next()));
		}
		in.close();
	}

}



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

int bubbleSort(int arr[], int n){
	int count = 0;
	for(int i = 0; i < n; i++){
		for(int j = n - 1; j > i; j--){
			if(arr[j] < arr[j - 1]){
				swap(arr[j], arr[j - 1]);
				count++;
			}
		}
	}
	return count;
}

void printArr(int arr[], int n){
	for(int i = 0; i < n; i++){
		cout << arr[i];
		if( i != n - 1){
			cout << ' ';
		}
	}
	cout << endl;
}

int main(){
	int n;
	int arr[100];

	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> arr[i];
	}

	int numOfSwaps = bubbleSort(arr, n);
	printArr(arr, n);
	cout << numOfSwaps << endl;

	return 0;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/03/17  Problem: ARC 092 A / Link: http://arc092.contest.atcoder.jp/tasks/arc092_a  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;



/*----------------------------
二部マッチング O(VE)
はやい
aliveはまだ
-----------------------------*/
struct Bipartite_Matching { // 借り物ライブラリにすること
	vector<vector<int> > graph;
	vector<int> match, alive, used;
	int timestamp;

	Bipartite_Matching(int n) {
		timestamp = 0;
		graph.resize(n);
		alive.assign(n, 1);
		used.assign(n, 0);
		match.assign(n, -1);
	}

	void add_edge(int u, int v) {
		graph[u].push_back(v);
		graph[v].push_back(u);
	}

	bool dfs(int v) {
		used[v] = timestamp;
		for (int i = 0; i < (int)graph[v].size(); i++) {
			int u = graph[v][i], w = match[u];
			if (alive[u] == 0) continue;
			if (w == -1 || (used[w] != timestamp && dfs(w))) {
				match[v] = u;
				match[u] = v;
				return (true);
			}
		}
		return (false);
	}

	int bipartite_matching() {
		int ret = 0;
		for (int i = 0; i < (int)graph.size(); i++) {
			if (alive[i] == 0) continue;
			if (match[i] == -1) {
				++timestamp;
				ret += dfs(i);
			}
		}
		return (ret);
	}
};




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

	cin >> N;
	VL a(N);
	VL b(N);
	VL c(N);
	VL d(N);
	FOR(i, 0, N) {
		cin >> a[i] >> b[i];
	}
	FOR(i, 0, N) {
		cin >> c[i] >> d[i];
	}
	Bipartite_Matching F(2 * N);
	FOR(i, 0, N) {
		FOR(j, 0, N) {
			if (a[i] < c[j] && b[i] < d[j]) {
				F.add_edge(i,N+j);
			}
		}
	}
	ans = F.bipartite_matching();
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int gcd(int a, int b)
{
    if (a < b)
        int c = a, a = b, b = c;
    return a % b == 0 ? b : gcd(b, a % b);
}

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int g=gcd(a,b);
  if(c%g==0)
    cout<<"YES"<<endl;
  else
     cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<string>
#include<time.h>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;

#define rep(i, n) for(int i = 0; i < (n); ++i)

using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    auto cmp = [](const P& a, const P& b) {
        if (a.first == b.first) return a.second > b.second;
        else return a.first > b.first;
    };
    auto cmp2 = [](const P& a, const P& b) {
        if (a.second == b.second) return a.first > b.first;
        else return a.second < b.second;
    };
    set<P, decltype(cmp)> rp(cmp);
    set<P, decltype(cmp2)> bp(cmp2);
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        rp.insert(P(a, b));
    }
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        bp.insert(P(a, b));
    }
    int res = 0;
    for (auto itr = rp.begin(); itr != rp.end(); ++itr) {
        for (auto it = bp.lower_bound(*itr); it != bp.end(); ++it) {
            if (itr->first < it->first) {
                bp.erase(it);
                ++res;
                break;
            }
        }        
    }
    cout << res << endl;
    return 0;
}



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

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using pii = std::pair<int, int>;
using namespace std;

constexpr ll INF = numeric_limits<ll>::max();

int main() {
  ll N, W;
  cin >> N >> W;
  vec<ll> w(N), v(N);
  REP(i, N) { cin >> v[i] >> w[i]; }

  vec<pair<ll, ll>> f(1 << (N / 2));
  REP(i, 1 << (N / 2)) {
    ll sw = 0, sv = 0;
    REP(j, N / 2) {
      if ((i >> j) & 0x01) {
        sw += w[j];
        sv += v[j];
      }
    }
    f[i] = make_pair(sw, sv);
  }
  sort(ALL(f));
  size_t m = 1;
  FOR(i, 1, 1 << (N / 2)) {
    if (f[m - 1].second < f[i].second) {
      f[m++] = f[i];
    }
  }

  ll answer = 0;
  REP(i, 1 << (N - (N / 2))) {
    ll sw = 0, sv = 0;
    REP(j, N - (N / 2)) {
      if ((i >> j) & 0x01) {
        sw += w[N / 2 + j];
        sv += v[N / 2 + j];
      }
    }
    if (sw <= W) {
      ll tv =
          (lower_bound(f.begin(), next(f.begin(), m), make_pair(W - sw, INF)) -
           1)
              ->second;
      answer = max(answer, sv + tv);
    }
  }
  cout << answer << endl;
  return 0;
}



Measured memory_bytes: 19196
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  ll H, W;
  cin >> H >> W;
  ll m = H * W;
  m = min(m, min(1LL, (H % 3)) * W); // 横に分ける
  m = min(m, min(1LL, (W % 3)) * H); // 縦に分ける
  ll a, b, c;
  switch(H % 2){
  case 0:
    switch(W % 3){
    case 0:
      m = min(m, 0LL);
      break;
    case 1:
      m = min(m, H / 2);
      break;
    case 2:
      m = min(m, H / 2);
      break;
    }
    break;
  case 1:
    switch(W % 3){
    case 0:
      m = min(m, W / 3 * 2);
      break;
    case 1:
      a = W / 3 * 2 + H / 2 + 1;
      b = H / 2;
      c = W / 3;
      m = min(m, max(a - b, a - c));

      a = W / 3 * 2;
      b = 0;
      c = W / 3 + H;
      m = min(m, max(c - b, a - b));
      break;
    case 2:
      a = W / 3 * 2 + H / 2 * 2 + 2;
      b = H / 2 * 2;
      c = W / 3;
      m = min(m, max(abs(a - b), max(abs(a - c), abs(b - c))));

      a = W / 3 * 2 + H / 2 + 1;
      b = H / 2;
      c = W / 3 + H;
      m = min(m, max(abs(a - b), max(abs(a - c), abs(b - c))));

      a = W / 3 * 2;
      b = 0;
      c = W / 3 + H * 2;
      m = min(m, max(abs(a - b), max(abs(a - c), abs(b - c))));
      break;
    }
    break;
  }
  switch(W % 2){
  case 0:
    switch(H % 3){
    case 0:
      m = min(m, 0LL);
      break;
    case 1:
      m = min(m, W / 2);
      break;
    case 2:
      m = min(m, W / 2);
      break;
    }
    break;
  case 1:
    switch(H % 3){
    case 0:
      m = min(m, H / 3 * 2);
      break;
    case 1:
      a = H / 3 * 2 + W / 2 + 1;
      b = W / 2;
      c = H / 3;
      m = min(m, max(a - b, a - c));

      a = H / 3 * 2;
      b = 0;
      c = H / 3 + W;
      m = min(m, max(c - b, a - b));
      break;
    case 2:
      a = H / 3 * 2 + W / 2 * 2 + 2;
      b = W / 2 * 2;
      c = H / 3;
      m = min(m, max(abs(a - b), max(abs(a - c), abs(b - c))));

      a = H / 3 * 2 + W / 2 + 1;
      b = W / 2;
      c = H / 3 + W;
      m = min(m, max(abs(a - b), max(abs(a - c), abs(b - c))));

      a = H / 3 * 2;
      b = 0;
      c = H / 3 + W * 2;
      m = min(m, max(abs(a - b), max(abs(a - c), abs(b - c))));
      break;
    }
    break;
  }
  cout << m << endl;
  return 0;
}


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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int n;
char s[N], t[N];
char ani[] = {'S', 'W'};

bool check(int st, int l, int r)
{
	if (st == 'S' && s[1] == 'o' && l != r) return false;
	else if (st == 'S' && s[1] == 'x' && l == r) return false;
	else if (st == 'W' && s[1] == 'o' && l == r) return false;
	else if (st == 'W' && s[1] == 'x' && l != r) return false;
	
	t[0] = l, t[1] = st, t[2] = r;
	for (int i = 2; i <= n; i ++ )
		if (t[i] == 'S')
		{
			if (s[i] == 'x') t[i + 1] = t[i - 1] == 'W' ? 'S' : 'W';
			else t[i + 1] = t[i - 1];
		}
		else
		{
			if (s[i] == 'o') t[i + 1] = t[i - 1] == 'W' ? 'S' : 'W';
			else t[i + 1] = t[i - 1];
		}
		
	return t[0] == t[n] && t[n + 1] == t[1];
}

int main()
{
	scanf("%d%s", &n, s + 1);
	
	for (int i = 0; i < 2; i ++ )
		for (int j = 0; j < 2; j ++ )
			for (int k = 0; k < 2; k ++ )
				if (check(ani[i], ani[j], ani[k]))
				{
					t[n + 1] = '\0';
					puts(t + 1);
					return 0;
				}
	
	puts("-1");
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;int main(){int N;cin>>N;vector<pair<int,int>>R(N);for(auto&i:R){int a,b;cin>>a>>b;i={a,a+b};}sort(R.begin(),R.end());vector<int>V(N+1,1),f(N);for(int i=N;i--;){int&l=f[i]=i+1;while(l<N&&R[l].first<R[i].second)l=f[l];V[i]=(V[i+1]+V[l])%998244353;}cout<<V[0]<<'\n';return 0;}

Measured memory_bytes: 3328
N = int(input())

A_list = []
B_list = []
sum_list = []
ans = 0


for i in range(N):
	A, B = map(int, input().split())
	A_list.append(A)
	B_list.append(B)
	sum_list.append([A+B, i])

sum_list.sort()

for i in range(N):
	point, j = sum_list.pop()
	if i%2 == 0:
		ans += A_list[j]
	else:
		ans -= B_list[j]

print(ans)

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

int f(int a, int hp) {
  return (hp+a-1)/a;
}

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(f(d,a) <  f(b,c)) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;

}




Measured memory_bytes: 3556
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int pt = 0, px = 0, py = 0;
	int t, x, y;
	int dt, dx, dy;
	for (int i = 0; i < n; i++) {
		cin >> t >> x >> y;

		dt = t - pt;
		dx = x - px;
		dy = y - py;

		if (abs(dx) + abs(dy) - dt > 0) {
			cout << "No" << endl;
			return 0;
		}
		else if ((dt - abs(dx) + abs(dy)) % 2 == 1) {
			cout << "No" << endl;
			return 0;
		}

		pt = t;
		px = x;
		py = y;
	}
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,cnt,L,ans,N;
vector<ll> v,a={1,3,6,10,15,21,28,36,45,55};
int main(void){
    cin>>n;
    N=n;
    for(ll i=2;i*i<=N;i++){
        if(n%i==0){
            while(n%i==0){
                n/=i;
                cnt++;
            }
            v.push_back(cnt);
            cnt=0;
        }
    }
    if(n!=1)v.push_back(1);
    for(auto x:v){
        //cout<<x<<endl;
        L=upper_bound(a.begin(),a.end(),x)-a.begin();
        ans+=L;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3632
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 
 using namespace std;

 int main()
 {
   string str;
   cin>>str;
   for(int i=0;i<str.length()/2;i++) swap(str[i],str[str.length()-i-1]);
   cout<<str<<endl;
   //while(1);      
   return 0;    
 }
 
 

Measured memory_bytes: 3160
//void __(){
//    _(int,n);
//    _(vpsi,a,n);
//    _(string,x);
//    int l = 0;
//    while(a[l].X != x)
//        ++l;
//    ll ans = 0;
//    rep(i,l+1,n-1)
//        ans += a[i].Y;
//    print ans;
//}
//
#include <iomanip>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define REP_INT(i,l,r) for(int i = l; i <= r; ++i)
#define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT,REP_ZERO_INT)(__VA_ARGS__)
#define all(v) (v).begin(), (v).end()
#define sz(v) ll(v.size())
#define X first
#define Y second
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
typedef pair<string,int> psi;
typedef vector<psi> vpsi;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
template <typename F, typename S> static
istream& operator>>(istream& stream, pair<F, S>& t){
    return stream >> t.first >> t.second;
}
T1 istream& read(T, T, istream& = cin);
T1 istream& operator>>(istream& stream, vector<T>& t){
    return read(all(t), stream);
}
T1 istream& read(T b, T e, istream& stream){
    for(T it = b; it != e; ++it)
        stream >> *it;
    return stream;
}
struct _print {
    string sep,end;
    bool space;
    ostream &stream;
    _print(string _sep=" ",string _end="\n",
            ostream &_stream = cout)
        : sep(_sep),end(_end),space(false),
            stream(_stream) {}
    ~_print() { stream << end; }
    template <typename T>
        _print &operator , (const T &t) {
            if (space) stream << sep;
            space = true;
            stream << t;
            return *this;
        }
};
#define print _print(),
#define INPUT_WITHOUT_INIT(type,name) type name; cin >> name
#define _IWI(type,name,...) type name(__VA_ARGS__); cin >> name
#define GET_INPUT_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define _(...) GET_INPUT_MACRO(__VA_ARGS__,_IWI,_IWI,_IWI,_IWI,_IWI,_IWI,INPUT_WITHOUT_INIT)(__VA_ARGS__)
void __(){
    _(int,n);
    _(vpsi,a,n);
    _(string,x);
    int l = 0;
    while(a[l].X != x)
        ++l;
    ll ans = 0;
    rep(i,l+1,n-1)
        ans += a[i].Y;
    print ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        __();
}


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

void insertionSort(int A[], int N) {
    for (int i = 1; i < N; i++) {
        int v = A[i];
        int j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        for (int k = 0; k < N; k++) {
            if (k > 0) cout << " ";
            cout << A[k];
        }
        cout << endl;
    }
    return;
}

int main() {
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++) {
        if (i > 0) cout << " ";
        cin >> A[i];
        cout << A[i];
    }
    cout << endl;
    insertionSort(A, N);
}


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

int main()
{
	int N, res = 30;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int A, cnt = 0;
		cin >> A;
		while (A % 2 == 0) A /= 2, cnt++;
		res = min(res, cnt);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 100005
typedef long long ll;
int n;ll a[N];
int main() {
	ll l=2,r=2;
	scanf("%d",&n);
	for(int i=0;i<n;++i) scanf("%lld",a+i);
	for(int i=n-1;~i;--i) {
		l=a[i]*((l+a[i]-1)/a[i]);
		r=a[i]*(r/a[i]+1)-1;
		if(l>r) {
			puts("-1");return 0;
		}
	}
	printf("%lld %lld\n",l,r);
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <utility>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
#define MAXSIZE 100000
#define MAXL 100
typedef long long int lli;

vector<lli> numList = {0, 0, 0, 0, 0};
vector<char> capList = {'M', 'A', 'R', 'C', 'H'};
vector <vector<string>> nameList = {{}, {}, {}, {}, {}};
vector<lli> dupList;

bool isGoodCap(char c);

//bool isNewName(string s);

//void increaseNumList(char c);

void getDupList();

void WriteOnNameList(string s);

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

    for(lli i = 0; i < n; i++){
        string s;
        cin >> s;
        if(isGoodCap(s[0])/* && isNewName(s)*/){
            WriteOnNameList(s);
            //nameList.push_back(s);
            //dupList.push_back(0);
            //increaseNumList(s[0]);
        }
    }

    //lli ub = nameList.size();
    lli ans = 0;
    for(lli i = 0; i < 5 - 2; i++){
        for(lli j = i + 1; j < 5 - 1; j++){
            for(lli k = j + 1; k < 5; k++){
                ans += (lli)(nameList[i].size()) * (lli)(nameList[j].size()) * (lli)(nameList[k].size());
            }
            //cout << "nameList[" << i << "][" << j << "] = " << nameList[i][j] << endl;
        }
    }
    cout << ans << endl;
    return 0;
}

bool isGoodCap(char c){
    for(lli i = 0; i < capList.size(); i++){
        if(c == capList[i]){
            return true;
        }
    }
    return false;
}

/*bool isNewName(string s){
    for(lli i = 0; i < nameList.size(); i++){
        if(s == nameList[i]){
            return false;
        }
    }
    return true;
}

void increaseNumList(char c){
    switch (c){
        case 'M':
            numList[0]++;
            break;
        case 'A':
            numList[1]++;
            break;
        case 'R':
            numList[2]++;
            break;
        case 'C':
            numList[3]++;
            break;
        default:
            numList[4]++;
            break;
    }
    return;
}*/

void getDupList(){
    for(lli i = 0; i < nameList.size(); i++){
        for(lli j = 0; j < nameList.size(); j++){
            if(i == j){
                continue;
            }else{
                if(nameList[i] == nameList[j]){
                    dupList[i]++;
                }
            }
        }
    }
    return;
}

void WriteOnNameList(string s){
    switch (s[0]){
        case 'M':
            nameList[0].push_back(s);
            break;
        case 'A':
            nameList[1].push_back(s);
            break;
        case 'R':
            nameList[2].push_back(s);
            break;
        case 'C':
            nameList[3].push_back(s);
            break;
        default:
            nameList[4].push_back(s);
            break;
    }
}

Measured memory_bytes: 5748
s = input()
a = [0 for _ in range(len(s)+1)]

cur = 0
for i in range(len(s)):
    if s[i] == '<':
        cur += 1
    else:
        cur = 0
    a[i+1] = max(a[i+1], cur)
    
cur = 0
for i in range(len(s)):
    j = len(s)-1 - i
    if s[j] == '>':
        cur += 1
    else:
        cur = 0
    a[j] = max(a[j], cur)
    
print(sum(a))

Measured memory_bytes: 24100
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define all(obj) (obj).begin(), (obj).end()
#define lpair pair<ll, ll>
#define vint vector<ll>
#define vinput(name) for(int i=0; i<(int)(name.size()); i++) cin >> name[i];
#define voutput(name) for(int i=0; i<(int)(name.size()); i++) cout << name[i] << endl;
typedef long long ll;

using namespace std;

ll ans = 0;

int main(void){
	string a, b; cin >> a >> b;
	if(a < b){
		rep(i, stoi(b))cout << a;
	} else{
		rep(i, stoi(a))cout << b;
	}
	return 0;
}

Measured memory_bytes: 256
local n=io.read("*n")
local a={}
for i=1,n do
    a[i]=io.read("*n")
end

local box={}
for i=n,1,-1 do
    local ball=0
    for j=2*i,n,i do
        ball=ball+(box[j] or 0)
    end
    if ball%2~=a[i] then
        box[i]=1
    end
end

local counter=0
for i=1,n do
    if box[i]==1 then
        counter=counter+1
    end
end
print(counter)
for i=1,n do
    if box[i]==1 then
        print(i)
    end
end

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

using namespace std;

#define LL long long 
#define ULL unsigned LL
#define LD long double 

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	int a[n];
	int x = 0;
	for(int i=0; i<n; i++) {
		cin>>a[i];
		x^=a[i];
	}
	int w[n];
	for(int i=0; i<n; i++) {
		w[i] = x^a[i];
		cout<<w[i]<<" ";
	}
}


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

public class Main {
  private static String solve(char[] cs) {
    Deque<Character> stack = new ArrayDeque<>();
    for (char c : cs) {
      if (c != 'B') {
        stack.addLast(c);
      } else if (!stack.isEmpty()) {
        stack.pollLast();
      }
    }
    StringBuffer sb = new StringBuffer();
    for (char c : stack) {
      sb.append(c);
    }
    return sb.toString();
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    char[] cs = reader.nextCharArray();
    out.println(solve(cs));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


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

int main() {
  string s; cin >> s;
  int n = s.size();
  for (int i = 1; i < n; i++) {
    if ((n - i) % 2) continue;
    int d = (n - i) / 2;
    bool f = true;
    for (int j = 0; j < d; j++) {
      if (s[j] != s[j + d]) f = false;
    }
    if (f) {
      cout << n - i << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
const int maxn = 100;

int a,b,n;
int ans = 0;

int32_t main() {
	FAST	
	cin >> a >> b >> n;
	
	ans = (floor(a * n / b) - a * floor(n/b));
	n = (int) floor(n / b) * b - 1;
	ans = max(ans, (int) (floor(a * n / b) - a * floor(n/b)));
	
	cout << ans;
	
	
}



Measured memory_bytes: 3648
//This disgusting code is wriiten by Juruo D0zingbear
//Please don't hack me! 0v0 <3
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string.h>
#include <stdio.h>
#define LL long long
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define piii pair<int, pii >
#define REP(i,n) for (int (i)=0;(i)<(n);(i)++)
#define vi vector<int>
#define vpi vector< pii >
#define INF 2147483647
#define big 19260817
#define pb push_back
#define mp make_pair
using namespace std;
const int Maxk=1005;
string mul(string a,string b){
	int res[Maxk];
	memset(res,0,sizeof(res));
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	for (int i=0;i<a.length();i++){
		for (int j=0;j<b.length();j++){
			res[i+j]+=(a[i]-'0')*(b[j]-'0');
		}
	}
	for (int i=0;i<Maxk;i++){
		if (res[i]>=10) {
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	string ret;
	bool flag=false;
	for (int i=Maxk-1;i>=0;i--){
		if (flag || res[i]){
			flag=true;
			ret=ret+(char)(res[i]+'0');
		}
	}
	if (ret=="") ret="0";
	return ret;
}
string add(string a,string b){
	if (a.length()<b.length()) swap(a,b);
	while (a.length()!=b.length()){
		b='0'+b;
	}
	for (int i=a.length()-1;i>=0;i--){
		a[i]+=(b[i]-'0');
		if (a[i]>'9' && i){
			a[i]-=10;
			a[i-1]++;
		}
	}
	if (a[0]>'9'){
		a[0]-=10;
		a='1'+a;
	}
	return a;
}

// cf IO: I64d
// atcoder IO: ｌｌｄ
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
int cnt[27];
int main(){
	string s;
	cin>>s;
	for (int i=0;i<s.length();i++){
		cnt[s[i]-'a']++;
	}
	long long n=s.length();
	long long ans=n*(n-1)/2;
	ans++;
	for (int i=0;i<26;i++){
		ans-=1ll*cnt[i]*(cnt[i]-1)/2;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
// #define int long long
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
using namespace std;

vector<int> sieve(1e6 + 1);
vector<int> pd;
vector<int> tot;

void go(int x, int i) {
    if (i == pd.size()) {
        tot.push_back(x);
    } else {
        go(x, i + 1);
        go(x * pd[i], i + 1);
    }
}

void calc(int x) {
    pd.clear();
    tot.clear();
    while (x > 1) {
        pd.push_back(sieve[x]);
        x /= sieve[x];
    }
    go(1, 0);
}

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

    for (int i = 2; i <= 1e6; i++) {
        if (sieve[i] == 0) {
            for (int j = i; j <= 1e6; j += i) {
                sieve[j] = i;
            }
        }
    }

    int n;
    cin >> n;
    set<int> st;
    set<int> dup;
    vector<int> kek(n);
    for (int i = 0; i < n; i++) {
        cin >> kek[i];
        if (st.find(kek[i]) != st.end()) {
            dup.insert(kek[i]);
        }
        st.insert(kek[i]);
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (dup.find(kek[i]) != dup.end()) {
            continue;
        }
        st.erase(kek[i]);
        calc(kek[i]);
        bool flag = false;
        for (int x : tot) {
            if (st.find(x) != st.end()) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            cnt++;
        }
        st.insert(kek[i]);
    }
    cout << cnt << '\n';

    fflush(stdout);
    return 0;
}


Measured memory_bytes: 18292
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
  void Solve()
  {
    var N = Console.ReadLine().Split();
    var A = int.Parse(N[0]);
    var B = int.Parse(N[1]);
    if ((Math.Abs(A - B) % 2) == 1)
      Console.WriteLine("IMPOSSIBLE");
    else
    {
      Console.WriteLine( (A + B) / 2);
    }
  }

  static void Main(string[] args)
  {
    new Program().Solve();
  }
}



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

int n;
vector<vector<int> > v(101010);
vector<int> stage(101010,-1);

int solve(int i){
    if(stage[i]>=0) {
        //cout<<i<<stage[i]<<endl;
        return stage[i];
    }
    if(v[i].size()==0) return stage[i]=0;
    else {
        vector<int> s;
        for(int j=0;j<v[i].size();j++){
            s.pb(solve(v[i][j]));
        }
        sort(s.begin(),s.end());
        int ans=0;
        for(int j=0;j<s.size();j++){
            ans=max(ans,s[j]+(int)s.size()-j);
        }
        //cout<<i<<" "<<ans<<endl;
        return stage[i]=ans;
    }
}

int main(){
    int i,j;
    
    cin>>n;
    
    for(i=1;i<n;i++){
        int x;
        cin>>x;
        x--;
        v[x].pb(i);
    }
    cout<<solve(0)<<endl;
    

    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

vector<ll> v;

ll dp[500][500];

ll solve(int l, int r) {
    if (l == r) {
        return 0;
    }
    if (l + 1 == r) {
        return dp[l][r] = v[r] - (l ? v[l - 1] : 0);
    }
    if (dp[l][r]) return dp[l][r];
    dp[l][r] = 1e18;
    for (int k = l + 1; k <= r; k++) {
        dp[l][r] = min(dp[l][r], solve(l, k - 1) + solve(k, r) + v[r] - (l ? v[l - 1] : 0));
    }
    return dp[l][r];
}

int main() {
    ios_base::sync_with_stdio(0);
    cout.tie(0); cin.tie(0);
    cout.precision(20); cout << fixed;
    int n;
    cin >> n;
    v.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        if (i) v[i] += v[i - 1];
    }
    cout << solve(0, n - 1) << endl;
}


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

int digit(int a){
  int sum = 0;
  while(a){
    sum += a % 10;
    a /= 10;
  }
  return sum;
}

int main(){
  int n, a, b, ans = 1e9;
  cin >> n;
  for(int i = 1; i < n; i++){
    a = i, b = n - i;
    ans = min(ans, digit(a) + digit(b));
  }
  cout << ans << endl;
  return 0;
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
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; }
//template end

struct BIT{
   int n; vector<int> bit;
   BIT(){}
   BIT(int n):n(n){
      bit.resize(n,0);
   }
   void init(int _n){
      n=_n; bit.resize(_n+1);
   }
   void add(int i,int x){
      for(i++;i<=n;i+=i&-i)bit[i]+=x;
   }
   ll sum(int i){
      ll res=0; for(i++;i;i-=i&-i)res+=bit[i]; return res;
   }
};

int main(){
   int n; scanf("%d",&n);
   BIT bit[26];
   rep(i,0,26)bit[i].init(n);
   string s; cin>>s;
   rep(i,0,n){
      bit[s[i]-'a'].add(i,1);
   }
   int q; scanf("%d",&q);
   rep(rot,0,q){
      int t; scanf("%d",&t);
      if(t==1){
         int i; char c; cin>>i>>c; i--;
         bit[s[i]-'a'].add(i,-1);
         bit[c-'a'].add(i,1);
         s[i]=c;
      }
      else{
         int l,r,res=0; scanf("%d%d",&l,&r); l--; r--;
         rep(i,0,26){
            if(bit[i].sum(r)-bit[i].sum(l-1))res++;
         }
         printf("%d\n",res);
      }
   }
   return 0;
}


Measured memory_bytes: 52532
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
// now

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0) : d(n,-1){}
    int Find (int x){
        if(d[x] < 0) return x;
        return d[x] = Find(d[x]);
    }
    bool unite (int x, int y){
        x = Find(x); y = Find(y);
        if(x == y ) return false;
        if(d[x] < d[y]){
            swap(x,y);
        }
        d[x] += d[y];
        d[y] = x;
        return true;
    } 

    bool same(int x, int y){
        return Find(x) == Find(y);
    }
    int size(int x) {
        return (-d[Find(x)]);
    }
};


int deg[100005];
vector<int> to[100005];

int main(){
    int n,m ,k;
    cin >> n >> m >>k;
    UnionFind uf(n);

    REP(i,m){
        int a,b;
        cin  >> a >> b;

        a--;b--;
        deg[a] ++;
        deg[b] ++;
        uf.unite(a,b);
    }

    REP(i,k){
        int a,b;
        cin >> a >> b;
        a--;b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    REP(i,n){
        int ans = uf.size(i) - 1 -deg[i];

        for(int x :to[i]){
            if(uf.same(i,x)) ans --;
        }
        cout << ans << " " ;
    }
    cout << endl;
}



Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep_start(a,i,n) for(ll i=a;i<=n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define rev1(i,n) for(ll i=n;i>0;i--)
#define sz(a) int((a).size())
#define all(c) c.begin,c.end()
#define tr(c,i) for(typeof(c).begin() i=c.begin; i!=c.end(); i++)
#define present(c,x) (c.find(x)!=c.end())
#define cpresent(c,x) (find(all(c),x)!=c.end())
#define pb push_back
#define F first
#define S second
#define INF 1e9+7
typedef long long int ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

ll gcd(ll a,ll b){
    return a%b==0?b:gcd(b,a%b);
}

ll gcd(ll a,ll b,ll c){
    return gcd(a, gcd(b,c));
}

void solve(){
    ll n;
    cin>>n;
    ll ans=0;
    rep1(i,n) rep1(j,n) rep1(k,n) ans+=gcd(i,j,k);
    cout<<ans;
}

signed main() {
    // your code goes here
    IOS
    ll t=1;
    //cin>>t;
    rep1(i,t){
        solve(); 
    }
}

Measured memory_bytes: 3644
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int H, W;
  cin >> H >> W;
  char S[H][W];
  REP(i, H) REP(j, W) cin >> S[i][j];
  int L[H][W], R[H][W], U[H][W], D[H][W];
  REP(i, H) REP(j, W) L[i][j] = R[i][j] = U[i][j] = D[i][j] = 0;
  REP(i, H) REP(j, W) {
    if (S[i][j] == '#')
      L[i][j] = 0;
    else if (j == 0)
      L[i][j] = 1;
    else
      L[i][j] = L[i][j - 1] + 1;
  }
  REP(i, H) RREP(j, W) {
    if (S[i][j] == '#')
      R[i][j] = 0;
    else if (j == W - 1)
      R[i][j] = 1;
    else
      R[i][j] = R[i][j + 1] + 1;
  }
  REP(i, H) REP(j, W) {
    if (S[i][j] == '#')
      U[i][j] = 0;
    else if (i == 0)
      U[i][j] = 1;
    else
      U[i][j] = U[i - 1][j] + 1;
  }
  RREP(i, H) REP(j, W) {
    if (S[i][j] == '#')
      D[i][j] = 0;
    else if (i == H - 1)
      D[i][j] = 1;
    else
      D[i][j] = D[i + 1][j] + 1;
  }
  int ans = 0;
  REP(i, H) REP(j, W) {
    ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 66688
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
#include<iomanip>
#define mod 1000000007
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mad(a,b) a=(a+b)%mod
#define mul(a,b) a=a*b%mod

#define N 100010
ll fac[N],inv[N],ivf[N];
ll C(ll n,ll k){
    return fac[n]*ivf[k]%mod*ivf[n-k]%mod;
}
ll H(ll n,ll k){
    return C(n+k-1,k);
}
ll beta(ll x,ll y,ll z,ll w){
    ll res=fac[x+y+z+w];
    mul(res,ivf[x]);
    mul(res,ivf[y]);
    mul(res,ivf[z]);
    mul(res,ivf[w]);
    return res;
}
ll n,a,b,c;
ll alpha(ll d){
    ll ans=0;
    for(ll x=0;x<=a;x++){
	ll y=b/2;
	ll z=a-x;
	if((d-z)%3>0||d<z)continue;
	ll w=(d-z)/3;
	mad(ans,beta(x,y,z,w));
    }
    return ans;
}
int main(){
    fac[0]=ivf[0]=inv[1]=1;
    for(ll i=1;i<N;i++){
	if(i>1)inv[i]=(mod-(mod/i*inv[mod%i]%mod))%mod;
	fac[i]=fac[i-1]*i%mod;
	ivf[i]=ivf[i-1]*inv[i]%mod;
    }
    cin>>n>>a>>b>>c;
    if(b%2==1)cout<<0<<endl;
    else if(b==0){
	cout<<alpha(c)<<endl;
    }
    else{
	ll ans=0;
	for(ll i=0;i<=c;i++){
	    ll cur=alpha(c-i);
	    mul(cur,H(b/2,i));
	    mad(ans,cur);
	}
	cout<<ans<<endl;
    }
}



Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n;
bool a[200010],b[200010];
vector<int> v;
int main()
{
	cin >>n;
	for (int i=1;i<=n;i++)
	{
		cin >>a[i];
		//a[i]=i%2;
	}
	for (int i=n;i>0;i--)
	{
		bool fl=0;
		for (int j=i+i;j<=n;j+=i) fl^=b[j];
		if (fl^a[i])
		{
			v.push_back(i); 
			b[i]=1;
		}
	}
	cout <<v.size()<<"\n";
	for (int i=0;i<v.size();i++) cout <<v[i]<<" ";
	return 0;
}

Measured memory_bytes: 2040
x = int(input())
a = (x+10) // 11
if 11*(a-1) < x <= 11*a-5:
    print(a*2-1)
else:
    print(a*2)

# 1,2,3,4,5,6       (1) 6
# 7,8,9,10,11       (2) 6 5 
# 12,13,14,15,16,17 (3) 6 5 6
# 18,19,20,21,22,   (4)  6 5 6 5



Measured memory_bytes: 38384
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n, m;
    cin >> n >> m;
    if (n == m)
        cout << "Yes"
             << "\n";
    else
        cout << "No"
             << "\n";
    return 0;
}

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

const ll mod = (long long) 1e9+7;
ll x,y,n;
vector <ll> adj[100005];
vector < vector <ll>> dp;
void dfs(ll u,ll e){
	dp[u][0]=1;
	dp[u][1]=1;
	bool check=true;
	for(ll i=0;i<adj[u].size();i++)
	{
		ll v= adj[u][i];
		if(v!=e){
		dfs(v,u);
		if(!check)
		{
			dp[u][0]*=dp[v][1]+dp[v][0];
			dp[u][0]%=mod;
		}
		else 
		{
			dp[u][0] = dp[v][1]+dp[v][0];
			dp[u][0]%=mod;
		}
		if(!check)
		{
			dp[u][1]*=dp[v][0];
			dp[u][1]%=mod;
		}
		else dp[u][1] = dp[v][0];
		check = false;
		}
	}
}
int main()
{
	scanf("%d",&n);
	for (ll i=1;i<n;i++) {
		cin >> x >> y;
		adj[x-1].push_back(y-1);
		adj[y-1].push_back(x-1);
	}
	dp.resize(n,vector<ll>(2));
	dfs(0,-1);
	cout << (dp[0][0]+dp[0][1])%mod;
	
}

Measured memory_bytes: 18176