akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

int n, q;
string s;

int get(int idx, vector<pair<char, int> >& r) {
	rep(i,0,q) {
		if(s[idx] == r[i].F) {
			idx += r[i].S;
		}
		if(idx < 0 || idx >= n) return idx;
	}
	return idx;
}

int solve(vector<pair<char, int> >& r) {
	int ret = 0;
	int low = 0;
	int hig = n;
	while(low<hig) {
		int mid = (low+hig) / 2 + 1;
		if(get(mid,r) == -1) {
			low = mid;
		} else {
			hig = mid-1;
		}
	}
	if(get(low,r) == -1) {
		ret += (low + 1);
	}
	low = 0;
	hig = n;
	while(low<hig) {
		int mid = (low+hig)/2;
		if(get(mid,r) == n) {
			hig = mid;
		} else {
			low = mid+1;
		}
	}
	ret += (n - low);
	return n - ret;
}

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	cin >> n >> q;
	cin >> s;
	vector<pair<char, int> > r(q);
	rep(i,0,q) {
		char t, d;
		cin >> t >> d;
		if(d == 'R') {
			r[i] = mp(t,1);
		} else {
			r[i] = mp(t,-1);
		}
	}
	cout << solve(r) << '\n';
	return 0;
}


Measured memory_bytes: 2196
#include<bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
long long power(int m,int n){
	long long res=1,mm=m;
	while(n){
		if(n & 1)res=(res*mm)%MOD;
		mm=(mm*mm)%MOD;
		n>>=1;
	}
	return res;
}
int main(){
	int m,n;
	cin>>m>>n;
	cout<<power(m,n)<<endl;
}


Measured memory_bytes: 3116
N = int(input())
A = list(map(int, input().split()))

suma = sum(A)
tmp = 0
ans = [0] * N
for i in range(N):
    if i % 2 == 0:
        tmp += A[i]
