akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
const int  N = 2e5 + 314;
void foo(){
    string s;
    cin>>s;
    int cnt=0;
    for(int i = 0; i < s.size()/2; i++){
        if(s[i]!=s[s.size()-i-1])cnt++;
    }  
    cout<<cnt;
}
int main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)foo();
}

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

void trace(int a[], int n) {
    for (int i=0; i<n; i++) {
        if ( i > 0 ) printf(" ");
        printf("%d", a[i]);
    }
    printf("\n");
}

int bubbleSort(int a[], int n) { //N個の配列の要素を含む0-オリジンの配列a
    int sortNum = 0;
    bool flag = true;
    while (flag) {
        flag = false;
        for (int j=n-1; j>0; j--) {
            if (a[j] < a[j-1]) {
                int temp = a[j];
                a[j] = a[j-1];
                a[j-1] = temp;
                sortNum++;
                flag = true;
            }
        }
    }
    return sortNum;
}

int main() {
    int n;
    int a[110];
    int ans;
    cin >> n;
    for (int i=0; i<n; i++) cin >> a[i];
    ans = bubbleSort(a, n);
    trace(a, n);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3256
sx,sy,tx,ty=map(int,input().split())
x=tx-sx
y=ty-sy
print("R"*x + "U"*y + "L"*x +"D"*y + "D" + "R"*(x+1) + "U"*(y+1) + "L" + "U" + "L"*(x+1) +"D"*(y+1) +"R")

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

#define ZeroMemory(ptr, size)	::memset(ptr, 0, size)

typedef struct
{
	int id;
	int cost;
	int acquired;
} COMPETITION;

typedef struct
{
	int cost;
} COMMITEE;

#define MAX_N	1000

int MaxAcquiredID(COMPETITION *lpCompes, int num)
{
	int id = 0;
	int max = 0;

	for (int i = 0; i < num; i++)
	{
		if (max < lpCompes[i].acquired)
		{
			max = lpCompes[i].acquired;
			id = lpCompes[i].id;
		}
	}

	return(id);
}

int main()
{
	COMPETITION	compes[MAX_N];
	COMMITEE	commits[MAX_N];
	int compesNum, commitsNum;

	// Init
	ZeroMemory(compes, sizeof(compes));
	ZeroMemory(commits, sizeof(commits));

	// Inputs
	::scanf("%i %i", &compesNum, &commitsNum);

	for (int i = 0; i < compesNum; i++)
	{
		compes[i].id = i + 1;
		::scanf("%i", &compes[i].cost);
	}
	for (int i = 0; i < commitsNum; i++)
	{
		::scanf("%i", &commits[i].cost);
	}

	// Vote
	for (int i = 0; i < commitsNum; i++)
	{
		for (int j = 0; j < compesNum; j++)
		{
			//::printf(">>%i, %i\n", compes[j].cost, commits[i].cost);
			if (compes[j].cost <= commits[i].cost)
			{
				compes[j].acquired++;
				break;
			}
		}
	}
	/*
	for (int i = 0; i < compesNum; i++)
	{
		::printf(">%i\n", commits[i].cost);
	}
	*/
	::printf("%i\n", ::MaxAcquiredID(compes, compesNum));
}

Measured memory_bytes: 1048
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef pair<int, int> P;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define x first
#define y second

int mx[] = {0, 1, 1, 0, -1, -1};
int my[] = {-1, -1, 0, 1, 1, 0};

class C{
  public:
    int t;
    vector<P> h;
    C(){}
    C( int _t, vector<P> _h) { t = _t; h = _h; }
};

bool adj(P &a, P &b){
  REP(i, 6){
    P np = P(b.x + mx[i], b.y + my[i]);
    if(np == a) return true;
  }
  return false;
}

void dfs(vector<P> &H, int n, set< vector<P> > &S, vector< vector<P> > &ans, vector<P> &R, queue<C> &open, int &t){
  REP(i, 6){
    P tmp = H[n];
    H[n] = P(H[n].x + mx[i], H[n].y + my[i]);
    bool f = true, ff = true;
    REP(j, R.size()) REP(k, H.size()) if(R[j] == H[k]) f = false;
    REP(j, H.size()){
      FOR(k, j + 1, H.size()){
        if(H[k] == H[j]) ff = false;
        if((j == k + 1 || j == k - 1) && (H[k] == H[j])) f = false;
        if(j == k + 1 || j == k - 1) { if(!adj(H[k], H[j])) f = false; }
        else { if(adj(H[k], H[j])) ff = false; }
      }
    }
    if(f){
      if(ff && S.find(H) == S.end()){
        S.insert(H);
        open.push(C(t + 1, H));
      }
      if(n + 2 < (int)H.size()) dfs(H, n + 2, S, ans, R, open, t);
    }
    H[n] = tmp;
  }
  if(n + 2 < (int)H.size()) dfs(H, n + 2, S, ans, R, open, t);
}

int dist(P &a, P &b){
  return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}

int bfs(vector<P> &H, vector<P> &R, P &G){
  queue<C> open;
  open.push(C(0, H));
  set< vector<P> > closed;
  closed.insert(H);
  while(!open.empty()){
    C c = open.front(); open.pop();
    if(G == c.h[0]) return c.t;
    if(c.t >= 19) continue;
    if(dist(c.h[0], G) >= (20 - c.t) * (20 - c.t)) continue;
    vector< vector<P> > next;
    dfs(c.h, 0, closed, next, R, open, c.t);
    dfs(c.h, 1, closed, next, R, open, c.t);
  }
  return 20;
}

int main() {
  int N, K;
  P G;
  while(cin >>N && N){
    vector<P> H(N);
    REP(i, N) scanf("%d %d", &H[i].x, &H[i].y);
    scanf("%d", &K);
    vector<P> R(K);
    REP(i, K) scanf("%d %d", &R[i].x, &R[i].y);
    scanf("%d %d", &G.x, &G.y);
    printf("%d\n", bfs(H, R, G));
  }
  return 0;
}

Measured memory_bytes: 9516
a=int(input())
flag=0
if(a<=6):
    flag=1
    print(1)
elif(6<a and a<=11):
    flag=1
    print(2)
elif(flag!=1 and a%11==0):
    print(a//11*2)
elif(flag!=1 and a%11!=0):
    if 6<a%11:
        print(a//11*2+2)
    else:
        print(a//11*2+1)

Measured memory_bytes: 3060
#include <cstdio>
#include <vector>
#include <queue>
#define maxn 100005
using namespace std;

typedef vector<int>* Graph;

int n, m, k, graphnum[maxn], subgraphsize[maxn];
vector<int> friends[maxn], block[maxn];

template <typename T>
void bfs(const Graph& G, int v, T visit, bool* visited)
{
	queue<int> q;
	q.push(v);
	while(!q.empty())
	{
		int x = q.front(); q.pop();
		if(visited[x]) continue;
		visited[x] = true;
		visit(x);
		for(int it: G[x]) q.push(it);
	}
}

void splitgraph(const Graph& G) // Returns: number of subgraphs
{
	int cnt = 0;
	auto vis = [&cnt](int v) {
		subgraphsize[graphnum[v] = cnt] ++;
	};
	bool* visited = new bool[n];
	// split into subgraphs
	for(int i=0; i<n; i++) visited[i] = false;
	for(int i=0; i<n; i++)
		if(!visited[i])
		{
			bfs(G, i, vis, visited);
			cnt ++;
		}
	delete[] visited;
}

int main(int argc, char** argv)
{
	// Input
	scanf("%d%d%d", &n, &m, &k);
	for(int i=0; i<m; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		friends[--x].push_back(--y);
		friends[y].push_back(x);
	}
	for(int i=0; i<k; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		block[--x].push_back(--y);
		block[y].push_back(x);
	}
	// Split firends into subgraphs
	splitgraph(friends);
	// Count bad (friendships & blockships in current subgraph & itself) for each vertex
	int* badcnt = new int[n];
	for(int i=0; i<n; i++) badcnt[i] = 1; // 1, not 0! (the vertex itself)
	for(int i=0; i<n; i++)
	{
		// Blockship 
		for(int it: block[i])
			if(it > i && graphnum[it] == graphnum[i])
				badcnt[i] ++, badcnt[it] ++;
		// Friendship
		for(int it: friends[i])
			if(it > i && graphnum[it] == graphnum[i])
				badcnt[i] ++, badcnt[it] ++;
	}
	for(int i=0; i<n; i++) printf("%d ", subgraphsize[graphnum[i]] - badcnt[i]);
	putchar('\n');
	delete[] badcnt;
	return 0;
}

Measured memory_bytes: 12872
#include <iostream>
#include <string>
#include <tuple>
#include <vector>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
using namespace std;

vector<pair<int, int> > solve(string const & s_) {
    const int n = s_.size();
    vector<bool> s(n + 1);
    REP (i, n) s[i + 1] = (s_[i] != '0');

    // check
    if (not s[1]) {
        return vector<pair<int, int> >();  // leaves are required
    }
    REP (i, n + 1) {
        if (s[i] != s[n - i]) {
            return vector<pair<int, int> >();  // invariant
        }
    }

    // construct
    vector<pair<int, int> > edges;
    int root = 0;
    int root_size = 1;
    int next = 1;
    REP3 (size, 2, n + 1) if (s[size] or size == n) {
        edges.emplace_back(root, next);
        root = next;
        ++ root_size;
        ++ next;
        while (root_size < size) {
            edges.emplace_back(root, next);
            ++ root_size;
            ++ next;
        }
    }
    return edges;
}

int main() {
    string s; cin >> s;
    auto edges = solve(s);
    if (edges.empty()) {
        cout << -1 << endl;
    } else {
        for (auto edge : edges) {
            int u, v; tie(u, v) = edge;
            cout << u + 1 << ' ' << v + 1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 2420
#include <stdio.h>
    #include <string.h>
    #include <iostream>
    #include <vector>
    #include <deque>
    #include <queue>
    #include <stack>
    #include <map>
    #include <string>
    #include <algorithm>
    #include <numeric>
    #include <utility>
    #include <cmath>
    #define pq priority_queue
     
    using namespace std;
     
    typedef long long ll;
    typedef unsigned int uint;
    typedef unsigned long long ull;
    typedef pair<int, int> pii;
    typedef pair<ll, int> pli;
     
    const int iinf = 1 << 29;
    const long long linf = 1ll << 61;
     
     
    int main(){
      int c[3][3];
      for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
          cin>>c[i][j];
        }
      }
      
      for (int i = 0; i < 2; i++) {
        if(c[i][0]-c[i+1][0]!=c[i][1]-c[i+1][1]||c[i][1]-c[i+1][1]!=c[i][2]-c[i+1][2]){cout<<"No"<<endl;return 0;}
      }
      for (int i = 0; i < 2; i++) {
        if(c[0][i]-c[0][i+1]!=c[1][i]-c[1][i+1]||c[1][i]-c[1][i+1]!=c[2][i]-c[2][i+1]){cout<<"No"<<endl;return 0;}
      }
      cout<<"Yes"<<endl;
      return 0;
    }


Measured memory_bytes: 256
"use strict";

function Main(input) {
  input = input.split("\n");
  var args = input[0].split(" ");
  var sum = 0;
  args.forEach(function (a) {
    sum = sum + Number(a);
  });
  sum == 17 ? console.log("YES") : console.log("NO");
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <map>
#include <stdio.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll MOD = (ll)pow(10.0, 9.0) + 7;
pint dx[4] = { {0, 1}, {0, -1}, {1, 0}, {-1, 0} };
char da[4] = { 'R', 'L', 'D', 'U' };
char dax[4] = { -1, 1, -1, 1 };
char dax2[4] = { 1, -1, 1, -1 };
ll min(ll a, ll b)
{

	return (a < b) ? a : b;
}
ll max(ll a, ll b) { return (a > b) ? a : b; }





vector<ll> V;



vector<ll> calc(int ln, int rn) {
	vector<ll> ret;
	for (int i = 0; i < ln; i++) {
		ret.push_back(V[i]);
	}

	for (int i = V.size() - 1; i > V.size() - 1 - rn; i--) {
		ret.push_back(V[i]);
	}

	return ret;
}


int main() {
	ll n, k;

	cin >> n >> k;

	V.resize(n);

	rep(i, n)
		cin >> V[i];


	vector<ll> q;
	ll ans = -1000000000;
	for (int i = 0; i <= min(n, k); i++) {
		
		for (int j = 0; j <= i; j++) {
			ll sum = 0;
			q = calc(j, i - j);

			sort(q.begin(), q.end());

			for (int l = 0; l < min(q.size(), k - i); l++) {
				if (q[l] < 0) q[l] = 0;
			}

			rep(l, q.size()) {
				sum += q[l];
			}

			ans = max(sum, ans);
		}
	}


	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    string s;
    cin >> s;
    int ans = 0;
    int l = s.size();
    bool check = true;
    rep(i, l - 1) {
        if(s[i + 1] != '9') check = false;
    }
    ans = s[0] - '0' - 1 + 9 * (l - 1);
    if(check) ans++;

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

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


int main()
{
    int n;
    cin>>n;
    int a[n];
    int max=-1;
    set<int> s;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(max<a[i])
            max=a[i];
        s.insert(a[i]);
    }
    long long b[max+1];
    memset(b,0,sizeof(b));
    long long sum=0;
    for(int i=0;i<n;i++)
    {
        b[a[i]]++;
        //cout<<b[i]<<endl;
    }
    for(auto i:s)
    {
        sum+=((b[i])*(b[i]-1))/2;
    }
    for(int i=0;i<n;i++)
    {
        cout<<sum- ((b[a[i]]*(b[a[i]]-1))/2 ) +  (((b[a[i]]-1)*(b[a[i]]-2))/2 )<<endl; 
    }
    return 0;
}


Measured memory_bytes: 9856
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;

vi to[200005];
vi ans;
vi pass;

int dfs(int pos,int p=-1){
    //cout<<"pos:"<<pos<<endl;
    pass[pos]=true;
    for(int i=0;i<to[pos].size();i++){
        if(pass[to[pos][i]]==true)continue;
        ans[to[pos][i]]+=ans[pos];
        dfs(to[pos][i],pos);
    }
    return 0;
}

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

    int n,q;
    cin>>n>>q;
    int a,b;
    rep(i,n-1){
        cin>>a>>b;
        to[a-1].push_back(b-1);
        to[b-1].push_back(a-1);
    }
    int p,x;
    ans.resize(n);
    pass.resize(n,false);
    rep(i,q){
        cin>>p>>x;
        ans[p-1]+=x;
    }
    dfs(0);
    for(int i=0;i<n;i++){
        cout<<ans[i]<<endl;
    }


//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 24320
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
int A[100];
bool F[8];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N) cin >> A[i];
  int free = 0;
  rep(i, N) {
    int x = A[i];
    if (x >= 3200) {
      free++;
      continue;
    }
    if (x < 400) F[0] = true;
    else if (x < 800) F[1] = true;
    else if (x < 1200) F[2] = true;
    else if (x < 1600) F[3] = true;
    else if (x < 2000) F[4] = true;
    else if (x < 2400) F[5] = true;
    else if (x < 2800) F[6] = true;
    else if (x < 3200) F[7] = true;
  }
  int ctr = 0;
  rep(i, 8) ctr += F[i];
  int lo = ctr, hi = ctr;
  if (N == free) lo++;
  hi += free;
  cout << lo << " " << hi << "\n";
  return 0;
}


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

typedef long long ll;
using namespace std;

const ll MOD = 1e9+7;
const ll INF = 1e18+7;

signed main(){
	int n, m;
	cin >> n >> m;
	vector<int> a(m);
	vector<int> d = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
	vector<int> v;
	for(auto& x : a){
		cin >> x;
	}
	sort(a.begin(), a.end());
	for(auto& x : a){
		v.push_back(d[x]);
	}

	/*
	vector<int> vs = v;
	sort(vs.begin(), vs.end());
	 */

	bitset<10007> bs;
	bs.set(0);
	int b = 0;
	for(int i = 0; i < n; ++i){
		bitset<10007> nex;
		for(auto& x : v)
			nex |= bs << x;
		if(nex[n])
			b = i + 1;
		bs = move(nex);
	}

	vector<vector<bitset<10007>>> dp(m + 1, vector<bitset<10007>>(b + 1));
	dp[0][0].set(0);
	for(int i = 0; i < m; ++i){
		for(int j = 0; j < b; ++j){
			dp[i][j + 1] |= dp[i][j] << v[i];
			dp[i + 1][j] |= dp[i][j];
		}
	}
	// 今はm番目までをb回使ってnがtrue
	int now_j = b;
	int now_k = n;
	for(int i = m; i > 0; --i){
		for(int j = 0; j <= now_j; ++j){
			int diff = now_j - j;
			int minus = diff * v[i - 1];
			if(now_k - minus >= 0 && dp[i - 1][j][now_k - minus]){
				for(int k = 0; k < diff; ++k)
					cout << a[i - 1];
				now_j = j;
				now_k -= minus;
				break;
			}
		}
	}

	cout << endl;

}


Measured memory_bytes: 67712
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const ll inf = 1e9;
const int MAX_N = 500;

int main() {
    int n; cin >> n;
    vector<double> a(n);
    rep(i,n) {
        double x; cin >> x;
        x -= (i+1);
        a[i] = x;
    }
    sort(all(a));
    int median = a[n/2];
    ll ans = 0;
    rep(i,n) ans += abs(a[i]-median);
    cout << ans << endl; 
}

Measured memory_bytes: 1792
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;
const LL MOD = 1000000007;

struct modll {
	long long x;
	modll() { }
	modll(long long _x) : x(_x) { }
	operator int() const { return (int)x; }
	modll operator+(const modll& r) { return (x + r.x) % MOD; }
	modll operator+=(const modll& r) { return x = (x + r.x) % MOD; }
	modll operator-(const modll& r) { return (x + MOD - r.x) % MOD; }
	modll operator-=(const modll& r) { return x = (x + MOD - r.x) % MOD; }
	modll operator*(const modll& r) { return (x * r.x) % MOD; }
	modll operator*(int r) { return (x * r) % MOD; }
	modll operator*=(const modll& r) { return x = (x * r.x) % MOD; }
	static modll modinv(int a) { return modpow(a, MOD - 2); }
	static modll modpow(int a, int b) {
		modll x = a, r = 1;
		for (; b; b >>= 1, x *= x) if (b & 1) r *= x;
		return r;
	}
};

int main(int argc, char* argv[]) {
#ifdef _MSC_VER
	while (true)
#endif
	{
		int n = -1;
		cin >> n;
		if (n < 0) return 0;
		vector<LL> a(n);
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
		}
		modll ans = 0;
		for (int b = 0; b < 60; ++b) {
			LL c = (1LL << b);
			int pos = 0, neg = 0;
			for (int i = 0; i < n; ++i) {
				if (a[i] & c) {
					++pos;
				} else {
					++neg;
				}
			}
			if (b > 0) {
				LL d = (c / 2) % MOD;
				for (int i = 0; i < n; ++i) {
					modll e;
					if (a[i] & c) {
						e = neg;
					} else {
						e = pos;
					}
					e *= d;
					ans += e;
				}
			} else {
				for (int i = 0; i < n; ++i) {
					modll e;
					if (a[i] & c) {
						e = neg;
					} else {
						e = pos;
					}
					ans += e;
				}
				ans *= modll::modinv(2);
			}
		}
		cout << ans << endl;
	}
	return 0;
}


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

#define REP(i,s,n) for(int (i)=s; (i)<(int)(n);(i)++)
#define RIT(it,c) for(__typeof(c.begin()) it = c.begin();it!=c.end();it++)
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x).size()
#define MSET(m,v) memset(m,v,sizeof(m))


using namespace std;


typedef long long LL;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<LL> vL;
typedef vector<bool> vb;
typedef pair<int,vi> iv;
typedef pair<LL,LL> pLL; 



int main(){
	string s;
	cin>>s;
	long N = (int)s.size();
	map<char,long> cnt;
	for(auto c:s) cnt[c]++;
	long ans = N*(N-1)/2+1;
	for(auto p:cnt) ans -= p.second*(p.second-1)/2;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#include <bitset>
#include <math.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 10007;
const int INF = LLONG_MAX/3;
const int MAX = 710000;

/*-----Library-----*/

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
    vector<int> sizeuf; //要素数
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n); sizeuf.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            sizeuf[i]=1;
        }
    }

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

    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 (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        sizeuf[x]+=sizeuf[y];
        return true;
    }

    int size(int x){
        return sizeuf[root(x)];
    }
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}

