akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE BangPatterns #-}
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State
import           Data.Array.IArray
import           Data.Array.ST
import           Data.Array.Unboxed    (UArray)
import qualified Data.Array.Unboxed    as U
import           Data.Bits
import           Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as BS
import           Data.Char
import           Data.Graph
import           Data.Int              (Int64)
import           Data.List
import           Data.Maybe
import           Data.Proxy
import qualified Data.Set              as S
import           Data.STRef
import           Data.Vector.Unboxed   (Vector)
import qualified Data.Vector.Unboxed   as V
import           Numeric

getAsInt :: IO [Int]
getAsInt =  unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

getAsIntLine :: Int -> IO [[Int]]
getAsIntLine n = replicateM n getAsInt

getAsIntArray1Dr :: Int -> IO (UArray Int Int)
getAsIntArray1Dr n = U.listArray (1,n) <$> getAsInt

getAsIntVec1Dr :: IO (Vector Int)
getAsIntVec1Dr = V.fromList <$> getAsInt

getAsIntArray1Dc :: Int -> IO (UArray Int Int)
getAsIntArray1Dc n = U.listArray (1,n) . concat <$> getAsIntLine n

getAsIntVec1Dc :: Int -> IO (Vector Int)
getAsIntVec1Dc n = V.fromList . concat <$> getAsIntLine n

-- n: number of lines
-- m: number of values per a line
getAsIntArray2D :: Int -> Int -> IO (UArray (Int,Int) Int)
getAsIntArray2D n m = U.listArray ((1,1),(n,m)) . concat <$> getAsIntLine n

getAsString :: IO [String]
getAsString = map BS.unpack . BS.words <$> BS.getLine

getAsCharArray1DWithLength :: IO (Int, UArray Int Char)
getAsCharArray1DWithLength = BS.getLine >>= \cs ->
  let n = BS.length cs
      ary = (U.listArray (1,n) $ unfoldr BS.uncons cs) :: UArray Int Char
  in return (n, ary)

-- n: number of lines
-- m: number of chars per a line
getAsCharArray2D :: Int -> Int -> IO (UArray (Int,Int) Char)
getAsCharArray2D n m = U.listArray ((1,1),(n,m)) . unfoldr BS.uncons . BS.concat <$> replicateM n BS.getLine

main :: IO ()
main = do
  [k,n] <- getAsInt
  as <- getAsInt
  let bs = zipWith (-) (tail as) as
  print $ min (k - ((k - last as) + head as)) (k - maximum bs)


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

int main(){
    string s;
    cin >> s;
    for(int bit=0; bit<(1<<3); bit++){
        int tmp = (int)(s[0] - '0');
        char op[3];
        for(int i=0; i<3; i++){
            if(bit & (1<<i)){
                tmp += (int)(s[i+1] - '0');
                op[i] = '+';
            }
            else{
                tmp -= (int)(s[i+1] - '0');
                op[i] = '-';
            }
        }
        if(tmp == 7){
            cout << s[0];
            for(int i=0; i<3; i++) cout << op[i] << s[i+1];
            cout << "=7" << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)

constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;

ll g[202][202];

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

	int n, m, r; cin >> n >> m >> r;
	vector<int> a(r); rep(i, 0, r) cin >> a[i], --a[i];
	rep(i, 0, n) rep(j, 0, n) if (i != j) g[i][j] = INF;

	rep(i, 0, m) {
		ll a, b, c; cin >> a >> b >> c;
		--a, --b;
		g[a][b] = c;
		g[b][a] = c;
	}
	rep(k, 0, n) rep(i, 0, n) rep(j, 0, n) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);

	sort(a.begin(), a.end());
	ll ans = INF;
	do {
		ll tmp = 0;
		rep(i, 0, r - 1)
			tmp += g[a[i + 1]][a[i]];
		ans = min(ans, tmp);
	} while (next_permutation(a.begin(), a.end()));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3976
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pll;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s;
    cin >> s;
    if(s.back() == '3')
        cout << "bon";
    else if(s.back() == '0' || s.back() == '1' || s.back() == '6' || s.back() == '8')
        cout << "pon";
    else
        cout << "hon";
    return 0;
}


Measured memory_bytes: 3612
//                        DushtuBunny
//                        Rahul Halder    
//    Indian Institute of Engineering Science & Technology,Shibpur


#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define f first
#define se second
#define LB lower_bound
#define UB upper_bound
#define pb push_back
#define mp make_pair
#define vll vector<ll>
#define vi vector<int>
#define vc vector<char>
#define vpll vector<pair<ll,ll>>
const unsigned int MOD = 1000000007;

