akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <cmath>

std::vector<size_t>
get_primes(size_t MaxPrime) {
  std::vector<size_t> primes;
  std::vector<bool> is_prime(MaxPrime+1, true);
  is_prime[0] = false;
  is_prime[1] = false;

  for (size_t i=2; i<=std::sqrt(MaxPrime); i++) {
    if (is_prime[i]) {
      primes.push_back(i);
      for (size_t j=i*i; j<=MaxPrime; j+=i) {
        is_prime[j] = false;
      }
    }
  }

  for (size_t i=std::sqrt(MaxPrime)+1; i<=MaxPrime; i++) {
    if (is_prime[i]) {
      primes.push_back(i);
    }
  }

  return primes;
}

std::map<size_t, size_t>
get_prime_factors(size_t N) {
  std::map<size_t, size_t> prime_factors;

  if (N<2) {
    prime_factors.insert(std::make_pair(N, 1));
    return prime_factors;
  }

  for (auto const p : get_primes(std::sqrt(N))) {
    while (N % p == 0) {
      prime_factors[p]++;
      N /= p;
    }
  }

  if (N > 1) prime_factors[N]++;

  return prime_factors;
}
int main() {
  size_t N, P;
  std::cin >> N >> P;

  size_t ans = 1;

  for (auto const & p : get_prime_factors(P)) {
    auto n = std::get<1>(p);
    while (n >= N) {
      ans *= std::get<0>(p);
      n -= N;
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 1528
import java.math.BigInteger;
import java.util.Scanner;

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

        int N = sc.nextInt();
        int K = sc.nextInt();

        System.out.println(solve(N, K));

        sc.close();
    }

    static int solve(int N, int K) {
        return K * BigInteger.valueOf(K - 1).pow(N - 1).intValue();
    }
}

Measured memory_bytes: 23764
#include <stdio.h>
int main()
{
  int N;
  (void)scanf("%d", &N);

  int A[1001][1001];
  int* P[1001];

  for (int i = 1; i <= N; i++)
  {
    for (int j = 1; j <= N - 1; j++) (void)scanf("%d", &(A[i][j]));
    A[i][0] = 0;
    A[i][N] = 0;
    P[i] = A[i] + 1;
  }

  int I = 1, D = 1;
  while (I <= N)
  {
    if (*P[I] <= 0)
    {
      I++;
      continue;
    }

    int noMatch = 1;
    for (int i = I; i <= N; i++)
    {
      int* player1 = P[i];
      if (*player1 == 0) continue;
      int* player2 = P[*player1];

      if (*(player1 - 1) == -D) continue;
      if (*(player2 - 1) == -D) continue;

      if (*player2 == i)
      {
        P[i]++;
        P[*player1]++;

        *player1 = -D;
        *player2 = -D;

        noMatch = 0;
      }
    }

    if (noMatch)
    {
      printf("-1\n");
      return 0;
    }
    D++;
  }

  printf("%d\n", D - 1);
  return 0;
}

Measured memory_bytes: 4096
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0

for n in range(N):
    d = B[n] - A[n]
    if d >= 0:
        ans += A[n]
        e = d - A[n+1]
        if e >= 0:
            ans += A[n+1]
            A[n+1] = 0
        else:
            A[n+1] -= d
            ans += d
    else:
        ans += B[n]

print(ans)

Measured memory_bytes: 19116
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n);
	double L = 0, R = 1LL << 60;
	std::vector<int> x(n), r(n);
	for(int i = 0; i < n; i++) {
		scanf("%d%d", &x[i], &r[i]);
		
		L = std::max<double>(L, x[i] - r[i]);
		R = std::min<double>(R, x[i] + r[i]);
	}
	if(n == 1) {
		printf("%d\n", r[0]);
		return 0;
	}
	
	auto calc = [&](double t) {
		double ret = 1LL << 60;
		for(int i = 0; i < n; i++) {
			double D = std::abs(x[i] - t);
			double R = r[i];
			
			ret = std::min(ret, R * R - D * D);
		}
		return sqrt(ret);
	};
			
	double lo = L, hi = R;
	for(int _ = 0; _ < 100; _++) {
		double ml = (lo + lo + hi) / 3.;
		double mr = (lo + hi + hi) / 3.;
		
		
		if(calc(ml) < calc(mr)) lo = ml;
		else hi = mr;
	}
	printf("%.12lf\n", calc((lo + hi) / 2.));
	return 0;
}



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

//--------------------------------------------
#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(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------

int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  if (a == 1) a = 14;
  if (b == 1) b = 14;

  if (a > b) printf("Alice\n");
  else if (a < b) printf("Bob\n");
  else printf("Draw\n");
}


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

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

using namespace std;

int main(){
  ll n;cin>>n;
  ll a[100001*3];
  ll lsums[100001];
  ll rsums[100001];
  lsums[0]=0, rsums[n]=0;

  rep(i,3*n)cin>>a[i];

  priority_queue<ll, vector<ll>, greater<ll>> lq;
  priority_queue<ll> rq;

  rep(i,n){
    lq.push(a[i]);
    lsums[0]+=a[i];

    rq.push(a[3*n-1-i]);
    rsums[n]+=a[3*n-1-i];
  }

  rep(i,n){
    lq.push(a[i+n]);
    lsums[i+1]=(lsums[i]+a[i+n]-lq.top());
    lq.pop();

    rq.push(a[2*n-1-i]);
    rsums[n-1-i]=(rsums[n-i]+a[2*n-1-i]-rq.top());
    rq.pop();
  }


//cout<<lsums[0]<<' '<<rsums[0]<<endl;
  ll result = lsums[0]-rsums[0];
  rep(i,n){
    result=max(result, lsums[i+1]-rsums[i+1]);
  }

  cout<<result;

  return 0;
}


