akhauriyash/Code-Regression huggingface dataset:
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 500010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

struct Data {
    int l, r, cs, block;
    Data(int l = 0, int r = 0, int cs = 0, int block = 0) : l(l), r(r), cs(cs), block(block) {}
};

bool operator<(Data a, Data b) {
    if (a.block == b.block) return a.r < b.r; 
    return a.block < b.block;
}

vector<Data> b;
int n, q, a[MAXN], kq, cnt[MAXN], res[MAXN];

void add(int u) {
    kq += (cnt[a[u]]++ == 0);
}
void del(int u) {
    kq -= (--cnt[a[u]] == 0);
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> q;
    FOR(i,1,n) cin >> a[i];

    // length of one block
    int k = int(sqrt(n));
    // num of blocks
    int part = n / k + (n % k > 0);

    FOR(i,1,q) {
        int l, r;
        cin >> l >> r;
        b.push_back(Data(l, r, i, l / part - (l % part == 0)));
    }

    sort(ALL(b));
    int currL = 1, currR = 1;
    cnt[a[1]]++;
    kq = 1;
    FOR(i,0,q-1) {
        while (currR > b[i].r) del(currR--);
        while (currR < b[i].r) add(++currR);
        while (currL < b[i].l) del(currL++);
        while (currL > b[i].l) add(--currL);
        res[b[i].cs] = kq;
    }

    FOR(i,1,q) cout << res[i] << "\n";
    return 0;
}


Measured memory_bytes: 17532
import sys
sys.setrecursionlimit(100000)

def main():
    n = int(input())
    a = list(map(int, input().split()))

    def gcd(a, b):
        if b == 0:
            return a
        return gcd(b, a%b)

    lcm = 1
    for i in a:
        g = gcd(lcm, i)
        lcm *= i // g

    ans = 0
    mod = 10**9 + 7
    for i in a:
        ans += lcm // i
    ans %= mod
    print(ans)

main()


Measured memory_bytes: 4084
//
// Created by moono on 2018/10/27.
//

#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;



int main() {
    //
    string O, S;
    cin >> O;
    cin >> S;

    //
    int len_O = O.size(), len_S = S.size(), i = 0;
    for (; i < len_O && i < len_S ; ++i) {
        cout << O[i] << S[i];
    }
    for (int j = i; j < len_O; ++j) {
        cout << O[j];
    }
    for (int j = i; j < len_S; ++j) {
        cout << S[j];
    }

    return 0;
}

Measured memory_bytes: 256
n, k, q = map(int, input().split())
a_list = [int(input())-1 for _ in range(q)]
p_list = [k-q for _ in range(n)]

for a in a_list:
    p_list[a] += 1

for p in p_list:
    if p <= 0:
        print("No")
    else:
        print("Yes")


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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

int dfs(int i, vector<vector<int>>& graph, vector<int>& dist) {
    vector<int>& edges = graph[i];
    int sz = edges.size();
    if(sz == 0) return 0;

    if(dist[i] >= 0) return dist[i];

    int ans = 0;
    for(int edge : edges) {
        int cand = 1+dfs(edge, graph, dist);
        ans = max(cand, ans);
    }

    dist[i] = ans;
    return ans;
}

