akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int N;
const int M=1000001;
vector<int>a[M];
bool vis[M];
int gcd(int a,int b){
    return a?gcd(b%a,a):b;
}

main()
{
    cin>>N;
    for(int i=2;i<M;++i)for(int j=i;j<M;j+=i)a[j].push_back(i);
    int g=0;
    bool ok=true;
    for(int i=0;i<N;++i){
        int A;cin>>A;
        g=gcd(g,A);
        for(int j:a[A]){
            ok&=!vis[j];
            vis[j]=true;
        }
    }
    cout<<(ok?"pairwise coprime":g==1?"setwise coprime":"not coprime")<<endl;
}

Measured memory_bytes: 114984
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

const int K = 5000000;
P hoge[10][K+1];

// 1回の操作: digit_sumが-9 or 桁数が-1
// 終了条件: digit_sum <= 9 an 桁数が1
signed main() {
    int M;
    cin >> M;
    int digit_sum = 0;
    int digit_num = 0;
    for (int i = 0; i < M; i++) {
        int d, c;
        cin >> d >> c;
        digit_sum += c * d;
        digit_num += c;
    }

    int ret = (digit_sum - 1)/9 + (digit_num -1);
    cout << ret << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <queue>


void update(int node, std::vector<int>& weight, const std::vector<std::map<int, int>> link_list) {
    for (auto && l : link_list[node]) {
        if (weight[l.first] == -1 || weight[node] + l.second < weight[l.first]) {
            weight[l.first] = weight[node] + l.second;
            update(l.first, weight, link_list);
        }
    }
}


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

    std::vector<std::map<int, int>> link_list;
    for (int i = 0; i < n; i++) {
        int u, k;
        std::cin >> u >> k;
        std::map<int, int> map;
        for (int j = 0; j < k; j++) {
            int c, v;
            std::cin >> c >> v;
            map[c] = v;
        }
        link_list.emplace_back(map);
    }

    std::vector<int> weight(n, -1);
    weight[0] = 0;

    auto comp = [] (std::tuple<int, int, int> &lfs, std::tuple<int, int, int> &rhs) {
        return std::get<2>(lfs) > std::get<2>(rhs);
    };
    
    std::priority_queue<std::tuple<int, int, int>, std::vector<std::tuple<int, int, int>>, decltype(comp)> que(comp);
    for (auto && m : link_list[0]) {
        que.push(std::make_tuple(0, m.first, m.second));
    }

    while (!que.empty()) {
        auto val = que.top();
        que.pop();
        auto w = weight[std::get<0>(val)] + std::get<2>(val);
        if (weight[std::get<1>(val)] == -1 || w < weight[std::get<1>(val)]) {
            weight[std::get<1>(val)] = w;
            for (auto && m : link_list[std::get<1>(val)]) {
                que.push(std::make_tuple(std::get<1>(val), m.first, m.second));
            }
        }
    }

    for (int i = 0; i < n; i++) {
        std::cout << i << " " << weight[i] << std::endl;
    }
}




Measured memory_bytes: 50840
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
using namespace std;
#define INF 1000000007
#define LINF 8000000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
    {          \
    }
#define ARDEB(i, X) \
    {               \
    }
#define END \
    {       \
    }
#endif
typedef pair<int, int> P;
struct edge{int from,to,cost;};
int pow2(int n,int i){if(i==1)return n;return n*pow(n,i-1);};

typedef long long ll;

using namespace std;


int ans,ans2;
int n,m;

signed main(){  
    
    P p[111111];
    cin>>n;
    rep(i,n){
        int a;
        cin>>a;
        p[i].first=a;
        p[i].second=i+1;
    }
    sort(p,p+n);
    rep(i,n)cout<<p[i].second<<" ";
    cout<<endl;
}

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

