akhauriyash/Code-Regression huggingface dataset:
package main

import "fmt"

func main() {
	var N int
	var S string
	fmt.Scan(&N)
	fmt.Scan(&S)
	slideString(N, S)
}

func slideString(N int, S string) {
	alp := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
	for i := range S {
		s := S[i : i+1]
		for j, a := range alp {
			if s == a {
				if i == len(S)-1 {
					fmt.Println(alp[(j+N)%26])
					return
				}
				fmt.Printf(alp[(j+N)%26])
				break
			}
		}
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) "FUCK YOU"
#endif

const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void add(int&,int);
int mul(int,int);
int powz(int,int);
template<typename A> ostream& operator<<(ostream&,vector<A>&);

const int N=500006;

void solve(){
	int n;
	cin>>n;
	vector<pi> a;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		a.pb({x,i});
	}
	int ind=0;
	ll val=0;
	vector<pi>ans;
	sort(all(a));
	debug(a);
	while(ind<n&&a[ind].F<0){
		ind++;
	}
	if(ind==0&&a[ind].F>=0){
		val=a[0].F;
		for(int i=1;i<n-1;i++){
			
			ans.pb({val,a[i].F});
			val=val-a[i].F;
		}
		ans.pb({a[n-1].F,val});
		val=a[n-1].F-val;
		
	}
	else if(ind==n){
		val=a[n-1].F;
		for(int i=0;i<n-1;i++){
			ans.pb({val,a[i].F});
			val=val-a[i].F;
		}
		
	}
	else{
		//~ cout<<"CASE";
		int val1=a[0].F;
		for(int i=ind;i<n-1;i++){
			debug(i);
			ans.pb({val1,a[i].F});
			val1-=a[i].F;
		}
		int val2=a[n-1].F;
		for(int i=1;i<ind;i++){
			ans.pb({val2,a[i].F});
			val2-=a[i].F;
		}
		ans.pb({val2,val1});
			val=val2-val1;
		
		
	}
	cout<<val<<"\n";
	for(auto i:ans)cout<<i.F<<' '<<i.S<<"\n";
			
}
	
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}


}

int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}

void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
	if(a<0)a+=mod;
}

int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}

template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
	    output<<i<<' ';
	return output;	
}


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

typedef long long ll;

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

    string s;
    ll k,cnt=1;
    cin >> s >> k;
    if(s[0]=='1'){
        for(int i=1;i<s.size();i++){
            if(s[i]=='1') cnt++;
            else break;
        }
    }
    if(s[0]=='1' && cnt>=k){
        cout << 1 << endl;
    }else{
        for(int i=0;i<s.size();i++){
            if(s[i]!='1'){
                cout << s[i] << endl;
                break;
            }
        }
    }
    return 0;
}

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

long *tree[100001];

int main(void) {

  long n;
  scanf("%ld\n", &n);
  long tree_s[n+1];
  for (long i = 0; i <= n; i++) {
    tree_s[i] = 0;
  }
  long a,b;
  for (long i = 0; i < n-1; i++) {
    scanf("%ld %ld", &a, &b);
    tree[a] = realloc(tree[a], sizeof(long)*(tree_s[a]+1));
    tree[a][tree_s[a]] = b;
    tree_s[a]++;
    tree[b] = realloc(tree[b], sizeof(long)*(tree_s[b]+1));
    tree[b][tree_s[b]] = a;
    tree_s[b]++;
  }
  long parent[n+1],depth[n+1],color[n+1];
  for (long i = 0; i <= n; i++) {
    parent[i] = -1;
    depth[i] = -1;
    color[i] = -1;
  }
  parent[1] = 0;
  depth[1] = 0;
  color[1] = 1;
  color[n] = 0;
  long queue[n];
  queue[0] = 1;
  long start = 0, end = 0, tail = 0;
  long cur,next;
  while (tail < n-1) {
    for (long i = start; i <= end; i++) {
      cur = queue[i];
      for (long j = 0; j < tree_s[cur]; j++) {
        next = tree[cur][j];
        if (next == parent[cur]) {
          continue;
        }
        parent[next] = cur;
        depth[next] = depth[cur]+1;
        tail++;
        queue[tail] = next;
      }
    }
    start = end+1;
    end = tail;
  }
  cur = n;
  for (long i = depth[n]-1; i > depth[n]/2; i--) {
    cur = parent[cur];
    color[cur] = 0;
  }
  for (long i = depth[n]/2; i > 0; i--) {
    cur = parent[cur];
    color[cur] = 1;
  }
  for (long i = 1; i < n; i++) {
    cur = queue[i];
    if (color[cur] == -1) {
      color[cur] = color[parent[cur]];
    }
  }
  long black = 0, white = 0;
  for (long i = 2; i < n; i++) {
    if (color[i] == 1) {
      black++;
    } else {
      white++;
    }
  }
  if (black > white) {
    printf("Fennec\n");
  } else {
    printf("Snuke\n");
  }

  return 0;
}

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

using namespace std;

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

int main(){
    int i,A,B,C;
    //入力
    cin>>A>>B>>C;
    //処理
    //出力
    cout<<((C+B-A)>0?C+B-A:0)<<endl;
}