long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*-----Library-----*/
signed main(){
    int n;
    string s;
    cin>>n>>s;
    bool a[10]={};
    bool b[100]={};
    bool c[1000]={};
    for(int i=0;i<n;i++){
        int t=stoi(s.substr(i,1));
        for(int j=0;j<100;j++){
            if(b[j]==true)c[j*10+t]=true;
        }
        for(int j=0;j<10;j++){
            if(a[j]==true)b[j*10+t]=true;
        }
        a[t]=true;
    }
    int ans=0;
    for(int i=0;i<1000;i++)if(c[i])ans++;
    cout<<ans<<endl;
}



Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	m := make(map[rune]int)
	for _, r := range s {
		m[r]++
	}
	for c := 'a'; c <= 'z'; c++ {
		if m[c] == 0 {
			fmt.Printf("%c\n", c)
			break
		}
		if c == 'z' {
			fmt.Println("None")
		}
	}
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
typedef int64_t ll;


int main() {
    int D, T, S;
    cin >> D >> T >> S;
    if (S * T >= D){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3616
#include<iostream>
#include<unordered_map>
#include<string>
#include<set>

using namespace std;

int main(){
  int n;
  cin >> n;
  
  unordered_map<string, int> nameNumMap;
  
  for (int i = 0; i < n; i++){
    string temp;
    cin >> temp;
    if (nameNumMap.find(temp) == nameNumMap.end()){
      nameNumMap.emplace(temp, 1);
    }
    else{
      ++nameNumMap[temp];
    }
  }
  
  int maxNum = 0;
  set<string> nameSet;
  for (auto &nameNum : nameNumMap){
    if (nameNum.second < maxNum) continue;    
    if (nameNum.second > maxNum){
      nameSet.clear();
      maxNum = nameNum.second;
    }
    nameSet.emplace(nameNum.first);
  }
  
  for (auto &name : nameSet){
   cout << name << endl; 
  }
  
  return 0;
}

Measured memory_bytes: 35016
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
using P = pair<ll,ll>;
const int MAX = 510000;
const ll mod = 1e9+7;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i-1] * (ll)i % mod;
    inv[i] = mod - inv[mod%i] * (mod/(ll)i) % mod;
    finv[i] = finv[i-1] * inv[i] % mod;
  }
}

