akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import traceback
import logging

def main():
    try:
        N = int,raw_input()
        A = map(int,raw_input().split())
        A_size = len(A)
        distance = now_pos = 0
        for i in range(A_size):
            distance = distance + abs(now_pos - A[i])
            now_pos = A[i]

        distance = distance + abs(now_pos)
        for i in range(A_size):
            if i == A_size-1:
                print distance - abs(A[i-1] - A[i]) - abs(A[i]) + abs(A[i-1])
            elif i == 0:
                print distance - abs(A[i]) - abs(A[i] - A[i+1]) + abs(A[i+1])
            else:
                print distance - abs(A[i-1] - A[i]) - abs(A[i] - A[i+1]) + abs(A[i-1] - A[i+1])

    except:
        traceback.print_exc()
        return 0

main()


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

int main(){
  int n;
  cin >> n;
  string s="";
  while(n!=0){
    if(n%2!=0){
      n--;
      s='1'+s;
    }else{
      s='0'+s;
    }
    n/=-2;
  }
  if(s==""){
    s='0';
  }
  cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};

int main() {
  int n,q;
  cin >>n >> q;
  vi a(n);
  vi pi(n+1,-1);
  vector<vi> p(n);
  rep(i,n){
    cin >> a[i];
  }
  rep(i,n){
    int l = pi[a[i]];
    if(l != -1)p[l].push_back(i);
    pi[a[i]] = i;
  }
  vector<vp> qs(n);
  rep(i,q){
    int l,r;
    cin >> l >> r;
    l--;r--;
    qs[l].emplace_back(r,i);
  }
  vi ans(q);
  BIT<int> d(n);
  for(int x = n-1;x>=0;x--){
    for(int y:p[x])d.add(y,1);
    for(P query : qs[x]){
      int r = query.first, i = query.second;
      ans[i] = (r-x+1) - d.sum(r);
    }
  }
  rep(i,q)cout<<ans[i]<<endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int K;
  cin >> K;
  for(int i = 0; i < N; i++){
    if(S.at(i) != S.at(K - 1)){
      S.at(i) = '*';
    }
  }
  cout << S << endl;
}


Measured memory_bytes: 256
a,b,k=map(int,input().split())
if(2*k>(b-a+1)):
  for i in range(a,b+1):
    print(i)
else:
  for i in range(a,a+k):
    print(i) 
  for i in range(b-k+1,b+1):
    print(i)

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

a.sort()
b.sort()
c.sort()
ans = 0
for i in b:
  x = bisect.bisect_left(a, i)
  y = bisect.bisect_right(c, i)
  ans = ans + (x * (n-y))
print(ans)

Measured memory_bytes: 29492
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long c[51][51];
long long conb_table(int n){
  for(int i=0;i<=n;i++){
    for(int j=0;j<=i;j++){
      if(j==0||j==i){
        c[i][j]=1ll;
      }else{
        c[i][j]=(c[i-1][j-1]+c[i-1][j]);
      }
    }
  }
}