int32_t main() {

    int n, m; cin >> n >> m;
    vector<vector<int>> graph(n+1, vector<int>());
    for(int i = 0; i < m; ++i) {
        int x, y; cin >> x >> y;
        graph[x].push_back(y);
    }

    vector<int> dist(n+1, -1);

    int ans = 0;
    for(int i = 1; i <= n; ++i) {
        if(dist[i] < 0) {
            int cand = dfs(i, graph, dist);
            ans = max(ans, cand);
        }
    }

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


Measured memory_bytes: 9216
A, B, C, K = map(int, input().split())

if A > K:
    a = K
    b = 0
    c = 0
else:
    a = A
    if B > K - A:
        b = K - A
        c = 0
    else:
        b = B
        c = K - A - B

print(a - c)

Measured memory_bytes: 9180
import java.util.Scanner;

public class Main{
public static void main(String[] args){
	int n,i,x;
	Scanner sc = new Scanner(System.in);

	n=sc.nextInt();
	for(i=1;i<=n;i++){
		x=i;
		if(x%3==0){
			System.out.printf(" %d",i);
		}else{
			while(x!=0){
				if(x%10==3){
					System.out.printf(" %d",i);
					break;
				}
				x/=10;
			}
		}
	}
	System.out.printf("\n");

}
}

Measured memory_bytes: 33996
#include <bits/stdc++.h>
using namespace std;
#define forloop(n) for(int i = 0; i < n; i++)
#define ll long long
int main(){
	double x; cin>>x;
	int m = (int)x/1.08;
	if(m * 1.08 < x){
		m += 1;
	}
  	if(m *1.08 >= x+1){
      cout<<":(";
    }else{
      cout<<m;
    }
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int dp[16][15];
int h,w;
int map[16][15];
main()
{
	while(cin>>w>>h,w)
	{
	    for(int i=0;i<=h;i++)for(int j=0;j<w;j++)map[i][j]=0;
		for(int i=0;i<h;i++)
		{
			for(int j=0;j<w;j++)
			{
				cin>>map[i][j];
			}
		}
		for(int i=0;i<=h;i++)for(int j=0;j<w;j++)dp[i][j]=0;
		for(int i=0;i<w;i++)dp[0][i]=map[0][i]==0;
		for(int i=0;i<h;i++)
		{
			for(int j=0;j<w;j++)
			{
				if(dp[i][j]==0||map[i][j]==1)continue;
				if(map[i][j]==2)
				{
					dp[i+2<=h?i+2:h][j]+=dp[i][j];
					continue;
				}
				if(i<h-1&&j>0)
				{
					if(map[i+1][j-1]==0)dp[i+1][j-1]+=dp[i][j];
				}
				if(i<h-1&&j<w-1)
				{
					if(map[i+1][j+1]==0)dp[i+1][j+1]+=dp[i][j];
				}
				if(map[i+1][j]!=1)dp[i+1][j]+=dp[i][j];
			}
		}
		int ans=0;
		for(int j=0;j<w;j++)ans+=dp[h][j];
		cout<<ans<<endl;
	}
}



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

int n,k;
bool used[2020];
vector<vector<int>> v(2020);

int dfs(int p,int dist){
    used[p]=true;
    int ret=0;
    if(dist>k/2) ret++;
    for(auto i:v[p]){
        if(!used[i]){
            ret += dfs(i,dist+1);
        }
    }
    return ret;
}


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

    cin>>n>>k;
    for(int i=1;i<n;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        v[b].push_back(a);
        v[a].push_back(b);
    }
    int ans=1e9;
    if(k%2==0) {
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++) used[j]=false;
            ans = min(ans,dfs(i,0));
        }
    }
    else {
        k--;
        for(int i=0;i<n;i++){
            for(auto j:v[i]){
                for(int j=0;j<n;j++) used[j]=false;
                used[j]=true;
                int cnt=dfs(i,0);
                used[j]=false;
                cnt+=dfs(j,0);
                ans=min(ans,cnt);
            }
        }
    }
    cout<<ans<<endl;
    
    
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		String[] s = new String[h + 2];
		s[0] = ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,";
		s[h + 1] = ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,";
		for (int i = 1; i <= h; i++) {
			s[i] = sc.next();
		}

		for (int i = 1; i <= h; i++) {
			for (int j = 0; j < w; j++) {
				int count = 0;

				if (j > 0) {
					if (s[i - 1].charAt(j - 1) == '#') {
						count++;
					}
					if (s[i].charAt(j - 1) == '#') {
						count++;
					}
					if (s[i + 1].charAt(j - 1) == '#') {
						count++;
					}
				}
				if (s[i - 1].charAt(j) == '#') {
					count++;
				}
				if (s[i + 1].charAt(j) == '#') {
					count++;
				}
				if (j < w - 1) {
					if (s[i - 1].charAt(j + 1) == '#') {
						count++;
					}
					if (s[i].charAt(j + 1) == '#') {
						count++;
					}
					if (s[i + 1].charAt(j + 1) == '#') {
						count++;
					}
				}
				if (s[i].charAt(j) == '#') {
					System.out.print('#');
				} else {
					System.out.print(count);
				}
			}
			System.out.println();
		}

	}
}

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

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

  for(int i = 0; i < c.size(); i++)
  {
    if(c.at(i) == 'a' || c.at(i) == 'i' || c.at(i) == 'u' || c.at(i) == 'e' || c.at(i) == 'o')
      cout << "vowel" << endl;
    else
      cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
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(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int n,m;
    int d;cin>>n>>d;
    vvint x;
    initvv(x, n, d, 0);
    rep(i, n){
        rep(j, d){
            cin>>x[i][j];
        }
    }
    int ans = 0;
    rep(i, n-1){
        for(int j = i+1;j<n;j++){
            int tmp = 0;
            rep(k, d){
                tmp += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            rep(k, 40*40*10+1){
                if(k*k==tmp){
                    ans++;
                    break;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define printll(a) printf("%lld\n", a)
#define printYes() printf("Yes\n")
#define printNo() printf("No\n")
#define scanll(a) scanf("%lld", &a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scan4Int(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
typedef long long ll;
const int INF = 1001001001;
using namespace std;
void swap(int *a, int *b) {
    int tmp = *a;
    *a = *b;
    *b = tmp;
    return;
}
int gdc(int a, int b) {
    int r;
    if (a < b)
        swap(&a, &b);
    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main() {
    int a, b;
    scan2Int(a,b);
    a -= b * 2;
    if (a < 0) printInt(0);
    else printInt(a);
    return 0;
}

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

using namespace std;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)
typedef long long ll;
const int  INF = 2147483647;
const ll INFL = 1LL << 50;
const ll mod = 1000000007;



bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}
	return true;
}


int main() {
	VI v(100010, 0);
	REP(i, 100005) {
		if (IsPrime(i) && IsPrime((i + 1) / 2))v[i + 1] = v[i] + 1;
		else v[i + 1] = v[i];
	}
	int q;
	cin >> q;
	REP(i, q) {
		int l, r;
		cin >> l >> r;
		cout << v[r+1]-v[l-1] << endl;
	}
}

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

## 2個しかない場合
if N == 2:
  A.sort()
  print(A[-1] - A[0])
  print(A[-1], A[0])
  exit()

## 全部非負整数の場合
if sum(a < 0 for a in A) == 0:
  A.sort()
  solver = []
  var = A[0]
  for i in range(1,N-1):
    solver.append((var, A[i]))
    var = var - A[i]
  else:
    solver.append((A[-1], var))
    var = A[-1] - var

  print(var)
  for i in range(len(solver)):
    print(solver[i][0], solver[i][1])
  exit()
  
## 全部非正整数の場合
if sum(a > 0 for a in A) == 0:
  A.sort(reverse=True)
  solver = []
  var = A[0]
  for i in range(1,N):
    solver.append((var, A[i]))
    var = var - A[i]

  print(var)
  for i in range(len(solver)):
    print(solver[i][0], solver[i][1])
  exit()
  
## 正整数も負整数もある場合
A.sort()
n_nega = sum(a < 0 for a in A)
n_posi = sum(a > 0 for a in A)
solver = []
var = A[n_nega-1]
if n_posi > 1:
  for i in range(n_nega,N-1):
    solver.append((var, A[i]))
    var = var - A[i]
solver.append((A[-1], var))
var = A[-1] - var
if n_nega > 1:
  for i in range(n_nega-1):
    solver.append((var, A[i]))
    var = var - A[i]

print(var)
for i in range(len(solver)):
  print(solver[i][0], solver[i][1])




Measured memory_bytes: 19384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n;
	cin >> n;
	vll a(n);
	for (ll i = 0; i < n; i++) cin >> a[i];
	sort(all(a));
	ll cnt = 0;
	for (ll i = 0; i < n - 1; i++) {
		if (a[i] == a[i + 1]) cnt++;
	}
	if (cnt % 2 == 0) cout << n - cnt << endl;
	else cout << n - cnt - 1 << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define INF 100005

string n;
vector<int>coin;
string ans;

bool maxx(string aa,string bb)
{
	if(aa.size()!=bb.size())
	{
		return aa.size()>bb.size();
	}
	for(int i=0;i<aa.size();i++)
	{
		if(aa[i]>bb[i])
		{
			return true;
		}
		if(aa[i]<bb[i])
		{
			return false;
		}
	}
	return true;
}

void rec(string a)
{
	if(maxx(a,n))
	{
		if(maxx(ans,a))
		{
			ans=a;
		}
		return;
	}
	if(a.size()>n.size()+1)
	{
		return;
	}
	for(int i=0;i<coin.size();i++)
	{
		string now=a;
		now.push_back((char)('0'+coin[i]));
		if(now!="0")
		{
			rec(now);
		}
	}
}

int main()
{
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int kk;
    cin >> n >> kk;
    int aa[11]={0};
    for(int k=0;k<kk;k++)
    {
    	int num;
    	cin >> num;
    	aa[num]=1;
    }
    for(int k=0;k<10;k++)
    {
    	if(aa[k]==0)
    	{
    		coin.push_back(k);
    	}
    }
    ans="999999999";
    rec("");
    cout << ans << endl;
}

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

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

using namespace std;
using ll = long long;
using P = pair<int,int>;

 
int main(void)
{
    int n,i,ans;
    double d,x,y,l;

    cin >> n >> d;

    ans = 0;

    for(i=0;i<n;i++){
        cin >> x >> y;
        l = sqrt(x*x + y*y);
        if(l <= d)ans++;
    }

    cout << ans << endl;

}

Measured memory_bytes: 3804
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

int n,col[200010],cnt1,cnt2,maxv;
vector<int> v[200010],res[3];

inline void dfs(int x,int pr,int dist)
{
	if(dist%2==1){col[x]=1;cnt1++;}
	else{col[x]=2;cnt2++;}
	res[col[x]].push_back(x);
	for(int i=0;i<v[x].size();i++) if(v[x][i]!=pr){
		int u=v[x][i];
		dfs(u,x,dist+1);
	}
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<n;i++){
		int a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a); 
	}
	dfs(1,-1,1);
	int val1=n/3+(n%3>0),val2=n/3+(n%3>1),val3=n/3;
	if(cnt1<val1){
		for(int i=0;i<res[1].size();i++){
			col[res[1][i]]=0;
		}
		int rem0=val3-res[1].size(),rem1=val1;
		for(int i=0;i<res[2].size();i++){
			if(rem0>0){
				rem0--;
				col[res[2][i]]=0;
			}
			else if(rem1>0){
				rem1--;
				col[res[2][i]]=1;
			}
		}
	}
	else if(cnt2<val2){
		for(int i=0;i<res[2].size();i++){
			col[res[2][i]]=0;
		}
		int rem0=val3-res[2].size(),rem2=val2;
		for(int i=0;i<res[1].size();i++){
			if(rem0>0){
				rem0--;
				col[res[1][i]]=0;
			}
			else if(rem2>0){
				rem2--;
				col[res[1][i]]=2;
			}
		}
	}
	else{
		while(cnt1>val1){
			col[res[1].back()]=0;
			res[1].pop_back();
			cnt1--;
		}
		while(cnt2>val2){
			col[res[2].back()]=0;
			res[2].pop_back();
			cnt2--;
		}
	}
	int num1=1,num2=2,num3=3;
	for(int i=1;i<=n;i++){
		if(col[i]==0){
			cout<<num3<<" ";
			num3+=3;
		}
		else if(col[i]==1){
			cout<<num1<<" ";
			num1+=3;
		}
		else{
			cout<<num2<<" ";
			num2+=3;
		}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 18676
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
using namespace std;
using ll=long long;
#define MOD  1000000007

int main(int argc, char const *argv[]) {
  string s[110];
  int h,w;
  std::cin >> h >> w;
  for(int i=0; i<h; i++) std::cin >> s[i];

  for(int i=0; i<h; i++){
    std::cout << s[i] << '\n';
    std::cout << s[i] << '\n';
  }
  
  return 0;
}


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

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

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N, Q;
    cin >> N >> Q;
    string s;
    cin >> s;
    vector<char> t(Q), d(Q);
    REP(i, Q) cin >> t[i] >> d[i];

    ll left = -1, right = N;
    for(int i = Q-1;i>=0;i--){
    	if(s[left+1] == t[i] && d[i] == 'L') left++;
    	if(s[left] == t[i] && d[i] == 'R') left--;
    	if(s[right-1] == t[i] && d[i] == 'R') right--;
    	if(s[right] == t[i] && d[i] == 'L') right++;
    }
    //dump(left)
    //dump(right)
    if(right > left){
    	cout << N - (left+1) - (N-right) << endl;
    }else{
    	cout << N << endl;
    }
    return 0;
}

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

int main(){

    long long N, K;
    cin >> N >> K;
    vector<long long> h(N);
    for(long long i = 0; i < N; i++) cin >> h[i];
    sort(h.begin(), h.end());
    long long min = 1e12;
    for(long long i = 0; i < N - K + 1; i++) if(min > h[i + K - 1] - h[i]) min = h[i + K - 1] - h[i];
    cout << min << endl;

    return 0;
}

Measured memory_bytes: 1024
// IOI 2021
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
 
////////////////////////////////////////////////////////////////////
 
const int N = 1e5 + 5;

int n, A[N];

int GCD(int a, int b) { return !b ? a : GCD(b, a % b); }

bool G() {
	int e = 0, o = 0;
	bool f = 1;
	for (int i = 0; i < n; i++) f &= (A[i] == 1), (A[i] & 1 ? o : e)++;
	if (f) return 0;
	if (e & 1) return 1;
	if (o > 1) return 0;
	int g = 0;
	for (int i = 0; i < n; i++) {
		if (A[i] == 1) return 0;
		else if (A[i] & 1) A[i]--;
		g = GCD(g, A[i]);
	}
	for (int i = 0; i < n; i++) A[i] /= g;
	return !G();
}

int main() {
 
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	mt19937 Rnd(time(0));
	
	cin >> n;
	for (int i = 0; i < n; i++) cin >> A[i];
	cout << (G() ? "First" : "Second") << endl;

	return 0;
}


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

int main(int argc,char* argv[]){
  int array[12];
  int post_array[12];
  int i,j;

  for(;;){
    int n;
    int count = 0;
    scanf("%d",&n);
    if(n == 0){break;}

    for(i = 0; i < n; i++){
      scanf("%d",&array[i]);
    }
    
    for(;;){
      int ok = 1;
      memset(post_array,0,sizeof(post_array));

      for(i = 0; i < n; i++){
	for(j = 0; j < n; j++){
	  if(array[i] == array[j]){
	    post_array[i]++;
	  }
	}
      }

      for(i = 0; i < n; i++){
	if(post_array[i] != array[i]){
	  ok = 0;
	  break;
	}
      }

      if(ok == 0){
	for(i = 0; i < n; i++){
	  array[i] = post_array[i];
	}
	count++;
	continue;
      }else{
	break;
      }
    }

    printf("%d\n",count);
    for(i = 0; i < n; i++){
      if(i != 0){printf(" ");}
      printf("%d",array[i]);
    }
    printf("\n");
  }
  
  return 0;
  
}

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


string dump(int x) {
    string  res;
    if(!x) res = "0";
    while(x) {
        res += to_string(x & 1 ? 1 : 0);
        x = x >> 1;
    }
    return res;
}

class Solver {
  public:
    bool solve() {
        string S; cin >> S;
        int N = S.size();
        map<int, int> dp;
        dp[0] = 0;
        //rep(i, 'z' - 'a') dp[1 << i] = 1;
        int hash = 0;
        rep(i, N) {
            int prev_cnt = dp[hash];
            hash ^= 1 << (S[i] - 'a');
            // cerr << "now "; dump(hash);
            if(not dp.count(hash)) dp[hash] = INF;
            rep(j, 'z' - 'a' + 1) {
                int need = hash ^ (1 << j);
                if(dp.count(need)) {                    
                    // cerr << "found " << dump(need) << " : " << dp[need] << endl;
                    dp[hash] = min(dp[hash], dp[need] + 1);
                } else {
                    dp[hash] = min(dp[hash], prev_cnt + 1);
                }
            }
            set_min(dp[hash], prev_cnt + 1);
            // cerr << i << " : " << dp[hash] << endl;
        }        
        cout << max(1, dp[hash]) << endl;        
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 9876
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 100001
long long A[MAX];
 
int main(){
    int i, K;
    cin >> K;
    for(i=0; i<K; i++) cin >> A[i];
    long long lo = 2, hi = 2;
 
    for(i=K-1; i>=0; i--) {
        if(hi < A[i]) {
            cout << -1 << endl;
            return 0;
        }
        long long lk = (lo + A[i] - 1) / A[i];
        long long hk = hi / A[i];
        if(hk < lk) {
            cout << -1 << endl; 
            return 0;
        }
        lo = lk * A[i];
        hi = hk * A[i] + A[i] - 1;
    }
 
    cout << lo << ' ' << hi << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.io.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws java.io.IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String l = in.readLine();
        String m = in.readLine();
        String n = in.readLine();
        String o = in.readLine();
        
    int N = Integer.parseInt(l);//5
    int K = Integer.parseInt(m);//3
    int X = Integer.parseInt(n);//10000
    int Y = Integer.parseInt(o);//9000

    
          	   	 if(N>K) {
        	   	   	 System.out.println(N*X-(X-Y)*(N-K));   
  				 } else if (N<=K)
       				 System.out.println(N*X); 
   }
   }

Measured memory_bytes: 8144
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
ll a, b, c, d;
ll gcd(ll c, ll b)
{
    if (b == 0)
        return c;
    return (gcd(b, c % b));
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b >> c >> d;
    ll sub = b;
    ll divc = sub / c;
    ll divd = sub / d;
    ll divdc = sub / (c * d / gcd(max(c, d), min(c, d)));
    ll ansb = b - divc - divd + divdc;
    sub = a-1;
    divc = sub / c;
    divd = sub / d;
    divdc = sub / (c * d/ gcd(max(c, d), min(c, d)));
    ll ansa = a-1 - divc - divd + divdc;
    cout << ansb - ansa << "\n";
}

Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

v, e = map(int, input().split())
INF = float("inf")
dist = [[INF for _ in range(v)] for _ in range(v)]
for i in range(e):
    s, t, d = map(int, input().split())
    dist[s][t] = d

for k in range(v):
    for i in range(v):
        for j in range(v):
            if i == j:
                dist[i][j] = 0
            elif dist[i][j] > dist[i][k] + dist[k][j]:
                dist[i][j] = dist[i][k] + dist[k][j]

# check negative cycle
has_negative = False
for k in range(v):
    for i in range(v):
        for j in range(v):
            if dist[i][j] > dist[i][k] + dist[k][j]:
                has_negative = True
                break
if has_negative:
    print("NEGATIVE CYCLE")
    exit()

for i in range(v):
    for j in range(v):
        if dist[i][j] == INF:
            print("INF", end="")
        else:
            print(dist[i][j], end="")
        if j != v - 1:
            print(" ", end="")
    print()


Measured memory_bytes: 7276
# AOJ 0130 Train
# Python3 2018.6.19 bal4u

for _ in range(int(input())):
	s = list(input())
	ans, dir = [], '>'
	for x in s:
		if x.isalpha():
			if dir == '>':
				if x not in ans: ans.append(x)
			else:
				if x not in ans: ans.insert(0, x)
		elif x == '>' or x == '<': dir = x
	print(*ans, sep='')


Measured memory_bytes: 5628
#include<bits/stdc++.h>
#define Mx 1000000000005 
#define ll long long  
#define pi 3.141592653
#define vi vector<ll>
#define Mo 1000000007
#define mp make_pair
#define M map<ll,ll>
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define vii vector<pair<ll,ll> > 
#define fi first
#define se second
#define pb push_back
#define ld long double
#define fill(a,x) memset(a,x,sizeof(a))
using namespace std;
bool comp(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
  return a.second<b.second;
}
/*vi b=v;
   sort(b.begin(), b.end());
  b.resize(unique(b.begin(), b.end()) - b.begin());
  ll t; cin>>t; fr(f,0,t){ 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 */
vector<vector<ll>> dp(1e5 + 2, vector<ll>(2,-1));
ll func(vi v[],ll s,bool vis[],ll c)
{ 
  if(dp[s][c]!=-1) return dp[s][c];

  ll ans=1,x;
  vis[s]=1;
  fr(i,0,v[s].size())
  {
    if(!vis[v[s][i]])
    { 
      if(c==0)
        x=func(v,v[s][i],vis,c)+func(v,v[s][i],vis,(c+1)%2);
      else 
        x=func(v,v[s][i],vis,(c+1)%2);
      x%=Mo;
      ans*=x; ans%=Mo;
    }
  }
  vis[s]=0;
  return dp[s][c]=ans;
}
int main()
{
  ll V,x,y; cin>>V;
  vi v[V+1];
  fr(i,0,V-1)
  {
    cin>>x>>y;
    v[x].pb(y);
    v[y].pb(x);
  }

  bool vis[V+1]={0};
  ll ans=(func(v,V,vis,0)+func(v,V,vis,1))%Mo;
  cout<<ans;


}


Measured memory_bytes: 20924
#include<bits/stdc++.h>
using namespace std;
int main()
{

   int n;
   cin>>n;
   vector<int>v1;
   for(int i=0;i<n;i++)
   {
       int x;
       cin>>x;
       v1.push_back(x);
   }
   int count=0;
      for(int i=0;i<n;i++)
   {
       if(v1[i]!=i+1)
        count++;
   }
  if (count == 2 || count == 0)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }




    return 0;
}








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

#define FASTIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vl(p) vector<p>
#define w while
#define For(i,s,x) for(i=s;i<x;i++)
#define Fore(i,s,x) for(i=s;i<=x;i++)
#define FOR(i,x) for(i=0;i<x;i++)
#define Rof(i,s,x) for(i=s;i>=x;i--)
#define all(v) v.begin(),v.end()
#define it(r,v) for(auto r=v.begin();r!=v.end();r++)
#define pb push_back
#define in insert
#define sz size()
#define F first
#define S second
#define nl cout<<"\n"
#define pr(a) cout<<a<<" "
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define pr3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define mod 1000000007
const double PI = 3.141592653589793238;

int main()
{
	FASTIO;

        ll i,j,k,x,y,z,n,a,b,c,c1=0,c2=0,flag=0,sum=0;
        cin>>n>>k;
        ll arr[n];
        FOR(i,n)
            cin>>arr[i];

        sort(arr, arr+n);

        FOR(i,k)
            sum=sum+arr[i];
        cout<<sum;
        nl;



}


Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

    int n = scan.nextInt();
    int m = scan.nextInt();

    int[] h = new int[n];
    for (int i = 0; i < n; i++) {
      h[i] = scan.nextInt();
    }

    boolean[] res = new boolean[n];
    for (int i = 0; i < n; i++) {
      res[i] = true;
    }

    for (int i = 0; i < m; i++) {
      int a = scan.nextInt();
      int b = scan.nextInt();
      a--;
      b--;
      if (h[a] > h[b]) {
        res[b] = false;
      } else if (h[a] < h[b]) {
        res[a] = false;
      } else {
        res[a] = false;
        res[b] = false;
      }
    }

    int cnt = 0;
    for (int i = 0; i < n; i++) {
      if (res[i] == true) {
        cnt++;
      }
    }

    System.out.println(cnt);

  }

}

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

#ifdef ONLINE_JUDGE
#define freopen \
  if (0) freopen
#define cerr \
  if (0) cerr
#endif

#define fi first
#define se second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)

#define sqr(a) ((a)*1ll * (a))
#define sz(a) (int)a.size()
#define len(a) (int)a.length()
#define all(a) a.begin(), a.end()
#define nl '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pi;

const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

void solve() {
  string s;
  cin >> s;
  for (int i = 0; i < len(s) - 1; i++) {
    if (s[i] == s[i + 1]) {
      cout << i + 1 << ' ' << i + 2;
      return;
    }
  }
  for (int i = 0; i < len(s) - 2; i++) {
    string t = s.substr(i, 3);
    sort(all(t));
    if (t[0] == t[1] || t[1] == t[2]) {
      cout << i + 1 << ' ' << i + 3;
      return;
    }
  }
  cout << -1 << ' ' << -1;
}

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

  freopen(".in", "r", stdin);

  solve();

  return 0;
}

Measured memory_bytes: 3760
N = int(input())
A = list(map(int, input().split()))
M = 1000
stock = 0
for i in range(1, N):
  # print(i)
  if A[i-1] < A[i]:
    if stock == 0:
      stock += M // A[i-1]
      M -= stock * A[i-1]
  elif A[i-1] > A[i]:
    M += stock * A[i-1]
    stock = 0
M += stock * A[-1]
print(M)

Measured memory_bytes: 9116
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args){
    
    	try {
    		InputStreamReader isr = new InputStreamReader(System.in);
    		BufferedReader br = new BufferedReader(isr);
    		String buf = br.readLine();
    		StringTokenizer st=new StringTokenizer(buf," ");
    		int a = Integer.parseInt(st.nextToken());
    		int b = Integer.parseInt(st.nextToken());
    		int c = Integer.parseInt(st.nextToken());

    		if(a < b && b < c)
    			System.out.println("Yes");
    		else
    			System.out.println("No");

    	} catch(IOException e) {
		    System.err.println(e);
		}
    }
}

