akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<string> vs;

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

void init_global() {}

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

	ll X;  cin >> X;

	ll t = 0;
	ll distMax = 0;
	while (distMax < X) {
		t++;
		distMax = t*(1 + t) / 2;
	}

	ll ans=t;
	cout << ans << endl;
	return 0;
}


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

int main(){
  while(true){
    int a,b;
    cin >> a >> b;
    if(a == 0 && b == 0){
      break;
    }
    int maximum = max(a, b);
    int minimum = min(a, b);
    cout << minimum << " " << maximum << endl;
  }
}


Measured memory_bytes: 3064
#include <cstdio>
#include <set>
#include <cassert>
#include <cmath>
#include <iostream>
using namespace std;

void bruteforce(int N, int D, int *d, bool *ans) {
    int p[N+1];
    p[0] = D;
    for (int i = 0, pos = D; i < N; i++) {
        pos = min(pos, abs(pos - d[i]));
        p[i+1] = pos;
    }
    if (p[N] != 0) {
        fill(ans, ans+N, true);
        return;
    }
    fill(ans, ans+N, false);
    set<int> S;
    S.insert(0);
    for (int i = N-1; i >= 0; i--) {
        for (int x = p[i]; x > 0; x--)
            if (S.find(x) == S.end()) {
                ans[i] = true;
                break;
            }
        set<int> temp;
        for (int p = 0; p <= d[i]; p++)
            if (S.find(min(p, d[i] - p)) != S.end()) temp.insert(p);
        for (int x : S) temp.insert(x + d[i]);
        S.swap(temp);
        // cerr << "i = " << i << "; "; for (int x : S) cerr << x << " "; cerr << endl;
    }
}

int main() {
    int N, D; cin >> N >> D;
    int d[N]; for (int i = 0; i < N; i++) scanf(" %d", &d[i]);
    bool ans[N];
    int p[N+1], s[N+1];
    p[0] = D;
    for (int i = 0, pos = D; i < N; i++) {
        pos = min(pos, abs(pos - d[i]));
        p[i+1] = pos;
    }
    // for (int i = 0; i <= N; i++) cerr << p[i] << endl;
    if (p[N] == 0) {
        s[N] = 0;
        for (int i = N-1; i >= 0; i--) {
            ans[i] = p[i] > s[i+1];
            s[i] = max((d[i] + 1) / 2, d[i] - s[i+1]) - min(d[i] / 2, s[i+1]) <= 1 ? d[i] + s[i+1] : min(d[i] / 2, s[i+1]);
            // cerr << i << " " << s[i] << endl;
        }
    } else {
        fill(ans, ans+N, true);
    }

    // bool ans2[N];
    // bruteforce(N, D, d, ans2);
    // for (int i = 0; i < N; i++)
    //     if (ans[i] != ans2[i]) {
    //         cerr << "wrong answer on i = " << i << "; " << ans[i] << " != " << ans2[i] << endl;
    //     }

    int q; cin >> q;
    while (q--) {
        int x; cin >> x;
        puts(ans[x-1] ? "YES" : "NO");
    }
}


Measured memory_bytes: 9508
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
#define fi first
#define se second
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<pii> vpii; 
typedef vector<string> vs;
typedef vector<vi> vvi;
int main() {
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout); 
	int n,h,w;
	int x,y;
	int cnt=0;
	cin>>n>>h>>w;
	for(int i=0;i<n;i++){
		cin>>x>>y;
		if(x>=h && y>=w)cnt++;
	}
	cout<<cnt<<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++)
#define rep2(i, m, n) for(int i = m; i < (int)(n); i++)
#define MOD 1000000007
#define Graph vector<vector<int>>
typedef pair<int, int> PII;
typedef long long int ll;

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> Hi(N);

  rep(i,N) cin >> Hi[i];

  sort(Hi.begin(),Hi.end());
  reverse(Hi.begin(),Hi.end());
  
  ll ans = 0;
  rep(i,N){
    if(i < K) continue;
    ans += Hi[i];
  }

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a;
    cin >> a;
    double c,b;
    if(a%2 == 0){
        b = a/2;
        c = b/a;
        cout << fixed <<setprecision(10);
        cout <<c <<endl;
    }
    else if(a%2 == 1){
        b = a/2+1;
        c = b/a;
        cout << fixed <<setprecision(10);
        cout <<c <<endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    string S;cin>>S;
    int cnt=0;
    for(int i=0;i<N;i++) if(S[i]=='R') cnt++;
    
    int ans=0;
    for(int i=0;i<cnt;i++) if(S[i]=='W') ans++;
    
    cout<<ans<<endl;
}


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

