akhauriyash/Code-Regression huggingface dataset:
//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    int k,s,x,y,z,r=0;
    scanf("%d%d",&k,&s);
    for(x=0;x<=k;x++){
        for(y=0;y<=k;y++){
            z=s-x-y;
            if(0<=z && z<=k){r++;}
        }
    }
    printf("%d\n",r);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

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

    int n = s.size();
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        if (s[i] != s[i+1]) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;
    long long bot = min({A, B, C, D, E});
    long long min_path;
    min_path = 5 + (N + bot - 1) / bot - 1;
    cout << min_path << endl;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=1000005;
const int mod=998244353;
int n,ans;
int a[maxn],inv[maxn],mu[maxn],pri[maxn],sum[maxn],val[maxn];

int main(){
	scanf("%d",&n);
	REP(i,n)scanf("%d",&a[i]),sum[a[i]]++;
	mu[1]=1;
	REP(i,1000000)for(int j=i*2;j<=1000000;j+=i)mu[j]-=mu[i];
	inv[0]=inv[1]=1;
	for(int i=2;i<=1000000;i++)inv[i]=1LL*inv[mod%i]*(mod-mod/i)%mod;
	REP(i,1000000)REP(j,1000000/i){
		val[i*j]+=inv[i]*mu[j];
		if(val[i*j]>=mod)val[i*j]-=mod;
		if(val[i*j]<0)val[i*j]+=mod;
	}
	REP(i,1000000){
		int cur=0;
		REP(j,1000000/i){
			cur+=1LL*sum[i*j]*(i*j)%mod;
			if(cur>=mod)cur-=mod;
		}
		ans+=1LL*cur*cur%mod*val[i]%mod;
		if(ans>=mod)ans-=mod;
	}
	REP(i,n){
		ans-=a[i];
		if(ans<0)ans+=mod;
	}
	printf("%d\n",1LL*ans*inv[2]%mod);
	return 0;
}


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

