akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;


public class Main 
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		int total = 0;
		float sum = 0;
		int kind = 0;
		for(; scanner.hasNext(); kind++)
		{
			String in = scanner.next();
			String[] w = in.split(",");
			
			total += Integer.parseInt(w[0]) * Integer.parseInt(w[1]);
			sum += Integer.parseInt(w[1]);
		}
		System.out.println(total);
		System.out.println(String.format("%1$d", (int)(sum/kind+0.5)));
	}
}

Measured memory_bytes: 26212
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from bisect import bisect_left

def find_left_right(lis: list, pos: int):
    left_idx = bisect_left(lis, pos) - 1
    left = lis[left_idx]
    right = lis[left_idx+1]
    return left, right

def find_min(sh_l, sh_r, tm_l, tm_r, x):
    ret = 10**18
    ret = min(ret, max(x-sh_l, x-tm_l))
    ret = min(ret, (tm_r - sh_l + min(x-sh_l, tm_r-x)))
    ret = min(ret, (sh_r - tm_l + min(x-tm_l, sh_r-x)))
    ret = min(ret, max(sh_r-x, tm_r-x))

    return ret

a,b,q = li()
INF = 10**18
s = [-INF] + [ni() for _ in range(a)] + [INF]
t = [-INF] + [ni() for _ in range(b)] + [INF]
x = [ni() for _ in range(q)]

for xi in x:
    shrine_left, shrine_right = find_left_right(s, xi)
    temple_left, temple_right = find_left_right(t, xi)
    print(find_min(shrine_left, shrine_right, temple_left, temple_right, xi))


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  while (1) {
    int N, W; cin >> N >> W;
    if (N == 0 and W == 0) break;
    vector<int> value(N);
    REP(i, N) cin >> value[i];
    int max_v = *max_element(ALL(value));
    int cnt_len = max_v / W + 1;
    vector<int> counter(cnt_len, 0);
    for (int v : value) {
      REP(i, cnt_len) {
        if (v < (i+1) * W) {
          counter[i]++;
          break;
        }
      }
    }
    int M = *max_element(ALL(counter));
    double ans = 0.0;
    REP(i, cnt_len) ans += 1.0  * (cnt_len-1 - i) /  (cnt_len-1) * counter[i] / M;
    cout << setprecision(20) << ans + 0.01 << endl;
  }
  return 0;
}

Measured memory_bytes: 3272
import itertools
import math
import fractions
import functools
import copy
n, m = map(int, input().split())
lr = []
for i in range(m):
    l, r = map(int, input().split())
    lr.append([l,r])

result = list(range(lr[0][0],lr[0][1]+1))


maximum = lr[0][1]
minimum = lr[0][0]
for i in range(len(lr)):
    maximum = min(maximum,lr[i][1])
    minimum = max(minimum,lr[i][0])

if maximum < minimum:
    print(0)
else:
    print(maximum-minimum+1)

Measured memory_bytes: 84692
//h16-2 スタンプラリー2(解き直し)
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#include <boost/multiprecision/cpp_int.hpp>
namespace boost_multiprecision = boost::multiprecision;
#define LL long long
#define CINT boost_multiprecision::cpp_int
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775807
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while (true)

int N;
string S;

vector<int> J;
vector<int> O;
vector<int> I;

int main(){

    cin >> N >> S;

    for(int i=0; i<N; i++){
        if(S[i] == 'J'){
            J.push_back(i);
        }
        if(S[i] == 'O'){
            O.push_back(i);
        }
        if(S[i] == 'I'){
            I.push_back(i);
        }
    }

    LL sum = 0;
    for(int i=0; i<O.size(); i++){
        auto itr = lower_bound(J.begin(), J.end(), O[i]);
        int a = itr - J.begin();
        auto itr2 = lower_bound(I.begin(), I.end(), O[i]);
        int b = itr2 - I.begin();
        b = I.size() - b;
        sum += a * b;
    }

    LL ans = 0;

    //O
    for(int i=0; i<N+1; i++){
        auto itr = lower_bound(J.begin(), J.end(), i);
        int a = itr - J.begin();
        auto itr2 = lower_bound(I.begin(), I.end(), i);
        int b = itr2 - I.begin();
        b = I.size() - b;
        ans = max(ans, sum + a*b);
        //cout << sum + a*b << endl;
    }

    //J
    LL tmp = 0;
    J.insert(J.begin(), -1);
    for(int i=0; i<O.size(); i++){
        auto itr = lower_bound(J.begin(), J.end(), O[i]);
        int a = itr - J.begin();
        auto itr2 = lower_bound(I.begin(), I.end(), O[i]);
        int b = itr2 - I.begin();
        b = I.size() - b;
        tmp += a * b;
    }
    J.erase(J.begin());
    ans = max(ans,tmp);
    //cout << tmp << endl;

    //I
    tmp = 0;
    I.push_back(N);
    for(int i=0; i<O.size(); i++){
        auto itr = lower_bound(J.begin(), J.end(), O[i]);
        int a = itr - J.begin();
        auto itr2 = lower_bound(I.begin(), I.end(), O[i]);
        int b = itr2 - I.begin();
        b = I.size() - b;
        tmp += a * b;
    }
    ans = max(ans,tmp);
    //cout << tmp << endl;

    cout << ans << endl;

    return 0;
}


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