int main(){
  int n;
  cin >> n;
  if(1<=n&&n<=9) cout << n << endl;
  else if(10<=n&&n<=99) cout << 9 << endl;
  else if(100<=n&&n<=999) cout << n-90 << endl;
  else if(1000<=n&&n<=9999) cout << 909 << endl;
  else if(10000<=n&&n<=99999) cout << n-9090 << endl;
  else cout << 90909 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
queue<int> A;
stack<int> B;

int main()
{
  int64_t N, M, a, b, c, sum = 0;
  cin >> N >> M;
  priority_queue<int64_t> A;
  vector<pair<int64_t, int64_t>> vp(M);
  for (int i = 0; i < N; i++)
  {
    cin >> a;
    A.push(a);
  }

  for (int i = 0; i < M; i++)
  {
    cin >> b >> c;
    vp.at(i) = make_pair(c, b);
  }
  sort(vp.begin(), vp.end());
  reverse(vp.begin(), vp.end());

  queue<int64_t> B;
  for (int i = 0; i < vp.size(); i++)
  {
    int x = vp.at(i).first;
    int y = vp.at(i).second;
    for (int j = 0; j < y; j++)
    {
      B.push(x);
    }
    if (B.size() >= N)
      break;
  }

  for (int i = 0; i < N; i++)
  {
    if (A.top() > B.front())
    {
      sum += A.top();
      A.pop();
    }
    else
    {
      sum += B.front();
      B.pop();
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)
#define INF 1 << 28
typedef pair<int,int> Pi;
#define F first
#define S second
#define pb push_back

inline void chmax(int &a, int b) { a = max(a,b); }
inline void chmin(int &a, int b) { a = min(a,b); }

int main()
{
  string s;
  int maxv = 0;
  int m[3] = {'J','O','I'};

  cin >> s;
  int i = 0;
  while(i < s.size()) {
    if(m[0] == s[i]) {
      int count[3] = {0};
      Rep(j,3)for(; m[j] == s[i]; i++, count[j]++);
      if(min(count[0],count[2]) < count[1])continue;
      chmax(maxv,count[1]);
    } else i++;
  }
  cout << maxv << endl;
  return 0;
}

Measured memory_bytes: 3960
#include <stdio.h>
#define INF 100000000

int main(void){
	int n, k;
	int a, b, c, d;
	int v;
	int cost[100][100];
	int i, j, l, m;

	while(1){
		v = 0;
		scanf("%d %d", &n, &k);
		if(n == 0 && k == 0) break;

		//Initialize
		for(i=0; i<n; i++){
			for(j=0; j<n; j++){
				cost[i][j] = INF;
			}
		}
		for(i=0; i<n; i++){
			cost[i][i] = 0;
		}

		for(i=0; i<k; i++){
			scanf("%d", &a);
			if(a == 0){
				scanf("%d %d", &b, &c);
				if(cost[b-1][c-1] != INF){
					printf("%d\n", cost[b-1][c-1]);
				}else{
					printf("-1\n");	
				}
			}else if(a == 1){
				scanf("%d %d %d", &b, &c, &d);
				if(cost[b-1][c-1] == INF) v++;
				if(cost[b-1][c-1] > d) {
					cost[b-1][c-1] = d;
					cost[c-1][b-1] = d;
					//WF
					for(l=0; l<n; l++){
						for(m=0; m<n; m++){
							for(j=0; j<n; j++){
								if(cost[m][j] > cost[m][l] + cost[l][j]){
									cost[m][j] = cost[m][l] + cost[l][j];
								}
							}
						}
					}
				}

			}
		}
	}
	
	return 0; 
}

Measured memory_bytes: 460
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  long n;
  cin >> n;
  vl sum(n+1,0);
  rep(i,n){
    sum.at(i+1) = sum.at(i) + i+1;
  }
  long ans = 0;
  REP(i,1,n+1){
    long t = n / i;
    ans += sum.at(t) * i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 81392
n, x = gets.chomp.split(' ').map(&:to_i)
$arr_p = Array.new(n + 1, 0)
$arr_n = Array.new(n + 1, 0)
$arr_p[0] = 1
$arr_n[0] = 1

(1..n).each do |i|
  $arr_p[i] = $arr_p[i - 1] * 2 + 1
  $arr_n[i] = $arr_n[i - 1] * 2 + 3
end

def func(n, x)
  if n == 0
    return 1
  elsif x == 1
    return 0
  elsif $arr_n[n - 1] + 1 > x
    return func(n - 1, x - 1)
  elsif $arr_n[n - 1] + 1 == x
    return $arr_p[n - 1]
  elsif $arr_n[n - 1] + 2 == x
    return $arr_p[n - 1] + 1
  else
    return func(n - 1, [x - $arr_n[n - 1] - 2, $arr_n[n - 1]].min) + $arr_p[n - 1] + 1
  end
end

puts func(n, x)

Measured memory_bytes: 3836
import sys
input = sys.stdin.readline

from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))

ans = 0
dic = defaultdict(int)
for a in A:
    dic[a] += 1
    ans += a

Q = int(input())
for _ in range(Q):
    B, C = map(int, input().split())
    tmp = dic[B]
    ans -= tmp * B
    dic[C] += tmp
    ans += tmp * C
    dic[B] = 0
    print (ans)



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

// bool evenNumberOfOnesInBinary(int number){
//     int count = 0;
//     while(number>0){
//         if(number%2!=0) count++;
//         number = number/2;
//     }
//     return count%2==0;
// }

bool evenNumberOfOnesInBinary(long long int x)
{
    long long int y = x ^ (x >> 1);
    y = y ^ (y >> 2);
    y = y ^ (y >> 4);
    y = y ^ (y >> 8);
    y = y ^ (y >> 16);
   if (y & 1)
        return false;
    return true;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string S; cin>>S;
    int a = 0, b = 0;
    for(int i=0; i<3; ++i){
        if(S[i]=='A') a = 1;
        if(S[i]=='B') b= 1;
    }
        if(a && b) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
}

Measured memory_bytes: 256
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_4_B&lang=jp

#include<iostream>
 using namespace std;

int main(){

    double r ;
    cin >> r ;
    
    cout << fixed; //精度保障のためこの記述が必要なようです。
    cout << r * r * 3.1415926535897 << " " << 2 * r * 3.1415926535897 << endl ;  
    return 0;

}


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

using namespace std;

int main() {
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	long long count = 0;
	int rest = n - k;
	if (rest < 0)
	{
		rest = 0;
		k = n;
	}
	count = k*x + y*rest;
	cout << count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define X first
#define Y second
#define pb push_back
#define pii pair<int, int>
typedef long long ll;
using namespace std;

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int OFF = (1 << 20);

int h, n, a, zbr = 0;

int main () {

	cin >>h >> n;
	for (int i = 0;i < n; i++) {
		cin >> a;
		zbr += a;
	}
	
	if (zbr >= h) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;

int main(){
    int a,b,c,d; cin >> a >> b >> c  >> d;
    string ans;
    for(;;){
        c-=b;
        if(c<=0){
            ans="Yes";
            break;
        }
        a-=d;
        if(a<=0){
            ans="No";
            break;
        }
    }
    cout << ans << endl;
return 0;
}



Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	vector<int> v(5);
	for (int i = 0; i < 5;i++) cin >> v[i];
	sort(v.begin(), v.end());
	for (int i = 4;i >= 0;i--) {
		cout << v[i];
		if (i != 0)cout << " ";
		else cout << endl;
	}
}

Measured memory_bytes: 3048
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        c: i32,
        b: [i32; m],
    };

    let mut count = 0;
    for _ in 0..n {
        input! {
            a: [i32; m],
        };

        let a: Vec<i32> = a;

        let mut sum: i32 = 0;
        for (ai, bi) in a.iter().zip(b.iter()) {
            sum += ai * bi;
        }
        sum += c;

        if sum > 0 {
            count += 1;
        }
    }

    println!("{}", count);
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <iostream>
typedef long long ll;
typedef int64_t in;
using namespace std;
#define INF 1000000007


int main() {
    while(1){
        int n, m;
        cin >> n >> m;
        if(n==0 && m==0) break;
        vector<int> a(n);
        for(int i=0; i<n; i++) cin >> a[i];

        int max = -1;
        for(int i=0; i<n; i++){
            for(int j=i+1; j<n; j++){
                if(max < a[i]+a[j] && a[i]+a[j] <= m){
                    max = a[i] + a[j];
                }
            }
        }
        if(max == -1) cout << "NONE" << endl;
        else cout << max << endl;
    }
}


Measured memory_bytes: 3100
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define FASTIO cin.tie(0),ios::sync_with_stdio(0)



int main() {
    FASTIO;
    int n;
    cin >> n;
    vector<ll> a(n);
    for (auto&& i : a) cin >> i;

    sort(ALL(a));
    map<ll, int> cnt;
    for (auto&& i : a) {
        cnt[i]++;
    }

    vector<ll> b;
    for (auto&& i : cnt) {
        rep(j, i.second / 2) b.push_back(i.first);
    }

    int m = b.size();
    if (m < 2) {
        cout << 0 << endl;
    }
    else {
        cout << b[m - 1] * b[m - 2] << endl;
    }

    return 0;
}

Measured memory_bytes: 7296
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    A = [0] + readInts() + [0]
    S = 0
    for i in range(1,n+2):
        S += abs(A[i] - A[i-1])
    #print(S)
    for i in range(1,n+1):
        print(S + abs(A[i-1] - A[i+1]) - (abs(A[i-1] - A[i]) + abs(A[i] - A[i+1])))
    


if __name__ == '__main__':
  main()


Measured memory_bytes: 14048
#include<stdio.h>
#include<map>
#define max(a,b) ((a<b)?b:a)

int N;
int A[100003],B[100003];
int cntn[100003];
int cl[100003];
int maxc;
int i,j,k;
std::map<int,bool> used[100003];
std::map<int,int> path[100003];
int node;
int main(){
  scanf("%d",&N);
  for(i=0;i<=N;i++){
    cntn[i] = 0;
  }
  for(i=0;i<N-1;i++){
    scanf("%d%d",A+i,B+i);
    path[A[i]][cntn[A[i]]] = i;
    cntn[A[i]]++;
    cl[i] = -1;
  }
  for(i=0;i<N;i++){
    k=1;
    for(j=0;j<cntn[i];j++){
      for(;used[i][k];k++){}
      cl[path[i][j]] = k;
      used[B[path[i][j]]][k] = true;
      k++;
    }
  }
  maxc=0;
  for(i=0;i<N-1;i++){
    maxc = max(maxc,cl[i]);
  }
  printf("%d\n",maxc);
  for(i=0;i<N-1;i++){
    printf("%d\n",cl[i]);
  }
}


Measured memory_bytes: 25472
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
#define MAX_N 110
#define MAX_V 100010

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

// Input
int N;
long long W, weight[MAX_N], value[MAX_N];

// DP table
long long dp[MAX_N][MAX_V];

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; i++) cin >> weight[i] >> value[i];

    // Initialization
    for (int i = 0; i < MAX_N; i++) for (int j = 0; j < MAX_V; j++) dp[i][j] = INF;

    // Initial state
    dp[0][0] = 0;

    // Update
    for (int i = 0; i < N; i++) {
        for (int sum_v = 0; sum_v < MAX_V; sum_v++) {
            if (sum_v - value[i] >= 0) chmin(dp[i+1][sum_v], dp[i][sum_v - value[i]] + weight[i]);
            chmin(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }

    // Ans
    long long res = 0;
    for (int sum_v = 0; sum_v < MAX_V; sum_v++) {
        if (dp[N][sum_v] <= W) res = sum_v;
    }
    cout << res << endl;
}


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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

    // 入力
    int w, h, n;
    cin >> w >> h >> n;
    int x[n], y[n], a[n];
    rep(i, n) { cin >> x[i] >> y[i] >> a[i]; }
    // rep(i, n) { cout << x[i] << y[i] << a[i]; }

    // 処理
    int v = 0;
    int u = w;
    int l = 0;
    int z = h;
    rep(i, n) {
        if (a[i] == 1) {
            v = max(v, x[i]);
        } else if (a[i] == 2) {
            u = min(u, x[i]);
        } else if (a[i] == 3) {
            l = max(l, y[i]);
        } else {
            z = min(z, y[i]);
        }
    }
    // cout << v << " " << u << " " << l << " " << z << endl;
    int ans = max(u - v, 0) * max(z - l, 0);

    // 出力
    if (ans < 0) {
        cout << 0 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

void foo(string s, vector<string> w, vector< vector<string> >& v) {
	if (s.empty()) {
		v.push_back(w);
		return;
	}
	for (int l = 1; l <= s.length(); l++) {
		vector<string> _w = w;
		_w.push_back(s.substr(0, l));
		foo(s.substr(l), _w, v);
	}
}

int main() {
	for (;;) {
		int t; string num; cin >> t >> num;
		if (t == 0) break;
		vector< vector<string> > v;
		foo(num, vector<string>(), v);
		int _i, maxi = -1;
		bool rejected = false;
		for (int i = 0; i < v.size(); i++) {
			int sum = 0;
			for (int j = 0; j < v[i].size(); j++) {
				stringstream ss(v[i][j]);
				int x; ss >> x;
				sum += x;
			}
			if (sum > t) continue;
			if (sum > maxi) {
				_i = i;
				maxi = sum;
				rejected = false;
			}
			else if (sum == maxi)
				rejected = true;
		}
		if (maxi == -1) cout << "error" << endl;
		else if (rejected) cout << "rejected" << endl;
		else {
			cout << maxi;
			for (int j = 0; j < v[_i].size(); j++)
				cout << ' ' << v[_i][j];
			cout << endl;
		}
	}
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
#define ll long long
#define INF 10000000000000ll
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n;i>=0;i++)
using namespace std;
signed main(){
  double n,a[1000],sum[1000],mp=INF,cun=0,b=0;
  cin>>n;
  rep(i,n){
    cin>>a[i];
    cun+=a[i];
  }
  cun = cun / n;
  rep(i,n){
    sum[i] = abs(a[i]-cun);
    if(mp>sum[i]){
      mp = sum[i];
      b = i;
    }
  }
  cout<<b<<"\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	char a,b;
	cin>>a>>b;
	if(a>b) cout<<">\n";
	else if(a<b) cout<<"<\n";
	else cout<<"=\n";
}


Measured memory_bytes: 256
use std::io::{self, Read, Write};

fn main() {
    let si = io::stdin();
    let mut si = si.lock();
    let so = io::stdout();
    si.read_exact(&mut [0; 4]).unwrap();
    let mut so = so.lock();
    write!(so, "2018").unwrap();
    io::copy(&mut si, &mut so).unwrap();
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

LL n, a[100001], b[100000];

int main() {
	cin >> n;
	inc(i, n + 1) { cin >> a[i]; }
	inc(i, n) { cin >> b[i]; }
	
	LL ans = 0;
	inc(i, n) {
		LL c = min(a[i], b[i]);
		ans += c;
		a[i] -= c;
		b[i] -= c;
		
		c = min(a[i + 1], b[i]);
		ans += c;
		a[i + 1] -= c;
		b[i] -= c;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <random>
#include <fstream>
#include <time.h>
// #define int long long
#define debug(x) cerr << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double EPS = 1e-9;


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

  ll n;
  cin>>n;
  string s[n];
  rep(i,n) cin>>s[i];
  ll frontb = 0, backa = 0, both = 0;
  ll ans = 0;
  rep(i,n) {
    ll l = s[i].size();
    rep(j, l-1) {
      if(s[i][j] == 'A' && s[i][j+1] == 'B') {
        ans++;
      }
    }
    if(s[i][0] == 'B' && s[i][l - 1] == 'A') {
      both++;
    } else if (s[i][0] == 'B') {
      frontb++;
    } else if (s[i][l-1] == 'A') {
      backa++;
    }
  }
  if(both > 0) {
    ans += both-1;
  }
  if(both > 0 && frontb>0) {
    ans++;
    frontb--;
  }
  if(both > 0 && backa>0) {
    ans++;
    backa--;
  }
  ans += min(frontb, backa);

  // ans += min(frontb, backa);
  // if(frontb != backa && both > 0) {
  //   ans++;
  // }
  // if(both > 0) {
  //   ans += both-1;
  // }
  cout << ans << endl;


  return 0;
}


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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(0)





void solve() {

	
	int n;
	cin >> n;
	ll sum = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			for(int k = 1; k <= n; k++) {
				sum += __gcd(i, __gcd(j, k));
			}
		}
	}
	fix;
	cout << sum << "\n";




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	fix;
	solve();

	return 0;
}

Measured memory_bytes: 3588
#include<stdio.h>
int main(void){
char s[12],a[12];
int i,c=0;
scanf("%s",s);
for(i=0;s[i]!='\0';i++){
if(s[i]=='B'){
c--;
if(c<0)c=0;
}else{
a[c]=s[i];
c++;
}
}
for(i=0;i<c;i++)printf("%c",a[i]);
puts("");return 0;
}

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

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = in.nextInt(), m = in.nextInt();
        while (n != 0) {
            long[] a = new long[n];
            long ans = -1;
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                for (int j = 0; j < i; j++) {
                    if (a[i] + a[j] <= m) {
                        ans = Math.max(a[i] + a[j], ans);
                    }
                }
            }
            if (ans == -1) {
                out.println("NONE");
            } else {
                out.println(ans);
            }

            n = in.nextInt();
            m = in.nextInt();
        }
        out.flush();
    }
}



