akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

//const ll INF = 1e15;
const ll MOD = 1e9 + 7;


int main(){
	ll N, K;
	cin >> N >> K;
	vll X, Y, C;
	ll i, j;
	for (i = 0; i < N; i++){
		ll x, y;
		char c;
		cin >> x >> y;
		cin >> c;
		if (c == 'B'){
			C.push_back(1);
		}
		else{
			C.push_back(0);
		}
		x = x % (2 * K);
		y = y % (2 * K);
		X.push_back(x);
		Y.push_back(y);
	}
	vector<vector<pair<ll, bool>>> H(2 * K);
	vector<vector<pair<ll, bool>>> V(2 * K);
	for (i = 0; i < N; i++){
		ll x = X[i];
		ll y = Y[i];
		if (C[i] == 1){
			H[y].push_back(make_pair(x, 1));
			V[x].push_back(make_pair(y, 1));
		}
		else{
			H[y].push_back(make_pair(x, 0));
			V[x].push_back(make_pair(y, 0));
		}
	}
	ll tmp = 0;
	for (i = 0; i < K; i++){
		for (auto p : V[i]){
			if (p.first < K && p.second == 0){
				tmp++;
			}
			else if (p.first >= K && p.second == 1){
				tmp++;
			}
		}
	}
	for (i = K; i < 2 * K; i++){
		for (auto p : V[i]){
			if (p.first < K && p.second == 1){
				tmp++;
			}
			else if (p.first >= K && p.second == 0){
				tmp++;
			}
		}
	}
	ll ok_min = tmp;
	ll ok_max = tmp;
	ll now = tmp;
	for (i = 0; i < K; i++){
		for (j = 1; j < K; j++){
			for (auto p : H[j - 1]){
				if ((p.first - i >= 0 && p.first < K + i) && (p.second == 1)){
					tmp++;
				}
				else if ((p.first - i < 0 || p.first >= K + i) && (p.second == 0)){
					tmp++;
				}
				else{
					tmp--;
				}
			}
			for (auto p : H[j + K - 1]){
				if ((p.first - i >= 0 && p.first < K + i) && (p.second == 0)){
					tmp++;
				}
				else if ((p.first - i < 0 || p.first >= K + i) && (p.second == 1)){
					tmp++;
				}
				else{
					tmp--;
				}
			}
			ok_min = min(ok_min, tmp);
			ok_max = max(ok_max, tmp);
		}
		tmp = now;
		if (i == K - 1){
			break;
		}
		for (auto p : V[i]){
			if ((p.first < K) && (p.second == 1)){
				tmp++;
			}
			else if ((p.first >= K) && (p.second == 0)){
				tmp++;
			}
			else{
				tmp--;
			}
		}
		for (auto p : V[i + K]){
			if ((p.first < K) && (p.second == 0)){
				tmp++;
			}
			else if ((p.first >= K) && (p.second == 1)){
				tmp++;
			}
			else{
				tmp--;
			}
		}
		ok_min = min(ok_min, tmp);
		ok_max = max(ok_max, tmp);
		now = tmp;
	}
	ll ans = max(ok_max, N - ok_min);
	cout << ans << endl;

	return 0;
}

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

int main(){
  ll n,k;
  cin>>n>>k;
  ll vec[110000]={};
  for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    vec[a]+=b;
  }
  ll sum=0;
  for(int i=0;i<110000;i++){
    sum+=vec[i];
    if(sum>=k){
      cout<<i<<endl;
      return 0;
    }
  }
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

template<class T>
class SegmentTree {
    using Func = std::function<T(T, T)>;
    private:
        const Func F;
        const T DEF;
        int N;
        std::vector<T> dat;
    public:
        SegmentTree(int n, const Func f, const T def) : F(f), DEF(def) {
            N = 1;
            while (N < n) N *= 2;
            dat.assign(2*N, DEF);
        }
        // a is 0-indexed
        void set(int a, const T v) { dat[a+N] = v; }
        void build() { for (int i=N-1; i>0; --i) dat[i] = F(dat[2*i], dat[2*i+1]); }
        // a is 0-indexed
        void update(int a, const T v) {
            int cur = a + N;
            dat[cur] = v;
            while ((cur /= 2) > 0) dat[cur] = F(dat[2*cur], dat[2*cur+1]);
        }
        // return value of [a, b)
        // a and b are 0-indexed
        T get(int a, int b) const { return get(a, b, 1, 0, N); }
        T get(int a, int b, int k, int l, int r) const {
            if (b <= l || r <= a) return DEF;
            if (a <= l && r <= b) return dat[k];
            T vleft = get(a, b, 2*k, l, (l+r)/2);
            T vright = get(a, b, 2*k+1, (l+r)/2, r);
            return F(vleft, vright);
        }
        // a is 0-indexed
        T at(int a) const { return dat.at(a+N); }
};

void solve() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i=0; i<N; ++i) cin >> A[i];

    int len = 300001;
    SegmentTree<int> st(len, [](int a, int b){return max(a, b);}, 0);
    for (int i=0; i<len; ++i) st.set(i, 0);
    st.build();
    for (int x : A) {
        int maxi = st.get(max(0, x-K), min(len, x+K+1));
        st.update(x, maxi+1);
    }
    cout << st.get(0, len) << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 8492
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

int x,a,b;