using namespace std;

#define MAX_NUM 200000

struct Info{
  int latest;
  int len;
  int axis; // latestの座標

  Info(int inputted_len, int inputted_axis){
    latest = 1; // 追加される時点で1
    len = inputted_len;
    axis = inputted_axis;
  }

  bool operator<(const Info &another) const
  {
    return len < another.len;//年齢を比較
  };
};
  

int tbl[MAX_NUM] = {0};

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

  vector <int> a;
  int tmp;
  bool onenone = true;
  int zero_ptr = 0;
  for(int i = 0; i < n; i++){
    cin >> tmp;
    if(tmp == 1) onenone =false;
    --tmp;
    a.push_back(tmp);
  }

  if(onenone == true){
    cout << -1 << endl;
    return 0;
  }

  int latest = 0;
  int latest_ptr = 0;
  int len = 0;
  for(int i = 0; i < n; i++){
    if(a[i] == 0){
      zero_ptr = i;
      len = i;
      break;
    }
  }
  latest_ptr = zero_ptr;
  for(int i = zero_ptr + 1; i < n; i++){
    if(a[i] == latest + 1){
      len += i - latest_ptr - 1;
      latest_ptr = i;
      ++latest;
    }
  }

  len += n - 1 - latest_ptr;
  cout << len << endl;
  
  return 0;
}
  


Measured memory_bytes: 1400
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		
		if (A > C || A + B < C) {
			System.out.println("NO");
		} else {
			System.out.println("YES");
		}
		
	}
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define rep(i, n) rep2(i, 0, n)
using ll = long long;
using V = vector<int>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
const int MOD  = int(1e9)+7;