Measured memory_bytes: 50164
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <math.h>
#include <time.h>
#include <vector>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long ll;

int main(void){
    ll a, b, q, s[100010], t[100010], x;
    cin >> a >> b >> q;
    s[0] = t[0] = 0;
    for (int i = 1; i <= a; i++) cin >> s[i];
    for (int i = 1; i <= b; i++) cin >> t[i];
    s[a+1] = t[b+1] = 1e11;
    
    for (int i = 0; i < q; i++) {
        cin >> x;
        
        ll low1 = 0, high1 = a+1; 
        while (high1 - low1 > 1) {
            ll mid1 = (low1 + high1) / 2;
            if (s[mid1] < x) low1 = mid1;
            else high1 = mid1;
        }
        
        ll low2 = 0, high2 = b+1; 
        while (high2 - low2 > 1) {
            ll mid2 = (low2 + high2) / 2;
            if (t[mid2] < x) low2 = mid2;
            else high2 = mid2;
        }
        
        ll d[4];
        if (s[low1] < t[low2]) {
            if (s[low1 + 1] < t[low2 + 1]) {
                if (low1 *low2 != 0) d[0] = x - s[low1];
                else d[0] = 1e18;
                if (low2 != 0) d[1] = x - 2*t[low2] + s[low1 + 1];
                else d[1] = 1e18;
                if (low1 != a && low2 != 0) d[2] = 2 * s[low1 + 1] - x - t[low2];
                else d[2] = 1e18;
                if (low1 != a && low2 != b) d[3] = t[low2 + 1] - x;
                else d[3] = 1e18;
            }
            else {
                if (low1 * low2 != 0) d[0] = x - s[low1];
                else d[0] = 1e18;
                if (low1 != a && low2 != b) d[1] = s[low1 + 1] - x;
                else d[1] = 1e18;
                d[2] = d[3] = 1e18;
            }
        }
        else {
            if (s[low1 + 1] < t[low2 + 1]) {
                if (low1 *low2 != 0) d[0] = x - t[low2];
                else d[0] = 1e18;
                if (low1 != a && low2 != b) d[1] = t[low2 + 1] - x;
                else d[1] = 1e18;
                d[2] = d[3] = 1e18;
            }
            else {
                if (low1 *low2 != 0) d[0] = x - t[low2];
                else d[0] = 1e18;
                if (low1 != 0) d[1] = x - 2*s[low1] + t[low2 + 1];
                else d[1] = 1e18;
                if (low2 != b && low1 != 0) d[2] = 2 * t[low2 + 1] - x - s[low1];
                else d[2] = 1e18;
                if (low1 != a && low2 != b) d[3] = s[low1 + 1] - x;
                else d[3] = 1e18;
            }
        }
        //cout << s[low1] << " " << t[low2] << " " << endl;
        //cout << s[low1+1] << " " << t[low2+1] << endl;
        
        //cout << d[0] << " " << d[1] << " " << d[2] << " " << d[3] << endl;
        cout << min(d[0], min(d[1], min(d[2], d[3]))) << endl;
        
    }
    
}