ans[0] = (tmp*2) - suma
for i in range(N-1):
    ans[i+1] = (A[i] - (ans[i]//2))*2
print(" ".join(map(str, ans)))


Measured memory_bytes: 19172
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mpr make_pair
#define fi first
#define se second
#define pq priority_queue<int>
#define pqll priority_queue<ll>
#define up(x,y) (x<(y)?x=(y):0)
#define dn(x,y) (x>(y)?x=(y):0)
#define ad(x,y) (x=(x+(y))%mod)
using namespace std;

int n,m,a[1009]; ll s[1009];
int calc(ll tmp){
	int i,j,ans=0;
	for (i=1; i<=n; i++)
		for (j=i; j<=n; j++) if ((s[j]-s[i-1]&tmp)==tmp) ans++;
	//cerr<<tmp<<' '<<ans<<'\n';
	return ans;	
}
int main(){
	scanf("%d%d",&n,&m);
	int i;
	for (i=1; i<=n; i++){
		scanf("%d",&a[i]); s[i]=s[i-1]+a[i];
	}
	ll ans=0;
	for (i=60; i>=0; i--)
		if (calc(ans|1ll<<i)>=m) ans|=1ll<<i;
	printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int  
ll n,ar[100005][3],dp[100005][4];
ll call(ll i,ll last)
{
	if(dp[i][last]!=-1) return dp[i][last];
	if(i>n-1) return 0;
	ll maxa=-1;
	for(int j=0;j<3;j++)
	{
		if(j==last) continue;
		if(j==0)
			maxa=max((ar[i][j]+call(i+1,0)),maxa);
		if(j==1)
                        maxa=max((ar[i][j]+call(i+1,1)),maxa);
		if(j==2)
                        maxa=max((ar[i][j]+call(i+1,2)),maxa);
	}
	dp[i][last]=maxa;
	return maxa;
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		dp[i][0]=-1;
		for(int j=0;j<3;j++)
		{
			cin>>ar[i][j];
			dp[i][j+1]=-1;
		}
	}
	ll ans=call(0,3);
	cout<<ans<<endl;
}


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

int GCD(int m, int n){
  while(m!=n){
    if(m>n) m-=n;
    else n-=m;
  }
  return m;
}

int LCM(int m, int n){
  return m/GCD(m, n)*n;
}

int main(){
  int a, b;
  
  while(cin>>a>>b){
    cout<<GCD(a, b)<<" "<<LCM(a, b)<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3096
#include <cstdio>
int n,tmp,min=0x7fffffff,max=0x80000000;
int main(){
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d",&tmp);
		if(max < tmp-min) max = tmp - min;
		if(min > tmp) min = tmp;
	}
	printf("%d\n",max);
	return 0;
}


Measured memory_bytes: 2764
from collections import deque
from itertools import product
import itertools

def dfs(w, h, graph):
    visited = [[0] * w for _ in range(h)]
    dy_dx = [(0, 0), (0, 1), (0, -1), (1, 1), (1, -1), (1, 0), (-1, 1), (-1, -1), (-1, 0)]
    dots = itertools.product(range(h), range(w))
    count = 0
    for dot in dots:
        dot_y, dot_x = dot
        if graph[dot_y][dot_x] == 0:
            continue
        if visited[dot_y][dot_x] == 1:
            continue

        q = deque()
        q.append((dot_y, dot_x))
        while q:
            move_y, move_x = q.pop()

            for delta in dy_dx:
                dy, dx = delta

                moved_x = move_x + dx
                moved_y = move_y + dy

                if moved_y < 0 or h -1 < moved_y or moved_x < 0 or w -1 < moved_x:
                    continue
                if graph[moved_y][moved_x] == 0:
                    continue
                if visited[moved_y][moved_x] == 0:
                    q.append((moved_y, moved_x))
                    visited[moved_y][moved_x] = 1
        
        count += 1

    return count

if __name__ == "__main__":

    answer_list = []
    while True:
        w, h = map(int, input().split())
        if w == 0 and h == 0:
            break

        graph = [list(map(int, input().split())) for _ in range(h)]
        answer_list.append(dfs(w, h, graph))
    
    for answer in answer_list:
        print(answer)


Measured memory_bytes: 6020
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//-------------------------------------------------------
struct SegTree {
	int sz;
	vector<long> X;
	SegTree(int N){
		sz = 1;
		while(sz < N) sz <<= 1;
		//初期値代入
		X.assign(2*sz,0);
	}
	long f(long a,long b){
		return max(a,b);
	}
  	void Set(int k,const long x){
    	X[k+sz] = x;
  	}
  	void Build(){
    	for(int k=sz-1;k>0;k--){
      		X[k] = f(X[2*k],X[2*k+1]);
    	}
  	}
  	void Update(int k,const long x){
    	k += sz;
    	X[k] = x;
    	while(k >>= 1){
      		X[k] = f(X[2*k+0],X[2*k+1]);
    	}
  	}
  	long Query(int a,int b){
    	long L = 0, R = 0;
    	for(a += sz,b += sz+1;a < b;a >>= 1,b >>= 1){
      		if(a & 1) L = f(L,X[a++]);
      		if(b & 1) R = f(X[--b],R);
    	}
    	return f(L,R);
  	}
}; 
int H[200000];
long A[200000];
void Calc(){
	int N = rei();
	for(int i=0;i<N;i++){
		H[i] = rei()-1;
	}
	for(int i=0;i<N;i++){
		A[i] = rel();
	}
	SegTree Seg(N);
	long ans = 0;
	for(int i=0;i<N;i++){
		long t = Seg.Query(0,H[i]) + A[i];
		ans = max(ans,t);
		Seg.Update(H[i],t);
	}
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 6656
package main

import "fmt"

func gcd(a, b int64) int64 {
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func factors(n int64) map[int64]int {
	ret := make(map[int64]int)
	x := n
	for i := int64(2); i*i <= n; i++ {
		for x%i == 0 {
			ret[i]++
			x /= i
		}
	}
	if x != 0 {
		ret[x]++
	}
	return ret
}

func main() {
	var a, b int64
	fmt.Scan(&a, &b)
	f := factors(gcd(a, b))
	f[1] = 1
	ans := 0
	for range f {
		ans++
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <sys/time.h>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>

using namespace std;

using ll = long long;
using P = pair<double, double>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
ll mod = 1000000007LL;

//  S o: 左右がW W or S S; x;　W　S　or 　S　W 
//  S o: 

string solve(string& s, char c0, char c1) {
	int n = s.size();
	string ans(n,' ');
	ans[0] = c0;
	ans[1] = c1;
	for(int i = 2; i < n; i++) {

		bool is_same = (s[i - 1] == 'o');
		//cout << "i:" << i << " is_same:" << is_same << endl;

		if (ans[i - 1] == 'W') {
			is_same = !is_same;
		}
		//cout << "i:" << i << " is_same:" << is_same << endl;


		if (is_same) {
			ans[i] = ans[i - 2];

		} else {
			ans[i] = ans[i - 2] == 'W' ? 'S' : 'W'; 
		}
	}

	// i == 0

	bool is_same0 = s[n - 1] == 'o';
	if (ans[n - 1] == 'W') {
		is_same0 = !is_same0;
	}
	if ((ans[0] == ans[n - 2]) != is_same0) {
		return "";
	}

	// i == 1
	bool is_same1 = s[0] == 'o';
	if (ans[0] == 'W') {
		is_same1 = !is_same1;
	}
	if ((ans[1] == ans[n - 1]) != is_same1) {
		return "";
	}

	return ans;
}

int main() {
	int n;
	string s;
	cin >> n >> s;


	string ans = solve(s, 'S', 'S' );
	if (ans != "") {
		cout << ans << endl;
		return 0;
	}
	ans = solve(s, 'W', 'W' );
	if (ans != "") {
		cout << ans << endl;
		return 0;
	}
	ans = solve(s, 'W', 'S' );
	if (ans != "") {
		cout << ans << endl;
		return 0;
	}
	ans = solve(s, 'S', 'W' );
	if (ans != "") {
		cout << ans << endl;
		return 0;
	}

	cout << -1 << endl;



	return 0;
}


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

int main() {
    int n; cin >> n;
    int a[100];
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    double ave = (double)sum / n;
    //cout << ave << endl;
    int ansn = a[0];
    for (int i = 1; i < n; i++) {
        if (abs(a[i] - ave) < abs(ansn - ave) ) ansn = a[i];
        //cout << abs(a[i] - ave) << endl;
    }
    for (int i = 0; i < n; i++) {
        if (a[i] == ansn) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
int a, b, c;
scanf("%d %d %d\n", &a, &b, &c);
if (a<=b&&b<=c)
	printf("%d %d %d\n", a, b, c);
else if (a<=c&&c<=b)
	printf("%d %d %d\n", a, c, b);
else if (b<=a&&a<=c)
	printf("%d %d %d\n", b, a, c);
else if (b<=c&&c<=a)
	printf("%d %d %d\n", b, c, a);
else if (c<=a&&a<=b)
	printf("%d %d %d\n", c, a, b);
else if (c<=b&&b<=a)
	printf("%d %d %d\n", c, b, a);
return 0;
}

Measured memory_bytes: 2728
#include <iostream>

using namespace std;

int main() {
    int N;
    int V[50];
    int C[50];
    int out = 0;
    cin >> N;
    for (int i=0; i<N; i++) {
        scanf("%d", &V[i]);
    }
    for (int i=0; i<N; i++) {
        scanf("%d", &C[i]);
    }
    for (int i=0; i<N; i++) {
        if (V[i]-C[i]>0) {
            out += V[i]-C[i];
        }
    }
    printf("%d", out);
    return 0;
}

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

using namespace std;

int Dis[3];

void Set_Movable(int ind) {
	if (ind%4 == 0) {
		Dis[0] = -1;
		Dis[1] = ind+1;
	}
	else if (ind%4 == 3) {
		Dis[0] = ind-1;
		Dis[1] = -1;
	}
	else {
		Dis[0] = ind-1;
		Dis[1] = ind+1;
	}
	Dis[2] = (ind+4)%8;
}

int main(void) {
	map<string,int> all_data;
	queue<string> puzz;
	queue<int> index;
	queue<int> deep;
	puzz.push("01234567");
	index.push(0);
	deep.push(0);
	int ind,d;
	string str;
	string temp;
	while (!puzz.empty()) {
		str = puzz.front();
		ind = index.front();
		d = deep.front();
		Set_Movable(ind);
		puzz.pop();
		index.pop();
		deep.pop();
		for (int i = 0; i < 3; ++i) {
			temp = str;
			if (Dis[i] >= 0) {
				swap(temp[ind],temp[Dis[i]]);
				if (all_data[temp] == 0 && temp != "01234567") {
					all_data[temp] = d + 1;
					puzz.push(temp);
					index.push(Dis[i]);
					deep.push(d + 1);
				}
			}
		}
	}
	while (getline(cin,temp)) {
		string str = "";
		for (int i = 0; i < 8; ++i) {
			str += temp[2*i];
		}
		cout << all_data[str] << endl;
	}
	return 0;
}

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

/*
   AtCoder contest code
   coder : yoichidon
 */
import java.util.*;
import java.io.*;

public class Main {
    public static boolean isKeyence(String S){
        final String keyence = "keyence";
        for(int i=0; i<keyence.length(); i++){
            if(S.startsWith(keyence.substring(0,i)) && S.endsWith(keyence.substring(i,keyence.length()))) return true;
        }
        return false;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        if(isKeyence(S)) System.out.println("YES");
        else System.out.println("NO");

    }
}


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

int main() {
    int a,b,c;
    cin >>a>>b>>c;
    if (a<=b&&b<=c) {
      cout << a<<" "<< b<<" "<< c << endl;
      }else if (c<=a&&a<=b) {
       cout << c<<" "<< a<< " "<< b << endl;
    } else if(c<=b&&b<=a){
      cout << c<<" "<< b<<" "<< a << endl;
    } else if(a<=c&&c<=b) {
    cout << a<<" "<< c<<" "<< b << endl;
} else if(b<=a&&a<=c){
      cout << b<<" " << a<<" "<< c <<endl;
 } else {
  cout << b<<" "<< c<<" "<< a<< endl;
 }  
   return 0;
    }


Measured memory_bytes: 3076
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;

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

typedef vector<int> vi;

int main()
{
	stack<int> train;

	int n;
	while(scanf("%d", &n) != EOF){
		if(n)
			train.push(n);
		else{
			printf("%d\n", train.top());
			train.pop();
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)

int c[3][3];

void solve() {
    int a[3], b[3];
    a[0] = 0, b[0] = c[0][0], b[1] = c[0][1], b[2] = c[0][2];
    a[1] = c[1][0] - b[0], a[2] = c[2][0] - b[0];
    REP(i, 3)REP(j, 3) if (a[i] + b[j] != c[i][j]) {
                cout << "No" << endl;
                return;
            }
    cout << "Yes" << endl;
}

int main() {
    REP(i, 3)REP(j, 3) cin >> c[i][j];
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll n, m;
vl visited;

void dfs(const vvl &G, ll v) {
    // 行きの処理はこのへんに書く
    visited[v] = 1;
    rep(u, n) {
        if(visited[u]) {
            continue;
        }
        if(G[v][u]) {
            dfs(G, u);
        }
    }
}

int main() {
    
    cin >> n >> m;    
    
    vvl G(n, vl(n));
    vl a(m), b(m);
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--;  b[i]--;
        G[a[i]][b[i]] = G[b[i]][a[i]] = 1;
    }

    ll ans = 0;
    rep(i, m) {
        G[a[i]][b[i]] = G[b[i]][a[i]] = 0;
        visited.assign(n, 0);
        dfs(G, 0);
        bool ok = false;
        rep(v, n) {
            if(!visited[v]) {
                ok = true;
            }
        }
        if(ok) {
            ans++;
        }
        G[a[i]][b[i]] = G[b[i]][a[i]] = 1;
    }

    out(ans);
    re0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int dy[4]={1,0,-1,0};
int dx[4]={0,1,0,-1};
vector<vector<int>> graph;

bool sort_sec(const pair<int,int> &a,const pair<int,int> &b){
   if(a.second<b.second){
      return true;
   }
   return false;
}

void swap(int *a,int *b){
   int temp=*a;
   *a=*b;
   *b=temp;
}

int main(void){
   int R,G,B,N;
   cin>>R>>G>>B>>N;
   long long ans=0;
   for(int i=0;i<=3000;i++){
      for(int j=0;j<=3000;j++){
         int temp=N-R*i-G*j;
         if(0<=temp&&temp%B==0) ans++;
      }
   }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    string s;
    cin >> s;

    int cnt = 0;
    char c = s[0];
    for(int i=0; i<s.length(); i++){
        if(s[i] == c) continue;
        c = s[i];
        cnt++;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 512
//Utkarsh.25dec
#include <bits/stdc++.h>
#define ll long long int 
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
using namespace std;
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll h,w;
    cin>>h>>w;
    ll a,b;
    cin>>a>>b;
    for(int i=1;i<=b;i++)
    {
        for(int j=1;j<=a;j++)
            cout<<0;
        for(int j=a+1;j<=w;j++)
            cout<<1;
        cout<<'\n';    
    }
    for(int i=b+1;i<=h;i++)
    {
        for(int j=1;j<=a;j++)
            cout<<1;
        for(int j=a+1;j<=w;j++)
            cout<<0;
        cout<<'\n';    
    }
}
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
}

Measured memory_bytes: 13056
#include<bits/stdc++.h> 
using namespace std; 
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define forp(i,a,b) for (int i = a; i <b; i++)
#define forn(i,a,b) for (int i = a; i >b; i--)
#define mod 1000000007
#define multiple_testcases_t int t;cin>>t;while(t--){solve();}
#define single_testcase_t solve();
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;


ll fact(ll n)
{
  if(n==0 || n==1)
  return 1;
  else
  return (n*fact(n-1)%mod)%mod;
}

int prime(ll n)
{
  for(int i=2;i<=sqrt(n);i++)
  {
    if(n%i==0)
    {
      return 0;
    }
  }
  return 1;
}

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

ll lcm(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}

int check_palin(string s)
{
  string str=s;
  reverse(str.begin(),str.end());
  if(str==s)
  return 1;
  else 
  return 0;
}

vector<ll> divisors(ll n)
{
  vector<ll> v;
  for(int i=2;i<=sqrt(n);i++)
  {
    if(n%i==0)
    {
      if(i==n/i)
      v.PB(i);
      else
      v.PB(i),v.PB(n/i);
    }
  }
return v;
}

ll bin_expo(int x,int n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_expo(x*x,n/2);
    else                             //n is odd
        return x*bin_expo(x*x,(n-1)/2);
}

ll modular_expo(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return modular_expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*modular_expo((x*x)%M,(n-1)/2,M))%M;
}

ll kadane_algo(int a[],int n)
{
   ll max_so_far=0,max_ending_here=0;
   forp(i,0,n)
   {
     max_ending_here+=a[i];
     if(max_ending_here<0)
     max_ending_here=0;
     
     if(max_ending_here>max_so_far)
     max_so_far=max_ending_here;
   }

   return max_so_far;
}

// <----- Actual solve() function to print output -----> //
void solve()
{
  ll n,z=0,k=0;
  cin>>n;
  
  int a[n];
  forp(i,0,n)
  {
       cin>>a[i];
  }
  sort(a,a+n);
  k=n-2;
  z=a[n-1];
  forn(i,n-2,-1)
  {
     if(k==0)
     break;
     else
     {
       z+=a[i];
       k--;
       if(k==0)
       break;
       z+=a[i];
       k--;
     }
  }
  cout<<z;
  //cout<<"\n";      //if t>1 uncomment this
}

// MAIN function --------------------------------------------------------------------------//
int main()
{
    fast_io
    single_testcase_t   //Uncomment this if only single testcase & single answer to print
  //  multiple_testcases_t  //Uncomment this if t>1(t is given in question)(multiple testcases)      
return 0;
}
            
            
            
            

Measured memory_bytes: 4396
#include <cstdio>

int N, M, P;
int cnt[10][10];
int ball[10][10][10], t[10][10][10];

int max(int a, int b){return (a>b)?a:b;}
const int dirs = 13;
const int dx[] = {1, 0, 0, 1, 1, 0, 1,  1,  1,  0,  1,  1, -1};
const int dy[] = {0, 1, 0, 1, 0, 1, 1, -1,  0,  1,  1, -1,  1};
const int dz[] = {0, 0, 1, 0, 1, 1, 1,  0, -1, -1, -1,  1,  1};

int FindLine(){
    for(int i=1;i<=P;i++){
        int x, y, z;
        scanf("%d %d", &x, &y); z=++cnt[x][y];
        ball[x][y][z] = (i%2)+1;
        t[x][y][z] = i;
    }
    int MIN = -1;
    for(int x=1;x<=N;x++){
        for(int y=1;y<=N;y++){
            for(int z=1;z<=N;z++){
                if(ball[x][y][z]==0) continue;
                for(int d=0 ; d<=dirs ; d++){
                    bool flag = true;
                    int maxt = t[x][y][z];
                    for(int k=0;k<M;k++){
                        int nx = x+dx[d]*k;
                        int ny = y+dy[d]*k;
                        int nz = z+dz[d]*k;
                        if(nx<1 || N<nx) {flag=false; break;}
                        if(ny<1 || N<ny) {flag=false; break;}
                        if(nz<1 || N<nz) {flag=false; break;}
                        if(ball[x][y][z] != ball[nx][ny][nz]) {flag=false; break;}
                        maxt = max(maxt, t[nx][ny][nz]);
                    }
                    if(!flag) continue;
                    if(MIN==-1 || MIN>maxt) MIN = maxt;
                }
            }
        }
    }
    return MIN;
}

int main(){
    while(scanf("%d %d %d", &N, &M, &P) && N){
        for(int i=0;i<=N;i++){
            for(int j=0;j<=N;j++){
                cnt[i][j] = 0;
                for(int k=0;k<=N;k++)
                    ball[i][j][k] = 0;
            }
        }
        int res = FindLine();
        if(res == -1) puts("Draw");
        else if(res%2==1)printf("Black %d\n", res);
        else printf("White %d\n", res);
    }
    return 0;   
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main()
{   
    int n, w;
    cin >> n >> w;

    vector<int> v(n);
    vector<int> wei(n);
    vector<vector<int>> dp(101, vector<int> (10001));

    REP(j, w) {
        dp[0][j] = 0;
    }

    REP(i, n) {
        cin >> v[i] >> wei[i];
    }

    REP(i, n) {
        REP(j, w+1) {

            if (wei[i] <= j) {
                dp[i+1][j] = max(dp[i][j], dp[i][j-wei[i]]+v[i]);
            }

            else {
                dp[i+1][j] = dp[i][j]; 
            }
        }
    }

    cout << dp[n][w] << endl;
}


Measured memory_bytes: 6860
#include<bits/stdc++.h>
#define Rep(i, n) for(int i = 0; i < (n); i++)
#define fr first
#define sc second
#define pb(a) push_back(a)
#define INF INT_MAX
using namespace std;

typedef pair<int, int> P;
vector<P> mp[151];
int n, m, dp[151][1001][76];

void initDp(){
  Rep(i, 151) mp[i].clear();
  Rep(i, 151){
    Rep(j, 1001){
      Rep(k, 76){
	dp[i][j][k] = INF;
      }
    }
  }
}

int solve(int row, int cn, int jump){
  if(row == n-1 || (row == n-2 && jump > 0)) return 0;
  int slv = dp[row][cn][jump];
  if(slv == INF){
    int col = mp[row][cn].fr;
    int stn = mp[row][cn].sc;
    if(row+2 < n && jump > 0){
      Rep(i, mp[row+2].size()){
	int ncol = mp[row+2][i].fr;
	int nstn = mp[row+2][i].sc;
	int dng  = (stn + nstn) * abs(col - ncol);
	slv = min(slv, solve(row+2, i, jump-1)+dng);
      }
    }
    if(row+1 < n){
      Rep(i, mp[row+1].size()){
	int ncol = mp[row+1][i].fr;
	int nstn = mp[row+1][i].sc;
	int dng  = (stn + nstn) * abs(col - ncol);
	slv = min(slv, solve(row+1, i, jump)+dng);
      }
    }
  }
  return dp[row][cn][jump] = slv;
}

int main(){
  while(1){
    initDp();
    cin >> n >> m;
    if(n == 0 && m == 0) return 0;
    Rep(i, n){
      int k; cin >> k;
      Rep(j, k){
	int x, d;
	cin >> x >> d;
	mp[i].pb(P(x-1, d));
      }
    }
    
    int mn = INF;
    Rep(i, mp[0].size()){
      mn = min(mn, solve(0, i, m));
    }
    if(m > 0){
      Rep(i, mp[1].size()){
	mn = min(mn, solve(1, i, m-1));
      }
    }

    cout << mn << endl;
  }
}

Measured memory_bytes: 46116
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<random>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
struct val{
  ll n,c;
  bool mk;
};
const val INV = val{0,0,true};
void next_que(queue<val> &que,val &use){
  if(que.empty()){
    use = INV;
  }else{
    use = que.front();
    que.pop();
  }
}
void timers(chrono::system_clock::time_point start,double tl){
  double time;
  chrono::system_clock::time_point now;
  ll n;
  cin >> n;
  vector<ll> a(n),b(n),ans(n,0);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  bool can = false;
  map<ll,ll> mp;
  for(int i=0;i<n;i++){
    cin >> b[i];
    mp[b[i]]++;
  }
  vector<val> mpr;
  for(auto itr=mp.rbegin();itr!=mp.rend();itr++){
    mpr.push_back(val{itr->first,itr->second,false});
  }
  while(!can){
    val fi,se;
    queue<val> que;
    for(auto itr=mpr.begin();itr!=mpr.end();itr++){
      if(itr->n<=a.back()&&itr->n>=a.front()){
        que.push(val{itr->n,itr->c,false});
      }
    }
    for(auto itr=mpr.begin();itr!=mpr.end();itr++){
      if(itr->n>a.back()||itr->n<a.front()){
        que.push(val{itr->n,itr->c,true});
      }
    }
    next_que(que,fi);
    next_que(que,se);
    for(int i=0;i<n;i++){
      if(fi.n!=a[i]){
        ans[i] = fi.n;
        fi.c--;
        if(fi.c==0){
          fi = se;
          next_que(que,se);
        }
      }else{
        if(se.n==0){
          break;
        }
        ans[i] = se.n;
        se.c--;
        if(se.c==0){
          next_que(que,se);
        }
      }
    }
    if(ans.back()!=0){
      can = true;
      break;
    }
    auto tmp = mpr.back();
     std::random_device seed_gen;
  std::mt19937 engine(seed_gen());
    shuffle(mpr.begin(),mpr.end(),engine);
    now = chrono::system_clock::now();
    time = chrono::duration_cast<chrono::milliseconds>(now-start).count();
    if(time>=tl) break;
  }
  if(!can){
    cout <<"No\n";
    return;
  }
  cout << "Yes\n";
  for(int i=0;i<n;i++){
    cout << ans[i]<<" ";
  }
  cout << endl;
}
signed main(){
  init_io();
  timers(chrono::system_clock::now(),1800);
}


Measured memory_bytes: 30100
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    string s; cin >> s;
    vector<int> alph(26,0);

    rep(i,s.size()){
        alph[s[i] - 'a']++;
    }

    bool jud = true;

    rep(i,26) if(alph[i] %2 == 1) jud =false;

    if(jud) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int a, b;

  cin >> a >> b;

  cout << a * b - a - b + 1 << endl;

  return 0;
}


Measured memory_bytes: 256
sa = input()
sb = input()
sc = input()
a = [sa[i] for i in range(len(sa))]
b = [sb[i] for i in range(len(sb))]
c = [sc[i] for i in range(len(sc))]

n = 'a'
while True:
  if n == 'a':
    if len(a) == 0:
      print('A')
      exit()
    else:
      n = a.pop(0)
  elif n == 'b':
    if len(b) == 0:
      print('B')
      exit()
    else:
      n = b.pop(0)
  elif n == 'c':
    if len(c) == 0:
      print('C')
      exit()
    else:
      n = c.pop(0)

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

int main(){
	int n;
	cin >> n;
	int m = 3*n;
	vector<long> a(m);
	for (int i=0; i<m; i++){
	       cin >> a.at(i);
	}
	sort(a.begin(), a.end());
	long sum = 0;
	for(int i=n; i<m; i+=2){
		sum += a.at(i);
	}
	cout << sum << endl;
}	


Measured memory_bytes: 5536
def get_leap_years(from, to)
  res = []
  from.upto(to) do |i|
    if i%400 == 0
      res << i
    elsif i%100 == 0
      next
    elsif i%4 == 0
      res << i
    end
  end
  res
end

is_first_line = true
while gets do
  a, b = $_.split(' ').map(&:to_i)
  break if a == 0 && b == 0

  if is_first_line
    is_first_line = false
  else
    puts ''
  end

  res = get_leap_years(a, b)
  if res.count == 0
    puts 'NA'
  else
    puts res
  end
end

Measured memory_bytes: 6112
#include <bits/stdc++.h>
#include <iostream>
#include <set>
using namespace std;
typedef pair <long long,long long> pii;
int N;
pii arr[100005];
long long val[100005];
multiset <long long> larger;
multiset <long long>::iterator it;
struct quad{
    long long l, ll, r, rr;
};
quad neighbouring[100005];

int main() {
    cin >> N;
    for (int i=1; i<=N; i++) {
        scanf("%lld", &arr[i].first);
        val[i] = arr[i].first;
        arr[i].second = i;
    }
    sort(arr+1, arr+N+1);
    larger.insert(0);
    larger.insert(0);
    larger.insert(N+1);
    larger.insert(N+1);
    for (int i=N; i>=1; i--){
        it = larger.upper_bound(arr[i].second);
        it--;
        neighbouring[arr[i].second].l = *it;
        it--;
        neighbouring[arr[i].second].ll = *it;
        it = larger.upper_bound(arr[i].second);
        neighbouring[arr[i].second].r = *it;
        it++;
        neighbouring[arr[i].second].rr = *it;
        larger.insert(arr[i].second);
    }
    long long ans = 0;
    for (long long i=1; i<=N; i++){
        ans += (i-neighbouring[i].l)*(neighbouring[i].rr-neighbouring[i].r) * val[i];
        ans += (neighbouring[i].r-i)*(neighbouring[i].l-neighbouring[i].ll) * val[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10368
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
   
    int cost1, cost2, cost3, cost4;
    // AピザX枚，BピザY枚
    cost1 = A*X + B*Y;

    // AのためにABを使って残りはBを買う
    cost2 = 2*C*X + B*max(0, Y-X);

    // BのためにABを使って残りはAを買う
    cost3 = A*max(0, X-Y) + 2*C*Y; 

    // すべてABで補う
    cost4 = 2*C*max(X, Y);

    cout << min({cost1, cost2, cost3, cost4}) << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int h,w,d;cin>>h>>w>>d;
    vector<pair<int,pair<int,int>>> a;
    int tmp;
    FOR(i,0,h*w){
        cin>>tmp;
        tmp--;
        a.push_back(make_pair(tmp,make_pair(i/w,i%w)));
    }
    sort(a.begin(),a.end());
    vector<vector<int>> v(d);
    FOR(i,0,h*w){
        int x=a[i].first;
        int ind=x%d;
        if(x<d){
            v[ind].push_back(0);
        }else{
            int nx=a[i].second.first;
            int ny=a[i].second.second;
            int px=a[i-d].second.first;
            int py=a[i-d].second.second;
            int sum=v[ind][v[ind].size()-1];
            v[ind].push_back(sum+abs(nx-px)+abs(ny-py));
        }
    }
    int l,r,q;cin>>q;
    FOR(i,0,q){
        cin>>l>>r;l--;r--;
        cout<<v[l%d][r/d]-v[l%d][l/d]<<endl;
    }
    return 0;
}

Measured memory_bytes: 6388
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    int ans = 0;
    vector<int> flag(N, 1);
    for (int i = 0; i < N; ++i) {
        if (a[i] == a[a[a[i] - 1] - 1] && flag[a[i] - 1]) {
            flag[a[i] - 1] = 0;
            ans += 1;
        }
    }
    cout << ans/2 << endl;
    return 0;
}

Measured memory_bytes: 4048
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) cin>>V[I]
#define INS2(I,N,V1,V2) REP(I,N) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP(I,N) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<P<<endl
#define OUT2(P1,P2) cout<<P1<<" "<<P2<<endl
#define OUT3(P1,P2,P3) cout<<P1<<" "<<P2<<" "<<P3<<endl
#define OUTS(I,N,V) REP(I,N) cout<<V[i]<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
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; }
typedef unsigned long ul;
const ul INF = 1LL<<60;
int c[9],a1,a2,a3,i;
inline void solve(){
  REP(i,3){
    cin>>c[3*i]>>c[3*i+1]>>c[3*i+2];
  }
  REP(a1,101)REP(a2,101)REP(a3,101){
    if((c[0]-a1)==(c[3]-a2)&&(c[3]-a2)==(c[6]-a3)&&
       (c[1]-a1)==(c[4]-a2)&&(c[4]-a2)==(c[7]-a3)&&
       (c[2]-a1)==(c[5]-a2)&&(c[5]-a2)==(c[8]-a3)){
         OUT("Yes");
         return;
       }
  }
  OUT("No");
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


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

int main()
{
	int A=0,B=0,N=0;

	cin >> N;

	if (N == 1) {
		cout << "Hello World";
	}
	else if (N == 2) {
		cin >> A >> B;
		cout << A + B;
	}

	return 0;
}


Measured memory_bytes: 256
import sys


n = int(input())
xyh = []
for i in range(n):
    xyh.append(list(map(int, input().split())))
    if xyh[-1][2] >= 1:
        G = xyh[-1]

for cx in range(0, 101):
    for cy in range(0, 101):
        hs = []
        x, y, h = G
        H = h + abs(x - cx) + abs(y - cy)
        H = max(H, 0)
        invalid = False
        for i in range(n):
            x, y, h = xyh[i]
            hh = H - abs(x - cx) - abs(y - cy)
            hh = max(hh, 0)
            if hh != h:
                invalid = True
                break
        if invalid is False:
            print("{} {} {}".format(cx, cy, H))
            sys.exit()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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 INF=1001001001;
const int mod=1e9+7;
int64_t dp[2005];
int main() {
  int N;
  cin>>N;
  vector<int64_t>a,b;
  for(int i=0;i<N;i++){
    int x,y;
    cin>>x>>y;
    a.push_back(x+y);
    b.push_back(x-y);
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  cout<<max(a.back()-a[0],b.back()-b[0])<<endl;
  return 0;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  string ans = (
    (a == b && b == c && c == a) ||
    (a != b && b != c && c != a)
  ) ? "No" : "Yes";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu) FUNC(printe) FUNC(printe0);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

#include "atcoder/all"
using namespace atcoder;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    dsu uf(n);
    for(int i = 0; i < q; i++){
        int t, u, v;
        cin >> t >> u >> v;
        if(t == 0){
            uf.merge(u, v);
        }else{
            cout << uf.same(u, v) << '\n';
        }
    }
}


Measured memory_bytes: 3592
import java.util.*;
 
class Main{
    public static void main(String[] args){
		
		Scanner scan = new Scanner(System.in);
		StringBuffer sb = new StringBuffer(scan.next());
		String str = scan.next();

		sb.append(sb);
		int a = sb.indexOf(str);
		if(a != -1){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
    }
}

Measured memory_bytes: 26316
import java.io.*;

class Main {
	static int fieldlen = 0;
	static int fieldstart = 0;
    public static void main(String[] args) {
        BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
        try {
			
			char[] field = kb.readLine().toCharArray();
			fieldlen = field.length;
			int[] areas = new int[10000];
			int cnt, found, total;

			cnt = total = found  = 0;
            for( int i=0; i<fieldlen; i++ ) {
            	if( '\\' == field[i] ) {
	            	found = getArea( field, i );
	            	if( 0 < found ) {
	            		areas[cnt] = found;
	            		total += areas [cnt++];
	            		found = 0;
	            		i = fieldstart;
	            	}
            	}
            }
            
            StringBuilder output = new  StringBuilder( );
            output.append( total ).append( "\n" );
            output.append( cnt ).append( " " );
           	for( int i=0; i<cnt; i++ ) {
           		output.append( areas[i] ).append( " " );
         	}
         	output.deleteCharAt( output.lastIndexOf( " " ) );
         	System.out.println( output );

	    } catch( IOException e ) {
	        System.err.println( e );
	    }
	}
	public static int getArea( char[] field, int start )
	{
		int i, area, cnt, s, t;
		area = cnt = s = t = 0;
		for( i=start; i<fieldlen; i++ ) {
            if( '\\'== field[i] ) {
            	cnt++;
            	t++;
            	area += cnt;
            } else if( 0 < cnt && '/' == field[i] ) {
            	area += cnt;
            	cnt--;
            	if( 0 == cnt ) { break; }
            } else if( '_' == field[i]  ) {
            	s += cnt;
            }
		}
		if( fieldlen == i ) { 
			area = 0;
		} else {
			area = ( area - t + s );
			fieldstart = i;
		}
		return area;
	}
}

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

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; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  ll N;
  cin>>N;
  vector<vector<ll>> v(N,vector<ll>(2));
  for(ll i = 0; i < N; i++) cin>>v[i][0]>>v[i][1];
  vector<vector<ll>> w(N,vector<ll>(2));
  for(ll i = 0; i < N; i++) {
    w[i][0]=v[i][0]+v[i][1];
    w[i][1]=i;
  }
  sort(w.begin(),w.end());
  reverse(w.begin(),w.end());
  ll T=0LL,S=0LL;
  for(ll i = 0; i < N; i++){
    if(i%2==0) T+=v[w[i][1]][0];
    if(i%2==1) S+=v[w[i][1]][1];
  }
  cout<<T-S<<endl;
}

Measured memory_bytes: 11136
#import<cstdio>
int main(){for(int n,a,c,r,t;c=r=scanf("%d",&n),n;printf("%d\n",r))for(char d[]="123456",s[9];n--;r+=*d-48)scanf("%s",s),*s%6-4?a=*s%5+*s%2*2+c&3,t=*d,*d=d[a+=a/2?2-a%2*2:1],d[a]=d[5],d[5]=d[5-a],d[5-a]=t:c+=*s+3;}

Measured memory_bytes: 0
import sys
from collections import defaultdict


def main():
    N, A, *xlst = map(int, sys.stdin.read().split())
    x_p = []
    x_n = []
    x_z = 0
    xlst.sort()
    for i in xlst:
        if A < i:
            x_p.append(i - A)
        elif i < A:
            x_n.append(A - i)
        else:
            x_z += 1

    x_p_sum = defaultdict(int, {0: 1})
    x_n_sum = defaultdict(int, {0: 1})
    for i in range(len(x_p)):
        for j in sorted(x_p_sum, reverse=1):
            x_p_sum[j + x_p[i]] += x_p_sum[j]

    for i in range(len(x_n)):
        for j in sorted(x_n_sum, reverse=1):
            x_n_sum[j + x_n[i]] += x_n_sum[j]

    res = 0
    for i in x_n_sum:
        if i in x_p_sum:
            res += (x_n_sum[i] * x_p_sum[i])
    res *= 1 << x_z
    res -= 1
    print(res)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3436
import numpy as np
import sys
import math

n,d=map(int,input().split())
X=[]
for i in range(n):
    X.append(list(map(int,input().split())))
ans=0
X=np.array(X)
for i in range(n-1):
    for j in range(i+1,n):
        temp=0
        for k in range(d):
            temp+=(X[i][k]-X[j][k])**2
        if math.sqrt(temp)%1==0:
            ans+=1

print(ans)

Measured memory_bytes: 20636
n,m=map(int,input().split())
l=sorted(list(map(int,input().split())))
if n>=m:
    print(0)
    exit()
s=l[-1]-l[0]
l=sorted([a-b for a,b in zip(l[1:],l)], reverse=True)
print(s-sum(l[:n-1]))


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

using namespace std;

#define ldouble long double
#define llong long long int
#define print(x) cout << x << endl
#define ternary(condition, x, y) ((condition) ? x : y) 
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(STL) STL.begin(), STL.end()
#define stl_rep(itr, STL) for (auto itr = STL.begin(); itr != STL.end(); ++itr)

const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

int main (int argc, char *argv[]) {
    cin.tie(0); 
    ios::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;
    if (k <= ceil((double)n / 2)) cout << "YES" << endl;
    else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void cycleSwap(int* a, int* b, int* c)
{
    int tmp;
    tmp = *b;
    *b = *a;
    *a = *c;
    *c = tmp;
}

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cycleSwap(&a,&b,&c);
    cout<<a<<" "<<b<<" "<<c<<endl;
    return 0;
}


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

int main(){
  int n,m,c;
  cin >> n >> m>> c;
  vector<int> b(m);
  rep(i,m) cin>>b[i];
  int ans=0;
  rep(i,n){
    int sum=c;
    rep(j,m){
      int x;
      cin>>x;
      sum+=x*b[j];
    }
    if(sum>0) ans++;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3652
from sys import exit, stdin
N = int(stdin.readline().rstrip())
S = stdin.readline().rstrip()
xs = [0]
x = 0
for s in S:
    if s == 'I':
        x += 1
    elif s == 'D':
        x -= 1
    xs.append(x)
print(sorted(xs)[-1])

Measured memory_bytes: 38256
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

x = 0
b = 1 << 50
for _ in range(50):
    b = b >> 1
    if x + b > k:
        continue;

    cnt = 0
    for i in a:
        if i & b:
            cnt += 1

    if cnt < len(a) / 2:
        x += b

ans = 0
for i in a:
    ans += i ^ x

print(ans)

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

int main(int argc, const char * argv[]) {

    char a[101],b[101];
    int n,i;
    int x=0,y=0;

    scanf("%d",&n);
    for(i=0; i<n; i++){
        scanf("%s %s", a, b);
        if(strcmp(a,b) == 0) x++, y++;
        if(strcmp(a,b) > 0) x+=3;
        if(strcmp(a,b) < 0) y+=3;
    }
    
    printf("%d %d\n",x,y);
    return 0;
}



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

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

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

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

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

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

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

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


int main()
{
	int n; cin >> n;
	int now = 1;
	rep(i, n)
	{
		int a; cin >> a;
		if (a == now)++now;
	}
	if (now == 1)cout << -1 << endl;
	else cout << n - now + 1 << endl;
}

Measured memory_bytes: 3612
#include<stdio.h>
#include<string.h>	
#include<math.h>

int main(){
	int k;
	scanf("%d",&k);
	int x=7%k;
	for(int i=1;i<=k;i++){
		if(!x){
			printf("%d\n",i);
			return 0;
		}
		x=(x*10+7)%k;
	}
	printf("-1\n");
	return 0;
} 

Measured memory_bytes: 1688
#include <iostream>
#include <string.h>
using namespace std;

int main() {
    int N,M;

    cin >> N;


    char s[N][10];

    for(int i=0;i<N;i++){
        scanf("%s",s[i]);
        //printf("%s\n",s[i]);
    }
    cin >> M;
    char t[M][10];
    for(int i=0;i<M;i++){
        scanf("%s",t[i]);

    }
    bool flag[N];
    for(int i=0;i<N;i++){
        flag[i] = false;
    }
    int sum = 1;
    int max = 0;
    for(int i=0;i<N;i++){
        sum = 1;
        if(flag[i] ==true) continue;
        flag[i] = true;
        for(int j=i+1;j<N;j++){
            if(strcmp(s[i],s[j])==0){
                sum++;
                flag[j] = true;
            }
        }
        //printf("%s\n",s[0]);
        for(int j=0;j<M;j++){
            if(strcmp(s[i],t[j])==0){
                //printf("%d%s\n,%s\n",i,s[i],t[j]);
                sum = sum -1;
            }
        }
        if(sum > max) max = sum;
        //cout << sum <<"\n";
    }
    cout <<max << "\n";
}


Measured memory_bytes: 256