akhauriyash/Code-Regression huggingface dataset:
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: u32) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let mut n: u32 = read();

    print!("{}:", n);

    let mut i: u32 = 2;
    while n > 1 {
        if i * i > n {
            print!(" {}", n);
            break;
        } else if n % i == 0 {
            n /= i;
            print!(" {}", i);
        } else {
            i += 1;
        }
    }
    println!("");
}



Measured memory_bytes: 5020
import java.util.Scanner;
import java.util.Arrays;


class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    long H = sc.nextLong();

    int i = 0;
    for(i = 1;H > 1;i++){

      H = H/2;
    }


  /*  double N = 0;
    for(int n = 1;n <= i;n++){
      N += Math.pow(2, i-1)-1;
    }*/

  
  //  System.out.println(N);
    System.out.println((long)(Math.pow(2, i-1)+Math.pow(2, i-1)-1));
  }

}


Measured memory_bytes: 22100
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int A = in.nextInt();
            int B = in.nextInt();
            int K = in.nextInt();
            int[] a = new int[100];
            int k = 0;
            for (int n = 1; n <= 100; n++) {
                if (A % n == 0 && B % n == 0) {
                    a[k] = n;
                    k++;
                }
            }

            for (int i = 0; i < K; i++) {
                k--;
            }

//            Utils.debug(a, k, K);
            System.out.println(a[k]);
        }
    }
}


Measured memory_bytes: 21716
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <time.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000001
#define mod 1000000009
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)

int main()
{
    int n;
    long long t[100010],a[100010];
    long long kaku[100010];
    long long ans = 1;
    int flag = 0;
    cin >> n;
    for(int i = 0;i < n;i++){
        kaku[i] = -1;
    }
    for(int i = 0;i < n;i++){
        cin >> t[i];
        if(i == 0){
            kaku[i] = t[i];
        }
    }
    for(int i = 0;i < n;i++){
        cin >> a[i];
        if(i == n - 1){
            kaku[n - 1] = a[i];
        }
    }
    for(int i = 0;i < n; i++){
        if((t[n - 1] != a[0]) || (t[n - 1] < a[n - 1]) || (t[0] > a[0])){
            ans = 0;
            break;
        }
        if(kaku[i] == -1){
            if(t[i] - t[i - 1] != 0 && a[i] - a[i + 1] != 0){
                if(t[i] == a[i])kaku[i] = t[i];
                else ans = 0;
            }else if(t[i] - t[i - 1] != 0 && a[i] - a[i + 1] == 0){
                if(t[i] <= a[i])kaku[i] = t[i];
                else ans = 0;
            }else if(t[i] - t[i - 1] == 0 && a[i] - a[i + 1] != 0){
                if(a[i] <= t[i])kaku[i] = a[i];
                else ans = 0;
            }
        }
    }
    if(ans == 1){
        for(int i = 1;i < n - 1;i++){     
            if(kaku[i] == -1){
                if(t[i] <= a[i]){
                    ans *= t[i];
                }else if(t[i] > a[i]){
                    ans *= a[i];
                }
            }
           ans %= 1000000007; 
        }
        
    }
        
    cout << ans << endl;
}

Measured memory_bytes: 2560
N,Q = map(int,input().split())
S = input()
total = [0]*N

for i in range(1,N):
  if S[i] =="C" and S[i-1] == "A":
    total[i] = total[i-1] + 1
  else:
    total[i] = total[i-1]
for i in range(Q):
  r,l = map(int,input().split())
  print(total[l-1] -total[r-1])

Measured memory_bytes: 11436
#include <iostream>
#include <cstdio>

using namespace std;

int main(void) {
    int n, a[101];
    scanf("%d", &n);
    for(int i=n-1; i>=0; i--) {
        scanf("%d", &a[i]);
    }

    for(int i=0; i<n; i++){
        if(i) printf(" ");
        printf("%d", a[i]);
    }
    printf("\n");
}



Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる





int main() {
  ll r,c,d;
  cin>>r>>c>>d;

  vector<ll> a(r*c);
  vector<ll> b(r*c);
  rep(i,r){
    rep(j,c){
      ll x;
      cin>>x;
      x--;
      a[x]=i;
      b[x]=j;
    }
  }

  vector<ll> ans(r*c);
  rep(i,r*c){
    if(i<d) ans[i]=0;
    else {
      ans[i]=ans[i-d]+abs(a[i]-a[i-d])+abs(b[i]-b[i-d]);
    }
  }

  int z;
  cin>>z;
  rep(i,z){
    ll l,r;
    cin>>l>>r;
    l--;r--;
    cout << ans[r]-ans[l] << endl;
  }

}