Measured memory_bytes: 2816
n,w=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]

lim=n*10**3+1
#dp=[[float('inf') for i in range(lim)] for i in range(n+1)]
dp=[[10**15 for i in range(lim)] for i in range(n+1)]

'''
for i in range(n+1):
 dp[i][0]=0
'''
dp[0][0]=0

for i in range(n):
 for sum_v in range(lim):

  if sum_v-l[i][1]>=0:
   dp[i+1][sum_v] = min(dp[i+1][sum_v],dp[i][sum_v-l[i][1]]+l[i][0])

  dp[i+1][sum_v]=min(dp[i+1][sum_v],dp[i][sum_v])

ans=0
for i in range(lim):
 if dp[-1][i]<=w:
  ans=max(ans,i)
print(ans)

Measured memory_bytes: 173832
using System;
class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        int[] checklist = new int[52];
        for (int i = 0; i < n; i++)
        {
            string[] data = Console.ReadLine().Split(' ');
            if (data[0] == "S")
            {
                checklist[int.Parse(data[1])-1] = -1;
            }
            else if (data[0] == "H")
            {
                checklist[int.Parse(data[1]) + 12] = -1;
            }
            else if (data[0] == "C")
            {
                checklist[int.Parse(data[1]) + 25] = -1;
            }
            else if (data[0] == "D")
            {
                checklist[int.Parse(data[1]) + 38] = -1;
            }
        }
        for (int i = 0; i < 52; i++)
        {
            if (checklist[i] != -1)
            {
                if (i < 13)
                {
                    Console.WriteLine("S {0}",i + 1);
                }
                else if (i < 26)
                {
                    Console.WriteLine("H {0}", i - 12);
                }
                else if (i < 39)
                {
                    Console.WriteLine("C {0}", i - 25);
                }
                else if (i < 52)
                {
                    Console.WriteLine("D {0}", i - 38);
                }
            }
        }
    }
}

