akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin>>n;
    ll a[300010];
    ll ans=0;
    rep(i,n){
        cin>>a[i];
    }
    ll b[300010][66];
    rep(i,n+4)rep(j,65) b[i][j]=0;
    rep(i,n){
        rep(bit,60){
            if(a[i]&(1ll<<bit)){
                b[i+1][bit]=b[i][bit]+1;
            }
            else{
                b[i+1][bit]=b[i][bit];
            }
        }
    }
    rep2(i,1,n){
        rep(bit,60){
            if(a[i]&(1ll<<bit)){
                ans+=(((1ll<<bit)%MOD)*(i-b[i][bit])%MOD)%MOD;
                ans%=MOD;
                // cout<<"Yes"<<ans<<endl;
            }
            else{
                ans+=(((1ll<<bit)%MOD)*b[i][bit]%MOD)%MOD;
                ans%=MOD;
            }
        }
        // cout<<ans<<endl;
    }
    cout<<ans%MOD<<endl;
    return 0;
}

Measured memory_bytes: 157312
from collections import defaultdict
import bisect
mod = 10**9+7
N = int(input())
S = []
s = ''
for i in range(N):
    c = input()
    if s != c:
        S.append(c)
    s = c

d = defaultdict(lambda:[])
dd = defaultdict(lambda:{})
dcum = defaultdict(lambda:[0])
for i in range(len(S)):
    d[S[i]].append(i)
    dd[S[i]][i] = len(d[S[i]])-1
    dcum[S[i]].append(0)
n = len(S)
dp = [0]*(n+1)
dp[-1]=1

for i in range(n-1,-1,-1):
    l = d[S[i]]
    j = dd[S[i]][i]+1
    dp[i] += dp[i+1]
    dp[i] += dcum[S[i]][j]
    dp[i] %= mod
    dcum[S[i]][j-1] += dp[i+1]+dcum[S[i]][j]
print(dp[0])

Measured memory_bytes: 164464
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

const int mod=1e9+7;
const int MAX=200000;

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< mod >;

long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main(){
    COMinit();
    int n,a,b,c,d;cin>>n>>a>>b>>c>>d;
    modint dp[n+1][b+1];
    rep(i,n+1) rep(j,b+1) dp[i][j]=0;
    dp[0][0]=1;
    rep(i,n+1) rep(j,1,b+1){
        dp[i][j]+=dp[i][j-1];
        modint p=1;
        if(a>j)continue;
        rep(k,1,d+1){
            if(i<j*k)break;
            p*=modint(COM(i-j*(k-1),j));
            p/=modint(k);
            if(c<=k)dp[i][j]+=dp[i-j*k][j-1]*p;
        }
    }
    cout<<dp[n][b]<<endl;
}

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