ll COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

int main(){
  int h, w, n;
  cin >> h >> w >> n;
  COMinit();
  vector<P> pos(n+2);
  rep(i,n) cin >> pos[i+1].first >> pos[i+1].second;
  pos[0] = P(1,1); pos[n+1] = P(h,w);
  sort(pos.begin(),pos.end());
  vector<vector<ll>> dp(n+2,vector<ll>(2));
  dp[0][0] = 1;
  rep(i,n+1) {
    for(int j = i+1; j <= n+1; j++) {
      if(pos[i].first <= pos[j].first && pos[i].second <= pos[j].second) {
        ll dx = pos[j].first - pos[i].first;
        ll dy = pos[j].second - pos[i].second;
        (dp[j][1] += dp[i][0] * COM(dx+dy,dx)) %= mod;
        (dp[j][0] += dp[i][1] * COM(dx+dy,dx)) %= mod;
      }
    }
  }
  ll ans = (dp[n+1][1] - dp[n+1][0]) % mod;
  if(ans < 0) ans += mod;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 12416
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,arr1[200040],arr2[200040],ans;
int v1[200040],v2[200040];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++) scanf("%d",arr1+i);
	for(int i=0;i<n;i++) scanf("%d",arr2+i);
	for(int i=0;i<=30;i++)
	{
	    int now=0,s1=0,s2=0;
	    for(int j=0;j<n;j++) if(arr1[j]&(1<<i)) s1^=1;
	    for(int j=0;j<n;j++) if(arr2[j]&(1<<i)) s2^=1;
	    if((s1*(n-s2)+(n-s1)*s2)&1) now^=1;
		for(int j=0;j<n;j++) v1[j]=(arr1[j]&((1<<i)-1));
		for(int j=0;j<n;j++) v2[j]=(arr2[j]&((1<<i)-1));
		//sort(v1,v1+n);
		sort(v2,v2+n);
		ll cnt=0;
		for(int j=0;j<n;j++)
            cnt+=v2+n-lower_bound(v2,v2+n,(1<<i)-v1[j]);
		cnt%=2;
		if(cnt) now^=1;
		ans|=(now<<i);
	} printf("%d",ans);
}