int main(){
  int n,a,b,i,j,k;
  cin >> n >> a >> b;
  conb_table(n);
  vector<long long> v(n);
  for(i=0;i<n;i++)cin >> v[i];
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  long long sum=0;
  long long ch = 1e16;
  long long cnt_use=1;
  for(i=0;i<a;i++){
    sum+=v[i];
    if(ch == v[i])cnt_use++;
    else{
      cnt_use=1;
      ch=v[i];
    }
  }
  cout << fixed << (double)sum/a << endl;
  long long cnt = count(v.begin(),v.end(),ch);
  long long ret=0ll;
  if(v[0]!=ch)ret=c[cnt][cnt_use];
  else{
    for(i=a;i<=b;i++)ret+=c[cnt][i];
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
from itertools import accumulate
import bisect

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a_acc = [0] + list(accumulate(a))  # aを0冊読む=1冊も読まない場合があるので、[0]を先頭に追加します
b_acc = list(accumulate(b))  # bisect_rightでは、x以下の要素がいくつあるか？を求めるので、こちらに0は入れません

ans = 0
for an in range(n + 1):
    rem = k - a_acc[an]
    if rem < 0:
        # aをこれ以上読めません
        break

    bn = bisect.bisect_right(b_acc, rem)
    ans = max(ans, an + bn)

print(ans)

Measured memory_bytes: 133372
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int c;
	cin >> c;
	int a;
	cin >> a;
	int b;
	cin >> b;

	if ((10 * a + b) % 4 == 0)
	cout << "YES" << endl;
	else
	cout << "NO" << endl;

	
	
}

Measured memory_bytes: 256
#include <iostream>

void outputField(char** field, int row, int column) {
    for (int i = 0; i < row; i++) {
        for (int j = 0; j < column; j++) {
            std::cout << field[i][j];
        }
        std::cout << std::endl;
    }   
}

char countMine(char** field, int rowIndex, int columnIndex) {
    char counter = 0;
    for (int i = rowIndex - 1; i <= rowIndex + 1; i++) {
        for (int j = columnIndex - 1; j <= columnIndex + 1; j++) {
            if(field[i][j] == '#') {
                counter++;
            }
        }
    }
    return counter;
}

int main() {
    int row = 0;
    int column = 0;
    
    // 入力からフィールドを作成
    std::cin >> row >> column;
    char** field = new char*[row];
    for (int i = 0; i < row; i++) {
        field[i] = new char[column];
    }
    for (int i = 0; i < row; i++) {
        for (int j = 0; j < column; j++) {
            std::cin >> field[i][j];
        }
    }
    
    // フィールドからカウント用フィールドを作成
    const static char INITIAL_VALUE = 0;
    char** countField = new char*[1 + row + 1];
    countField[0] = new char[1 + column + 1];
    countField[row + 1] = new char[1 + column + 1];
    for (int i = 0; i < 1 + column + 1; i++) {
        countField[0][i] = INITIAL_VALUE;
        countField[row + 1][i] = INITIAL_VALUE;
    }
    for (int i = 0; i < row; i++) {
        countField[i + 1] = new char[1 + column + 1];
        countField[i + 1][0] = INITIAL_VALUE;
        for (int j = 0; j < column; j++) {
            countField[i + 1][j + 1] = field[i][j] == '#' ? '#' : INITIAL_VALUE;
        }
        countField[i + 1][column + 1] = INITIAL_VALUE;
    }
    
    // カウントを行う
    for (int i = 1; i < row + 1; i++) {
        for (int j = 1; j < column + 1; j++) {
            if (countField[i][j] == 0) {
                countField[i][j] = countMine(countField, i , j) + '0';
            }
        }
    }
    
    // カウント用フィールドから出力用フィールドを作成
    char** outField = new char*[row];
    for (int i = 0; i < row; i++) {
        outField[i] = new char[column];
    }
    for (int i = 0; i < row; i++) {
        for (int j = 0; j < column; j++) {
            outField[i][j] = countField[i + 1][j + 1];
        }
    }
    
    outputField(outField, row, column);
    
    for (int i = 0; i < row; i++) {
        delete[] field[i];
        delete[] outField[i];
    }
    delete[] field;
    delete[] outField;
    
    for (int i = 0; i < 1 + row + 1; i++) {
        delete[] countField[i];
    }
    delete[] countField;
}


Measured memory_bytes: 3584
import java.util.Scanner

import scala.collection.mutable.ArrayBuffer


object Main {

  // u: from
  // v: to
  case class Edge(u: Int, v: Int, w: Long)

  def read() = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    // ここ、0オリジン化した方がいい
    val edges = IndexedSeq.fill(n - 1)(Edge(sc.nextInt(), sc.nextInt(), sc.nextInt()))
    (n, edges)
  }

  def read2() = {
    val input = io.Source.stdin.getLines()
    val n = input.next().toInt
    val edges = IndexedSeq.fill(n - 1) {
      val strs = input.next().split(" ")
      Edge(strs(0).toInt, strs(1).toInt, strs(2).toInt)
    }
    (n, edges)
  }

  def read3() = {
    import scala.io.StdIn._
    val n = readInt()
    val edges = IndexedSeq.fill(n - 1){
      val strs = readLine().split(" ")
      Edge(strs(0).toInt, strs(1).toInt, strs(2).toInt)
    }
    (n, edges)
  }

  def solve(n: Int, edges: IndexedSeq[Edge]): IndexedSeq[Int] = {
    val nextList = IndexedSeq.fill(n + 1)(ArrayBuffer.empty[Edge])
    for (edge <- edges) {
      val from = edge.u
      val to = edge.v
      nextList(from).append(edge)
      nextList(to).append(Edge(to, from, edge.w))
    }
    val visited = Array.fill(n + 1)(false)
    // 1から
    visited(1) = true
    val open: java.util.Queue[Int] = new java.util.ArrayDeque[Int]()
    //add, remove
    open.add(1)
    //白:false ,黒:true
    val colors = Array.fill(n + 1)(true)
    colors(1) = false


    while (!open.isEmpty) {
      val current = open.remove()
      for (edge <- nextList(current)) {
        val next = edge.v
        if (!visited(next)) {
          val w = edge.w
          if (w % 2 == 0) {
            colors(next) = colors(current)
          } else {
            colors(next) = !colors(current)
          }
          visited(next) = true
          open.add(next)
        }
      }
    }
    colors.takeRight(n).map(p => if (p) 1 else 0)
  }

  def output1(result: IndexedSeq[Int]) = {
    result.foreach(println)
  }

  def output2(result: IndexedSeq[Int]) = {
    result.foreach(System.out.println)
  }

  def output3(result: IndexedSeq[Int]) = {
    val out = new java.io.PrintWriter(System.out)
    result.foreach(out.println)
    out.flush()
  }

  def main(args: Array[String]): Unit = {
    val (n, edges) = read3()
    output3(solve(n, edges))
  }
}