using namespace std;

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

    IOS;
    int T;
    // cin>>T;
    T=1;

    while(T--)
    {
        ll n,k;
        cin>>n>>k;

        ll d[k];

        map<int,int>m;
        for(int i=0;i<k;i++)
        {
            cin>>d[i];
            for(int j=0;j<d[i];j++){
                ll x;
                cin>>x;
                m[x]++;
            }
        }   

        ll ans=0;
        for(int i=1;i<=n;i++)
            if(!m[i])
                ans++;

        cout<<ans;

    }
    

    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<typename ... Args> std::string format(const std::string& fmt, Args ... args ) { size_t len = std::snprintf( nullptr, 0, fmt.c_str(), args ... ); std::vector<char> buf(len + 1); std::snprintf(&buf[0], len + 1, fmt.c_str(), args ... ); return std::string(&buf[0], &buf[0] + len); }


struct Tmp {
  int u, v, count;
  bool isTakahashi;
};

void solve(void)
{
  int N; cin >> N;
  int u, v; cin >> u >> v;
  --u, --v;
  vector<vector<int>> tree(N);
  for (int _ = 0; _ < N-1; ++_) {
    int a, b; cin >> a >> b;
    --a; --b;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }

  vector<int> takahashi(N, -1);
  vector<int> aoki(N, -1);
  { // aoki
    std::queue<int> que{};
    que.push(v);
    aoki[v] = 0;
    while (!que.empty()) {
      auto c = que.front();
      que.pop();
      for (const auto& n : tree[c]) {
        if (aoki[n] == -1) {
          aoki[n] = aoki[c] + 1;
          que.push(n);
        }
      }
    }
  }

  { // takahashi
    std::queue<int> que{};
    que.push(u);
    takahashi[u] = 0;
    while (!que.empty()) {
      auto c = que.front();
      que.pop();
      for (const auto& n : tree[c]) {
        if (takahashi[n] == -1) {
          takahashi[n] = takahashi[c] + 1;
          que.push(n);
        }
      }
    }
  }

  int ans{-1};
  for (int i = 0; i < N; ++i) {
    if (takahashi[i] < aoki[i]) {
      chmax(ans, aoki[i]-1);
    }
  }

  assert(ans != -1);
  cout << ans << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


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

score = sum(b)
for i,j in zip(a,a[1:]):
    if j == i+1:
        score += c[i-1]

print(score)


Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
using namespace std;




int main(){
ll n;
ll ans=0;
cin>>n;
vector<string> a(n);
for(ll i=0;i<n;i++)cin>>a[i];

for(ll i=1;i<n;i++){
int tmp = a[i-1].size();
tmp--;
if(a[i-1][tmp]!=a[i][0]){
  cout<<"No"<<endl;
  return 0;
}

for(ll j=0;j<i;j++){

if(a[j]==a[i]){
  cout<<"No"<<endl;
  return 0;
}


}




}

cout<<"Yes"<<endl;

return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(5)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<short, short> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 100000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator > (const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int n;
vector<string> fld;
int cnt[1005][1005];

bool search(int m)
{
	REP(i, n - m + 1)REP(j, n - m + 1)
	{
		REP(k, m)
		{
			if (cnt[i+k][j] < m) goto next;
		}

		return true;
	next:;
	}
	return false;
}

int main()
{
	while (cin >> n, n)
	{
		MS(cnt, 0);
		fld.resize(n);
		REP(i, n)
		{
			cin >> fld[i];
			cnt[i][n] = 0;
			REP(j, n)
			{
				cnt[i][n - j - 1] = (fld[i][n - j - 1] == '*' ? 0 : cnt[i][n - j] + 1);
			}
		}
		int lb = 0, ub = 2 * n;
		while (ub - lb > 1)
		{
			int mid = (ub + lb) / 2;
			if (search(mid)) lb = mid;
			else ub = mid;

		}
		cout << lb << endl;
	}
	return 0;
}

Measured memory_bytes: 6008
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
 
	double rate, maxrate=-1.0;
	int water,sugar,maxsugar;
	int x,y;
	for(int i=0; i*a*100<=f; i++) {
		for(int j=0; j*b*100<=f; j++) {
			water=i*a*100+j*b*100;
			maxsugar=(i*a+j*b)*e;
			for(int k=0; k*c<=maxsugar; k++) {
				for(int l=0; l*d<=maxsugar; l++) {
					sugar=k*c+l*d;
					rate=(double)100*sugar/(water+sugar);
					if(maxrate<rate&&sugar<=maxsugar&&water+sugar<=f) {
						maxrate=rate;
						x=water;
						y=sugar;
					}
				}
			}
		}
	}
	
	cout<<x+y<<' '<<y<<endl;
 
	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (x, y) = readLine()!!.split(' ').map { it.toInt() }
    if (y == 2*x || y == 4*x) {
        println("Yes")
        return
    } else if (y % 2 == 1 || y > 4*x || y < 2*x) {
        println("No")
        return
    }

    var ashi = 4 * x
    var change = x
    while (ashi != y) {
        ashi -=2
        change--
    }
    if (ashi == y) println("Yes")
    else println("No")
}


Measured memory_bytes: 36356
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main() {
    int a,b;
    cin>>a>>b;
    double e = a/b;
    cout<<(a/b)<<" "<<a%b<<" "<<fixed<< setprecision(5) << (double)a/(double)b<<endl;
}


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

int main()
{
	string S, T;
	int val;
	cin >> S >> T;
	val = stoi(S + T);
	int i;
	for ( i = 1; i * i <= val; i++ ) {
		if ( i * i == val ) {
			break;
		}
	}
	if ( i * i > val ) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
	return ( 0 );
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
int f(int x,int y){return ceil((log(x)-log(y))/log(4));}
int n,a[220001],dp[2][220001][16];
main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int k=0;k<2;k++)
	{
		for(int i=n-1;i>=0;i--)
			for(int j=0;j<16;j++)
			{
				int r=max(0ll,f(a[i],a[i+1])+j);
				dp[k][i][j]=r<16?dp[k][i+1][r]+r:dp[k][i+1][15]+r+(n-i-2)*(r-15);
			}
		if(!k)
			for(int i=0;i<n/2;i++)swap(a[i],a[n-i-1]);
	}
	int ans=1ll<<62;
	for(int i=0;i<n;i++)ans=min(ans,(dp[0][i][0]+dp[1][n-i][0])*2+i);
	cout<<ans<<'\n';
}


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

typedef vector <long long> vi;
typedef vector <vi> vvi;
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define ll long long
#define ld long double
#define MAX 305

ld dp[MAX][MAX][MAX];

ld sushi(ll a, ll b, ll c)
{
    if ((a < 0 || b < 0) || c < 0)
        return 0;
    
    if (dp[a][b][c] == -1)
        dp[a][b][c] = (dp[1][0][0] / (a + b + c)) + (((sushi(a - 1, b, c) * a) + (sushi(a + 1, b - 1, c) * b) + (sushi(a, b + 1, c - 1) * c)) / (a + b + c));
    return dp[a][b][c];
}

int main(void)
{
    ll a = 0, b = 0, c = 0, n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        ll tmp;
        cin >> tmp;
        if (tmp == 1)
            a++;
        else if (tmp == 2)
            b++;
        else
            c++;
    }

    for (int i = 0; i < MAX; i++)
        for (int j = 0; j < MAX; j++)
            for (int k = 0; k < MAX; k++)
                dp[i][j][k] = -1;

    dp[1][0][0] = n;
    
    cout << setprecision(10) << fixed << sushi(a, b, c) << "\n";
}


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