Measured memory_bytes: 256
N = int(input())
ans = {i:0 for i in range(100000)}
for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            i = x**2 + y**2 + z**2 + x*y + y*z + z*x
            ans[i] += 1
for i in range(1, N+1):
    print(ans[i])


Measured memory_bytes: 19444
#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 = (int)m; i < (int)n; i++)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;


/*FUNCs=================================================*/



/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    int n; cin >> n;
    vi l(n); rep(i,n) cin >> l[i];

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

    int sum= 0;
    rep(i,n-1) sum += l[i];
    cout << (sum > l[n-1] ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<cstdio>
int main(void)
{
    long long w,h,x,y;
    scanf("%lld %lld %lld %lld" ,&w,&h,&x,&y);
    printf("%.9f %lld" ,w*h/2.0,(w==2*x && h==2*y));
    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	int sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
		sum += A.at(i);
	}
	int average_min = sum / N, average_max = sum / N + 1;
	int MIN = 0, MAX = 0;
	for (int i = 0; i < N; i++) {
		MIN += (A.at(i) - average_min) * (A.at(i) - average_min);
	}
	for (int i = 0; i < N; i++) {
		MAX += (A.at(i) - average_max) * (A.at(i) - average_max);
	}
	cout << min(MIN, MAX) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int N, i;

	scanf("%d", &N);

	char str[101];

	scanf("%s", str);

	if (N % 2 == 1) {
		printf("No\n");
		return 0;
	}
	else {
		int a = N / 2;
		for (i = 0; i < a; i++) {
			if (str[i] != str[a + i]) {
				printf("No\n");
				return 0;
			}
		}
	}

	printf("Yes\n");


	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;

int dist(pii a, pii b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}

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

	int H, W, D;
	cin >> H >> W >> D;
	map<int, pii>mp;
	REP(i, H) {
		REP(j, W) {
			int a; cin >> a;
			a--;
			mp[a] = pii(i, j);
		}
	}

	vector<VI> sum(D, VI(H*W / D + 10, 0));
	REP(i, D) {
		int j = i;
		int a = 1;
		while (j + D < H * W) {
			sum[i][a] += sum[i][a - 1] + dist(mp[j], mp[j + D]);
			j += D;
			a++;
		}
	}
	int Q; cin >> Q;
	REP(i, Q) {
		
		int L, R; cin >> L >> R;
		L--; R--;
		
		cout << sum[R%D][R / D] - sum[L%D][L / D] << endl;
	}


	return 0;
}



Measured memory_bytes: 16640
#include <cstdio>
#include <string>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <iomanip>
#include <tuple>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (int i=a;i<n;++i)
#define repeq(i, a, n) for(int i=a;i<=n;++i)
#define repi(m, itr) for (auto itr = m.begin();itr != m.end();++itr)
#define per(i, a, n) for (int i=n-1; i>=a;--i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()

// 
int H, W;
char a[110][110];
vector<vector<char>> ans;

int main(){
    cin >> H >> W;
    rep(i, 0, H){
        rep(j, 0, W){
            cin >> a[j][i];
        }
    }
    
    rep(i, 0, H){
        bool del = true;
        rep(j, 0, W){
            if(a[j][i] == '#'){
                del = false;
            }
        }
        if(del){
            rep(j, 0, W){
                a[j][i] = 'd';
            }
        }
    }
    rep(j, 0, W){
        bool del = true;
        rep(i, 0, H){
            if(a[j][i] == '#'){
                del = false;
            }
        }
        if(del){
            rep(i, 0, H){
                a[j][i] = 'd';
            }
        }
    }
    
    int hs = 0;
    int ws = 0;
    rep(i, 0, H){
        ws = 0;
        vector<char> tmp;
        int plshs = false;
        rep(j, 0, W){
            if(a[j][i] != 'd'){
                tmp.push_back(a[j][i]);
                ++ws;
                plshs = true;
                cout << a[j][i];
            }
        }
        ans.push_back(tmp);
        if(plshs){
            cout << endl;
        }
    }
    return 0;
}




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

using ll = long long int;
using ld = long double;
using pii = pair<int,int>;

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

int main(){
  int n;cin >> n;
  bool t=false;
  for(int i=1;i<10;i++){
    for(int j=1;j<10;j++){
      if(i*j==n)t=true;
    }
  }
  if(t) cout << "Yes"<<endl;
  else cout << "No" << endl;
}

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

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    vector<int64_t> A(N + 1);
    vector<int64_t> B(M + 1);
    A.at(0) = 0;
    B.at(0) = 0;
    for (int i = 1; i <= N; i++) {
        int64_t a;
        cin >> a;
        A.at(i) = A.at(i - 1) + a;
    }
    for (int i = 1; i <= M; i++) {
        int64_t a;
        cin >> a;
        B.at(i) = B.at(i - 1) + a;
    }
    int ans = 0, idx = M;
    for (int i = 0; i <= N && A.at(i) <= K; i++) {
        while (A.at(i) + B.at(idx) > K) {
            idx--;
        }
        ans = max(ans, i + idx);
    }
    cout << ans << endl;
}


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