Measured memory_bytes: 5636
#include<bits/stdc++.h>
using namespace std;
#define X           first
#define Y           second
#define pb          push_back
#define pp          pop_back
#define mk          make_pair
#define EPS         1e-9
#define INF         1<<25
#define ln          '\n'
#define sp          ' '
#define all(x)      x.begin(),x.end()
#define Sort(x)     sort(all(x))
#define mem(a,b)    memset(a,b,sizeof(a))
#define lpa(p,v)    for(auto p:(v))
#define lp(a,b,c)   for(int a=(b);a<(c);a++)
#define lp0(a,n)    lp(a,0,n)
#define lpr(a,b,c)  for(int a=(b);a>=(c);a--)
#define faster      ios_base::sync_with_stdio(0);cin.tie(0);
#define debug(a)    cout<<a<<ln;
#define debug2(a,b)    cout<<a<<sp<<b<<ln;
#define debug3(a,b,c)    cout<<a<<sp<<b<<sp<<c<<ln;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<int,string> psi;
typedef map<int,int>mii;

inline bool sc(int &_x){return scanf("%d",&_x)==1;}
inline bool sc(int &_x, int &_y){return sc(_x)&&sc(_y);}
inline bool sc(int &_x, int &_y, int &_z){return sc(_x)&&sc(_y)&&sc(_z);}
inline bool sc(int &_x, int &_y, int &_z, int &_zz){return sc(_x)&&sc(_y)&&sc(_z)&&sc(_zz);}