Measured memory_bytes: 70548
#include <bits/stdc++.h>
#define ll long long
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++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
 
ll MOD = 1000000007;
ll INF =1<<29;
 
int main(){
     int n,k;
     cin >> n >> k;
     vector<int> p(n);
     rep(i,n)cin >> p[i];
     int tot = 0;
     int omax=-1;
     if(k==1){
        rep(i,n){
            omax = max(omax,p[i]);
        }
        double oans = double(omax+1)/2;
        cout << fixed<<setprecision(8) << oans <<endl;
        return 0;
     }
     double nans;
     if(k==n){
         rep(i,n){
             nans += double(p[i]+1)/2;
         }
         cout << fixed <<setprecision(8) << nans <<endl;
         return 0;
     }
     vector<int> s(n);
     s[0]=p[0];
     rep(i,n-1){
         s[i+1] = s[i]+p[i+1];
     }
     int ma = s[k-1];
     int ans;
     for(int i = 1;i+k<n;++i){
          if(s[i+k]-s[i]>ma){
              ma = s[i+k]-s[i];
              ans = i;
          }
     }
     double kita =0;
     for(int i = ans;i<ans+k;++i){
          kita+=(double)(p[i+1]+1)/2;
     }
     cout << fixed<<setprecision(8)<<kita <<endl;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;

int ans;
int N;
vi h;

void water(int l, int r) // [l, r)
{
    if(l == r) return;
    int mh = INF;
    for(int i = l; i < r; i++) mh = min(mh, h[i]);
    for(int i = l; i < r; i++) h[i] -= mh;
    ans += mh;
    for(int i = l; i < r; i++)
    {
        if(h[i] == 0)
        {
            water(l, i);
            water(i+1, r);
            break;
        }
    }
}

void solve()
{
    cin >> N;
    h.resize(N); REP(i, N) cin >> h[i];
    water(0, N);
    cout << ans << endl;
}
    
int main() 
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
# K - Stones
def main():
    N, K, *A = map(int, open(0).read().split())
    dp = [False] * (K + 1)  # dp[i] := a player can win if i stones remain in their turn. (dp[0] := lose)
    for i in range(K):
        if dp[i]:
            continue
        for a in A:
            if i + a > K:
                break
            dp[i + a] = True
            if dp[-1]:
                print("First")
                return
    print("Second")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3828
n = int(input())
s = list(input() for _ in range(n))
m = int(input())
t = list(input() for _ in range(m))

res = []
for i in range(n):
    res.append(s.count(s[i]) - t.count(s[i]))
if max(res) > 0:
    print(max(res))
else:
    print(0)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep for(int i = 0;i<n;i++)
 
int main(void){
  int n;
  cin >> n;
  int a[n];int b[n];
  rep{
    cin >> a[i];
  }
  rep{
    cin >> b[i];
  }
  int xy = 0;
  rep{
    if(a[i] - b[i] > 0){
      xy += a[i] - b[i];
    }
  }
  cout << xy << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define DEC(i, a, b) for (int i = (a); i > (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
typedef long long ll;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
const ll LINF = (int)1e18;
const double EPS = 1e-9;

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

  int a,b;
  cin >> a >> b;
  int socket = 1;
  int ans = 0;
  while (socket < b) {
    --socket;
    socket += a;
    ++ans;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> P;

int par[110000]; //親
int ran[110000]; //木の深さ

// n要素を初期化
void init(int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    ran[i]=0;
  }
}

//木の根を求める
int find(int x){
  if(par[x]==x){
    return x;
  }else{
    return par[x]=find(par[x]);
  }
}

//xとyの属する集合を併合
void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y) return;

  if(ran[x]<ran[y]){
    par[x]=y;
  }else{
    par[y]=x;
    if(ran[x]==ran[y]) ran[x]++;
  }
}

//xとyが同じ集合に属するか否か
bool same(int x,int y){
  return find(x)==find(y);
}

int main(){
  bool flag=true;
  int N,M,a[100],b[100],count=0;
  cin>>N>>M;
  for(int i=0;i<M;i++){
    cin>>a[i]>>b[i];
  }

  for(int i=0;i<M;i++,flag=true){
    init(N+1);

    for(int j=0;j<M;j++){
      if(i==j) continue;
      unite(a[j],b[j]);
    }

    for(int j=1;j<N;j++){
      if(same(j,j+1)==false) flag=false;
    }
    if(!flag) count++;
  }

  cout<<count<<endl;
}


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

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
    	int N, add;
    	String s, t;
    	
        void solve(InputReader in, PrintWriter out) {
        	N = in.nextInt();
        	add = N;
        	s = in.next();
        	t = in.next();
        	
        	for (int i = 0; i < N; i++) {
				if (s.substring(i, N).equals(t.substring(0, N - i))) {
					add = i;
					break;
				}
			}
        	
        	out.println(N + add);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

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

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

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

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int size) {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
    }
}


Measured memory_bytes: 21460
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
    int n,a[110],alice = 0,bob = 0;
    cin >> n;
    for(int i = 0;i < n;i++){cin >> a[i];}
    sort(a,a + n,greater<int>());
    for(int i = 0;i < n;i++)
    {
        if((i + 1) % 2 == 1){alice += a[i];}
        else{bob += a[i];}
    }
    cout << alice - bob << endl;
    return 0;
}

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