int main(){
    scanf("%d %d %d",&x,&a,&b);
    printf("%d\n",(x-a)%b);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s[11];
int n,m,k,ans;
int fa[11],cnt[11];
inline void chk(int v)
{
	int fff=0;
	for(int j=1;j<=n;j++) cnt[j]=0;
	fa[1]=1;for(int i=2;i<=n;i++) if(v&(1<<(i-2))) fa[i]=fa[i-1];else fa[i]=i,fff++;
	for(int i=0;i<m;i++)
	{
		for(int j=1;j<=n;j++) cnt[fa[j]]+=s[j][i]=='1';
		bool flag=0;
		for(int j=1;j<=n;j++) if(cnt[j]>k) {flag=1;break;}
		if(flag)
		{
			for(int j=1;j<=n;j++) cnt[j]=0;
			for(int j=1;j<=n;j++) cnt[fa[j]]+=s[j][i]=='1';
			flag=0;
			for(int j=1;j<=n;j++) if(cnt[j]>k) {flag=1;break;}
			if(flag) return;
			fff++;
		}
	}
	ans=min(ans,fff);
}
int main()
{
	cin>>n>>m>>k;ans=n+m-2;
	for(int i=1;i<=n;i++) cin>>s[i];
	chk(0);
	for(int i=0;i<(1<<(n-1));i++) chk(i);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


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

	int N;
	cin >> N;
	int mn = N + 1;
	int res = 0;
	REP(i, N) {
		int p;
		cin >> p;
		if (p < mn) {
			res++;
			mn = p;
		}
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0 ; i < (int)(n) ; i++)
typedef long long ll;
////////////////////////////////////////////////
int main(){
    int a, b;
    cin >> a >> b;
    int ans;
    ans = max(a+b, a-b);
    ans = max(ans, a*b);
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <map>
#include <iomanip>

using namespace std;



int main() 
{
	vector<int> all;
	for (int i = 0; i < 3; i++)
	{
		int t;
		cin >> t;
		all.push_back(t);
	}
	sort(all.begin(), all.end());
	int start = all[0];
	int ans = 0;
	for (int i = 1; i < 3; i++)
	{
		ans += abs(all[i] - start);
		start = all[i];
	}
	cout << ans << "\n";







}

Measured memory_bytes: 256
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define VI vector<int>
#define VL vector<lint>
#define VB vector<bool>
#define VC vector<char>
#define VS vector<string>
#define VVI vector<VI>
#define VVL vector<VL>
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define REPR(i, x, n) for(int i = n - 1 ; i >= x ; i--)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) REPR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int pow(int x, int n){
    int t = 1;
    while(n > 0){
        if(n & 1){
            t *= x;
        }
        x *= x;
        n >>= 1;
    }
    return t;
}

int main(){
    string s;
    cin >> s;
    VB a(s.size() - 1);
    int l = pow(2, s.size() - 1);
    lint ans = 0;
    rep(i, l){
        int tmp = i, cnt = 0;
        string res = s;
        while(tmp > 0){
            a[cnt] = (tmp % 2);
            tmp /= 2;
            cnt++;
        }
        cnt = 0;
        rep(j, a.size()){
            if(a[j]){
                res.insert(res.begin() + j + 1 + cnt, '+');
                cnt++;
            }
        }
        lint k = 1;
        repr(j, res.size()){
            if(res[j] == '+'){
                k = 1;
            }else{
                ans += (res[j] - '0') * k;
                k *= 10;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int val = 0;
    int c = 0;
    scanf("%d",&val);
    while(val != 0){
        if((val % 10) == 2){
            c++;
        }
        val = val /10;
    }
    printf("%d\n",c);
    return 0;
}

Measured memory_bytes: 128
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


char TO(ll x,ll y){
    if(x==1 && y==1){return 'R';}
    if(x==1 && y==-1){return 'U';}
    if(x==-1 && y==-1){return 'L';}
    return 'D';
}



int main(){
    ll n;
    cin>>n;
    vector<pll> A(n);
    vector<pll> B(n);
    ll count=0;
    for(int i=0;i<n;i++){
        cin>>A[i].first>>A[i].second;
        B[i].first=A[i].first+A[i].second;
        B[i].second=A[i].first-A[i].second;
        if((A[i].first+A[i].second)%2){count++;}
    }
    if(count!=0 && count!=n){cout<<-1<<endl; return 0;}
    if(count==n){
        vector<ll> d(35);
        d[0]=1;
        for(int i=1;i<35;i++){
            d[i]=d[i-1]<<1;
        }
        reverse(d.begin(),d.end());
        cout<<35<<endl;
        for(int i=0;i<35;i++){
            cout<<d[i];
            if(i!=34){cout<<" ";}
        }
        cout<<endl;
        for(int i=0;i<n;i++){
            ll xs=1,ys=1;
            if(B[i].first<0){B[i].first*=-1; xs*=-1;}
            if(B[i].second<0){B[i].second*=-1; ys*=-1;}
            ll X=d[0]<<1; X--;
            ll Y=d[0]<<1; Y--;
            X^=B[i].first;
            Y^=B[i].second;
            cout<<TO(xs,ys);
            for(int t=34;t>0;t--){
                cout<<TO(xs*(X>>t&1?-1:1),ys*(Y>>t&1?-1:1));
            }
            cout<<endl;
        }
    }
    else{
        vector<ll> d(35);
        d[0]=1;
        for(int i=1;i<35;i++){
            d[i]=d[i-1]<<1;
        }
        reverse(d.begin(),d.end());
        cout<<36<<endl;
        cout<<1<<" ";
        for(int i=0;i<35;i++){
            cout<<d[i];
            if(i!=34){cout<<" ";}
        }
        cout<<endl;
        for(int i=0;i<n;i++){
            ll xs=1,ys=1;
            if(B[i].first<0){B[i].first*=-1; xs*=-1;}
            if(B[i].second<0){B[i].second*=-1; ys*=-1;}
            ll X=d[0]<<1; X--;
            ll Y=d[0]<<1; Y--;
            B[i].first++;
            B[i].second++;
            X^=B[i].first;
            Y^=B[i].second;
            cout<<TO(xs*-1,ys*-1);
            cout<<TO(xs,ys);
            for(int t=34;t>0;t--){
                cout<<TO(xs*(X>>t&1?-1:1),ys*(Y>>t&1?-1:1));
            }
            cout<<endl;
        }
    }
    
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    int point = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] == 1) point = i;
    }
    int res = 0;
    for(int i = 0; i < n-1; i += k-1){
        //if(i+1 == point) i++;
        //if(i == n-1) break;
        res++;
    }
    cout << res << endl; 
    return 0;
}

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

int main()
{
    int a,b,c,d;
    while(~scanf("%d",&a))
    {
        if(a==1)
            printf("Hello World\n");
        else
        {
            scanf("%d %d",&b,&c);
            printf("%d\n",b+c);
        }
    }
    return 0;
}

Measured memory_bytes: 128
package main
import (
   "fmt"
   "os"
   "bufio"
   "strconv"
)
var sc = bufio.NewScanner(os.Stdin)

func main() {
  sc.Split(bufio.ScanWords)
  var result []string
  for {
    n := nextString()
	if n == "-" {
		break
	}
	nCopy := n
    m := nextInt()
	for i:= 0; i < m; i++ {
      h := nextInt()
	  nCopy = nCopy[h:] + nCopy[:h]
	}
	result = append(result, nCopy)
  }

  length := len(result)
  for i := 0; i < length; i++ {
    fmt.Println(result[i])
  }
}

func nextString() (string) {
	sc.Scan()
	v := sc.Text()
	return v
}

func nextInt() (int) {
	sc.Scan()
	v, e := strconv.Atoi(sc.Text())
    if e != nil { panic(e) }
    return v
}

func nextFloat() (float64) {
	sc.Scan()
	v, e := strconv.ParseFloat(sc.Text(), 64)
    if e != nil { panic(e) }
    return v
}



Measured memory_bytes: 1112
import sys
input_str=sys.stdin.read()

con=[0]*4
for a in input_str:
    if a=='K':
        con[0]+=1
    elif a=='U':
        con[1]+=1
    elif a=='P':
        con[2]+=1
    elif a=='C':
        con[3]+=1
    else :
        pass
    
print(min(con))


Measured memory_bytes: 5564
import sys

input = sys.stdin.readline


def main():
    N, M = [int(x) for x in input().split()]
    AB = [[int(x) for x in input().split()] for _ in range(M)]

    AB.sort()

    ans = 1
    right = AB[0][1]
    left = AB[0][0]
    for a, b in AB[1:]:
        if a >= right:
            ans += 1
            right = b
            left = a
        else:
            left = max(left, a)
            right = min(right, b)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 21992
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto abcd = readints;
    int a = abcd[0], b = abcd[1], c = abcd[2], d = abcd[3];

    writeln(max(a * b, c * d));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=100100;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
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; }

int main(){
    ll X,Y,A,B,C,a=0,sum=0;
    cin>>X>>Y>>A>>B>>C;
    vector<ll> p(A),q(B),r(C),ans;
    for(ll i=0;i<A;i++) cin>>p[i];
    for(ll i=0;i<B;i++) cin>>q[i];
    for(ll i=0;i<C;i++) cin>>r[i];
    sort(p.rbegin(),p.rend());
    sort(q.rbegin(),q.rend());
    for(ll i=0;i<X;i++) ans.push_back(p[i]);
    for(ll i=0;i<Y;i++) ans.push_back(q[i]);
    for(ll i=0;i<C;i++) ans.push_back(r[i]);
    sort(ans.rbegin(),ans.rend());
    for(ll i=0;i<X+Y;i++) sum+=ans[i];
    cout<<sum<<endl;
}


Measured memory_bytes: 8560
main(n,m,e,j,t){while(scanf("%d",&n),n)for(;n--;)scanf("%d%d%d",&m,&e,&j),t=m+e+j,puts(m==100|e==100|j==100|m+e>179|t>239?"A":t>209|t>149&(m>79|e>79)?"B":"C");}

Measured memory_bytes: 0
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readString = map BS.unpack . BS.words

getString = readString <$> BS.getLine

calc :: String -> Char -> Int
calc [] _ = 0
calc (c : s) c'
  | c == c' = calc s c'
  | otherwise = 1 + calc s c

main = do
  [s] <- getString
  print $ calc s (head s)


Measured memory_bytes: 5616
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	a := make([]int, n)
	for i := range a {
		a[i] = nextInt()
	}

	sumList := make([]int, n)
	for i, v := range a {
		if i == 0 {
			sumList[0] = v
		} else {
			sumList[i] = sumList[i-1] + v
		}
	}

	var min int
	for i := 0; i < n-1; i++ {
		x := sumList[i]
		y := sumList[n-1] - sumList[i]
		diff := abs(x - y)
		if i == 0 {
			min = diff
		} else {
			if diff < min {
				min = diff
			}
		}
	}

	fmt.Println(min)
}