int main(){
    //input
    string S;
    cin >> S;
    long long keta=S.length();
    long long N[keta];
    long long i;
    for(i=0; i<keta; i++){
        N[i]=(long long)(S[i]-'0');
    }

    //calc
    long long cho=0, kuri=100;
    long long cho_copy, kuri_copy;
    for(i=keta-1; i>=0; i--){
        cho_copy=cho;
        kuri_copy=kuri;
        cho = min(cho_copy+N[i],kuri_copy+1+N[i]);
        kuri = min(cho_copy+(10-N[i]),kuri_copy+(9-N[i]));
    }

    //answer
    cout << min(cho,kuri+1) << endl;
    system("pause");
    return 0;
}

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



int main() {

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int s;
	int w;

	cin >> s >> w;

	if (w >= s) {
		cout << "unsafe";
	} else {
		cout << "safe";
	}






}


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


int main(){
    int H,W;
    cin >> H >> W;
    char a[104][104];
    REP(i,H){
        REP(j,W){
            cin >> a[i][j];
        }
    }
    REP(j,W+2){
        cout << "#";
    }
    cout << endl;
    REP(i,H){
        cout << "#";
        REP(j,W){
            cout << a[i][j];
        }
        cout << "#" << endl;
    }
    REP(j,W+2){
        cout << "#";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()

using namespace std;

int N;
int X[101];
int Y[101];

using P = pair<double, double>;
P p[101];
int ary[101];

signed main()
{
	cin >> N;
	REP(i, N)
	{
		cin >> X[i] >> Y[i];

		double angle = atan2(Y[i], X[i]);
		p[i] = make_pair(angle, i);
	}

	ARY_SORT(p, N);
	
	REP(i, N)
	{
		ary[i] = p[i].second;
	}

	double ans = 0;

	for (int i = 0; i < N; i++)
	{
		for (int j = 1; j <= N; j++)
		{
			double x = 0.0;
			double y = 0.0;

			for (int k = 0; k < j; k++)
			{
				int index = (i + k) % N;
				x += X[ary[index]];
				y += Y[ary[index]];
			}

			double len = sqrt(x * x + y * y);
			ans = max(ans, len);
		}
	}

	cout << fixed << setprecision(10) << ans << endl;
}



Measured memory_bytes: 512
if __name__ == "__main__":
    C = 0.006
    N = int(input())
    T, A = map(int, input().split())
    H_list = map(int, input().split())

    t_list = map(lambda x: T - C * x, H_list)
    abs_list = list(map(lambda x: abs(x - A), t_list))
    print(abs_list.index(min(abs_list)) + 1)


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <set>

#define rep(i, x, n) for (int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;

int main()
{
    int N, M;
    cin >> N >> M;
    long long dp[100010];
    set<int> se;
    rep(i, 0, M)
    {
        int a;
        cin >> a;
        se.insert(a);
    }
    dp[0] = 1;
    rep(i, 1, N + 1)
    {
        dp[i] = 0;
    }
    rep(i, 0, N)
    {
        if (se.count(i) != 0)
        {
            continue;
        }
        if (se.count(i + 1) == 0)
        {
            dp[i + 1] += dp[i] % 1000000007;
            dp[i + 1] = dp[i + 1] % 1000000007;
        }
        if (se.count(i + 2) == 0)
        {
            dp[i + 2] += dp[i];
            dp[i + 2] = dp[i + 2] % 1000000007;
        }
    }
    //    rep(i, 0, N)
    // {
    //     cout<<dp[i]<<endl;
    // }
    cout << dp[N] << endl;
}

Measured memory_bytes: 5760
s = input()
a = 0
cg, cp = 0, 0
for c in s:
  if c == "p":
    if cg > cp:
      cp += 1
    else:
      cg += 1
      a -= 1
  else:
    if cg > cp:
      cp += 1
      a += 1
    else:
      cg += 1
print(a)

Measured memory_bytes: 3316
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions
template <typename T>
using priority_queue_lo = priority_queue<T, vector<T>, greater<T>>;
#endif

int N;
vl S;
vvl dp;
priority_queue<ll> pq;
ll dfs(int n, ll sum) {
    if (n >= N) {
        pq.push(sum);
        return 0;
    }

    if (dp[n][sum] >= 0) return dp[n][sum];

    ll yes = dfs(n + 1, sum+S[n]) + S[n];
    ll no = dfs(n + 1, sum);

    ll ret = max(yes, no);

    dp[n][sum] = ret;

    return ret;
}

int main_C() {
    cin.tie(0);
    ios::sync_with_stdio(false);
        
    cin >> N;
    S=vl(N); REP(i, N) cin >> S[i];

    dp = vvl(N+MGN, vl(100*N+MGN, -1));
    dfs(0,0);

    ll ans = pq.top();
    while(!pq.empty() && ans%10==0) {
        ans = pq.top();
        pq.pop();
    }

    cout << ans << endl;    

    while(!pq.empty()) pq.pop();

    return 0;
}

Measured memory_bytes: 8960
import java.util.Scanner;

public class Main {
	private static int W,H;
	private static int[][] c;
	private static boolean[][] seen;

	private static int[] dh = {1, -1, 0, 0, 1, -1, 1, -1};
	private static int[] dw = {0, 0, 1, -1, 1, 1, -1, -1};

	private static void dfs(int[][] c, int h, int w) {
		// c(h,w)を探索済みとする
		seen[h][w] = true;
		int nextH, nextW;
		// 8方向を探索する
		for(int i = 0; i < 8; i++) {
			nextH = h + dh[i];
			nextW = w + dw[i];
			// 領域外である場合、探索しない
			if(nextH < 0 || nextW < 0 || nextH >= H || nextW >= W) {
				continue;
			}
			// 海である場合、探索しない
			if(c[nextH][nextW] == 0) {
				continue;
			}
			// 探索済みである場合、探索しない
			if(seen[nextH][nextW]) {
				continue;
			}
			dfs(c, nextH, nextW);
		}
	}

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		W = scan.nextInt();
		H = scan.nextInt();

		while(!(W == 0 && H == 0)) {
			c = new int[H][W];
			seen = new boolean[H][W];
			for(int i = 0; i < H; i++) {
				for(int j = 0; j < W; j++) {
					c[i][j] = scan.nextInt();

					// 全ての領域を未探索状態にする
					seen[i][j] = false;
				}
			}

			int count = 0;
			// 全ての領域を探索する
			for(int i = 0; i < H; i++) {
				for(int j = 0; j < W; j++) {
					// 探索済みであるまたは海である場合、探索は行わない
					if(!seen[i][j] && c[i][j] == 1) {
						dfs(c, i, j);
						count++;
					}
				}
			}
			System.out.println(count);
			W = scan.nextInt();
			H = scan.nextInt();
		}
		scan.close();

	}
}



Measured memory_bytes: 45608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);

		int S=sc.nextInt();

		int h=S/3600;
		int m=(S-h*3600)/60;
		int s=S-(h*3600+m*60);

		System.out.println(h+":"+m+":"+s);
	}
}