int main() {
  string S;
  cin >> S;
  int K;
  cin >> K;
  int cur = 0;
  char result;
  for (int i=0; i<S.size(); ++i) {
    if (S[i] == '1') {
      ++cur;
      if (cur == K) {
        result = '1';
        break;
      }
    } else {
      result = S[i];
      break;
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multi_array.hpp>
#include <boost/range/algorithm.hpp>
#define rep(i,n) for (int i=0; i< (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> w(n);
  rep(i,n){
    cin >> w[i];
  }
  int g1,g2;
  g1 = 0;
  g2 = 0;
  rep(i,n){g2+=w[i];}
  int ans = 1000000;
  rep(i,n-1){
    g1 += w[i];
    g2 -= w[i];
    if (ans > abs(g1-g2)) ans = abs(g1-g2);
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
 int N,min,max,x,d;

	cin >> N;
	cin >>x;
	min=x;
	max=x;
  
	for(int i=1;i<N;i++){
      cin>>x;
      if(max<x) max=x;
      if(min>x) min=x;
    }
	
	d=max-min;
	cout<<d<<endl;
	return 0;
}
      

Measured memory_bytes: 768
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int T[100];
int P[100];
int X[100];

int main()
{
	int N, M, sum = 0;

	cin >> N;
	rep(i, N) {
		cin >> T[i];
		sum += T[i];
	}
	cin >> M;
	rep(i, M) cin >> P[i] >> X[i];

	rep(i, M) {
		cout << sum - T[P[i] - 1] + X[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define L long
#define endl "\n"
#define set0(x) memset(x, 0, sizeof(x))
#define setT(x) memset(x, true, sizeof(x))
#define setF(x) memset(x, false, sizeof(x))
#define For(i, init, n) for (ll int i = init; i < n; i++)
#define ___ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

const double PI = acos(-1), E = exp(1.0), EPS = DBL_EPSILON;
const ll int MOD = (ll int)1e9 + 7, N = (int)1e5;

int main()
{   
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ___
    
    string s;
    cin >> s;

    int cnt = 0, mx = 0;
    for (int i = 0; i < 3; i++)
    {
        if (s[i] == 'R')
        {
            cnt++;
        }
        else
        {
            mx = max(cnt, mx);
            cnt = 0;
        }
    }
    mx = max(cnt, mx);
    cout<< mx;
    
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int x,a,b;
  cin>>x>>a>>b;
  if(a>=b){
    cout<<"delicious"<<"\n";
  }
  else{
    b-=a;
    if(x<b){
      cout<<"dangerous"<<"\n";
    }
    else{
      cout<<"safe"<<"\n";
    }
  }
  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
	#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
	#define ll long long int
	using namespace std;
	const long double pi = 3.14159265358979323;
	const double EPS = 1e-9;
	const int N = 1e6 + 5;
	const int MOD = 1e9 + 7;


	int main(){
		fast;
		ll n,ans = 0, ct;
		cin >> n;
		for(int i = 1; i <= n; i++){
			if(i % 2 == 0) continue;
			ct = 0;
			for(int j = 1; j <= i; j++){
				if(i % j == 0) ct++;
			}
			if(ct == 8)
				ans++;
		}
		cout << ans;
		return 0;
	}

Measured memory_bytes: 256
N = input()
a = map(int, raw_input().split())
x, total = 0, sum(a)
ans = sum(map(abs, a))
for i in range(N-1):
    x = x + a[i]
    y = total - x
    if ans > abs(x-y):
        ans = abs(x-y)
print ans

Measured memory_bytes: 18440
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007

int main(){
  FIO;
  // ifstream cin("input");
  int n;
  cin>>n;
  string a;
  cin>>a;
  int i;
  for(i=0;i<min((int)a.size(),n);i++){
    cout<<a[i];
  }
  if(n<a.size()){
    cout<<"..."<<endl;
  }
  return 0;  
}

Measured memory_bytes: 3644
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

int main() {
	string s; cin >> s;
	s = s + s;
	string p; cin >> p;
	if (s.find(p) != string::npos)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 1192
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{

	int n;
	cin >> n;
	int *R = new int[n];
	for (int i = 0; i < n; i++)
		cin >> R[i];
	int Rmin = 1000000001;
	int maxv = -999999999;
	for (int i = 0; i < n-1; i++)
	{
		Rmin = min(R[i], Rmin);
		maxv = max(R[i+1]-Rmin, maxv);
	}
	cout << maxv << endl;
	delete[] R;
}


Measured memory_bytes: 3556
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>
#include <bitset>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
	long long int N, A, B;
	cin >> N >> A >> B;
	if(A % 2 == B % 2){
		cout << abs(A - B) / 2 << endl;
	}else{
		cout << min((A + B - 1) / 2, (N * 2 - A - B + 1) / 2) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    int x = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        x = x ^ a[i];
    }
    for (int i = 0; i < n; i++) {
        cout << (a[i] ^ x) << endl;
    }
}


Measured memory_bytes: 3996
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int b[200000] = {0};

int main()
{
  int n, k, kindOfNumber = 0;
  cin >> n >> k;
  int a[n], ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (b[a[i]] == 0) kindOfNumber++;
    b[a[i]]++;
  }
  sort(b, b + 200000);
  for (int i = 0; i < 200000; i++) {
    if (kindOfNumber <= k) break;
    if (b[i] == 0) continue;
    ans += b[i], kindOfNumber--;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>

 

using namespace std;

 

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


Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#define INF (long)1e9
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	long n;
	cin >> n;
	string ans = "";
	if(n == 0)
	{
		cout << 0 << endl;
		return 0;
	}
	while(n != 0)
	{
		if(n % 2 != 0)
		{
			n--;
			ans += '1';
		}
		else
			ans += '0';
		n /= -2;
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 
struct node_t {
    int key;
    struct node_t *next;
};
typedef struct node_t Node;
 
Node *enqueue(Node *node, int key) {
  Node *p, *q;
  
  if (node == NULL) {
    node = malloc(sizeof(Node));
    node->key = key;
    node->next = NULL;
    return node;
  }
  
  for (p = node; p != NULL; p = p->next) {
    q = p;
  }
  q->next = malloc(sizeof(Node));
  q->next->key = key;
  q->next->next = NULL;
  return node;
}

Node *dequeue(Node *node, int *key) {
  Node *p;
  
  if (node != NULL) {
    *key = node->key;
    p = node->next;
    free(node);
        return p;
  }
  return NULL;
}

int main(void) {
  int num, i, j, k, u;
  int way[101][101] = {{0}};
  int d[101];
  Node *q = NULL;
  
  scanf("%d", &num);
  for (i = 0; i < num; i++) {
    scanf("%d %d", &u, &k);
    for (j = 0; j < k; j++) {
      scanf("%d", &way[u-1][j]);
    }
  }
 
  d[0] = 0;
  for (i = 1; i < num; i++) {
    d[i] = -1;
  }
  q = enqueue(q, 0);
  
  while (q != NULL) {
    q = dequeue(q, &u);
    for (i = 0; i < num; i++) {
      k = way[u][i] - 1;
      if (d[k] < 0) {
	d[k] = d[u] + 1;
	q = enqueue(q, k);
      }
    }
  }
  
  for (i = 0; i < num; i++) {
    printf("%d %d\n", i+1, d[i]);
  }
  return 0;
}

Measured memory_bytes: 648
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long


int main()
{
	int N;
	cin >> N;
	if (N % 10 == 9 || (N / 10) % 10 == 9) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3616
#include <stdio.h>

int main(){
    int S;
    int h, m, s;

    scanf("%d", &S);

    h = S/3600;
    m = (S%3600)/60;
    s = (S%3600)%60;

    printf("%d:%d:%d\n", h, m, s);
    return 0;
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
const int inf=1e9;
const int mod=1e9+7;
const int maxn=1e5+10;
int n,m;
char s[2010][2010];
int l[2010][2010],r[2010][2010],u[2010][2010],d[2010][2010];
int main(){
	ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>s[i]+1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i][j]=='.') l[i][j]=l[i][j-1]+1;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=m;j>=1;j--){
			if(s[i][j]=='.') r[i][j]=r[i][j+1]+1;
		}
	}
	for(int i=n;i>=1;i--){
		for(int j=1;j<=m;j++){
			if(s[i][j]=='.') d[i][j]=d[i+1][j]+1;
		}
	}	
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i][j]=='.') u[i][j]=u[i-1][j]+1;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i][j]=='.') ans=max(ans,l[i][j]+r[i][j]+d[i][j]+u[i][j]-3);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 67328
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

ll gcd(ll, ll);

int main()
{
	ll A, B, C, D;
	cin >> A >> B >> C >> D;
	ll g = gcd(C, D);
	ll l = C * D / g;
	ll n_B = B - B / C - B / D + B / l;
	ll n_A = (A-1) - (A - 1) / C - (A - 1) / D + (A - 1) / l;
	ll ans = n_B - n_A;

	cout << ans;
	return 0;
}

ll gcd(ll a, ll b)
{
	ll g = 1;
	if (a < b) 
	{
		ll c = b;
		b = a;
		a = c;
	}
	while (true)
	{
		if (a % b == 0)
		{
			g = b;
			break;
		}
		a %= b;
		ll c = b;
		b = a;
		a = c;
	}
	return g;
}

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

long gcd(long a, long b) {
	if (a < b) swap(a, b);
	while (b > 0) {
		long c = a % b;
		a = b;
		b = c;
	}
	return a;
}

int main(void) {
	long A, B;
	scanf("%ld%ld", &A, &B);

	printf("%ld", A * B / gcd(A, B));

	return 0;
}


Measured memory_bytes: 3828
cards = list()
suit = ['S', 'H', 'C', 'D']
n = int(input())
for i in range(n):
    s,r = input().split()
    r = int(r)
    if s == "S": cards.append(0 + r)
    elif s == "H": cards.append(13 + r)
    elif s == "C": cards.append(26 + r)
    elif s == "D": cards.append(39 + r)
for i in range(1,53):
    if not (i in cards):
        print(suit[(i-1)//13], (i-1)%13+1)


Measured memory_bytes: 5612
N,M = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
s = 0
cnt = { 0 => 1 }
A.each{ |a|
  s = (s + a) % M
  cnt[s] = (cnt[s] || 0) + 1
}
puts cnt.values.map{ |c| c*(c-1)/2 }.inject(:+)

Measured memory_bytes: 13060
import java.util.Scanner;
public class Main {
	static int id;
static int minus(int a) {
	 if(a==0)return 2;
	 if(a==2)return 0;
	 return 1;
}

static int seki(int a,int b) {
	 if(a==0 || b==0) return 0;
	 if(a==2 && b==2) return 2;
	 return 1;
}

static int plus(int a,int b) {
	 if(a==2||b==2) return 2;
	 if(a==1||b==1) return 1;
	 return 0;
}

static int lastInd(String str,char ch1,char ch2) {
	 int n = 0;
	 for(int i=str.length()-1;i>0;i--) {
	  char c = str.charAt(i);
	  if(c=='(')
	   n++;
	  if(c==')')
	   n--;
	  if((ch1==c||ch2==c) && n==0)
	   return i;
	 }
	 return -1;
}

static int parse(String str) {
	 if(id==str.length())return 0;
	 if(Character.isDigit(str.charAt(id))) {
		 id++;
		  return Integer.parseInt(String.valueOf(str.charAt(id-1)));
	 }
	 if(str.charAt(id)=='-') {
		 id++;
		 return minus(parse(str));
	 }
	 if(str.charAt(id)=='(') {
		 id++;
		 int a = parse(str);
		 char c = str.charAt(id);
		 id++;
		 int b = parse(str);
		 id++;
		 if(c=='+') return plus(a,b);
		 else if(c=='*')return seki(a,b);
	 }
	 return 0;
 
}

public static void main(String[] args) {
	 Scanner sc = new Scanner(System.in);
	 while(sc.hasNext()) {
	  String str = sc.next();
	  String str1 = str;
	  if(str.equals(".")) break;
	 
	  int cnt = 0;
	   for(int p=0;p<3;p++) {
	    for(int r=0;r<3;r++) {
	     for(int q=0;q<3;q++) {
	    	 str1 = str1.replaceAll("--","");
	    	 str1 = str.replace("P", String.valueOf(p)).replace("R", String.valueOf(r)).replace("Q", String.valueOf(q));
	    	 id = 0;
		     if(parse(str1)==2) {
		   	   cnt++;
		      }     
		      str1 = str;
	     }
	    }
	   }
	   System.out.println(cnt);
	  }	 
	}
}


Measured memory_bytes: 44904
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
typedef long long ll;

int main()
{
	int n;
	cin >> n;
	rep(i,n)
	{
		int hoge;cin>>hoge;
		int u; cin>>u;
		if(u==0)
		{
			rep(j,n)
			{
				if(j)cout<<" ";
				cout<<0;
			}
			cout<<endl;
			continue;
		}else
		{
		queue<int> v;
		rep(j,u){int a;cin>>a;v.push(a);}
		int itr=0;
		rep(j,n)
		{
			if(j)cout<<" ";
			if( (v.front()-1)==j)
			{
				cout<<1;
				v.pop();
			}
			else
			{
				cout<<0;
			}
		
			
			
		
		}
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3088
import java.util.Scanner;	//Scannerクラス：Java標準入力を取得する

class Main{	//三つの整数の大小を比べる
	public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {	//Scanerクラスを変数scで使えるようにする
            int a = sc.nextInt();	//二つの変数a,b,cに整数を入力
            int b = sc.nextInt();
            int c = sc.nextInt();

            //かつ(&&),または(||)を用いたif文
            if(a < b && b < c) {			//bがaより大きくcがaより大きい場合
            	System.out.println("Yes");
            }else { 						//上記以外の場合
            	System.out.println("No");
            }
        }
    }
 }



Measured memory_bytes: 26332
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime> 
#include <memory.h>
#include <assert.h>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18 + 1;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> v(M, 0);
    for(int i = 0; i < N; i++) {
        int K;
        cin >> K;
        for(int j = 0; j < K; j++) {
            int a;
            cin >> a;
            a--;
            v[a]++;
        }
    }

    ll ans = 0;
    for(int i = 0; i < M; i++) {
        if(v[i] == N) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Node{
  int key;
  struct Node *right,*left,*parent;
};

struct Node *root,*NIL;

struct Node * find(struct Node *u,int k){
  while(u!=NIL && k!=u->key){
    if(k < u->key) u=u->left;
    else u=u->right;
  }
  return u;
}

void insert(int k){
  struct Node *y=NIL;
  struct Node *x=root;
  struct Node *z;
  z=(struct Node *)malloc(sizeof(struct Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
  while(x!=NIL){
    y=x;
    if(z->key < x->key) x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL) root=z;
  else {
    if(z->key < y->key) y->left=z;
    else y->right=z;
  }
}

void inorder(struct Node *u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(struct Node *u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main()
{
  struct Node *t;
  char str1[]="insert";
  char str2[]="print";
  int n,i,x;
  char com[1000];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",com);
    if(com[0]=='f'){
      scanf("%d",&x);
      t=find(root,x);
      if(t!=NIL) printf("yes\n");
      else printf("no\n");
    }
    else if(strcmp(com,str1)==0){
      scanf("%d",&x);
      insert(x);
    }
    else if(strcmp(com,str2)==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 19372
MOD = 10 ** 9 + 7
modinv = lambda a, mod=MOD: pow(a, mod - 2, mod)

N = int(input())
X = list(map(int, input().split()))
Acc = [X[-1] - X[i] for i in range(N - 2, -1, -1)]

fac = 1
for i in range(2, N):
    fac = (fac * i) % MOD
prob = [fac] * (N - 1)
for i in range(N - 1):
    prob[i] = (prob[i] * modinv(N - 1 - i)) % MOD

ans = 0
for i in range(N - 1):
    ans += Acc[i] * prob[i]
    ans %= MOD
print(ans)


Measured memory_bytes: 15184
#include <iostream>
#include <string>
using namespace std;
int main() {
	string S; cin >> S;
	bool ans = true;
	for (int i = 0; i < S.size(); i++) {
		if ((S.at(i) == 'R' && i % 2 != 0) || (S.at(i) == 'L' && i % 2 == 0)) {
			ans = false;
			break;
		}
	}
	cout << (ans == true ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        var rdx = Console.ReadLine().Split();
        var r = int.Parse(rdx[0]);
        var d = int.Parse(rdx[1]);
        var x = int.Parse(rdx[2]);

        for (int i = 0; i < 10; i++)
        {
            x = r * x - d;
            Console.WriteLine(x);
        }
    }
}


Measured memory_bytes: 11092
// 2017/05/27 Tazoe

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

class Stack{
private:
	int sp;			// ????????????????????????
	int S[100];		// ?????????????????????
public:
	Stack()			{  sp = 0;  }
	bool isFull() const	{  return (sp==100);  }
	bool isEmpty() const	{  return (sp==0);  }
	void push(int d);
	int top();
	void pop();
};

void Stack::push(int d)
{
	if(isFull())
		return;		// ??????

	S[sp++] = d;		// ???????????????????????????????????????
}

int Stack::top()
{
	if(isEmpty())
		return -1;	// ??°??????????????????

	return S[sp-1];		// ??????????????????
}

void Stack::pop()
{
	if(isEmpty())
		return;		// ???

	sp--;			// ??????????????????????????????????????????
}


int main()
{
	Stack s;

	string expr;
	getline(cin, expr);	// 1???????????????

	istringstream is(expr);	// ????????????????????????

	while(!is.eof()){
		string op;
		is >> op;

		int tmp1, tmp2;

		switch(op[0]){
		case '+':
			tmp1 = s.top();  s.pop();
			tmp2 = s.top();  s.pop();
			s.push(tmp2+tmp1);
			break;
		case '-':
			tmp1 = s.top();  s.pop();
			tmp2 = s.top();  s.pop();
			s.push(tmp2-tmp1);
			break;
		case '*':
			tmp1 = s.top();  s.pop();
			tmp2 = s.top();  s.pop();
			s.push(tmp2*tmp1);
			break;
		default:
			istringstream is2(op);
			is2 >> tmp1;
			s.push(tmp1);
			break;
		}
	}

	cout << s.top() << endl;

	return 0;
}

Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
using graph = vector<vector<int>>;

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> num(n);
	rep(i,n){
		cin >> num.at(i);
	}
	set<int> st;
	sort(num.begin(), num.end());
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(st.count(num[i])) continue;
		else{
			int cnt = 1;
            if(i+1 < n && num[i] != num[i+1]) ans++;
            if(i == n-1) ans++;
			while(num[i] * cnt <= 1000000){
				st.insert(num[i]*cnt);
				cnt++;
			}
		}
	}
	cout << ans << endl;
} 





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

vector<ll> dp((1 << 12) + 1, 1e10);

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    vector<int> b(m);
    vector<int> c(m);
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        int mask = 0;
        for (int j = 0; j < b[i]; j++) {
            int s;
            cin >> s;
            c[i] |= 1 << (s - 1);
        }
    }

    dp[0] = 0;
    for(int s = 0; s < (1<<n); s++) {
        for(int j = 0; j < m; j++) {
            int t = s | c[j];
            dp[t] = min(dp[t], dp[s] + a[j]);
        }
    }

    ll res = dp[(1<<n)-1];
    if (res == 1e10)
        res = -1;
    cout << res << 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;

using ll = long long;

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


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

int main() {
    int n;
    cin >> n;
    int h[n];
    rep(i,n)cin >> h[i];

    int now = h[0]-1;

    srep(i,1,n){
        if(h[i]<now){
            cout << "No" << endl;
            return 0;
        }else if(now<h[i]){
            now = h[i]-1;
        }
    }
    cout << "Yes" << endl;
    return 0;
}
 
 


Measured memory_bytes: 640
#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>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (int)(n); i++
using namespace std;

int main() {
	int n,cnt=0;
	cin>>n;cout<<n<<':';
	const int num=32000;
	vector<int> a(num+1,1);a[0]=0;a[1]=0;
	for (int i = 2; i * i <= num; i++) {
		if (a[i] == 1) {
			for (int j = i * i; j <= num; j += i) {
				a[j] = 0;
			}
		}
	}
	for (int i = 2; i < num; i++) {
		while (a[i] == 1 && n % i == 0) {
			cout << ' ' << i;
			n /= i;
			cnt++;
		}
	}
	if (cnt == 0) {
		cout << ' ' << n;
	}
	cout << endl;
}




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

int main(int argc, const char * argv[]) {
    // insert code here...
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    
    cout << min(A, B) + min(C, D) << endl;
    
    return 0;
}


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

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

  int min = 1;

  for(int i = 0; i < n; i++) {
      if(min*2 > min + k) {
          min = min + k;
      } else {
          min = 2*min;
      }
  }

  cout << min << endl;




}


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

using namespace std;

int main(){
	string a, b, c; cin >> a >> b >> c;
	if(*a.rbegin() == *b.begin() && *b.rbegin() == *c.begin()) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
    if i not in d:
        d[i] = 1
    else:
        d[i] += 1
for j in range(1, n+1):
    if j in d:
        print(d[j])
    else:
        print(0)

Measured memory_bytes: 33440
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int n, m; cin >> n >> m;
    map<int, int> ma;
    rep(i, n)
    {
        int k; cin >> k;
        rep(j, k)
        {
            int a; cin >> a;
            ma[a]++;
        }
    }

    int ans = 0;
    for(auto v : ma)
    {
        if (v.second == n) ans++;
    }
    cout << ans << endl;
}

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

int main() {

    int a, b;

    cin >> a >> b;

    if ( a > b )  cout << "a > b" << endl;
    if ( a < b )  cout << "a < b" << endl;
    if ( a == b )  cout << "a == b" << endl;

    return 0;
}

Measured memory_bytes: 3100
S = list(input())
S_con = []
ctr = 1

for i in range(len(S)-1):
    if (S[i] != S[i + 1]):
        ctr += 1
    else:
        S_con.append(ctr)
        ctr = 1

if (ctr > 1):
    S_con.append(ctr)
else:
    S_con.append(1)

even = sum(S_con[0::2])
odd=sum(S_con[1::2])
answer = min(even, odd)
print(answer)

Measured memory_bytes: 5036
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int ans = 0;
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		while(true) {
			boolean flag = false;
			for(int i = 0; i < n; i++) {
				if(a[i]%2 == 1) {
					flag = true;
				}
			}
			if(flag) {
				break;
			}
			ans++;
			for(int j = 0; j < n; j++) {
				a[j] = a[j]/2;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21972
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End

/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template

signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cini(a);  Cins(s);
    if(a>=3200) cout << s << nn;
    else cout << "red" << nn;
    return 0;
}

Measured memory_bytes: 256
import itertools
l = list()
for i in range(5):
    l.append(int(input()))
it = list(itertools.combinations(l, 2))
k = int(input())
for i in it:
    if abs(i[0] - i[1]) <= k:
        continue
    else:
        print(":(")
        quit()
print("Yay!")

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

int main(){
  double a,b,h,m,angle,pi=3.14159265358979;
  cin>>a>>b>>h>>m;
  angle = 2*pi*abs(h/12+m/12/60-m/60);
  cout<<setprecision(10)<<sqrt(a*a+b*b-2*a*b*cos(min(2*pi-angle,angle)));
}

Measured memory_bytes: 4148
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] a = sc.next().toCharArray();
        char[] b = sc.next().toCharArray();

        char[] c = new char[a.length + b.length];

        StringBuilder sb = new StringBuilder(a.length + b.length);
        sb.append(a);
        sb.append(b);

        int num = Integer.parseInt(sb.toString());

        String ans;

        ans = (Math.sqrt(num) % 1 == 0) ? "Yes" : "No";

        System.out.println(ans);

    }

}


Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
using std::min;
using std::max;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << /*#X <<":" <<*/X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e9;
// typedef std::pair<int,int> P;
struct edge {int to,cost;};
#define VMAX 100000

ll N,K,ans=0;
ll A[2*100010],S[2*100010],X[2*100010];


int main(){
    std::ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,N){
        cin>>A[i];
    }
    S[0]=A[0];
    REP(i,N){
        S[i+1]+=S[i];
    }
    bool ch=true;
    int l=0,r=0;
    REP(i,20){
        if(A[0]&(1<<i))X[i]++;
    }
    while(ch){
        ch=false;
        bool f=true;
        REP(i,20){
            if(X[i]>1)f=false;
        }
        if(!f){
            REP(i,20){
                if(A[l]&(1<<i))X[i]--;
            }
            if(l==r&&r!=N-1){r++;ch=true;}
            if(l!=N-1){l++;ch=true;}
        }else{
            ans+=1+r-l;
            if(r!=N-1){
                r++;ch=true;
                REP(i,20){
                    if(A[r]&(1<<i))X[i]++;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3456
using static System.Console;
using static System.Convert;

class Program
{
    static void Main(string[] args)
    {
        var str = ReadLine();
        var result = "";
        for(var i = 0; i < str.Length; i++)
        {
            switch (str.Substring(i, 1))
            {
                case "0":
                    result += "0";
                    break;
                case "1":
                    result += "1";
                    break;
                case "B":
                    if(result.Length!=0)
                    result=result.Substring(0,result.Length-1);
                    break;
            }
        }

        WriteLine(result);
    }
}


Measured memory_bytes: 11092
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

count = 0
for i in range(n):
    if a[i] < b[i]:
        count += a[i]
        b[i] -= a[i]
        if a[i+1] < b[i]:
            count += a[i+1]
            a[i+1] = 0
        else:
            count += b[i]
            a[i+1] -= b[i]
    else:
        count += b[i]

print(count)


Measured memory_bytes: 18624
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int n = 0,count = 0;
	boolean check = true;

	while(sc.hasNext()){
	    n = sc.nextInt();
	    count = 0;//テ・ツ按敕ヲツ慊淌・ツ個?
	    check = true;

	    if(n==0) break;

	    for(int i = n+1;i<=2*n;i++){
		check = true;
		for(int j = 2;j*j<=i;j++){
		    if(i%j == 0) check = false;
		}
		
		if(check) count++;
	    }

	    System.out.println(count);
	}

    }
}

Measured memory_bytes: 20088
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
using namespace std;
#define rep(i, j, n) for (int i = j; i < (n); ++i)
#define rrep(i, j, n) for (int i = (n)-1; j <= i; --i)

int dx[4]{-1, 1, 0, 0};
int dy[4]{0, 0, -1, 1};

void update(int s, int n, vector<bool>& exist, vector<vector<int>>& d) {
  queue<int> q;
  q.push(s);
  while (q.size()) {
    int y = q.front() / n;
    int x = q.front() % n;
    q.pop();
    rep(i, 0, 4) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (0 <= nx && nx < n && 0 <= ny && ny < n &&
          d[ny][nx] > d[y][x] + exist[y * n + x]) {
        // d[ny][nx]からはd[y][x]を通った方がいいよ
        q.push(ny * n + nx);
        d[ny][nx] = d[y][x] + exist[y * n + x];
      }
    }
  }
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n * n);
  for (int& x : a) {
    cin >> x;
    --x;
  }

  vector<vector<int>> need(n, vector<int>(n));
  vector<bool> exist(n * n, true);
  rep(i, 0, n) rep(j, 0, n) need[i][j] = min({i, j, n - 1 - i, n - 1 - j});

  int ans = 0;
  for (int& x : a) {
    ans += need[x / n][x % n];
    exist[x] = false;
    update(x, n, exist, need);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5372
#include<bits/stdc++.h>
#include<math.h>
#include <stdio.h>
#include<vector>
#include<deque>
#include<stdlib.h>
//#include <algorithm>
#include<set>
#include <limits>
#include<iomanip>
#include<string>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define ll long long
#define d_5 100000
#define d9_7 1000000007
int main(void){
  int n;
  cin >> n;
  vector<double> v;
  double tmpv;
  rep(i,n){
    cin>>tmpv;
    v.push_back(tmpv);
  }
  sort(v.begin(),v.end());
  double sum=v[0];
  rep(i,n-1){
    sum=(sum+v[i+1])/2;
  }
  std::cout << std::fixed;
  cout << setprecision(10)<< sum;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <string>
using namespace std;
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
typedef long long ll;
const int INF = numeric_limits<int>::max();
const int MOD = (1e9 + 7);


int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int x=C-A; int y=D-B;
  string S = "";
  rep(i, x){
    S.push_back('R');
  }
  rep(i, y){
    S.push_back('U');
  }
  rep(i, x){
    S.push_back('L');
  }
  rep(i, y+1){
    S.push_back('D');
  }
  rep(i, x+1){
    S.push_back('R');
  }
  rep(i, y+1){
    S.push_back('U');
  }
   S.push_back('L');
   S.push_back('U');
  rep(i, x+1){
    S.push_back('L');
  }
  rep(i, y+1){
    S.push_back('D');
  }
 S.push_back('R');
  cout << S << endl;
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;//b
int main()
{
    int countt=0;

    char a[3],b[3],c[3];
    for(int i=0;i<3;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<3;i++)
    {
        cin>>b[i];
    }
    c[0]=b[2];
    c[1]=b[1];
    c[2]=b[0];

    for(int i=0;i<3;i++)
    {
        if(a[i]>='a' && a[i]<='z' && c[i]>='a' && c[i]<='z'){
        if(a[i]==c[i]) countt++;
        }
        else countt=-1;
    }
    if(countt==3) cout<<"YES\n";
    else if(countt>=0 && countt<3) cout<<"NO\n";
    return 0;
}


Measured memory_bytes: 256
// C++ code to find number of distinct numbers 
// in a subarray 
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long
const ll MAX = 1000001; 

// structure to store queries 
struct Query 
{ 
    ll l, r, idx; 
}; 

// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
    return x.r < y.r; 
} 

// updating the bit array 
void update(ll idx, ll val, ll bit[], ll n) 
{ 
    for (; idx <= n; idx += idx&-idx) 
        bit[idx] += val; 
} 

// querying the bit array 
ll query(ll idx, ll bit[], ll n) 
{ 
    ll sum = 0; 
    for (; idx>0; idx-=idx&-idx) 
        sum += bit[idx]; 
    return sum; 
} 

void answeringQueries(ll arr[], ll n, Query queries[], ll q) 
{ 
    // initialising bit array 
    ll bit[n+1]; 
    memset(bit, 0, sizeof(bit)); 

    // holds the rightmost index of any number 
    // as numbers of a[i] are less than or equal to 10^6 
    ll last_visit[MAX]; 
    memset(last_visit, -1, sizeof(last_visit)); 

    // answer for each query 
    ll ans[q]; 
    ll query_counter = 0; 
    for (ll i=0; i<n; i++) 
    { 
        // If last visit is not -1 update -1 at the 
        // idx equal to last_visit[arr[i]] 
        if (last_visit[arr[i]] !=-1) 
            update (last_visit[arr[i]] + 1, -1, bit, n); 

        // Setting last_visit[arr[i]] as i and updating 
        // the bit array accordingly 
        last_visit[arr[i]] = i; 
        update(i + 1, 1, bit, n); 

        // If i is equal to r of any query store answer 
        // for that query in ans[] 
        while (query_counter < q && queries[query_counter].r == i) 
        { 
            ans[queries[query_counter].idx] = 
                    query(queries[query_counter].r + 1, bit, n)- 
                    query(queries[query_counter].l, bit, n); 
            query_counter++; 
        } 
    } 

    // print answer for each query 
    for (ll i=0; i<q; i++) 
        cout << ans[i] << endl; 
} 

// driver code 
int main() 
{ 
    ll n,q;
    cin>>n>>q;
    ll a[n];
    for(ll i=0;i<n;i++)
        cin>>a[i];
    Query queries[q];
    for(ll i=0;i<q;i++)
    { 
        ll l1,r1;
        cin>>l1>>r1;
        l1--;r1--;
        queries[i].l = l1; 
        queries[i].r = r1; 
        queries[i].idx = i;
    } 
    sort(queries, queries+q, cmp); 
    answeringQueries(a, n, queries, q); 
    return 0; 
} 


Measured memory_bytes: 35000
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.Int (Int64)
import Data.Bifunctor (first)
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as U

-- skipping 3 (U.fromList [0,1,2,3,4,5]) = [0,3]
skipping :: (U.Unbox a) => Int -> U.Vector a -> U.Vector a
skipping !d !v = U.generate ((U.length v + d - 1) `quot` d) $ \i -> v U.! (i * d)

main = do
  n <- readLn
  ss <- U.unfoldrN n (readInt64 . BS.dropWhile isSpace) <$> BS.getLine
  let ts = U.zipWith (+) ss (U.reverse ss)
  print $ maximum $ [ U.maximum $ U.scanl (+) 0 (skipping d $ U.take l ts)
                    | d <- [1..n-2]
                    , let l | (n - 1) `rem` d == 0 = min (n `quot` 2) (n - 1 - d)
                            | otherwise = n - 1 - d
                    ]

readInt64 :: BS.ByteString -> Maybe (Int64, BS.ByteString)
readInt64 s = first fromIntegral <$> BS.readInt s


Measured memory_bytes: 7164