Measured memory_bytes: 3200
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
s = ins()
q = inn()
kl = inl()
accd = [0]*(n+1)
accm = [0]*(n+1)
for i in range(n):
    accd[i] = accd[i-1] + (1 if s[i]=='D' else 0)
    accm[i] = accm[i-1] + (1 if s[i]=='M' else 0)
#ddprint(accd)
#ddprint(accm)
for k in kl:
    #ddprint(k)
    dm = 0
    dmc = 0
    for i in range(1,n):
        if i>=k and s[i-k]=='D':
            dm -= accm[i-1]-accm[i-k]
        if s[i]=='M':
            dm += accd[i-1]-accd[max(-1,i-k)]
        if s[i]=='C':
            dmc += dm
        #ddprint(f"{i=} {dm=} {dmc=}")
    print(dmc)


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

set<int> g[MAXN];
map<int, int> leafs;
set<int> pars;

void solve(){
	int n, a, b;
	scanf("%d", &n);
	REP(i, 1, n) {
		scanf("%d%d", &a, &b);
		g[a].insert(b);
		g[b].insert(a);
	}
	REPN(i, 1, n) {
		if (SZ(g[i]) == 1) {
			int par = *g[i].begin();
			if (leafs.find(par) != leafs.end()) {
				printf("First\n");
				return;
			}
			leafs[par] = i;
			if (SZ(g[par]) == 2) {
				pars.insert(par);
			}
		}
	}
	int cur_cnt = n;
	while(1) {
		if (cur_cnt == 1 || cur_cnt == 3) {
			printf("First\n");
			return;
		}
		if (cur_cnt == 2) {
			printf("Second\n");
			return;
		}
		cur_cnt -= 2;
		int par = *pars.begin();
		int leaf = leafs[par];
		
		leafs.erase(par);
		pars.erase(par);
		g[leaf].clear();
		g[par].erase(leaf);
		
		int parpar = *g[par].begin();
		g[par].clear();
		g[parpar].erase(par);
		
		if (SZ(g[parpar]) == 1) {
			int parparpar = *g[parpar].begin();
			if (leafs.find(parparpar) != leafs.end()) {
				printf("First\n");
				return;
			}
			leafs[parparpar] = parpar;
			if (SZ(g[parparpar]) == 2) {
				pars.insert(parparpar);
			}
		} else if (leafs.find(parpar) != leafs.end() && SZ(g[parpar]) == 2) {
			pars.insert(parpar);
		}
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

using namespace std;

const int N = 1000006;

int n, m, k;
vector<vector<char>> mat;
vector<vector<int>> dist;

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

void bfs(int x1, int y1, int x2, int y2) {
	dist.assign(n, vector<int>(m, -1));
	vector<vector<vector<bool>>> vis(n, vector<vector<bool>>(m, vector<bool>(4, false)));
	dist[x1][y1] = 0;
	vector<pair<int, int>> q;
	q.emplace_back(x1, y1);
	while(!q.empty()) {
		vector<pair<int, int>> next_q;
		for(int i = 0; i < 4; i++) {
			if(i == 0) {
				sort(q.begin(), q.end(), [](pair<int, int> a, pair<int, int> b) {
					return a.first < b.first;		
				});
			}
			else if(i == 1) {
				sort(q.begin(), q.end(), [](pair<int, int> a, pair<int, int> b) {
					return a.first > b.first;		
				});
			}
			else if(i == 2) {
				sort(q.begin(), q.end(), [](pair<int, int> a, pair<int, int> b) {
					return a.second > b.second;		
				});
			}
			else if(i == 3) {
				sort(q.begin(), q.end(), [](pair<int, int> a, pair<int, int> b) {
					return a.second < b.second;		
				});
			}

			for(auto p : q) {
				int x, y;
				tie(x, y) = p;
				for(int val = 1; val <= k; val++) {
					int nx = x + val * dx[i], ny = y + val * dy[i];
					if(nx < 0 or nx >= n or ny < 0 or ny >= m) continue;
					if(mat[nx][ny] == '@') break;
					if(vis[nx][ny][i]) break;
					vis[nx][ny][i] = 1;
					if(dist[nx][ny] == -1) {
						dist[nx][ny] = dist[x][y] + 1;
						next_q.emplace_back(nx, ny);
					}
				}
			}
		}
		q = next_q;
	}
}

int main() {
	scanf("%d %d %d", &n, &m, &k);
	int x1, y1, x2, y2;
	scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
	mat.assign(n, vector<char>(m));

	for(int i = 0; i < n; i++) for(int j = 0; j < m; j++)
		scanf(" %c", &mat[i][j]);

	x1--, y1--, x2--, y2--;
	bfs(x1, y1, x2, y2);

	printf("%d\n", dist[x2][y2]);
}


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

using namespace std;

using int64 = long long;
const int64 INF = 1LL << 60;

int main()
{
  int K, A[100000];

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

  int64 large = 2, small = 2;
  for(int i = K - 1; i >= 0; i--) {
    small = (small + A[i] - 1) / A[i] * A[i];
    large = large / A[i] * A[i];
    large += A[i] - 1;
    if(small > large) {
      cout << -1 << endl;
      return (0);
    }
  }

  cout << small << " " << large << endl;
}


Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class DMegalomania {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            DMegalomania.Job[] jobs = new DMegalomania.Job[n];
            for (int i = 0; i < n; i++) {
                jobs[i] = new DMegalomania.Job(in.nextInt(), in.nextInt());
            }

            Arrays.sort(jobs, Comparator.comparingInt(j -> j.deadline));

            boolean answer = true;
            long curTime = 0;
            for (int i = 0; i < n; i++) {
                curTime += jobs[i].time;
                answer &= (curTime <= jobs[i].deadline);
            }

            out.println(answer ? "Yes" : "No");
        }

        private static class Job {
            final int time;
            final int deadline;

            private Job(int time, int deadline) {
                this.time = time;
                this.deadline = deadline;
            }

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 53504
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int main() {


	int D;
	scanf("%d", &D);

	if (D == 25)printf("Christmas");
	else if (D == 24)printf("Christmas Eve");
	else if (D == 23)printf("Christmas Eve Eve");
	else printf("Christmas Eve Eve Eve");


}

Measured memory_bytes: 128
#include <cstdio>

int main(int argc, const char * argv[]) {
   
    int n;
    int ans = 0;
    scanf("%d",&n);
    
    for(int i=0,tmp;i<n;i++){
        scanf("%d",&tmp);
        if( !(tmp&1)){
            
            while(tmp%2==0){
                ans++;
                tmp/=2;
            }
        }
    }
    printf("%d\n",ans);
    
    return 0;
}


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

int main() {
	int n;cin >> n;
	bool ans = 0;
	if(n == 3)ans = 1;
	if(n == 5)ans = 1;
	if(n == 7)ans = 1;
	if(ans)cout << "YES";
	else cout << "NO";
	return 0;
}

Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
const int MAX_N = 400;
int dp[MAX_N][MAX_N];
int N;
int A[MAX_N];
int S[MAX_N + 1];

int rec(int i, int j) {
    if (i >= j) return 0;
    if (dp[i][j] >= 0) return dp[i][j];
    if (i + 1 == j) return dp[i][j] =  A[i] + A[j];

    int ret = 0 + rec(i+1, j) + S[j+1] - S[i];
    ret = min(ret, rec(i, j-1) + 0 + S[j+1] - S[i]);
    for (int right = i + 1; right < j - 1; right++) ret = min(ret, rec(i, right) + rec(right + 1, j) + S[j+1] - S[i]);

    return dp[i][j] = ret;
}

signed main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        S[i+1] = S[i] + A[i];
    }
    fill(dp[0], dp[N], -1);
    cout << rec(0, N - 1) << endl;
    return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> x(M), y(M);
  rep(i, M) {
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
  }
  vector<int> num(N, 1);
  vector<bool> red(N);
  red[0] = true;
  rep(i, M) {
    if(red[x[i]]) {
      if(num[x[i]] == 1)
        red[x[i]] = false;
      red[y[i]] = true;
    }
    num[x[i]]--;
    num[y[i]]++;
  }
  int ans = 0;
  rep(i, N) {
    if(red[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include <utility>
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    typedef std::pair<long, int> pair;
    std::vector<pair> pairs;
    for (int i = 0; i < N; i++){
        int a, b;
        cin >> a >> b;
        pairs.push_back(pair(a, b));
    }
    sort(pairs.begin(), pairs.end());
    
    long total_yen = 0;
    int total_hon = 0;
    for (auto& itr: pairs){
        total_yen += itr.first * itr.second;
        total_hon += itr.second;
        if (total_hon > M){
            total_yen -= itr.first * (total_hon - M);
            break;
        }
    }
    cout << total_yen << endl;
    /*
    for (auto& itr: pairs){
        cout << itr.first << "," << itr.second << endl;
    }
    */
    return 0;
}

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

int dp[200];
vector<pair<int, int>> m;

int main()
{
  while(true)
  {
    fill(dp, dp + 200, -1);
    m.clear();

    for(int i = 0; i < 2; i++)
    {
      int a;
      cin >> a;
      if(!a)
        return 0;
      for(int j = 0; j < a; j++)
      {
        int x, y;
        cin >> x >> y;
        m.push_back(make_pair(x, y));
      } 
    }
    sort(m.begin(), m.end());
    int ans = 0;
    for(int i = 0; i < m.size(); i++)
    {
      dp[i] = 1;
      for(int j = 0; j < i; j++)
        if(m[j].first < m[i].first && m[j].second < m[i].second)
          dp[i] = max(dp[i], dp[j] + 1);
      ans = max(ans, dp[i]);
    }
    cout << ans << endl;;
  }
}

Measured memory_bytes: 1204
// LNU_Algotesters
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <fstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;


const int MAX = 100 * 1000 + 47;

vector<PII> G[MAX];
int U[MAX];
int C[MAX];
int E, V;
LL X[3];

bool DFS(int v, int c)
{
    U[v] = 1;
    V++;
    E += SZ(G[v]);
    X[c]++;
    C[v] = c;
    bool ok = 1;
    FOR(i, 0, SZ(G[v]))
    {
        int to = G[v][i].first;
        int nc = (c + G[v][i].second + 1) % 3;
        
        if (U[to])
        {
            if (nc != C[to])ok = 0;
            continue;
        }
        
        if (!DFS(to, nc))ok = 0;
    }
    return ok;
}

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    FOR(i, 0, m)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        --x, --y;
        G[x].PB(MP(y, 0));
        G[y].PB(MP(x, 1));
    }
    LL ans = 0;
    FOR(i, 0, n)
    {
        if (U[i]) continue;
        E = V = 0;
        X[0] = X[1] = X[2] = 0;
        if(!DFS(i, 0))
        {
            ans += V * 1LL * V;
        }
        else if (X[0] == 0 || X[1] == 0 || X[2] == 0)
        {
            ans += E / 2;
        }
        else
        {
            ans += X[0] * X[1] + X[1] * X[2] + X[0] * X[2];
        }
    }
    printf("%lld", ans);
   

}



Measured memory_bytes: 12800
import math

A, B, H, M = [int(i) for i in input().split(' ')]


theta1 = 360.0/12.0*H + 360.0/12.0/60.0*M
theta2 = 360.0/60.0*M

theta = abs(theta1-theta2)

c = A**2 + B**2 - 2.0*A*B*math.cos(math.radians(theta))

print(math.sqrt(c))


Measured memory_bytes: 62632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const int INF=1000000000;
const int MOD=1000000007;

int main()
{
 int x, y, z;
 cin >> x >> y >> z;
 cout << z <<" " << x << " " << y;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int maxring(int x, int y, int z);

int main(void)
{
    int a, b, c;
    int max;

    scanf("%d %d %d", &a, &b, &c);
    max = maxring(a, b, c);
    printf("%d", a + b + c - max);

    return 0;
}

int maxring(int x, int y, int z)
{
    int max = x;

    if (y > max)
        max = y;
    if (z > max)
        max = z;

    return max;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  for (int i=0; i<s.size(); i++)
    if (s[i]=='7')
    {
      cout<<"Yes"<<endl;
      return 0;
    }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3628
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		String s = sc.next();

		char[] c = s.toCharArray();
		int[] a = new int[c.length];

		for (int i = 0; i < c.length; i++)
			a[i] = 1;

		for (int i = c.length - 1; i >= 2; i--) {
			if (c[i] == 'L' && c[i - 1] == 'L' && c[i - 2] == 'L') {
				a[i-2] += a[i];
				a[i] = 0;
			}
		}

		for (int i = 0; i < c.length - 2; i++) {

			if (c[i] == 'R' && c[i + 1] == 'R' && c[i + 2] == 'R') {
				a[i + 2] += a[i];
				a[i] = 0;
			} else if (c[i] == 'R' && c[i + 1] == 'R' && c[i + 2] == 'L') {
				a[i + 2] += a[i];
				a[i] = 0;
			}

			else if (c[i] == 'R' && c[i + 1] == 'L' && c[i + 2] == 'L') {
				a[i] += a[i + 2];
				a[i + 2] = 0;
			}

		}

		for (int i = 0; i < c.length; i++)
			System.out.print(a[i] + " ");

	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 43988
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

ll modpow(ll r,ll n,ll m=MOD){
  ll re=1,d=r%m;
  if(n<0)(n%=MOD-1)+=MOD-1;
  for(;n;n/=2){
    if(n&1)(re*=d)%=m;
    (d*=d)%=m;
  }
  return re;
}
vector<ll> fact,finv,inv;
ll comb(ll n,ll r){
  if(n<r||r<0)return 0;
  return fact[n]*finv[n-r]%MOD*finv[r]%MOD;
}
class Doralion{
  void Modinvs(vector<ll> &re,int n){
    re.resize(n+1); re[1]=1;
    for(int i=2;i<=n;++i)re[i]=re[MOD%i]*(MOD-MOD/i)%MOD;
  }
  void Facts(vector<ll> &re,int n){
    re.resize(n+1); re[0]=1;
    rep(i,n)re[i+1]=re[i]*(i+1)%MOD;
  }
  void Factinvs(vector<ll> &re,const vector<ll> &inv,int n){
    re.resize(n+1); re[0]=1;
    rep(i,n)re[i+1]=re[i]*inv[i+1]%MOD;
  }
public:
  Doralion(int n){
    Modinvs(inv,n);
    Facts(fact,n);
    Factinvs(finv,inv,n);
  }
} doralion(1123456);

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n,m,t;
  cin>>n>>m>>t;
  ll re=0,pw=modpow(3,m+t),sum=1;
  rep(i,m+t+1){
    (re+=pw*comb(n-1+i,i)%MOD*sum%MOD)%=MOD;
    //cout<<pw<<","<<comb(n-1+i,i)<<","<<sum<<endl;
    (pw*=inv[3])%=MOD;
    (sum*=2)%=MOD;
    if(t<=i) (sum+=MOD-comb(i,i-t))%=MOD;
    if(m<=i) (sum+=MOD-comb(i,i-m))%=MOD;
  }
  //rep(i,m+1)rep(j,t+1) (re+=comb(n-1+i+j,i)*comb(n-1+j,j)%MOD*modpow(3,m+t-i-j)%MOD)%=MOD;
  cout<<re<<endl;
  return 0;
}


Measured memory_bytes: 26624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0, x = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'I') x++;
    else x--;
    ans = max(ans, x);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define SORT(v, n) sort(v, v+n)
#define VREV(v,n) reverse(v,v+n)
#define REV(v,n) reverse(v,v+n)
#define vi vector<int>
#define pf push_front
#define pb push_back
#define P pair<int,int>
#define Pll pair<ll,ll>

template<class T, size_t N> size_t countof(const T (&array)[N]) { return N; }
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

void mprint(auto *matrix,auto N){
	REP(i,N) cout<<matrix[i]<<(i!=N-1?' ':'\n');
	return;
}


const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18; //(+1までok)
const long MOD =1e+9+7;
#define PI 3.14159265258979

#define iP pair<int,P>
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

inline int in(){int x; cin>>x; return x;}

int H,W;

int main(void){
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	char D[52][52];
	int cn=0,d[52][52];
	priority_queue<iP,vector<iP>,greater<iP>> qe;

	
	cin>>H>>W;
	REP(i,H+2){
		REP(j,W+2){
			if(i==0||i==H+1||j==0||j==W+1) D[i][j]='B';
			else cin>>D[i][j];
		if(D[i][j]=='#') cn++;
		d[i][j]=-1;
		}
	}
	
	qe.push(iP(1,P(1,1)));

	while(!qe.empty()){
		int cost=qe.top().first;
		int x=qe.top().second.first,y=qe.top().second.second;
		qe.pop();
		if(d[x][y]!=-1) continue;
		d[x][y]=cost;

		if(x==H&&y==W){
			print(H*W-cost-cn);
			//REP(i,H+2) mprint(d[i],W+2);
			return 0;
		}else{
			REP(i,4){
				int nx=x+dx[i],ny=y+dy[i];
				if(D[nx][ny]=='.') qe.push(iP(cost+1,P(nx,ny)));
			}
		}
	}
	print(-1);
	//REP(i,H+2) mprint(d[i],W+2);
	return 0;
}





Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline

def MST(n, E):
    def par(m):
        if UF[m] == m:
            return m
        ret = par(UF[m])
        UF[m] = ret
        return ret
    
    UF = [i for i in range(n)]
    E = sorted(E, key=lambda x: x[2])
    ans = 0
    for i, j, d in E:
        if par(i) != par(j):
            ans += d
            UF[par(i)] = par(j)
    return ans

N = int(input())

X = []
for i in range(N):
    x, y = map(int, input().split())
    X.append((i, x, y))

F = []
Y = sorted(X, key = lambda x: x[1])
for i in range(len(Y)-1):
    F.append((Y[i][0], Y[i+1][0], abs(Y[i+1][1]-Y[i][1])))

Y = sorted(X, key = lambda x: x[2])
for i in range(len(Y)-1):
    F.append((Y[i][0], Y[i+1][0], abs(Y[i+1][2]-Y[i][2])))

print(MST(N, F))


Measured memory_bytes: 147400
#include <iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
#define loop(i,n) for(int i = 0; i < (n); i++)
#define loops(i,f,n) for(int i = (f); i < (n); i++)
#define INF 1e9
int main()
{
    vector<int> v;
    int t;
    while(cin>>t)
    {
        if(t==0)break;
    v.push_back(t);
    }
    loop(i,v.size())cout<<"Case "<<i+1<<": "<<v[i]<<endl;
}


Measured memory_bytes: 3268
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int num = n;
        int index = 1;
        while (n > 0) {
            n -= index;
            index++;
        }
        index--;
        int tmp = 0;
        for (int i = index; i > 0; i--) {
            tmp += index;
            if (tmp > num) {
                tmp -= index;
                index--;
                continue;
            }
            System.out.println(index);
            if (tmp == num) {
                break;
            }
            index--;
        }
    }
}