int main(){
    int N;  ll K;
    cin >> N >> K;
    vector<ll> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    int nBit = 41;
    vector<int> cnt(nBit,0);
    for(int i=0; i<N; i++){
        ll a = A[i];
        int j = 0;
        while(a > 0){
            if(a%2==1) cnt[j]++;
            a/=2;
            j++;
        }
    }

    ll KK = K + 1;
    vector<int> Kbin(nBit,0);
    for(int i=0; i<nBit; i++){
        if(KK%2==1) Kbin[i] = 1;
        KK/=2;
    }

    ll ans = 0;
    for(int i=0; i<nBit; i++){
        if(Kbin[i]==0) continue;

        vector<int> Xbin(nBit,0);
        Xbin[i] = 0;
        for(int j=i+1; j<nBit; j++){
            Xbin[j] = Kbin[j];
        }
        for(int j=0; j<i; j++){
            if(cnt[j]<(N+1)/2){
                Xbin[j] = 1;
            }
        }

        ll X = 0;
        for(int j=0; j<nBit; j++){
            if(Xbin[j]==1) X += (ll)1 << j;
        }

        ll tmp = 0;
        for(int j=0; j<N; j++){
            tmp += X^A[j];
        }
        
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <bits/stdc++.h>
#define MAX_SIZE 500010
#define NIL -1
#define INFTY 2000000000
using namespace std;

struct Node { int p, l, r; };
Node T[MAX_SIZE];
int D[MAX_SIZE], H[MAX_SIZE];

int getDepth(int u) {
    int d = 0;
    while (T[u].p != NIL) {
        u = T[u].p;
        d++;
    }
    return d;
}

void setDepth(int u, int d) {
    if (u == NIL) return;
    D[u] = d;
    setDepth(T[u].r, d + 1);
    setDepth(T[u].l, d + 1);
}

int setHeight(int u) {
    if (u == NIL) return -1;
    int h1 = setHeight(T[u].l) + 1;
    int h2 = setHeight(T[u].r) + 1;
    return H[u] = max(h1, h2);
}

int getSibling(int u) {
    if (T[u].p == NIL) return NIL;
    int p = T[u].p;
    if (T[p].r == u) return T[p].l;
    if (T[p].l == u) return T[p].r;
    return NIL;
}

int getDegree(int u) {
    if (T[u].l == NIL) {
        if (T[u].r == NIL) return 0;
        return 1;
    }
    if (T[u].r == NIL) return 1;
    return 2;
}

void printNode(int v) {
    cout << "node " << v << ": ";
    cout << "parent = " << T[v].p << ", ";
    cout << "sibling = " << getSibling(v) << ", ";
    cout << "degree = " << getDegree(v) << ", ";
    cout << "depth = " << D[v] << ", ";
    cout << "height = " << H[v] << ", ";
    if (T[v].p == NIL) cout << "root";
    else if (T[v].l == NIL && T[v].r == NIL) cout << "leaf";
    else cout << "internal node";
    cout << endl;
}

int main(){
    int i, j, v, k, n, c, l, r;
    cin >> n;
    for (i=0; i < n; i++) T[i].l = T[i].r = T[i].p = NIL;
    for (i=0; i < n; i++) {
        scanf("%d", &v);
        scanf("%d %d", &l, &r);
        T[v].l = l;
        T[v].r = r;
        if (l != NIL) T[l].p = v;
        if (r != NIL) T[r].p = v;
    }
    for (i=0; i < n; i++) if (T[i].p == NIL) r = i;
    setDepth(r, 0);
    setHeight(r);
    for (v=0; v < n; v++) printNode(v);
    return 0;
} 


Measured memory_bytes: 3176
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <queue>
using namespace std;

using Weight = int;
using Capacity = int;
struct Edge {
	int src, dst; Capacity cap;
	Edge(int s, int d, Capacity c) : src(s), dst(d), cap(c) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

struct Dinic {
	int n, s, t;
	vector<int> level, prog, que;
	vector<vector<Capacity>> cap, flow;
	vector<vector<int>> g;
	Capacity inf;
	Dinic(const Graph &graph)
		: n(graph.size()),
		cap(n, vector<Capacity>(n)), flow(n, vector<Capacity>(n)),
		g(n, vector<int>()), inf(numeric_limits<Capacity>::max() / 8) {
		for(int i = 0; i < n; i++) {
			for(auto &e : graph[i]) {
				int u = e.src, v = e.dst;
				Capacity c = e.cap;
				cap[u][v] += c; cap[v][u] += c; flow[v][u] += c;
				g[u].push_back(v); g[v].push_back(u);
			}
		}
	}
	inline Capacity residue(int u, int v) { return cap[u][v] - flow[u][v]; }
	Capacity solve(int s_, int t_) {
		this->t = t_, this->s = s_;
		que.resize(n + 1);
		Capacity res = 0;
		while(levelize()) { prog.assign(n, 0); res += augment(s, inf); }
		return res;
	}
	bool levelize() {
		int l = 0, r = 0;
		level.assign(n, -1); level[s] = 0; que[r++] = s;
		while(l != r) {
			int v = que[l++]; if(v == t) break;
			for(const int &d : g[v]) if(level[d] == -1 && residue(v, d) != 0) {
				level[d] = level[v] + 1; que[r++] = d;
			}
		}
		return level[t] != -1;
	}
	Capacity augment(int v, Capacity lim) {
		Capacity res = 0;
		if(v == t) return lim;
		for(int &i = prog[v]; i < (int)g[v].size(); i++) {
			const int &d = g[v][i];
			if(residue(v, d) == 0 || level[v] >= level[d]) continue;
			const Capacity aug = augment(d, min(lim, residue(v, d)));
			flow[v][d] += aug; flow[d][v] -= aug;
			res += aug; lim -= aug;
			if(lim == 0) break;
		}
		return res;
	}
};


int W, H;
int toV(int i, int j) {
	return W * i + j;
}

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

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


	int Test;
	cin >> Test;
	for(int t = 1; t <= Test; t++) {
		cin >> W >> H;
		int r[20][20];
		int sum = 0;
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				cin >> r[i][j];
				sum += r[i][j];
			}
		}
		Graph G(H * W + 2);

		int S = H * W, T = S + 1;
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				if((i + j) % 2 == 0) {
					G[S].push_back(Edge{ S, toV(i, j), r[i][j] });
					G[toV(i, j)].push_back(Edge{ toV(i, j), T, 0 });
					for(int k = 0; k < 4; k++) {
						int ni = i + dy[k], nj = j + dx[k];
						if(ni < 0 || H <= ni || nj < 0 || W <= nj) continue;
						G[toV(i, j)].push_back(Edge{ toV(i, j), toV(ni, nj), (int)1e9 });
					}
				}
				else {
					G[S].push_back(Edge{ S, toV(i, j), 0 });
					G[toV(i, j)].push_back(Edge{ toV(i, j), T, r[i][j] });
				}
			}
		}

		Dinic dinic(G);
		cout << "Case " << t << ": " << sum - dinic.solve(S, T) << endl;
	}

}

Measured memory_bytes: 4276
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

void Main(){

  ll N;
  cin >> N;

  ll dp[65][3]={}; //[上位i桁まで][Nとの差(どれだけ低いか)]=(vの通り).jは2以上は2に。

  dp[64][0]=1;

  repr(i,63,0){ //桁dp
    rep(j,3){ //012
      rep(k,3){ //(00)(01)(11) a,bの組。01は必ず可換で,00と11はvが必ず異なる。
        ll j2 = min((ll)2,2*j+(N>>i &1)-k);
        if(j2>=0) {
          dp[i][j2]+=dp[i+1][j];
          dp[i][j2]%=MOD;
        }
      }
    }
  }

  cout << ((dp[0][0]+dp[0][1]+dp[0][2])%MOD) <<"\n";
}
//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define Task ""

using namespace std;
typedef long long ll;

const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;

int N;
map<int, int> ma;
int ma1 = 0, ma2 = 0;