int main() {
	int n;
	cin >> n;
	string s[n];
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	int m;
	cin >> m;
	string t[m];
	for (int i = 0; i < m; i++) {
		cin >> t[i];
	}

	int ans = 0;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i; j < n; j++) {
			if (s[i] == s[j]) {
				sum++;
			}
		}
		for (int k = 0; k < m; k++) {
			if (s[i] == t[k]) {
				sum--;
			}
		}
		if (ans < sum) {
			ans = sum;
		}
		sum = 0;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> push(n,0);
  vector<int> butt(n);
  rep(i,n)cin>>butt.at(i);
  int now = 0;
  int count = 1;
  while(true){
    if(push.at(now)==1){cout << -1  << endl;return 0;}
    if(butt.at(now)==2){cout << count << endl;return 0;}
    push.at(now)++;
    now = butt.at(now) -1;
    count++;
  }

	return 0;
}


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

using namespace std;

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

    vector<int> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    h[0]--;
    for (int i = 0; i < n - 1; ++i) {
        if (h[i] < h[i + 1]) h[i + 1]--;

    }

    for (int i = 0; i < n - 1; ++i) {
        if (h[i] > h[i + 1]) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 640
fun main(args: Array<String>) {
    abc143b()
}

fun abc143b() {
    val n = readLine()!!.toInt()
    val dList = readLine()!!.split(" ").map { it.toInt() }

    val answer = (0 until n).map { i ->
        (i + 1 until n).map { j ->
            dList[i] * dList[j]
        }
    }.flatten().sum()

    println(answer)
}


Measured memory_bytes: 38004
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n;

string s;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> s;
    n = s.size();
    s = " " + s;
    int ans = INT_MAX;
    for(int c = 0; c < 26; c++)
    {
        int last = 0;
        int mx = 0;
        for(int i = 1; i <= n; i++)
            if(s[i] == char('a' + c))
            {
                mx = max(mx, i - last - 1);
                last = i;
            }
        mx = max(mx, n - last);
        ans = min(ans, mx);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3596
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

int c[35][35];
int x[505][505];
int p0[35],p1[35],p2[35];
int ans=INF;
int C;

#include <functional>

void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(int *)> f) {
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}

// nPnの順列に対して処理を実行する
void foreach_permutation(int n, std::function<void(int *)> f) {
  int indexes[n];
  for (int i = 0; i < n; i++) indexes[i] = i;
  do {
    f(indexes);
  } while (std::next_permutation(indexes, indexes + n));
}

// nPkの順列に対して処理を実行する
void foreach_permutation(int n, int k, std::function<void(int *)> f) {
  foreach_comb(n, k, [&](int *c_indexes) {
    foreach_permutation(k, [&](int *p_indexes) {
      int indexes[k];
      for (int i = 0; i < k; i++) {
        indexes[i] = c_indexes[p_indexes[i]];
      }
      f(indexes);
    });
  });
}

int main(){
    int n;
    cin >> n>>  C;
    rep2(i,C){
        rep2(j,C){
            cin >> c[i][j];
            
        }
    }
    rep(i,n){
        rep(j,n){
            cin >> x[i][j];
            if((i+j)%3==0){
                p0[x[i][j]]++;
            }else if((i+j)%3==1){
                p1[x[i][j]]++;
            }else if((i+j)%3==2){
                p2[x[i][j]]++;
            }
        }
    }
    cerr<<endl;
    rep2(i,C){
        cerr<<p0[i]<<' ';
    }
    cerr<<endl;
    cerr<<endl;
    foreach_permutation(C, 3, [](int *indexes) { 
        int temp=0;
        int q0=indexes[0]+1,q1=indexes[1]+1,q2=indexes[2]+1;
        rep2(i,C){
            if(i!=q0){
                temp+=p0[i]*c[i][q0];
            }
            if(i!=q1){
                temp+=p1[i]*c[i][q1];
            }
            if(i!=q2){
                temp+=p2[i]*c[i][q2];
            }
            cerr<<p0[i]*c[i][q0]<<' '<<p1[i]*c[i][q1]<<' '<<p2[i]*c[i][q2]<<endl;
        }
        cerr<<q0<<' '<<q1<<' '<<q2<<' '<<temp<<endl;
        ans=min(ans,temp);
     });
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <math.h>
#define int long long
#define INF 1000000000000
using namespace std;
int n, k;
signed main()
{
    cin >> n >> k;
    int a[n + 2], total[n + 2];
    total[0] = 0;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 1; i < n; i++)
    {
        total[i] = INF;
        for (int j = 1; j <= k; j++)
            if (i >= j)
                total[i] = min(total[i], total[i - j] + abs(a[i] - a[i - j]));
    }
    cout << total[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1792
import sys,bisect,math
sys.setrecursionlimit(15000)

M,N = map(int,sys.stdin.readline().split())

def powmod(m,n,mod):
  if n == 1:
    return m
  ret = (powmod(m*m%mod,n//2,mod))%mod
  if n%2==1:
    return (ret*m)%mod
  return ret%mod

print(powmod(M,N,1000000007))


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

int main() {
  int n;
  cin >> n;
  
  
  if ((n-1000*(n/1000))%111==0 || (n-n%10)%1110==0) {
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
}

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

int main(){
    int N, M; cin >> N >> M;
    int s[M], c[M];
    for(int i=0; i<M; i++){
        cin >> s[i] >> c[i];
        s[i]--;
    }
    int digit[3]={}, flag[3]={}, ans=0;
    for(int i=0; i<M; i++){
        if(flag[s[i]] && digit[s[i]] != c[i]){
            cout << -1 << endl;
            return 0;
        }else if(s[i] == 0 && c[i] == 0 && N != 1){
            cout << -1 << endl;
            return 0;
        }else{
            digit[s[i]] = c[i];
            flag[s[i]] = 1;
        }
    }
    if(flag[0] == 0 && N != 1){
        digit[0] = 1;
    }
    for(int i=0; i<N; i++){
        ans += digit[N-i-1]*pow(10, i);
        }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
int main(){
	vector <int> v;
  	int t=3;
while(t--){
	int a;
  cin>>a;
  v.push_back(a);
}
	sort(v.begin(),v.end());
  if (v[0]==5 and v[1]==5 and v[2]==7)
    cout<<"YES";
  else cout<<"NO";
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int count = sc.nextInt();
            List<Integer> list = new ArrayList<>();
            int max=Integer.MIN_VALUE;
            int min=Integer.MAX_VALUE;
            while (count-- > 0) {
                int a = sc.nextInt();
                if (a>max) max=a;
                if (a<min) min=a;
                list.add(a);
            }
            if (max == min) {
                System.out.println(0);
            }else{
                int res=Integer.MAX_VALUE;
                for (int i=min;i<=max;i++) {
                    int minValue = getMinValue(list, i);
                    if (minValue<res) res=minValue;
                }
                System.out.println(res);
            }

        }
    }

    public static int getMinValue(List<Integer> list, int value) {
        int sum=0;
        for (Integer x : list) {
            sum+=(x-value)*(x-value);
        }
        return sum;
    }
}

Measured memory_bytes: 9684
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);


int GCD(int a, int b) {
  if(a>b) {
    int tmp = a;
    a = b;
    b = tmp;
  }

  /* a <= b */
  int r = b%a;
  while(r!=0) {
    b = a;
    a = r;
    r = b%a;
  }

  return a;
}

int main() {
  int N;
  cin >> N;
  int A;
  cin >> A;

  rep(i, N-1) {
    int a;
    cin >> a;
    A = GCD(A, a);
  }

  cout << A << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

void solve(){
  ll a,b,c;
  cin >>a >> b>> c;
  a+=b;
  a+=c;
  cout << (a>=22?"bust":"win") << endl;
}

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 3652
import java.util.*;

/**
 * A
 */
public class Main {

    Node root;

    public void run() {

        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        
        for(int i=0; i<m; i++) {
            String str = sc.next();
            Node ans;
            if(str.startsWith("i")) {
                insert(sc.nextInt());
            } else if(str.startsWith("f")) {
                ans = find(sc.nextInt());
                if(ans != null) {
                    System.out.println("yes");
                } else {
                    System.out.println("no");
                }
            } else {
                inorder(root);
                System.out.println();
                preorder(root);
                System.out.println();
            }
        }

        sc.close();

    }

    
    public void insert(int v) {
        
        Node x = root; // root
        Node y = null; // parent of x
        Node z = new Node(v); // it will be inserted
        
        while(x != null) {
            y = x;
            if(z.id < x.id) {
                x = x.left;
            } else {
                x = x.right;
            }
        }
        if(y == null) {
            root = z;
        } else if(z.id < y.id) {
            y.left = z;
        } else {
            y.right = z;
        }
        
    }
    
    public Node find(int v) {

        Node n = root;

        while (n != null && n.id != v) {
            if(n.id > v) {
                n = n.left;
            } else {
                n = n.right;
            }
        }

        return n;

    }

    public void inorder(Node tree) {
        
        if(tree == null) {
            return;
        }

        inorder(tree.left);
        System.out.print(" "+tree.id);
        inorder(tree.right);

    }

    public void preorder(Node tree) {

        if(tree == null) {
            return;
        }

        System.out.print(" "+tree.id);
        preorder(tree.left);
        preorder(tree.right);

    }

    public static void main(String[] args) {
        new Main().run();
    }

}

class Node {

    int id;
    Node left;
    Node right;

    Node(int id) {
        this.id = id;
    }

}


Measured memory_bytes: 201860
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;

int main()
{
	int N;cin>>N;
	vector<int> b(N);
	for(int i=0;i<N;++i)cin>>b[i];
	stack<int> ans;
	for(int i=0;i<N;i++)
	{
		for(int j=b.size()-1;1;j--)
		{
			if(j==-1)
			{
				cout<<-1<<endl;
				return 0;
			}
			if((j+1)==b[j])
			{
				//cout<<b[j]<<"を挿入"<<endl;
				ans.push(j+1);
				b.erase(b.begin()+j);;
				break;
			}
			
		}
	}
	for(int i=0;i<N;i++)
	{
		cout<<ans.top()<<endl;
		ans.pop();
	}
   return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
#include <limits.h>
//#include <math.h>

#define Min(a, b) (a < b ? a : b)

int main() {
  int n;
  scanf("%d", &n);
  int x[n];
  for (int i=0; i<n; i++)
    scanf("%d", x+i);
  int ans = INT_MAX, cnt;
  for (int i=1; i<101; i++) {
    cnt = 0;
    for (int j=0; j<n; j++) {
      cnt += (x[j]-i)*(x[j]-i);
    }
    ans = Min(ans, cnt);
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N; cin >> N;
	int a[N];
	rep(i, N) cin >> a[i];
	sort(a, a + N);
	int leftans = a[N - 1];
	int rightans = -1;
	int index = -1;
	rep(i, N) {
		int tmp = min(a[i], leftans - a[i]);
		if (rightans < tmp) {
			rightans = tmp;
			index = i;
		}
		
	}
	cout << leftans << " " << a[index] << endl;


    return 0;
}


Measured memory_bytes: 640
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func main() {
	sc := NewScanner()
	_, M := sc.nextInt(), sc.nextInt()
	is := make([][]int, 100000)
	for i := 0; i < M; i++ {
		a := sc.nextInt()
		b := sc.nextInt()
		is[a-1] = append(is[a-1], b-1)
	}
	count := 0
	end := -1
	for start, v := range is {
		if len(v) == 0 {
			continue
		}
		sort.Ints(v)
		nend := v[0]
		if start < end {
			if nend <= end {
				end = nend
			}
		}
		if end <= start {
			count++
			end = nend
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 7552
#include <stdio.h>

int main() {

	int n, height[100];
	int i, front_max = 0, count = 0;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &height[i]);
		if (height[i] >= front_max) {
			count++;
			front_max = height[i];
		}
	}
	printf("%d", count);

	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
long long a, b, c, d, ans, t;
int main() {
	scanf("%lld%lld%*lld%lld%lld", &a, &b, &c, &d);
	t = a%2 + c%2 + d%2;
	if(t>=2 && a && c && d) {
		ans += 3;
		a--; c--; d--;
	}
	ans += b + a/2*2 + c/2*2 + d/2*2;
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 128
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<cstddef>
#include<vector>
#include<algorithm>

using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = uint_fast64_t;
#define rep(i, n) for (usize i = 0; i < (usize)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i64 h,n;
cin >> h >> n;
vector<i64> a(n),b(n);
rep(i,n)cin >> a[i] >> b[i];
vector<i64> dp(2 * h + 1,1e9);
dp[0] = 0;
rep(i,h){
    rep(j,n){
        if(dp[i] != 1e9){
            dp[min<i32>(i + a[j],2 * h)] = min(dp[min<i32>(2 * h,i + a[j])],dp[i] + b[j]);
        }
    }
}
i64 ans = 1e9;
for(i32 i = h; i <= h * 2; i++)ans = min(ans,dp[i]);
cout << ans << endl;
}

Measured memory_bytes: 3652
#include <iostream>
using namespace std;
void swap(int* x,int* y){
	int tmp;
	tmp =*x; *x =*y; *y =tmp;
}
int main(){
	int n,sum=0;
	cin >>n;
	int x[n],minj;
	for(int i=0;i<n;i++) cin>>x[i];
	for(int i=0;i<n;i++){
		minj =i;
		for(int j=i;j<n;j++){
			if(x[j]<x[minj]) minj =j;
		}
		if(i != minj){
			swap(&x[i],&x[minj]); sum++;
		}
	}
	for(int i=0;i<n;i++){
		if(i==0) cout<<x[i];
		else cout<<" "<<x[i];
	}
	cout <<"\n"<<sum<<"\n";
}


Measured memory_bytes: 3092
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define FORR(i,a,b) for (int i = a; i > b; i--)
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


int main(){
    ll ans = 0;
    ll a, b, x, a_x, b_x;
    cin >> a >> b >> x;
    
    a_x = (a + x - 1) / x * x;
    b_x = b / x * x;
    
    ans = (b_x - a_x) / x + 1;
    
    cout << ans << endl;
    return 0;
}










Measured memory_bytes: 256
fun main(args: Array<String>) {
    var n= readLine()!!.toInt()
    var pList= readLine()!!.split(" ").map { it.toInt() }
    var tmp=2e5.toInt()+1
    var ans=0
    for(i in pList){
        if(i<tmp){
            ans++
            tmp=i
        }
    }
    println(ans)
}

Measured memory_bytes: 83228
#include <iostream>

using namespace std;

char tile[20][20];
int canVisit[20][20];

void bfs(int x, int y, int w, int h)
{  
  if (tile[y][x] == '#') return;
  if (canVisit[y][x] == 1) return;
  
  if (canVisit[y][x] == 0) {
    canVisit[y][x] = 1;
  }
  
  int dx[] = { -1,  0,  0,  1 };
  int dy[] = {  0,  1, -1,  0 };

  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      if (x + dx[i] >= 0 && x + dx[i] < w
          && y + dy[i] >= 0 && y + dy[i] < h) {
        bfs(x + dx[i], y + dy[i], w, h);

      }
    }
  }
}

int main()
{
  int w, h;
  int init_x, init_y;
  
  while (1) {
    cin >> w >> h;
    if (w == 0 && h == 0) break;

    for (int i = 0; i < 20; i++) {
      for (int j = 0; j < 20; j++) {
        tile[i][j] = '#';
        canVisit[i][j] = 0;
      }
    }
    
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> tile[i][j];
        if (tile[i][j] == '@') {
          init_x = j;
          init_y = i;
        }
      }
    }

    bfs(init_x, init_y, w, h);
    
    int sum_of_tile = 0;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        sum_of_tile += canVisit[i][j];
      }
    }
    cout << sum_of_tile << endl;
  }
}



Measured memory_bytes: 3120
N = int(input())
S = input()
dp = [[0]*N for _ in range(N)]
ans = 0
for i in range(N):
    for j in range(i+1,N):
        if(S[i]==S[j]):
            if(i==0):
                dp[i][j] = 1
            else:
                last = dp[i-1][j-1]
                if(j-last == i):
                    continue
                dp[i][j] = last+1

                ans = max(dp[i][j],ans)
print(ans)


Measured memory_bytes: 229896
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

template<int mod>
struct ModInt{
  int x;

  ModInt() : x(0){}
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod){}

  ModInt &operator+=(const ModInt &p){
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p){
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p){
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p){
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const {return ModInt(-x);}
  ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;}
  ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;}
  ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;}
  ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;}
  bool operator==(const ModInt &p) const {return x == p.x;}
  bool operator!=(const ModInt &p) const {return x != p.x;}

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p){
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a){
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod(){return mod;}
};