Measured memory_bytes: 5996
from collections import deque

S = list(input())
T = list(input())
T_deque = deque(T)

S_deque = deque(S)
flag = 0
for i in range(len(S)):
    # print(S_deque)
    if S_deque == T_deque:
        flag = 1
        break
    else:
        S_deque.rotate()

if flag == 1:
    print("Yes")
else:
    print("No")

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

int main()
{
    int K;
    cin >> K;
    int a = 0;
    int b = 0;
    for(int i = 1; i <= K; i++)
    {
        if(i % 2 == 0) a++;
        else if(i % 2 == 1) b++;
    }
    int c = a * b;
    cout << c;
    return 0;
}


Measured memory_bytes: 256
def main():
	n,m = map(int,input().split())
	h = list(map(int,input().split()))
	l = [list(map(int, input().split())) for i in range(m)]

	ans = int(n)
	del_list = set()
	for i in range(m):
		if h[l[i][0]-1] > h[l[i][1]-1] and l[i][1] not in del_list:
			ans -= 1
			del_list.add(l[i][1])
		elif h[l[i][0]-1] < h[l[i][1]-1] and l[i][0] not in del_list:
			ans -= 1
			del_list.add(l[i][0])
		elif h[l[i][0]-1] == h[l[i][1]-1]:
			if l[i][0] not in del_list and l[i][1] not in del_list:
				ans -= 2
				del_list.add(l[i][0])
				del_list.add(l[i][1])
			elif l[i][0] not in del_list:
				ans -= 1
				del_list.add(l[i][0])
			elif l[i][1] not in del_list:
				ans -= 1
				del_list.add(l[i][1])
			else:
				ans += 0
		else:
			ans += 0

	print(ans)





if __name__ == '__main__':
	main()

Measured memory_bytes: 100732
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

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

    int count=0;
    rep(i,s.size()){
        if(s[i] == 'o')++count;
    }
    int nokori = 15 - s.size();
    if((count+nokori) >= 8)cout<<"YES";
    else cout<<"NO";
}

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

int main() {
    int R;
    cin >> R;
    if (R < 1200) {
        cout << "ABC" << endl;
    } else if (R < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }
}

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

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true;
    for (auto next_v : G[v]) {
        if (seen[next_v]) continue;
        dfs(G, next_v); // 再帰的に探索
    }
}