signed main(void)
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (fopen("A.INP", "r")){
        freopen("A.INP", "r", stdin);
        freopen("A.OUT", "w", stdout);
    }
    if (fopen(Task".INP", "r")){
        freopen(Task".INP", "r", stdin);
        freopen(Task".OUT", "w", stdout);
    }
    cin >> N;
    while (N--){
        int len;
        cin >> len; ++ma[len];
        if (ma[len] == 2){
            if (ma2 < len){
                ma1 = ma2;
                ma2 = len;
            }
            else if (ma1 < len){
                ma1 = len;
            }
            ma[len] = 0;
        }
    }
    cout << 1ll * ma1 * ma2 << '\n';
}


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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> vec(N);
  for(int i = 0; i < N; i++) cin >> vec.at(i);
  sort(vec.begin(), vec.end());
  int ans = 0;
  for(int i = 0; i < K; i++) ans += vec.at(i);
  cout << ans << endl;
}

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

int main() {
    int N;
    cin>>N;
    vector<int> A(N);
    for(int x=0;x<N;x++){
        cin>>A.at(x);
    }
    for(int i=0;;i++){
        for(int j=0;j<N;j++){
            if(A.at(j)%2==0){
                A.at(j)=A.at(j)/2;
            }else{
                cout<<i<<endl;
                return 0;
            }
        }
    }
return 0;}
/*
g++ code.cpp
./a.out
*/

Measured memory_bytes: 256
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(void){
    int a,b;

    cin >> a >> b;

    int diff = b -a;

    int sum=0;
    for(int i=1;i<diff;i++){
        sum = sum+i;
    }
    cout << sum - a << endl;
    return 0;
    
       
}

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

int main(){
  int X;
  cin >> X;
  
  int A, B;
  for(A = -200; A < 200; A++){
    for(B = -200; B < 200; B++){
      if(pow(A, 5)-pow(B, 5)==X){
        cout << A <<" " << B << endl;
        return 0;
      }
    }
  }
}

  

Measured memory_bytes: 4008
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;


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

const int N=222222;
int a[N],b[N];

int main() {
    int n;
    scanf("%d",&n);
    for (int i=1;i<=n;i++) scanf("%d",&a[i]);
    memset(b,-1,sizeof(b));

    b[0]=0;
    int ans=-1;
    for (int i=1;i<=n;i++) {
        int x=a[i];
        if (b[x-1]==-1) continue;
        b[x]=max(b[x], b[x-1]+1);
        ans=max(ans, b[x]);
    }
    if (ans>0) ans=n-ans;
    else ans=-1;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 5480
#include <iostream>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int maxi=1;
    for(int i=1;i*i<=m;i++)
    {
        if(m%i==0)
        {
           int br=m/i;
           if(br>=n)
           maxi=max(maxi,i);
            if(i>=n)
            {
                maxi=max(maxi,br);
            }
        }
    }
    cout<<maxi<<endl;
    return 0;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())
cnt = 0

for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      sum = i*500 + j*100 + k*50
      if sum == x:
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
#include<stdio.h>
#include<malloc.h>
void sweap(int *a,int *b){
    int t;
    t=*a,*a=*b,*b=t;
}
int main(){
    int *a,*b,*c,*n;
    a=(int *)malloc(sizeof(int));
    b=(int *)malloc(sizeof(int));
    c=(int *)malloc(sizeof(int));
    n=(int *)malloc(sizeof(int));
    scanf("%d%d%d%d",a,b,c,n);
    if(*a<*b)sweap(a,b);
    if(*b<*c)sweap(b,c);
    if(*c<*n)sweap(c,n);
    if(*a<*b)sweap(a,b);
    if(*b<*c)sweap(b,c);
    if(*a<*b)sweap(a,b);
    scanf("%d",n);
    if(*a<*n)sweap(a,n);
    if(*b<*n)sweap(b,n);
    if(*c<*n)sweap(c,n);
    scanf("%d",n);
    if(*a<*n)sweap(a,n);
    if(*b<*n)sweap(b,n);
    if(*c<*n)sweap(c,n);
    scanf("%d",n);
    if(*a<*n)sweap(a,n);
    if(*b<*n)sweap(b,n);
    if(*c<*n)sweap(c,n);
    scanf("%d",n);
    if(*a<*n)sweap(a,n);
    if(*b<*n)sweap(b,n);
    if(*c<*n)sweap(c,n);
    scanf("%d",n);
    if(*a<*n)sweap(a,n);
    if(*b<*n)sweap(b,n);
    if(*c<*n)sweap(c,n);
    scanf("%d",n);
    if(*a<*n)sweap(a,n);
    if(*b<*n)sweap(b,n);
    if(*c<*n)sweap(c,n);
    printf("%d\n%d\n%d\n",*a,*b,*c);
    return 0;
}

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

using namespace std;

#define reps(i, n, m) for (int i = (int) (n); i < (int) (m); i++)
#define rep(i, n) reps(i, 0, (n))
#define all(v) (v).begin(), (v).end()
using ll = long long;