Measured memory_bytes: 17024
N,K=map(int,input().split(' '))
S=input()
left=[]
right=[]
for i in range(len(S)):
	#len(left)>len(right)のとき1区間が開いていると呼ぶ
	#開いているときにS[i]=='1'なら何もしない
	#開いているときにS[i]=='0'ならrightにi-1を追加
	#閉じているときにS[i]=='1'ならleftにiを追加
	#開いているときにS[i]=='0'なら何もしない
	if len(left)>len(right):
		if S[i]=='0':
			right.append(i-1)
	elif len(left)==len(right):
		if S[i]=='1':
			left.append(i)
#右端の通常処理を行なう
#S[-1]=='0'なら区間はすでに閉じているはずなので何もしない
#S[-1]=='1'なら区間はまだ開いているはずなのでrightにN-1を追加して閉じる
if len(left)>len(right):
	right.append(N-1)

section=[ [left[i],right[i]] for i in range(len(left)) ]

section=[[0, 0]] + section + [[N-1, N-1]]
#print(section)

length=[]

if K+1>=len(section):
	print(N)
else:
	for i in range(len(section)-K):
		length.append(section[i+K][1] - section[i][0] + 1)
	print(max(length))

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

int main(){
  long long N;
  cin >> N;
  double ans = 0.0, den = 0.0, A;
  for(int i = 0; i < N; i++){
    cin >> A;
    den += 1.0 / A;
  }
  
  ans = 1.0 / den;
  cout << setprecision(16) << ans << endl;
}