int main() {
    // 頂点数と辺数
    int N, M; cin >> N >> M;

    // グラフ入力受取
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    // 全頂点が訪問済みになるまで探索
    int count = 0;
    seen.assign(N, false);
    for (int v = 0; v < N; ++v) {
        if (seen[v]) continue; // v が探索済みだったらスルー
        dfs(G, v); // v が未探索なら v を始点とした DFS を行う
        ++count;
    }
    cout << count - 1 << endl;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL n, k, a[100000], b[100000];

LL f(int p) {
	LL sum = 0;
	inc(i, n) {
		if(((a[i] >> p) & 1) == 0 && ((a[i] >> p) | (k >> p)) == (k >> p)) { sum += b[i]; }
	}
	return sum;
}

int main() {
	cin >> n >> k;
	inc(i, n) { cin >> a[i] >> b[i]; }
	
	k++;
	LL ans = 0;
	inc(bit, 31) {
		if((k >> bit) & 1) { setmax(ans, f(bit)); }
	}
	
	cout << ans << endl;
	
	return 0;
}


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

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

struct status{
	ll b;
	ll d;
	ll p;
};

ll ord(ll t){
	return ((t == 0) ? 1 : -1);
}

ll calc_value(status item, int i, int j, int k){
	int ob = ord(i), od = ord(j), op = ord(k);
	return item.b * ob + item.d * od + item.p * op;
}

int main(){
	int N, M; 
	cin >> N >> M;
	vector<status> item(N);
	rep(i,N)cin >> item[i].b >> item[i].d >> item[i].p;
	ll ans = -1;
	rep(i,2)rep(j,2)rep(k,2){
		vector<pair<ll, int>> values(N);
		rep(l, N){
			values[l].first = calc_value(item[l], i, j, k);
			values[l].second = l;
			//if(l == 0){
			//	printf("[i,j,k = %d, %d, %d]->[values[0] = %lld]\n", i, j, k, values[l].first );
			//}
		}
		sort(all(values), greater<pair<ll,int>>());
		ll sum_b = 0, sum_d = 0, sum_p = 0;
		rep(l,M){
			int item_num = values[l].second;
			sum_b += item[item_num].b * ord(i);
			sum_d += item[item_num].d * ord(j);
			sum_p += item[item_num].p * ord(k);
		}
		ans = max(ans, abs(sum_b) + abs(sum_d) + abs(sum_p));
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;


int gcd(int a, int b) {
  while(b) {
    a %= b;
    swap(a, b);
  }
  return a;
}

int N, Ma, Mb, a[40], b[40], c[40], dp[40][401][401];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> Ma >> Mb;
  for (int i = 0; i < N; ++i) {
    cin >> a[i] >> b[i] >> c[i];
  }

  int inf = 100*40+1;
  for (int i = 0; i < N; ++i) {
    for (int ai = 0; ai <= 400; ++ai) {
      for (int bi = 0; bi <= 400; ++bi) {
        dp[i][ai][bi] = inf;
      }
    }
  }

  dp[0][0][0] = 0;
  dp[0][a[0]][b[0]] = c[0];
  for (int i = 1; i < N; ++i) {
    for (int ai = 0; ai <= 400; ++ai) {
      for (int bi = 0; bi <= 400; ++bi) {
        if (ai-a[i]>=0 && bi-b[i]>=0 && dp[i-1][ai-a[i]][bi-b[i]]!=inf) {
          dp[i][ai][bi] = min(dp[i][ai][bi], dp[i-1][ai-a[i]][bi-b[i]] + c[i]);
        }
        if (dp[i-1][ai][bi]!=inf) {
          dp[i][ai][bi] = min(dp[i][ai][bi], dp[i-1][ai][bi]);
        }
      }
    }
  }
  int ans = inf;
  for (int i = 0; i < N; ++i) {
    for (int ai = 1; ai <= 400; ++ai) {
      for (int bi = 1; bi <= 400; ++bi) {
        if (dp[i][ai][bi]!=inf) {
          int g = gcd(ai, bi);
          if (ai/g==Ma && bi/g==Mb) {
            ans = min(ans, dp[i][ai][bi]);
          }
        }
      }
    }
  }
  cout << (ans==inf ? -1 : ans) << endl;
  return 0;
}


Measured memory_bytes: 25344
import heapq

N = int(input())
a = [int(n) for n in input().split()]
former = a[:N]

heapq.heapify(former)

former_sum = [sum(former)]


for k in range(N):
  heapq.heappush(former, a[N+k])
  former_sum.append(former_sum[k]+a[N+k]-heapq.heappop(former))

a = [n * (-1) for n in a]
latter = a[2*N:]
heapq.heapify(latter)
latter_sum = [sum(latter)]

for k in range(N):
  heapq.heappush(latter, a[2*N-k-1])
  latter_sum.append(latter_sum[k] + a[2*N-k-1] - heapq.heappop(latter))

res = [former_sum[k] + latter_sum[N-k] for k in range(N+1)]

print(max(res))

Measured memory_bytes: 122640
class Square
  attr_reader :squares

  def initialize
    @squares = build_two_dimensions
  end

  def build_two_dimensions
    Array.new(10) { [] }.map { Array.new(10) { 0 } }
  end

  def update(x, y, size)
    range = case size
            when 1
              small_range
            when 2
              middle_range
            when 3
              large_range
            else
              []
            end

    range.each do |a, b|
      increment(x + a, y + b)
    end
  end

  def zero_count
    squares.flatten.select(&:zero?).count
  end

  def max
    squares.flatten.max
  end

  private

  def large_range
    middle_range.concat [[-2, 0], [0, -2], [0, 2], [2, 0]]
  end

  def middle_range
    small_range.concat [[-1, -1], [-1, 1], [1, -1], [1, 1]]
  end

  def small_range
    [[-1, 0], [0, -1], [0, 0], [0, 1], [1, 0]]
  end

  def increment(x, y)
    squares[x][y] += 1 if x.between?(0, 9) && y.between?(0, 9)
  end
end

square = Square.new
STDIN.read.split("\n").each do |line|
  x, y, size = line.split(',').map(&:to_i)
  square.update(x, y, size)
end
puts [square.zero_count, square.max]

Measured memory_bytes: 8644
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <sstream>

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define pb(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

using namespace std;

int cnt = 0;
void insertionSort(vector<int> &A, int n, int g) {
	FOR(i, g, n) {
		int v = A[i];
		int j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j = j - g;
			cnt++;
		}
		A[j + g] = v;
	}
}


int main() {
	int n;

	vector<int> a;
	cin >> n;
	int b = n;
	REP(i, n) {
		int b;
		cin >> b;
		a.pb(b);
	}
	int m = 0;
	while (b > 0) {
		b /= 2;
		m++;
	}
	m = max(1, m - 1);
	vector<int> g;
	RREP(i, m) {
		g.pb((int)pow(2, i));
	}
	REP(i, m) {
		insertionSort(a, n, g[i]);
	}
	cout << m << endl;
	REP(i, m) {
		cout << g[i];
		if (i != m - 1) cout << " ";
	}
	cout << endl;
	cout << cnt << endl;
	REP(i, n) {
		cout << a[i] << endl;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 6944
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<stack>
using namespace std;
#define MS(m,z) memset(m,z,sizeof(m))
typedef unsigned U; typedef pair<int,int > P; typedef long long ll;
void inp();
int main(){
#ifdef XS
	freopen("findMaxRectangle.in","r",stdin);
#endif
	//int n;scanf("%d",&n);for(int i=1;i<=n;i++)
	inp();
	return 0;
}
const int N = 2000;
int g[N][N];
int s[N];
int findMaxRectangle(int *a,int n){
	int cnt=0;
	a[n]=0; n++;
	int ma=0;
	for(int i = 0;i<n;i++){
		while(cnt&&a[s[cnt-1]]>a[i]){
			int cur=s[cnt-1];cnt--;
			int wid=cnt?(i-s[cnt-1]-1):i;
			ma=max(ma,(a[cur])*wid);
			//printf("in %d cur %d wid:%d,ea:%d\n",i,cur,wid,a[cur]*wid);
		}
		s[cnt]=i; cnt++;
	}
	return ma;
}
void inp(){
	int h,w,x;scanf("%d%d",&h,&w);
	for(int i =1;i<=h;i++){
		for(int j =1;j<=w;j++){ scanf("%d",&x);g[i][j]=!x; }
	}
	int ma=0;
	//int a[]={2,1,5,6,2,3},n=sizeof(a)/sizeof(int);
	//printf("%d\n",findMaxRectangle(a,n));
	for(int i = 1;i<=h;i++){
		for(int j =1;j<=w;j++){
			if(g[i-1][j]&&g[i][j])
				g[i][j]+=g[i-1][j];
		}
		ma=max(ma,findMaxRectangle(&g[i][1],w));
	}
	printf("%d\n",ma);
}
//findMaxRectangle.cc by xsthunder at Mon Aug 21 22:30:32 2017

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

int main(){
ll k; cin >> k;
if(k%2==0 || k%5==0){
cout << -1 << endl;
return 0;
}
ll n = 7;
ll ans = 1;
for(int i = 0; i<= 1e6; i++){
 if(n%k==0) break;
n = (10*n+7)%k;
ans++;
}
cout << ans << endl;
return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        v.push_back(a);
    }
    sort(v.begin(), v.end());
    int t = 0;
    for (int i = 1; i < v.size(); i++) {
        t += v[i] - v[i-1];
    }
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include<cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include<bitset>

#define REP(i, b, n) for(int i=b;i<(int)n;i++)
#define rep(i, n)   REP(i,0,n)
#define ALL(C)     (C).begin(),(C).end()
#define FOR(it, o)  for(__typeof((o).begin()) it=(o).begin(); it!=(o).end(); ++it)
#define dbg(x) cout << __LINE__ << ' ' << #x << " = " << (x) << endl


typedef long long ll;

using namespace std;

//ハマったらチェックリスト見ろ!!

int main() {
    int a, b;
    cin >> a >> b;

    if(a + b == 15){
        cout << "+" << endl;
    }else if(a * b == 15){
        cout << "*"  << endl;
    }else cout << "x" << endl;

    return 0;
}

Measured memory_bytes: 888
N = int(input())
T = [int(input()) for _ in range(N)]

def GCD(a,b):
    x3 = a % b
    if x3 == 0:
        return min(a,b)
    N = GCD(b,x3)
    return N

def lcm(a,b):
    return a*b // GCD(a,b)
        
ans = T[0]
for i in range(1,N):
    ans = lcm(ans,T[i]) 

print(int(ans))
    

Measured memory_bytes: 3064
#include<stdio.h>
#define MATRIX_MAX 101
#define LOOP_RESET 0
#define MATRIX_RESET 0
#define RETURN 0

int main(){
	unsigned long ulW_D_inact[MATRIX_MAX][MATRIX_MAX];	/* 行列Ａの格納用配列 */
	unsigned long ulW_D_act[MATRIX_MAX][MATRIX_MAX];  	/* 行列Ｂの格納用配列 */
	unsigned long ulW_D_ans[MATRIX_MAX][MATRIX_MAX];  	/* 積の格納用変数 */
	unsigned short row;                                          	/* 行数の格納用変数 */
	unsigned short share;                                        	/*  */
	unsigned short col;                                          	
	unsigned short i, j, k;                                      	
	
	for(i = LOOP_RESET;i < MATRIX_MAX;i++){
		for(j = LOOP_RESET;j < MATRIX_MAX;j++){
			ulW_D_inact[i][j] = MATRIX_RESET;
			ulW_D_act[i][j] = MATRIX_RESET;
			ulW_D_ans[i][j] = MATRIX_RESET;
		}
	}
	
	scanf("%d %d %d", &row, &share, &col);
	
	for(i = LOOP_RESET;i < row;i++){
		for(j = LOOP_RESET;j < share;j++){
			scanf("%ld", &ulW_D_inact[i][j]);
		}
	}
	
	for(i = LOOP_RESET;i < share;i++){
		for(j = LOOP_RESET;j < col;j++){
			scanf("%ld", &ulW_D_act[i][j]);
		}
	}
	

	for(i = LOOP_RESET;i < row;i++){
		for(j = LOOP_RESET;j < col;j++){
			for(k = LOOP_RESET;k < MATRIX_MAX;k++){
				ulW_D_ans[i][j] += ulW_D_inact[i][k] * ulW_D_act[k][j];
			}
		}
	}
	
	for(i = LOOP_RESET;i < row;i++){
		for(j = LOOP_RESET;j < col - 1;j++){
			printf("%ld ", ulW_D_ans[i][j]);
		}
		printf("%ld\n", ulW_D_ans[i][col - 1]);
	}
	
	return RETURN;
}




Measured memory_bytes: 2076
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    DateTimeFormatter sdf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
    LocalDate reiwa = LocalDate.of(2019, 5, 1);

    LocalDate d = LocalDate.parse(S, sdf);
    if (d.isBefore(reiwa)) {
      System.out.println("Heisei");
    } else {
      System.out.println("TBD");
    }
  }
}


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

typedef long long ll;

int main(){
  int n;
  cin>>n;
  int a,b,c,d;
  a=n/1000;
  b=(n%1000)/100;
  c=((n%1000)%100)/10;
  d=n-a*1000-b*100-c*10;
  if(a==b&&b==c){
    cout<<"Yes"<<endl;
  }
  else if(b==c&&c==d){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


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

int main(void)
{
    ll r, D, x;
    cin >> r >> D >> x;

    ll weight = 0;
    ll temp = x;
    for (int i = 0; i < 10; i++)
    {
        weight = r * temp - D;
        cout << weight << endl;
        temp = weight;
    }

    return (0);
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1L << 30
#define long long long
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int N;
int A;
int main(){
	cin >> N;
	rep(i, N){
		cin >> A;
		if (A%2==0){
			if (A%3 == 0 || A%5 == 0){
				continue;
			}
			else{
				cout << "DENIED" << endl;
				exit(0);
			}
		}
	}
	cout << "APPROVED" << endl;
}

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

template<int MAX>
struct Prime {
    vector<bool> is_prime;
    vector<int> primes, min_factor;
    Prime() : is_prime(MAX+1, true), min_factor(MAX+1, -1) {
        is_prime[0] = is_prime[1] = false;
        min_factor[0] = 0, min_factor[1] = 1;
        for (int i = 2; i <= MAX; i++) {
            if (!is_prime[i]) continue;
            primes.emplace_back(i);
            min_factor[i] = i;
            for (int j = i*2; j <= MAX; j += i) {
                is_prime[j] = false;
                if (min_factor[j] == -1) min_factor[j] = i;
            }
        }
    }

    vector<pair<int, int>> prime_factors(int n) {
        vector<pair<int, int>> ret;
        while (n != 1) {
            int p = min_factor[n], sz = 0;
            while (min_factor[n] == p) sz++, n /= p;
            ret.emplace_back(p, sz);
        }
        return ret;
    }

    vector<int> divisor(int n) {
        auto pf = prime_factors(n);
        vector<int> ret = {1};
        for (auto &f: pf) {
            int sz = ret.size(), k = 1;
            while (f.second--) {
                k *= f.first;
                for (int i = 0; i < sz; i++) {
                    ret.emplace_back(ret[i]*k);
                }
            }
        }
        return ret;
    }
};

template<int MAX>
struct ModInv {
    vector<long long> inv;
    ModInv() : inv(MAX+1) {
        for (int i = 1; i <= MAX; i++) {
            if (i == 1) inv[i] = 1;
            else {
                inv[i] = (mod - (mod / i) * inv[mod % i]) % mod;
                if (inv[i] < 0) inv[i] += mod;
            }
        }
    }
    const long long operator[](int i) const { return inv[i]; };
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    constexpr int M = 1000000;
    Prime<M> P; ModInv<M> inv;
    int n; cin >> n;
    vector<int> a(n);
    vector<long long> f(M+1, 0), w(M+1, 0);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        f[a[i]] += a[i];
    }
    for (auto &p: P.primes) {
        for (int k = M / p; k > 0; k--) {
            f[k] += f[k*p];
        } 
    }
    for (int i = 1; i <= M; i++) {
        w[i] = inv[i], f[i] %= mod;
        f[i] = f[i] * f[i] % mod;
    }
    for (auto &p: P.primes) {
        for (int k = M / p; k > 0; k--) {
            w[k*p] -= w[k];
            if (w[k*p] < 0) w[k*p] += mod;
        } 
    }
    long long ans = 0;
    for (int i = 0; i <= M; i++) ans += w[i] * f[i] % mod;
    for (int i = 0; i < n; i++) ans -= a[i];
    cout << (ans % mod + mod) * inv[2] % mod << "\n";
    return 0;
}

Measured memory_bytes: 28920
import numpy as np
N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

my_max = np.max(np.array(A))
max_count = np.count_nonzero(A == my_max)

if max_count > 1:
    [print(my_max) for _ in range(N)]
else:
    my_next_max = np.max(np.array([a for a in A if a != my_max]))
    [print(my_max) if a != my_max else print(my_next_max) for a in A]

Measured memory_bytes: 23284
def resale(n, v, c)
  ret = 0
  n.times do |i|
    ret += (v[i] - c[i]) > 0 ? (v[i] - c[i]) : 0
  end
  ret
end

n = gets.to_i
v = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)
puts resale(n, v, c)

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define f first
#define s second
#define mp make_pair
#define sz size()
#define ll long long
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n, m;
	cin >> n >> m;
	ll ans = (n * m) / __gcd(n, m);
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
int main(){
    int X, N;
    cin >> X >> N;
    vector<long long> P(N);
    for(int i = 0; i < N; i++) cin >> P[i];
    sort(P.begin(), P.end());
    for(int i = 0; i < 200; i++){
        if(!binary_search(P.begin(), P.end(), X - i)){
            cout << X - i << endl;
            return 0;
        }
        if(!binary_search(P.begin(), P.end(), X + i)){
            cout << X + i << endl;
            return 0;
        }
    }
}

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


int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> data(H, vector<char>(W));
  vector<bool> h_check(H);
  vector<bool> w_check(W);
  
  int i, j;
  for(i=0; i<H; i++){
    for(j=0; j<W; j++){
      cin >> data.at(i).at(j);  
    }
  }
  
  for(i=0; i<H; i++){
    for(j=0; j<W; j++){
      if(data.at(i).at(j) == '#'){
      h_check.at(i) = true;
      w_check.at(j) = true;  
      } 
    }
  }
  
  for(i=0; i<H; i++){
    for(j=0; j<W; j++){
      if(h_check.at(i) == true && w_check.at(j) == true){
        cout << data.at(i).at(j);
      }
      if (j == W-1 && h_check.at(i) == true){
        cout << endl;
      }
    }
  }
}


Measured memory_bytes: 256
#include <stdio.h>
    
int main(void){
    
  int A[100][100] = {0};
  int b[100] = {0};
  int sum = 0;
  int n,m;
  register int i,j;
    
  scanf("%d %d",&n,&m);
  for(i = 0;i < n;i++){
    for(j = 0;j < m;j++){
      scanf("%d",&A[i][j]);
    }
  }
  for(i = 0;i < m;i++){
    scanf("%d",&b[i]);
  }
  for(i = 0;i < n;i++){
    sum = 0;
    for(j = 0;j < m;j++){
      sum += (A[i][j] * b[j]);
    }  
    printf("%d\n",sum);
  }
  return 0;
}

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

int main() {
  
  string S;
  cin >> S;
  
  int count = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == 'o') {
      count++;
    }
  }
  
  int nokori = 15 - S.size();
  
  if (nokori + count < 8) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
    
  
  
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int total = sc.nextInt();
    int num = sc.nextInt();
    if(total % num == 0){
      System.out.println(0);
    }else{
      System.out.println(1);
    }
    
  }
}

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