int main()
{
    vector<vector<int>> a(3, vector<int>(3));
    rep(i, 3) rep(j, 3) cin >> a[i][j];
    int n;
    cin >> n;
    vector<int> b(n);
    rep(i, n) cin >> b[i];
    rep(i, n) rep(j, 3) rep(k, 3)
    {
        if (b[i] == a[j][k])
            a[j][k] = 0;
    }
    rep(i, 3)
    {
        bool bingo = true;
        rep(j, 3)
        {
            if (a[i][j] != 0)
                bingo = false;
        }
        if (bingo)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    rep(i, 3)
    {
        bool bingo = true;
        rep(j, 3)
        {
            if (a[j][i] != 0)
                bingo = false;
        }
        if (bingo)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    if (a[0][0] == 0 && a[1][1] == 0 && a[2][2] == 0)
    {
        cout << "Yes" << endl;
        return 0;
    }
    if (a[2][0] == 0 && a[1][1] == 0 && a[0][2] == 0)
    {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3616
n = int(input())
A = [int(x) for x in input().split()]
dict = {}
res = 0
for i, a in enumerate(A, 1):
  dict[i] = a
for i in range(1, n+1):
  if dict[i] in dict.keys() and dict[dict[i]] == i:
    res += 1
print(res // 2)

Measured memory_bytes: 20704
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int[] a  = new int[3];
		int[] b = new int[2];
		for(int i = 0; i < 3;i++){
			a[i]=cin.nextInt();
		}
		b[0]=cin.nextInt();
		b[1]=cin.nextInt();
		int min = 99999999;
		for(int i = 0; i < 3;i++){
			for(int j = 0; j < 2;j++){
				if(min > a[i]+b[j]){
					min = a[i]+b[j];
				}
			}
		}
		System.out.println(min-50);
	}

}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MAX=109999;
const ll INF=0x3f3f3f3f3f3f3f;
vector<int> conn[MAX];
queue<pii> bfs;
int ans[20],len,q;
int find_len(){
    int t=10,i;
    char tmp[10];
    for(i=1;i<=9;i++,t*=10){
        printf("? %d\n",t);
        fflush(stdout);
        scanf(" %s",tmp);
        if(tmp[0]=='N'){
            return i;
        }
    }
    t=2; q=1;
    for(i=0;i<=9;i++,t*=10){
        printf("? %d\n",t);
        fflush(stdout);
        scanf(" %s",tmp);
        if(tmp[0]=='Y'){
            return i;
        }
    }
    return -1;
}
int range(int x,int y,int r){
    int p=(x+y)/2;
    char tmp[10];
    if(y-x==1) return x;
    ans[r]=p;
    printf("? ");
    for(int i=0;i<len+1;i++) printf("%d",ans[i]);
    printf("\n");
    fflush(stdout);
    scanf(" %s",tmp);
    if(tmp[0]=='N') return range(p,y,r);
    return range(x,p,r);
}
int build(){
    int t=0;
    for(int i=0;i<len;i++) t*=10,t+=ans[i];
    return t+1;
}
int main()
{
    len=find_len();
    if(q==1){
        int t=1;
        for(int i=0;i<len;i++) t*=10;
        printf("! %d\n",t);
        fflush(stdout);
        return 0;
    }
    ans[0]=range(1,10,0);
    for(int i=1;i<len;i++) ans[i]=range(0,10,i);
    printf("! %d",build());
    printf("\n");
    fflush(stdout);
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
const ll INF = ll(1e9);
const int N = 1e5 + 5;
const ll mod = 1000000007 ;
using namespace std;


ll dp[N];

ll binpow(ll x, ll y) {
	ll z = 1;
	while (y) {
		if (y % 2) z = (z * x) % mod;

		y = y / 2;
		x = (x * x) % mod;
	}
	return z % mod;
}




int main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);


	ll tc = 1;

//	cin >> tc;

	while (tc--) {

		ll n, k, i, j;
		cin >> n;

		std::vector<ll> a(n + 1);

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

		ll dp[n + 1] = {0};

		dp[0] = 0;
		dp[1] = 0;
		dp[2] = abs(a[2] - a[1]);
		for (i = 3; i <= n; i++) {
			dp[i] = min(abs(a[i] - a[i - 1]) + dp[i - 1], abs(a[i] - a[i - 2]) + dp[i - 2] );
		}

		cout << dp[n] << endl;



	}

}

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

int main(){
  int N;
  cin >> N;
  set<int> S;
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    if(S.count(a)){
      cout << "NO" << endl;
      return 0;
    }
    S.insert(a);
  }
  
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 9600
package main

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

// VMAX is the maximum value of element in progression.
const VMAX = 10000

func main() {
	fmt.Println(answer(os.Stdin))
}

func answer(r io.Reader) string {
	sc := bufio.NewScanner(r)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	// A[0], B[0] and C[0] won't be used due to handling the inconsistency
	// between the size of slice and its number of element.
	A, B := make([]int, n+1), make([]int, n+1)
	C := make([]int, VMAX+1)
	for i := 0; i < n; i++ {
		sc.Scan()
		A[i+1], _ = strconv.Atoi(sc.Text())
		C[A[i+1]]++
	}

	countingSort(A, B, C, n)
	return String(B)
}

func countingSort(A, B, C []int, n int) {
	for i := 1; i <= VMAX; i++ {
		C[i] += C[i-1]
	}

	for j := 1; j <= n; j++ {
		B[C[A[j]]] = A[j]
		C[A[j]]--
	}
}

func String(B []int) string {
	// trim junk element B[0] when stringifying the entire elements of progression.
	return strings.Trim(fmt.Sprint(B[1:])[1:], "[]")
}



Measured memory_bytes: 66816
#include<iostream>
using namespace std;
 
int main(){
    int a, b;
     
    cin>> a >> b;
     
    if ( a < b ) cout << "a < b" << endl;
    else if ( a > b ) cout << "a > b" << endl;
    else cout << "a == b" << endl;
 
    return 0;
}

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

using namespace std;

#define	MIN(X, Y)	X < Y ? X : Y
#define	INF	1000000001

int **PEOPLE;
int H, W;

// 総距離の計算
// 引数:幹線道路とする場所
int Total_Calc(int yoko_road, int tate_road)
{
	int total_distance = 0;

	for(int i = 0; i < H; i++){
		int tmp = 0;
		for(int j = 0; j < W; j++){
			int tmp2 = MIN(fabs(i - yoko_road), fabs(j - tate_road)); // 最寄の幹線道路までの距離
			tmp += PEOPLE[i][j] * tmp2;
		}
		total_distance += tmp;
	}

	return total_distance;
}

int main()
{
	int in_data;
	int tate_road, yoko_road, ans;

	// データ入力
	cin >> H >> W;

	PEOPLE = new int*[H];
	for(int i = 0; i < H; i++)
		PEOPLE[i] = new int[W];

	for(int i = 0; i < H; i++)
		for(int j = 0; j < W; j++)
			cin >> PEOPLE[i][j];
/*
	// 入力データ、チェック完了
	cout << "入力データ" << endl;
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++)
			cout << " " << PEOPLE[i][j];
		cout << endl;
	}
*/
	// 愚直に幹線道路を作成したと仮定して総距離を計算していく
	int min = INF;
	for(yoko_road = 0; yoko_road < H; yoko_road++){
		for(tate_road = 0; tate_road < W; tate_road++){
			int total_distance = Total_Calc(yoko_road, tate_road);
			min = MIN(total_distance, min);
		}
	}

	cout << min << endl;

	return 0;
}

// ごちゃごちゃしたことはせずに愚直に求めればいいらしい、O((H * W)^2) -> 最大 25~4


Measured memory_bytes: 3120
#include <stdio.h>
int main(){
  int n,b,f,r,v,i,j,p;
  int A[3][10],B[3][10],C[3][10],D[3][10];
  for (i=0;i<4;i++){
    for (j=0;j<10;j++){
      A[i][j]=0;
      B[i][j]=0;
      C[i][j]=0;
      D[i][j]=0;
    }
  }
  scanf("%d",&n);
  for (i=0;i<n;i++){
    scanf(" %d %d %d %d",&b,&f,&r,&v);
    if (b==1) {
      A[f-1][r-1]+=v;
    } else if (b==2) {
      B[f-1][r-1]+=v;
    } else if (b==3) {
      C[f-1][r-1]+=v;
    } else if (b==4) {
      D[f-1][r-1]+=v;
    }
  }
  for (p=0;p<3;p++){
    for (i=0;i<3;i++){
      for (j=0;j<10;j++){
        if (p==0){
          printf(" %d",A[i][j]);
        } else if (p==1){
          printf(" %d",B[i][j]);
        } else if (p==2){
          printf(" %d",C[i][j]);
        }
        }
        printf("\n");
      }
      printf("####################\n");
    }
  for (i=0;i<3;i++){
    for (j=0;j<10;j++){
      printf(" %d",D[i][j]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 2704
hash = {}
while (str = gets) != nil
  word, page = str.split
  if hash[word] == nil
    hash[word] = [page.to_i]
  else
    hash[word] << page.to_i
  end
end
hash.values.each {|item| item.sort!}
hash = Hash[hash.sort]
hash.each {|k, v| puts k, v.join(" ")}

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

using namespace std;



int main(){
    
    int a,b;
    cin>>a>>b;
    string x,y;
    int sum = 0;
    for(;a<=b;a++){
    	y = x = to_string(a);
    	reverse(y.begin(),y.end());
    	if(x==y) sum++;
    }

    cout<<sum;

    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

// i????????????????????????,j????§????????????£???
int dp[50][50]={};

int main()
{
    int n,m,l;
    cin >>n >>m >>l;

    vector<int> s(m),g(m),w(m);
    rep(i,m)
    {
        int d,a,k;
        cin >>d >>a >>k >>w[i];

        s[i] = d*n+a-1;
        g[i] = s[i]+k;
    }

    rep(i,5*n)rep(j,l)rep(k,m)
    {
        if(i<=s[k]) dp[g[k]][j+1] = max(dp[g[k]][j+1], dp[i][j]+w[k]);
    }

    int ans = 0;
    rep(i,50)rep(j,l+1) ans = max(ans,dp[i][j]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3100
using namespace std;

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <limits>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <numeric>
typedef long long ll;
typedef pair<int,int> p;

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


int main()
{
  string s;
  cin >> s;
  if (s.size() % 2 == 1) {
    for(int i = 0; i < int(s.size()); i += 2){
      std::cout << s[i];
    }
  }
  else
  {
    for(int i = 0; i < int(s.size())-1; i += 2){
      std::cout << s[i];
    }

  }
  std::cout << '\n';
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c){
    return b / c - (a - 1) / c;
}

int main(){
    int n, x;
    string s;
    cin >> n;
    cin >> s;
    for (int i = 0; i < s.size(); i++){
        x = n;
        if (int(s[i]) + n > int('Z')){
            x = x - (int('Z') - int(s[i])) - 1;
            s[i] = 'A';
        }
        s[i] += x;
    }
    cout << s << endl;
}

Measured memory_bytes: 256
def d_snuke_numbers(K):
    import math

    def ns(n):  # n/S(n)の計算
        return n / sum(map(int, list(str(n))))

    def f(n):  # n<=xの中で ns(x) を最小にするような最小の値xを求める
        digit = len(str(n))
        # n自身も候補の1つである
        min_ns = ns(n)
        ret = n
        for d in range(digit + 1):
            x = (10**(d+1)) * math.floor(n / (10**(d+1)) + 1) - 1
            s = ns(x)
            if min_ns > s:
                min_ns = s
                ret = x
        return ret

    n = 0
    candidate = []
    for _ in range(K):
        n = f(n + 1)
        candidate.append(n)
    ans = '\n'.join(map(str, candidate))
    return ans

K = int(input())
print(d_snuke_numbers(K))

Measured memory_bytes: 3064
N,M=map(int, input().split())
d=set()
a,b=1,N
for _ in range(M):
    print(a,b)
    d.add(b-a)
    d.add(N-b+a)
    a+=1
    b-=1
    while b-a in d or N-b+a in d or b-a == N-b+a: b-=1


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

int main(){
	int k;
  	cin >> k;
	int x = 7 % k;
  	set<int> s;
  
  	int i = 1;
  	while(s.count(x) == 0){
      	if(x == 0){
        	cout << i << endl;
          	return 0;
        }
      
		s.insert(x);
      	x = (x * 10 + 7) % k;
      	i++;
    }
  
  	cout << -1 << endl;
}

Measured memory_bytes: 50476
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a, b, c, d, e, f = map(int, readline().split())
ans = [0, 0]
check = 0
S = set()
W = set()
for i in range(31):
    for j in range(31):
        if 100 * a * i + 100 * b * j <= f:
            W.add(100 * a * i + 100 * b * j)
for i in range(1501):
    for j in range(1501):
        if c * i + d * j <= f:
            S.add(c * i + d * j)
W = sorted(list(W))
S = sorted(list(S))
for w in W:
    for s in S:
        if w == 0:
            continue
        n = 100 * s / (w + s)
        if w + s > f or s > e * (w / 100):
            break
        if n > check:
            ans = w + s, s
            check = n
if ans[0] == 0:
    print(100 * a, ans[1])
else:
    print(*ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
 using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 int main(){
   int n,X=0,Y=0;
   cin>>n;
   vector<int> x(n);
   vector<int> y(n);
   rep(i,n)cin>>x.at(i);
   rep(i,n)cin>>y.at(i);
   rep(i,n){
   if(x.at(i)>y.at(i)){
      X+=x.at(i);
      Y+=y.at(i);
    }
   }
   cout<<X-Y<<endl;
}


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

using namespace std;

long long x[4];

int main() {
	for (int i = 0; i < 4; i++)
		scanf("%lld", x + i);
	if (x[3] % 2 == 0)
		printf("%lld\n", x[0] - x[1]);
	else
		printf("%lld\n", x[1] - x[0]);
	return 0;
}

Measured memory_bytes: 256
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans






N,M = m()

a = l()

a.sort()

aaa = s(a)



po = [0 for i in range(10**5+1)]
ans = 0
for i in range(N):
    po[a[i]] += 1
for i in range(10**5-1,-1,-1):
    po[i] += po[i+1]
ll = 0
rr = 10**5 * 2

while True:
    mid = (ll+rr)//2
    if mid == ll:
        co = 0
        for i in range(N):
            ui = a[i]
            if mid > ui + 10**5:
                continue
            elif ui >= mid:
                co += N
            else:
                co += po[mid-ui]
        cco = 0
        mid = rr

        for i in range(N):
            ui = a[i]
            if mid > ui + 10**5:
                continue
            elif ui >= mid:
                cco += N
            else:
                cco += po[mid-ui]
        
        

        if co == cco:
            mid = rr

        elif cco == M:
            mid = rr
            co=cco

        else:
            mid = ll

        break

    co = 0
    for i in range(N):
        ui = a[i]
        if mid > ui + 10**5:
            continue
        elif ui >= mid:
            co += N
        else:
            co += po[mid-ui]
    
    if co < M:
        rr = mid                 
    else:
        ll = mid


a.sort(reverse = True)
dp = [0]

ans -= mid * (co - M)



for i in range(N):
    dp.append(dp[-1]+a[i])

for i in range(N):
    pl = a[i]
    if pl >= mid:
        ans += pl*N + dp[-1]
        
    elif pl + 10**5 < mid:
        continue
    else:
        ans += pl*po[mid-pl] + dp[po[mid-pl]]
print(ans)





Measured memory_bytes: 26276
#include<stdio.h>
#include<string.h>

int main()
{
	char S[3];
	scanf("%s", S);
	
	if(S[0] == 'S' && S[1] == 'U') printf("7");
	if(S[0] == 'M') printf("6");
	if(S[2] == 'E') printf("5");
	if(S[2] == 'D') printf("4");	
	if(S[2] == 'U') printf("3");
	if(S[2] == 'I') printf("2");
	if(S[2] == 'T') printf("1");
	
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(void){
    map<string,int> memo;
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        memo[s]++;
    }
    int maxv=0;
    for(const auto& x : memo){
        int v=x.second;
        maxv=max(v,maxv);
    }
    for(auto it=memo.begin();it!=memo.end();it++){
        if(it->second==maxv) cout << it->first << endl;
    }
}

Measured memory_bytes: 19212
a = []
ans = 0
for i in range(5):
  po = int(input())
  a.append(po)

mindiv = 15
for i in range(5):
  div = a[i] % 10
  if div == 0:
    div = 10
  if div < mindiv:
    mindiv = div
    index = i
           
for i in range(5):
  if i != index:
    if a[i]%10 !=0:
      ans = ans + (int(a[i]/10)+1)*10
    else:
      ans = ans + a[i]
  else:
    ans = ans + a[index]
    
print(int(ans))


Measured memory_bytes: 3064
#include<stdio.h>

int main(){
	
	char buf[256];
	int A, B, C, D;
	int S1, S2;
		
	fgets(buf,256,stdin);
	sscanf(buf,"%d %d %d %d",&A, &B, &C, &D);
	
	S1 = A*B;
	S2 = C*D;
	
	printf("%d\n", ((S1 >= S2) ? S1 : S2));
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 2e5 + 5;
const ll MOD = 1e9 + 7;
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pis pair<ll,string>
#define F first
#define S second
#define LCM(a,b) ((a*b)/__gcd(a,b))
#define inf 1e15
#define test ll cse;cin>>cse;for(ll _i=1;_i<=cse;_i++)
#define PI 3.14159265
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const double EPS = 1E-9;
typedef vector< vector<double> > matrix;
typedef vector<int> vi;


int ar[N];
int main() {
    fast;


    ll n; cin >> n;
    cout << (n + n*n + n*n*n) << "\n";
    return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

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

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

vector<pii> g[MAXN];

int is_in[MAXN], is_out[MAXN];

int used[MAXN][3];

ll cc[3];

vi comp;

set<pii> ee;

void dfs(int s, int r){
	//printf("%d %d\n", s, r);
	if (used[s][0] + used[s][1] + used[s][2] == 0){
		comp.pb(s);
	}
	used[s][r] = 1;
	REP(i, 0, SZ(g[s])){
		int to = g[s][i]._1;
		int r_to = (r + 3 + g[s][i]._2) % 3;
		if (!used[to][r_to]){
			dfs(to, r_to);
		}
	}
}

void solve(){
	int n, m;
	scanf("%d%d", &n, &m);
	REP(i, 0, m){
		int a, b;
		scanf("%d%d", &a, &b);
		is_in[b] = 1;
		is_out[a] = 1;
		g[a].pb(mp(b, 1));
		g[b].pb(mp(a, -1));
	}
	ll ans = 0ll;
	REPN(i, 1, n){
		if (!is_in[i] || !is_out[i]){
			continue;
		}
		if (used[i][0] || used[i][1] || used[i][2]){
			continue;
		}
		comp.clear();
		dfs(i, 0);
		int fl = 0;
		REP(j, 0, 3){
			cc[j] = 0;
		}
		REP(j, 0, SZ(comp)){
			int a = comp[j];
			if (used[a][0] + used[a][1] + used[a][2] > 1){
				fl = 1;
			} else {
				REP(k, 0, 3){
					cc[k] += used[a][k];
				}
			}
		}
		ll tmp = SZ(comp);
		if (fl){
			ans += tmp * tmp;
		} else {
			ans += cc[0] * cc[1] + cc[1] * cc[2] + cc[2] * cc[0];
		}
	}
	ll add = 0;
	REPN(i, 1, n){
		if (used[i][0] || used[i][1] || used[i][2]){
			continue;
		}
		add += SZ(g[i]);
	}
	add /= 2;
	ans += add;
	printf("%lld\n", ans);
}   

int main(){
    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 26872
import numpy as np
 
 
def solve(string):
    n, *a = map(int, string.split())
    # a = ["{:060b}".format(_a) for _a in a]
    a = np.asarray(a, dtype=np.int64)
    m = 10**9 + 7
    ans = 0
    for i in range(60):
        s = int((a & 1).sum())
        a >>= 1
        # ans += s * (n - s) * pow(2, 59 - i, m)
        ans += s * (n - s) * pow(2, i, m) % m
        ans %= m
    return str(ans)
 
 
if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

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

int main(){
    int n;cin >> n;
    map<string,int> mp;
    rep(i,n){
        string s; cin >> s;
        mp[s]++;
    }
    int m; cin >> m;
    rep(i,m){
        string s; cin >> s;
        mp[s]--;
    }
    int ans = 0;
    for(auto itr=mp.begin();itr!=mp.end();++itr){
        ans = max(ans,itr->second);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = gets.to_i
h = gets.split.map(&:to_i)

ans = 0
loop do
    c = 0
    pre = -1
    n.times do |i|
        if h[i] == 0
            pre = i
        elsif pre == i - 1
            h[i] -= 1
            c += 1
        else
            h[i] -= 1
        end
    end

    c == 0 ? break : ans += c
end

puts ans

Measured memory_bytes: 1788
/*
[abc136] F - Enclosed Points
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 2e5;
const int MOD = 998244353;
const int MAX_BIT_IDX = MAX_N;

class gf {
public:
    int n;
    gf() : n(0) {}
    gf(int n) : n(n % MOD) {}
    gf operator+(const gf x) const { return gf((n + x.n) % MOD); }
    gf operator-(const gf x) const { return gf((n - x.n + MOD) % MOD); }
    gf operator*(const gf x) const { return gf((1LL * n * x.n) % MOD); }
    gf& operator+=(const gf x) { return *this = (*this + x); }
    gf& operator-=(const gf x) { return *this = (*this - x); }
    gf& operator*=(const gf x) { return *this = (*this * x); }
};

template <typename T>
class BIT {
public:
    T b[MAX_BIT_IDX + 1];
    int n;
    void init(int num) {
        n = num;
        for (int i = 0; i <= n; i++) {
            b[i] = 0;
        }
        return;
    }
    T sum(int i) {  // i : [0, n], returns sum of [0, i)
        T s = 0;
        for (; i > 0; i -= i & -i) {
            s += b[i];
        }
        return s;
    }
    void add(int i, T x) {  // i : [0, n)
        for (i += 1; i <= n; i += i & -i) {
            b[i] += x;
        }
        return;
    }
};

int N;
pii XY[MAX_N];
vector<int> xs, ys;
BIT<int> bit;
int cnt[4][MAX_N];
gf pow2[MAX_N + 1];

ll solve() {
    for (int i = 0; i < N; i++) {
        xs.push_back(XY[i].first);
        ys.push_back(XY[i].second);
    }
    sort(xs.begin(), xs.end());
    sort(ys.begin(), ys.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
    ys.erase(unique(ys.begin(), ys.end()), ys.end());
    for (int i = 0; i < N; i++) {
        XY[i].first =
            lower_bound(xs.begin(), xs.end(), XY[i].first) - xs.begin();
        XY[i].second =
            lower_bound(ys.begin(), ys.end(), XY[i].second) - ys.begin();
    }

    sort(XY, XY + N);

    pow2[0] = 1;
    for (int i = 1; i <= N; i++) {
        pow2[i] = pow2[i - 1] * 2;
    }

    for (int c = 0; c < 2; c++) {
        bit.init(N);
        for (int i = (c == 0 ? 0 : N - 1); 0 <= i && i < N;
             i += (c == 0 ? 1 : -1)) {
            cnt[c * 2 + 0][i] = bit.sum(XY[i].second);
            cnt[c * 2 + 1][i] = bit.sum(N) - bit.sum(XY[i].second + 1);
            bit.add(XY[i].second, 1);
        }
    }

    gf ans;
    for (int i = 0; i < N; i++) {
        ans += pow2[N - 1];
        ans += (pow2[cnt[0][i]] - 1) * (pow2[cnt[1][i]]) * (pow2[cnt[2][i]]) *
               (pow2[cnt[3][i]] - 1);
        ans += (pow2[cnt[0][i]]) * (pow2[cnt[1][i]] - 1) *
               (pow2[cnt[2][i]] - 1) * (pow2[cnt[3][i]]);
        ans -= (pow2[cnt[0][i]] - 1) * (pow2[cnt[1][i]] - 1) *
               (pow2[cnt[2][i]] - 1) * (pow2[cnt[3][i]] - 1);
    }

    return ans.n;
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> XY[i].first >> XY[i].second;
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 8300
#include<iostream>
#include<bits/stdc++.h>
#define db(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define fr(i,a,n) for(int i=a;i<=(n);++i)
#define rf(i,a,n) for(int i=a;i>=(n);--i)
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll,ll>
#define _ <<" "<<
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<int,pair<int,int>> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

vector<bool> vis;
vvi dp;

ll stones(vi a, int i, int j){
	if(i>=j)
		return 0;
	if(i+1==j)
		return a[i]+a[j];
	ll minval=LLONG_MAX;
	db2(i,j);
	for(int k=i;k<j;k++){
		minval=min(minval,stones(a,i,k)+a[k]+a[k+1]+stones(a,k+1,j));
	}
	db(minval);
	return minval;
}
 
int main(){
  	int n;
  	cin>>n;
  	vi a(n),sum(n,0);
  	for(int i=0;i<n;i++){
  		cin>>a[i];
  		if(i>0)
  			sum[i]=a[i]+sum[i-1];
  		else
  			sum[i]=a[i];
  	}
  	// cout<<stones(a,0,n-1);
  	dp.resize(n,vi(n,1e18));
  	for(int gap=0;gap<n;gap++){
  		for(int i=0,j=i+gap;j<n;j++,i++){
  			if(i==j){
  				dp[i][j]=0;
  				// cout<<dp[i][j]<<endl;
  				continue;
  			}
  			for(int k=i;k<j;k++){
  				// db3(i,k,j);
  				// db2(dp[i][k],dp[k+1][i]);
  				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]);
  			}
  			// db(sum[j]);
  			dp[i][j]+=sum[j];
  			if(i>0)
  				dp[i][j]-=sum[i-1];
  			// cout<<dp[i][j]<<endl;
  		}
  		// cout<<endl;B
  	}
  	cout<<dp[0][n-1]<<endl;
  	return 0;
}



Measured memory_bytes: 1536
N, Y = list(map(int, input().split()))
for i in range(N+1):
  for j in range(N+1-i):
    k = N-(i+j)
    if 10000*i + 5000*j + 1000*k == Y:
      print('{} {} {}'.format(i, j, k))
      exit()

print('-1 -1 -1')

Measured memory_bytes: 2940
#include <stdio.h>

int main(){
    int Hills[10];
    int i,j,temp;

    for(i=0;i<10;i++)scanf("%d",&Hills[i]);
    for(i=0;i<3;i++){
        for(j=i;j<10;j++){
            if(Hills[i]<Hills[j]){
                temp = Hills[i];
                Hills[i] = Hills[j];
                Hills[j] = temp;
            }
        }
    }
    printf("%d\n",Hills[0]);
    printf("%d\n",Hills[1]);
    printf("%d\n",Hills[2]);
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int n,m;
	cin >> m;
	if(m == 0) break;
	vector< pair<int,int> > cons(m);
	set< pair<int,int> > s;
	REP(i,m){
	    int x,y;
	    cin >> x >> y;
	    cons[i] = pair<int,int>(x,y);
	}
	cin >> n;
	vector< pair<int,int> > star(n);
	REP(i,n){
	    int x,y;
	    cin >> x >> y;
	    star[i] = pair<int,int>(x,y);
	    s.insert(star[i]);
	}
	sort(ALL(star));
	sort(ALL(cons));
	REP(i,star.size()){
	    int dx = star[i].first - cons[0].first;
	    int dy = star[i].second - cons[0].second;
	    bool flg = true;
	    REP(j,cons.size()){
		pair<int,int> temp;
		temp.first = dx + cons[j].first;
		temp.second = dy + cons[j].second;
		if(s.find(temp) == s.end()){
		    flg = false;
		    break;
		}
	    }
	    if(flg){
		printf("%d %d\n",dx,dy);
		break;
	    }
	}
    }
    return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#include <stdint.h>
#include <algorithm>
#include <vector>


using namespace std;

int main() {
	int n;
	string s;
	cin >> n >> s;
	int ans = 1;
	char pre = s.at(0);
	for(int i = 1; i < n; i++) {
		if (pre == s.at(i)) {
			//何もしない
		} else {
			pre = s.at(i);
			ans++;
		}
	}
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int k = in.nextInt(), s = in.nextInt();
        int res = 0;
        for (int i = 0; i <= k; ++i) {
            for (int j = 0; j <= k; ++j) {
                int dif = s - i - j;
                if (dif >= 0 && dif <= k) {
                    ++res;
                }
            }
        }
        System.out.println(res);
    }
}



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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
typedef vector<pi> vp;

#define pb push_back
#define mp make_pair
#define fora(i, a, n) for(int i = a; i < n; i++)
#define forb(i, a, n) for (int i = a; i >= (n); --i)
#define PI 3.1415926535897932384626433832795
#define INF 1e9

int main(){ 
ios::sync_with_stdio(false);
cin.tie(NULL);
//freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

ll n, k;
cin >> n >> k;
ll ans = n%k;
ll temp1 = abs(ans-k);
ll temp2 = abs(temp1-k);
cout << min(temp1, temp2) << endl;

}

Measured memory_bytes: 384
/*
 * sto Qingyu orz
 * 感谢真神sqy无私的教诲。膜时队者处处阿克，只因大师sqy在他背后。不膜大师者违背了真神的旨意，真神必将降下天谴,
 * 使其天天爆零
 * 我不由自主地膜拜真神sqy。
 * Author: RainAir
 * Time: 2019-10-16 10:11:35
 */
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define fi first
#define se second
#define U unsigned
#define P std::pair
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

const int MAXN = 5000+5;
const int ha = 998244353;
int cnt[MAXN];
int n,k,fac[MAXN],inv[MAXN];

inline int qpow(int a,int n=ha-2){
    int res = 1;
    while(n){
        if(n & 1) res = 1ll*res*a%ha;
        a = 1ll*a*a%ha;
        n >>= 1;
    }
    return res;
}

inline void prework(){
    fac[0] = 1;
    FOR(i,1,MAXN-1) fac[i] = 1ll*fac[i-1]*i%ha;
    inv[MAXN-1] = qpow(fac[MAXN-1]);
    ROF(i,MAXN-2,0) inv[i] = 1ll*inv[i+1]*(i+1)%ha;
}

inline int C(int n,int m){
    if(n < m) return 0;
    return 1ll*fac[n]*inv[m]%ha*inv[n-m]%ha;
}

int main(){
    scanf("%d%d",&k,&n);
    prework();
    FOR(i,1,k) cnt[i+1]++,cnt[i+k+1]--;
    FOR(i,1,2*k) cnt[i] += cnt[i-1],cnt[i-1] = (cnt[i-1]+1)/2;
//    FOR(i,1,2*k) DEBUG(cnt[i]);
    FOR(i,2,k*2){
        int ans = 0;
        FOR(j,0,std::min(cnt[i],n/2)){
            (ans += 1ll*((j&1)?ha-1:1)*C(cnt[i],j)%ha*C(n-2*j+k-1,k-1)%ha)%=ha;
        }
        printf("%d\n",ans);
    }
    return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





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

    int R,G,B,N;

    cin>>R>>G>>B>>N;

    int res = 0;

    for (int r=0; r*R<=N; r++) {
	for (int g=0; r*R+g*G<=N; g++) {
	    int b = N-r*R-g*G;
	    if (b%B==0) {
		//cout<<r<<" "<<g<<" "<<b<<endl;
		res++;
	    }
	}
    }

    cout<<res<<endl;
    
    
    return 0;
}


Measured memory_bytes: 3620
import sys
readline = sys.stdin.readline

def popcount(i):
    assert 0 <= i < 0x100000000
    i = i - ((i >> 1) & 0x55555555)
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
    return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24

N = int(readline())

G = [0]*N
H = [0]*N
for i in range (N):
    A = int(readline())
    for _ in range(A):
        x, y = map(int, readline().split())
        if y == 1:
            G[i] |= 1<<(x-1)
        else:
            H[i] |= 1<<(x-1)

ans = 0

for s in range(1<<N):
    for i in range(N):
        if (1<<i) & s:
            g, h = G[i], H[i]
            if g != (g&s):
                break
            if h != (h&(~s)):
                break
            
    else:
        ans = max(ans, popcount(s))
print(ans)

Measured memory_bytes: 40816
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n; cin >> n;
	//n = 200000;
	vector<int> a(n);
	int x = 0;
	rep(i, n)
	{
		cin >> a[i];
		//a[i] = 1e9;
		x ^= a[i];
	}
	rep(i, n)cout << (x ^ a[i]) << endl;
}

Measured memory_bytes: 4048
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
#include<set>
#include <cstdint>
#include<tuple>
using namespace std;
using ll = __int64_t;
using lll = __int128_t;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;
const ll mod=1e9+7;

int main(void){
  int n;
  cin>>n;
  int a[n];
  rep0(i,n) cin>>a[i],--a[i];
  int index[n];
  rep0(i,n){
    index[a[i]]=i;
  }
  rep0(i,n){
    cout<<index[i]+1<<" ";
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 1536
import subprocess
import os
import time


import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

input = sys.stdin.readline


mod = 10**9+7
N = 10**6
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]


# def find_n(x, y):
#     moves = int((x+y)/3)
#     for n in range(moves+1):
#         if n + (moves-n)*2 == x and n*2 + (moves-n) == y:
#             return n % mod, (moves-n) % mod


# def cmb(n, r):
#     return math.factorial(n) % mod // ((math.factorial(r) % mod) * (math.factorial(n-r) % mod))


def cmb(n, r):
    if r < 0 or r > n:
        return 0
    r = min(r, n-r)

    return g1[n] * g2[r] * g2[n-r] % mod


def main():
    for i in range(2, N + 1):
        g1.append((g1[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod // i)) % mod)
        g2.append((g2[-1] * inverse[-1]) % mod)

    x, y = map(int, input().split())

    if (x+y) % 3:
        print(0)
        sys.exit()

    # n, m = find_n(x, y)

    n = int(((x*2 - y) // 3))
    m = int(((y*2 - x) // 3))

    ans = cmb(n+m, n)

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 125368
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 2000005;
char en = '\n';
ll inf = 1e16;
ll mod = 998244353;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
ll pre[N];

bool prime[N];

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

  ll n;
  cin >> n;
  string s;
  cin >> s;

  if (n & 1) {
    cout << "No" << en;
  } else {
    string a = s.substr(0, n / 2);

    string b = s.substr(n / 2, n / 2);

    cout << ((a == b) ? "Yes" : "No") << en;
  }

  return 0;
}

/*
5
1 2 3 1 2
1
1 5
 */

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         998244353
#define mode        1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323

const int N = 1e5+5;
ll n,a[N];

void solve()
{
       ll ans=0;
       cin>>n;
       rep(i,1,n+1) cin>>a[i];
       if(n==1)
       {
              cout<<1;
              exit(0);
       }
       ll inc=0,dec=0;
       ll cc=1;
       if(a[2]==a[1]) {inc=1; dec=1;}
       else if(a[2]>a[1]) {inc=1;}
       else { dec=1; }
       ll i=2;
       while(i<n)
       {
              if(a[i]<a[i+1])
              {
                     if(dec && !inc) {  cc++;  inc=1; dec=1; }
                     else if(inc && dec) { inc=1; dec=0; }
              }
              else if(a[i]>a[i+1])
              {
                     if(inc && !dec) { cc++; inc=1; dec=1;}
                     else if(inc && dec) { dec=1; inc=0;}
              }
              i++;
       }
       cout<<cc;
}


int main()
{
    speed_up
    ll T=1;
    //cin>>T;
    while(T--)
        solve();
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

#define Max 100000
#define S 1000000000

typedef struct Card{
  char suit;
  int value;
}Card;

Card L[Max / 2 + 2], R[Max / 2 + 2];

void merge(Card a[], int n, int l, int m, int r){
  int i, j, k, n1, n2;
  n1 = m - l;
  n2 = r - m;
  
  for(i = 0 ; i < n1 ; i++) L[i] = a[l + i];
  for(i = 0 ; i < n2 ; i++) R[i] = a[m + i];
  
  L[n1].value = R[n2].value = S;
  i = j = 0;
  
  for(k = l ; k < r ; k++){
    if(L[i].value <= R[j].value){
      a[k] = L[i++];
    }
    else{
      a[k] = R[j++];
    }
  }
}

void mergeSort(Card a[], int n, int l, int r){
  int m;
  if(l + 1 < r){
    m = (l + r) / 2;
    mergeSort(a, n, l, m);
    mergeSort(a, n, m, r);
    merge(a, n, l, m, r);
  }
}

int partition(Card a[], int n, int p, int r){
  int i, j;
  Card t, x;
  x = a[r];
  i = p - 1;

  for(j = p ; j < r ; j++){
    if(a[j].value <= x.value){
      i++;
      t = a[i];
      a[i] = a[j];
      a[j] = t;
    }
  }

  t = a[i + 1];
  a[i + 1] = a[r];
  a[r] = t;

  return i + 1;
}

void quickSort(Card a[], int n, int p, int r){
  int q;
  if(p < r){
    q = partition(a, n, p, r);
    quickSort(a, n, p, q - 1);
    quickSort(a, n, q + 1, r);
  }
}


int main(){
  int n, i, v, stable = 1;
  Card a[Max], b[Max];
  char s[10];

  scanf("%d", &n);

  for(i = 0 ; i < n ; i++){
    scanf("%s %d", s, &v);
    a[i].suit = b[i].suit = s[0];
    a[i].value = b[i].value = v;
  }

  mergeSort(a, n, 0, n);
  quickSort(b, n, 0, n - 1);
  
  for(i = 0 ; i < n ; i++){
    if(a[i].suit != b[i].suit) stable = 0;
  }

  if(stable == 1) printf("Stable\n");
  else printf("Not stable\n");
  for(i = 0 ; i < n ; i++){
    printf("%c %d\n", b[i].suit, b[i].value);
  }

  return 0;
}


Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ris return *this
template<class c> struct rge {
	c b, e;
};
template<class c> rge<c> range(c i, c j) {
	return rge<c>{i, j};
}
template<class c> auto dud(c* x) -> decltype(cerr << *x, 0);
template<class c> char dud(...);
struct debug {
#ifdef LOCAL
	~debug() {
		cerr << endl;
	}
	template<class c> typename
		enable_if<sizeof dud<c>(0) != 1, debug&>::type operator << (c i) {
			cerr << boolalpha << i;
			ris;
		}
	template<class c> typename
		enable_if<sizeof dud<c>(0) == 1, debug&>::type operator << (c i) {
			ris << range(begin(i), end(i));
		}
	template<class c, class b> debug & operator << (pair <b, c> d) {
		ris << "(" << d.first << ", " << d.second << ")";
	}
	template<class c> debug & operator << (rge<c> d) {
		*this << "[";
		for (auto it = d.b; it != d.e; ++it)
			*this << ", " + 2 * (it == d.b) << *it;
		ris << "]";
	}
#else
	template<class c> debug & operator << (const c&) {
		ris;
	}
#endif
};
#define imie(...) " [" << #__VA_ARGS__": " << (__VA_ARGS__) << "] "
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const double pi = acos(-1.0);
const double eps = 1e-10;

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

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

template<typename T>
void s_add(T& a, T b) {
	a += b;
}

template<typename T>
void s_madd(T& a, T b) {
	a = (a + b) % mod;
}

const int N = 1e5 + 5;
int n;
vector<int> adj[N];
ll dp[N][2];

ll solve(int v, int p, int c) {
	if (dp[v][c] != -1)
		return dp[v][c];
	ll ways = 1, total = 0;
	if (c == 0) {
		for (auto it : adj[v])
			if (it != p)
				ways = (ways * solve(it, v, 1)) % mod;
		total += ways;
	}
	ways = 1;
	for (auto it : adj[v])
		if (it != p)
			ways = (ways * solve(it, v, 0)) % mod;
	total = (total + ways) % mod;
	return dp[v][c] = total;
}

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

	cin >> n;
	int x, y;
	for (int i = 0; i < n - 1; i++) {
		cin >> x >> y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	memset(dp, -1, sizeof(dp));
	ll answer = solve(1, 0, 0);
	cout << answer;

	return 0;
}


Measured memory_bytes: 15616