Measured memory_bytes: 256
from collections import deque
n,m=map(int,input().split())
G=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)
D=deque([0])
V=[0]*n
V[0]=1
P=[0]*n
while len(D)>0:
  x=D[0]
  D.popleft()
  for i in range(len(G[x])):
    if V[G[x][i]]==0:
      V[G[x][i]]=1
      P[G[x][i]]=x+1
      D.append(G[x][i])
print("Yes")
for i in range(1,n):
  print(P[i])

Measured memory_bytes: 98932
#include<iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void){
	int N = 0;
	string s;
	cin >> s;
	if(s[0] != 'A'){
		cout << "WA" << endl;
		return 0;
	}
	if(!(s[1]-'a' >= 0 && 'z'-s[1]>= 0)){
		N=2;
	}
	for(int i = 2; i < s.length()-1; i++){
		if(s[i] == 'C'){
			N++;
		}else if(!(s[i]-'a' >= 0 && 'z'-s[i]>= 0)){
			N=2;
		}
	}
	 if(!(s[s.length()-1]-'a' >= 0 && 'z'-s[s.length()-1]>= 0)){
			N=2;
	}
	if(N==1){
		cout << "AC" << endl;
	}else{
		cout << "WA" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <unordered_set>

#define REP(i, s, e) for (ll i = s; i < e; ++i)

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

int gcd(ll x, ll y)
{
    if (y == 0) return x;
    return gcd(y, x % y);
}

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

    int N; cin >> N;
    ll X; cin >> X;
    ll px; cin >> px;
    int result = abs(px - X);
    REP(i, 0, N - 1)
    {
        ll x;
        cin >> x;
        result = gcd(result, abs(x - px));
        px = x;
    }

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.nextLine());
		
		int[] map = new int[N + 2];
		map[0] = 0;
		map[N + 1] = 0;
		
		for (int i = 1; i <= N; i++) {
			map[i] = sc.nextInt();
		}
		
		int sum = 0;
		for (int i = 1; i < map.length; i++) {
			sum += Math.abs(map[i - 1] - map[i]);
		}
		
		for (int i = 1; i < (map.length - 1); i++) {
			int sub = Math.abs(map[i - 1] - map[i]);
			sub += Math.abs(map[i] - map[i + 1]);
			int add = Math.abs(map[i - 1] - map[i + 1]);
			System.out.println(sum - sub + add);
		}
	}
	
}