int main(){
    vector<int> vec(0);
    int tmp;
    do{
        cin >> tmp;
        vec.push_back(tmp);
    }while(tmp != 0);
    
    for(int i=0; i<vec.size()-1; i++){
        cout << "Case " << i+1 << ": " << vec[i] << endl;
    }
    
    return 0;
    
}


Measured memory_bytes: 3112
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();
        if(a>b){
            System.out.println("safe");
        }else{
            System.out.println("unsafe");
        }
    }
}


Measured memory_bytes: 35736
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a[] = new int[N];
        for(int i = 0; i<N; i++){
            a[i] = sc.nextInt();
        }
        int time = selsort(a, N);
        for(int i = 0; i<N; i++){
            System.out.printf("%d", a[i]);
            if(i < N-1) System.out.printf(" ");
        }
        System.out.printf("\n%d\n", time);
        sc.close();

    }
    static int selsort(int a[], int size){
        int time = 0;
        int minj;
        for(int i = 0; i<size-1; i++){
            minj = i;
            for(int j = i+1; j<size; j++){
                if(a[j] < a[minj]) minj = j;
            }
            if(i != minj){
                int tmp = a[i];
                a[i] = a[minj];
                a[minj] = tmp;
                time++;
            }
        }
        return time;
    }
}


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