using mint = ModInt<MOD>;

// dp[i][j][k]: i段目まで、保留j、奇妙さk
mint dp[51][51][2600];

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

    dp[0][0][0] = 1;
    for(int i = 0; i < N; i++){
        for(int j = 0; j <= i; j++){
            for(int k = 0; k <= K; k++){
                {
                    int nj = j;
                    dp[i+1][nj][k+nj*2] += dp[i][j][k];
                }
                {
                    int nj = j+1;
                    dp[i+1][nj][k+nj*2] += dp[i][j][k];
                }
                {
                    int nj = j;
                    mint x = j*2; 
                    dp[i+1][nj][k+nj*2] += dp[i][j][k] * x;
                }
                if(j >= 1){
                    int nj = j - 1;
                    mint x = j*j;
                    dp[i+1][nj][k+nj*2] += dp[i][j][k] * x;
                }
            }
        }
    }

    cout << dp[N][0][K] << '\n';

    return 0;
}

Measured memory_bytes: 26624
#include<iostream>
typedef long long ll;
using namespace std;

const int MOD = 1e9 + 7, MAX = 2500000;

int comb(int n, int k){
    // Calculate factorial and inverse element
    ll fac[MAX], finv[MAX], inv[MAX];
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int X, Y, ans = 0;
    cin >> X >> Y;
    int n = (2 * Y - X) / 3;
    int m = (2 * X - Y) / 3;
    if ((X + Y) % 3 == 0 && n >= 0 && m >= 0) {
        ans = comb(n + m, n);
    }
    cout << ans << endl;
}