Measured memory_bytes: 3328
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>

using namespace std;
typedef long long ll;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int main() {
    int H, W;
    cin >> H >> W;
    int ch[H][W];
    char c;
    queue<int> q1;
    queue<int> q2;

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> c;
            if (c == '#') {
                q1.push(i);
                q2.push(j);
                ch[i][j] = 0;
            } else {
                ch[i][j] = 3000;
            }
        }
    }

    int m = 0;
    while (q1.empty() == false && q2.empty() == false) {
        int i = q1.front();
        q1.pop();
        int j = q2.front();
        q2.pop();
        for (int k = 0; k < 4; k++) {
            if (0 <= i + dy[k] && i + dy[k] < H && 0 <= j + dx[k] && j + dx[k] < W) {
                if (ch[i][j] + 1 < ch[i + dy[k]][j + dx[k]]) {
                    ch[i + dy[k]][j + dx[k]] = ch[i][j] + 1;
                    q1.push(i + dy[k]);
                    q2.push(j + dx[k]);
                    m = max(m, ch[i][j] + 1);
                }
            }
        }
    }


    cout << m << endl;
    return 0;
}


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

int main() {
  int i=1,n,a;
  cin >> n;
  for (int j=0; j < n; ++j) {
    cin >> a;
    if (i == a) {
      ++i;
    }
  }
  if (i == 1) cout << -1;
  else cout <<  n + 1 - i;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define pll pair <ll, ll>
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define x first
#define y second
#pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
#define plll pair <pair <ll, ll>, ll>
#define pllll pair <pair <ll, ll>, pair <ll, ll> >
#define psl pair <string, ll>
#define pld pair <ld, ld>
#define all(a) a.begin(), a.end()
#define vvl vector <vector <ll> >
#define cld complex <double>

typedef long long ll;

typedef long double ld;

using namespace std;

const ll maxn = 1e6 + 100;

ll n, m, k, t;

vector <ll> V[maxn];

ll to, from;

ll cnt = 0;

void dfs(ll v, ll p) {
    if (v == to) {
        cnt++;
        return;
    }
    if (v == from && p != from) {
        // cout <
        return;
    }
    for (auto v1 : V[v]) {
        if (v1 == p) {
            continue;
        }
        dfs(v1, v);
    }
}

int main() {
    pyshnapyshnakaa
    ll q, w, e, a, b, c;
    cin >> n >> m;
    for (q = 0; q < m; q++) {
        cin >> a >> b;
        a--; b--;
        V[a].pb(b);
        V[b].pb(a);
    }
    // ll overkill = 0;
    for (q = 0; q < n; q++) {
        if (V[q].size() % 2 == 1) {
            cout << "No";
            return 0;
        }
        // overkill += (V[q].size() - 2) / 2;
    }
    vector <ll> fours;
    for (q = 0; q < n; q++) {
        if (V[q].size() == 4) {
            fours.pb(q);
        }
        if (V[q].size() >= 6) {
            cout << "Yes";
            return 0;
        }
    }
    if (fours.size() >= 3) {
        cout << "Yes";
        return 0;
    }
    if (fours.size() < 2) {
        cout << "No";
        return 0;
    }
    if (fours.size() == 2) {
        to = fours[1];
        from = fours[0];
        dfs(fours[0], fours[0]);
        // cout << to + 1 << endl;
        // cout << "CNT " << cnt << endl;
        if (cnt == 2) {
            cout << "Yes";
        }
        else {
            cout << "No";
        }
        return 0;
    }
    return 0;
}


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

using namespace std;

int main()
{
    int N , L ;
    cin >> N >> L ;
    vector <string> S ;
    int i ;
    for(i=0 ; i<N ; i++)
    {
        string s ;
        cin >> s ;
        S.push_back(s) ;
    }

    sort(S.begin() , S.end()) ;

    string a = S.at(0) ;

    for (i=1 ;  i<N ; i++)
    {
        a = a + S.at(i) ;
    }

    cout << a ;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<unordered_map>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define PI 3.141592653589793

using namespace std;
using ll = unsigned long long;


int main() {

	int x[5];
	rep(i, 5) {
		cin >> x[i];
		if (x[i] == 0) {
			cout << i + 1 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3588
H1,M1,H2,M2,K = map(int, input().split(' '))

#print(H1,M1,H2,M2,K)

# 開始時刻から終了時刻までの長さを分に変換し、勉強時間を減産する

start = (H1 * 60) + M1
end = (H2 * 60) + M2

#print("{0}分から{1}分まで勉強する".format(start, end))

goal = end - start - K

print(goal)

Measured memory_bytes: 9168
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    map<int,int> mp;
    int N;cin>>N;
    int A;
    for(int i=0;i<N;i++){
        cin>>A;
        mp[A]++;
    }
    int ans=0;
    for(auto itr=mp.begin();itr!=mp.end();itr++)
        if(itr->second%2==1)ans++;
    cout<<ans<<endl;
    return 0;
    
}

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

int main() {
	int n, m;
	while (cin >> n >> m, n || m) {
		vector<int>v;
		v.push_back(0);
		rep(i, n + m) {
			int a; cin >> a;
			v.push_back(a);
		}
		sort(v.begin(), v.end());
		vector<int>ans;
		rep(i, n + m) {
			ans.push_back(v[i + 1] - v[i]);
		}
		sort(ans.begin(), ans.end(), greater<>());
		cout << ans[0] << endl;
	}
}

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

bool datalist[51][31];

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){
			break;
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<30;j++){
				datalist[i][j] = false;
			}
		}

		for(int i=0;i<n;i++){
			int c;
			cin >> c;
			for(int j=0;j<c;j++){
				int buf;
				cin >> buf;
				datalist[i][buf-1] = true;
			}
		}

		vector<vector<int> > memo;
		for(int i=0;i<n;i++){
			vector<int> buf;
			buf.push_back(i);
			memo.push_back(buf);
		}

		int ans = 31;
		for(int day=0;day<30;day++){
			set<int> s;
			for(int i=0;i<n;i++){
				if(datalist[i][day]){
					for(int j=0;j<memo[i].size();j++){
						s.insert(memo[i][j]);
					}
				}
			}
			if(s.size() == n){
				ans = day+1;
				break;
			}
			vector<int> buf(s.begin(),s.end());
			for(int i=0;i<n;i++){
				if(datalist[i][day]){
					memo[i] = buf;
				}
			}
		}
		if(ans == 31){
			cout << -1 << endl;
		}else{
			cout << ans << endl;
		}
	}
}