/*int x4[]= {1,-1,0,0};
int y4[]= {0,0,1,-1};
int x8[]= {0,0,+1,-1,-1,+1,-1,+1};
int y8[]= {-1,+1,0,0,+1,+1,-1,-1};
int kx[]= {2,2,-2,-2,1,-1,1,-1};
int ky[]= {1,-1,1,-1,2,2,-2,-2};*/
const double PI=acos(-1.0);
const int N=1000005;
const int MOD=1e9+7;
pii a[N];
int main()
{
    int n,m;cin>>n>>m;
    int l=0,r=INF;
    lp0(i,m)cin>>a[i].X>>a[i].Y;
    sort(a,a+m);
    lp0(i,m)
    {
        l=max(l,a[i].X);
        r=min(r,a[i].Y);
    }
    cout<<max(0,r-l+1)<<ln;


}




Measured memory_bytes: 1024
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

a, b, k = Is()
if a > k:
    print("{} {}".format(a-k, b))
elif a + b > k:
    print(("0 {}".format(b-k+a)))
else:
    print("0 0")

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    REP(i,n){
        cin>>a[i];
    }
    int m=a[0];
    int ans=0;
    REP(i,n){
        if(m<=a[i]){
            ans++;
            m=a[i];
        }
    }
    OUT(ans);
    return 0;
}

Measured memory_bytes: 256
N,K = input().strip().split(' ')
N,K = [int(N),int(K)]

P = 0.0

for n in range(1,N+1) :
    count = 0
    k = n
    while k < K:
        count += 1
        k = k * 2
    
    P += ( 1 / N * 1/pow(2,count))
    # print(P)