Measured memory_bytes: 58880
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import GHC.ST
-- import System.IO.Unsafe
 
-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
whenM :: Monad m => m Bool -> m () -> m ()
whenM c a = c >>= flip when a
-- templete



main = getInts >>= print . (`div`2) . sum



Measured memory_bytes: 3620
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 201

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

bool calc(){
  string s;
  set<string> ss;
  
  cin >> s;
  
  for(int i=1;i<s.size();i++){
    string a = s.substr(0,i);
    string b = s.substr(i);

    string ra = a,rb = b;
    
    reverse(ra.begin(),ra.end());
    reverse(rb.begin(),rb.end());

    ss.insert(a+b);
    ss.insert(ra+b);
    ss.insert(a+rb);
    ss.insert(ra+rb);
    ss.insert(b+a);
    ss.insert(rb+a);
    ss.insert(b+ra);
    ss.insert(rb+ra);
  }

  printf("%d\n",(int)ss.size());
  
  return true;
}

int main(){
  int m;
  
  scanf("%d",&m);
  
  for(int i=0;i<m;i++){
    calc();
  }
  
  return 0;
}

Measured memory_bytes: 3400
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use itertools::Itertools;
use std::process::exit;
use std::cmp::*;
use num::*;
use num::integer::Roots;

fn main() {
    input! {
    n:usize,
    }
    for i in 1..999 {
        if n*i%360==0 {println!("{}",i);exit(0)}
    }
}

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