Measured memory_bytes: 1244
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

P = [i + a for i, a in enumerate(A, start=1)]
Q = [j - a for j, a in enumerate(A, start=1)]

ans = 0
QC = Counter(Q)
for p in P:
    ans += QC[p]

print(ans)


Measured memory_bytes: 50780
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define int long long
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int N;
    cin >> N;
    string ans = "No";

    while(N >= 0){
        if(N % 4 == 0) ans = "Yes";
        N -= 7;
    }

    cout << ans;

    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

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

int main() {
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A), b(B);
    for (int i = 0; i < A; i++) cin >> a.at(i); 
    for (int i = 0; i < B; i++) cin >> b.at(i);

    int minA = *min_element(a.begin(), a.end()); int minB = *min_element(b.begin(), b.end());
    int res = minA + minB;
    for (int i = 0; i < M; i++) {
        int x, y, c;
        cin >> x >> y >> c; x--; y--;
        res = min(res, a.at(x) + b.at(y) - c);
    }
    cout << res << endl;
}


Measured memory_bytes: 3972
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	cout<<(a%3==0||b%3==0||(a+b)%3==0?"Possible":"Impossible")<<endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    int N, M;
    cin >> N >> M;

    vi c(N);
    rep(i, M)
    {
        int a, b;
        cin >> a >> b;
        c[--a]++;
        c[--b]++;
    }

    for (auto x : c)
    {
        if (x % 2 != 0)
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 640
a, b, k = map(int, input().split())

if (a, b, k) == (1, 1, 1):
    print(1)
    exit(0)

cnt = 0
for i in range(max(a,b), -1, -1):
    if a%i==0 and b%i==0:
        cnt+=1
    if cnt==k:
        break
print(i)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

struct node{
    int id;
    node* left; node* right;
    node() : id(-1),left(nullptr),right(nullptr){}
};

string s;

int num(int& pos){
    string res;
    while(isdigit(s[pos])){
        res.pb(s[pos]);
        pos++;
    }
    return stoi(res);
}

node* expr(int& pos);

node* term(int& pos){
    pos++;
    node* res = expr(pos);
    pos++;
    return res;
}

node* expr(int& pos){
    if(s[pos] == ')'){
        return nullptr;
    }
    node* mid = new node;
    mid->left = term(pos);
    pos++;
    mid->id = num(pos);
    pos++;
    mid->right = term(pos);
    return mid;
}

string dfs(node* n1,node* n2)
{
    string res;
    res.pb('(');
    if(n1->left && n2->left){
        res += dfs(n1->left,n2->left);
    }
    res.pb(')');
    res.pb('[');
    stringstream ss;
    ss << (n1->id+n2->id);
    res += ss.str();
    res.pb(']');
    res.pb('(');
    if(n1->right && n2->right){
        res += dfs(n1->right,n2->right);
    }
    res.pb(')');
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    int pos = 0;
    node* r1 = expr(pos);
    cin >> s;
    pos = 0;
    node* r2 = expr(pos);
    cout << dfs(r1,r2) << "\n";
    return 0;
}

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int> a;
	for(int i=0;i<n;i++){
		int x;cin>>x;
		a.push_back(x);
	}
	sort(a.begin(),a.end());
	int x=n/2;
	cout<<a[x]-a[x-1]<<endl;
	return 0;
}