print(P)



Measured memory_bytes: 2940
n, l = map(int,input().split())
aji = [0]*n
for i in range(1,n+1,1):
    aji[i-1] = l+i-1

aji_abs = [0]*n
for i in range(1,n+1,1):
    aji_abs[i-1]  = abs(aji[i-1])
aji.remove(aji[aji_abs.index(min(aji_abs))])
print(sum(aji))


Measured memory_bytes: 3060
// AtCoder-Template.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

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

#define FOR(i,N) for(auto i=0; i<N; ++i)

/* clang-format off */
template <class T> inline void chmin(T& a, const T& b) { if (b < a) a = b; }
/* clang-format on */


int main() {
	ll N; cin >> N; vector<ll> A(N); FOR(i, N) cin >> A[i];
	ll ans = 0;

	auto getSign = [](auto a) { if (a > 0) return 1; else return -1; };
	auto reverseSign = [&](auto a) { return -1 * getSign(a);  };

	ll accumu = A[0];
	if (accumu <= 0) {
		ans += abs(accumu) + 1;
		accumu = 1;
		
	}
	FOR(i, N - 1) {
		accumu +=  A[i + 1];
		if (i + 1 >= 1 and !(   ((i+1)%2 == 0) ? accumu > 0 : accumu < 0)  ) {
			ans += abs(accumu) + 1;
			accumu = reverseSign(accumu);
		}
		;
	}

	// -------------------------- 

	accumu = A[0];
	ll tmp = 0;
	if (accumu >= 0) {
		tmp += abs(accumu) + 1;
		accumu = -1;

	}
	FOR(i, N - 1) {
		accumu += A[i + 1];
		if (i + 1 >= 1 and !(((i+1)% 2 == 1) ? accumu > 0 : accumu < 0)) {
			tmp += abs(accumu) + 1;
			accumu = reverseSign(accumu);
		}
	}

	
	chmin(ans, tmp);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1152
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define sz size()

const double EPS = 1e-10;
const int INF = 100000000;


int solve(string s){
    int c=0;
    map<string,bool> data;
    data.clear();
    
    int len=s.sz;
    REP(i,1,len){
        string a=s.substr(0,i);
        string b=s.substr(i,len-i);
        
        if(data[a+b]==false)c++;
        data[a+b]=true;
        
        reverse(all(a));
        if(data[a+b]==false)c++;
        data[a+b]=true;
        
        reverse(all(b));
        if(data[a+b]==false)c++;
        data[a+b]=true;
        
        reverse(all(a));
        if(data[a+b]==false)c++;
        data[a+b]=true;

        reverse(all(b));
        
        if(data[b+a]==false)c++;
        data[b+a]=true;
        
        reverse(all(a));
        if(data[b+a]==false)c++;
        data[b+a]=true;
        
        reverse(all(b));
        if(data[b+a]==false)c++;
        data[b+a]=true;
        
        reverse(all(a));
        if(data[b+a]==false)c++;
        data[b+a]=true;

    }
    
    
    return c;
}


int main(){
    
    int n;
    cin>>n;
    rep(i,n){
        string s;
        cin>>s;
        cout<<solve(s)<<endl;
    }
    
    return 0;
}

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

int main() {
  int a,b,x;
  cin >> a >> b;
  string c,d;
  c = to_string(a);
  d = to_string(b);
  x = stoi((c+d));
  bool y = true;
  for(int i=0;i<1000;i++){
    if( i*i == x ){
      cout << "Yes" <<endl;
      y = false;
    }
  }
  if(y)
    cout << "No" <<endl;
  
}

Measured memory_bytes: 3688
A,B,C=sorted(map(int,input().split()))
Z=C-B
ZZ = (C-(A+Z))/2
ANS=0
if ZZ == (C-(A+Z))//2:
  ANS = Z + (C-(A+Z))//2
else:
  import math
  ANS = Z + math.ceil(ZZ) + 1
print(ANS)

Measured memory_bytes: 3060
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var sch = new List<int>[30];
            for (int i = 0; i < 30; i++) sch[i] = new List<int>();
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Trim().Split(' ');
                var t = int.Parse(line[0]);
                for (int j = 1; j <= t; j++)
                {
                    var w = int.Parse(line[j]) - 1;
                    sch[w].Add(i);
                }
            }
            Console.WriteLine(getAns(sch, setMap(n)));
        }
    }
    public static long[] setMap(int n)
    {
        var ret = new long[n];
        for (int i = 0; i < n; i++)
            ret[i] = 1L << i;
        return ret;
    }
    public static int getAns(List<int>[] sch, long[] map)
    {
        var n = map.Length;
        var w = Convert.ToInt64(new string('1', n), 2);

        for (int i = 0; i < 30; i++)
        {
            var ret = 0L;
            foreach (var x in sch[i])
                ret = ret | map[x];
            if (ret == w) return i + 1;
            foreach (var x in sch[i]) map[x] = ret;
        }
        return -1;
    }
}