func next() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	i, err := strconv.Atoi(next())
	if err != nil {
		fmt.Println(err)
	}
	return i
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}


Measured memory_bytes: 5248
#include <cstdio>
#define fol(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int n;scanf("%d",&n);
    int a,b=0,c=0;
    fol(i,n){
        scanf("%d",&a);
        a%2?c++:b++;
    }
    if(b>=0&&c%2==0){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 128
s = input()
a = ["KIHBR","AKIHBR","KIHABR","KIHBAR","KIHBRA","AKIHABR","AKIHBAR","AKIHBRA","KIHABAR","KIHABRA","KIHBARA","AKIHABAR","AKIHABRA","AKIHBARA","KIHABARA","AKIHABARA"]
if s in a:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
ll inf=100000000000000000,mod=1000000007;
int main(){
  
	ios::sync_with_stdio(false);
	cin.tie(0);
    ll n;
    cin>>n;
    ll arr[n],barr[n];
    for(ll i=0;i<n;i++)
    cin>>arr[i],barr[i]=arr[i];
    for(ll i=1;i<n;i++)
    {
        barr[i]=min(arr[i],barr[i-1]);
    }
    ll sum=0;
    for(ll i=0;i<n;i++)
    {
        if(arr[i]==barr[i])
        sum++;
    }
    cout<<sum<<endl;

}


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


#define M_MAX 20
#define N_MAX 50000
#define INFTY 1 << 29


int main(){
long long int n;
cin >>n;

long long int num=(int)sqrt(n);

for(long long int i=num;num>0;num--){
if(n%num==0){
long long int a=n/num;
cout << max((int)log10(a)+1,(int)log10(num)+1);
break;
}
}



}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") 
  
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;

int n, e[(int)1e5 + 5];

int main()
{
    cin >> n;
    
    for(int i = 1; i <= n; ++ i)
    {
        int u; 
        
        cin >> u;
        
        e[u] = i;
    }
    
    ll res = 0;
    
    multiset < int > w;
    
    w.insert(0);
    w.insert(0);
    w.insert(n + 1);
    w.insert(n + 1);
    
    for(int i = n; i >= 1; --i)
    {
        ll a = i;
        
        w.insert(e[a]);
        
        auto z = w.find(e[a]), x = prev(z), c = prev(x), v = next(z), b = next(v);
        
        int s = *x, d = *c, f = *v, g = * b;
        
        
        ll ans = (f - e[i]) * 1LL * (s - d) + 1LL * (g - f) * (e[i] - s);
        
        res += ans * a;
    }
    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
const int MOD=1000000007;
int main(){
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
}

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

using namespace std;
int main(){
  int n; cin >> n;
  string s; cin >> s;
  
  int now_white = 0;
  for (int i=0; i<n; i++) if (s.at(i) == '.') now_white++;
  int now_white_right=now_white, nbl=0, min_change=now_white;
  for (int i=0; i<n; i++) {
    if (s.at(i) == '.') now_white_right--;
    else nbl++;
    min_change = min(now_white_right+nbl, min_change);
  }
  cout << min_change << endl;
}


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

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

const int INF = 1e9;
const int mod = 1e9+7;

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

    ll cnt = 0,ans = 0;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'W') ans += cnt;
        else cnt++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
fn main() {
    let _ = read::<u32>();
    let mut v = read_vec::<u32>();

    v.sort_by(|a, b| b.cmp(a));

    let mut alice = 0;
    let mut bob = 0;

    for (i, a) in v.into_iter().enumerate() {
        if i % 2 == 0 {
            alice += a;
        } else {
            bob += a;
        }
    }

    println!("{}", alice - bob);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int 
const int MOD = 1e9+7;
const int MAXN = 2e5+5;

int32_t main()
{
  
    IOS
    int n,k;
    cin>>n>>k;
    int arr[n+1];   
    for(int i=1;i<=n;i++)  cin>>arr[i];
    int dp[n+1];
    memset(dp,MAXN,sizeof(dp));
    dp[1]=0;
    //for(auto it :dp) cout<<it<<" ";
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=i+k;j++){
            if(j<=n){
                dp[j]=min(dp[j],dp[i]+abs(arr[i]-arr[j]));
            
            }
        }
    }
    
    cout<<dp[n]<<'\n';
    return 0;
}
        

