akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(){
    int n; scanf("%d",&n);
    int q=n/100;
    if(n<=100*q+10*q+q){
        printf("%d",100*q+10*q+q);
    }else{
        printf("%d",100*(q+1)+10*(q+1)+(q+1));
    }   
    return 0;
}   


Measured memory_bytes: 128
from collections import deque

N = int(input())
L = [[] for i in range(N)]
for i in range(N-1) :
    u,v = map(int,input().split())
    u -= 1
    v -= 1
    L[u].append(v)
    L[v].append(u)

da = [0]*N
db = [0]*N

qa = deque([0])
visited = [False]*N
visited[0] = True
while qa :
    u = qa.popleft()
    for v in L[u] :
        if not visited[v] :
            visited[v] = True
            da[v] = da[u] + 1
            qa.append(v)

qb = deque([N-1])
visited = [False]*N
visited[N-1] = True
while qb :
    u = qb.popleft()
    for v in L[u] :
        if not visited[v] :
            visited[v] = True
            db[v] = db[u] + 1
            qb.append(v)

c = sum([1 if da[i] <= db[i] else 0 for i in range(N)])
ans = "Fennec" if c > N-c else "Snuke"
print(ans)


Measured memory_bytes: 31648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn = 2e5 + 5;
const ll maxm = 1e3 + 5;
const ll cnt = 1e18;
inline void qread(){}
template<class T1, class ...T2>
inline void qread(T1 &IEE, T2&... ls){
    register T1 __ = 0, ___ = 1;
    register char ch;
    while(!isdigit(ch = getchar())) ___ = (ch == '-') ? -___ : ___;
    do{
        __ = (__ << 1) + (__ << 3) + (ch ^ 48);
    }while(isdigit(ch = getchar()));
    __ *= ___;
    IEE = __;
    qread(ls...);
    return ;
}
ll n, a[maxn];
ll p = 1;
bool f = 0;
int main(){
    qread(n);
    for(int i = 1;i <= n;i++){
        qread(a[i]);
        if(a[i] == 0){
            f = 0;
            p = 0;
        } else {
            if(p > cnt / a[i]){
                f = 1;
            } else {
                p *= a[i];
            }
        }
    }
    if(f){
        puts("-1");
    } else {
        cout << p << endl;
    }
    return 0;
}

Measured memory_bytes: 4416
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        scanner.close();

        int d = (B - A) % 2;
        if (d == 1) {
            System.out.println("Borys");
        }else {
            System.out.println("Alice");
        }
    }
}


Measured memory_bytes: 21844
S = input()
counts = []

for i, s in enumerate(S):
    if i == 0:
        counts.append(1)
        continue
    if S[i] == S[i - 1]:
        counts[len(counts) - 1] += 1
    else:
        counts.append(1)
result = []
for i, c in enumerate(counts):
    if i % 2 == 1:
        continue
    c2 = counts[i + 1]
    right = c // 2
    left = c - right
    left2 = c2 // 2
    right2 = c2 - left2
    result += ['0']*(c-1)
    result += [str(left+left2), str(right + right2)]
    result  += ['0']*(c2-1)
print(' '.join(result))


Measured memory_bytes: 10868
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    long long n;
    cin>>n;
    long long ans=1;
    long long a[n+1]={};

    for(int i=2;i<=n;i++){
        int t=i;
        for(int j=2;j<=t;j++){
            while(t%j==0){
                t/=j;
                a[j]++;
            }
        }
        
    }
    for(int i=1;i<=n;i++){
        ans=(long long)ans*(a[i]+1)%1000000007;
    }
    cout<<ans;
}

Measured memory_bytes: 256
taro = 0
hanako = 0
n = int(input())

for i in range(n):
    t, h = input().split()
    if t == h:
        taro += 1
        hanako += 1
    elif t > h:
        taro += 3
    else:
        hanako += 3

print(taro, hanako)

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

using namespace std;
// {{{ Modint
// using mint = modint<1000000007>;
// mint x = 2;
// std::cout << x.a << std::endl;
template <std::int64_t M>
class modint {
 public:
  int64_t a;

  explicit constexpr modint(const int64_t x = 0) noexcept :
    a((x % M + M) % M) {}
  constexpr int64_t &value() noexcept { return a; }
  constexpr const int64_t &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= M) {
      a -= M;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += M;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % M;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    int64_t exp = M - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
  constexpr modint pow(ll t) const {
    if (!t) return modint(1);
    modint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
};
// }}}
using mint = modint<1000000007>;

typedef pair<ll, ll> v2d;

ll N;
map<v2d, ll> mp; // x >= 0
map<v2d, bool> used;

ll gcd(ll x, ll y) {
  if (y < x)
    swap(x, y);
  // cout << x << " " << y << endl;
  if (x == 0 && y == 0)
    return 1;
  if (x == 0)
   return y;
  if (y % x == 0)
    return x;
  return gcd(y%x, x);
}

ll absl(ll x) {
  if (x < 0)
    return -x;
  return x;
}

// 2^x
mint pow2(ll x) {
  if (x == 0)
    return mint(1);

  if (x % 2 == 0) {
    auto t = pow2(x / 2);
    return t * t;
  }

  auto t = pow2(x / 2);
  return t * t * mint(2);
}

int main() {
  cin >> N;
  rep(i, N) {
    ll x, y;
    cin >> x >> y;
    ll g = gcd(absl(x), absl(y));
    x /= g;
    y /= g;
    if (x < 0) {
      x *= -1;
      y *= -1;
    }
    if (x == 0 && y < 0) {
      y *= -1;
    }
    // cout << x << " " << y << " " << g << endl;
    mp[v2d(x, y)]++;
  }
  // (0, 0) を含む場合
  mint ans(mp[v2d(0, 0)]);
  used[v2d(0, 0)] = true;

  // (0, 0) を含まない場合
  mint t(1);
  for (auto e : mp) {
    auto v1 = e.first;
    auto n1 = e.second;
    auto v2 = v2d(v1.second, -1 * v1.first);
    if (used[v1]) {
      continue;
    }
    if (v2.first < 0) {
      v2.first *= -1;
      v2.second *= -1;
    }
    if (v2.first == 0 && v2.second < 0) {
      v2.second *= -1;
    }
    auto n2 = mp[v2];
    if (n2 == 0) {
      t *= pow2(n1);
    } else {
      t *= pow2(n1) + pow2(n2) - mint(1);
    }
    used[v1] = true;
    used[v2] = true;
  }

  // 空はだめ
  ans += t - mint(1);

  cout << ans.value() << endl;
  return 0;
}

Measured memory_bytes: 53580
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,A,B,C,D;cin>>N>>A>>B>>C>>D;
  A--;B--;C--;D--;
  string S;cin>>S;
  if(C==D){puts("No");return 0;}
  if(C<D){
    for(int i=A;i<D;i++){
      if(S.at(i)==S.at(i+1)&&S.at(i)=='#'){puts("No");return 0;}
    }
    puts("Yes");return 0;
  }
  for(int i=A;i<C;i++){
    if(S.at(i)==S.at(i+1)&&S.at(i)=='#'){puts("No");return 0;}
  }
  for(int i=B-1;i<D;i++){
    if(S.at(i)==S.at(i+1)&&S.at(i)==S.at(i+2)&&S.at(i)=='.'){puts("Yes");return 0;}
  }
  puts("No");
}