Measured memory_bytes: 9768
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    ll f = INF-100000LL;
    vector<P> p;
    REP(i,n) {
        ll a;
        cin >> a;
        p.push_back({a, f});
        f += 2LL;
    }
    sort(p.begin(), p.end());
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> c(n-1);
    a[0] = 1;
    b[0] = p[0].second-a[0];
    for (int i = 1; i < n; ++i) {
        if (p[i].second-p[i-1].second >= 0) {
            b[i] = b[i-1]-1;
            a[i] = p[i].second-b[i];
        } else {
            a[i] = a[i-1]+1;
            b[i] = p[i].second-a[i];
        }
    }
    REP(i,n) {
        cout << a[i] << " ";
    }
    cout << endl;
    REP(i,n) {
        cout << b[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
  
template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& a){ return is >> a.first >> a.second; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& a){ return os << a.first << " " << a.second; }
template<typename T> istream& operator>>(istream& is, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) is >> vc[i]; return is; }
template<typename T> ostream& operator<<(ostream& os, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) os << vc[i] << endl; return os; }
  
#define ForEach(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++)
#define ALL(v) (v).begin(), (v).end()
#define UNQ(s) { sort(ALL(s)); (s).erase( unique( ALL(s)), (s).end());}
 
typedef long long int64;
typedef pair< int64 , int64 > Pi;
typedef pair< int , Pi > Pii;
const int INF = 1 << 30;

vector< int64 > seg, added;
struct SegmentTree{
  typedef pair< int, int > Pi;
private:
  int n;
public:
  void add(int a, int b, int64 x, int k, int l, int r){
    if( r <= a || b <= l) return;
    if( a <= l && r <= b){
      added[k] += x;
      while(k > 0){
        k = (k - 1) >> 1;
        seg[k] = max( seg[k * 2 + 1] + added[k * 2 + 1], seg[k * 2 + 2] + added[k * 2 + 2]);
      }
    } else {
      add( a, b, x, k * 2 + 1, l, (l + r) >> 1);
      add( a, b, x, k * 2 + 2, (l + r) >> 1, r);
    }
  }
  void add(int a, int b, int64 x){
    add( a, b, x, 0, 0, n);
  }

  int64 query( int a, int b, int k, int l, int r){
    if( r <= a || b <= l ) return 0;
    if( a <= l && r <= b ) return seg[k] + added[k];
    int64 vl = query( a, b, k * 2 + 1, l, (l + r) / 2);
    int64 vr = query( a, b, k * 2 + 2, (l + r) / 2, r);
    return(max( vl, vr) + added[k]);
  }
  int64 query( int a, int b){
    return(query( a, b, 0, 0, n));
  }
  int64 top(){
    return(seg[0]);
  }
  SegmentTree(const int& size){
    n = 1;
    while( n < size ) n *= 2;
    seg = vector< int64 >(2 * n + 1, 0);
    added = vector< int64 >(2 * n + 1, 0);
  }
};


int main()
{
  int N, H;
  scanf("%d %d", &N, &H);
  vector< int > d(N - 1), h(N - 1);
  for(int i = 0; i < N - 1; i++){
    scanf("%d %d", &d[i], &h[i]);
  }

  priority_queue< Pi > que;
  SegmentTree segtree(N);
  int64 Life = H;
  int64 ret = 0;
  for(int i = 0; i < N - 1; i++){
    segtree.add( i, i + 1, Life);

    Life -= d[i];
    que.push(make_pair( h[i], i));  //とてもわからない
    while(Life <= 0){
      Pi p = que.top(); que.pop();
      int64 Big = segtree.query( p.second, i + 1); // 体力の最大値
      if(p.first + Big > H){ // 上限を超えた
        que.push( make_pair( H - Big, p.second));
      } else {
        int64 Count = min(-Life / p.first + 1, (H - Big) / p.first); // min( 必要な体力 / 回復量 + 1, (体力の上限 - 体力の最大値) / 回復量)
        ret += Count;
        int64 hell = Count * p.first;
        Life += hell;
        segtree.add( p.second, i + 1, hell);
        que.push(p);
      }
    }
  }
  printf("%lld\n", ret);
}

Measured memory_bytes: 9000
import math
n, d = map(int, input().split())
x = [[] for i in range(n +1)]
for i in range(n):
  x[i] = list(map(int, input().split()))
k = 0
for i in range(n - 1):
  for j in range(i+1,n):
    sum = 0
    for m in range(d):
      sum += (x[i][m] - x[j][m]) ** 2
    tmp = math.sqrt(sum)
    if tmp.is_integer():
      k += 1
print(k)  

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((LL)1e9+7) 
#define INF ((LL)1e9+7)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

LL modpow(LL x, LL b){
	LL res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

LL modinv(LL x){
	return modpow(x, MOD-2);
}

int main(){
	int N;
	cin >> N;
	vector<int> line(N);
	foreach(i, line){
		cin >> i;
	}
	int lh = INF;
	int ans = 0;
	int count = 0;
	PER(i, N){
		if(lh <= line[i]){
			++count;
			chmax(ans, count);
		}else{
			count = 0;
		}
		lh = line[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640