char c;

int main() {
	cin >> c;
	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') cout << "vowel" << endl;
	else cout << "consonant" << endl;
	return 0;
}

Measured memory_bytes: 256
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    let x: isize;
    let a: isize;
    let b: isize;

    input!(x, a, b);

    if a - b >= 0 {
        println!("delicious")
    } else {
        if b - a <= x {
            println!("safe");
        } else {
            println!("dangerous");
        }
    }
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
signed main() {
	char c; cin >> c;
	if (c == 'A')cout << "T\n";
	else if (c == 'T')cout << "A\n";
	else if (c == 'G')cout << "C\n";
	else cout << "G\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <list>
#include <fstream>
#include <iomanip>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int

#include <nmmintrin.h>
#ifdef _MSC_VER

#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

struct Edge {
	int from, to;
};
struct RLAQ {
	ll sst[1 << 18];
	ll adt[1 << 18];
	RLAQ() {
		fill(sst, sst + (1 << 18), 0);
		fill(adt, adt + (1 << 18), 0);
	}
	void add(int p, int q, ll x, int k = 0, int l = 0, int r = (1 << 17)) {
		if (r <= p || q <= l) return;
		if (p <= l && r <= q) {
			adt[k] += x;
			return;
		}
		add(p, q, x, 2 * k + 1, l, (l + r) / 2);
		add(p, q, x, 2 * k + 2, (l + r) / 2, r);
		sst[k] = max(sst[2 * k + 1] + adt[2 * k + 1], sst[2 * k + 2] + adt[2 * k + 2]);
	}
	ll find(int p, int q, int k = 0, int l = 0, int r = (1 << 17)) {
		if (r <= p || q <= l) return LLONG_MIN / 2;
		if (p <= l && r <= q) return sst[k] + adt[k];
		ll m1, m2;
		m1 = find(p, q, 2 * k + 1, l, (l + r) / 2);
		m2 = find(p, q, 2 * k + 2, (l + r) / 2, r);
		return max(m1, m2) + adt[k];
	}
};

int arr[1000001], pc;
void Eratosthenes(int N) {//Nまでの素数表
	for (int i = 0; i < N; i++) {
		arr[i] = 1;
	}
	for (int i = 2; i < sqrt(N); i++) {
		if (arr[i]) {
			for (int j = i * 2; j <= N; j += i) {
				arr[j] = 0;
			}
		}
	}

	int cou = 0;
	for (int i = 2; i < N; i++) {
		if (arr[i] == 1) {
			arr[cou] = i;
			cou++;
		}
	}
	pc = cou;
}
int main() {

	ll n, m;
	cin >> n >> m;

	if (n > m) swap(n, m);

	if (n == 1) {
		if (m >= 2)
			cout << m - 2 << endl;
		else
			cout << 1 << endl;
	}
	else {
		cout << n * m - (2 * n + 2 * m - 4) << endl;
	}


	return 0;
}

Measured memory_bytes: 256
/*

This Submission is to determine how many 120/240 min const. delivery point there are.

*/
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 1000000007
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)
unsigned long xor128() {
	static unsigned long x = time(NULL), y = 362436069, z = 521288629, w = 88675123;
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
long long dp[3000] = {};
int main() {
	long long n, m, p;
	cin >> n >> m >> p;
	vector <tuple<long long,long long, long long >> edges;
	REP(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		c = c - p;
		edges.push_back(make_tuple(a, b, c));
	}
	REP(i, n) {
		dp[i] = -LONG_INF;
	}
	dp[0] = 0;
	REP(i,2LL * n) {
		REP(q, edges.size()) {
			long long a = get<0>(edges[q]);
			long long b = get<1>(edges[q]);
			long long c = get<2>(edges[q]);
			if (dp[b] < dp[a] + c) {
				dp[b] = dp[a] + c;
			}
		}
	}
	long long ans = dp[n-1];
	REP(i, 2LL * n) {
		REP(q, edges.size()) {
			long long a = get<0>(edges[q]);
			long long b = get<1>(edges[q]);
			long long c = get<2>(edges[q]);
			if (dp[b] < dp[a] + c) {
				dp[b] = dp[a] + c;
			}
		}
	}
	if (ans != dp[n - 1]) {
		cout << "-1" << endl;
	}
	else {
		cout << max(0LL,ans) << endl;
	}
}

Measured memory_bytes: 704