Measured memory_bytes: 3728
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL;
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
 
int main (int argc, char *argv[]){ 
    int n,t,a;cin>>n>>t>>a;
    double mi=1e9,ans=0;
    rep(i,0,n){
        int x;cin>>x;
        if(mi>abs(a-(t-x*0.006))){
            mi=abs(a-(t-x*0.006));
            ans=i+1;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

int main(int argc, char* argv[]){
  std::string s;
  int a;
  std::cin >> a;
  if (a >= 1000){
    std::cout << "ABD" << std::endl;
  } else {
    std::cout << "ABC" << std::endl;      
  }

  return 0;  
}



Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>
#include <cstdint>

typedef long long int llint;



void solve(void){

  llint n;
  std::cin >> n;
  std::string s;

  int cnt = 1;
  while(true){
    llint tmp = std::pow(26LL, cnt);
    if(n>tmp){
      n -= tmp;
      cnt++;
      continue;
    }else break;
  }

  //std::cout << cnt << " " << n << std::endl;
  n--;

  for(int i=0; i<cnt; i++){
    char c = 'a' + n%26;
    n/=26;
    s = s+c;
  }

  for(int i=0; i<s.size(); i++){
    std::cout << s[s.size()-1-i];
  }
  std::cout << std::endl;

}

int main(void){

  solve();
  
  return 0;
}


Measured memory_bytes: 4100
from itertools import product

N, K = map(int, input().split())
V = [int(x) for x in input().split()]

ans = 0
# l: 左から取り出す数
for l, r in product(range(K + 1), repeat=2):
    if l + r == 0 or l + r > N or l + r > K:
        continue

    A = V[:l] + V[N - r:]
    s = sum(A)

    # 入れることができる回数
    a = K - (l + r)
    if a > 0:
        A = sorted(A)
        for i in range(min(a, len(A))):
            if A[i] < 0:
                s -= A[i]
            else:
                break
    ans = max(ans, s)
print(ans)


Measured memory_bytes: 3064
#16:25
n,t = map(int,input().split())
wv = []
for _ in range(n):
  wv.append(list(map(int,input().split())))
wv.sort(key=lambda x:x[0])
now = [0 for _ in range(t+1)]
for i in range(n):
  w,v = wv[i]
  last = now
  now = []
  for f in range(t):
    if f >= w:
      now.append(max(last[f-w]+v,last[f]))
    else:
      now.append(last[f])
  now.append(max(last[-2]+v,last[-1]))
print(now[-1])

Measured memory_bytes: 52568
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long H,W;
  cin >> H >> W;

  if (H == 1 || W == 1) {
    cout << 1 << endl;
  } else {
    cout << (H * W + 1) / 2 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n,k;
ll a[100005];
ll b[100005];
ll c[100005];
ll d[100005];
ll sum;
ll m=1000000000000000000,M=-1000000000000000000;
int main(void){
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=a[i];
        if(a[i]>0) sum+=a[i];
        if(a[i]<0) a[i]=0;
        if(b[i]>0) b[i]=0;
        c[i+1]=c[i]+a[i];
        d[i+1]=d[i]+b[i];
    }
    for(int i=0;i<=n-k;i++){
        m=min(m,c[i+k]-c[i]);
        M=max(M,d[i+k]-d[i]);
        //cout<<m<<" "<<M<<endl;
    }
    ll ans=max(sum+M,sum-m);
    if(ans<0) ans=0;
    cout<<ans<<endl;


}



Measured memory_bytes: 6644
import java.math.BigDecimal;
import java.util.Scanner;
class Main {
	public static void main(String[] args){
		double num;
		Scanner sc = new Scanner(System.in);
		Doctor d;
		
		while(true){
			num = sc.nextDouble();
			if(num < 0){
				break;
			}
			d = new Doctor(num);
			if(d.judge()){
				System.out.println(d.getBD());
			}else{
				System.out.println("NA");
			}
		}
	}
}

class Doctor {
	double num;
	String bd;
	int integers;
	double decimals;
	
	Doctor(double num){
		this.num = num;
		bd = "";
		integers = (int)num;
		decimals = num-integers;
	}
	
	public boolean judge(){
		if(integers>255 || decimals>0.9375){
			return false;
		}
		return true;
	}
	
	private boolean toBinaryDigits(){
		String tmp = "";
		int count = 1;
		
		for(int i=integers;i>0;i/=2){
			tmp += i%2;
		}
		StringBuffer sb = new StringBuffer(tmp);
		for(int i=0;i<8-tmp.length();i++){
			bd += "0";
		}
		bd += sb.reverse().toString()+".";
		
		decimals = new BigDecimal(decimals).setScale(4, BigDecimal.ROUND_DOWN).doubleValue();
		while(true){
			if(decimals == 0){
				bd += "0000";
				break;
			}
			
			if(count > 4){
				return false;
			}
			decimals *= 2;
			if(decimals >= 1){
				decimals -=1;
				bd += "1";
				if(decimals == 0){
					for(int i=0;i<4-count;i++){
						bd += "0";
					}
					break;
				}
			}else{
				bd += "0";
			}
			count++;
		}
		
		return true;
	}
	
	public String getBD(){
		if(toBinaryDigits()){
			return bd;
		}
		return "NA";
	}
}

Measured memory_bytes: 32116
n = gets.to_i
a = gets.split.map(&:to_i)

if n == 0
    p a[0] == 1 ? 1 : -1
    exit
elsif a[0] == 1
    p -1
    exit
end

x = 1
s = a.sum
ans = 0
1.upto(n) do |i|
    x * 2 < a[i] and (p -1; exit)

    ans += x + a[i]
    s -= a[i]
    x * 2 - a[i] <= s ? x = x * 2 - a[i] : x = s
end

p ans

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

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

template<class T> struct UnionFindDiff {
    int n;
    vector<int> U;
    vector<T> D; // P[U[x]] - P[x]
    UnionFindDiff() {}
    UnionFindDiff(int n_): n(n_), U(n, -1), D(n, T(0)) {}
    int root(int x) {
	if (U[x] < 0) return x;
	int r = root(U[x]);
	if (U[x] != r) {
	    D[x] = D[U[x]] + D[x];
	    U[x] = r;
	}
	return r;
    }
    int link(int x, int y, T diff /* = P[x] - P[y] */) {
	int p, q;
	p = root(x); q = root(y);
	if (p == q) return p;
	if (U[q] < U[p]) { swap(p, q); swap(x, y); diff = -diff; }
	D[q] = D[x] - D[y] + diff;
	U[p] += U[q];
	n--;
	return U[q] = p;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int size(int x) { return -U[root(x)]; }
    int count() { return n; }
    T diff(int x, int y) { // return P[x] - P[y];
	root(x); root(y);
	// assert(root(x) == root(y));
	return D[y] - D[x];
    }
};

int N, M;
int L[200111], R[200111], D[200111];

void MAIN() {
    scanf("%d%d", &N, &M);
    REP (i, M) scanf("%d%d%d", L+i, R+i, D+i), L[i]--, R[i]--;

    UnionFindDiff<int> U(N);
    REP (i, M) {
	U.link(R[i], L[i], D[i]);
//	rprintf("%d", U.D.begin(), U.D.end());
    }
    bool yes = true;
    REP (i, M) {
//	eprintf("%d %d %d : %d\n", L[i], R[i], D[i], U.diff(R[i], L[i]));
	if (D[i] != U.diff(R[i], L[i])) {
	    yes = false;
	    break;
	}
    }

    puts(yes? "Yes": "No");
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 3328
n = int(input())
aa = list(map(int, input().split()))

if n == 1:
    print(0)
    exit(0)

for i in range(n):
    aa[i] -= i + 1

aa = sorted(aa)
b1 = aa[n//2]
b2 = aa[n//2 + 1]
ans = min(
    sum([abs(a - b1) for a in aa]),
    sum([abs(a - b2) for a in aa])
)
print(ans)


Measured memory_bytes: 31000
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  if (a%2 == 1 && b%2 == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ll,ii>
#define int ll

int a,b,c,d;
int k;

bool ok(int i){
	if (i==-1) return true;
	
	int da,db;
	
	db=(i+1)/(k+1); //pos i-1 confirm have 'a'
	da=(i+1)-db;
	
	db=b-db;
	da=a-da;
	
	return db<=(da+1)*k;
}

main(){
	//freopen("input.txt","r",stdin);
	ios::sync_with_stdio(0);
    cin.tie(0);
	
	int TC;
	cin>>TC;
	while (TC--){
		cin>>a>>b>>c>>d;
		
		k=max(ceil((double)a/(b+1)),ceil((double)b/(a+1)));
		
		if (k==1){
			bool temp=(a>=b);
			
			for (int x=c-1;x<d;x++){
				if (temp^(x&1)) cout<<"A";
				else cout<<"B";
			}
			cout<<endl;
			continue;
		}
		
		int lo=-1,hi=a+b+1,mi;
		
		while (hi-lo>1){
			mi=hi+lo>>1;
			
			if (ok(mi)) lo=mi;
			else hi=mi;
		}
		
		//cout<<k<<" "<<lo<<endl;
		
		//sometimes its better to move the partition 1 space to the left
		if ((lo+1)%(k+1)==0 && (a+b-lo)%(k+1)){
			lo--;
		}
		
		int pos;
		for (int x=c-1;x<d;x++){
			if (x==lo) cout<<'A';
			else if (x<lo){
				pos=x;
				if ((pos+1)%(k+1)==0) cout<<'B';
				else if ((lo+1)%(k+1)==0 && x==lo-1 && lo!=a+b) cout<<'B';
				else cout<<'A';
			}
			else{
				pos=a+b-1-x;
				if ((pos+1)%(k+1)==0) cout<<'A';
				else cout<<'B';
			}
		}
		
		cout<<endl;
	}
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
# モジュールのインポート
import sys

# 標準入力を取得
N = int(input())
x, y = [], []
for i in range(N):
    x_i, y_i = list(map(int, input().split()))
    x.append(x_i)
    y.append(y_i)

# 求解処理
max_z = -sys.maxsize
min_z = sys.maxsize
max_w = -sys.maxsize
min_w = sys.maxsize
for x_i, y_i in zip(x, y):
    z_i = x_i + y_i
    max_z = max(max_z, z_i)
    min_z = min(min_z, z_i)
    w_i = x_i - y_i
    max_w = max(max_w, w_i)
    min_w = min(min_w, w_i)
ans = max(max_z - min_z, max_w - min_w)

# 結果出力
print(ans)


Measured memory_bytes: 24852
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,sum;
char s[N];
void init(){scanf("%d%s",&n,s+1); sum=0;}
void work(){for(int i=1;i<=n;++i) sum+=(s[i]!=s[i+1]);}
void prin(){printf("%d",sum);}
int main(){init(); work(); prin(); return 0;}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
  int n;
  cin>>n;
  vector<int> hoge(n);
  for(int i=0; i<n; i++){
    cin>>hoge.at(i);
  }
  sort(hoge.begin(),hoge.end());
  long long int ans=0;
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      auto itr=lower_bound(hoge.begin(),hoge.end(),hoge.at(i)+hoge.at(j));
      ans+=itr-hoge.begin()-1-j;
    }
  }
  cout<<ans<<endl;
}

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

double v (int floor){
	int h = (floor - 1) * 5;
	return 9.8 * sqrt (h / 4.9);
}

int main(void) {
	int N;
	double v_min;
	while (scanf ("%lf", &v_min) != EOF){
		for (N=1; v(N) < v_min; N++){}
		printf("%d\n", N);
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main(){
    int H, W;
    while(1){
        cin>>H>>W;
        if(H==0 && W==0)break;
        for(int i=0;i<H;i++){
            for(int j=0; j<W;j++){
                if(i==0 || i==H-1 || j==0 || j==W-1){
                    cout<<"#";
                }else{
                    cout<<".";
                }
            }
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;

const int INF = 1e9 ;
const int maxN = 1e5 + 5;

int n,h,w;
int main()
{
	scanf("%d%d%d",&n,&h,&w);
	int ans = (n-h+1) * (n-w+1);
	cout<<ans<<endl;

	return 0;
} 

Measured memory_bytes: 256
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N = read()

inv = [0] * N
for i in range(N):
  x = read()
  inv[x-1] = i

inv.append(-1)
print(inv, file=stderr)

maxans = 1
count = 1
for i in range(1, N+1):
  if inv[i-1] < inv[i]:
    count += 1
  else:
    print('stopped at ' + str(i), file=stderr)
    maxans = max(maxans, count)
    count = 1

print(maxans, file=stderr)
print(N - maxans)


Measured memory_bytes: 14548
#include <iostream>

using namespace std;

string str;

int main() {
    cin >> str;
    if (str.at(2) == str.at(3) && str.at(4) == str.at(5)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl;
int n;
double v,x,y,l[50],r[50],d[50],u[50],g=9.8,eps=1e-9;
int comp(double lb,double ub,double x){
	if(x<lb+eps) return -1;
	if(ub<x+eps) return 1;
	return 0;
}
void fix(double x){
	if(x<0&&x>-eps) x=0;
	if(x>0&&x<eps) x=0;
}
double calcy(double vy,double t){
	return -g/2*t*t+vy*t;
}
bool check(double qx,double qy){
	double a=g*g/4,b=g*qy-v*v,c=qx*qx+qy*qy,D=b*b-4*a*c;
	fix(D);
	if(D<0) return false;
	double s=-1;
	rep(ssign,2){
		bool ok=true;
		s*=-1;
		double t2=(-b+s*sqrt(D))/(2*a);
		fix(t2);
		if(t2<=0) continue;
		double t=sqrt(t2);
		double vx=qx/t,vy=(qy+g/2*t*t)/t;
		if(vx<=0) continue;
		double t2t=x/vx,ry=calcy(vy,t2t);
		if(ry+eps<y) continue;
		//show(qx);
		//show(qy);
		//show(vx);
		//show(vy);
		rep(i,n){
			if(x<=l[i]) continue;
			if(r[i]>=x&&y<=u[i]&&d[i]<=ry) ok=false;
			int ly=comp(d[i],u[i],calcy(vy,l[i]/vx));
			int ry=comp(d[i],u[i],calcy(vy,r[i]/vx));
			int hx=comp(l[i],r[i],vy/g*vx);
			int hy=comp(d[i],u[i],calcy(vy,vy/g));
			if(hx==0&&hy>=0&&ly<0) ok=false;
			if(ly*ry<=0) ok=false;
		}
		// if(ok){
		// 	show(qx);
		// 	show(qy);
		// 	show(vx);
		// 	show(vy);
		// }
		if(ok) return true;
	}
	return false;
}
int main(){
	cin>>n>>v>>x>>y;
	rep(i,n) cin>>l[i]>>d[i]>>r[i]>>u[i];
	rep(i,n) r[i]=min(r[i],x);
	bool can=false;
	can|=check(x,y);
//	if(can) cout << "d";
	rep(i,n){
		can|=check(l[i],u[i]);
		can|=check(r[i],u[i]);
	}
	cout << (can ? "Yes\n" : "No\n");
}

Measured memory_bytes: 1188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define FFOR(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define rep(i,n) FOR(i,0,n-1)
#define int long long
#define MOD 998244353
#define MAXN  100005
#define P pair<int,int>

int a[MAXN],b[MAXN];

signed main(){
	
	int n;cin >>n;
	int cnt = 0;
	rep(i,n)
	{
		int a;cin>>a;
		if(a%2) cnt++;
	}
	
	cout << ((cnt%2)?"NO":"YES") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

// lcm
ll lcm(ll x, ll y) { return (x * y) / __gcd(x, y); }

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

  ll n, m;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;

  ll l = lcm(n, m);
  ll g = __gcd(n, m);

  bool ok = true;
  for (int i = 0; i < g; i++) {
    if (s[i * (n / g)] != t[i * m / g]) {
      ok = false;
      break;
    }
  }

  cout << (ok ? l : -1) << ln;

  return 0;
}

Measured memory_bytes: 640
package main

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

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func main() {
	list := getStdinIntArr()
	X := list[0]
	A := list[1]

	if X < A {
		fmt.Printf("%d\n", 0)
	} else {
		fmt.Printf("%d\n", 10)
	}
}

func getStdin() string {
	return readLine()
}
func getStdinArr() []string {
	str := getStdin()
	list := strings.Split(str, " ")
	return list
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 640
#include  <stdio.h>
/* Aizu Online Judge Problem 	    */
/* Volume0 0006:Reverse Sequence 	*/

int main(void)
{
  char str[21];
  int i;

  scanf("%s", str);

  i = 0;
  while(str[i] != '\0')
    i++;
  i--;

  while(i >= 0)
  {
    printf("%c", str[i]);
    i--;
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 524
import java.util.Scanner;
class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		double r,x,y;
			r = scanner.nextDouble();
		    x=r*r*Math.PI;
		    y=2*r*Math.PI;
            System.out.printf("%f %f\n",x,y);
	}
}


Measured memory_bytes: 28340
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int N;
    cin >> N;
    
    int count = 0;
    
    for (int i = 1; i <= N; i++) {
        if (to_string(i).length() % 2 == 0) {
            continue;
        }
        
        count++;
    }
    
    cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)

//9^20はオーバーフローするので以下のエラーが出続けた笑
//Illegal instruction: 4

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

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

int main(){
  const ll INF=1e10;
  ll dp[100010];
  rep(i,100010)dp[i]=INF;

  ll n;
  cin >> n;

  dp[0]=0;
  rep(i,n+1){
    if(i>0)chmin(dp[i],dp[i-1]+1);//1å††
    ll pow6=1;
    rep(j,20){
      pow6*=6;
      if(i-pow6>=0)chmin(dp[i],dp[i-pow6]+1);
    }
    ll pow9=1;
    rep(k,15){
      pow9*=9;
      if(i-pow9>=0)chmin(dp[i],dp[i-pow9]+1);
    }
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 1024
import math
time = 5 * 10**15

num = list(input())
k = int(input())

chk = 0
count = 0
while chk == 0:
    if num[0] == '1':
        num.pop(0)
        count += 1
        if len(num)==0:
            break
    else:
        chk = 1

if k <= count:
    print(1)
else:
    print(num[0])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b,h;
    cin >> a >> b >> h;
    cout << (a+b) * h / 2 << endl;
}


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

int a[1123];

int main(){
    int n;
    cin >> n;
    int sum = 0;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        sum += a[i];
    }
    sort(a + 1,a + 1 + n);
    for(int i = 1; i <= n; i++){
        if(sum % 10 == 0){
            if((a[i]%10 != 0)){
                sum -= a[i];
            }
        }
        else{
            break;
        }
    }
    if(sum % 10 > 0){
        cout << sum;
        return 0;
    }
    cout << 0;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N,K,Q;
    cin>>N>>K>>Q;
    vi A(Q);
    rep(i,Q) cin>>A.at(i);
    rep(i,Q) A.at(i)--;
    vi Point(N,K);
    rep(i,N) Point.at(i)-=Q;
    rep(i,Q) {
        Point.at(A.at(i))++;
    }
    rep(i,N) {
        if(Point.at(i)>0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

Measured memory_bytes: 1408
#[allow(dead_code)]
fn rd() -> String {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input.trim().to_owned()
}

/// 1行の文字を空白で分割してVec<T>にする。
#[allow(dead_code)]
fn rd_vec<T : std::str::FromStr>() -> Vec<T> {
    rd().split_whitespace().map(|x| x.parse().ok().unwrap()).collect()
}

/// 1つの要素を入力で受け取る
#[allow(dead_code)]
fn rd_one<T : std::str::FromStr>() -> T {
    rd().parse().ok().unwrap()
}

/// 複数回read_splitを行う
#[allow(dead_code)]
fn rd_vec_mul<T : std::str::FromStr>(count : i32) -> Vec<Vec<T>> {
    (0..count).map(|_| rd_vec()).collect()
}

/// Vecを1列で出力する
#[allow(dead_code)]
fn op_vec<T : std::fmt::Display>(item : Vec<T>, splitter : char) {
    let cnt = item.len();
    let mut c = 0;
    for i in item.iter() {
        c+=1;
        if cnt > c {print!("{}{}", i, splitter);} else {println!("{}", i);}
    }
}

fn main() {
    let input: Vec<char> = rd().chars().collect();
    let input2: Vec<char> = rd().chars().collect();
    let mut answer = 0;
    for i in 0..3 {
        if input[i] == input2[i] { answer += 1 ;}
    }
    println!("{}", answer);
}


Measured memory_bytes: 4352
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

S = input()
N = len(S)

# dp[i][bit][j] := i桁目まで見て、出現済の3,5,7の集合がbitで、Nより小さいのが確定しているorしていない(j=0,1)状態の場合の数
dp = list3d(N+1, 1<<3, 2, 0)
dp[0][0][0] = 1
for i in range(N):
    a = int(S[i])
    for bit in range(1<<3):
        # 0への遷移
        if bit == 0:
            dp[i+1][bit][1] += dp[i][bit][0]
            dp[i+1][bit][1] += dp[i][bit][1]
        # 3,5,7への遷移
        for k, x in enumerate([3, 5, 7]):
            dp[i+1][bit|1<<k][1] += dp[i][bit][1]
            if a == x:
                dp[i+1][bit|1<<k][0] += dp[i][bit][0]
            elif a > x:
                dp[i+1][bit|1<<k][1] += dp[i][bit][0]
# N桁見終わって、3,5,7出現済(bit=111)の合計
print(dp[N][-1][0] + dp[N][-1][1])


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

int main() {
    string S;
    string T;

    cin >> S >> T;

    vector<vector<int>> dp(S.size() + 1, vector<int>(T.size() + 1));
    for (int i = 0; i < S.size(); i++) {
        dp[i][0] = 1;
    }

    for (int i = 0; i < S.size(); i++) {
        for (int j = 0; j < T.size(); j++) {
            if (S.at(i) == T.at(j) || S.at(i) == '?') {
                dp[i + 1][j + 1] += dp[i][j];
            }
        }
    }

    // rep(i, S.size() + 1) {
    //     rep(j, T.size() + 1) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    bool flg = false;
    int last_i = 0;
    for (int i = 0; i < S.size(); i++) {
        if (dp[i + 1][T.size()] != 0) {
            flg = true;
            last_i = i;
        }
    }

    if (flg) {
        // cout << "last_i: " << last_i << endl;
        for (int j = 0; j < T.size(); j++) {
            // cout << S.at(last_i - T.size() + 1 + j) << endl;
            // cout << T.at(j) << endl;

            S.at(last_i - T.size() + 1 + j) = T.at(j);
        }

        for (int i = 0; i < S.size(); i++) {
            if (S.at(i) == '?') S.at(i) = 'a';
        }
        cout<< S << endl;
    } else {
        cout << "UNRESTORABLE" << endl;
    }

}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define ll long long
typedef pair<ll , ll > pii;
ll mod=998244353;
ll p=1e9+7;

 
int  main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c,k; cin>>a>>b>>c>>k;
    int ans=0;
    ans+=min(a,k);
    k-=a;
    if(k>0) k-=b;
    if(k>0) ans-=k;
    cout<<ans;
    
    return 0;
}

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

int main(void) {
	int n, right = 0,left=0,minR=100000,minL=100000;
	scanf("%d", &n);
	vector<int> a(n),w(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		cin >> w[i];
	for (int i = 0; i < n; i++) {
		if(a[i]){
			left++;
			if (minL > w[i]) minL = w[i];
		}else{
			right++;
			if (minR > w[i]) minR = w[i];
		}
	}
	if(right == 0 || right == n)
		printf("0\n");
	else
		printf("%d\n", minL + minR);
	return 0;
}


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

int main() {
  int n,w; cin >> n >> w;
  long long knap[n][2];
    for (int i = 0; i < n; i++)
      for (int j = 0; j < 2; j++)
        cin >> knap[i][j];
  //入力
  long long dp[n+1][w+1];
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= w; j++)
      dp[i][j] = 0;
  //dp表
  for (int i = 1; i <= n; i++){
    for (int j = 1; j <= w; j++){
      if (j >= knap[i-1][0])
        dp[i][j] = max(dp[i-1][j],dp[i-1][j-knap[i-1][0]]+knap[i-1][1]);
      else
        dp[i][j] = dp[i-1][j];
    }
  }
  cout << dp[n][w] << endl;
}

Measured memory_bytes: 79104
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,mod=1000000007;
const long long llinf=1000000000000ll;
int n,m,w,v;
long long dp[N],ans;
int main(){
	cin>>n>>m;
	for(int i=0;i<=100000;i++)
		dp[i]=llinf;
	dp[0]=0;
	for(int i=1;i<=n;i++)
	{
		cin>>w>>v;
		for(int j=1000*i;j>=v;j--)
			dp[j]=min(dp[j],dp[j-v]+w);
	}
	for(int i=0;i<=100000;i++)
		if(dp[i]<=m)
			ans=i;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1144
n=input()
if int(n[0])+int(n[1])+int(n[2])+int(n[3])==7:
  print(n[0]+"+"+n[1]+"+"+n[2]+"+"+n[3]+"="+"7")
elif int(n[0])+int(n[1])+int(n[2])-int(n[3])==7:
  print(n[0]+"+"+n[1]+"+"+n[2]+"-"+n[3]+"="+"7")
elif int(n[0])+int(n[1])-int(n[2])+int(n[3])==7:
  print(n[0]+"+"+n[1]+"-"+n[2]+"+"+n[3]+"="+"7")
elif int(n[0])-int(n[1])+int(n[2])+int(n[3])==7:
  print(n[0]+"-"+n[1]+"+"+n[2]+"+"+n[3]+"="+"7")
elif int(n[0])-int(n[1])-int(n[2])+int(n[3])==7:
  print(n[0]+"-"+n[1]+"-"+n[2]+"+"+n[3]+"="+"7")
elif int(n[0])-int(n[1])+int(n[2])-int(n[3])==7:
  print(n[0]+"-"+n[1]+"+"+n[2]+"-"+n[3]+"="+"7")
elif int(n[0])+int(n[1])-int(n[2])-int(n[3])==7:
  print(n[0]+"+"+n[1]+"-"+n[2]+"-"+n[3]+"="+"7")
else:
  print(n[0]+"-"+n[1]+"-"+n[2]+"-"+n[3]+"="+"7")

Measured memory_bytes: 3192
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main() {
	int n, m;
	cin >> n >> m;
	P student[55];
	for (int i = 0; i < n; i++) {
		int a,b;
		cin >> a >> b;
		student[i]=make_pair(a, b);
	}
	P point[55];
	for (int i = 0; i < m; i++) {
		int c, d;
		cin >> c >> d;
		point[i] = make_pair(c, d);
	}
	for (int i = 0; i < n; i++) {
		int anspoint = 100;
		ll ans = inf;
		for (int j = 0; j < m; j++) {
			ll x = abs(student[i].first - point[j].first) + abs(student[i].second - point[j].second);
			
			if (ans > x) {
				ans = x;
				anspoint = j+1;
			}
		}
		cout << anspoint << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
using namespace std;

typedef long long int ll;
#define MOD 1000000007
#define INF 1000000001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

bool bfs(vector<vector<int>> g, vector<int> &dist, int sv)
{
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

int main(void) {
	int a,b; cin >> a >> b;
	int sum = a+b;
	if(sum%2) out("IMPOSSIBLE");
	else out(sum/2);

}




Measured memory_bytes: 256
from collections import Counter
from functools import reduce

N,P = list(map(int,input().split()))
def prime_factorize(n):
    while n % 2 == 0:
        yield 2
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            yield f
            n //= f
        else:
            f += 2
    if n != 1:
        yield n

counter = Counter(prime_factorize(P))

ans = reduce(lambda total, x: total * x[0] ** (x[1]//N), counter.items(), 1)
print(ans)



Measured memory_bytes: 3572
n, m, x = map(int, input().split())
list_ca = [list(map(int, input().split())) for _ in range(n)]

num = pow(2, n)
min_cost = -1
for count in range(num):
    a_list = [0] * m
    cost = 0
    for i in range(n):
        bit = pow(2, i)
        if (count // bit) % 2 == 1:
            for j in range(m):
                a_list[j] = a_list[j] + list_ca[i][j + 1]
            cost += list_ca[i][0]
    if min(a_list) >= x:
        if min_cost == -1:
            min_cost = cost
        elif min_cost > cost:
            min_cost = cost

print(min_cost)

Measured memory_bytes: 9236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;



int main(){
    int h,w;
    cin >> h >> w;

    int sx,sy,gx,gy;
    cin >> sy >> sx >> gy >> gx;
    sx--;sy--;gx--;gy--;

    pair<int,int> s = make_pair(sx,sy), g = make_pair(gx,gy); 
    vector<vector<int>> ans(h,vector<int>(w,mod));
    string sur[h];

    for(int i = 0; i < h; i++) cin >> sur[i];

    auto inout = [&](int x,int y){
        if(0 <= x && x < w && 0 <= y && y < h) return true;
        else return false;
    };

    auto add = [&](pair<int,int> now,int dx,int dy){
        pair<int,int> ret = make_pair(now.first+dx,now.second+dy);
        return ret;
    };

    auto answer = [&](pair<int,int> now){
        if(now == g){
            cout << ans[now.second][now.first] << endl;
            return true;
        } else return false;
    };

    queue<pair<int,int>> p,q;
    map<pair<int,int>,bool> seen;

    

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

    p.push(s);
    seen[s] = true;
    ans[s.second][s.first] = 0;

    int can = 0;

    while(!p.empty()){
        while(!p.empty()){
            pair<int,int> now = p.front();
            p.pop();
            bool first = true;
            for(int i = 0; i < 4; i++){
                pair<int,int> nxt = add(now,dx[i],dy[i]);
                if(inout(nxt.first,nxt.second)){
                    if(sur[nxt.second][nxt.first] == '.' && !seen[nxt]){
                        ans[nxt.second][nxt.first] = can;
                        seen[nxt] = true;
                        if(answer(nxt)) return 0;
                        p.push(nxt);
                    } else if(sur[nxt.second][nxt.first] == '#' && first){
                        q.push(now);
                        first = false;
                    }
                }
            }
        }
        can++;
        while(!q.empty()){
            pair<int,int> now = q.front();
            q.pop();
            for(int i = -2; i < 3; i++){
                for(int j = -2; j < 3; j++){
                    pair<int,int> nxt = make_pair(now.first+i,now.second+j);
                    if(inout(nxt.first,nxt.second)){
                        if(sur[nxt.second][nxt.first] == '.' && !seen[nxt]){
                            ans[nxt.second][nxt.first] = can;
                            seen[nxt] = true;
                            p.push(nxt);
                            if(answer(nxt)) return 0;
                        }
                    }
                }
            }
        }
    }

    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 35540
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

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

    map<int, long long> bars;
    vector<long long> bars2 = {0, 0};

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        if (bars.count(a) == 0) {
            bars[a] = 1;
        } else {
            bars[a]++;
        }
    }

    for (auto i : bars) {
        if (i.second >= 4) {
            bars2.push_back(i.first);
            bars2.push_back(i.first);
        } else if (i.second >= 2) {
            bars2.push_back(i.first);
        }
    }

    sort(bars2.begin(), bars2.end(), greater<int>());

    cout << bars2[0] * bars2[1] << endl;
    
    return 0;
}


Measured memory_bytes: 6528
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n,m,c=parseMap(split(readline()))
    b=parseMap(split(readline()))
    a=[parseMap(split(readline())) for i in 1:n]
    ans=0
    for i in 1:n
        res=c
        for j in 1:m
            res+=a[i][j]*b[j]
        end
        if res>0
            ans+=1
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 112824
import functools
import threading
import sys


def main():
    @functools.lru_cache(maxsize=None)
    def _solve(n, action):
        if n == 1:
            return Utility[1][action]
        else:
            return max(
                _solve(n - 1, a) + Utility[n][action] for a in range(3) if a != action
            )

    def solve(n):
        return max(_solve(n, a) for a in range(3))

    N = int(input())
    Utility = [[None, None, None]]
    for i in range(N):
        Utility.append([int(x) for x in input().split(" ")])
    print(solve(N))


if __name__ == "__main__":

    sys.setrecursionlimit(1024 * 1024 * 2)
    threading.stack_size(128 * 1024 * 1024 * 2)
    threading.Thread(target=main).start()


Measured memory_bytes: 606100
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
#![allow(unused_assignments)]
use proconio::input;
use proconio::marker::*;
use std::collections::*;
use std::cmp::*;
use std::mem::swap;
use std::f64::consts::*;

const MOD: u64 = 1000000007;
const INF: usize = std::usize::MAX / 4;

fn main() {
    input! {
        N: i64,
        K: i64,
    }

    println!("{}", min(N % K, K - N % K));
}


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

string lcs(char *x,char *y,int n,int m)
{
	int a[n+1][m+1];
	int i,j;
	for(i=0;i<=n;i++)
	{
		for(j=0;j<=m;j++)
		{
			if(i == 0|| j == 0)
			{
				a[i][j] = 0;
			}

			else if(x[i] == y[j])
			{				
				a[i][j] = 1 + a[i-1][j-1];
			}

			else
			{
				a[i][j] = max(a[i-1][j],a[i][j-1]);
			}
		}
	}
	
	string s = "";
	
	i = n;
	j = m;
	
	while (i > 0 && j > 0)
	{
	   if(a[i][j] > max(a[i-1][j],a[i][j-1]))
	   {
	       s = s + x[i];
	       i--;
	       j--;
	       /*cout << "HELLO\n" << s << "\n";*/
	   }
	   else if(a[i][j] == a[i-1][j])
	   {
	       i--;
	   }
	   else
	   {
	       j--;
	   }
	}
	return s;
}

int main()
{
	string a,b;
	cin >> a;
	cin >> b;
	int n,m;
	n = a.size();
	m = b.size();
	char x[n+1],y[m+1];
	int i;
	for(i=1;i<=n;i++)
	{
		x[i] = a[i-1];
	}
	for(i=1;i<=m;i++)
	{
		y[i] = b[i-1];
	}
	string s = lcs(x,y,n,m);
	
	for(i=s.size()-1;i>=0;i--)
	{
	    cout << s[i];
	}
}



Measured memory_bytes: 35456
<?php
// $n = (int)trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));

$n = (int)$input[0];
$m = (int)$input[1];

$list = [];
for ($i=0; $i < $m; $i++) { 
	$input = explode(' ', trim(fgets(STDIN)));
	$s = (int)$input[0];
	$c = (int)$input[1];
	if (!isset($list[$s])) {
		$list[$s] = $c;
	}elseif ($list[$s] !== $c) {
		echo '-1';
		exit();
	}
}
$str = "";
for ($i=1; $i <= $n; $i++) { 
	if (isset($list[$i])) {
		$str .= $list[$i];
	} else {
		if ($n !== 1 && $i === 1) {
			$str .= "1";
		}else{
			$str .= "0";
		}
	}
}
if (strlen($str) > 1 && $str[0] == "0") {
	echo '-1';
	exit();
}
echo $str;

Measured memory_bytes: 4728
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, M, p, y;
  cin >> N >> M;
  vector<vector<pair<int, int>>> V(N);
  for (int i = 0; i != M; ++i) {
    cin >> p >> y;
    V[--p].push_back({y, i});
  }

  vector<pair<int, int>> A(M);
  for (int i = 0; i != N; ++i) {
    sort(begin(V[i]), end(V[i]));
    for (int j = 0, n = V[i].size(); j != n; ++j) {
      A[V[i][j].second] = {i + 1, j + 1};
    }
  }

  for (auto &a : A)
    cout << setfill('0') << setw(6) << a.first << setw(6) << a.second << endl;
}


Measured memory_bytes: 9380
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cctype>
#define rep(i,x,y) for(int i=x; i<=y; ++i)

using namespace std;
const int N=17,M=40000,INF=1000000000;
int n,m,f[M],q[M],tot,dis[N][N],u,v,c;

int getint()
{
	char ch;
	int f=1;
	while(!isdigit(ch=getchar())) if(ch=='-') f=-1;
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;
	return x*f;
}

int query1(int x)
{
	int rt=0;
	rep(i,1,n)
		if(x&(1<<i-1))
			rep(j,i+1,n)
				if(x&(1<<j-1) && dis[i][j]!=INF)
					rt+=dis[i][j];
	return rt;
}

int query2(int x,int y)
{
	int rt=0,maxn=0;
	rep(j,1,n)
		if(x&(1<<j-1))
		{
			rt=0;
			rep(i,1,n)
				if(y&(1<<i-1) && dis[j][i]!=INF)
					rt+=dis[j][i];
			maxn=max(maxn,rt);
		}
	return maxn;
}

int main()
{
	n=getint(),m=getint();
	rep(i,1,n) rep(j,1,n) dis[i][j]=i==j?0:INF;
	rep(i,1,m) u=getint(),v=getint(),dis[u][v]=dis[v][u]=c=getint(),tot+=c;

	rep(i,1,(1<<n)-1) f[i]=-INF;
	f[1]=0;
	rep(i,1,(1<<n)-2)
		if(f[i]!=-INF)
		{
			rep(j,1,n)
				if(!(i&(1<<j-1)))
				{
					int maxn=0;
					rep(k,1,n)
						if(i&(1<<k-1) && dis[j][k]!=INF)
							maxn=max(maxn,dis[j][k]);
					if(maxn) f[i|(1<<j-1)]=max(f[i|(1<<j-1)],f[i]+maxn);
				}
		}
	
	rep(i,1,(1<<n)-1)
	{
		if(!(i&1) || !(i&(1<<n-1))) f[i]=-INF;
		q[i]=query1(i);
	}
	
	rep(i,1,(1<<n)-1)
		if(f[i]!=-INF)
			for(int j=((1<<n)-1)^i; j; j=(j-1)&(((1<<n)-1)^i))
				f[i|j]=max(f[i|j],f[i]+q[j]+query2(i,j));

	printf("%d\n",tot-f[(1<<n)-1]);
	return 0;
}

Measured memory_bytes: 384