int main() {
    int N;
    ll V;
    scanf("%d%lld", &N, &V);
    vector<ll> v[4];
    vector<ll> v2[2];
    rep(i, 4) {
        v[i].resize(N);
        rep(j, N) {
            scanf("%lld", &v[i][j]);
        }
    }
    rep(i, N) {
        rep(j, N) {
            v2[0].push_back(v[0][i] + v[1][j]);
            v2[1].push_back(v[2][i] + v[3][j]);
        }
    }
	v2[1].push_back(-1);
	v2[0].push_back(LLONG_MAX);
    sort(all(v2[1]));
	sort(all(v2[0]));
    ll res = 0;
	for (int j = v2[1].size() - 1; j; j = 0) {
        rep(i, v2[0].size()) {
    		const ll g = V - v2[0][i];
    		if (g <= 0) break;
    		ll t = 0;
	    	while (v2[1][j] >= g) {
	    		t += v2[1][j] == g;
	    		j--;
	    	}
    		int k = i;
	    	while (v2[0][i] == v2[0][k]) {
	    		res += t;
		    	k++;
		    }
		    i = k - 1;
        }
	}
    cout << res << endl;
}


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

using namespace std;

typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<int> l(n * 2);
    for (int i = 0; i < n * 2; ++i) {
        cin >> l[i];
    }
    sort(l.begin(), l.end());
    int s = 0;
    for (int i = 0; i < n * 2; i += 2) {
        s += l[i];
    }
    cout << s;
    return 0;
}

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