Measured memory_bytes: 63608
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

s = p[:x] + q[:y]
s.sort()
ans = sum(s)
for si, ri in zip(s, r):
    if si < ri:
        ans += ri - si

print(ans)

Measured memory_bytes: 29488
s = input()

#ACGTを*に置き換え、それ以外の大文字は?に。そして?でsplitする。最も長いものを提出

s = s.replace('A','*')
s = s.replace('C','*')
s = s.replace('G','*')
s = s.replace('T','*')
# print(s)
for i in range(len(s)):
    # print(i,'番目の文字について')
    if s[i] != '*':
        # print('*になっていないので?に置き換えます')
        if i != len(s):
            s = s[:i]+'?'+s[i+1:]
        else:
            s = s[:i]+'?'
        # print('置き換えました')
    # print(s)
# print('置き換え終了',s)
sl = s.split('?')
# print('分割',sl)
sl.sort()
# print('ソート',sl)
if sl:
    print(len(sl[-1]))
else:
    print(0)

Measured memory_bytes: 3064
/******************************************
* AUTHOR : HRITIK AGGARWAL *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define int ll
ll po(ll a, ll x,ll m){ if(x==0){return 1;}ll ans=1;ll k=1;  while(k<=x) {if(x&k){ans=((ans*a)%m);} k<<=1; a*=a; a%=m; }return ans; }
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   
    int n;
    cin>>n;
    int a[n];
    forr(i,n)
        cin>>a[i];
    int sum =0;
    forr(i,n)
        sum+=a[i];
    int mp;
    if(sum%n==0){
        mp = sum/n;
    }else{
        //sort(a,a+n);
        mp = (sum)/n;
    }

    int ans1=0,ans2=0;
    forr(i,n){
        int temp = a[i]-mp;
        temp*=temp;
        ans1+=temp;
    }
    mp++;
    forr(i,n){
        int temp = a[i]-mp;
        temp*=temp;
        ans2+=temp;
    }
    int ans=min(ans1,ans2);
    cout<<ans<<"\n";
return 0;
}

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

using namespace std;

int main()
{
	int cup[3] = {1, 0, 0}, c1, c2;
	string str;

	while(cin >> str){
		if(str[0] == 'A')         c1 = 0;
		else if(str[0] == 'B')    c1 = 1;
		else                      c1 = 2;
		
		if(str[2] == 'A')         c2 = 0;
		else if(str[2] == 'B')    c2 = 1;
		else                      c2 = 2;
	
		if(cup[c1] == 1){
			cup[c1] = 0;
			cup[c2] = 1;
		}
		else if(cup[c2] == 1){
			cup[c2] = 0;
			cup[c1] = 1;
		}
	}

	for(int i = 0; i < 3; i++){
		if(cup[i] == 1){
			if(i == 0)    cout << "A\n";
			if(i == 1)    cout << "B\n";
			if(i == 2)    cout << "C\n";

			break;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string S;
    cin >> S;
    int ans = 0;
    rep(i, S.size() / 2) {
        if (S[i] != S[S.size() - i - 1]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.15f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto L = RD;
	auto a = RDA;
	long pos = -1;
	foreach (i; 0..N-1)
	{
		if (a[i] + a[i+1] >= L)
		{
			pos = i;
			break;
		}
	}

	if (pos == -1)
		writeln("Impossible");
	else
	{
		writeln("Possible");
		foreach (i; 0..pos)
		{
			writeln(i+1);
		}
		foreach_reverse (i; pos+1..N-1)
		{
			writeln(i+1);
		}
		writeln(pos+1);
	}

	stdout.flush();
	debug readln();
}

Measured memory_bytes: 4944
#include <stdio.h>
#define N_MAX 100

int n;
int s[N_MAX * 2];

int solve(void){
	int x = n, y = n;
	int i = 0;
	int turn = 0;
	while(x && y){
		if(s[i]){
			if((int)(s[i] & 1) == (int)turn){
				if(turn){
					y--;
				}else{
					x--;
				}
				s[i] = 0;
				turn ^= 1;
			}
		}
		i++;
		if(i == n*2){
			turn ^= 1;
			i = 0;
		}
	}
	return printf("%d\n%d\n", y, x);
}

void input(void){
	int i,j;
	memset(s, -1, sizeof(int)*n*2); // LSB = 1
	for(i = 0; i < n; i++){
		scanf("%d", &j);
		s[j-1] ^= 1; // LSB = 0
	}
	return;
}

int main(void){
	while(scanf("%d", &n), n){
		input();
		solve();
	}
	return 0;
}

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

using namespace std;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD 1e9 + 7
#define PAI  3.1415
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

int main(){

  int n;
  while(cin >> n , n){
    int maxa = -inf, mina = inf;
    int sum = 0;
    rep(i,n){
      int a; cin >> a;
      chmin(mina,a);
      chmax(maxa,a);
      sum += a;
    }
    cout << (sum - maxa - mina) / (n-2) << endl;
  }

  return 0;

}



Measured memory_bytes: 3112
n,k = map(int,input().split())
num = (n // k) ** 3
if k % 2 == 0:
    if n - ((n // k) * k) < k // 2:
        print(num * 2)
    else:
        print(num + ((n // k + 1) ** 3))
else:
    print(num)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <utility>
#include <algorithm>
#include <map>
#include <cassert>
using namespace std;
#define REPP(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,a) for(int i = 0; i < (a); ++i)
#define PER(i,a) for(int i = (a) - 1; i >= 0; --i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair

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

int main() {
    int n, t;
    scanf("%d", &n);
    int a, b;
    priority_queue<int> q1;
    priority_queue<int, vector<int>, greater<int> > q2;
    ll left = 0, right = 0, cst = 0;
    REP(i, n) {
        scanf("%d", &t);
        if (t == 1) {
            scanf("%d%d", &a, &b);
            cst += b;
            if (q1.empty() || a < q1.top()) q1.push(a), left += a;
            else q2.push(a), right += a;
            if (q1.size() > q2.size() + 1) {
                int t = q1.top();
                left -= t, right += t;
                q1.pop();
                q2.push(t);
            } else if (q1.size() < q2.size()) {
                int t = q2.top();
                left += t, right -= t;
                q1.push(t);
                q2.pop();
            }
        } else {
            ll ans = cst;
            int x = q1.top();
            ans += 1LL * x * q1.size() - left;
            ans += right - 1LL * x * q2.size();
            cout << x << " " << ans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3452
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;
#define int ll

ll n, m;
pair<string, pair<int, int> > f[777];

signed main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> f[i].first >> f[i].second.first;
        f[i].second.first *= -1;
        f[i].second.second = i + 1;
    }
    sort(f, f + n);
    for (int i = 0; i < n; i++)
    {
        cout << f[i].second.second << "\n";
    }
}


Measured memory_bytes: 256
n,k = map(int,input().split())
p = []
for i in range(1,n+1):
    ti = i
    pn = 0
    while ti < k:
        ti *= 2
        pn += 1
    p.append(pn)

res = 0
for pn in p:
    res += 1/(2** pn)

print(res / n)

Measured memory_bytes: 3864
s = input()

if ("N" in s and "S" in s) and ("W" in s and "E" in s):
    print ("Yes")
elif ("N" in s and "S" in s) and (not "W" in s and not "E" in s):
    print ("Yes")
elif (not "N" in s and not "S" in s) and ("W" in s and "E" in s):
    print ("Yes")
else:
    print ("No")


Measured memory_bytes: 9112