akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

#define MAX (8)

class Square{
public:

  bool state;
  bool queen;

  Square(){
    this->init();
  }

  void init(){
    this->state = false;
    this->queen = false;
  }

};

class Board{
public:

  int queenNum;
  Square board[MAX][MAX];

  Board(){
    this->queenNum = 0;
    initBoard();
  }

  void initBoard(){
    int i;
    int j;

    for(i = 0;i < MAX;i++){
      for(j = 0;j < MAX;j++){
	this->board[i][j].init();
      }
    }
  }

  bool setQueen(int x,int y){

    int i;
    bool flag;

    if(checkQueen(x,y) == true){
      return false;
    }
    else {
      this->queenNum++;
      this->board[x][y].queen = true;
    }

    for(i = 1;i < MAX;i++){
      if(check(x+i,y) == false){
	return false;
      }      
      if(check(x-i,y) == false){
	return false;
      }
      if(check(x,y-i) == false){
	return false;
      }      
      if(check(x,y+i) == false){
	return false;
      }      
      if(check(x+i,y+i) == false){
	return false;
      }      
      if(check(x+i,y-i) == false){
	return false;
      }      
      if(check(x-i,y+i) == false){
	return false;
      }      
      if(check(x-i,y-i) == false){
	return false;
      }
    }
  }

  bool checkQueen(int x,int y){
    return this->board[x][y].queen;
  }

  bool check(int x,int y){
    if(x < MAX && x >= 0 &&
       y < MAX && y >= 0)
      {
	if(checkQueen(x,y) == true){
	  return false;
	}
	else{
	  this->board[x][y].state = true;
	}
      }
    return true;
  }

  void print(){
    int i;
    int j;

    for(i = 0;i < MAX;i++){
      for(j = 0;j < MAX;j++){
	if(this->board[i][j].queen == true){
	  cout << "Q";
	}
	else {
	  cout << ".";
	}
      }
      cout << endl;
    }
  }

};

Board generate8Queen(Board board,int x,int y){

  int i;
  Board temp;

  for(i = 0;i < MAX;i++){
    temp = board;
    if(board.board[x][y+i].state == false){
      temp.setQueen(x,y+i);
      if(x+1 < MAX){
      temp = generate8Queen(temp,x+1,0);
      }
      if(temp.queenNum == MAX){
	return temp;
      }
    }
  }
  return temp;
}


int main(){

  Board board;

  int i;
  int n;
  int x;
  int y;

  cin >> n;

  for(i = 0;i < n;i++){
    cin >> x;
    cin >> y;
    board.setQueen(x,y);
  }

  board = generate8Queen(board,0,0);

  board.print();

  return 0;
}

Measured memory_bytes: 1160
//Buffet
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <set>

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector<int> B(N);
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }
    vector<int> C(N);
    for (int i = 0; i < N-1; i++) {
        cin >> C[i];
    }

    int res = 0;
    for (int i = 0; i < N; i++) {
        int j = A[i]-1;
        res += B[j];
        if (i==0) {
            continue;
        }
        if (A[i]-1 == A[i-1]) {

            //cout << i << " " << j << " " << C[j-1] << endl;
            res += C[j-1];
        }
    }

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

Measured memory_bytes: 888
//   __________________
//  | ________________ |
//  ||          ____  ||
//  ||   /\    |      ||
//  ||  /__\   |      ||
//  || /    \  |____  ||
//  ||________________||
//  |__________________|
//  \###################\
//   \###################\
//    \        ____       \
//     \_______\___\_______\
// An AC a day keeps the doctor away.

#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/extc++.h>
#ifdef local
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(...) qqbx(#__VA_ARGS__,  __VA_ARGS__)
template <typename H, typename ...T> constexpr void qqbx(const char *s, const H &h, T &&...args) {
    for(; *s && *s != ','; ++s) if(*s != ' ') std::cerr << *s;
    std::cerr << " = " << h << (sizeof...(T) ? ", " : "\n");
    if constexpr(sizeof...(T)) qqbx(++s, args...); // C++ 17!
}
#else
#include <bits/stdc++.h>
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
#define all(v) begin(v),end(v)
#define get_pos(v,x) (lower_bound(begin(v),end(v),x)-begin(v))
#define sort_uni(v) sort(begin(v),end(v)),v.erase(unique(begin(v),end(v)),end(v))
#define pb emplace_back
#define ff first
#define ss second
#define mem(v,x) memset(v,x,sizeof v)

using namespace std;
using namespace __gnu_pbds;
typedef int64_t ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
template <typename T> using max_heap = std::priority_queue<T,vector<T>,less<T> >;
template <typename T> using min_heap = std::priority_queue<T,vector<T>,greater<T> >;
template <typename T> using rbt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
constexpr ld PI = acos(-1), eps = 1e-7;
constexpr ll N = 200025, INF = 1e18, MOD = 1000000007, K = 357, inf = 1e9;
constexpr inline ll cdiv(ll x, ll m) { return x/m + ((x<0 ^ m>0) && (x%m)); } // ceiling divide
constexpr inline ll modpow(ll e,ll p,ll m=MOD) { ll r=1; for(e%=m;p;p>>=1,e=e*e%m) if(p&1) r=r*e%m; return r; }

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, d, ans;
    cin >> n >> d >> ans;
    for(int i = 0; i < n; i++) {
        int a;
        cin >> a;
        ans += cdiv(d, a);
    }
    cout<<ans<<'\n';
}



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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N, K;
	cin >> N >> K;
	vector<ll> h(N);
	REP(i, N) cin >> h[i];

	vector<ll> res(N, 10101010101010);
	res[0] = 0;
	REP(i, N){
		REP(j, K) if(i+j+1<N) res[i+j+1] = min(res[i+j+1], res[i]+abs(h[i+j+1]-h[i]));
	}
	cout << res[N-1] << endl;
    return 0;
}

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