Measured memory_bytes: 23124
from itertools import permutations
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
comb = sorted(list(permutations([i for i in range(1, N+1)], N)))
print(abs((comb.index(P) + 1) - (comb.index(Q) + 1)))

Measured memory_bytes: 8308
#include<cstdio>
#include<cstring>
#include<iostream>
#define mod 1000000007
using namespace std;
struct Edge{
	int to;
	int nxt;
	int head;
};
Edge edge[10005];
int n,ed=1,x,y,sz[5005];
long long dp[5005][5005],fact[5005],ans,p[5005];
inline void add_edge(int u,int v){
	edge[ed].to=v;
	edge[ed].nxt=edge[u].head;
	edge[u].head=ed;
	ed++;
}
inline int read(){
	int ans=0,f=1;
	char in=getchar();
	while(!(in>='0'&&in<='9')){
		if(in=='-'){
			f=!f;
		}
		in=getchar();
	}
	while(in>='0'&&in<='9'){
		ans=(ans<<1)+(ans<<3)+(in^'0');
		in=getchar();
	}
	return ans*f;
}
inline void dfs(int now,int father){
	dp[now][1]=1;sz[now]=1;
	int tmp=edge[now].head;
	while(tmp>0){
		int son=edge[tmp].to;
		if(son==father){
			tmp=edge[tmp].nxt;
			continue;
		}
		dfs(son,now);
		sz[now]+=sz[son];
		for(register int i=1;i<=sz[now];i++){
			p[i]=0;
		}
		for(register int i=1;i<=sz[now]-sz[son];i++){
			for(register int j=1;j<=sz[son];j++){
				p[i]-=(dp[now][i]*dp[son][j]%mod*fact[j]);p[i]%=mod;
				p[i+j]+=(dp[now][i]*dp[son][j]);p[i+j]%=mod;
			}
		}
		for(register int i=1;i<=sz[now];i++){
			dp[now][i]=p[i];
		}
		tmp=edge[tmp].nxt;
	}
}
int main(){
	scanf("%d",&n);
	for(register int i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		add_edge(x,y);
		add_edge(y,x);
	}
	fact[0]=1;
	for(register int i=2;i<=n;i++){
		fact[i]=fact[i-2]*(i-1);fact[i]%=mod;
	}
	dfs(1,-1);
	for(register int i=2;i<=n;i+=2){
		ans+=(dp[1][i]*fact[i]);
		ans%=mod;
	}
	ans+=mod;ans%=mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 92584
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		   int n;
           cin>>n;
           int ans=-1;
            int g=0;
           rep(i,1,n+1){
             int cnt=0;
             int c=i;
            
             while(c%2==0&&c>0){
               c/=2;
               cnt++;
             }
             if(chmax(ans,cnt)){
               g=i;
             }
           }
           cout<<g<<endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
int main()
{
    // 整数の入力
	string s;
    
    cin >> s;
    if(s=="Sunny"){
        cout << "Cloudy" << endl;
    }else if(s=="Cloudy"){
         cout << "Rainy" << endl;
    }else {
         cout << "Sunny" << endl;
    }
   
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,x,s;
	while(scanf("%d %d",&a,&b)!=EOF){
		x=a+b;
		s=0;
		while(0<x){
			s++;
			x=x/10;
		}
		printf("%d\n",s);
	}

	return 0;
}

Measured memory_bytes: 1760
import math

lines = int(input())
score_list = []
for line in range(lines):
    score_list.append(int(input()))
answer = sum(score_list)
if answer % 10 == 0:
    score_list.sort()
    for score in score_list:
        if score % 10 != 0:
            answer -= score
            break
    if answer % 10 == 0:
        answer = 0
print(answer)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
 
 
void solve(){
    string s1,s2;
    cin>>s1>>s2;
    if(s1[0]==s2[2]&&s1[1]==s2[1]&&s1[2]==s2[0]){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}
 
int main(){
	solve();
}

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

int main(int argc, char *args[])
{
    char s[10];
    scanf("%s", s);
    //文字列の長さを調べる
    int n;
    n = strlen(s);
    int ans = 0;
    int cnt = 0;
    for(int i=0;i < n;i++){
        if(s[i] == 'A' || s[i] == 'C' ||s[i] == 'G' ||s[i] == 'T' ){
            cnt++;
        }
        else{
            cnt = 0;
        }
        if(ans < cnt){
            ans = cnt;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1712
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include <cstdint>
#include <boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<ll>t(n), a(n);
	rep(i, n) {
		cin >> t[i] >> a[i];
	}
	ll takahashi = t[0];
	ll aoki = a[0];
	rep(i, n-1) {
		ll tmp = 1;
		ll j = 1;
		ll k = 1;
		if (takahashi <= t[i]) {
			takahashi = t[i];
		}
		else {
			if (takahashi%t[i] == 0) {
				j = takahashi / t[i];
			}
			else {
				j = takahashi / t[i] + 1;
			}
		}
		if (aoki <= a[i]) {
		    aoki = a[i];
		}
		else {
			if (aoki%a[i] == 0) {
				k = aoki / a[i];
			}
			else {
				k = aoki / a[i] + 1;
			}
		}
		tmp = max(j, k);
		if (tmp > 1) {
			takahashi = t[i] * tmp;
			aoki = a[i] * tmp;
		}
	}
	ll takamin = takahashi;
	ll aomin = aoki;
	if (takahashi %t[n - 1] != 0) {
		takahashi = (takahashi / t[n - 1] + 1)*t[n-1];
	}
	takahashi /= t[n - 1];
	if (aoki%a[n - 1] != 0) {
		aoki = (aoki / a[n - 1] + 1)*a[n - 1];
	}
	aoki /= a[n - 1];
	ll ans = min(takahashi, aoki);
	if (!(ans*t[n - 1] >= takamin&&ans*a[n - 1] >= aomin) ){
		ans = max(takahashi, aoki);
	}
	ans *= (t[n - 1]+a[n - 1]);
	cout << ans << endl;
	
	
}


Measured memory_bytes: 256
// #define USE_CPP11
// #define USE_PRINTF

#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <utility>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <complex>
#include <memory>
#include <sstream>

#ifdef USE_CPP11
#include <unordered_map>
#include <unordered_set>
#include <functional>
#endif

#define PRINT(obj) cout << obj << endl
#define REP(i, n) for(int (i) = 0; (i) < (n); i++)
#define REV(s) (string((s).rbegin(), (s).rend()))
#define SPACE " "

typedef long long ll;

using namespace std;

namespace Scanner {
#ifdef USE_PRINTF
  int    nextInt()    { int    d; scanf("%d" , &d); return d; }
  float  nextFloat()  { float  f; scanf("%f" , &f); return f; }
  double nextDouble() { double f; scanf("%lf", &f); return f; }  
  string nextString() { string s; scanf("%s" , &s); return s; }
  ll     nextll()     { ll     l; scanf("%ll", &l); return l; }
#else
  int    nextInt()    { int    d; cin >> d; return d; }
  float  nextFloat()  { float  f; cin >> f; return f; }
  double nextDouble() { double f; cin >> f; return f; }  
  string nextString() { string s; cin >> s; return s; }
  ll     nextll()     { ll     l; cin >> l; return l; }
#endif

  string getLine() { 
    string input;
    getline(cin, input);
    return input;
  }
};

namespace myLibrary {
  vector<string> split(const string& str, char delim) {
    vector<string> ret;
    size_t current = 0, found;
    while ((found = str.find_first_of(delim, current)) != string::npos) {
      ret.push_back(string(str, current, found - current));
      current = found + 1;
    }
    ret.push_back(string(str, current, str.size() - current));
    return ret;
  }
  
#ifdef USE_CPP11
  ///
  /// higher-order functional
  /// This is like map in haskell, python, etc.
  /// Sample usage:
  ///   vector<int> a = {1, 2, 3, 4, 5};
  ///   vector<int> b = myLibrary::_Map<int, int>(a, [](int n){
  ///     return n * n;
  ///   });
  /// Result:
  ///   b = 1, 4, 9, 16, 25
  ///
  template<typename T_IN, typename T_OUT, class Functor>
  vector<T_OUT> _Map(vector<T_IN> src, Functor func) {
    vector<T_OUT> ret;
    for (int i = 0; i < src.size(); i++) {
      ret.push_back(func(src[i]));
    }
    return ret;
  }
#endif

};


/// BEGIN //////////////////////////////////////////////////////////

int main() {
  int n = Scanner::nextInt();
  while (n--) {
    string input = Scanner::nextString();
    set<string> s;
    for (int i = 1; i < input.size(); i++) {
      string n1 = input.substr(0, i);
      string n2 = input.substr(i);
      
      REP(j, 2) {
        s.insert(n1 + n2);
        s.insert(REV(n1) + n2);
        s.insert(n1 + REV(n2));
        s.insert(REV(n1) + REV(n2));
        swap(n1, n2);
      }
    }
    cout << s.size() << endl;
  }
  return 0;
}

/// END   //////////////////////////////////////////////////////////

Measured memory_bytes: 1296
package main

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

var sc *bufio.Scanner

const BufferSize = 1024

func nextInt() int {
	if !sc.Scan() {
		panic(nil)
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	a := make([]int, 3)
	a[0] = nextInt()
	a[1] = nextInt()
	a[2] = nextInt()
	sort.Ints(a)
	sum := a[0] + a[1]

	_, _ = fmt.Fprintf(writer, "%d", sum)
}

func main() {
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

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

int main(){
    string s;
    cin >> s;
    if(s=="AAA"||s=="BBB"){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 888
import numpy as np

N, M = map(int, input().split())
S = np.array(list(map(int, input().split())))
T = np.array(list(map(int, input().split())))
MOD = 10 ** 9 + 7

neq = (S[:, None] != T[None, :])
dp = np.ones(M + 1, dtype=np.int64)
for i in range(N):
    new_dp = dp.copy()
    new_dp[1:] -= dp[:-1] * neq[i]
    np.cumsum(new_dp, out=new_dp)
    dp = new_dp % MOD
print(dp[M])


Measured memory_bytes: 16460
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    int a,b;
    string s;
    cin >> a >> b >> s;
    rep(i,s.length()){
        if(i == a && s[i] != '-'){
            cout << "No\n";
            return 0;
        }else if(i != a && s[i] == '-'){
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

int main() {
    char ca, cb, cc, cd;
    cin >> ca >> cb >> cc >> cd;

    int a = ca - '0';
    int b = cb - '0';
    int c = cc - '0';
    int d = cd - '0';

    int op = 0;

    while (1) {
        int ans = a;

        if (op & 0b100) {
            ans += b;
        } else {
            ans -= b;
        }

        if (op & 0b010) {
            ans += c;
        } else {
            ans -= c;
        }

        if (op & 0b001) {
            ans += d;
        } else {
            ans -= d;
        }

        if (ans == 7) {
            cout << a;
            cout << (op & 0b100 ? '+' : '-');
            cout << b;
            cout << (op & 0b010 ? '+' : '-');
            cout << c;
            cout << (op & 0b001 ? '+' : '-');
            cout << d << "=7" << endl;

            return 0;
        }
        op++;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>

using namespace std;

long long N,i,j,k,ans;

char S[10];

int main()
{
  cin >>N;
  
  for(i=1;i<=N;i++)
  {
    if(i%3!=0 && i%5!=0) ans+=i;
  }
  
  cout <<ans;
  
  
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  int* P = new int[N];
  for (int i = 0; i < N; i++)
    cin >> P[i];
  sort(P, P + N);
  int ans = 0;
  for (int i = 0; i < K; i++)
    ans += P[i];
  cout << ans;
}


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

int main(){
    int n;
    cin>>n;
    vector<int>nan(n);
    for(int i=0;i<n;i++){
        cin>>nan.at(i);
    }
    
    long int ans=1000000;
    for(int i=0;i<n;i++){
        long int minta=0;
        long int maxta=0;
        for(int k=0;k<=i;k++){
            minta+=nan.at(k);
         
        }
        for(int h=i+1;h<n;h++){
            maxta+=nan.at(h);

        }
        long int h=abs(maxta-minta);
        ans=min(ans,h);


    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <fstream>

using namespace std;

int main(void)
{
	int a, b, c, d;

	cin >> a >> b >> c >> d;

	a = max(a, c);
	b = min(b, d);

	if (a >= b)
	{
		cout << "0" << endl;
	}
	else
	{
		cout << b - a << endl;
	}

	return 0;
}

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

int main() {
	ll n; cin >> n;
	ll d = 1;
	for (ll i = 0;; i++) {
		if (d - 1 >= n) { cout << i << endl; return 0; }
		d <<= 1;
	}
}

Measured memory_bytes: 3096
n = gets.to_i
nums = []
n.times {
    nums.push( gets.to_i )
}

cnt = n
nums.each { |val|
	if 2 == val
		next
	end
	if 0 == val%2
		cnt-=1
		next
	end
	last = Math.sqrt(val);
	3.step( last, 2 ) { |j|
		if 0 == val%j
			cnt-=1
			break
		end
	}
}

puts( cnt )

Measured memory_bytes: 8984