int main()
{
  int n;
  cin>>n;
  std::vector<int> v(n);
  set<int> st;
  for (int i = 0; i < n; ++i)
  {
    int tmp;
    cin>>tmp;
    v[i]=tmp;
    st.insert(tmp);
  }
  if(st.size()==1){
    cout<<n/2;
    return 0;
  }
  std::vector<int> v1,v2;
  set<int> st1,st2;
  for (int i = 0; i < n; ++i)
  {
    if(i%2==0) {
      v2.push_back(v[i]);
      st2.insert(v[i]);
    }
    else {
      v1.push_back(v[i]);
      st1.insert(v[i]);
    }
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  vector<pair<int,int>> p1,p2;
  for(auto &e: st1) {
    auto u=upper_bound(v1.begin(), v1.end(),e);
    auto l=lower_bound(v1.begin(), v1.end(),e);
    p1.push_back(make_pair(u-l,e));
  }
  for(auto &e: st2) {
    auto u=upper_bound(v2.begin(), v2.end(),e);
    auto l=lower_bound(v2.begin(), v2.end(),e);
    p2.push_back(make_pair(u-l,e));
  }
  sort(p1.begin(), p1.end());
  sort(p2.begin(), p2.end());
  reverse(p1.begin(), p1.end());
  reverse(p2.begin(), p2.end());
  
  if(p1[0].second!=p2[0].second){
    cout<<n-p1[0].first-p2[0].first;
    return 0;
  }
  cout<<n-max(p1[0].first+p2[1].first,p1[1].first+p2[0].first);
}

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

const int INF = 2e9;

int main(){
    int n;
    cin >> n;
    vector<pii> x(n);
    int cnt = 1;
    rep(i,n){
        int a;
        cin >> a;
        x[i].first = a;
        x[i].second = cnt;
        cnt++;
    }
    sort(x.begin(),x.end());
    rep(i,n){
        cout << x[i].second << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1536
#include <cstdio>
#include <cmath>

int people;
int score[1000];

int main(){	
	while(1){
		int sum =0;
		scanf("%d", &people);
		if(people == 0){
			break;
		}
		for(int i=0; i<people; ++i){
			scanf("%d", &score[i]);
			sum += score[i];
		}
		double mean = (double)sum / (double)people;;
		double temp = 0.;
		
		for(int i=0; i<people; ++i){
			double error = (double)score[i] - mean;
			temp += error*error;
		}
		double deviation = sqrt(temp / (double)people);		
		printf("%.8lf\n", deviation);
	}
}


Measured memory_bytes: 2700
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Sparsh Sanchorawala
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CReplacingInteger solver = new CReplacingInteger();
        solver.solve(1, in, out);
        out.close();
    }

    static class CReplacingInteger {
        public void solve(int testNumber, InputReader s, PrintWriter w) {
            long n = s.nextLong(), k = s.nextLong();
            w.println(Math.min(n % k, k - n % k));
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 21460
#include <algorithm>
#include <cstdio>
const int INFN = 1e9+7;
const int MAXM = 1005;
const int MAXN = 12;
const int NOPE = -1;
int A[MAXM];
int B[MAXM];
int C[MAXM];
int dp[1 << MAXN]{ };
int c, M, N;
int L;

void init() {
  for (int i = 0; i < L; ++i) {
    dp[i] = INFN;
  }
  dp[0] = 0;
}

void read() {
  for (int i = 0; i < M; ++i) {
    scanf(" %d%d", &A[i], &B[i]);
    C[i] = 0;
    for (int j = 0; j < B[i]; ++j) {
      scanf("%d", &c);
      C[i] |= (1 << (c - 1));
    }
  }
  L = (1 << N);
}

int solve() {
  for (int mask = 0; mask < L; ++mask) {
    for (int j = 0; j < M; ++j) {
      int next = (mask | C[j]);
      if (next == mask) {
        continue;
      }
      dp[next] = std::min(dp[mask] + A[j], dp[next]);
    }
  }
  int ret = dp[L-1];
  return (ret == INFN) ? NOPE : ret;
}

int main() {
  scanf(" %d%d", &N, &M);
  read();
  init();
  printf("%d\n", solve());
  return 0;
}

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

const int modulo=998244353;

int main()
{
	int n,k;
	cin >> n >> k;
	vector<pair<int,int>> lr(k);
	for (int i=0;i<k;++i)
	{
		int l,r;
		cin >> l >> r;
		lr[i]=make_pair(l,r);
	}
	sort(lr.begin(),lr.end());

	vector<vector<pair<int,int>>> pairs(n+1);
	for (int i=1;i<=n;++i)
	{
		for (int j=0;j<lr.size();++j)
		{
			if (i>=lr[j].first)
			{
				pairs[i].push_back(make_pair(i-lr[j].first,max(i-lr[j].second,0)));
			}
		}
	}

#ifdef NEVER_DEFINED
	for (int i=1;i<=n;++i)
	{
		fprintf(stderr, "%d ",i);
		for (int j=0;j<pairs[i].size();++j)
		{
			fprintf(stderr,"[%d,%d], ",pairs[i][j].first,pairs[i][j].second);
		}
		fprintf(stderr,"\n");
	}
#endif // NEVER_DEFINED

	vector<int64_t> countsum(n+2);
	countsum[0]=0;
	countsum[1]=1;
	for (int i=1;i<=n;++i)
	{
		int64_t sumi=0;
		for (int j=0;j<pairs[i].size();++j)
		{
			sumi+=(countsum[pairs[i][j].first+1]-countsum[pairs[i][j].second]);
		}

		sumi+=countsum[i];
		while (sumi<0)
		{
			sumi+=modulo;
		}
		sumi%=modulo;
		countsum[i+1]=sumi;
	}

#ifdef NEVER_DEFINED
	fprintf(stderr,"\n");
	for (int i=0;i<=n+1;++i)
	{
		fprintf(stderr,"%d %d\n",i,(int)countsum[i]);
	}
#endif // NEVER_DEFINED

	//int64_t result=countsum[n+1]-countsum[n];
	int64_t result=countsum[n]-countsum[n-1];
	if (result<0)
	{
		result+=modulo;
	}
	cout << result % modulo << endl;
}








Measured memory_bytes: 22704
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

using ll = long long;

int main(){
    ll N, M, X;
    cin >> N >> M >> X;
    ll ret = 0;
    for (auto && i: irange(0LL, M)){
        ll a;
        cin >> a;
        if (a > X){
            ret++;
        }

    }
    cout << min(ret, M-ret);

  return 0;
}

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

int main() {
	// your code goes here
	int n,a,b;
	cin>>n>>a>>b;
	if(n==2) cout<<"Borys";
	else{
		if((b-a)%2==0) cout<<"Alice";
		else cout<<"Borys";
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a,i;
	cin>>a;
	i=a%10+a%100/10+a%1000/100+a%10000/1000+a%100000/10000+a%1000000/100000+a%10000000/1000000+a%100000000/10000000+a%1000000000/100000000+a%10000000000/1000000000;
	if(a%i==0) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
if __name__ == "__main__":
    a = int(input())
    tmp = 0
    result = int(0)
    while a >= 5:
        coin500 = int(a / 500)
        a %= 500
        coin5 = int(a / 5)
        a %= 5
        result += (coin5 * 5) + (coin500 * 1000)
    print(result)
    

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
//---------------------------------------------
// Mr.HITMAN/hblord787
// Solution for Problem Code : C - Fennec  vs Monster
// Contest : Beginner 153 
//-------------------------------------------- 
int main() {
    
/////////////////////////////////////////////////////////////////////////////////////////////////////////////    
	ios_base::sync_with_stdio(false); // fast io
	cin.tie(NULL);
	cout.tie(NULL);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
    int n,k;
    cin >> n >> k;
    int arr[n];
  	long long int sum = 0;
  	for(int i = 0; i < n; i++)
  	    {
  	        cin >> arr[i];
  	        sum = sum + arr[i];
  	    }
  	   if(k == 0)
  	   {
  	       cout << sum ;
  	   }
  	   else if(k >= n)
  	   {
  	       cout << 0;
  	   }
  	   else 
  	   {
  	        sort(arr,arr+n);
  	        sum = 0;
  	        for(int i = 0; i < n-k; i++)
  	        {
  	            sum += arr[i];
  	        }
  	        cout << sum;
  	   }
  	
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
//#define int long long int
using namespace std;

signed main(){
    ll W,H; cin>>W>>H;
    ll x,y; cin>>x>>y;
    cout<< double(W*H)/double(2.0)<<" ";

    if( W/2 == x and W % 2 == 0 and H/2 == y and H % 2 == 0 ) cout<<1<<endl;
    else cout<<0<<endl;

    

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
    int N, M, K;
 
    cin >> N >> M >> K;
 
    int A[N];
    int B[M];
    long long A_SUM[N+1];
    long long B_SUM[M+1];
    int k = 0;
    int ans = 0;
 
    A_SUM[0] = 0;
    B_SUM[0] = 0;
 
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
 
    for (int i = 0; i < M; i++) {
        cin >> B[i];
    }
 
    for (int i = 1; i <= N; i++) {
        A_SUM[i] = A_SUM[i - 1] + A[i - 1];
    }
 
    for (int i = 1; i <= M; i++) {
        B_SUM[i] = B_SUM[i - 1] + B[i - 1];
    }
 
    for (int i = 0; i <= N; i++) {
        if (A_SUM[i] > K) {
            break;
        }
        
        for (int j = k; j <= M; j++) {
            if ((A_SUM[i] + B_SUM[M - j] <= K)) {
                k = j;
                break;
            }
        }
        ans = max(ans, i + (M - k));
    }

    
    cout << ans << endl;
 
}

Measured memory_bytes: 8308
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    int n = readint;
    int[][] ab;
    for (int i = 0; i < n; i++) {
        ab ~= readints;
    }

    ab.sort!((x, y) => sum(x) > sum(y));
    long a = 0;
    long b = 0;
    for (int i = 0; i < ab.length; i++) {
        if (i % 2 == 0) a += ab[i][0];
        else b += ab[i][1];
    }
    writeln(a - b);
}


Measured memory_bytes: 16892
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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;
}

ll comb2(const ll a) {
    return a * (a - 1) / 2;
}

vector<vector<ll>> edges;

int main(void) {
    ll N, K;
    cin >> N >> K;

    ll max_num = (N - 2) + comb2(N - 2);
    if (K > max_num) {
        cout << "-1" << endl;
        return 0;
    }

    edges.resize(N);
    edges[0].push_back(1);
    for (int i = 2; i < N; i++) {
        edges[1].push_back(i);
    }

    ll remain = max_num - K;
    // printf("max_num: %lld, remain: %lld\n", max_num, remain);
    ll link_one_num = min(remain, N - 2);
    for (int i = 0; i < link_one_num; i++) {
        edges[0].push_back(i + 2);
    }
    remain = remain - link_one_num;

    int i = 2;
    while (remain > 0) {
        for (int j = i + 1; j < N; j++) {
            edges[i].push_back(j);
            remain--;
            if (remain == 0) break;
        }
        i++;
    }

    ll count = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < (int) edges[i].size(); j++) {
            count++;
        }
    }
    cout << count << endl;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < (int) edges[i].size(); j++) {
            cout << i + 1 << " " << edges[i][j] + 1 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#define MAXLENGTH 80

void slideString(char str[MAXLENGTH]) {
	int i = 0;
	while(str[i] != '\0') {
		if (str[i] >= 'a' && str[i] <= 'y') {
			str[i] = str[i] + 1;
		}
		else if(str[i] == 'z') {
			str[i] = 'a';
		}
		else if(str[i] >= 'A' && str[i] <= 'Y') {
			str[i] = str[i] + 1;
		}
		else if(str[i] == 'Z') {
			str[i] = 'A';
		}
		i++;
	}
}

int checkString(char str[MAXLENGTH]) {
	if (strstr(str , "the") != NULL) {
		return 1;
	}
	if (strstr(str , "this") != NULL) {
		return 1;
	}
	if (strstr(str , "that") != NULL) {
		return 1;
	}
	return 0;
}

void searchChipher(char str[MAXLENGTH]) {
	int slideCount = 0;
	while(checkString(str) == 0 && slideCount < 26) {
		slideString(str);
		slideCount++;
	}

	if (slideCount != 26) {
		puts(str);
	}
}

int main () {
	char str[MAXLENGTH];
	while(scanf("%[^\n]" , str) != EOF) {
		searchChipher(str);
		getchar();
	}
	return 0;
}

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

int main(){
  int n,d,k;
  cin >> n >> d;
  
  
  k = 2*d +1;
  if (n%k != 0)
  cout << (n-(n%k))/k +1 << endl;
  else
    cout << n/k << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  int mod;
  string ans = " ";

  while (n!=0) {
    n--;
    mod = n % 26;
    char c = ('a' + mod);
    ans = c + ans;
    n /= 26;
    //cout << mod << " " << c << " " << n << endl;
  }
  cout << ans << endl;
}  

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define err(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

using namespace std;

typedef long long ll;

const int mod = 998244353;
const int dd = 4007;

int n;
bitset<dd> a[8], X;

void read(bitset<dd> &cur) {
	string s;
	cin >> s;
	int n = (int)s.size();
	for (int i = 0; i < n; i++) cur[n - i - 1] = (s[i] == '1');
}

int get(bitset<dd> &cur) {
	for (int i = dd - 1; i >= 0; i--) if (cur[i]) return i;
	return dd;
}

int main() {
	cin >> n;
	read(X);
	
	for (int i = 0; i < n; i++) read(a[i]);
	
	for (int i = 1; i < n; i++) {
		while (1) {
			int l = get(a[0]);
			int r = get(a[i]);
			if (l > r) swap(a[0], a[i]), swap(l, r);
			if (r == dd) break;
			a[i] ^= (a[0] << (r - l));
		}
	}
	int p = get(a[0]);
	int pw = 1, ans = 0;
	
	for (int i = p; i < dd; i++) {
		if (X[i]) ans = (ans + pw) % mod;
		pw = (pw + pw) % mod;
	}
	
	a[1].reset();
	for (int i = dd - 1; i >= p; i--) {
		if (a[1][i] != X[i]) {
			a[1] ^= (a[0] << (i - p));
		}
	}
	
	int ok = 1;
	for (int i = p - 1; i >= 0; i--) {
		if (a[1][i] < X[i]) break;
		if (a[1][i] > X[i]) { ok = 0; break; }
	}
	if (ok) ans = (ans + 1) % mod;
	cout << ans << "\n";
	return 0;
}

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


int main(){
  string s;
  cin >> s;
  int n = stoi(s);
  if(n/100<13&&0<n/100&&n%100<13&&0<n%100){
    cout << "AMBIGUOUS" << endl;
  }
  else if(n/100<13&&0<n/100){
    cout << "MMYY" << endl;
  }
  else if(n%100<13&&0<n%100){
    cout << "YYMM" << endl;
  }
  else{
    cout << "NA" << endl;
  }
    
}
      


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;

int main(void) {
	int n, i, dp[1000003][2] = {};
	string s;

	cin >> s;

	n = s.size();

	dp[0][0] = 0;
	dp[0][1] = 1;
	for (i = 1; i <= n; i++) {
		dp[i][0] = min(dp[i - 1][0] + s[i - 1] - '0', dp[i - 1][1] + 10 - (s[i - 1] - '0'));
		dp[i][1] = min(dp[i - 1][0] + s[i - 1] - '0' + 1, dp[i - 1][1] + 9 - (s[i - 1] - '0'));
	}

	cout << dp[n][0] << endl;

	return 0;
}

Measured memory_bytes: 9220
import collections as cc
import sys
import bisect as bi
I=lambda:list(map(int,input().split()))
a,b,m=I()
ar=[I() for i in range(m)]
row=cc.defaultdict(int)
col=cc.defaultdict(int)
rr=cc.defaultdict(int)
ccc=cc.defaultdict(int)
for i in ar:
	rr[i[0]]+=1
	ccc[i[1]]+=1
	row[tuple(i)]=1
rc=max(rr.values())
cr=max(ccc.values())
p=[i for i in rr if rr[i]==rc]
q=[i for i in ccc if ccc[i]==cr]
ans=rc+cr
tf=0
for i in p:
	for j in q:
		if row[(i,j)]==0:
			tf=1
			break
	if tf:
		break
if tf==0:
	ans-=1
print(ans)


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

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
// #define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...) 42
#define dump(x) 42
#define debug(x) 42
#endif

typedef long long ll;

const ll MOD = 1e9 + 7;

void solve(string S) {
    int former = stoi(S.substr(0, 2)), latter = stoi(S.substr(2, 2));

    if (former > 12 || former == 0) { // former == YY
        if (latter > 12 || latter == 0) { // latter == YY
            cout << "NA" << '\n';
        } else {
            cout << "YYMM" << '\n';
        }
    } else { // former == YY or MM
        if (latter > 12 || latter == 0) { // latter == YY
            cout << "MMYY" << '\n';
        } else {
            cout << "AMBIGUOUS" << '\n';
        }
    }

    return;
}

signed main() {
    string S;
    cin >> S;
    
    solve(S);
    
    return 0;
}



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

using namespace std;

int main()
{
    string s;

    cin >> s;

    for(int i=1; s[i-1] != '\0'; i++){
        if(i%2==1){
            if(s[i-1]=='L'){
                cout << "No" << endl;
                return 0;
            }
        }
        if(i%2==0){
            if(s[i-1]=='R'){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int
main()
{
  int h,w,n;
  int result;
  
  cin >> h >> w >> n;
  
  if ( h < w ) {
    result = ( n + w - 1 ) / w;
  } else {
    result = ( n + h - 1 ) / h;
  }
  
  cout << result << endl;
}


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

#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using Pair = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;

/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/
//UnionFind
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int N,M;
int A[101],B[101];

int main(){
  cin >> N >> M;
  
  rep(i,M){
    cin >> A[i] >> B[i];
    A[i]--,B[i]--;
  }
  int ans = 0;
  
  rep(i,M){
    UnionFind uf(N);
    rep(j,M) if(j != i) uf.merge(A[j],B[j]);
    int c = 0;
    rep(j,N) if(j == uf.root(j)) c++;
    if(1<c) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pr(s) std::cout << s << std::endl
#define prb(s) std::cout << s
using namespace std;


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


  int buf = 0;
  int min = 10;
  int t = 0;
  int mem = 0;
  for (int i = 0; i < 5; i++) {
    cin >> buf;
    int rem = buf % 10;
    if (rem < min && rem != 0) {
      min = rem;
      t += ceil(mem / 10.0) * 10;
      mem = buf;
    } else {
      t += ceil(buf / 10.0) * 10;
    }
  }
  t += mem;
  pr(t);


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
set<string> st;
int main(){
	int n;
	cin >> n;
	rep(i,n){
		st.clear();
		string s;
		cin >> s;
		int m=s.size();
		rep1(i,m-1){
			string x=s.substr(0,i),y=s.substr(i,m-i),rx=x,ry=y;
			reverse(rx.begin(),rx.end());
			reverse(ry.begin(),ry.end());
			st.insert(x+y);
			st.insert(x+ry);
			st.insert(rx+y);
			st.insert(rx+ry);
			st.insert(y+x);
			st.insert(y+rx);
			st.insert(ry+x);
			st.insert(ry+rx);
		}
		cout << st.size() << endl;
	}
}

Measured memory_bytes: 1288
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()


int main() {
    int N;
    string S, left_s, right_s;
    map<pair<string, string>, ll> left, right;
    cin >> N >> S;
 
    left_s = S.substr(0, N); right_s = S.substr(N); reverse(ALL(right_s));
    REP(i, 1 << N) {
        string rl, rr, bl, br;
        REP(j, N) {
            if ((i >> j) & 1) {
                rl.push_back(left_s[j]);
                rr.push_back(right_s[j]);
            }
            else {
                bl.push_back(left_s[j]);
                br.push_back(right_s[j]);
            }
        } 
        left[{rl, bl}]++;
        right[{rr, br}]++;
    }

    ll ans = 0;
    for (auto p : left) {
        if (right[p.first] > 0) {
            ans += p.second * right[p.first];
        } 
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 108288
#include <bits/stdc++.h>
using namespace std;
vector<int>a[10005];
int main()
{
    int h,w;
    cin>>h>>w;
    int n;
    cin>>n;
    int f=0;
    for(int i=0; i<n; i++)
    {
        int x;
        scanf("%d",&x);
        for(int j=0;j<x;j++)
            a[f/w].push_back(i+1),f++;
    }

    for(int i=0; i<h; i++)
    {
        if(i&1)reverse(a[i].begin(),a[i].end());
        printf("%d",a[i][0]);
        for(int j=1; j<w; j++)
            printf(" %d",a[i][j]);
        printf("\n");
    }
    return 0;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define maxs(a,b) a=max(a,b);
#define mins(a,b) a=min(a,b);

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){
   
    int n;cin>>n;
    vi d(n);rep(i,n)cin>>d[i];
    int c=998244353;
    
    int mx=0;
    rep(i,n){
        maxs(mx,d[i]);
    }

    vi dd(mx+1,0);
    rep(i,n){
        dd[d[i]]++;
    }

    if(d[0]!=0 || dd[0]!=1){
        cout<<0<<endl;
        return 0;    
    }

    ll ans=1;

    repa(i,1,mx+1){
        if(dd[i]==0){
            cout<<0<<endl;
            return 0;
        }
        if(i==1)continue;
        rep(j,dd[i]){
            ans=(ans*dd[i-1])%c;
        }
    }

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){ return (int)s.size(); }

int cal(int x, int y){
    if(x <= y) return y-x;
    else return y;
}

int main(){
    cout << fixed << setprecision(20);
    int n; cin >> n;
    ll ans = 0;
    vi a(n);
    map<int,int> m;
    rep(i,n){
        cin >> a[i];
        m[a[i]]++;
    }
    sort(a.begin(), a.end());
    int pre = a[0];
    ans += cal(a[0],m[a[0]]);
    rng(i,1,n){
        if(pre == a[i]) continue;
        else{
            pre = a[i];
            ans += cal(a[i],m[a[i]]);
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  int ans = -999999999, minv; cin >> minv;
  for (int i = 1; i < n; ++i) {
    int a;
    cin >> a;
    ans = max(ans, a - minv);
    minv = min(minv, a);
  }
  cout << ans << endl;
 // system("pause");
}

Measured memory_bytes: 3100
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
#include<iostream>
#include<vector>
#define MAXN 300000
#define INF 0x3f3f3f3f
#include <algorithm>
using namespace std;
struct node
{
    int x,y;
};
node a[MAXN];
bool cmp(node c,node b)
{
    return c.y<b.y;
}
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>a[i].x>>a[i].y;

    }
    int cnt=1;
    sort(a,a+m,cmp);
    int pos=a[0].y;
    for(int i=1;i<m;i++)
    {
        if(a[i].x>=pos)
        {
            pos=a[i].y;
            cnt++;
        }

    }
    cout<<cnt;

}


Measured memory_bytes: 1024
def main():
    S = input()
    print(S[:3])


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 9084
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }

int main() {
    int n, k; cin >> n >> k;
    vll h(n);
    rep(i, n) cin >> h[i];
    vll dp(n, 1LL<<60);
    dp[0] = 0;
    rep(i, n) {
        FOR(j, 1, k+1) {
            if(i+j < n) chmin(dp[i+j], dp[i] + abs(h[i+j] - h[i]));
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1792