int main(void)
{
    string str;
    cin >> str;
    int size = str.size();
    
    long long sum = 0;
    for(unsigned int i = 0, e = pow(2,size-1);i < e; i++){
        string s = str;
        for(int j = 0; j < size; j++) {
            if ( (i & (1 << j)) != 0 ) {
                s.insert(s.begin()+size-j-1,' ');
            }
        }
        //cerr << s << endl;
        vector<long long> v;
        stringstream ss(s);
        string buf;
        while(getline(ss,buf,' ')){
            //cerr << i << " " << buf << endl;
            v.push_back(stoll(buf));
        }
        sum += accumulate(v.begin(),v.end(),0LL);
    }
    cout << sum << endl;
            
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.PriorityQueue;

class Shop implements Comparable<Shop> {
    long price;
    int number;

    public Shop(long price, int number) {
        this.price = price;
        this.number = number;
    }

    public void setPrice(long price) {
        this.price = price;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public long getPrice() {
        return price;
    }

    public int getNumber() {
        return number;
    }

    @Override
    public int compareTo(Shop shop) {
        if (this.getPrice() > shop.getPrice()) {
            return 1;
        } else if (this.getPrice() < shop.getPrice()) {
            return -1;
        } else {
            return 0;
        }
    }
}


public class Main {

    private static int inputNum = 0;
    private static int drinkNeed = 0;

    private static long solver(Shop[] shop) {

        PriorityQueue<Shop> pq = new PriorityQueue<>();
        for (int i = 0; i < inputNum; i++) {
            pq.add(shop[i]);
        }

        int drinkNum = 0;
        long cost = 0;
        while (pq.size() != 0) {
            Shop s = pq.remove();
            if(drinkNum +s.getNumber() >= drinkNeed){

                return cost + (s.getPrice()* (drinkNeed - drinkNum));
            }else {
                drinkNum += s.getNumber();
                cost += s.getPrice() * s.getNumber();
            }
        }

        return 0;

    }


    public static void main(String[] args) {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(is);

        try {
            String[] inputArray = br.readLine().split(" ");
            inputNum = Integer.parseInt(inputArray[0]);
            drinkNeed = Integer.parseInt(inputArray[1]);
        } catch (Exception e) {
            e.printStackTrace();
        }


        Shop[] shop = new Shop[inputNum];
        try {
            for (int i = 0; i < inputNum; i++) {
                String[] inputArray = br.readLine().split(" ");
                shop[i] = new Shop(Integer.parseInt(inputArray[0]), Integer.parseInt(inputArray[1]));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(solver(shop));

    }
}

Measured memory_bytes: 48188
### constant

DXYS = [[1, 0], [0, -1], [-1, 0], [0, 1]]

### main

loop do
  w, h = gets.split.map(&:to_i)
  break if (w | h) == 0

  tls = h.times.map{w.times.map{true}}
  sx = sy = 0

  for y in (0...h)
    line = gets.strip
    for x in (0...w)
      case line[x]
      when '#'
        tls[y][x] = false
      when '@'
        sx = x
        sy = y
      end
    end
  end
  #p tls
  #p [sx, sy]

  visited = h.times.map{w.times.map{false}}
  visited[sy][sx] = true
  count = 1
  q = [[sx, sy]]

  while ! q.empty?
    x, y = q.shift

    DXYS.each do |dx, dy|
      x0 = x + dx
      y0 = y + dy
      if x0 >= 0 && x0 < w && y0 >= 0 && y0 < h &&
          tls[y0][x0] && ! visited[y0][x0]
        visited[y0][x0] = true
        count += 1
        q << [x0, y0]
      end
    end
  end

  puts count
end

Measured memory_bytes: 6136
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int l=sc.nextInt();
    int r=sc.nextInt();
    int tmp=10000;
    if(r-l>=2019){
      System.out.println(0);
      return;
    }else{
      l=l%2019;
      r=r%2019;
      for(int i=l;i<=r-1;i++){
        for(int j=l+1;j<=r;j++){
          if(tmp>(i*j)%2019){
            tmp=(i*j)%2019;
          }
        }
      }
      System.out.println(tmp);
      
      
    }
    
  }
  

  
}

Measured memory_bytes: 21844
import java.io.*;
import java.util.*;
class Main {
  public static int result = 0;
  public static int a = 0;
  public static int b = 0;
  public static int c = 0;
  public static int k = 0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        a = sc.nextInt(); //1のカード枚数
        b = sc.nextInt(); //0のカード枚数
        c = sc.nextInt(); //-1のカード枚数
        k = sc.nextInt(); //引くカードの枚数
        k = calc(a,k, 1);
        k = calc(b,k, 0);
        k = calc(c,k, -1);
        System.out.println(result);
    }
    public static int calc(int num, int k , int card){
      if(k==0) return k;
      if(num >= k){
        result += k*card;
        k=0;
      }else {
        result += num*card;
        k-=num;
      }
      return k;
    }
}


Measured memory_bytes: 35680
N = int(input())
T = list(map(int, input().split()))
V = list(map(int, input().split()))

MAX_V = [0]
# グラフを整える準備
for v, t in zip(V, T):
    # 転換地点では低い方に合わせる
    MAX_V[-1] = min(MAX_V[-1], v)
    for ti in range(t * 2):
        MAX_V.append(v)

# 前から
for i in range(1, len(MAX_V)):
    MAX_V[i] = min(MAX_V[i - 1] + 0.5, MAX_V[i])

MAX_V[-1] = 0
# 後ろから
for i in range(len(MAX_V) - 2, -1, -1):
    MAX_V[i] = min(MAX_V[i], MAX_V[i + 1] + 0.5)

ans = 0
for i in range(len(MAX_V) - 1):
    ans += (MAX_V[i] + MAX_V[i + 1]) * 0.5 / 2

print(ans)


Measured memory_bytes: 3500
import sys
from bisect import bisect_left
A, B, Q = map(int, input().split())
minf, inf = -(10**18), 10**18
jinja = [minf] + list(map(int, (sys.stdin.readline() for _ in [0]*A))) + [inf]
tera = [minf] + list(map(int, (sys.stdin.readline() for _ in [0]*B))) + [inf]
queries = list(map(int, sys.stdin))
 
for q in queries:
    i = bisect_left(jinja, q)
    j = bisect_left(tera, q)
    left_jinja, right_jinja = q-jinja[i-1], jinja[i]-q
    left_tera, right_tera = q-tera[j-1], tera[j]-q
 
    res = min(
        max(left_jinja, left_tera),
        left_jinja + right_tera + min(left_jinja, right_tera),
        right_jinja + left_tera + min(right_jinja, left_tera),
        max(right_jinja, right_tera)
    )
    print(res)

Measured memory_bytes: 135900
N,M = map(int,input().split())
# 正解数
SEIKAI = 0
# ペナルティ
PENALTI = 0

L = [0] * 100001

for i in range(M):
    _P,S = input().split()
    P = int(_P)
    if S == 'WA' and L[P] != -1:
        L[P] += 1
    elif S == 'AC' and L[P] != -1:
        SEIKAI += 1
        PENALTI += L[P]
        # -1は正解済みのフラグ
        L[P] = -1

print(SEIKAI,PENALTI)

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll
#define INF 1e16
#define mod 1000000007
int main(){
    string s,t;
    cin>>s>>t;
    bool flg = false;
    for(int i = s.size()-t.size();i>-1;i--){
    // rep(i,s.size()-t.size()+1){
        flg = true;
        repl(j,i,i+t.size()){
            if(s[j]=='?' || s[j]==t[j-i]) continue;
            else flg = false;
        }
        // cout<<i<<endl;
        if(flg){
            string ans="";
            rep(k,s.size()){
                if(k>=i and k < i + t.size()) ans+=t[k-i];
                else if(s[k]!='?') ans+=s[k];
                else ans+='a';
            }
            cout<<ans<<endl;
            return 0;
        }
    }
    cout<<"UNRESTORABLE"<<endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<long> L(N+1);
  L.at(0) = 2;
  L.at(1) = 1;
  for(int i=2; i < N+1; i++){
    L.at(i) = L.at(i-2)+L.at(i-1);
  }
  cout << L.at(N) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rp(i,n) for(ll i=0; i<n; i++)
using namespace std;
using ll=long long;
int main(){
    ll n;
    string s;
    cin >> n >> s;
    ll Rc=0,Gc=0,Bc=0;
    rp(i,n){
        if(s.at(i)=='R') Rc++;
        if(s.at(i)=='G') Gc++;
        if(s.at(i)=='B') Bc++;
    }
    ll ans=Rc*Bc*Gc;
    for(ll i=1; i<=(n-1)/2; i++){
        for(ll j=0; j<n-i-i;j++){
            if(s.at(j)!=s.at(j+i)&&s.at(j+i)!=s.at(j+i+i)&&s.at(j)!=s.at(j+i+i)) ans--;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll N, K; cin >> N >> K;
  ll A[N]; rep(i,N) cin >> A[i];
  rep(i,min(100ll,K)) {
    ll ta[N+1] = {};
    rep(j,N) {
      ll l = max(0ll,j-A[j]), r = min(N, j+A[j]+1);
      ta[l]++; ta[r]--;
    }
    // debug(ta,ta+(N+1));
    rep(j,N) A[j] = j==0 ? ta[j] : A[j-1]+ta[j];
    // debug(A,A+N);
  }
  
  debug(A,A+N);
  return 0;
}

Measured memory_bytes: 6756
#include<stdio.h>

int main()
{
    int A, B;
    scanf("%d %d", &A, &B);
    int total = A + B + 1;
    
    char str[100];
    scanf("%s", str);
    
    int i, count = 0;
    
    if (str[A] == '-')
    {
        for (i = 0; i < total; i++)
        {
            if (str[i] >= '0' && str[i] <= '9')
            {
                count++;
            }
        }
        
        if (count == total - 1)
        {
            printf("Yes\n");
        }
        
        else
        {
            printf("No\n");
        }
    }
    
    else
    {
        printf("No\n");
    }
    
    return 0;
}

Measured memory_bytes: 1620
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
    public static void main (String[] args) throws java.lang.Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int N = Integer.parseInt(line);
        int ans = N*800 - (N/15)*200;
        System.out.println(ans);
    }
}

Measured memory_bytes: 21076
#include <stdio.h>

int T;
int pa[100001];
int si[100001];
int dg[100001];

int cDepth(int i) {
  if(pa[i] == -1) return 0;
  return cDepth(pa[i]) + 1;
}

int cHeight(int i) {
  int j, h;
  h = 0;
  
  for(j = 0; j < T; ++j) {
    if(pa[j] == i) {
      int tmp = cHeight(j) + 1;
      if(tmp > h) h = tmp;
    }
  }
  return h;
}

int main() {
  int i,j;
  
  scanf("%d", &T);
  for(i = 0; i < T; ++i) {
    pa[i] = -1;
    si[i] = -1;
    dg[i] = 0;
  }
  for(i = 0; i < T; ++i) {
    int id, le, ri;
    scanf("%d %d %d", &id, &le, &ri);
    if(le != -1) {
      pa[le] = id;
      si[le] = ri;
      ++dg[id];
    }
    
    if(ri != -1) {
      pa[ri] = id;
      si[ri] = le;
      ++dg[id];
    }
  }

  for(i = 0; i < T; ++i) {
    int depth = cDepth(i);
    
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",
           i, pa[i], si[i], dg[i], depth, cHeight(i));
    if(depth == 0) {
      printf("root\n");
    } else if(dg[i] == 0) {
      printf("leaf\n");
    } else {
      printf("internal node\n");
    }
  }
  
  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=200005;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
int len;
ll ans=0;
string s;
void dfs(int now,ll gg)
{
    if(now>=len)
    {
        ans+=gg;
        return ;
    }
    for(int i=0; i<len; i++)
    {
        ll sum=0;
        if(now+i<len)
        {
            for(int j=now; j<=now+i; j++)
            {
                sum=sum*10+(s[j]-'0');
            }
            //cout<<gg<<" "<<sum<<" "<<ans<<endl;
            dfs(now+i+1,gg+sum);
        }
    }
}
int main()
{
    std::ios::sync_with_stdio(false);
    while(cin>>s)
    {
        len=s.length();
        ans=0;
        dfs(0,0);
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
# 正整数Xの正約数個数をf(X)とするときの \sum_(K=1)^N {K*f(K)}
# 正整数jの倍数でありN以下のものの総和をg(j)とするときの \sum_(j=1)^N g(j)

N = int(input())
ans = 0
for j in range(1, N+1):
  # Y = N/j とすると g(j) = j+2j+...+Yj = (1+2+...+Y)j = Y(Y+1)/2 *j
  g = (N//j)*(N//j+1)*j//2
  ans += g
print(ans)

Measured memory_bytes: 9136
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{ min, max };

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

#[allow(dead_code)]
const M: i64 = 1_000_000_007;

fn pow(a: usize, b: usize) -> usize {
    if b == 0 {
        1
    } else if b == 1 {
        a
    } else if b % 2 == 0 {
        pow(a * a, b / 2)
    } else {
        pow(a * a, b / 2) * a
    }
}

fn main() {
    let mut sc = Scanner::new();
    let m: usize = sc.cin();
    let k: usize = sc.cin();

    if m == 0 {
        if k == 0 {
            put!("0 0");
        } else {
            put!("-1");
        }
    } else if m == 1 {
        if k == 0 {
            put!("0 0 1 1");
        } else {
            put!("-1");
        }
    } else {
        let m2 = pow(2, m);
        if k < m2 {
            for i in 0..m2 {
                if i == k { continue }
                print!("{} ", i);
            }
            print!("{} ", k);
            for i in (0..m2).rev() {
                if i == k { continue }
                print!("{} ", i);
            }
            println!("{} ", k);

        } else {
            put!("-1");
        }
    }
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 5884
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005

long long n,a,b;

int32_t main(){
    ios_base :: sync_with_stdio(0);
    cin >> n >> a >> b;
    if(a>b) cout << 0;
    else if(n==1 && a==b) cout << 1;
    else if(n==1) cout << 0;
    else cout << (b-a)*(n-2)+1;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void){
    double a, b, c, PI=acos(-1);
   
   scanf("%lf %lf %lf", &a, &b, &c);

   c = c/180*PI;
   
   printf("%.11lf\n", a*b*sin(c)/2);
   printf("%.13lf\n", a + b + sqrt(a*a + b*b - 2*a*b*cos(c)));
   printf("%.13lf\n", b*sin(c));
   
   return 0;
}


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

using i64 = int64_t;

int main(){
    int r, g, b, n;
    cin >> r >> g >> b >> n;
    i64 ans = 0;
    for(int i=0;i<=3000;++i){
        for(int j=0;j<=3000;++j){
            int m = n - (i*r + j*g);
            if(m<0 || m%b != 0)continue;
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

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

  ll ans;
  if (a%2 == b%2) ans = (b-a)/2;
  else ans = min(a-1,n-b) + 1 + (b-a-1)/2;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int n;
    cin>>n;
    vector<long long int> v(n);
    REP(i,n){
        cin>>v[i];

    }

    long long int result=0;
    REP(i,n-1){
        FOR(j,i+1,n){
            result+=v[i]*v[j];
            //cout << i << " " << j << endl;
        }
    }
    cout<<result<<endl;

    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
    #define ll long long
    #define rep(i,a,b) for(i=a;i<b;i++)
    #define pb push_back
    #define all(v) v.begin(),v.end()
    #define F first
    #define S second
    #define vi vector < ll  int >
    #define CLR(a) memset((a),0,sizeof(a))
    #define mp make_pair
    #define hell 1000000007
    using namespace std;

void solve()
{
 ll i,j=1,k,n,m=0,f,s1=0,x,c=1,t;
 string s;
 cin>>s;
 string s2=s; n=s.size();
 reverse(all(s2));
 if(s2!=s) {cout<<"No"; return;}
 s2=s.substr(0,(n-1)/2);
 string ss=s2; //cout<<ss;
 reverse(all(ss));
 if(ss!=s2) {cout<<"No"; return;}
 s2=s.substr((n+3)/2-1);
 ss=s2;
 reverse(all(ss));
 if(ss!=s2) {cout<<"No"; return;}
 cout<<"Yes";
}


 //}

    signed main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int t=1;
         //cin>>t;
        while(t--)
        solve();
    }


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

int ary[1010];
int main(){
	int N,M;
	cin>>N>>M;
	for(int i=1;i<=N;i++){
		cin>>ary[i];
	}

	for(int i=1;i<=M;i++){
		for(int j=1;j<N;j++){
			if(ary[j]%i>ary[j+1]%i){
				swap(ary[j],ary[j+1]);
			}
		}
	}

	for(int i=1;i<=N;i++) cout<<ary[i]<<endl;
	return 0;
}

Measured memory_bytes: 3076
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	s := Scan()
	d := make(map[rune]struct{})
	for _, r := range s {
		d[r] = struct{}{}
	}
	if len(s) == len(d) {
		fmt.Println("yes")
	} else {
		fmt.Println("no")
	}
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
const int INF = 1e9;
using namespace std;

unordered_map<ll,int> prime_factor(ll n){
    unordered_map<ll,int> ret;
    for(ll i=2; i*i<=n; i++){
        while(n % i == 0){
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n]=1;
    return ret;
}
//for(auto p:prime_factor(i))

main() {
    ll N,P; cin >> N >> P;
    ll ans=1;
    for(auto p:prime_factor(P)){
        if(p.second/N>0)
        rep(i,p.second/N)
        ans*=p.first;
    }
    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
const int MAXN = 1e5 + 2;
int n, arr[MAXN];
ll ans;

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 0;i < n;i++)
        cin >> arr[i];

    for(int i = 0;i < n;i++)
    {
        ans += 1LL * arr[i] / 2;
        arr[i] %= 2;
        int p = min(arr[i], arr[i + 1]);
        arr[i] -= p;
        arr[i + 1] -= p;
        ans += 1LL * p;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<int,vector<int>>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;



int main()
{

    int N;
    cin >> N;
    vi p(N);
    in(N,p);
    int ans = 0;
    rep(i,N){
        if(i==N-1 && p[i]==i+1) ans++;
        else if(p[i] == i+1){
            swap(p[i],p[i+1]);
            ans++;
        }
    }
    out(ans);

    return 0;
}


Measured memory_bytes: 768
#include <iostream>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	int a[100];
	cin>>n;
	for(int i=0; i<n; i++) cin>>a[i];
	cout<<a[n-1];
	for(int i=n-2; i>=0; i--) cout<<' '<<a[i];
	cout<<'\n';
	return 0;
}



Measured memory_bytes: 3172
def solve(N,K,S):
    if K != 0 and K != N:
        for i in range(0, K):
            print(S)
        for i in range(K, N):
            if S == 1:
                print(S+1)
            else:
                print(S-1)
    elif K == 0:
        for i in range(N):
            if S == 1:
                print(S+1)
            else:
                print(S-1)
    elif K == N:
        for i in range(N):
            print(S)
N ,K ,S = map(int,input().split())
solve(N,K,S) 

Measured memory_bytes: 9388
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){

    int s,fr,ba;
    bool flagFr = true,flagBa = true;

    cin >> s;
    fr = s/100;
    ba = s%100;

    if(fr == 0 || fr > 12)flagFr = false;
    if(ba == 0 || ba > 12)flagBa = false;

    if(flagFr == true && flagBa == true)cout << "AMBIGUOUS";
    else if(flagFr == true && flagBa == false)cout << "MMYY";
    else if(flagFr == false && flagBa == true)cout << "YYMM";
    else cout << "NA";

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int n;
  scanf("%d", &n);
  if (n > 0 && n < 10001){
      int x = (n + 999) / 1000;
      int i = x * 1000 - n;
      printf("%d\n", i);
  } else {
    printf("erorr\n");
  }
}


Measured memory_bytes: 1716
#include <iostream>
#include <string>
 
using namespace std;
 
int main(void){
  string str;
  cin >> str;
  if(str == "AAA" || str == "BBB"){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
 }


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n;
    cin >> n;
    map<string, int> mp;
    REP(i, n)
    {
        string s;
        cin >> s;
        mp[s]++;
    }
    int max = 0;
    for (auto i : mp)
    {
        if (i.second > max)
        {
            max = i.second;
        }
    }
    set<string> st;
    for (auto i : mp)
    {
        if (i.second == max)
        {
            st.insert(i.first);
        }
    }
    for (auto i : st)
    {
        cout << i << endl;
    }
}

Measured memory_bytes: 34560
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int[][] X = new int[n][d];
		int idx_n;
		int idx_d;
		for (idx_n = 0; idx_n < n; idx_n++) {
			for (idx_d = 0; idx_d < d; idx_d++) {
				X[idx_n][idx_d] = Short.parseShort(sc.next());
			}
		}

		int ans = 0;
		// 点x1とx2の(x1<x2)比較
		int x1;
		int x2;
		double dist;
		double distInt;
		for (x1 = 0; x1 < n - 1; x1++) {
			for (x2 = x1 + 1; x2 < n; x2++) {
				dist = calcDist(X[x1], X[x2], d);
				distInt = Math.round(dist);
				if (dist - distInt == 0.0) {
					++ans;
				}
			}
		}

		System.out.println(ans);

	}

	public static double calcDist(int[] x1, int[] x2, int d) {
		double dist = 0.0;
		int dist2 = 0;
		int idx = 0;

		for (idx = 0; idx < d; idx++) {
			dist2 += (x1[idx] - x2[idx]) * (x1[idx] - x2[idx]);
		}
		dist = Math.sqrt((double) dist2);

		return dist;
	}
}


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

long long n, k, a[200005], b[200005];
bool sudah[200005];

int main(){
	cin>>n>>k;
	for(int i=1; i<=n; i++){
		cin>>a[i];
	}
	memset(b, -1, sizeof(b));
	long long x=2, now=1, idx, cycle;
	b[1]=1;
	sudah[1]=true;
	while(b[x]==-1){
		b[x]=a[now];
		now=b[x];
		if(sudah[now]==true)break;
		sudah[now]=true;
		//cout<<b[x]<<endl;
		x++;
	}
	for(int i=1; i<=n; i++){
		if(b[i]==b[x]){
			cycle=i;
			break;
		}
	}
	//cout<<cycle<<endl;
	k++;
	if(k<=x){
		cout<<b[k]<<endl;
	}
	else {
	idx=(k-cycle+1)%(x-cycle);
	if(idx==0)idx=idx+x-cycle;
	//cout<<idx<<endl;
	idx=idx+cycle-1;
	//cout<<idx<<endl;
	cout<<b[idx]<<endl;
	}
	
}


Measured memory_bytes: 6944