ll ans;

int main() {
  double n;
  cin >> n;
  rep (i, sqrt(n)){
    if ((ll)n % i == 0) ans = (ll)n/i + i - 2;
  }
  cout << ans << endl;
  return 0;
}


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

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

using namespace std;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return mint(-x); }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator+(long long x,const mint& m){ return mint(x)+m; }
mint operator-(long long x,const mint& m){ return mint(x)-m; }
mint operator*(long long x,const mint& m){ return mint(x)*m; }
mint operator/(long long x,const mint& m){ return mint(x)/m; }

mint pow(mint m,long long k){
	mint res=1;
	for(;k>0;k>>=1,m*=m) if(k&1) res*=m;
	return res;
}

mint fact(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		for(;k<=n;k++) memo[k]=memo[k-1]*k;
	}
	return memo[n];
}

using graph=vector<vector<int>>;

void add_undirected_edge(graph& G,int u,int v){
	G[u].emplace_back(v);
	G[v].emplace_back(u);
}

vector<vector<int>> connected_components(const graph& G){
	int n=G.size();
	vector<vector<int>> res;
	vector<bool> vis(n);
	rep(u,n) if(!vis[u]) {
		vis[u]=true;
		res.emplace_back();
		queue<int> Q; Q.emplace(u);
		while(!Q.empty()){
			int v=Q.front(); Q.pop();
			res.back().emplace_back(v);
			for(int w:G[v]) if(!vis[w]) {
				vis[w]=true;
				Q.emplace(w);
			}
		}
	}
	return res;
}