int main() {
  int n; cin >> n;
  V a(n);
  rep(i, n) cin >> a[i];

  int k = 0;
  ll ans = 1;
  rep(i, n) {
    int x = 2*(i-k) + 1;
    if (a[i] < x) {
      ans *= i-k+1;
      if (ans > MOD) ans %= MOD;
      ++k;
    }
  }
  rep(i, n-k) {
    ans *= i+1;
    if (ans > MOD) ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;

bool isPrime(int X)
{
    int c = 0,k=sqrt(X)+1;
    rep2(i, 2, k)
    {
        while(X%i==0)
        {
            X /= i;
            c++;
        }
    }

    return (c==0);
}

int main()
{
    int X,ans=0;
    cin >> X;
    rep2(i, X, 100004)
    {
        if(isPrime(i))
        {
            ans = i;
            break;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
int main(){
	int n=0,c=0,r=0;
	std::cin>>n;
	int a[n];
	for(int x=0;x<n;x++)
		std::cin>>a[x];
	while(1){
		for(int x=0;x<n;x++){
			if(a[x]%2==0){
				a[x]/=2;
				c++;
			}
			else break;
		}
		if(c==n){
			r++;
			c=0;
		}
		else break;
	}
	std::cout<<r<<std::endl;
	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

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

    priority_queue<int> left;
    priority_queue<int, vector<int>, greater<int>> right;

    int Q;
    cin >> Q;

    ll sum_b = 0, sum_left = 0, sum_right = 0;
    for (int i = 0, type, a, b; i < Q; ++i) {
        cin >> type;
        if (type == 1) {
            cin >> a >> b;

            sum_b += b;
            if (left.empty() || a <= left.top()) {
                left.push(a);
                sum_left += a;
                if (left.size() > right.size() + 1) {
                    sum_left -= left.top();
                    sum_right += left.top();
                    right.push(left.top());
                    left.pop();
                }
            }
            else {
                right.push(a);
                sum_right += a;
                if (left.size() < right.size()) {
                    sum_left += right.top();
                    sum_right -= right.top();
                    left.push(right.top());
                    right.pop();
                }
            }
        }
        else {
            const ll min_x = left.top();
            const ll min_f = sum_b + min_x * left.size() - sum_left
                + sum_right - min_x * right.size();
            cout << min_x << " " << min_f << endl;
        }
    }

    return 0;
}


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

int main()
{
	int tmp, s[100000], t, n, m = 1, q, count = 0;

	cin >> n >> s[0];
	for (int i = 1; i < n; i++)
	{
		cin >> tmp;
		if (tmp > s[m - 1])
		{
			s[m] = tmp;
			m++;
		}
	}
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		cin >> t;
		for (int j = 0; j < m; j++)
		{
			if (s[j] < t)
				continue;
			else if (s[j] == t)
			{
				count++;
				break;
			}
			else
				break;
		}
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 3520
#include<bits/stdc++.h>
#define INF (1e9)
using namespace std;

string s;
int dp[1<<26];

int main(){

  cin>>s;
  
  for(int i=0;i<(1<<26);i++) dp[i]=INF;

  dp[0]=0;
  
  int S=0;
  
  for(int i=0;i<s.size();i++){
    S^=(1<<(s[i]-'a'));
    int minv=INF;
    minv=min(minv, dp[S]);
    for(int j=0;j<26;j++) minv=min(minv, dp[S^(1<<j)]);
    dp[S]=min(dp[S], minv+1);
  }
  
  if(dp[S]==0) dp[S]=1;
  cout<<dp[S]<<endl;
  
  return 0;
}


Measured memory_bytes: 262788
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const double EPS  = 1e-10;
const bool debug = 0;
//---------------------------//

int H, W;
int s[1000][1000], sum[1000][1001];
int allsum[1001][1001];
int dp[1001][1001];

int dfs(int i, int j, int turn) {
	if (i == H && j == W) return 0;
	if (~dp[i][j]) return dp[i][j];
	
	int res;
	if (i == H) res = dfs(i, j + 1, !turn);
	else if (j == W) res = dfs(i + 1, j, !turn) + sum[i][W] - sum[i][j];
	else {
		int fc1 = dfs(i + 1, j, !turn) + sum[i][W] - sum[i][j];
		int sc1 = allsum[H][W] - allsum[i][W] - allsum[H][j] + allsum[i][j] - fc1;
		
		int fc2 = dfs(i, j + 1, !turn);
		int sc2 = allsum[H][W] - allsum[i][W] - allsum[H][j] + allsum[i][j] - fc2;
		
		if (!turn) {
			if (fc1 - sc1 < fc2 - sc2) res = fc2;
			else res = fc1;
		}
		else {
			if (fc1 - sc1 > fc2 - sc2) res = fc2;
			else res = fc1;
		}
	}
	
	return dp[i][j] = res;
}

int main(){
	cin >> W >> H;
	REP(i, H) REP(j, W) scanf("%d", &s[i][j]);
	
	REP(i, H) REP(j, W) sum[i][j + 1] = sum[i][j] + s[i][j];
	
	REP(i, H) REP(j, W) allsum[i + 1][j + 1] = allsum[i + 1][j] + s[i][j];
	REP(j, W) REP(i, H) allsum[i + 1][j + 1] += allsum[i][j + 1];
	
	memset(dp, -1, sizeof(dp));
	
	int fc = dfs(0, 0, 0);
	int sc = allsum[H][W] - fc;
	cout << abs(fc - sc) << endl;
	
	return 0;
}

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

int main(){
    string w, t;
    int count = 0;
    //int index = 0;
    
    cin >> w;
    
    transform(w.begin(), w.end(), w.begin(), ::tolower);
    
    while(1){
        cin >> t;
        
        if(t == "END_OF_TEXT") break;
        
        transform(t.begin(), t.end(), t.begin(), ::tolower);
        if(t == w) count++;
    }
    
    cout << count << endl;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	string S;
	int ans = 0;
	cin >> S;
	rep(i, 0, SZ(S)/2)
	{
		if (S[i] != S[SZ(S) - 1 - i])
		{
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import           Control.Monad
import           Data.Array.IO
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Maybe
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM

readInt = fst . fromJust . BS.readInt
getInt = readInt <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

main = do
  n <- getInt
  as <- getIntVec n

  cs <- VM.new 61
  VM.set cs (0::Int)

  forM_ [0..n-1] $ \i -> do
    let a = as V.! i
    forM_ [0..60] $ \j ->
      when (testBit a j) $ do
        c <- VM.read cs j
        VM.write cs j (c+1)
  cs' <- V.freeze cs

  let calc a i c = let c1 = fromIntegral c :: Integer
                       c2 = fromIntegral (n-c) :: Integer
                   in
                     c1 * c2 * bit i + a

  print $ V.ifoldl' calc 0 cs' `mod` 1000000007


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

int main() {
	int x, p, seki = 1;
	bool bl[2005];
	cin >> x;
	for (int i = 1; i <= 2000; i++) bl[i] = false;
	bl[1] = true;
	for (int i = 2; i <= 31; i++) {
	    seki = i;
	    while (seki <= 1000 / i + 1) {
	        seki *= i;
	        bl[seki] = true;
	    }
	}
	while (bl[x] == false) x--;
	cout << x;
	return 0;
}


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

int main ()
{
  int W, H, x, y, r;

  scanf("%d", &W);
  scanf("%d", &H);
  scanf("%d", &x);
  scanf("%d", &y);
  scanf("%d", &r);

  if (x - r < 0 || y - r < 0) {
    printf("No\n");
  } else if (x + r > W || y + r > H) {
    printf("No\n");
  } else {
    printf("Yes\n");
  }
  return 0;
}

Measured memory_bytes: 2696
#include <cstdio>
#include <iostream>
using namespace std;
int n;
long long a[100];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)cin>>a[i];
	long long k=0;
	while(true){
		int t=1;
		for(int i=2;i<=n;++i)
		    if(a[i]>a[t])t=i;
		if(a[t]<n)break;
		long long tmp=a[t]/n;
		a[t]%=n;
		for(int i=1;i<=n;++i)
		    if(i!=t)a[i]+=tmp;
		k+=tmp;
	}
	cout<<k;
}

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

int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
char h[4] = { 'E', 'N', 'W', 'S' };
int G[51][51][4];
int dir[1100];
int dp[1100][51][51][4];

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

	int n, x0, y0, t;
	while(cin >> n >> x0 >> y0 >> t) {
		memset(dir, -1, sizeof dir);
		memset(G, 0, sizeof G);
		memset(dp, 0, sizeof dp);
		for(int i = 0; i < n; i++) {
			int x1, y1, x2, y2;
			cin >> x1 >> y1 >> x2 >> y2;
			if(x1 > x2) swap(x1, x2);
			if(y1 > y2) swap(y1, y2);
			if(x1 == x2) {
				for(int y = y1; y < y2; y++) {
					G[x1][y][1] = 1;
					G[x1][y + 1][3] = 1;
				}
			}
			else {
				for(int x = x1; x < x2; x++) {
					G[x][y1][0] = 1;
					G[x + 1][y1][2] = 1;
				}
			}
		}

		int dsum = 0;
		for(int i = 0; i < t; i++) {
			int d;
			char c;
			cin >> d >> c;
			dsum += d;
			int x = find(h, h + 4, c) - h;
			dir[dsum] = x;
		}

		for(int k = 0; k < 4; k++) {
			dp[0][x0][y0][k] = 1;
		}

		for(int i = 0; i <= dsum; i++) {
			for(int x = 0; x <= 50; x++) {
				for(int y = 0; y <= 50; y++) {
					for(int k = 0; k < 4; k++) {
						if(!dp[i][x][y][k]) continue;
						bool ok = 0;
						for(int l = 0; l < 4; l++) {
							if(abs(k - l) == 2) continue;
							if(!G[x][y][l]) continue;
							if(dir[i] != -1 && dir[i] != k && dir[i] != l) {
								continue;
							}
							int nx = x + dx[l], ny = y + dy[l];
							dp[i + 1][nx][ny][l] = 1;
							ok = 1;
						}
						dp[i][x][y][k] = ok;
					}
				}
			}

		}
		for(int x = 0; x <= 50; x++) {
			for(int y = 0; y <= 50; y++) {
				for(int k = 0; k < 4; k++) {
					if(dp[dsum][x][y][k]) {
						cout << x << " " << y << "\n";
						break;
					}
				}
			}
		}
		//cout << endl;
	}
}

Measured memory_bytes: 47944
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

ullong power(ullong m, ullong n)
{
	ullong x = 1;
	if (n > 0)
	{
		x = power(m, n / 2);
		if (n % 2 == 0)
		{
			x = (x * x) % MOD;
		}
		else
		{
			x = (((x * x) % MOD) * m) % MOD;
		}
	}

	return x;
}

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

	cout << power(m, n) << endl;
}


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

#define FOR(i, a, b)   for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)  for(int i = (a); i > (b); --i)
#define rep(i, n)      for(int i = 0; i < (n); ++i)
#define all(c)         begin(c), end(c)
#define rall(c)        rbegin(c), rend(c)
#define SZ(a)          ((ll) a.size())

typedef long long ll;
typedef unsigned long long ull;


void solve(long long N, long long M, std::vector<long long> A, std::vector<long long> B){
    dsu d(N);
    rep(i,M){
        d.merge(A[i]-1,B[i]-1);
    }
    vector<vector<int>> result;
    result = d.groups();
    cout << SZ(result)-1 << endl;

}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, M, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 9124
# -*- coding: utf-8 -*-
import collections
n = int(input())
a = [int(i) for i in input().split()]

ans = 0
c = collections.Counter(a)
b = list(set(a))
for i in range(len(b)):
    tmp = c[b[i] - 1] + c[b[i]] + c[b[i] + 1]
    if tmp > ans:
        ans = tmp
print(ans)


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

int main()
{
  int n,count=0;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  sort(arr,arr+n);
  for(int i=0;i<n-1;i++)
  {
    if(arr[i]==arr[i+1]){
      count=1;
    break;
    }
  }
  if(count==1)
    cout<<"NO"<<endl;
  else
    cout<<"YES"<<endl;
    
    return 0;
}

Measured memory_bytes: 1024
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let s = next()
    let cntW = 0
    let cntB = 0
    
    // white starts
    for(let i = 0; i<s.length; i++){
        if(i % 2 == 0 && s[i] == 0){
            cntW++
        }else if(i % 2 !== 0 && s[i] == 1){
            cntW++
        }
    }

    // black starts
    for(let i = 0; i<s.length; i++){
        if(i % 2 == 0 && s[i] == 1){
            cntB++
        }else if(i % 2 !== 0 && s[i] == 0){
            cntB++
        } 
    }
    console.log(Math.min(cntB, cntW))
}
Main()



Measured memory_bytes: 32524
#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
using namespace std;
char s[105];
int a[105],b[105],sz;
int main(){
	scanf("%s",s+1);
	int len=strlen(s+1);
	rep(i,1,len) a[s[i]-'a']++,sz++;
	if (sz<=25) {
		rep(i,1,len) printf("%c",s[i]);
		rep(i,0,25) if (!a[i]) {
			printf("%c\n",'a'+i); break;
		}	
	}
	else {
		rep(i,1,len) b[i]=s[i]-'a';
		if (next_permutation(b+1,b+1+len)) {
			int pos=1;
			rep(i,1,len) if (b[i]+'a'>s[i]) {pos=i; break;}
			rep(i,1,pos) printf("%c",b[i]+'a');	
		}
		else puts("-1");	
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;
int main(){
  typedef long long int ll;
string A, B, C,D;
cin >> A;
bool ans = false;
if(A[0] == 'a' || A[0] == 'i' || A[0] == 'u' || A[0] == 'e' || A[0] == 'o')ans = true;
if(ans)cout << "vowel" << endl;
else cout << "consonant" << endl;
        return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

    int n = sc.nextInt();
    int min = 200001;
    int ans = 0;

    for(int i = 0; i < n; i++){
      int p = sc.nextInt();
      if(p < min){
        ans += 1;
        min = p;
      }
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 63576
s=input()

a=[0]*(len(s)+1)

prev=0
for i in range(len(s)):
    if s[i]=='<':
        a[i+1]=a[i]+1

for j in range(len(s)-1,-1,-1):
    if s[j]=='>':
        if a[j]>a[j+1]+1:
            continue
        else:
            a[j]=a[j+1]+1

print(sum(a))

Measured memory_bytes: 29136
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n,a,b = LI()
    print(min(n*a,b))
    return

#B
def B():
    s = S()
    print(s.count("1"))
    return

#C
def C():
    n = list(map(int, S()))
    k = 0
    s = sum(n)
    for i in range(len(n)):
        k *= 10
        k += n[i]
    if k%s == 0:
        print("Yes")
    else:
        print("No")
    return

#D
def D():
    n = I()
    a = LI()
    ans = float("inf")
    for i in range(n):
        m = 0
        while a[i]%2 == 0:
            m += 1
            a[i] //= 2
        ans = min(m,ans)
    print(ans)
    return

#E
def E():
    n = I()
    f = LIR(n)
    p = LIR(n)

    return

#F
def F():
    n,k = LI()
    a = LI()
    d = defaultdict(int)
    for i in a:
        d[i] += 1
    d = list(d.values())
    d.sort()
    ans = 0
    for i in range(len(d)-k):
        ans += d[i]
    print(ans)
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    F()


Measured memory_bytes: 94460
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;

const int INF = 1e9;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;
const double PI = acos(-1);

struct Input
{
	int n;char c;char str[1024];string s;ll l;
	int nextInt(){scanf("%d", &n);return n;}
	ll nextLong(){scanf("%lld", &l);return l;}
	char nextChar(){scanf("%c", &c);return c;}
	string next(){scanf("%s", str);return string(str);}
	string nextLine(){getline(cin, s);return s;}
};
Input in;

int h[250][250];
int v[250][250];

int sx = 125, sy = 125;

int top = 0, frt = 1, rit = 2, lft = 3, bck = 4, btm = 5;
int d[] ={1, 2, 3, 4, 5, 6};

void spin(int f1, int f2, int f3 ,int f4){
	int tmp = d[f1];
	d[f1] = d[f2];
	d[f2] = d[f3];
	d[f3] = d[f4];
	d[f4] = tmp;
}

void spin_s(){
	spin(top, frt, btm, bck);
}
void spin_e(){
	spin(top, rit, btm, lft);
}
void spin_cw(){
	spin(frt, rit, bck, lft);
}
void spin(int t, int f){
	rep(i, 4){
		if(d[top] == t) break;
		spin_s();
	}
	rep(i, 4){
		if(d[top] == t) break;
		spin_e();
	}
	rep(i, 4){
		if(d[frt] == f) break;
		spin_cw();
	}
}

int dir[] = {frt, rit, bck, lft};
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

void calc(int y, int x){
	if(h[y][x] == 0){
		h[y][x]++;
		v[y][x] = d[top];
		return;
	}
	for(int i = 6; i >= 4; i--){
		for(int j = 0; j < 4; j++){
			if(d[dir[j]] == i){
				int nx = x + dx[j], ny = y + dy[j];
				if(h[ny][nx] < h[y][x]){
					if(j == 0) rep(k, 3) spin_s();
					else if(j == 1) rep(k, 3) spin_e();
					else if(j == 2) spin_s();
					else spin_e();
					calc(ny, nx);
					return;
				}
				break;
			}
		}
	}
	h[y][x]++;
	v[y][x] = d[top];
}

int main(){
	while(1){
		int n = in.nextInt();
		if(n == 0) break;
		vi t(n), f(n);
		rep(i, n) t[i] = in.nextInt(), f[i] = in.nextInt();
		rep(i, 250) rep(j, 250) h[i][j] = v[i][j] = 0;
		rep(i, n){
			rep(i, 6) d[i] = i + 1;
			spin(t[i], f[i]);
			calc(sy, sx);
		}
		int ans[6] ={};
		rep(i, 250) rep(j, 250){
			if(v[i][j] == 0) continue;
			ans[v[i][j]-1]++;
		}
		rep(i, 6){
			if(i != 0) printf("%s", " ");
			printf("%d", ans[i]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 1684
#include <stdio.h>
#include <math.h>
int main()
{
	int X, Y, Z, area, people = 0, i;
	scanf("%d %d %d", &X, &Y, &Z);
	area = X - Z * 2;
	for (i = Y + Z; ; i += (Y + Z)) {
		people++;
		if (i - Z > area) {
			people--;
			break;
		} else if (i - Z == area) {
			break;
		}		
	}
	printf("%d\n", people);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
class Main{
    public static void main(String[] args){
		int n,a;
		int min=1000000;
		int max=-1000000;
		long total=0;
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		for(int i=0;i<n;i++){
			a=sc.nextInt();
			if(min>=a)min=a;
			if(max<=a)max=a;
			total+=a;
		}
		System.out.println(min+" "+max+" "+total);
    }
}



Measured memory_bytes: 41452
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

template <class T>
class EdgeBase
{
public:
    int to;
    T cost;
    EdgeBase(){};
    EdgeBase(int to0, T cost0){to = to0; cost = cost0;}
};
typedef EdgeBase<int> Edge;

template<class T>
void shortestPath(const vector<vector<EdgeBase<T> > >& edges, int start, vector<T>& dist)
{
    const T INF = numeric_limits<T>::max();
    const T EPS = static_cast<T>(1.0e-10);

    dist.assign(edges.size(), INF);
    dist[start] = 0;
    priority_queue<pair<T,int>, vector<pair<T,int> >, greater<pair<T,int> > > q;
    q.push(make_pair(0, start));

    while(!q.empty()){
        pair<T, int> p = q.top();
        q.pop();
        int v = p.second;
        if(dist[v] < p.first - EPS)
            continue;
        for(unsigned i=0; i<edges[v].size(); ++i){
            EdgeBase<T> e = edges[v][i];
            if(dist[v] + e.cost < dist[e.to] - EPS){
                dist[e.to] = dist[v] + e.cost;
                q.push(make_pair(dist[e.to], e.to));
            }
        }
    }
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<int> p(n+11);
        for(int i=2; i<=n; ++i)
            cin >> p[i];

        vector<vector<Edge> > edges(n+1);
        int ret = 0;
        for(int i=2; i<=n; ++i){
            int d;
            cin >> d;
            ret += d * 3;
            edges[i].push_back(Edge(p[i], d));
            edges[p[i]].push_back(Edge(i, d));
        }

        for(int i=1; i<=n; ++i){
            if(edges[i].size() == 1)
                ret -= edges[i][0].cost * 2;
        }

        int x = 1;
        while(x <= n && edges[x].size() == 1)
            ++ x;
        if(x <= n){
            vector<int> dist;
            shortestPath(edges, x, dist);
            for(int i=1; i<=n; ++i){
                if(edges[i].size() != 1 && dist[i] > dist[x])
                    x = i;
            }
            shortestPath(edges, x, dist);
            for(int i=1; i<=n; ++i){
                if(edges[i].size() != 1 && dist[i] > dist[x])
                    x = i;
            }
            ret -= dist[x];
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 1272
from collections import deque

K=int(input())
X=deque()
d=10

for i in range(1,d):
    X.append(i)

for i in range(K):
    k=X.popleft()
    if k%d!=0:
        X.append(k*10+(k%d)-1)
        
    X.append(k*10+(k%d))

    if k%d!=d-1:
        X.append(k*10+(k%d)+1)

print(k)


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

int main(){

	int a, b, c, temp;
	cin >> a >> b >> c;

	if(a > b){
		temp = a;
		a = b;
		b = temp;
	}

	if(b > c){
		temp = b;
		b = c;
		c = temp;
	}

	if(a > b){
		temp = a;
		a = b;
		b = temp;
	}

	cout << a << " " << b << " " << c << endl;

	return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
int n,m,L,f[310][310],Q;
long long a[310][310];
int main()
{
	scanf("%d%d%d",&n,&m,&L);
	memset(a,10,sizeof(a));
	for (int i=1;i<=m;i++) {
		int xx,yy,zz;
		scanf("%d%d%d",&xx,&yy,&zz);
		if (zz>L) continue;
		a[xx][yy]=zz;
		a[yy][xx]=zz;
		f[xx][yy]=1;
		f[yy][xx]=1;
	}
	for (int k=1;k<=n;k++)
	  for (int i=1;i<=n;i++)
	    for (int j=1;j<=n;j++)
	      if (a[i][k]+a[k][j]<a[i][j]) a[i][j]=a[i][k]+a[k][j];
	memset(f,10,sizeof(f));
	for (int i=1;i<=n;i++)
	  for (int j=1;j<=n;j++)
	    if (a[i][j]<=L) f[i][j]=0;
	for (int k=1;k<=n;k++)
	  for (int i=1;i<=n;i++)
	    for (int j=1;j<=n;j++) 
	    	if (f[i][k]+f[k][j]+1<f[i][j]) f[i][j]=f[i][k]+f[k][j]+1;
	scanf("%d",&Q);
	for (int i=1;i<=Q;i++) {
		int xx,yy;
		scanf("%d%d",&xx,&yy);
		if (a[xx][yy]==a[0][0]) printf("-1\n");
		else printf("%d\n",f[xx][yy]);
	}
	return 0;
}
	

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int h;
    cin >> h;
    int firs = h;
    int hiki = 1;

    int dec = 0;
    while (h > 1) {
        if (h % 2 == 1) dec += hiki;
        dec -= hiki;

        hiki *= 2;
        h /= 2;
    }
    print(firs - dec);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cctype>
#include <cstdio>
#include <vector>
using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a==b){
        cout << c;
    }else if(b==c){
        cout << a;
    }else{
        cout << b;
    }
    
    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
const int MAXX = 1e6+7;

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

    for (int i = 0, r = 7%k; i < MAXX; i++, r = (r*10+7)%k) {
        if (r==0) {
            cout << i+1 << endl;
            return 0;
        }
    }

    cout << -1 << endl;


    return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>
int i, j;
int min(int a, int b){
  if(a>b)return b;
  else return a;
}
int main(){
  int n;
  int a[101];
  scanf("%d", &n);
  for(i=0;i<n;i++)scanf("%d", &a[i]);
  int ans = 1000000;
  int c;
  for(i=0;i<100;i++){
    int tmp = 0;
    for(j=0;j<n;j++){
      tmp+=((i-a[j])*(i-a[j]));
    }
    ans = min(ans, tmp);
  }

  printf("%d\n", ans);

  return 0;
}


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

long long n;
vector<int> a, ans;

bool solve();

int main() {
  cin >> n;
  a.resize(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  if(solve()) {
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); ++i) {
      if(i != 0) cout << " ";
      cout << ans[i];
    }
    cout << endl;
  }
  else
    cout << -1 << endl;
  return 0;
}

bool solve() {
  for(long long i = n; i > 0; --i) {
    if(a[i - 1]) {
      ans.push_back(i);
      for(long long j = 1; j * j <= i; ++j)
        if(i % j == 0) {
          a[j - 1] = 1 - a[j - 1];
          if(j * j != i) a[i / j - 1] = 1 - a[i / j - 1];
        }
    }
  }
  return 1;
}


Measured memory_bytes: 2424
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)

using namespace std;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

ll s(ll x) {
  auto str = to_string(x);
  ll sum = 0;
  for (char c : str) sum += c - '0';
  return sum;
}

double calc(ll x) {
  return x / (double)s(x);
}

int main()
{
  ll k;
  cin>>k;
  ll mul = 1;
  vecll res;
  FOR(i,1,16) {
    vector<ll> rng;
    ll base = mul;
    FOR(j,1,10) {
      rng.push_back(j);
    }
    boost::reverse(rng);
    while (base > 1) {
      double supinf = calc(10*mul-1);
      vecll nx;
      for (auto x : rng) {
        double nmn = (x*base) / (double)(s(x) + s(base-1));
        double nmn_c = (x*base + base-1) / (double)(s(x) + s(base-1));
        if (nmn <= supinf) {
          REP(j,10) {
            nx.push_back(x*10 + (9-j));
          }
          supinf = min(supinf, nmn_c);
        }
      }
      swap(rng, nx);
      base /= 10;
    }
    double inf = calc(10*mul-1);
    for (ll x : rng) {
      if (calc(x) <= inf) {
        res.push_back(x);
        inf = calc(x);
      }
    }
    mul *= 10;
  }
  boost::sort(res);
  REP(i,k) cout<<res[i]<<endl;
  return 0;
}


Measured memory_bytes: 256
import math

N, P = map(int, input().split())

if N == 1:
    print(P)
    
else:
    T = int(math.pow(P, 1/N)) * 2

    Q = [False, False] + [True] * T
    F = []
    for n in range(T + 1):
        if Q[n]:
            F.append(n)
            for m in range(n, T + 1, n):
                Q[m] = False
    D = 1
    for f in F:
        c = 0
        while P % f == 0:
            c += 1
            P //= f
        D *= f ** (c // N)

    print(D)

Measured memory_bytes: 30580
mod = 10**9 + 7

N = int(input())
S = [input() for _ in range(2)]
P = []
for i in range(2):
    note = 0
    s = ""
    for j in range(N):
        if S[i][j] == note:
            continue
        s += S[i][j]
        note = S[i][j]
    P.append(s)
f = []
for j in range(len(P[0])):
    t = P[0][j]; b = P[1][j]
    if t == b:
        f.append(1)
    else:
        f.append(0)

if f[0] == 1:
    ans = 3
else:
    ans = 6
for j in range(1,len(P[0])):
    if f[j] == 1:
        if f[j-1] == 1:
            ans *= 2
        else:
            pass
    else:
        if f[j-1] == 1:
            ans *= 2
        else:
            ans *= 3
    ans %= mod

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
#define rep(i,n) for(int i=0;i<(int)(n);++i)

bool is_prime[100005];
void p(){
    rep(i,100005)is_prime[i]=true;
    is_prime[0]=false;
    is_prime[1]=true;
    int now=2;
    FOR(i,2,100005){
        if(!is_prime[i])continue;
        else{
            int np=2*i;
            while(np<100005){
                is_prime[np]=false;
                np+=i;
            }
        }
    }
}

int main(){
    vector<int> psum(100005,0);
    p();
    FOR(i,2,100005){
        if(i%2==1 && is_prime[i] && is_prime[(i+1)/2])psum[i]=psum[i-1]+1;
        else psum[i]=psum[i-1];
    }
    int q;cin>>q;
    int l,r;
    rep(i,q){
        cin>>l>>r;
        cout<<psum[r]-psum[l-1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1152
import sys
N = 0
debug = False
def test_init():
	N = int(input())
def test_eval(n):
	return ((n <= N and str(n) <= str(N)) or (n > N and str(n) > str(N)))

def query(n):
	# print(n, N, test_eval(n))
	if debug:
		return test_eval(n)
	print("? " + str(n))
	sys.stdout.flush()
	return input() == "Y"

def get_ndigit():
	retval = 1
	while not query(10 ** retval - 1):
		retval += 1
	if retval == 1:
		while not query((10 ** retval - 1) * 10 ** 9):
			retval += 1
		while not query(10 ** retval - 1):
			retval += 1
	return retval

def get_digit(x):
	l = len(str(x)) if x != 0 else 0
	def q(D):
		return query(x * 10 + D)
	d = 5
	r = q(d)
	if r:
		d = 7
		r = q(d)
		if r:
			d = 8
			r = q(d)
			if r:
				d = 9
				r = q(d)
				return 9 if r else 8
			else:
				return 7
		else:
			d = 6
			r = q(d)
			return 6 if r else 5
	else:
		d = 2
		r = q(d)
		if r:
			d = 3
			r = q(d)
			if r:
				d = 4
				r = q(d)
				return 4 if r else 3
			else:
				return 2
		else:
			d = 1
			r = q(d)
			return 1 if r else 0
if debug:
	test_init()
nd = get_ndigit()
# print(nd)
value = 0
for i in range(nd - 1):
	value = value * 10 + get_digit(value)
ar = [False] * 10
i = 0
if nd == 1:
	i = 1
while not query((value * 10 + i) * 10):
	i += 1
value = value * 10 + i
print("! " + str(value))

Measured memory_bytes: 3912
#include <bits/stdc++.h>
#define MAXN 2010
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x<n and y >=0 and y<n)
using namespace std;
const ll mod = 1e9 + 7;

int main (){
    ios_base::sync_with_stdio(false);
    string s;
    int n, moves = 0;
    cin >> s;

    n = s.size();

    if ((n%2) ^ (s[0] == s[n-1])){
        cout << "First" << endl;
    }
    else {
        cout << "Second" << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n; cin >> n;
    int num = n;
    int a = 0;
    while(num > 0){
        a += num % 10;
        num /= 10;
    }
    if(n % a == 0) cout << "Yes" << endl;
    else cout << "No" << endl; 
}

Measured memory_bytes: 256
// Problem : C - Maximum Volume
// Contest : AtCoder Beginner Contest 159
// URL : https://atcoder.jp/contests/abc159/tasks/abc159_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)


#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;
 
#define deb1a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        cout << it << " ";        \
    }                             \
    cout << endl;
#define deb2a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        for (auto it1 : it)       \
        {                         \
            cout << it1 << " ";   \
        }                         \
        cout << endl;             \
    }
#define mod 1000000007
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
int power(int x, unsigned int y, int p){ int res = 1;x = x % p;while (y > 0)  { if (y & 1)res = (res*x) % p;y = y>>1;  x = (x*x)% p;} return res;}

int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    double x = n*1.0 / 3;
    //deb(x);
    x = 1.0*x * x * x;
    cout << fixed << setprecision(12) << x;
    double ans = 0.0;
   
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

constexpr int m = 2019;

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

    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    int n = s.length();
    
    vector<int> sum(n + 1);
    sum[0] = 0;
    int mul = 1;
    for(int i = 0; i < n; ++i){
        int num = s[i] - '0';
        sum[i + 1] = (sum[i] + num * mul) % m;
        mul *= 10;
        if(mul > m) mul %= m;
    }
    map<int, int> mp;
    for(int i = 0; i <= n; ++i) ++mp[sum[i]];
    ll ans = 0;
    for(auto it : mp)   ans += (ll)it.second * (it.second - 1) / 2;
    cout << ans << endl;
}

Measured memory_bytes: 4424
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

const int MAX_N = 200005;

int n, q;
vector<int> g[MAX_N];
ll vRes[MAX_N];

void dfs(int u, int prev)
{
	if (prev != -1)
		vRes[u] += vRes[prev];
	for (int v : g[u])
		if (v != prev)
			dfs(v, u);
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> q;
	for (int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}

	for (int i = 0; i < q; i++)
	{
		int p; ll x;
		cin >> p >> x;
		p--;
		vRes[p] += x;
	}

	dfs(0, -1);
	for (int i = 0; i < n; i++)
		cout << vRes[i] << " ";
	cout << endl;
}

Measured memory_bytes: 21504
let scan_int () = Scanf.scanf " %d" (fun x -> x)
let print_array a = 
  let _ = Array.iter (Printf.printf "%d ") a in print_newline()

let rec solve i n arr =
  if i = n then arr
  else
    let input = scan_int() in
    let _ = arr.(input-1) <- i+1 in
    solve (i+1) n arr

let () =
  let n = scan_int() in
  let arr = Array.make n 0 in
  print_array (solve 0 n arr)

Measured memory_bytes: 5632