Measured memory_bytes: 26160
import sys
s=[list(map(int,e.split(',')))for e in sys.stdin]
for i in range(1,len(s)):
 for j in range(len(s[i])):
  t=j-(len(s[i])>len(s[i-1]))
  s[i][j]+=max(s[i-1][t*(j>0):t+2])
print(*s[-1])


Measured memory_bytes: 5608
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

template <class T>
class vector_at {
  using size_type = std::size_t;
  using _Tp = T;
  using reference = _Tp &;
  using _array = std::vector<_Tp>;

  size_type n;
public:
  _array con;
  vector_at(size_type n) : n(n) {
    con = _array(n);
  }

  vector_at() {
    con.reserve(100);
  }

  reference
  operator[] (size_type __n) {
    return this->at(__n);
  }

  reference
  at (size_type __n) {
    return con.at(__n);
  }

  void
  push_back (_Tp t) {
    con.push_back(t);
  }

  void
  pop_back () {
    con.pop_back();
  }

  void
  sort_i () {
    std::sort(con.begin(), con.end());
  }

  void
  sort_d () {
    std::sort(con.begin(), con.end(), std::greater<_Tp>());
  }

  void
  resize (size_type __n) {
    con.resize(__n);
  }
};

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

  vector<ll> b(n), ans;
  rep(i, n) cin >> b.at(i);

  for (int i = 0; i < n; ++i) {
    int pos = -1;
    for (int j = 0; j < n - i; ++j) {
      if (j + 1 == b[j]) {
        pos = j;
        // debug(j+1);
      }
    }

    if (pos == -1) {
      cout << -1 << endl;
      return 0;
    } else {
      ans.push_back(b[pos]);
      b.erase(b.begin() + pos);
    }
  }
  
  for (int i = n - 1; i >= 0; --i) 
    cout << ans[i] << endl;
}


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

struct tree {
	int node;
	tree *right;
	tree *left;
};

void insert(tree *trees) {
	int num;
	std::cin >> num;
	tree *t = new tree;
	t->node = num;
	t->left = NULL;
	t->right = NULL;
	while (true) {
		if (trees->node > num) {
			if (trees->left != NULL) {
				trees = trees->left;
			} else {
				trees->left = t;
				return;
			}
		} else {
			if (trees->right != NULL) {
				trees = trees->right;
			} else {
				trees->right = t;
				return;
			}
		}
	}
}

void show_in_order(tree *trees) {
	if (trees->left != NULL) show_in_order(trees->left);
	std::cout << " " << trees->node;
	if (trees->right != NULL) show_in_order(trees->right);
}

void show_pre_order(tree *trees) {
	std::cout << " " << trees->node;
	if (trees->left != NULL) show_pre_order(trees->left);
	if (trees->right != NULL) show_pre_order(trees->right);
}

void solve(tree *trees) {
	int num;
	std::cin >> num;
	std::string str;
	std::cin >> str;
	int n;
	std::cin >> n;
	trees->node = n;
	trees->left = NULL; trees->right = NULL;

	for (int i = 0; i < num - 1; i++) {
		std::cin >> str;
		if (str == "insert") {
			insert(trees);
		} else if (str == "print") {
			show_in_order(trees);
			std::cout << std::endl;
			show_pre_order(trees);
			std::cout << std::endl;
		}
	}
}

int main() {
	tree trees;
	solve(&trees);

	return 0;
}