int main(){
	int n; scanf("%d",&n);
	graph G(n);
	vector<bool> to(n);
	rep(u,n){
		int v; scanf("%d",&v); v--;
		if(v<0) to[u]=true;
		else    add_undirected_edge(G,u,v);
	}

	vector<int> namori,tree;
	for(auto C:connected_components(G)){
		bool b=false;
		for(int u:C) if(to[u]) b=true;
		if(!b) namori.emplace_back(C.size());
		else   tree.emplace_back(C.size());
	}
	int m0=namori.size(),m1=tree.size();

	vector<mint> dp(m1+1);
	dp[0]=1;
	rep(i,m1) for(int j=m1;j>0;j--) dp[j]+=tree[i]*dp[j-1];

	mint ans=pow(mint(n-1),m1)*(n-m0);
	for(int i=1;i<=m1;i++){
		mint c=dp[i]; // c 個の木を使ってできるサイクルの総数
		if(i==1) c-=m1;
		ans-=c*fact(i-1)*pow(mint(n-1),m1-i);
	}
	cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 4112
#ifndef Local
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
#endif

#include <bits/stdc++.h>

#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;

#define popCnt(x) (__builtin_popcountll(x))
#define sz(x) ((int)(x.size()))
#define all(v) begin(v), end(v)
typedef long long Long;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  int n;
  cin >> n;

  bool overflow = false;
  Long res = 1;
  while (n--) {
    Long x;
    cin >> x;
    if (x > LLONG_MAX / res) {
      overflow = true;
      continue;
    }
    if (x == 0) {
      res = 0;
      overflow = false;
      break;
    }
    res *= x;
  }

  overflow |= (res > round(1e18L));
  if (overflow) {
    cout << -1 << endl;
  } else {
    cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main(){
  ll n,a,b; cin >> n >> a >> b;
  ll maxi = min(a,b);
  ll mini = max(0LL, a+b-n);
  cout << maxi << " " << mini << endl; 
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import math
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(A: int, B: int, H: int, M: int):
    theta = math.radians(abs(360*(H*60+M)/(60*12)-360*M/60))
    print((A**2 - 2*A*B*math.cos(theta)+B**2)**0.5)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(A, B, H, M)


if __name__ == '__main__':
    main()


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

int main() {
  int year,month,day,z;
  while(cin >> year >> month >> day) {
    z = year * 10000 + month * 100 + day;
    if(z < 18680908)
      cout << "pre-meiji" << endl;
    else if(z <= 19120729)
      cout << "meiji" << " " <<year % 1867 << " " << month << " " << day << endl;
    else if(z <= 19261224)
      cout << "taisho" << " " <<year % 1911 << " " << month << " " << day << endl;
    else if(z <= 19890107)
      cout << "showa" << " " << year % 1925 << " " << month << " " << day << endl;
    else
      cout << "heisei" << " " << year % 1988 << " " << month << " " << day << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n, l;
    cin >> n >> l;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll mv = LONG_LONG_MIN, mi = -1;
    rep(i, n - 1) {
        ll val = a[i] + a[i + 1];
        if (mv < val) {
            mv = val;
            mi = i;
        }
    }
    if (mv < l) {
        cout << "Impossible" << endl;
        return 0;
    }
    cout << "Possible" << endl;
    rep(i, mi) {
        cout << (i + 1) << endl;
    }
    rreps(i, mi, n - 1) {
        cout << (i + 1) << endl;
    }
    return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

void printString(int n) 
{ 
    char str[maxn]; // To store result (Excel column name) 
    int i = 0; // To store current index in str which is result 
  
    while (n > 0) { 
        // Find remainder 
        int rem = n % 26; 
  
        // If remainder is 0, then a 'Z' must be there in output 
        if (rem == 0) { 
            str[i++] = 'z'; 
            n = (n / 26) - 1; 
        } 
        else // If remainder is non-zero 
        { 
            str[i++] = (rem - 1) + 'a'; 
            n = n / 26; 
        } 
    } 
    str[i] = '\0'; 
  
    // Reverse the string and print result 
    reverse(str, str + strlen(str)); 
    cout << str << endl; 
  
    return; 
} 

//START OF CODE ->->->->->->->

void solve()
{
    int n;
    cin>>n;
    printString(n);
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 3656
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>

using namespace std;
int main() {
	int n, a[100000], b;
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> b;
		a[b-1] = i + 1;
	}
	for (int i = 0; i < n; i++) {
		cout << a[i] << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1152
INF = 2000000000
diff = 0

def update(i, v):
  global diff
  d1 = 0
  d2 = 0
  if A[i-1] > A[i]: d1 += 1
  if A[i] > A[i+1]: d1 += 1
  A[i] = v
  if A[i-1] > A[i]: d2 += 1
  if A[i] > A[i+1]: d2 += 1
  diff += (d2 - d1)

def solve():
    global diff
    for i in range(1, N+1):
        if  A[i-1] > A[i]: diff += 1

    if diff == 0: return 0
    q = int(input())
    for i in range(1, q+1):
        a,b = map(int, input().split())
        v1 = A[a]
        v2 = A[b]
        update(a, v2)
        update(b, v1)
        if diff == 0:  return i

    return -1

N = int(input())
A = list(map(int, input().split()))
A.insert(0, -INF)
A.append(INF)
print(solve())



Measured memory_bytes: 39992
//%std
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
const int P=1e9+7;
int add(int a,int b)
{
	return (a+b>=P)?(a+b-P):(a+b);
}
void inc(int &a,int b)
{
	a=add(a,b);
}
int mul(int a,int b)
{
	return 1LL * a * b % P;
}
int fpow(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)
			res=mul(res,a);
		a=mul(a,a);
		b>>=1;
	}
	return res;
}
const int MAXN=2e5+10;
int c[MAXN],fac[MAXN],invfac[MAXN],bin[MAXN];
int binom(int M,int N)
{
	return mul(fac[M],mul(invfac[N],invfac[M-N]));
}
int main()
{
	int n=read();
	bin[0]=fac[0]=1;
	for(int i=1;i<=n;++i)
	{
		c[i]=read();
		bin[i]=mul(bin[i-1],2);
		fac[i]=mul(fac[i-1],i);
	}	
	invfac[n]=fpow(fac[n],P-2);
	for(int i=n-1;i>=0;--i)
		invfac[i]=mul(invfac[i+1],i+1);
	sort(c+1,c+1+n);
	reverse(c+1,c+1+n);
	int ans=0;
	for(int i=1;i<=n;++i)
	{
		int tmp=mul(c[i],bin[n-i]);
		tmp=mul(tmp,add(bin[i-1],mul(i-1,i>=2?bin[i-2]:0)));
		inc(ans,tmp);
	}
	cout<<mul(ans,bin[n])<<endl;
	return 0;
}


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

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

  int X = (floor)(N / 1.08);
  for (int i = 0; floor((X+i) * 1.08) <= N; i++)
  {
    if (floor((X+i) * 1.08) == N) {
      cout << X + i;
      return 0;
    }
  }
  cout << ":(";
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define M 100006
using namespace std;
char A[M],B[M];
set<int>Q[30];
set<int>::iterator it;
int main(){
	scanf("%s",A+1);
	scanf("%s",B+1);
	int n=strlen(A+1),m=strlen(B+1);
	for(int i=1;i<=n;i++){
		int now=A[i]-'a'+1;
		Q[now].insert(i);
	}
	int now=0,ans=0;
	for(int i=1;i<=m;i++){
		int k=B[i]-'a'+1;
		if(Q[k].empty()){
			puts("-1");
			return 0;
		}
		it=Q[k].upper_bound(now);
		if(it==Q[k].end()){
			ans++;
			now=*Q[k].begin();
			continue;
		}
		else now=*it;
	}
	printf("%lld\n",1ll*ans*n+now);
	return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,r,i;
	string s="abcdefghijklmnopqrstuvwxyz";
	string ans="";
	cin>>n;
	while(n!=0)
	{
		n--;
		r=n%26;
		ans=s[r]+ans;
		n=n/26;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3604
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
require 'prime'
def divisors(num)
  return [1] if num == 1

  pows = []
  # 0乗、1乗・・・した値を入れる
  num.prime_division.each do |b, r|
    pow = []
    0.upto(r).each do |n|
      pow << b ** n
    end

    pows << pow
  end

  first_array = pows.shift
  return first_array if pows.size == 0

  result = first_array.product(*pows)
  result.map do |item|
    item.inject { |sum, i| sum * i }
  end.sort
end

n=gi
a=gsmi

ans=1

# 最小2つの約数のどれかが答え
mins=a.min(2)
lcms = desc (divisors(mins[0])+divisors(mins[1])).uniq
lcms.each do |num|
  cnt=0
  a.each do |aa|
    next if aa%num==0
    cnt+=1
    break if cnt>1
  end
  if cnt<=1
    ans=num
    break
  end
end
puts ans

Measured memory_bytes: 10172
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a 
def gcd3(a,b,c):
    return gcd(gcd(a,b), c)

K = int(input())
ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            ans += gcd3(i,j,k)
print(ans)

Measured memory_bytes: 73892
n=int(input())
hs=list(map(int,input().split()))[::-1]
for i in range(n-1):
    d=hs[i]-hs[i+1]
    if d==-1:
        hs[i+1]-=1
    elif d<-1:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 14396
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, A[101010];

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) scanf("%d", A + i);
	sort(A, A + N);
	reverse(A, A + N);

	for (int i = N - 1; i >= 0; --i) {
		if (A[i] - 1 >= i) {
			int grundy = 0;

			int up = A[i] - 1 - i;
			int right = 0;
			for (int j = i + 1; j < N; ++j) if (A[j] - 1 >= i) ++right;
			else break;
		//	printf("%d %d\n", up, right);
			if (up % 2 != right % 2) grundy = 2;
			else grundy = up % 2;
			puts(grundy ? "First" : "Second");
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define ll long long
using namespace std;
int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
const int inf=0x3f3f3f3f;

int n,a[200010],b[200010];

int main(){
	n=read();
	for(int i=1;i<=n;i++)a[i]=read(),b[i]=a[i];
	sort(b+1,b+n+1);
	int x=b[n/2];
	for(int i=1;i<=n;i++){
		if(a[i]<=x)printf("%d\n",b[n/2+1]);else printf("%d\n",x);
	}
	
	
	return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
	int a,b;
	scanf("%i%i",&a,&b);
	if(b%2==0 && b>=a*2 && b<=a*4)
	{
		printf("Yes");
		return 0;
	}
	printf("No");
    return 0;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

void solve(istream& cin, ostream& cout) {
  ll a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  if (v <= w) {
    cout << "NO" << endl;
    return;
  }
  ll d = abs(b - a);
  ll d2 = (v - w) * t;
  if (d <= d2) {
    cout << "YES" << endl;
    return;
  }
  cout << "NO" << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif

Measured memory_bytes: 3568