int main(){
    ios::sync_with_stdio(0);
	cin.tie(0);
    ll n;
    cin >> n;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];

    int ans = 0;
    int tmp = 0;
    for(int i = 0; i < n-1; i++){
        if(h[i] >= h[i+1]){
            tmp++;
            ans = max(ans, tmp);
        }else{
            tmp = 0;
        }
    }

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

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#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 ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    int n,k; cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(ALL(p));
    int ans = 0;
    rep(i,k){
        ans += p[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
int A, B, K;

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

  cin >> A >> B >> K;

  if (B - A+1 <= 2*K){
    for(int i=A; i<=B; i++) cout << i << endl;
    return 0; 
  }
  for (int i = A; i< A+K; i++){
    cout << i << endl;
  }
  for (int i = B-K+1; i<= B; i++){
    cout << i << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int a,b,d,r;
	double f;
	scanf("%d %d",&a,&b);
	d=a/b;
	r=a%b;
	f=1.000000*a/b;
	printf("%d %d %f",d,r,f);
return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9;
vector<int>V[N];
int n, m, cnt, g[N], stk[N], top, wz[N], o, h[N], s, inh[N], xl[N], t;
bool col[N];

void Dfs (int u, int fa) {
	for (auto v : V[u]) if (!inh[v] && v != fa) {
		Dfs(v, u);
	/*	if (!col[v]) {
			if (col[u]) ++g[u];
			else col[u] ^= 1;
			col[v] ^= 1;
			++cnt;
		}*/
		g[u] -= g[v];
	}
	if (!col[u]) --g[u], col[u] ^= 1;
	if (!inh[u]) cnt += abs(g[u]);
}

void DfsH (int u) {
	stk[wz[u] = ++top] = u;
	for (auto v : V[u]) if (v != stk[top - 1]) {
		if (wz[v]) {
			o = v;
			break ;
		} else {
			DfsH(v);
			if (o) break;
		}
	}
	--top; wz[u] = 0;
	if (o > 0) {
		h[++s] = u;
		inh[u] = s;
		if (u == o) o = -1;
	}
}

void Solve () {
	DfsH(1);
	for (int i = 1; i <= s; ++i) Dfs(h[i], 0);
	for (int i = 1, j = 0; i <= s; ++i) {
		j = g[h[i]] - j;
		xl[++t] = i & 1 ? j : -j;
	}
	int ans;
	if (t & 1) {
		if (xl[t] & 1) puts("-1"), exit(0);
		ans = xl[t] >> 1;
	} else {
		if (xl[t] != 0) puts("-1"), exit(0);
		nth_element(xl + 1, xl + (t >> 1), xl + t + 1);
		ans = xl[t >> 1];
	}
	for (int i = 1; i <= t; ++i) {
		cnt += abs(ans - xl[i]);
	}
	g[1] = 0;
}

int main () {
	scanf("%d%d", &n, &m);
	for (int i = 1, a, b; i <= m; ++i) {
		scanf("%d%d", &a, &b);
		V[a].emplace_back(b);
		V[b].emplace_back(a);
	}
	if (m + 1 == n) {
		inh[1] = 1;
		Dfs(1, 0);
		if (!col[1]) --g[1];
		cnt += abs(g[1]);
	} else {
		Solve();
	}
	return printf("%d\n", g[1] == 0 ? cnt : -1), 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define INF 1e+18
#define ll long long
using namespace std;

signed main(){
	int n,m,cnt[100010] = {},ans = 0;
	cin >> n >> m;
	for(int i = 0;i < m;i++){
		int l,r;
		cin >> l >> r;
		cnt[l - 1]++;
		cnt[r]--;
	}
	for(int i = 0;i <= n;i++){
		cnt[i + 1] += cnt[i];
		if(cnt[i] == m) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
n = int(input())
al = [0] * n
bl = [0] * n
for i in range(n):
    al[i], bl[i] = map(int, input().split())

al.sort()
bl.sort(reverse=True)

if n % 2 == 0:
    print((bl[n//2-1] - al[n//2-1])+((bl[n//2] - al[n//2])+1))
else:
    print(bl[n//2] - al[n//2]+1)


Measured memory_bytes: 75672
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;

// dijkstra O(ElogV)
// verify : https://onlinejudge.u-aizu.ac.jp/problems/GRL_1_A
template<typename T>
struct Dijkstra {
private:
    int V;
    struct edge { int to; T cost; };
    vector<vector<edge>> G;
public:
    const T inf = numeric_limits<T>::max();

    // s から i の最小コスト
    // 経路がない場合は inf
    vector<T> d;

    Dijkstra(int V) : V(V) {
        G.resize(V);
    }

    // 辺の追加
    // 有向の場合　directed = true
    void add_edge(int from, int to, T weight, bool directed = false) {
        G[from].push_back({to,weight});
        if (!directed) G[to].push_back({from,weight});
    }

    void build(int s) {
        d.assign(V, inf);
        typedef pair<T, int> P; //(cost,v)
        priority_queue<P, vector<P>, greater<P>> pq;
        d[s] = 0;
        pq.push(P(d[s], s));

        while (!pq.empty()) {
            P p = pq.top(); pq.pop();
            int v = p.second;
            if (d[v] < p.first) continue;
            for (const edge &e : G[v])
            {
                // 最小値が更新されるとき push
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    pq.push({d[e.to], e.to});
                }
            }
        }
    }
};

int main() {
    int n, m; cin >> n >> m;
    Dijkstra<ll> G(n);
    REP(i, m) {
        int l, r; ll c; cin >> l >> r >> c;
        l--; r--;
        G.add_edge(l, r, c, true);
    }
    FOR(i,1,n) {
        G.add_edge(i, i - 1, 0, true);
    }
    G.build(0);
    if (G.d[n - 1] == G.inf) {
        cout << -1 << endl;
    }
    else {
        cout << G.d[n - 1] << endl;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
ll sum(ll x, ll b){
	ll ret = 0;
	while(x){
		ret += x%b;
		x /= b;
	}
	return ret;
}
vector<ll> v;
int main(){
	ll i,n,s;
	cin >> n >> s;
	if(n==s){
		cout << n + 1 << endl;
		return 0;
	}
	for(i=1;i*i<=(n - s);i++){
		if((n - s)%i==0){
			v.push_back(i);
			if(i*i!=n){
				v.push_back((n - s)/i);
			}
		}
	}
	sort(v.begin(),v.end());
	for(i=0;i<v.size();i++){
		if(sum(n,v[i] + 1)==s){
			cout << v[i] + 1 << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#define INF 1000000000
#define rep(i,n) for(int i =0;i<n;i++)
using namespace std;
typedef long long int ll;

int main(){
    for(;;){
        int n;
        cin >> n;
        if(!n)break;
        int g[500][500];
        for (int i=0; i<500; i++) {
            for (int j=0; j<500; j++) {
                g[i][j]=0;
            }
        }
        vector<pair<int,int> > memo(250,{0,0});
        g[250][250]=1;
        memo[0]={250,250};
        for (int i=1; i<n; i++) {
            int n,d;
            cin >> n >> d;
            int s=0,t=0;
            if (d==0) s=-1;
            if (d==1) t=-1;
            if (d==2) s=1;
            if (d==3) t=1;
            int ii=memo[n].first+s;
            int jj=memo[n].second+t;
            g[ii][jj]=1;
            memo[i]={ii,jj};
        }
        int u=0,m=0,h=0,s=0;
        for (int i=0; i<500; i++) {
            int ch=0;
            for (int j=0; j<500; j++) {
                if(g[i][j]!=0){
                    u=i;
                    ch++;
                    break;
                }
            }
            if(ch==1) break;
        }
        for (int i=499; i>=0; i--) {
            int ch=0;
            for (int j=0; j<500; j++) {
                if(g[i][j]!=0){
                    s=i;
                    ch++;
                    break;
                }
            }
            if(ch==1) break;
        }
        for (int i=0; i<500; i++) {
            int ch=0;
            for (int j=0; j<500; j++) {
                if(g[j][i]!=0){
                    h=i;
                    ch++;
                    break;
                }
            }
            if(ch==1) break;
        }
        for (int i=499; i>=0; i--) {
            int ch=0;
            for (int j=0; j<500; j++) {
                if(g[j][i]!=0){
                    m=i;
                    ch++;
                    break;
                }
            }
            if(ch==1) break;
        }
        cout << s-u+1<<" "<< m-h+1<<endl;
    }
}

Measured memory_bytes: 2168
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] n = sc.next().toCharArray();
		int ans = 0;
		for(int i = 0;i < n.length; i++) {
			ans += n[i]-'0';
		}
		for(int i= 1; i < n.length ; i++) {
			n[i] = '9';
		}
		
		int temp = 0;
		for(int i = 0 ; i < n.length; i++) {
			if(i==0) {
				temp += n[i]-'1';
			}
			else {
				temp += n[i]-'0';
			}
		}
		ans = Math.max(ans, temp);
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
h,w = map(int,input().split())
s = [str(input()) for i in range(h)]
for i in range(h):
  for j in range(w):
    if s[i][j] == "#":
      key = 0
      if j > 0:
        if s[i][j-1] == "#":key = 1
      if j < w-1:
        if s[i][j+1] == "#":key = 1
      if i > 0:
        if s[i-1][j] == "#":key = 1
      if i < h-1:
        if s[i+1][j] == "#":key = 1
      if key == 0:
        print("No")
        exit()
print("Yes")

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

int main()
{
	char b;
	cin >> b;
	
	if (b == 'A')
	{
		cout << 'T' << endl;
	}
	else if (b == 'T')
	{
		cout << 'A' << endl;
	}
	else if (b == 'C')
	{
		cout << 'G' << endl;
	}
	else
	{
		cout << 'C' << endl;
	}
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    ll N;
    cin >> N;
    vector<ll> s;
    REP(i, N) {
        ll m;
        cin >> m;
        s.push_back(m);
    }
    sort(s.begin(),s.end());

    ll Q;
    cin >> Q;
    ll ans = 0;
    REP(i, Q) {
        ll q;
        cin >> q;

        ll n = *lower_bound(s.begin(), s.end(), q) ;
        if (q == n)
            ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3836
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int4(int *a1, int *a2, int *a3, int *a4) {
  scanf("%d %d %d %d", a1, a2, a3, a4);
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}


#define NUM_MAX 8

void get_arr(int *arr, int size, int pat) {
    int idx = 0;
    while(pat) {
        int type = pat&3;
        arr[idx++] = type;
        pat /= 4;
    }
}

#define INF (1e+9)

int asc(const void *a1, const void *a2) { return *(int*)a1 - *(int*)a2; }

int main(void) {
    int num, a, b, c;
    get_int4(&num, &a, &b, &c);
    int num2 = num*2;
    int base[3] = {c, b, a}; // c<b<a
    int lens[NUM_MAX];
    fget_array(lens, num);

    int pat;
    int i;
    int ans = INF;
    for(pat = 1; pat < (1<<num2); pat++) {
        int arr[NUM_MAX] = {0};
        get_arr(arr, num, pat);
        int map[3] = {0};
        int consume = 0;
        for(i = 0; i < num; i++) {
            int type = arr[i];
            if(type == 3) continue; // no use
            if(map[type]) consume += 10;
            map[type] += lens[i];
        }
        int flag = 1;
        // # of length of banboo is positive.
        for(i = 0; i < 3; i++) if(!map[i]) flag = 0;
        if(!flag) continue;
        qsort(map, 3, sizeof(int), asc);

        for(i = 0; i < 3; i++) {
            consume += abs(base[i]-map[i]);
        }
#ifdef DEBUG
        printf("%d %d %d: consume : %d\n", map[0], map[1], map[2], consume);
#endif
        ans = min(ans, consume);
    }

    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n =sc.nextInt();
		int m = sc.nextInt();
		int[] k = new int[n];
		int[][] a = new int[n][m];
		for(int i = 0; i < n; i++) {
			k[i] = sc.nextInt();
			for(int j = 0; j < k[i]; j++) {
				a[i][j] = sc.nextInt();
			}
		}
		int[] like = new int[m];
		Arrays.fill(like, 0);
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < k[i]; j++) {
				like[a[i][j]-1]++;
			}
		}
		int ans = 0;
		for(int i = 0; i < m; i++) {
			if(like[i] == n) {
				ans++;
			}
		}
		System.out.println(ans);
		
		
		
	}
}


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

bool solve1(int N, vector<int> &A){
  sort(A.begin(),A.end());
  vector<bool> V(1000001,false),W(1000001,false);
  for(int i=0;i<N;i++){
    if(V[A[i]] && A[i]!=1) return false;
    V[A[i]] = true;
  }
  
  for(int i=2;i<=1000000;i++){
    if(W[i]) continue;
    int count = 0;
    for(int j=1;j*i<=1000000;j++){
      if(V[i*j]) count++;
      W[i] = true;
    }
    if(count>=2) return false;
  }
  return true;
}

bool solve2(int N, vector<int> &A){
  int g = A[0];
  for(int i=1;i<N;i++) g = gcd(g,A[i]);
  if(g==1) return true;
  else return false;
}

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++) cin >> A[i];
  
  if(solve1(N,A)) cout << "pairwise coprime" << endl;
  else if(solve2(N,A)) cout << "setwise coprime" << endl;
  else cout << "not coprime" << endl;
  return 0;
}


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

public class Main {
    public static PrintWriter out;
    public static FastScanner in;

    private class Student{
        int x;
        int y;
        int d;
        int idx;
        public Student(int x, int y, int d, int idx) {
            this.x = x;
            this.y = y;
            this.d = d;
            this.idx = idx;
        }


    }

    private void solve(){
        int n = in.nextInt();
        int m = in.nextInt();

        List<Student> lst = new ArrayList<>();

        for(int i=0;i<n;i++){
            lst.add(new Student(in.nextInt(),in.nextInt(),Integer.MAX_VALUE,-1));
        }

        for(int i=0;i<m;i++){
            int x = in.nextInt();
            int y = in.nextInt();

            for(Student s:lst){
                int v = Math.abs(s.x-x)+Math.abs(s.y-y);
                if(v < s.d){
                    s.idx = i;
                    s.d = v;
                }
            }
        }

        for(Student s:lst){
            out.println(s.idx+1);
        }
    }

    private void runIO() {
        in = new FastScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        solve();
        out.close();
    }
    private static class FastScanner {
        BufferedReader bufferedReader;
        StringTokenizer stringTokenizer;

        private FastScanner() {
            bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        }

        private String next() {
            if (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

        private int nextInt() {
            return Integer.parseInt(next());
        }

        private long nextLong() {
            return Long.parseLong(next());
        }

        private String nextLine() {
            String ret = "";
            try {
                ret = bufferedReader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return ret;
        }
    }

    public static void main(String[] args) {
        new Main().runIO();
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = (LL)1e9+7;
const int SIZE = 2e5+5;
const LL INF = 1LL<<60;
const double eps = 1e-4;
const double PI=3.1415926535897932;

double dp[150009];
double ans[150009];
vector<int> radj[150009],adj[150009];
int par[150009];

void dfs1(int x,int p=-1){
	int cc=SZ(radj[x])-(p!=-1);
	for(int i:radj[x]){
		if(i==p)continue;
		adj[x].PB(i);
		dfs1(i,x);
		dp[x]+=(dp[i]+1)/cc;
	}
}

void dfs2(int x,int p=-1){
	if(x==0)ans[x]=dp[x];
	else{
		int cc=SZ(radj[x]);
		int pcc=SZ(radj[p]);
		ans[x]=(dp[x]*(cc-1))/cc;
		if(pcc>1)ans[x]+=((ans[p]-(dp[x]+1)/pcc)/(pcc-1)*pcc+1)/cc;
		else ans[x]+=(double)1/cc;
	}
	for(int i:adj[x]){
		dfs2(i,x);
	}
}

int main(){
	DRI(n);
	REP(i,n-1){
		DRII(a,b);a--;b--;
		radj[a].PB(b);radj[b].PB(a);
	}
	dfs1(0);dfs2(0);
	REP(i,n){
		printf("%.10lf\n",ans[i]);
		//printf("%lf",[i]);
	}
}


Measured memory_bytes: 25600
//stack
#include<iostream>
#include<stack>
#include<vector>

int main (){
    using namespace std;

    int n,q;
    cin>>n>>q;
    stack <int> S[n]={};//これでいいの？

    for(int i=0;i<q;i++){
        int num,t,x;
        cin>>num>>t;
        switch (num){
            case 0:{
                cin>>x;
                S[t].push(x);
                break;
            }
            case 1:{
                if(S[t].empty()){
                    break;
                }
                else{cout<<S[t].top()<<endl;
                break;
                }
            }
            case 2:{
                if(S[t].empty()){
                    break;
                }
                else{
                S[t].pop();
                break;
                }
            }
        }

    }
    return 0;
}



Measured memory_bytes: 4372
n,k = map(int,input().split())
lst = [0] * n
ans = 0

for i in range(k):
  lenc = int(input())
  candy = input().split()
  for c in range(lenc):
    #print(candy[c])
    lst[int(candy[c])-1] += 1
#
#print(lst)
for i in lst:
  if i == 0:
    ans += 1
#

print(ans)

Measured memory_bytes: 67528
N = int(input())
A = list(map(int, input().split()))
B = [A[0]]
for i in range(1, N):
    B.append(A[i] + B[i-1])

cnt1, cum1 = 0, 0
for i in range(N):
    if i%2 == 0:
        if B[i] + cum1 > 0:
            pass
        else:
            d = 1 - (B[i] + cum1)
            cum1 += d
            cnt1 += abs(d)
    else:
        if B[i] + cum1 < 0:
            pass
        else:
            d = -1 - (B[i] + cum1)
            cum1 += d
            cnt1 += abs(d)

cnt2, cum2 = 0, 0
for i in range(N):
    if i%2 == 0:
        if B[i] + cum2 < 0:
            pass
        else:
            d = -1 - (B[i] + cum2)
            cum2 += d
            cnt2 += abs(d)
    else:
        if B[i] + cum2 > 0:
            pass
        else:
            d = 1 - (B[i] + cum2)
            cum2 += d
            cnt2 += abs(d)

print(min(cnt1, cnt2))

Measured memory_bytes: 14332
s = input()
n = len(s)

def dfs(i, f):
    if i == n - 1:
        return sum(list(map(int, f.split("+"))))
      
    return dfs(i + 1, f + s[i + 1]) + dfs(i + 1, f + "+" + s[i + 1])
    
print(dfs(0, s[0]))

Measured memory_bytes: 3060
#![allow(non_snake_case,unused_imports,dead_code)]
use std::str::FromStr;
use std::collections::{HashMap,HashSet,VecDeque,BinaryHeap};
use std::cmp::{max,min,Reverse,Ordering};

use proconio::input;
use proconio::marker::{Chars,Usize1,Isize1};

fn comp_f64(a: &f64, b: &f64) -> Ordering {
    if a < b {
        return Ordering::Less;
    } else if a > b {
        return Ordering::Greater;
    }
    Ordering::Equal
}

fn main() {
    input!{
        N:usize,
        mut H:isize,
        mut AB:[(isize,isize);N],
    }
    let a = AB.iter().map(|ab| ab.0).max().unwrap();
    AB.sort_by_key(|ab| Reverse(ab.1));
    let mut ans = 0;
    
    for &(_,b) in &AB{
        if b<=a{break;}
        ans += 1;
        H -= b;
        if H<=0{break;}
    }
    H = max(0,H);
    ans += (H+a-1)/a;

    println!("{}",ans);
}


Measured memory_bytes: 5944
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        String[] sArr = new String[n];

        for (int i = 0; i < n; i++) {
            sArr[i] = sc.next();
        }

        Arrays.sort(sArr);

        String res = "";
        for (int i = 0; i < n; i++) {
            res += sArr[i];
        }

        System.out.println(res);
    }
}


Measured memory_bytes: 24852
using System;

namespace AtTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int number = 0;
            for (int i = 0; i < input.Length; i++)
            {
                if (input[i] == '+')
                {
                    number++;
                }
                else
                {
                    number--;
                }
            }

            Console.WriteLine(number);
        }
    }
}


Measured memory_bytes: 11092
#!/usr/bin/env python3
import sys
import numpy as np
import math

def isPrime(n):
    if n==1:
        return False
    else:
        for k in range(2,int(math.sqrt(n))+1):
            if n%k == 0:
                return False
        return True

def solve(X: int):
    while(True):
        if isPrime(X):
            print(X)
            return
        else:
            X+=1

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


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

using namespace std;
int a[1000000];
int main(){
	a[0]=1;
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	a[i]=min(a[i-1]+k,a[i-1]*2);
	cout<<a[n];
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n), deg(n);
    vector<bool> used(n, false);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        deg[(i+a[i])%n]++;
    }
    for(int i=0;i<n;i++){
        int v = i;
        while(deg[v]==0 && !used[v]){
            used[v] = true;
            v = (v+a[v])%n;
            deg[v]--;
        }
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        if(deg[i] > 0) ans++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3544
#include<iostream>
#include<algorithm>
#include<vector>
#include<unordered_set>
using namespace std;
typedef long long ll;
typedef unordered_set<ll> set;
#define N 100010
#define D 20
ll n;
vector<ll> g[N];
set solve(ll x,ll from){
  vector<set> v;
  for(auto y:g[x])if(y!=from)v.push_back(solve(y,x));
  ll clash=-1;
  for(ll i=D;i-1;i--){
    int cnt=0;
    for(auto x:v)if(x.find(i)!=x.end())cnt++;
    if(cnt>=2){clash=i; break;}
  }
  ll gen;
  for(ll i=clash+1;;i++){
    int cnt=0;
    for(auto x:v)if(x.find(i)!=x.end())cnt++;
    if(cnt==0){gen=i; break;}
  }
  set res; res.insert(gen);
  for(ll i=gen+1;i<D;i++){
    int cnt=0;
    for(auto x:v)if(x.find(i)!=x.end())cnt++;
    if(cnt>0)res.insert(i);
  }
  return res;
}
int main(){
  cin>>n;
  for(int i=0;i<n-1;i++){
    ll a,b;cin>>a>>b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  set res=solve(1,0);
  ll ans=0;
  for(auto x:res)ans=max(ans,x);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 21680
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

const int mod = (int) 1e9 + 7;

void add(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int mult(int x, int y) {
  return (long long) x * y % mod;
}

int myPower(int x, int pw) {
  int res = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
  }
  return res;
}

const int maxk = (int) 1e5 + 10;
int notp[maxk];

int ps[maxk];
int cntp;

void precalc() {
  notp[0] = notp[1] = 1;
  cntp = 0;

  for (int i = 2; i < maxk; ++i) {
    if (notp[i]) {
      continue;
    }

    ps[cntp++] = i;
    for (int j = 2 * i; j < maxk; j += i) {
      notp[j] = 1;
    }
  }
}


const int maxn = (int) 1e5 + 10;

set<pair<long long, long long> > pairs;
map<long long, int> cnt;

int n;

int res;

int read() {
  if (scanf("%d", &n) < 1) {
    return 0;
  }
  res = 0;
  pairs.clear();
  cnt.clear();
  for (int i = 0; i < n; ++i) {
    long long x;
    scanf("%lld", &x);

    long long nx = 1;
    long long y = 1;
    for (int i = 0; i < cntp; ++i) {
      int p = ps[i];
      if (p >= (int) 3e3) {
        break;
      }
      if (x % p) {
        continue;
      }
      int ti = 0;
      for (; x % p == 0; x /= p) {
        ++ti;
      }
      ti %= 3;
      if (ti) {
        for (int j = 0; j < ti; ++j) {
          nx *= p;
        }
        long long np = 1;
        for (int j = ti; j < 3; ++j) {
          np *= p;
        }
        if (y > (long long) 1e10 / np) {
          y = (long long) 1e10 + 1;
          break;
        }
        y *= np;
      }
    }
    if (y > (long long) 1e10) {
      ++res;
      continue;
    }

    if (x > 1) {
      long long p = sqrt(x);
      if (p * p == x) {
        nx *= x;
        y *= p;
      } else {
        if (y > (long long) 1e10 / x / x) {
          ++res;
          continue;
        }
        nx *= x;
        y *= x * x;
      }
    }

    x = nx;

    if (x == 1) {
      cnt[x] = 1;
    } else {
      cnt[x] += 1;
    }

    if (x > y) {
      swap(x, y);
    }
    pairs.insert(mp(x, y));
  }
  return 1;
}

void solve() {
  //eprintf("res = %d\n", res);
  for (auto p : pairs) {
    auto x = p.first, y = p.second;
    //eprintf("%lld %lld\n", x, y);
    res += max(cnt[x], cnt[y]);
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 16128
N = int(input())
line = input()
arystrLine = line.split()
A = [int(s) for s in arystrLine]

ans = 0
max = A[0]

for i in range(1, N):
    #print(i, A[i])
    if A[i] > max:
        max = A[i]
    else:
        ans = ans + max - A[i]

print(ans)

Measured memory_bytes: 33596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int main(){
  
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  
  ll ac = a*c;
  ll ad = a*d;
  ll bc = b*c;
  ll bd = b*d;
  
  ll ans = ac;
  ans = max(ans,ad);
  ans = max(ans,bc);
  ans = max(ans,bd);
  
  cout << ans << endl;
}


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

#define fastio {\
    ios::sync_with_stdio(0);\
    cin.tie(0);\
}

#define file {\
    freopen("io\\in.txt", "r", stdin);\
    freopen("io\\out.txt", "w", stdout);\
    freopen("io\\err.txt", "w", stderr);\
}

#ifdef LOCAL
#define debug(args...) {\
    string _s(#args);\
    replace(_s.begin(), _s.end(), ',', ' ');\
    stringstream _ss(_s);\
    istream_iterator<string> _it(_ss);\
    debug1(_it, args);\
}

#pragma GCC diagnostic ignored "-Wunused-parameter"
void debug1(istream_iterator<string> it) {
    cerr << endl;
}
#pragma GCC diagnostic pop

template<class T, class... Args>
void debug1(istream_iterator<string> it, T a, Args... args) {
    cerr << '>' << *it << " = " << a << "; ";
    debug1(++it, args...);
}
#else
#define debug(args...)
#define cerr if (false) cerr
#endif

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define rep(i, n)   for (int i = 0; i < n; i++)
#define dotc()      int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)       (int)x.size()
#define eb          emplace_back
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define all(x)      x.begin(), x.end()
#define rall(x)     x.rbegin(), x.rend()
#define fi          first
#define se          second

const int inf(0x3fffffff);
const int mod(1000000007);
const double pi(acos(-1.0));

signed main() {
    fastio;
#ifdef LOCAL
    file;
#endif

    int k;
    cin >> k;
    int sum = 0;
    rep(i, k) rep(j, k) rep(r, k) sum += __gcd(i + 1, __gcd(j + 1, r + 1));
    cout << sum;

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int a, b, c;
  Int x, y, z;
  cin>>a>>b>>c;
  cin>>x>>y>>z;

  auto check= [&](){
    Int Dis = (a - x) * (a - x) + (b - y) * (b - y);
    Int r = (c - z) * (c - z);
    Int R =  (c + z) * (c + z);
    if(Dis > R) return 4;
    if(Dis == R) return 3;
    if(Dis == r ) return 1;
    if(Dis < r) return 0;
    return 2;
  };

  Int ans = check();
  cout<<ans<<endl;

  
    

  return 0;
}



Measured memory_bytes: 3148
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def input():
    return sys.stdin.readline()


def resolve():
    n, k = map(int, input().split())

    min_num = 9999999999999999

    amari = n % k

    ans_list = []
    ans_list.append(amari)

    ans1 = abs(amari - k)
    ans_list.append(ans1)
    ans2 = abs(ans1 - k)
    ans_list.append(ans2)

    answer = min(ans_list)

    print(answer)




if __name__ == "__main__":
    resolve()



Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;

int X[524288];

ll RSQ(int s, int t, int k = 1, int l = 0, int r = 262143) {
	if (t < l || r < s)return 0;
	if (s <= l && r <= t) {
		return X[k];
	}
	ll lv = RSQ(s, t, k * 2, l, (l + r) / 2);
	ll rv = RSQ(s, t, k * 2 + 1, (l + r) / 2 + 1, r);
	return lv + rv;
}

void upd(int x, int v = 0) {
	x += 262144;
	X[x] = v;
	while (x > 1) {
		x /= 2;
		X[x] = X[x * 2] + X[x * 2 + 1];
	}
}

int main() {
	ll N, K, Y;
	cin >> N >> K;
	vector<pair<ll, ll>> A(N + 1);
	vector<ll> C(N + 1, 0), B = C;
	for (int i = 1;i <= N;i++) {
		cin >> Y;
		B[i] = Y - K;
		B[i] += B[i - 1];
		A[i] = { B[i],i };
		upd(i, 1);
	}
	sort(all(A));
	for (int i = 0;i <= N;i++) {
		C[A[i].second] = i;
	}
	ll ans = 0;
	for (int i = 0;i <= N;i++) {
		ans += RSQ(C[i] + 1, N);
		upd(C[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 10112
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; } value
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c;
  cin >> a >> b >> c;
  bool ans = false;
  if(a == b && a != c) ans = true;
  if(a == c && a != b) ans = true;
  if(c == b && a != c) ans = true;
  YesorNo(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <cmath>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define debug(x) cerr<<#x<<": "<<x<<'\n'

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int a[200100] = {};
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i,n) cin >> a[i];
    int l = 0;
    int r = 1;
    int c = a[0];
    ll ans = 0;
    while(true){
      if(l>=n) break;
      if(r>=n || (c&a[r])!=0){
        int np = r-l;
        ans += np;
        c-=a[l];

        // cout << " r: " << r << " l: " << l << endl;
        l+=1;
      }
      else {
        c += a[r];
        r++;
      }
    }
    // int np = r-l;
    // cout << " r: " << r << " l: " << l << endl;
    // ans += (np*(np-1)/2);
    // ans += n;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
n,T = list(map(int,input().split()))
c = [0]*n
t = [0]*n
cmin = 1001
for i in range(0,n):
    c[i],t[i] = list(map(int,input().split()))
    if t[i] <= T:
        cmin = min(cmin,c[i])

if cmin == 1001:
    print("TLE")
else:
    print(cmin)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<map>
#include<set>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000
#define INFL (long long)(4e18)

using vi = vector<int>;


int main() {


	string a, b;

	cin >> a >> b;

	cout << b+a << endl;

	return 0;
}

Measured memory_bytes: 256
# coding: utf-8

import sys
import math
from collections import Counter
import itertools
import fractions
from decimal import *
#import numpy as np
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


N=II()


ans = factorization(N)

cnt = 0

for an in ans:
    if an[0] != 1:
        k = an[1]
        i = 1
        flg = True
        while flg:
            if k - i >= 0:
                k-=i
                cnt+=1
                i+=1
            else:
                flg = False
        


print(cnt)


Measured memory_bytes: 10712
#include<bits/stdc++.h>
#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 fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------


typedef long long ll;
int N, K, A[101010], B[101010];
int ma[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> K;
    rep(i, 0, N) cin >> A[i] >> B[i];
    rep(i, 0, N) ma[i] = -1;

    rep(i, 0, N) {
        int k = K, x = A[i];
        rep(j, 0, 31) {
            if ((k & 1) == 0 && (x & 1)) ma[i] = j;
            k /= 2, x /= 2;
        }
    }

    ll ans = 0;
    rep(i, 0, N) if (ma[i] < 0) ans += B[i];
    //rep(i, 0, N) printf("%d : %d\n", i, ma[i]);

    rep(d, 0, 31) {
        int mask = 1 << d;

        ll sm = 0;
        if (K & mask) { // 1
            rep(i, 0, N) if (ma[i] <= d) if ((A[i] & mask) == 0) sm += B[i];
        }

        ans = max(ans, sm);
    }
    cout << ans << endl;
}

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

int my_abs(int x){
    if(x<0){
        x*=-1;
    }
    return x;
}

int main() {

    int n,m;

    cin >> n >> m;

    int a[n],b[n];

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

    int c[m],d[m];

    for(int i=0; i<m; i++){
        cin >> c[i] >> d[i];
    }

    for(int i=0; i<n; i++){

        int dis = 500000000;
        int ans = -1;

        for(int k=0; k<m; k++) {
            if (dis > my_abs(c[k]-a[i]) + my_abs(d[k]-b[i])){
                dis = my_abs(c[k]-a[i]) + my_abs(d[k]-b[i]);
                ans = k+1;
            }
        }
        cout << ans << endl;

    }

    return 0;
}

Measured memory_bytes: 256