Measured memory_bytes: 16836
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if (a > c){
	swap(a,c);
	swap(b,d);
    }

    int res=0;
    if (b > c){
	if (b >= d) res=d-c;
	else res=b-c;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long int
#define ld long double
#define f(t) for(ll i =0;i<t;i++)
#define vi vector<int>
#define vl vector<ll>
#define pri pair<int,int>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 2e18
#define EPS 1e-3
#define PI 3.1415926535897932385
const double h = 1e-6;
const int MAX_  = 100005;
#define all(v) v.begin(),v.end()
#define display(v) for(int i= 0;i<v.size();++i)cout << v[i] << " "

inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c >= MOD) c -= MOD; return c; }
 //////////////////////*********CODE***********/////////////////////
 //////////////////////////////////////////////////////////////////


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n; cin>>n;
    ll ans = 0;
    for(ll i = 1;i<=n;++i){
        ll cnt = (n/i);
        ll ok = ((cnt)*(cnt + 1))/2;
        ans += (i*ok);
    }
    cout << ans;
    
  
    return 0;
}

//Химаншу

Measured memory_bytes: 3660
N, K = gets.split.map(&:to_i)
edges = Array.new(N){Hash.new}
(N-1).times do
    a, b = gets.split.map(&:to_i)
    edges[a-1][b-1] = true
    edges[b-1][a-1] = true
end

def cnt(start, d, edges, forbid=nil)
    return 1 if d == 0
    dist = Array.new(N)
    used = Array.new(N)
    queue = [start]
    used[start] = true
    dist[start] = 0
    used[forbid] = true if forbid
    ret = 1
    while queue.length > 0
        a = queue.shift
        edges[a].each do |b, _|
            next if used[b]
            dist[b] = dist[a] + 1
            used[b] = true
            ret += 1
            queue.push(b) if dist[b] < d
        end
    end
    ret
end

remain = 0
if K%2 == 0
    N.times do |start|
        result = cnt(start, K/2, edges)
        remain = result if remain < result
    end
else
    N.times do |s1|
        edges[s1].each do |s2, _|
            next if s1 < s2
            result = cnt(s1, K/2, edges, s2) + cnt(s2, K/2, edges, s1)
            p 
            remain = result if remain < result
        end
    end
end
puts N - remain

Measured memory_bytes: 43900
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  vector<tuple<ll, ll, ll>> xyz(n);
  rep(i, n){
    ll a, b, c;
    cin >> a >> b >> c;
    xyz.at(i) = {a, b, c};
  }

  ll ans = -1e18;
  rep(bit, 1 << 3){
    priority_queue<ll> q;
    for(auto t : xyz){
      auto [x, y, z] = t;
      if((bit & 1) == 0) x *= -1;
      if((bit & 2) == 0) y *= -1;
      if((bit & 4) == 0) z *= -1;
      q.push(x+y+z);
    }
    ll add = 0;
    rep(i, m){
      add += q.top();
      q.pop();
    }
    ans = max(ans, add);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <map>

int main()
{
	int n;
	scanf("%d", &n);
	int max = 0;
	std::map<std::string, int> mp;
	for (int i = 0; i < n; ++i)
	{
		std::string s;
		std::cin >> s;
		mp[s] += 1;
		if (max < mp[s])
		{
			max = mp[s];
		}
	}
	for (auto &p : mp)
	{
		if (p.second == max)
		{
			printf("%s\n", p.first.c_str());
		}
	}
	return 0;
}


Measured memory_bytes: 25216
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (InputReader reader = new InputReader(System.in)) {
            solve(reader);
        }
    }

    private static void solve(InputReader reader) throws IOException {
        int input = reader.readInt();
        for (int i = 111; i <= 999; i += 111) {
            if (input <= i) {
                System.out.println(i);
                break;
            }
        }
    }
}

class Util {
    static int gcd(int m, int n) {
        int min = Math.min(m, n);
        int max = Math.max(m, n);
        while (min != 0) {
            int tmp = min;
            min = max % tmp;
            max = tmp;
        }

        return max;
    }
}

class InputReader implements Closeable, AutoCloseable {
    private final BufferedReader br;

    InputReader(InputStream inputStream) {
        this.br = new BufferedReader(new InputStreamReader(inputStream));
    }

    String readLine() throws IOException {
        return this.br.readLine();
    }

    int readInt() throws IOException {
        return Integer.parseInt(this.readLine());
    }

    long readLong() throws IOException {
        return Long.parseLong(this.readLine());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(this.readLine());
    }

    String[] readStringsSplitByDelimiter(String delimiter) throws IOException {
        return this.readLine().split(delimiter);
    }

    int[] readIntsSplitByDelimiter(String delimiter) throws IOException {
        String[] strings = this.readStringsSplitByDelimiter(delimiter);

        int stringsLength = strings.length;
        int[] ints = new int[stringsLength];
        for (int i = 0; i < stringsLength; i++) {
            ints[i] = Integer.parseInt(strings[i]);
        }

        return ints;
    }

    long[] readLongsSplitByDelimiter(String delimiter) throws IOException {
        String[] strings = this.readStringsSplitByDelimiter(delimiter);

        int stringsLength = strings.length;
        long[] longs = new long[stringsLength];
        for (int i = 0; i < stringsLength; i++) {
            longs[i] = Long.parseLong(strings[i]);
        }

        return longs;
    }