Measured memory_bytes: 892
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		List answer = new ArrayList<String>();

		for (char s : S.toCharArray()) {
			if (s == '0') answer.add("0");
			if (s == '1') answer.add("1");
			if (s == 'B' && answer.size() != 0) answer.remove(answer.size() - 1);
		}

		System.out.println(String.join("", answer));
	}
}


Measured memory_bytes: 21588
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
#include <iomanip>
#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1844674407370955161
typedef long long int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007
 
 
 
int main()
{
    int N;
    cin >> N;
    ll A[N], B[N];
 
    priority_queue<pair<ll, int> > p;
    REP(i,0,N){
        cin >> A[i];
    }
    REP(i,0,N){
        cin >> B[i];
    }
    REP(i, 0, N)
    {
        if(A[i]>B[i]){
            cout << -1 << endl;
            return 0;
        }else if(B[i]>A[i]){
            p.push(make_pair(B[i], i));
        }
    }
    ll ans = 0;
 
 
    while(!p.empty()){
        pair<ll, int> t = p.top();
        p.pop();
        int idx = t.second;
        ll a, b, c;
        if (idx == 0)
        {
            a = B[N - 1];
            b = B[0];
            c = B[1];
        }else if(idx==N-1){
            a = B[N - 2];
            b = B[N-1];
            c = B[0];
        }else{
            a = B[idx - 1];
            b = B[idx];
            c = B[idx+1];
        }
 
        t = p.top();
        ll base = t.first;
        ll s = (B[idx] - A[idx]) / (a + c);
        if(s==0){
            s = 1;
        }
        B[idx] = B[idx] - s*a - s*c;
        ans += s;
        if (B[idx] > A[idx])
        {
            p.push(make_pair(B[idx], idx));
        }else if(B[idx]<A[idx]){
            cout << -1 << endl;
            return 0;
        }
        //ans++;
    }
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 9584
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000
const int mod = INF+7;

int gcd(int a, int b){
  if(a<b){
    int temp=a;
    a=b;
    b=temp;
  }
  int c;
  while(a%b!=0){
    c=a%b;
    a=b;
    b=c;
  }
  return b;
}

long lcm(int a, int b){
  int g=gcd(a,b);
  return (long)a*b/g;
}

int main(){
  char buf[1024];
  long A,B;
  int C,D;

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%ld %ld %d %d", &A, &B, &C, &D);

  long divc,divd,divcd;

  divc=B/C-(A-1)/C;
  divd=B/D-(A-1)/D;
  divcd=B/lcm(C,D)-(A-1)/lcm(C,D);

  long ans=B-A+1-(divc+divd-divcd);

  printf("%ld\n", ans);

  return 0;
}


Measured memory_bytes: 128
!!!**********************************************************************
program main
!!!**********************************************************************

  implicit none

  integer :: K, X, i

!!!----------------------------------------------------------------------

  read ( *, * ) K, X

  do i = X - K + 1, X + K - 1
  
     write ( unit = *, fmt = '(i0)', advance =  'no' ) i

     write ( unit = *, fmt = '(a1)', advance =  'no' ) ' '     
     
  end do


!!!**********************************************************************  
end program main
!!!**********************************************************************


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

void solve(){
	
	int v,e,l ;
	cin>>v>>e>>l ;

	vector<vector<int>> dist(v,vector<int>(v,mod)) ;
	
	rep(i,e){
		int a,b,c ;
		cin>>a>>b>>c ;
		a-- ;
		b-- ;

		dist[a][b]=dist[b][a]=c ;
		dist[a][a]=0 ;
		dist[b][b]=0 ;
	}

	rep(k,v){
		rep(i,v){
			rep(j,v){
				dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
			}
		}
	}

	vector<vector<int>> dist2(v,vector<int>(v,mod)) ;

	rep(i,v){
		rep(j,v){
			if(dist[i][j]<=l)
				dist2[i][j]=1 ;
		}
	}

	rep(k,v){
		rep(i,v){
			rep(j,v){
				dist2[i][j]=min(dist2[i][j],dist2[i][k]+dist2[k][j]) ;
			}
		}
	}

	int q ;
	cin>>q ;

	rep(i,q){

		int s,t ;
		cin>>s>>t ;
		s-- ;
		t-- ;

		if(dist2[s][t]==mod){
			cout<<-1<<"\n" ;
		}else{
			cout<<dist2[s][t]-1<<"\n" ;
		}
	}
	
	/*
	rep(i,v){
		rep(j,v){
			cout<<dist[i][j]<<" " ;
		}
		cout<<"\n" ;
	}

	rep(i,v){
		rep(j,v){
			cout<<dist2[i][j]<<" " ;
		}
		cout<<"\n" ;
	}
	*/

}

int main(){

	
	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{	
		solve() ;
	}

}

Measured memory_bytes: 4248
#-*- coding: utf-8 -*-
"""
oj dl https://atcoder.jp/contests/abc116/tasks/abc116_d -d test-d
oj test -d test-d -c "python abc116d.py"
oj test -d test-d -c "python abc116d.py" test-d/sample-3.in
"""
from collections import defaultdict
import sys
import math
from datetime import datetime
import re


def sol_lte(n, S):
    maxi = 0

    for i in range(n):
        tmp = 0
        for j in range(i, n):
            if j + 1 <= n -1:
                if S[j+1] <= S[j]:
                    tmp += 1
                else:
                    break
        maxi = max(maxi, tmp)
    return maxi


def sol(n, S):
    maxi = 0 # steps
    tmp = 0
    for i in range(1, n):
        if S[i] <= S[i-1]:
            tmp += 1
            maxi = max(maxi, tmp)
        else:
            tmp = 0

    return maxi


do_submit = True
#do_submit = False

def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(str, line.split())) for line in lines]
    #print(parsed_lines)
    n = int(parsed_lines[0][0])
    k = int(parsed_lines[0][1])
    #S = parsed_lines[0][0]
    return n, k