Measured memory_bytes: 1792
n = int(input())
b_list = list(map(int, input().split()))

#B_i = max(A_i, A_(i+1))の時が総和最大になる.
#B_(i-1) = max(A_(i-1), A_i)より、max(A_i) = min(B_i, B_(i-1)).
# ただし、B_-1=inf, B_n=infとしておく
a_list_sum = b_list[0]
for i in range(1, n-1):
    a_list_sum += min(b_list[i], b_list[i-1])
a_list_sum += b_list[n-2]
print(a_list_sum)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long int ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> c(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    int ans = 0;
    rep(i, n)
    {
        int x;
        cin >> x;
        ans += x;
    }
    rep(i, n - 1)
    {
        cin >> c[i];
    }
    rep(i, n - 1)
    {
        if (a[i + 1] == a[i] + 1)
        {
            ans += c[a[i] - 1];
        }
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 128
def my_solve(string):
    x, y, z, k, *abc = map(int, string.split())
    a, b, c = abc[:x], abc[x:x + y], abc[x + y:]
    ab = sorted([_a + _b for _b in b for _a in a])[-k:]
    *abc, = map(str, sorted([_ab + _c for _c in c for _ab in ab], reverse=True)[:k])
    return "\n".join(abc)


def solve(string):
    x, y, z, k, *abc = map(int, string.split())
    a, b, c = map(sorted, [abc[:x], abc[x:x + y], abc[x + y:]])
    ans = []
    for ia in range(1, x + 1):
        for ib in range(1, y + 1):
            for ic in range(1, z + 1):
                if ia * ib * ic <= k:
                    ans.append(a[x - ia] + b[y - ib] + c[z - ic])
                else:
                    break
    return "\n".join(list(map(str, sorted(ans, reverse=True)[:k])))


if __name__ == '__main__':
    print(solve('\n'.join([input() for _ in range(4)])))


Measured memory_bytes: 9656
ls_g=[]
ls_y=[]
ls_m=[]
ls_d=[]
cnt = -1
while True:
    try:
        ls=input().split()
        ls_g.append(ls[0])
        ls_y.append(int(ls[1]))
        ls_m.append(int(ls[2]))
        ls_d.append(int(ls[3]))
        cnt += 1
    except:
        break;

for _ in range(cnt+1):
    if ls_y[_]>31:
        ls_g[_]="?"
        ls_y[_]-=30
    elif ls_y[_]==31 and ls_m[_]>=5:
        ls_g[_]="?"
        ls_y[_]-=30
for i in range(cnt+1):
    print(ls_g[i]+" "+str(ls_y[i])+" "+str(ls_m[i])+" "+str(ls_d[i]))        



Measured memory_bytes: 5616
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

int main() {
    stack<int> S1;
    stack<pair<int, int> > S2;
    char c;

    int i = 0;
    int areas = 0;
    while(cin >> c) {
        switch(c) {
            case '\\':
                S1.push(i);
                break;
            case '/':
                if(S1.empty()) {
                    i++;
                    continue;
                }
                int j = S1.top();
                S1.pop();
                int a = i - j;
                areas += a;
                while(!S2.empty()) {
                    pair<int, int> b = S2.top();
                    if(b.first > j) {
                        S2.pop();
                        a += b.second;
                    }
                    else break;
                }
                S2.push(make_pair(j, a));
        }
        i++;
    }

    cout << areas << endl;

    vector<int> ans;
    while(!S2.empty()) {
        pair<int, int> a = S2.top();
        S2.pop();
        ans.insert(ans.begin(), a.second);
    }
    cout << ans.size();
    for(int i = 0; i < ans.size(); i++) {
        cout << " " << ans[i];
    }
    cout << endl;
}


Measured memory_bytes: 3228
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Created by mixnector on 2017/03/04.
 */
public class Main {
    static Scanner in;
    static PrintWriter out;
    static String INPUT = "";

    public static void main(String[] args) throws Exception
    {
        in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
        out = new PrintWriter(System.out);
        long N = nl();

        int halfN = (int)Math.sqrt(N);

        int min = 10;
        int A;
        long B;
        for(A = 1; A <= halfN; A++)
        {
            if(N % A == 0)
            {
                B = N / A;
                int F = (int)Math.log10(B) + 1;
                if(min > F)
                    min = F;
            }
        }

        out.println(min);
        out.flush();
    }

    static long nl() {
        return Long.parseLong(in.next());
    }
}

Measured memory_bytes: 23636
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	int total = 0;
	vector<int> t(n);
	for (int i = 0; i < n; i++) {
		cin >> t[i];
		total += t[i];
	}

	int m, p, x;
	cin >> m;
	vector<int> ans(m);
	for (int i = 0; i < m; i++) {
		cin >> p >> x;
		ans[i] = total - t[p-1] + x;
	}

	for (auto x: ans) {
		cout << x << endl;
	}
	return 0;
}


Measured memory_bytes: 256
a, b, c = gets.chomp.split.map(&:to_i)
d, e, f = gets.chomp.split.map(&:to_i)
g, h, i = gets.chomp.split.map(&:to_i)

n = gets.chomp.to_i

bingo = []
n.times do
  bingo << gets.chomp.to_i
end

b1 = [a, b, c]
b2 = [d, e, f]
b3 = [g, h, i]
b4 = [a, d, g]
b5 = [b, e, h]
b6 = [c, f, i]
b7 = [a, e, i]
b8 = [g, e, c]



if (b1 & bingo).size == 3
  puts 'Yes'
elsif (b2 & bingo).size == 3
  puts 'Yes'
elsif (b3 & bingo).size == 3
  puts 'Yes'
elsif (b4 & bingo).size == 3
  puts 'Yes'
elsif (b5 & bingo).size == 3
  puts 'Yes'
elsif (b6 & bingo).size == 3
  puts 'Yes'
elsif (b7 & bingo).size == 3
  puts 'Yes'
elsif (b8 & bingo).size == 3
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 1788
import java.util.ArrayDeque
import kotlin.Comparator
import kotlin.String

fun main(args: Array<String>) {
    val (h, w) = readIntList()
    val (ch, cw) = readIntList().map { it - 1 }
    val (dh, dw) = readIntList().map { it - 1 }
    val s = List(h) { readString() }

    val q = ArrayDeque<Pair<Int, Int>>()
    q.addLast(ch to cw)

    val ans = List(h) { MutableList(w) { Int.MAX_VALUE } }
    ans[ch][cw] = 0

    val af = listOf(Pair(0, 1), Pair(0, -1), Pair(1, 0), Pair(-1, 0))

    while (q.isNotEmpty()) {
        val (x, y) = q.removeFirst()

        af.forEach { (xf, yf) ->
            val tx = x + xf
            val ty = y + yf
            if (tx >= 0 && ty >= 0 && tx < h && ty < w && s[tx][ty] == '.' && ans[x][y] < ans[tx][ty]) {
                ans[tx][ty] = ans[x][y]
                q.addFirst(tx to ty)
            }
        }

        for (xf in -2..2) {
            for (yf in -2..2) {
                val tx = x + xf
                val ty = y + yf

                if (tx == x && ty == y) continue
                if (tx == x + 1 && ty == y) continue
                if (tx == x - 1 && ty == y) continue
                if (tx == x && ty == y + 1) continue
                if (tx == x && ty == y - 1) continue

                if (tx >= 0 && ty >= 0 && tx < h && ty < w && s[tx][ty] == '.' && ans[x][y] + 1 < ans[tx][ty]) {
                    ans[tx][ty] = ans[x][y] + 1
                    q.addLast(tx to ty)
                }
            }

        }
    }

    if (ans[dh][dw] == Int.MAX_VALUE) {
        println(-1)
    } else {
        println(ans[dh][dw])
    }
}

// read
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

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

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

const ll INF = 1LL << 60;

int main(){
  set<int> s;
  int n,a;
  cin >> n;
  FOR(i,n){
    cin >> a;
    s.insert(a); 
  }
  cout << s.size() << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		String t = sc.next();
		int a = 0;
		
		for(int i = 0 ; i < s.length() ; i++) {
			if((char)s.charAt(i) == (char)t.charAt(i)) {
				a++;
			}
		}
		
		if(a == s.length()) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 27008
N = int(input())
A_list = list(map(int, input().split()))

A_list.insert(0, 0)
A_list.append(0)
A_list_abs = []
A_sum = 0

for i in range(1, N+2):
    temp = abs(A_list[i] - A_list[i-1])
    A_list_abs.append(temp)
    A_sum += temp
#print(A_list_abs, A_sum)

for i in range(N):
    if (A_list[i] <= A_list[i+1] <= A_list[i+2]) or (A_list[i] >= A_list[i+1] >= A_list[i+2]):
        print(A_sum)
    else:
        print(A_sum - A_list_abs[i] - A_list_abs[i+1] + abs(A_list_abs[i] - A_list_abs[i+1]))

Measured memory_bytes: 20452
#include<stdio.h>
int main()
{
	int H, W;
	int i, j;

	while (1) {
		scanf("%d%d", &H, &W);
		if (H == 0 && W == 0) break;

		for (i = 0; i < H; i++) {
			for (j = 0; j < W; j++) {
				printf("#");
			}printf("\n");
		}printf("\n");
	}
		return 0;
}

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

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,k,j;
  int maxi=0;
  int memo;
  cin>>n>>k;
  rep(i,n){
      cin>>memo;
      if(i==0)j=memo;
      if(memo>maxi)maxi=memo;
      j=gcd(j,memo);
  }
 
  if(k<=maxi&&k%j==0){
      cout<<"POSSIBLE"<<endl;
  }
  else{
      cout<<"IMPOSSIBLE"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
import Data.List
import qualified Data.ByteString.Char8 as B
import Control.Monad
import qualified Data.Array as A 

main :: IO ()
main = readLn >>= main'
    where
        main' n = replicateM n breads >>= main'' n . edit
        main'' n fs = replicateM n breads >>= print . solve n fs . edit2

edit :: [[Int]] -> [[Int]]
edit (x : xs) = zipWith (:) x $ edit xs
edit _ = replicate 10 []

edit2 :: [[Int]] -> [A.Array Int Int]
edit2 = fmap (A.listArray (0, 10))

solve :: Int -> [[Int]] -> [A.Array Int Int] -> Int
solve n fs ps = foldl' ff (-10000000000) . tail $ patterns 10
    where
        ff acc = max acc . foldl' ff3 0 . zip ps . foldl' ff2 (replicate n 0) . zip fs
        ff2 acc (xs, b)
            | b = zipWith (+) acc xs
            | otherwise = acc
        ff3 acc (p, i) = acc + p A.! i


patterns :: Int -> [[Bool]]
patterns n
    | n == 0 = [[]]
    | otherwise = (:) <$> [False, True] <*> patterns (n - 1)

     
breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)

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

typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    ll r;
    cin >> r;
    cout << 2*r*acos(-1);
    return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define dbg(x) cerr<<#x": "<<(x)<<endl
#define dbg_p(x) cerr<<#x": "<<(x).first<<' '<<(x).second<<endl
#define dbg_v(x, n) {cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<(x)[_]<<' ';cerr<<endl;}
#define all(v) v.begin(), v.end()
#define fi first
#define se second

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

template <typename T>
ostream& operator <<(ostream &out, const vector<T>& v) {
	for(const auto &item : v) out << item << ' ';
	return out;
}

const int N = 100010;

int fr[100];
ll a[N], v[100];

int main()
{
	ios_base::sync_with_stdio(false);
	
	int n;
	
	cin >> n;
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		for(int j = 0; j < 60; ++j)
			if(a[i] & (1LL << j)) ++fr[j];
	}
	
	ll ans = 0;
	for(int j = 0; j < 60; ++j)
		if(fr[j] % 2) {
			ans += (1LL << j);
			for(int i = 0; i < n; ++i)
				if(a[i] & (1LL << j)) a[i] ^= (1LL << j);
		}
	
	memset(v, -1, sizeof v);
	for(int i = 0; i < n; ++i)
		for(int j = 59; j >= 0; --j)
			if(a[i] & (1LL << j)) {
				if(v[j] == -1) { v[j] = a[i]; break; }
				a[i] ^= v[j];
			}
	
	ll curr = 0;
	for(int j = 59; j >= 0; --j)
		if(v[j] != -1 && !(curr & (1LL << j))) curr ^= v[j];
	
	cout << ans + 2 * curr << '\n';
	
	return 0;
}


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    int n;
    cin >> n;
    vector<ll> l(n);
    for(int i = 0; i < n; i++){
        cin >> l[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            for(int k = j+1; k < n; k++){
                if( (l[i] + l[j] > l[k]) && 
                    (l[j] + l[k] > l[i]) &&
                    (l[i] + l[k] > l[j])){
                    if( (l[i] != l[j]) &&
                        (l[j] != l[k]) &&
                        (l[i] != l[k])){
                        ans++;
                    }
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3600
#ARC052B

n=int(raw_input())
s=raw_input()
res_max=0
temp=0
for i in range(len(s)):
 if s[i]=='I':
  temp+=1
  res_max=max(res_max,temp)
 elif s[i]=='D':
  temp-=1
print res_max


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

int cmp(const void * n1, const void * n2)
{
	if (*(char *)n1 > *(char *)n2)
	{
		return 1;
	}
	else if (*(char *)n1 < *(char *)n2)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int cmp_s(const void * left, const void * right)
{
	char *left_char = (char *)left;
  char *right_char = (char *)right;

  return strcmp(left_char, right_char);
}

int main(void){

  int n;
  scanf("%d", &n);
	char s[n][11];
	for (int i = 0; i < n; i++) {
		scanf("%s", s[i]);
	}

	for (int i = 0; i < n; i++) {
		qsort(s[i], 10, sizeof(char), cmp);
	}

	qsort(s, n, sizeof(s[0]), cmp_s);

	long count = 1;
	long sum = 0;
	for (int i = 1; i < n; i++) {
		if (strcmp(s[i],s[i-1]) == 0) {
			count++;
		} else {
			sum += count*(count-1)/2;
			count = 1;
		}
	}
	sum += count*(count-1)/2;
	printf("%ld\n", sum);

  return 0;
}

Measured memory_bytes: 2300
n = int(input())
S = input()
leftstack = 0

remrights = 0
for s in S:
    if s == '(':
        leftstack += 1
    else:
        if leftstack > 0:
            leftstack -= 1
        else:
            remrights += 1
print('('*remrights + S + ')'*leftstack)



Measured memory_bytes: 9048
#include<iostream>
#include<algorithm>

int main(void){
    int a[5];
    for(int i=0;i<5;i++) std::cin>>a[i];
    std::sort(a,a+5);
    for(int i=4;i>=0;i--) std::cout<<(i==4?"":" ")<<a[i];
    std::cout<<std::endl;

    return 0;
}


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n;
vector<int>a(200003);
vector<int>::iterator it,it2;
bool ch(int mid){
  r(i,n){
    int p=(i==0?0:a[i-1]);
    it=lower_bound(a.begin(),a.begin()+i+n,mid+p);
    it2=lower_bound(a.begin(),a.begin()+i+n,mid+(*(it)));
    if((*(a.begin()+i+n-1))-(*(it2))>=mid)return 1;
  }
  return 0;
}
main(){
  cin>>n;
  r(i,n){
    cin>>a[i];
    a[i+n]=a[i];
  }
  r(i,n*2)a[i+1]+=a[i];
  int l=0,r=1e17;
  while(l<r){
    int mid=(l+r)/2;
    if(!ch(mid))r=mid;
    else l=mid+1;
  }
  cout<<l-1<<endl;
}

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

inline bool check(const vector<int> &c){
  for(int i=0;i<8;i++)if(c[i]!=c[i+1])return false;
  for(int i=9;i<11;i++)if(c[i]!=c[i+1])return false;
  for(int i=12;i<14;i++)if(c[i]!=c[i+1])return false;
  for(int i=15;i<17;i++)if(c[i]!=c[i+1])return false;
  for(int i=18;i<20;i++)if(c[i]!=c[i+1])return false;
  for(int i=21;i<29;i++)if(c[i]!=c[i+1])return false;
  return true;
}

inline void rot(vector<int> &c, int d){
  if(d == 0){
    swap(c[0],c[23]); swap(c[3],c[26]); swap(c[6],c[29]);
    swap(c[15],c[17]); swap(c[9],c[20]);
  }
  if(d == 1){
    swap(c[6],c[21]); swap(c[7],c[22]); swap(c[8],c[23]);
    swap(c[9],c[11]); swap(c[12],c[17]);
  }
  if(d == 2){
    swap(c[2],c[21]); swap(c[5],c[24]); swap(c[8],c[27]);
    swap(c[12],c[14]); swap(c[11],c[18]);
  }
  if(d == 3){
    swap(c[0],c[27]); swap(c[1],c[28]); swap(c[2],c[29]);
    swap(c[18],c[20]); swap(c[14],c[15]);
  }
}

int rec(int d, vector<int> &c){
  if(check(c))return d;
  if(d>=8)return 8;

  int res = 8;
  for(int i=0;i<4;i++){
    rot(c,i);
    res = min(res, rec(d+1,c));
    rot(c,i);
  }
  return res;
}

int main(){
  int t;
  cin >> t;
  while(t--){
    vector<int> p(30);
    for(int i=0;i<30;i++)cin >> p[i];
    cout << rec(0,p) << endl;
  }
}

Measured memory_bytes: 1192
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <map>
#include <list>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <random>
#include <queue>
#include <fstream>
#include <iterator> // std::back_inserter
#include <chrono>
#include <string>
#include <stdio.h>
#include <iomanip>
#include <float.h>

using namespace std;

int N, X;

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

    cin >> N >> X;

    vector<int> s;

    int a;

    for (int i = 0; i < N; i++)
    {
        cin >> a;
        s.push_back(a);
    }

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

    long long int line = 1;

    // for (int i = 2; i < N + 1; i++)
    // {
    //     line *= i;
    // }

    long long int p[X + 1] = {}; //最終値はX未満

    p[X] = 1;

    for (int i = 1; i < N + 1; i++)
    {
        for (int t = 0; t < X + 1; t++)
        {
            if (p[t] > 0)
            {
                long long int rem = p[t];
                p[t] = rem * (N-i);
                p[t] %= 1000000007;
                p[t % s[N-i]] += rem;
                p[t % s[N-i]] %= 1000000007;

                //cout << i << " " << t % s[N-i] << " " << p[t % s[N-i]] << " " << p[t] << "\n";
                //cout << p[t] <<"\n";
            }
        }
    }

    long long int ans = 0;

    for (int i = 1; i < X + 1; i++)
    {
        ans += i * p[i];
        ans %= 1000000007;
    }

    

    cout << ans;

    return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        String S = ns();

        if (S.indexOf('C') == -1 || S.indexOf('F') == -1) {
            out.println("No");
            return;
        }
        int cindex = 0, findex = 0;
        for (int i = 0; i < S.length(); i++) {
            if (S.charAt(i) == 'C') cindex = i;
            if (S.charAt(i) == 'F') findex = i;
        }

        if (cindex < findex) {
            out.println("Yes");
        } else {
            out.println("No");
        }
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

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

int main(){
	int n;
	cin>>n;
	int sum=0;
	int arr[n];
	for(int i=0;i<n;i++)cin>>arr[i];
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			sum+=arr[i]*arr[j];
		}
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
/*   _ _ _                     
    | | | | ___  ___           
    | | | || . ||  _|          
    |_____||_  ||_|  _____     
             |_|    |_____|  */
// Time : 19/10/16
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
int main(){
#ifdef Wqr_
    freopen("in.txt","r",stdin);
#endif
    std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    ll a, b;
    cin >> a >> b;
    ll c = __gcd(a, b);
    ll d = c, ans = 1;
    for(ll i = 2; i * i <= d; i++){
        if(c % i == 0){
            ans++;
            while(c % i == 0) c /= i;
        }
    }
    if(c != 1) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<ctype.h>
# define pb push_back
#define fst first
#define sec second
#define For(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
#define fo(i,n) for(ll i=0;i<n;i++)
#define endl "\n"
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define boolsize 1000001
#define pi pair<ll,ll>
#define vi vector<ll>
#define vii vector<pi>
using namespace std;
template<typename T>
void showvector(vector <T> v)
{
    for(T x:v)
        cout<<x<<" ";
    cout<<endl;

}
template<typename T>
void showvector1(vector <T> v)
{
    ll n=v.size();
    fo1(i,n-1)
        cout<<v[i]<<endl;

}
template<typename T>
void showset(set <T> s)
{
    for(T x: s)
        cout<<x<<" ";
    cout<<endl;
}
template<class T>
void showvectorpair(vector<T> v)
{
    for(auto it=v.begin();it!=v.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T,typename P>
void showmap(map <T,P> m)
{
    for(auto it=m.begin();it!=m.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T>
bool comp(T a,T b)
{
    return (a>b);
}
template<class T>
bool comppair(T a,T b)
{
    if(a.first==b.first)
        return(a.second>b.second);
    return (a.first>b.first);
}
bool sameparity(ll a,ll b)
{
    return (a%2==b%2);
}
bool difparity(ll a,ll b)
{
    return !(a%2==b%2);
}
bool isprime(ll x)
{   if(x<=1)
     return false;
    for(ll i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
            return false;
    }
    return true;
}
bool iseven(ll x)
{
    return !(x%2);
}
bool isodd(ll x)
{
    return (x%2);
}
/// check for test case before submitting
void vfun()
{
    ll n,k;
    cin>>n;
    vector <ll> v(n);
    fo(i,n)
    cin>>v[i];

}
ll power(ll a,ll n)
{
    ll res=1;
    while(n!=0)
        {
            if(n%2)
                res*=a;
            n/=2;a*=a;
        }
    return res;
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("inputh.txt", "r", stdin);
    freopen("outputh.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0); ///cant use scanf, printf
    cin.tie(0);cout.tie(0); /// no longer auto flush cout before each cin, remove for interactive
    //cout << fixed << setprecision(11); /// no scientific output
    ll test=1;
    //cin>>test;
    while(test--)
    {

            ll n;
            cin>>n;
            ll x=log2(n);
            x+=1;
            ll ans=power(2,x)-1;
            cout<<ans;
//         if(vfun())
//            cout<<"YES\n";
//         else
//            cout<<"NO\n";
    }
}
///before sub
/// check for value of zero and single input in array
///loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking inputs
/// check whether test cases are given or not





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

int parent(int i) { return i/2; }
int left(int i) { return i*2; }
int right(int i) { return i*2+1; }

void maxHeapify(int A[], int i, int n) {
  int l = left(i);
  int r = right(i);
  int largest;

  if (l <= n && A[l] > A[i]) largest = l;
  else largest = i;
  if (r <= n && A[r] > A[largest]) largest = r;

  if (largest != i) {
    swap(A[i], A[largest]);
    maxHeapify(A, largest, n);
  }
}

void buildMaxHeap(int A[], int n) {
  for(int i = n/2; i > 0; i --) {
    maxHeapify(A, i, n);
  }
}

int main() {
  int n;cin>>n;
  int A[n+1];
  for(int i = 1; i < n+1; i++) {
    cin >> A[i];
  }

  buildMaxHeap(A, n);
  for(int i = 1; i < n+1; i++) {
    cout << " " << A[i];
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 5028