    double[] readDoublesSplitByDelimiter(String delimiter) throws IOException {
        String[] strings = this.readStringsSplitByDelimiter(delimiter);

        int stringsLength = strings.length;
        double[] doubles = new double[stringsLength];
        for (int i = 0; i < stringsLength; i++) {
            doubles[i] = Double.parseDouble(strings[i]);
        }

        return doubles;
    }

    @Override
    public void close() throws IOException {
        this.br.close();
    }
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

int dfs(vector<vector<int>>& g, vector<pair<int,int>>& res, int v, 
    int& count, int from, vector<int>& low, vector<int>& pre){
    pre[v] = count++;
    low[v] = pre[v];

    for(auto to: g[v]){
        if(pre[to] == -1){//未到達なら
            low[v] = min(low[v], dfs(g,res,to,count,v,low,pre));
            if(low[to] == pre[to]){
                res.push_back(make_pair(v,to));
            }
        }else{
            if(from == to){//来た道にはもどらない
                continue;
            }
            low[v] = min(low[v], low[to]);
        }
    }
    return low[v];
}

vector<pair<int,int>> bridges(vector<vector<int>>& g, int V){
    vector<pair<int,int>> res;
    if(V>0){
        vector<int> pre(V,-1);
        vector<int> low(V,-1);
        int count = 0;
        dfs(g,res,0,count,-1,low,pre);
    }
    return res;
}

int main() {
    int N,M; cin >> N >> M;
    vector<vector<int>> G(N);
    REP(i,M){
        int a,b; cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    cout << bridges(G,N).size() << endl;

    return 0;
}

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

#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007

ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
/*
ll factor(ll n){
    vll ans;
	if(n==2)ans.pb(2);
	else
    {for(ll i=2;i*i<=n;i++){if(n%i==0 && n%i!=i){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}ans.pb(n);}
    return ans.sz+1;
}
ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i; 
    return res; } 
  
ll nCr(ll n, ll r){ return fact(n) / (fact(r) * fact(n - r)); } 
  
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<string,int> &a,const pair<string,int> &b){return (a.second<b.second);} 

ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;}
bool prime(int n){
    int i,j;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
*/
void solve()
{
	ll a,b;
	cin>>a>>b;
	if(a%3==0 || (a+b)%3==0 || b%3==0)
		cout<<"Possible";
	else
		cout<<"Impossible";
}            
int main()
{
	fast;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}


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

int main(void){
  int n,l,r,ans=0;
  vector<char> v;
  
  cin >> n;
  for (int i=0; i<n; i++){
    char c; cin >> c;
    v.push_back(c);
  }
  l = 0; r = n-1;
  while (1){
    while (1){
      if (l>n || v[l]=='W') break;
      l++;
    }
    while (1){
      if (r<=0 || v[r]=='R') break;
      r--;
    }
    if (l>=r) break;
    v[l++]='R'; v[r--]='W';
//    for (int i=0; i<n; i++) cout << v[i];
//    cout << endl;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define VV(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a); i>n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
inline void f(int i, int x) {
	if ( x % 10 == 3 ){
		cout << " " << i;
		return;
	}
	x /= 10;
	if ( x ) f(i, x);
}
int main() {
	int n; cin >> n;
	rep(i, 3, n + 1) {
		int x = i;
		if ( x % 3 == 0 ){
			cout << " " << i;
			continue;
		}
		f(i, x);
	}
	P("");
	return 0;
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

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

ll dp[16][1024];

int main() {
	dp[0][0] = 1;
	rep(i, 101) repr(j, 9) for(int k = 0; i + k < 1001; ++k) {
		dp[j + 1][i + k] += dp[j][k];
	}
	int n, s;
	while(scanf("%d %d", &n, &s), n | s) {
		printf("%lld\n", dp[n][s]);
	}
	return 0;
}

Measured memory_bytes: 3264
#include "bits/stdc++.h"
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair <ll, ll > pll;
//bool comp(
//
//	st pll &a, const pll &b) {
//	return a.first < b.first;
//}
//std::vector<int> enum_div(int n)//nの約数を列挙
//{
//	std::vector<int> ret;
//	for (int i = 1; i*i <= n; ++i)
//	{
//		if (n%i == 0)
//		{
//			ret.push_back(i);
//			if (i != 1 && i*i != n)
//			{
//				ret.push_back(n / i);
//			}
//		}
//	}
//	return ret;
//}

template<int N>
int factorial() {
	return factorial<N - 1>() * N;
}

template<>  /// 特殊化：factorial<N=”1”>だったら，値を返す
int factorial<1>() {
	return 1;
}

int main()
{
	priority_queue<int> q;
	ll h = 0, w = 0, k = 0, a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, ans = 0;
	string s = {};
	char x[302][302] = {};
	ll y[302][302] = {};

	cin >> h;
	for (int i = 1; i <= 1000; i++)
	{
		if (i*100<=h&&h<=i*105)
		{
			cout << 1 << endl;
			return 0;
		}
	}

	cout << 0 << endl;


	//cout<<factorial<10><<endl;

	//cin >> a >> b;
	//for (int i = 0; i < a; i++)
	//{
	//	cin >> s[i];
	//	if (s[i] >= b)
	//	{
	//		ans++;
	//	}
	//}

	//cout << ans << endl;
	return 0;
}
//2つの組の数をソートしたりするやつ
//vector<pair<ll, ll> > hoges(a);
//for (int i = 1; i <= a; i++)
//{
//	cin >> h;
//	hoges[i - 1] = make_pair(h, i);
//}
//sort(hoges.begin(), hoges.end(), comp);
//for (int i = 0; i < a; i++)
//{
//	cout << hoges[i].second << endl;
//}


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


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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


int main(){
    ll N,K;
    cin>>N>>K;
    v A(N);
    rep(i,0,N)cin>>A[i];
    bool changed = true;
    while(changed && K--){
        changed = false;
        vector <pair<ll,ll>> imos;
        rep(i,0,N){
            imos.PB(MP(i - A[i],1));
            imos.PB(MP(i + A[i] + 1,-1));
        }
        sort(all(imos));
        ll now = 0;
        ll sum = 0;
        rep(i,0,N){
            while(imos[now].first <= i){
                sum += imos[now].second;
                now++;
            }
            if(A[i] != sum){
                A[i] = sum;
                changed = true;
            }
        }
    }
    rep(i,0,N)cout<<A[i]<<" ";

    return 0;
}

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

using namespace std;
string s(100003,0);
int main(){
    long n;
    cin >> s;

    long count=0;
    for(int i=1; i<s.length(); i++){
        if( s[i-1] == s[i]){
            count++;
            if( s[i]== '0' ) s[i]='1';
            else s[i]='0';
        }
    }
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 384
/*==============================================*\
Codeforces ID:    mdshihab
                                                  |
Name:     Md. Shihabul Minhaz                     |
Study:      CSE, JKKNIU                           |
Address:  Trishal, Mymensingh, Bangladesh         |
                                                  |
 mail:   mdshihabul20171@gmail.com                |
 FB  :   fb.com/mdshihabul.minhaz.7               |
 github: Shihabulminhaz                           |
stopstalk :  mdshihab                             |
                                                  |
@uthor   Md. Shihabul Minhaz (shihab)             |
\*===============================================*/


#include<bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d",&a);
#define fli(a) scanf("%ld",&a);
#define fll(a) scanf("%lld",&a);
#define pi(a) printf("%d\n",a);
#define ppi(i,a) printf("Case %d: %d\n",i,a);
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int shihab;
void FI()
{
#ifndef ONLINE_JUDGE
    freopen("C:\\Users\\SHIHAB\\Desktop\\input.in","r",stdin);
#endif // ONLINE_JUDGE
}

int main()
{
    fast
  //  FI(); /// skip this line for compile
    int n,a;
    cin >> n >> a;
    while(n>=500){
        n-=500;
    }
    if(n<=a) cout << "Yes\n";
    else cout << "No\n";
    return 0;
    //code end
}
//okbye


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265


void f(){
  string s;
  cin>>s;
  map<string,bool> mp;
  rep(i,s.size()){
    string t,u;
    rep(j,i){
      t += s[j];
    }
    FOR(j,i,s.size()){
      u += s[j];
    }
    mp[t+u] = true;
    mp[u+t] = true;
    reverse(all(t));
    mp[t+u] = true;
    mp[u+t] = true;
    reverse(all(u));
    mp[t+u] = true;
    mp[u+t] = true;
    reverse(all(t));
    mp[t+u] = true;
    mp[u+t] = true;
  }
  cout<<mp.size()<<endl;
}


int main(){
  int n;
  cin>>n;
  rep(i,n){
    f();
  }

  return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
int N;
const int M=1000001;
vector<int>a[M];
bool vis[M];
int gcd(int a,int b){
    return a==0?b:gcd(b%a,a);
}

main()
{
    cin>>N;
    for(int i=2;i<M;++i)for(int j=i;j<M;j+=i)a[j].push_back(i);
    int g=0;
    bool flag=true;
    for(int i=0;i<N;++i){
        int A;cin>>A;
        g=gcd(g,A);
        for(int j:a[A]){
            flag&=!vis[j];
            vis[j]=true;
        }
    }
    if(flag){
        cout<<"pairwise coprime"<<endl;
    }else if(g==1){
        cout<<"setwise coprime"<<endl;
    }else{
        cout<<"not coprime"<<endl;
    }
}

Measured memory_bytes: 114988
#include<bits/stdc++.h>
        #define ll long long int
        using namespace std;
        #define mod 1000000007
        #define pb push_back
        #define fi first
        #define si second
        #define mp make_pair
        #define f(n) for(ll i=0;i<n;i++)
        #define ff(m) for(ll j=0;j<m;j++)
        #define fr(i,p,n) for(ll i=p;i<n;i++)
        #define in insert
        ll exp(ll a,ll b,ll m);
        #define vl vector<ll> 
        #define pll pair <ll,ll>

    
        void solve(){

        	int n,k;
        	cin>>n>>k;
        	vl h(n,0);
        	f(n)
        	cin>>h[i];

        	const int INF=1e9;
        	vl dp(n, INF);
        	dp[0]=0;
        	f(n){
        		for(int j=i-1;j>=max((int)(i-k),0);j--){
        			dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
        		}
        	}
        	cout<<dp[n-1]<<endl;


        }
 
       int main(){
 
            int t=1;
 			//cin>>t;
            while(t--)
               solve();
    
    		return 0;
		}
 
		ll exp(ll a,ll b,ll m)
		{
			if(b==0)
			{
				return 1;
			}
			ll temp =exp(a,b/2,m);
			temp=(temp*temp)%m;
			if(b&1)
			{
				return (temp*(a%m))%m;
			}
			return temp;
		}

Measured memory_bytes: 1792
s=input()

a=[1,0,0,0]

for i in range(len(s)):
    c=s[i]
    if c=="A":
        a[1]=(a[1]+a[0])%1000000007
    elif c=="B":
        a[2]=(a[2]+a[1])%1000000007
    elif c=="C":
        a[3]=(a[3]+a[2])%1000000007
    elif c=="?":
        tmp=[a[i] for i in range(4)]
        a[0]=tmp[0]*3
        for j in range(3):
            a[j+1]=tmp[j+1]*3+tmp[j]
        a=list(map(lambda x: x%1000000007,a))

    
print(a[3]%1000000007)

Measured memory_bytes: 3188
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
l.sort(key=lambda x:x[0])
cnt=0
ans=0
num=0
for i in range(n):
  if cnt>=m:
    break
  cnt+=l[i][1]
  ans+=l[i][0]*l[i][1]
  num=i
print(ans-(cnt-m)*l[num][0])


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

signed main() {
  int d, t, s;
  cin >> d >> t >> s;

  int dist = s * t;
  if(dist < d) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 3636
def getsum(data, start, end):
    if start == 0:
        return data[end - 1]
    else:
        return data[end - 1] - data[start - 1]

def getdiff(data, start_point, second_point, end_point):
    return abs(getsum(data, second_point, end_point) - getsum(data, start_point, second_point))

n = int(input())
input_data = list(map(int,input().split()))
summed_data = []
summed_data.append(input_data[0])

for i in range(1, n):
    summed_data.append(summed_data[i-1]+input_data[i])

first_separator = 1
third_separator = 3
minimized_diff = 2 * pow(10, 5) * pow(10, 9)

for second_separator in range(2, (n - 1)):
    if second_separator >= third_separator:
        third_separator = second_separator + 1

    while first_separator < (second_separator - 1) and getdiff(summed_data, 0, (first_separator + 1), second_separator) < getdiff(summed_data, 0, first_separator, second_separator):
        first_separator = first_separator + 1

    while third_separator < (n - 1) and getdiff(summed_data, second_separator, (third_separator + 1), n) < getdiff(summed_data, second_separator, third_separator, n):
        third_separator = third_separator + 1

    sum_list = [getsum(summed_data, 0, first_separator), getsum(summed_data, first_separator, second_separator), getsum(summed_data, second_separator, third_separator), getsum(summed_data, third_separator, n)]
    diff = max(sum_list) - min(sum_list)
    if diff < minimized_diff:
        minimized_diff = diff

print(minimized_diff)

Measured memory_bytes: 25672
#abc135 c
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

ans=0
for i in range(n):
    if a[i]-b[i]>=0:
        ans+=b[i]
    else:
        ans+=a[i]
        b[i]=b[i]-a[i]
        if a[i+1]-b[i]>=0:
            ans+=b[i]
            a[i+1]-=b[i]
        else:
            ans+=a[i+1]
            a[i+1]=0
print(ans)


Measured memory_bytes: 18624
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  long long n;
  long long ans = 0, p;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    p = n/i;
    ans += p*(p+1)/2*i;
  }
  cout << ans << endl;
}

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

int mod = 1000000007;

int main()
{
    string S, T, U;
    int A, B;
    cin >> S >> T >> A >> B >> U;
    if (S == U)
        cout << A - 1 << " " << B;
    else
        cout << A << " " << B - 1;
}

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

#define int long long
int n, a, b, k, mod = 998244353, fac[300005], invfac[300005], ans;
int inv(int x){
    int pw = mod - 2, ans = 1;
    while(pw){
        if(pw & 1) ans = (ans * x) % mod;
        x = (x * x) % mod;
        pw /= 2;
    }
    return ans;
}

int c(int n, int k){
    int tmp = (fac[n] * invfac[k]) % mod;
    return (tmp * invfac[n - k]) % mod;
}

signed main(){
    cin >> n >> a >> b >> k;
    fac[0] = 1;
    for(int i = 1; i <= 300000; i++) fac[i] = (fac[i - 1] * i) % mod;
    for(int i = 0; i <= 300000; i++) invfac[i] = inv(fac[i]);
    for(int i = 0; i <= n; i++){
        int tmp = k - (a * i);
        if(tmp < 0) break;
        if(tmp % b) continue;
        if((tmp / b) > n) continue;
        //cout << n << " " << i << " " << tmp / b << " ";
        ans = (ans + (c(n, i) * c(n, tmp / b))) % mod;
        //cout << ans << "\n";
    }
    cout << ans;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
using namespace std;
int main(){
    string s; cin>>s;
    if (s == "Sunny") cout << "Cloudy";
    else if (s == "Cloudy") cout << "Rainy";
    else cout << "Sunny";
}

Measured memory_bytes: 3548