if not do_submit:
    n, k = input_parse("""
    5
10 4 8 7 3
    """)
    print(sol(n, k))

    n, k = input_parse("""
    100000 5
    """)
    print(sol(n, k))


else:
    n = int(input().strip())
    S = list(map(int, input().split()))
    #S = input()
    print(sol(n, S))

    # S = input().strip()
    # print(sol(S))





Measured memory_bytes: 15156
#include<stdio.h>
#include<stdlib.h>

int main(void){
	int i, m, n, card[52];
	char suit;
	for(i=0; i<52; i++)
		card[i]=1;
	
	scanf("%d",&n);
	for(i=0; i<n; i++){
		scanf(" %c %d",&suit,&m);
		switch(suit){
			case 'S':
			card[ 0*13 + m-1 ] = 0;
			break;
			case 'H':
			card[ 1*13 + m-1 ] = 0;
			break;
			case 'C':
			card[ 2*13 + m-1 ] = 0;
			break;
			case 'D':
			card[ 3*13 + m-1 ] = 0;
			break;
		}
	}
	for(i=0; i<52; i++){
		if(card[i]==1){
			switch(i/13){
				case 0:
				printf("S %d\n",i%13+1);
				break;
				case 1:
				printf("H %d\n",i%13+1);
				break;
				case 2:
				printf("C %d\n",i%13+1);
				break;
				case 3:
				printf("D %d\n",i%13+1);
				break;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> ps(n);
  for(Int i=0;i<n;i++) cin>>ps[i],ps[i]--;

  Int cnt=0;
  for(Int i=0;i<n;i++)
    if(i!=ps[i]) cnt++;

  cout<<(cnt<=2?"YES":"NO")<<endl;
  return 0;
}


Measured memory_bytes: 256