akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = list(map(int, input().split()))
s = 0
for j in range(n // 2):
    s += a[(j * 2 + 1) % n] * 2
ret = []
ret.append(sum(a) - s)
for i in range(0, n - 1):
    ret.append((a[i] - ret[-1] // 2) * 2)
print(" ".join(map(str, ret)))

Measured memory_bytes: 84708
#include <stdio.h>

void print_array(int a[], int length)
{
    for(int i=0; i<length; i++){
        if(i==length-1)
            printf("%d\n", a[i]);
        else
            printf("%d ", a[i]);
    }
}


int bubble_sort(int a[], int length)
{
    int swap_num = 0;
    for(int i=0; i<length; i++){
        //for(int j=0; j<length-i; j++){
        for(int j=length-1; j>=i+1; j--){
            if(a[j] < a[j-1]){
                int temp = a[j];
                a[j] = a[j-1];
                a[j-1] = temp;
                swap_num++;
            }
        }
    }
    return swap_num;
}

int main(){
    int data_length, arr[110];
    scanf("%d", &data_length);
    for(int i=0; i<data_length; i++){
        scanf("%d", &arr[i]);
    }
    int swap = bubble_sort(arr, data_length);
    print_array(arr, data_length);
    printf("%d\n", swap);
}



Measured memory_bytes: 2148
open System 

let R() = Console.ReadLine()

let f (s: string): bool =
    s.ToCharArray()
    |> Array.groupBy id 
    |> Array.forall (fun (_,v) -> Array.length v = 2)

let S = R()

f S
|> function 
| true -> "Yes"
| _ -> "No"
|> printfn "%s"

Measured memory_bytes: 29696
// 誤差ゲー
#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;

typedef long double ld;
const ld EPS = 1e-10;

ld comb[100][51][51] = {};

int main(){
    int n, m, l;
    cin >> n >> m >> l;
    vector<ld> p(n), t(n), v(n);
    for(int i = 0; i < n; i++)  cin >> p[i] >> t[i] >> v[i], p[i]/=100.0;
    for(int i = 0; i < n; i++){
        comb[i][0][0] = 1;
        for(int j = 1; j <= m; j++){
            for(int k = 0; k <= j; k++){
                comb[i][j][k] = (k>0 ? comb[i][j-1][k-1] : 0)*p[i]+comb[i][j-1][k]*(1-p[i]);
            }
        }
    }
    for(int i = 0; i < n; i++){
        if(v[i] == 0){
            cout << 0 << endl;
            continue;
        }
        ld ans = 0;
        for(int j = 0; j <= m; j++){
            ld me = l/v[i]+t[i]*j;
            ld add = comb[i][m][j];
            for(int k = 0; k < n; k++){
                if(i == k || v[k] == 0)  continue;
                ld oppo = l/v[k]+t[k]*m;
                ld tim = 0;
                int now = m;
                while(now>=0 && oppo-me > EPS){
                    tim += comb[k][m][now--], oppo -= t[k];
                }
                add *= tim;
            }
            ans += add;
        }
        cout << fixed << setprecision(12) << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 7312
n,q = map(int,input().split())
s = input()
t = [0] * (n + 1)
for i in range(n):
  t[i+1] = t[i] + (1 if s[i:i+2] == "AC" else 0)
for i in range(q):
  l,r = map(int,input().split())
  print(t[r-1] - t[l-1])


Measured memory_bytes: 9412
package main

import (
	"fmt"
	"math"
	"strconv"
)

func isInteger(x float64) bool {
	return math.Floor(x) == x
}
func main() {
	var a, b string
	fmt.Scan(&a, &b)
	num, _ := strconv.Atoi(a+b)
	if isInteger(math.Sqrt(float64(num))){
		fmt.Println("Yes")
	}else{
		fmt.Println("No")
	}
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<time.h>
#include<cctype>
#include<iostream>
#include<ostream>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cstring>
#include<string>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;//1061109567
const int INF=0x7fffffff;//2147483647
const int SUP=0x80000000;//-2147483648
#define MAX 1000000
ll a[MAX]={0},b[MAX]={0};
int main()
{
    int n;
    int t;
    ll sum=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>t;
        if(i+t<=n)a[i+t]++;
        if(i-t>=1)b[i-t]++;
    }
    for(int i=1;i<=n;i++)
    {
        sum+=a[i]*b[i];
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 6688
N,K = map(int,input().split())
H = []
for i in range(N):
	H.append(int(input()))

H.sort()
ans = H[N-1]
# print(H)
for i in range(0,len(H)-K+1):
	# print(H[i],H[i+K-1],len(H)-K-1)
	if ans >  H[i+K-1] - H[i]:
		ans =  H[i+K-1] - H[i]
		# print(ans)
print(ans)



Measured memory_bytes: 7384
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
using namespace std;

#define __int64 long long
#define long __int64
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vec = 4;
const int Vecy[Vec] = {0,-1,0,1};
const int Vecx[Vec] = {1,0,-1,0};
const int Modd = 1000000007;

string s[100];
int p[100];
vector<pair<string, int>> datas;
vector<pair<string, int>> motoDatas;

// 理想ならばtrue
bool comp(const pair<string, int> &lh, const pair<string, int>& rh) {
    if(lh.first < rh.first){
        return true;
    }

    if(lh.first > rh.first){
        return false;
    }

    if(lh.second > rh.second){
        return true;
    } else {
        return false;
    }
}

// インデックスを破棄してしまったので検索＼(^o^)／
int getIndex(pair<string, int> dat){
    for(int i=0; i<motoDatas.size(); i++){
        if(dat.first == motoDatas[i].first
           && dat.second == motoDatas[i].second){
               return i + 1;
           }
    }

    return -1;
}

int main(){
    int n, p;
    string s;
    cin >> n;
    rep(i,n){
        cin >> s >> p;
        datas.push_back(pair<string, int>(s, p));
        motoDatas.push_back(pair<string, int>(s, p));
    }

    sort(datas.begin(), datas.end(), comp);

    for(pair<string, int> dat : datas){
        cout << getIndex(dat) << endl;
    }

}

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

class list
{
    int L[1000001];
    int head, tail, MAX;
public:
    list();
    void initialize();
    void ins(int);
    void del(int);
    void del_first();
    void del_last();
    void show();
};

list::list() : MAX(1000001){}

void list::initialize(){ head = tail = 0; }

void list::ins(int key)
{
    L[head] = key;
    head++;
    if(head == MAX) head = 0;
    return;
}

void list::del(int key)
{
    int i = head, j;
    do{
        if(i == 0) i = MAX;
        i--;
        if(i == tail && L[tail] != key) return;
    }while(L[i] != key);
    // ????????£???????????§L[i]????????????key. ???????????°??????????????????
    j = i;
    do{
        if(j == MAX - 1){
            L[j] = L[0];
        }else{ L[j] = L[j + 1]; }
        j++;
        if(j == MAX) j = 0;
    }while(j != head);
    // ?????????head???1???????????????
    head--;
    if(head < 0) head = MAX - 1;
	return;
}

void list::del_first()
{
    head--;
    if(head < 0) head = MAX - 1;
    return;
}

void list::del_last()
{
    tail++;
    if(tail == MAX) tail = 0;
    return;
}

void list::show()
{
    int i = head;

    while(i != tail){
        if(i == 0) i = MAX;
        cout << L[i - 1];
        i--;
        if(i != tail) cout << " ";
    }
    cout << endl;
    return;
}

int main()
{
    list l = list();
    string order;
    int i, n, key;
    l.initialize();

    cin >> n;
    for(i = 0; i < n; i++){
        cin >> order;
        if(order[0] == 'i'){
            cin >> key;
            l.ins(key);
        }else if(!order[6]){
            cin >> key;
            l.del(key);
        }else{
            if(order[6] == 'F') l.del_first();
            if(order[6] == 'L') l.del_last();
        }
    }
    l.show();

    return 0;
}

Measured memory_bytes: 5104
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#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 rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    string s,t;
    cin >> s >> t;
    int cnt = 0;
    rep(i,sz(s)){
        if(s[i]!=t[i]) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3804
#include<cstdio>
using namespace std;
int main(){
  int n,m,q,g[2001][2001]={},v[2001][2001]={},h[2001][2001]={},a[2001]={},b[2001]={},x1,x2,y1,y2;
  char s[2001][2001];
  scanf("%d %d %d",&n,&m,&q);
  for(int i=0;i<n;i++)
    scanf("%s",s[i]);
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      if(s[i][j]=='1'){
        a[j+1]=a[j]+1;
        if(j!=0&&s[i][j-1]=='1')
          b[j+1]=b[j]+1;
        else
          b[j+1]=b[j];
      }
      else{
        a[j+1]=a[j];
        b[j+1]=b[j];
      }
      g[i+1][j+1]=g[i][j+1]+a[j+1];
      h[i+1][j+1]=h[i][j+1]+b[j+1];
    }
  }
  for(int j=0;j<m;j++){
    for(int i=1;i<n;i++){
      if(s[i][j]=='1'&&s[i-1][j]=='1'){
        b[i+1]=b[i]+1;
      }
      else{
        b[i+1]=b[i];
      }
      v[i+1][j+1]=v[i+1][j]+b[i+1];
    }
  }
  for(int i=0;i<q;i++){
    scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
    printf("%d\n",g[x2][y2]-g[x2][y1-1]-g[x1-1][y2]+g[x1-1][y1-1]-(h[x2][y2]-h[x2][y1]-h[x1-1][y2]+h[x1-1][y1])-(v[x2][y2]-v[x2][y1-1]-v[x1][y2]+v[x1][y1-1]));
  }
}

Measured memory_bytes: 52608
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int h, w, a, b;
	
	cin>>h>>w>>a>>b;
	
	cout<<h*w-(h/a)*a*(w/b)*b<<endl;
	
	
	return 0;
}


Measured memory_bytes: 3216
#include<stdio.h>
#include<math.h>

int main(void){
	int n;
	int sum=100000;

	scanf("%d",&n);
	while(n--){
		sum=sum+sum*0.05;
		sum=ceil(sum*0.1);
		sum*=10;
		sum=ceil(sum*0.01);
		sum*=100;
		sum=ceil(sum*0.001);
		sum*=1000;
	}
	printf("%d\n",sum);

	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <random>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

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

int arr[110];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);

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

    for (int i = 0; i < N; ++i)
    {
        cin >> arr[i];
    }

    for (int i = 1; i <= M; ++i)
    {
        int idx = 0;
        while (idx + 1 < N)
        {
            if (arr[idx] % i > arr[idx + 1] % i)
            {
                swap(arr[idx], arr[idx + 1]);
                idx++;
            }
            else
            {
                idx++;
            }
        }
    }
    for (int i = 0; i < N; ++i)
    {
        cout << arr[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3164
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define o 200005
using namespace std;
long long ans;
int n;
int a[o],pos[31];
long long s1[o];
int s2[o];
int main(){
	scanf("%d",&n);
	for(register int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(register int i=1;i<=n;i++) s1[i]=s1[i-1]+(long long)a[i],s2[i]=a[i]^s2[i-1];
	int j=1;
	for(register int i=1;i<=n;i++){
		for(int k=0;k<=20;k++) if((a[i]>>k)&1){
			j=max(j,pos[k]+1);
			pos[k]=i;
		}
		ans+=(long long)(i-j+1);
	}
		
	cout<<ans<<endl;
}

Measured memory_bytes: 3328
from heapq import heappop,heappush,heapify
n,m=map(int,input().split())
work=[[] for _ in range(m+1)]
for _ in range(n):
    a,b=map(int,input().split())
    if a<=m: work[a].append(b)

ans=0
q=[]
heapify(q)
for i in range(1,m+1):
    for x in work[i]:
        heappush(q,-x)
    if q!=[]: ans+=heappop(q)
print(-ans)

Measured memory_bytes: 18388
#include <stdio.h>



int main(void)
{
	//変数の宣言
	int a,b,c;
	int min,max;
	
	//データの読み込み
	scanf("%d %d %d",&a,&b,&c);
	
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	
	
	//実際の処理
	
	min=a;
	max=a;
	
	if(a<b){
		max=b;
	}else{
		min=b;
	}
	
	if(min>c){
		min=c;
	}else if(max<c){
		max=c;
	}
	
	
//	printf("計算部分終了\n");
	
	//出力
	
	printf("%d",max-min);
	
//	printf("結果の出力終了\n");
	
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(){
  char s[3];
  int i;
  int flag1=0;
  int flag2=0;
  int flag3=0;
  scanf("%s",s);
  
  for(i=0;i<3;i++){
    if(s[i]=='a')
      flag1++;
    if(s[i]=='b')
      flag2++;
    if(s[i]=='c')
      flag3++;
  }
  
  if(flag1==1&&flag2==1&&flag3==1)
    printf("Yes");
  else
    printf("No");
  return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

#define int long long

class CHT { // y = b - kx
    #define x first
    #define y second

private:
    vector <pii> lines;
    vector <int> points;

    int intersect(pii a, pii b) {
        return (a.fs - b.fs) / (a.sc - b.sc);
    }

    int f(pii line, int x) {
        return line.fs - line.sc * x;
    }

public:
    void add(pii line) {
        if (lines.empty()) {
            lines.pb(line), points.pb(0);
            return;
        }
        if (intersect(line, lines.back()) <= points.back()) {
            lines.pop_back(), points.pop_back();
            add(line);
            return;
        }
        points.pb(intersect(line, lines.back()));
        lines.pb(line);
    }

    int get(int x) {
        int i = --lower_bound(all(points), x) - points.begin();
        return f(lines[i], x);
    }

    void print() {
        cout << "lines\n";
        for (auto i : lines)
            cout << i.fs << " " << i.sc << "\n";
        cout << "points\n";
        for (auto i : points)
            cout << i << "\n";
        cout << "\n\n";
    }
};

main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, c;
    cin >> n >> c;
    vector <int> h(n);
    cin >> h;
    CHT a;
    vector <int> dp(n);
    dp[0] = 0;
    a.add({dp[0] + h[0] * h[0], 2 * h[0]});
    forn (i, 1, n) {
        dp[i] = a.get(h[i]) + h[i] * h[i] + c;
        a.add({dp[i] + h[i] * h[i], 2 * h[i]});
    }
    cout << dp[n - 1];
    return 0;
}

Measured memory_bytes: 10724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll k, n, ans;
  cin >> k >> n;
  ll arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  ans = arr[n-1] - arr[0];
  for (int i = 1; i < n; i++) {
    ans = min(ans, arr[i-1] + k - arr[i]);
  }
  cout << ans;
}

Measured memory_bytes: 5140
#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
      (cons (subseq str 0 pos)
            (split x (subseq str (+ pos size))))
      (list str))))

(defmacro collect-times (time body)
  `(loop repeat ,time collect ,body))

(defun read-times (time)
  (collect-times time (read)))

(defun main (str)
  (count #\1 str))

(defun func (x)
  (loop for x across (write-to-string x)
        sum (- (char-code x) (char-code #\0))))

(defun main (n min max)
  (loop for i from 1 to n
        for v = (func i)
        when (<= min v max)
          sum i))

(princ (main (read) (read) (read)))


Measured memory_bytes: 15928
#! /usr/bin/env python3

n = int(input())
a = list(map(int, input().split()))
s = set()
for i in a:
    if 1 <= i <= 399 : s.add(1)
    if 400 <= i <= 799 : s.add(2)
    if 800 <= i <= 1199 : s.add(3)
    if 1200 <= i <= 1599 : s.add(4)
    if 1600 <= i <= 1999 : s.add(5)
    if 2000 <= i <= 2399 : s.add(6)
    if 2400 <= i <= 2799 : s.add(7)
    if 2800 <= i : s.add(8)
r = len([1 for x in a if 2800 <= x <= 3199]) < 1
print(len(s), len(s) + max((len([1 for x in a if x > 3199]) - r, 0)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
//const ll MOD = 1e9+7;
const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

template<ll mod> struct Mod_Int{
    ll x;
    Mod_Int() {}
    Mod_Int(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod){}

    Mod_Int &operator += (const Mod_Int &p) {
        x = (x + p.x) % mod;
        return *this;
    }

    Mod_Int &operator -= (const Mod_Int &p) {
        x = (x + mod - p.x) % mod;
        return *this;
    }

    Mod_Int &operator *= (const Mod_Int &p) {
        x = (x * p.x) % mod;
        return *this;
    }

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

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

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

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

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

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

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

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

    Mod_Int pow(ll n) const{
        Mod_Int now = *this, ret = 1;
        while(n > 0){
            if(n & 1) ret *= now;
            now *= now, n >>= 1;
        }
        return ret;
    }

    Mod_Int inverse() const{
        return pow(mod-2);
    }
};

using mint = Mod_Int<MOD>;
const int MAX_N = 1e6;
mint fac[MAX_N+1];

void init(){
    fac[0] = 1;
    rep2(i, 1, MAX_N){
        fac[i] = fac[i-1]*mint(i);
    }
}

mint comb(mint n, mint k){
    return fac[n.x]/(fac[n.x-k.x]*fac[k.x]);
}

mint perm(mint n, mint k){
    return fac[n.x]/fac[n.x-k.x];
}

int main(){
    ll N, A, B, K;
    cin >> N >> A >> B >> K;
    mint ans = 0;
    init();
    for(ll i = 0; i <= N; i++){
        ll C = K-A*i;
        if(C >= 0 && C%B == 0 && C/B <= N){
            ll j = C/B;
            ans += comb(N, i)*comb(N, j);
        }
    }
    cout << ans.x << endl;
}

Measured memory_bytes: 8064
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        N = N % 100;
        N = N % 10;
        if(N == 3){
            System.out.print("bon");
        }else if(N == 2||N == 4||N == 5||N == 7||N == 9){
            System.out.print("hon");
        }else{
            System.out.print("pon");
        }
    }
}

Measured memory_bytes: 27068
x = int(input())
if 400 <= x <= 599:
  ans = 8
elif 600 <= x <= 799:
  ans = 7
elif 800 <= x <= 999:
  ans = 6
elif 1000 <= x <= 1199:
  ans = 5
elif 1200 <= x <= 1399:
  ans = 4
elif 1400 <= x <= 1599:
  ans = 3
elif 1600 <= x <= 1799:
  ans = 2
elif 1800 <= x <= 1999:
  ans = 1
print(ans)

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

int main() {
    int n, sum;
    int scores[1000];
    double mean, temp = 0;

    while(true) {
        cin >> n;
        if (n == 0) break;

        for (int i = 0; i < n; i++) cin >> scores[i];
        sum = 0;
        for (int i = 0; i < n; i++) sum += scores[i];
        mean = (double) sum / n;
        temp = 0;
        for (int i = 0; i < n; i++) {
            temp += (scores[i] - mean) * (scores[i] - mean);
        }
        printf("%lf\n", sqrt(temp / n));
    }

    return 0;
}


Measured memory_bytes: 3168
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n,a,b;
    scanf("%d%d%d",&n,&a,&b);
    int x=min(a,b);
    int y=max(0,a+b-n);
    printf("%d %d",x,y);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff        first
#define ss        second
#define ll        long long
#define int       long long
#define inf       ((ll)1e18)
#define double    long double
#define ull       unsigned long long
#define mod       1000000007
#define vi        vector<ll>
#define ppi       pair<int,int>
#define pii       pair<pair<int,int>,int>
#define pb        push_back
#define pi        2*acos(0.0)
#define pr(a,x,y) for(int i=x;i<y;i++){cout<<a[i]<<" ";}
#define p(a)      cout<<a;
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define all(v)    v.begin(), v.end()
#define rall(v)   v.rbegin(), v.rend()
#define test      cout<<"THIS_AND_THIS"<<endl;
#define str       string
#define endl      '\n'
#define e         cout<<'\n';
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
ll ans[1000005];
void init(){
	memset(ans,0,sizeof(ans));
	for(int i=1;i<=100;i++){
		for(int j=1;j<=100;j++){
			for(int k=1;k<=100;k++){
				ll x=i*i+j*j+k*k+i*j+k*j+k*i;
				ans[x]+=1;
			}
		}
	}
}
void solve(){
	ll n;cin>>n;
	init();
	for(int i=1;i<=n;i++){cout<<ans[i]<<endl;}
}
int32_t main(){
	kehsihba();
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}




Measured memory_bytes: 11420
#include<iostream>

using namespace std;

const int MAX = 50;

int data[MAX];
int in,num;
int copyA[MAX];

void change(int p, int c){

  for(int i = p; i < p+c; i++) data[i-p] = copyA[i];
  for(int i = 0; i < p; i++) data[i+c] = copyA[i]; 
}
void make(){
  for(int i = 0; i < in; i++) data[i] = i;
}
void copy_1(){
  for(int i = 0; i < in; i++) copyA[i] = data[i];
}

int main(){

  while(cin >> in >> num && in+num){
    make();
    for(int i = 0; i < num; i++){
      int p,c;
      cin >> p >> c;
      copy_1();
      change(p-1,c);
    }
    cout << in - data[0] << endl;
  }
  return 0;
}

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

int main(){
    ll mx = 1000000;
    ll mn = -mx;
    ll k, x;
    cin >> k >> x;

    for(ll i = max(mn, x-k+1); i <= min(mx, x+k-1); i++){
        cout << i << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)
cnt = 0
n.times do |i|
  if a[i] <= b[i]
    cnt += a[i]
    b[i] -= a[i]
    a[i] = 0
    if a[i+1] <= b[i]
      cnt += a[i+1]
      a[i+1] = 0
    else
      cnt += b[i]
      a[i+1] -= b[i]
    end
  else
    cnt += b[i]
  end
end
puts cnt



Measured memory_bytes: 19224
N=int(input())
L=[]
for i in range(N):
    x,l=map(int,input().split())
    a,b=x-l,x+l
    L.append((a,b))
L.sort(key=lambda  ab: ab[1])
#print(L)
robot=1
b=L[0][1]
for i in range(1,N):
    A,B=L[i]
    if A>=b:
        robot+=1
        b=B
print(robot)



Measured memory_bytes: 19408
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int a,c=0,d=0,e=0,f=0;
  cin>>a;
  int b[a];
  for(int i=0;i<a;i++)
    cin>>b[i];
  for(int i=0;i<a;i++){
    if(c<=d){
      c+=b[i-e];
      f++;
    }else{
      d+=b[a-i+f-1];
      e++;
    }
  }
  cout<<max(c,d)-min(c,d)<<endl;
}

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

int main(){
  int W, a, b;
  cin >> W >> a >> b;
  if ((a<=b && b<=a+W) || (a<=b+W && b<=a)){
    cout << 0 <<endl;
    return 0;
  }
  int x=abs(b-a-W);
  int y=abs(b+W-a);
  cout << min(x,y)<<endl;
}

Measured memory_bytes: 256
// #include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
// int fac(int a);
const int R=100010;
int main(){ 
    int n;
    int DP[R];
    cin>>n;
    
    for (int i=1;i<=R;i++){
        DP[i]=R;
        DP[0]=0;
        int power=1;
        while(power<=i){
            DP[i]=min(DP[i-power]+1,DP[i]);
            power *= 6;
        }
    }
    for (int i=1;i<=R;i++){
        int power=1;
        while(power<=i){
            DP[i]=min(DP[i-power]+1,DP[i]);
            power *= 9;
        }
    }
    cout<<DP[n]<<endl;
     return 0;
}

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

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

using namespace std;

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

	int ans = 1;
	REP(i, N-1) {
		if (s[i] != s[i + 1]) ans++;
	}

	cout << ans << endl;

	return 0;
}

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

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

const long long INF = 1LL << 60; // 十分大きい値とする

int main() {
    // 入力
    int N; cin >> N;
    vector<long long> h(N);
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    vector<long long> dp(N, INF);

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 0; i < N; ++i) {
        if (i + 1 < N) chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
        if (i + 2 < N) chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }

    // 答え
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
let () = Scanf.scanf "%d %d\n" @@ fun h w ->
  let ass = Array.init h @@ fun _ -> Scanf.scanf "%s\n" @@ fun s -> s in
  let rec bfs n ijs =
    match
      List.fold_left (fun (b, ijs) (i, j) ->
        if
          i < 0 || h <= i ||
          j < 0 || w <= j ||
          ass.(i).[j] = '#'
        then (b, ijs)
        else begin
          ass.(i).[j] <- '#';
          (false, (i - 1, j) :: (i + 1, j) :: (i, j - 1) :: (i, j + 1) :: ijs)
        end) (true, []) ijs
    with
    | (true, _) -> n
    | (false, ijs) -> bfs (n + 1) ijs in
  Printf.printf "%d\n" @@ bfs 0 @@
  List.concat @@ Array.to_list @@ Array.init h @@ fun i ->
    List.concat @@ Array.to_list @@ Array.init w @@ fun j ->
      if
        ass.(i).[j] = '#' ||
        List.for_all (fun (i, j) ->
          i < 0 || h <= i ||
          j < 0 || w <= j ||
          ass.(i).[j] = '.')
        [(i - 1, j); (i + 1, j); (i, j - 1); (i, j + 1)]
      then []
      else [(i, j)]


Measured memory_bytes: 145268
#include <iostream>
#include <stdlib.h>

using namespace std;

int main(){
  uint32_t A,B,C;
  cin >> A >> B >> C;
  uint8_t res = 0;
  if(A == B){
    if(B == C){
      if(C == A){
        cout << "Yes" << endl;
        res = 1;
      }
    } 
  }

  if(!res)
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]){
  int n[5];
  while(std::cin >> n[0], n[0]){
    n[0]--;
    for (int i = 0; i < 4; i++) {
      std::cin >> n[i + 1];
      n[i + 1]--;
    }
    bool used[3] = {}, draw = false;
    for (int i = 0; i < 5; i++) {
      used[n[i]] = true;
    }
    int win = -1;
    set<int> a;
    vector<int> ans;
    for (int i = 0; i < 5; i++) {
      a.insert(n[i]);
    }
    for (int i: a){
      ans.push_back(i);
    }
    if(ans.size() == 1 || ans.size() == 3){
      draw = true;
    }else if(ans[0] == 0 && ans[1] == 1){
      win = 0;
    }else if(ans[0] == 1 && ans[1] == 2){
      win = 1;
    }else if(ans[0] == 0 && ans[1] == 2){
      win = 2;
    }
    if(draw){
      for (int i = 0; i < 5; i++) {
        std::cout << 3 << std::endl;
      }
    }else{
      for (int i = 0; i < 5; i++) {
        if(win == n[i])std::cout << 1 << std::endl;
        else std::cout << 2 << std::endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1212
/*
 * Matheus Oliveira
 * 09:41:28 01/09/2019
 * e.cpp
*/

#include <bits/stdc++.h>
using namespace std;

#define EPS
#define INF
#define MAXN 1010
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define debug(x) printf("%s: %d\n", #x, x);
#define debugarr(x, ini, fim) printf("%s: ", #x); for(int i = ini; i <= fim; i++) printf("%d%c", x[i], (i == fim) ? '\n' : ' ');

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

bool day[MAXN];
int st[MAXN], m[MAXN][MAXN], poin[MAXN], n, idxs[MAXN], dae[MAXN];

bool compare(int f, int s) { return st[f] > st[s]; }

int main() {
	int pl1, pl2, ans = 0;
	scanf("%d", &n);
	
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j < n-1; j++) {
			scanf("%d", &m[i][j]);
			st[ m[i][j] ]++;
		}
	}

	for(int i = 1; i <= n; i++) idxs[i] = i;
	sort(idxs + 1, idxs + 1 + n, compare);

	bool att = true;

	while(att) {
		att = false;

		for(int i = 1; i <= n; i++) {
			while( poin[ idxs[i] ] < n-1 ) {
				pl1 = idxs[i];
				pl2 = m[pl1][ poin[pl1] ];

				if( m[pl2][ poin[pl2] ] == pl1) {
					att = true;

					dae[pl1] = dae[pl2] = max(dae[pl2], dae[pl1]);

					dae[pl1]++;
					dae[pl2]++;

					poin[pl1]++, poin[pl2]++;
					ans = max(ans, max(dae[pl1], dae[pl2]));
				}
				else break;
			}
		}

		if(att);
		else {
			bool ok = true;
			for(int i = 1; i <= n; i++) {
				if(poin[i] != n-1) ok = false;
			}
			
			if(not ok) printf("-1\n");
			else printf("%d\n", ans);

			return 0;
		}
	}

	assert(1 == 0);
	return 0;
}

Measured memory_bytes: 4224
#include<iostream>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long double ld;
#define mp make_pair
#define pb push_back

#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)

#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)

#define all(A) A.begin(), A.end()

const double PI = 3.141592653589793;

// const ll mod = 1e9 + 7;
const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}

ll id(char c) {
	return c - 'a';
}

bool isOK(vi& a, ll k, ll index) {
	return a[index] < k * (index + 1);
}

ll binary_search(vi& a, ll k) {
	ll left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	ll right = (ll)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		ll mid = left + (right - left) / 2;

		if (isOK(a, k, mid))
			right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}

template<class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
	return os << "{" << p.first << "," << p.second << "}";
}

template<class t> ostream& operator<<(ostream& os, const vector<t>& v) {
	os << "{";
	for (auto e : v)os << e << ",";
	return os << "}";
}

const ll M = 1e9 + 7;

vector<ll> fac(1e6+1); //n!(mod M)
vector<ll> ifac(1e6+1); //k!^{M-2} (mod 
ll mpow(ll x, ll n) { //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}

ll comb(ll a, ll b) { //aCbをmod計算
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}

int main() {
	ll X, Y;
	cin >> X >> Y;

	ll a = 2 * Y - X;
	ll b = 2 * X - Y;
	if ( a < 0 || b < 0 || a % 3 != 0 || b % 3 != 0) {
		cout << 0 << endl;
		return 0;
	}
	a /= 3;
	b /= 3;

	//大した量ではないので，先にfax[i]とifax[i]を全て計算しておく
	fac[0] = 1;
	ifac[0] = 1;
	for (ll i = 0; i < 1e6; i++) {
		fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
		ifac[i + 1] = ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
	}

	ll ans = comb(a + b, a);
	cout << ans << endl;

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<ll>> matrix;
const int MOD = 1000000007;

int g[16][16];
int n;

ll dp[1 << 16];
ll cache[1 << 16];

void solve() {
  cin >> n;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      cin >> g[i][j];
    }
  }
  for(int mask = 1; mask < (1<<n); mask++) {
    for(int i = 0; i < n; i++) {
      if(mask&(1<<i)) {
        for(int j = 0; j < i; j++) {
          if(mask&(1<<j)) {
            cache[mask] += g[i][j];
          }
        }
      }
    }
  }
  for(int mask = 1; mask < (1<<n); mask++) {
    dp[mask] = max(0LL, cache[mask]);
    int t = mask-1;
    while(true) {
      t &= mask;
      if(t == 0) break;
      dp[mask] = max(dp[mask], cache[t] + dp[mask ^ t]);
      t--;
    }
  }
  cout << dp[(1<<n)-1] << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
}


Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<cmath>
#include<cstdio>

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

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

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

int main(int argc, const char * argv[]) {
    
    int H, W;
    int CH, CW;
    int DH, DW;
    char S[1000][1000];
    int COST[1000][1000];
    
    cin >> H >> W;
    cin >> CH >> CW;
    cin >> DH >> DW;
    
    CH--;
    CW--;
    DH--;
    DW--;
    
    for(int h=0; h<H; h++){
        string s;
        cin >> s;
        
        for(int w=0; w<W; w++){
            S[h][w] = s[w];
            COST[h][w] = -1;
        }
    }
    

    deque<P> que;
    que.push_front(P(CH, CW));
    
    COST[CH][CW] = 0;
    
    while(que.size()){

        P p = que.front();
        que.pop_front();

        for(int i=0; i<4; i++){

            int ny = p.first + dy[i];
            int nx = p.second + dx[i];
            
            if(ny<0 || ny >= H || nx<0 || nx >= W) continue;
            
            //cout << ny << " " << nx << endl;
            
            if(COST[ny][nx] <= COST[p.first][p.second] && COST[ny][nx] > -1) continue;
            if(S[ny][nx] == '.'){
                COST[ny][nx] = COST[p.first][p.second];
                que.push_front(P(ny, nx));
            }
        }
        
        for(int i=4; i<24; i++){

            int ny = p.first + dy[i];
            int nx = p.second + dx[i];
            
            if(ny<0 || ny >= H || nx<0 || nx >= W) continue;
            if(COST[ny][nx] > -1) continue;

            if(S[ny][nx] == '.'){
                COST[ny][nx] = COST[p.first][p.second] + 1;
                que.push_back(P(ny, nx));
            }
        }
        
        /*or(int h=0; h<H; h++){
            for(int w=0; w<W; w++){
                if(COST[h][w] == -1) cout << COST[h][w] << ' ';
                else cout << ' ' << COST[h][w] << ' ';
            }
            cout << endl;
        }
        
        cout << endl;*/
    }
    
    cout << COST[DH][DW] <<  endl;
    
    return 0;
}


Measured memory_bytes: 8036
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<iomanip>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{"; for(auto nth : list){ cout << nth << " ";}cout << "}" << endl;

using namespace std;

int main(){

	int n;
	cin >> n;
	rep(i,n){
		string text;

		map<string,int> list;
		list.clear();
		cin >> text;
//		cout << text << endl;

		rep(k,text.length()){
			string ab,cd,ba,dc;
			
			ab=text.substr(0,k);
			cd=text.substr(k,text.length());
			
			//cout << ab << "+" << cd << endl;

			ba=ab;
			dc=cd;

			reverse(ba.begin(),ba.end());
			reverse(dc.begin(),dc.end());
	
			list[ab+cd]=1;
			list[ab+dc]=1;
			list[ba+cd]=1;
			list[ba+dc]=1;
			list[cd+ab]=1;
			list[cd+ba]=1;
			list[dc+ab]=1;
			list[dc+ba]=1;
			
		}

		cout << list.size() << endl;
		
	}
}

Measured memory_bytes: 1300
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const ll mod = 1000000007;
const ll LIM = 33;

string delsp(string s){
    string t = "";
    for(char c:s)if(c!=' ') t+=c;
    return t;
}

string s;
int n;
map<int,vector<int>> pos;

ll E(int &idx, int dep, int RR);
ll T(int &idx, int dep, int RR);

inline ll sq(ll x){
    return (x*x)%mod;
}

ll N(int &idx){
    ll ret = 0;
    while(idx<n && isdigit(s[idx])){
        ret = ret*10 + (s[idx]-'0');
        ret %= mod;
        ++idx;
    }
    return ret;
}

ll E(int &idx, int dep, int RR){
    if(pos[dep].empty()){
        return T(idx,dep,RR);
    }
    else{
        auto itr = lower_bound(all(pos[dep]), RR);
        if(itr != pos[dep].begin()){
            --itr;
            int rx = *itr;
            if(idx < rx){
                ll L = E(idx,dep,rx-1);
                assert(idx == rx);
                idx += 2;
                ll R = T(idx,dep,RR);

                if(R>LIM) return 0;
                else return L>>R;
            }
            else return T(idx,dep,RR);
        }
        else return T(idx,dep,RR);
    }
}

ll T(int &idx, int dep, int RR){
    if(isdigit(s[idx])){
        return N(idx);
    }
    else if(s[idx]=='S'){
        ++idx;
        assert(s[idx]=='<');
        ++idx;
        ll v = sq(E(idx,dep+1,RR));
        assert(s[idx]=='>');
        ++idx;
        return v;
    }
    else assert(false);
}

int main(){
    while(getline(cin,s),(s!="#")){
        pos.clear();

        s = delsp(s);

        n = s.size();
        int idx = n-1;
        while(idx>0){
            if(idx>0 && idx<n-1 && s[idx]=='>' && s[idx-1]=='>'){
                if(s[idx+1]=='S' || isdigit(s[idx+1])){
                    s[idx-1] = 'x';
                    s[idx] = 'x';
                }
            }
            --idx;
        }

        n = s.size();

        int d = 0;
        idx = 0;
        while(idx<n){
            if(s[idx]=='x'){
                pos[d].pb(idx);
                idx += 2;
            }
            else{
                if(s[idx]=='S') ++d;
                else if(s[idx]=='>') --d;

                ++idx;
            }
        }

        idx = 0;
        cout << E(idx,0,n) << endl;
    }
    return 0;
}



Measured memory_bytes: 10672
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    while (true) {
        int n, a, b, c, x;
        cin >> n >> a >> b >> c >> x;

        if (n == 0 && a == 0 && b == 0 && c == 0 && x == 0) {
            return 0;
        }

        vector<int> ys;
        for (int i = 0; i < n; ++i) {
            int y;
            cin >> y;
            ys.push_back(y);
        }

        int x_ = x;
        auto lcg = [a, b, c, &x_] {
            auto x__ = x_;
            x_ = (a * x_ + b) % c;
            return x__;
        };

        int count = 0;
        for (int i = 0; i < n; ++i) {
            while (true) {
                auto xx = lcg();
                count += 1;
                if (ys[i] == xx) {
                    break;
                }
                if (count > 10000) {
                    count = -1;
                    break;
                }
            }
            if (count == -1) {
                break;
            }
        }
        cout << (count == -1 ? count : count - 1) << endl;
    }
}

Measured memory_bytes: 3092
import java.util.*;
import java.io.*;
import java.math.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main{
    static long mod=1000000007;
    // static int dx[]={1,-1,0,0};
    // static int dy[]={0,0,1,-1};
    // static int dx[]={1,-1,0,0,1,1,-1,-1};
    // static int dy[]={0,0,1,-1,1,-1,1,-1};
    // PriorityQueue<Integer> que = new PriorityQueue<Integer>(); 
    //HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
    //ArrayList<Integer> lis = new ArrayList<Integer>();
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        // int n=sc.nextInt();
        long k=sc.nextLong();
        long r=50-k%50,q=k/50,d[]=new long[50];
        for( int i=0; i<50; i++ ){
            d[i] = i+1;
        }
        // r%=50;
        for( int i=0; i<r; i++ ){
            d[i]--;
        }
        out.println(50);
        if(k==0)fill(d,0);
        for( int i=0; i<50; i++ ){
            out.print(d[i]+q);
            if(i<49)out.print(" ");
        }

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

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }

    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }
     
    static boolean bit(long x,int k){
        // weather k-th bit (from right) be one or zero
        return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
    }
}

class Pair implements Comparable<Pair>{
    int x,y,id;
    Pair(int x, int y,int id) {
        this.x=x;
        this.y=y;
        this.id=id;
    } 
    public int compareTo(Pair p){
        return p.x -     x;
    } 
}

// class Pair implements Comparable<Pair>{
//     int x,y;
//     Pair(int x, int y) {
//         this.x=x;
//         this.y=y;
//     } 
//     public int compareTo(Pair p){//descend
//         return p.x - x;
//     } 

// }

class P implements Comparable<P>{
    int diff,id1,id2;
    P(int diff, int id1,int id2) {
        this.diff=diff;
        this.id1=id1;
        this.id2=id2;
    } 
      
    public int compareTo(P p){//ascend
        return diff - p.diff;
    } 
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

Measured memory_bytes: 22740
from heapq import heappop, heappush

class UnionFind():
    def __init__(self, n):
        self.parents = list(range(n))
        self.size = [1] * n

    def find(self, x):
        if self.parents[x] == x:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.size[x] < self.size[y]:
                x,y = y,x
            self.parents[y] = x
            self.size[x] += self.size[y]

N = int(input())
x = [None] * N
y = [None] * N
for i in range(N):
    a, b = map(int, input().split())
    x[i] = (a,i)
    y[i] = (b,i)

x.sort()
y.sort()
q = []
for i in range(N-1):
    heappush(q, (abs(x[i][0]-x[i+1][0]), x[i][1], x[i+1][1]))
    heappush(q, (abs(y[i][0]-y[i+1][0]), y[i][1], y[i+1][1]))

uf = UnionFind(N)
ans = 0
# クラスカル法
while len(q) > 0:
    w, s, t = heappop(q)
    if uf.find(s) != uf.find(t):
        ans += w
        uf.union(s,t)
print(ans)

Measured memory_bytes: 119592