akhauriyash/Code-Regression huggingface dataset:
N = int(input())
L = list(map(int, input().split()))

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if L[i]!=L[j] and L[j]!=L[k] and L[i]!=L[k]:
                if L[i]+L[j]>L[k] and L[i]+L[k]>L[j] and L[j]+L[k]>L[i]:
                    ans += 1

print(ans)

Measured memory_bytes: 9204
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pi;
const int MAXN=105;
const int MOD=1000000007;

#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 fst first
#define snd second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

int N, K;
main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >>K;
	set<int> S;
	FOR(i,1,N) S.insert(i);
	FOR(i,1,K){
		int d; cin >> d;
		FOR(j,1,d){
			int t;cin>>t;
			S.erase(t);
		}
	}
	cout<<sz(S);
}


Measured memory_bytes: 3656
long n,k;long fun(long n, long x){if(n==0)return(x<=0?0:1);long p=(1LL<<n)-1;if(x<=2*p)return fun(n-1,x-1);return p+1+fun(n-1,x-1-2*p);}main(){scanf("%ld%ld",&n,&k);printf("%ld\n",fun(n,k));}

Measured memory_bytes: 128
N = int(input())

# ある自然数未満までのエラトステネスの篩をつくる
def mark(s, x):
    for i in range(x + x, len(s), x):
        s[i] = False


def eratosthenes(n):
    s = [True] * n
    for x in range(2, int(n ** 0.5) + 1):
        if s[x]: mark(s, x)
    return [i for i in range(0, n) if s[i] and i > 1]

E = eratosthenes(55556)
ans = []
cnt = 0
for e in E[2:]:
    if e % 5 == 1:
        ans.append(str(e))
        cnt += 1
        if N == cnt:
            break
print(" ".join(ans))


Measured memory_bytes: 3572
#include "bits/stdc++.h"
using namespace std;
int main() {
	string s;
	cin >> s;
	while (s.size() >= 2 && s[0] == 'h' && s[1] == 'i') {
		s.erase(s.begin());
		s.erase(s.begin());
	}
	cout << (s.empty() ? "Yes" : "No") << "\n";
}


Measured memory_bytes: 764
N = int(input())
m = 999
M = []
N1 = 0
N2 = 0
for i in range(N-1):
  L1 = list(str(i+1))
  N1 = 0
  N2 = 0
  for j in range(len(L1)):
    N1 += int(L1[j])
  L2 = list(str(N - (i+1)))
  for j in range(len(L2)):
    N2 += int(L2[j])
  M.append(N1+N2)
print(min(M))

Measured memory_bytes: 3864
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  cout << a[0] << b[0] << c[0] << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
using namespace std;
const long long MOD = 1e9 + 7;
int N, K;
int A[103];
int dp[100005];

int main() {
    cin >> N >> K;
    for (int i = 0; i < N; ++i)
        cin >> A[i];
    for (int i = 1; i <= K; ++i) {
        for (int j = 0; j < N; ++j) {
            if (i - A[j] < 0) continue;
            if (dp[i - A[j]] == 0) dp[i] = 1;
        }
    }
    if (dp[K] == 1) cout << "First";
    else cout << "Second";
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,p;
  cin >> n >> p;
  vector<int> a(n);
  bool odd=false;
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(a[i]%2==1){
      odd=true;
    }
  }
  long long ans=1;
  if(!odd){
    if(p==1){
      cout << 0 << endl;
    }
    else{
      for(int i=0;i<n;i++){
        ans*=2;
      }
      cout << ans << endl;
    }
  }
  else{
    for(int i=0;i<n-1;i++){
        ans*=2;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

int main(){
	int a,b;
	cin>>a>>b;
	cout<<a+b/2<<endl;
}


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

using namespace std;

const int N = 2e5 + 100;

int a[N];

int main() {
	int n, k, sum = 0, maxx = 0;
	cin >> n >> k;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	for (int i = 0; i < k; ++i)
		sum += a[i];
	maxx = sum;
	for (int i = k; i < n; ++i) {
		sum += a[i] - a[i - k];
		maxx = max(maxx, sum);
	}
	double ans = maxx;
	ans /= 2;
	ans += k * 0.5;
	cout << fixed << setprecision(9) << ans << '\n';
}


Measured memory_bytes: 1024
use proconio::input;
fn main() {
    input!(n: usize);
    let mut ans = 0;
    let table = trial_division(n);
    //println!("{:?}", table);
    for (&a, &i) in &table {
        if a == 1 {
            continue;
        }
        //let tmp = calc(i);
        //println!("{} => {}", i, tmp);
        ans += calc(i);
    }

    println!("{}", ans);
}

fn calc(n: usize) -> usize {
    for i in 1..n + 1 {
        if (i * (i + 1)) / 2 == n {
            return i;
        } else if (i * (i - 1)) / 2 < n && n < (i * (i + 1)) / 2 {
            return i - 1;
        }
    }
    return 0;
}

// 試し割り
// O(√N)
use std::collections::HashMap;
fn trial_division(n: usize) -> HashMap<usize, usize> {
    let mut primes = HashMap::new();
    let mut i = 2;
    let mut n = n;

    //  n を root n 以下の整数で割り切れるまで割っていく
    while i * i <= n {
        while n % i == 0 {
            n /= i;
            // match primes.get_mut(&i) {
            //   None => { primes.insert(i, 1); },
            //   Some(x) => {
            //       *x += 1;
            //   },
            // }

            match primes.get(&i) {
                Some(&val) => {
                    primes.insert(i, val + 1);
                }
                _ => {
                    primes.insert(i, 1);
                }
            }
        }
        i += 1;
    }

    // 最後にnが素数になっている場合はそれ自身も素因数に含めて終了
    // match primes.get_mut(&n) {
    //   None => { primes.insert(n, 1); },
    //   Some(x) => {
    //     *x += 1;
    //   },
    // }

    match primes.get(&n) {
        Some(&val) => {
            primes.insert(n, val + 1);
        }
        _ => {
            primes.insert(n, 1);
        }
    }

    primes
}


Measured memory_bytes: 2164
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,cnt=0;
    cin >> a >> b >> c;
    if(a==b){
        cnt++;
    }
    if(b==c){
        cnt++;
    }
    if(a==c){
        cnt++;
    }
    if(cnt==1)cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
int main(){
  int n,q;
  cin>>n>>q;
  dsu s(n);
  for(int _=0;_<q;_++){
    int t,u,v;
    cin>>t>>u>>v;
    if(t==0)
      s.merge(u,v);
    if(t==1)
      cout<<s.same(u,v)<<'\n';
  }
  cout<<flush;
}

Measured memory_bytes: 4024
n=int(input())
v=list(map(int, input().split()))
c=list(map(int, input().split()))

score = 0

for i in range(n):
    if (v[i-1] - c[i-1] )> 0:
        score = score + (v[i-1] - c[i-1] )

print(score)

Measured memory_bytes: 3060
/// Swift5 -> Swift2.2
extension String {
    // split(separator:maxSplits:omittingEmptySubsequences:)
    func split(separator separator: Character) -> [String] {
        return self.characters.split(separator).map(String.init)
    }
}
extension Array {
    // init(repeating:count:)
    init(repeating: Element, count: Int) {
       self.init(count: count, repeatedValue: repeating)
    }
}
/// end

let input = readLine()!.split(separator: " ").map { Int($0)! }
let N = input[0]
let K = input[1]
let h = [0] + readLine()!.split(separator: " ").map { Int($0)! }

var dp = Array(repeating: Int.max, count: N + 1)
dp[1] = 0

for i in 1 ... N {
    for j in 1 ... K {
        guard i + j <= N else { break }
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
    }
}

print(dp.last!)


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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n , k;
	cin>>n>>k;
	if(k&1)
	{
		long long cnt = 0LL;
		for(int i = 1; i <= n; i++)
		{
			if(i%k==0) cnt ++;
		}
		cout<<cnt*cnt*cnt<<endl;
	}
	else
	{
		long long cnt = 0LL;
		for(int i = 1; i <= n; i++)
		{
			if(i%k==0) cnt ++;
		}
		long long cnt1 = 0 ;
		int ok  = k/2;
		for(int i = 1; i <= n; i++)
		{
			if(i%k== ok) cnt1 ++;
		}
		cout<<cnt*cnt*cnt + cnt1*cnt1*cnt1<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
	int n, m;
	cin >> n >> m;
	
	int ** A = new int *[n];
	for (int i = 0; i < n; i++)
		A[i] = new int[m];

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> A[i][j];

	int *B = new int[m];
	for (int i = 0; i < m; i++)
		cin >> B[i];

	for (int i = 0; i < n; i++)
	{
		int c = 0;
		for (int j = 0; j < m; j++)
			c += (A[i][j] * B[j]);
		cout << c << endl;
	}
	
	delete[] B;

	for (int i = 0; i < n; i++)
		delete[] A[i];
	delete[] A;

	return 0;
}

Measured memory_bytes: 1236
h, w = list(map(int, input().split()))
n = int(input())
a = list(map(int, input().split()))
color = [[0]*w for i in range(h)]
loch = 0
locw = 0
for i in range(n):
  for j in range(a[i]):
    color[loch][locw]=str(i+1)
    if loch % 2 == 0:
      if locw != w-1:
        locw+=1
      else:
        loch+=1
    else: 
      if locw != 0:
        locw-=1
      else:
        loch+=1

for i in range(h):
  print(" ".join(color[i]))
    

Measured memory_bytes: 3700
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

void precalc() {
}

const int maxn = (int) 1e5 + 5;
int n;
int ls[maxn], rs[maxn];

int read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &ls[i], &rs[i]);
  }
  return true;
}

set<pair<int, int> > st[2];

long long solve1() {
  int x = 0;
  st[0].clear();
  st[1].clear();
  for (int i = 0; i < n; i++) {
    st[0].insert(make_pair(rs[i], i));
    st[1].insert(make_pair(-ls[i], i));
  }
  int t = 0;
  long long res = 0;
  while (!st[0].empty()) {
    int id = st[t].begin()->second;
    st[0].erase(make_pair(rs[id], id));
    st[1].erase(make_pair(-ls[id], id));
    if (x < ls[id]) {
      res += ls[id] - x;
      x = ls[id];
    } else if (x > rs[id]) {
      res += x - rs[id];
      x = rs[id];
    }
    t ^= 1;
  }
  res += abs(x);
  x = 0;
  return res;
}

void solve() {
  long long res = 0;
  for (int it = 0; it < 2; it++) {
    res = max(res, solve1());
    for (int i = 0; i < n; i++) {
      ls[i] *= -1;
      rs[i] *= -1;
      swap(ls[i], rs[i]);
    }
  }
  printf("%lld\n", res);
}

int main() {
  while (read()) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 10368
#include<stdio.h>
int query(int a,int k)
{
	while(1)
	{
		int d=a/k+1;
		int dd=(a%k)/d;
		a-=d*dd;
		if(a%k==0)
		{
			return a/k;
		}
		a-=d;
	}
}
int main()
{
	int n;
	scanf("%d",&n);
	int ans=0;
	while(n--)
	{
		int a,k;
		scanf("%d%d",&a,&k);
		ans^=query(a,k);
	}
	if(ans)
	{
		printf("Takahashi\n");
	}
	else
	{
		printf("Aoki\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define f(i,n) for(int i=0; i<n; ++i)
#define fi(i,st,n) for(int i=st; i<=n; ++i)
#define veci vector<int>
#define vecp vector<pair<int,int> >
#define vecl vector<ll>
int prime[100000+10];

ll lcm(ll a, ll b) {
	return a*b/__gcd(a,b);
}

ll power(ll a, ll n, ll mod) {
	ll res = 1;
	while(n > 0) {
		if(n&1) {
			res = (res*a)%mod;
		}
		a = (a*a)%mod;
		n = n/2;
	}
	return res;
}

ll sum(int arr[], int n) {
	ll res = 0;
	f(i,n) {
		res += arr[i];
	}
	return res;
}

void seive() {
	prime[1] = 0;
	for(int i=2; i<=100000; i++) {
		prime[i] = 1;
	}
	for(ll i=2; i<=100000; i++) {
		if(prime[i]) {
			for(ll j=i*i; j<=100000; j+=i) {
				prime[j] = 0;
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--){
		int n,d;
		cin>>n>>d;
		int ans = 0;
		while(n--) {
			ll p,q;
			cin>>p>>q;
			if(sqrt(p*p+ q*q) <= d) {
				ans++;
			}
		}
		cout<<ans;
 	}
 	return 0;
}


Measured memory_bytes: 3688
#include<stdio.h>
#include<string.h>
int main()
{
    long long int a,b,c=0,o,e,d=1,i,t,j,n,y,k,m,l,r=0;
    char x[105];
    scanf("%lld",&n);
    scanf("%s",x);
   l=strlen(x);
    if(l>n)
    {
    x[n]='.';
    x[n+1]='.';
    x[n+2]='.';
    x[n+3]='\0';
    printf("%s\n",x);
    }
    else{printf("%s\n",x);}
}


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

#define int long long

int memo[100001];

auto main() -> signed {
    int n, k;
    cin >> n >> k;
    set<int> v;
    for(int i=0; i<n; ++i) {
        int a, b;
        cin >> a >> b;
        v.insert(a);
        memo[a] += b;
    }

    for(auto&& e : v) {
        k -= memo[e];
        if(k<=0) {
            cout << e << endl;
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 3968
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n = I()
s = input()
ans = ""
prv = None
for i in range(n):
    if i == 0:
        prv = s[i]
        ans += s[i]
        continue
    if s[i] == prv:
        continue
    else:
        prv = s[i]
        ans += s[i]
print(len(ans))


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

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

int Ssize = s.size();
int Tsize = t.size();

vector<string>ss(Ssize);
vector<string>tt(Tsize);


for(int i = 0;i < Ssize;i++){
  ss[i] = s[i];
}
sort(ss.begin(),ss.end());



for(int i = 0;i < Tsize;i++){
  tt[i] = t[i];
}
sort(tt.begin(),tt.end());


string S,T;

for(int i = 0;i < Ssize;i++){
  S+= ss[i];
}

for(int i = 0;i < Tsize;i++){
  T += tt[i];
}
reverse(T.begin(),T.end());

if(S < T){
  cout << "Yes" <<endl;
}
else{
  cout << "No" <<endl;
}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if ( a < b ) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if ( a > b ) { a = b; return 1; } return 0;}

const ll INF = 1LL << 60;
const int MAX = 100100;

// input 
int N, K;
ll h [MAX];

// dp table
ll dp[MAX];

int main() {
    int N; cin >> N >> K;
    for (int i = 0; i < N; i++) cin >> h[i];

    // init
    for (int i = 0; i < MAX; i++) dp[i] = INF;
    
    dp[0] = 0;

    // loop
    for (int i = 0; i < N; i++) {
        for (int j = 1; j <= K; j++) {
            chmin(dp[i+ j], dp[i] + abs(h[i] - h[i+j]));
        }
    }

    // 0-index
    cout << dp[N-1] << '\n';
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#include <bitset>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1e9+7
using namespace std;
typedef long long ll;
const double pi=acos(-1);

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    ll n;
    cin >> n;
    vector<int> tmp(0);
    while(n){
        ll x;
        x=n%26;
        tmp.push_back(x);
        n/=26;
        if(x==0) n--;
    }
    for(int i=tmp.size()-1;i>=0;i--){
        int shift=tmp[i]-1;
        char ans='a'+shift;
        if(shift>=0) cout << ans;
        else cout << 'z';
    }
    cout << endl;
}

Measured memory_bytes: 3584
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	g := make([][]int, n)
	for i := 0; i < n-1; i++ {
		a, b := scanInt()-1, scanInt()-1
		g[a] = append(g[a], b)
		g[b] = append(g[b], a)
	}

	dp := make([]int, n)
	cnt := make([]int, n)
	par := make([]int, n)
	factorialInit(n)
	memo := make([]int, 0, n)

	var dfs func(v, p int) int
	dfs = func(v, p int) int {
		memo = append(memo, v)
		par[v] = p
		dp[v] = 1
		for _, to := range g[v] {
			if to == p {
				continue
			}
			c := dfs(to, v)
			cnt[v] += c
			dp[v] = (dp[v] * dp[to]) % mod
			dp[v] = (dp[v] * ifac[c]) % mod
		}
		dp[v] = (dp[v] * fac[cnt[v]]) % mod

		cnt[v]++
		return cnt[v]
	}

	dfs(0, 0)

	ans := make([]int, n)
	dp2 := make([]int, n)
	dp2[0] = 1
	ans[0] = dp[0]

	for i := 1; i < n; i++ {
		v := memo[i]
		p := par[v]
		dp2[v] = dp[p] * ifac[cnt[p]-1] % mod * fac[cnt[v]] % mod * fac[n-1-cnt[v]] % mod * ifac[n-cnt[p]] % mod
		dp2[v] = div(dp2[v], dp[v]) * dp2[p] % mod
		ans[v] = dp[v] * dp2[v] % mod * ifac[cnt[v]-1] % mod * fac[n-1] % mod * ifac[n-cnt[v]] % mod
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(wr, ans[i])
	}

}

const mod = 1000000007

var fac, ifac, inv []int

func factorialInit(n int) {
	fac = make([]int, n+1)
	ifac = make([]int, n+1)
	inv = make([]int, n+1)

	fac[0], fac[1] = 1, 1
	ifac[0], ifac[1] = 1, 1
	inv[1] = 1

	for i := 1; i < n; i++ {
		fac[i+1] = fac[i] * (i + 1) % mod
		inv[i+1] = mod - inv[mod%(i+1)]*(mod/(i+1))%mod
		ifac[i+1] = ifac[i] * inv[i+1] % mod
	}
}

func div(b, c int) int {
	a, p, x, u := c, mod, 1, 0
	for p != 0 {
		t := a / p
		a, p = p, a-t*p
		x, u = u, x-t*u
	}
	res := b * x % mod
	if res < 0 {
		res += mod
	}
	return res
}


Measured memory_bytes: 33464
s=input()
for _ in range(int(input())):
 a=input().split()
 i=int(a[1]);j=int(a[2])
 if a[0][0]=='p':print(s[i:j+1])
 else:
  t=a[3]if'p'==a[0][2]else s[i:j+1][::-1]
  s=s[0:i]+t+s[j+1:]

Measured memory_bytes: 5612
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        n: usize,
        k: usize,
        a: [usize; n]
    }

    let mut min_cost = std::usize::MAX;
    for bit in 0..(1 << n) {
        let mut min_height = a[0];
        let mut color_num = 1;
        let mut cost = 0;
        for i in 1..n {
            if color_num == k {
                break;
            }
            if min_height < a[i] {
                min_height = a[i];
                color_num += 1;
            } else {
                if (bit >> i) & 1 == 1 {
                    // min_heightより1高くする
                    cost += (min_height + 1) - a[i];
                    min_height = min_height + 1;
                    color_num += 1;
                }
            }
        }

        if color_num == k {
            min_cost = min_cost.min(cost);
        }
    }
    println!("{}", min_cost);
}


Measured memory_bytes: 2172
S = input()

if S == "ooo" :
    print('1000')
elif S == "oox":
    print('900')
elif S == "oxo" :
    print('900')
elif S == "xoo":
    print('900')
elif S == "oxx":
    print('800')
elif S == "xox":
    print('800')
elif S == "xxo":
    print('800')
else:
    print('700')



Measured memory_bytes: 2940
/*
g++ --std=c++17 A.cpp
*/

#include <iostream>
#include <iomanip> //! for setprecision(20)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int INF = 1000000000;
const int MOD = 1000000007;
using mint = static_modint<MOD>;

/*
  == AC Library Cheat sheet
  documentation: file:///Users/nobu/Downloads/ac-library/document_ja/index.html

  mint
    mint m.pow(int p)  //! return m^p
    mint m.inv() //! returns i that gives (m * i).val() == 1 
    int m.val() 

  fenwick_tree (BIT)
    fenwick_tree<T> fw(int n) //! init a[0] .. a[n-1] with all 0
    void fw.add(int idx, T x); //! a[idx] += x
    T fw.sum(int l, int r); //! return a[l] + .. + a[r-1]

  dsu (UnionFind)
    dsu d(int n)  //! prepare dsu with n nodes
    void d.merge(int x, int y)  //! connect node x and y
    bool d.same(int x, int y)  //! return true if node x and y are connected
    int d.leader(int x)  //! return the leader node of the connected group
    int d.size(int x) //! return the size of the group that node x belongs to
    vector<vector<int>> d.groups() //! return a vector of vectors that contain the nodes in each group

  scc_graph
    scc_graph　g(int n)  //! create a directed graph with n nodes
    g.add_edge(int from, int to)  //! create a directed edge from node from to node to
    vector<vector<int>> g.scc()  //! return the vector of strongly connected components that are topologically sorted

  segtree
    segtree<S, op, e>
      S: type of the monoid 
      op: function to return the product of two elements
      e: function to return the identity element such that op(x, e) == x fo any x 

  lazy_segtree
    lazy_segtree<S, op, e, F, mapping, composition, id>
      F: type of parameters to define the operation applied to the target elements
      mapping: function to return the element after applying the operation to the target element
      composition: function to combine the two sets of operation parameters to one
      id: function to return the operation parameter i such that mapping(i, x) = x for any x

      using S = int;
      S op(S a, S b) { return min(a, b); }
      S e() { return INF; }
      using F = int;
      S mapping(F f, S x) { return min(f, x); }
      F composition(F f, F g) { return min(f, g); }
      F id() { return INF; }

  floor_sum(ll n, ll m, ll a, ll b)   
*/



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

  int k;
  cin >> k;
  string ans;
  rep(i, k) {
    ans += "ACL";
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3672
#include <stdio.h>
#include <stdlib.h>

int main() {
  long long int n,m,a,r,c,h,i;
  m=0;
  a=0;
  r=0;
  c=0;
  h=0;
  scanf("%lld",&n);
  char name[100];
  for(i=0;i<n;i++) {
    scanf("%s",name);
    if(name[0]=='M') {
      m++;
    } else {
      if(name[0]=='A') {
        a++;
      } else {
        if(name[0]=='R') {
          r++;
        } else {
          if(name[0]=='C') {
            c++;
          } else {
            if(name[0]=='H') {
              h++;
            }
          }
        }
      }
    }
  }
  long long int ans = 0;
  ans += m*a*(r+c+h);
  ans += m*r*(c+h);
  ans += m*c*h;
  ans += a*r*(c+h);
  ans += a*c*h;
  ans += r*c*h;
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
using namespace std;
using P = pair<int, int>;
using ll = long long;

int main()
{
    // input
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int q;
    cin >> q;
    vector<int> m(q);
    rep(i,q) cin >> m[i];
    

    // solve
    sort(ALL(a));
    rep(i,q){
        // dp
        vector<vector<bool>> dp(n+1, vector<bool>(m[i]+1));    
        rep(j, n) dp[j][0] = true;
        // dploop
        rep(j, n){
            rep(k, m[i]+1){
                if(a[j] > k) dp[j+1][k] = dp[j][k];
                else dp[j+1][k] = (dp[j][k-a[j]] || dp[j][k]);
            }
        }
        if(dp[n][m[i]]==true) cout << "yes" << endl;
        else cout << "no" << endl;
    }   

    return 0;
}


Measured memory_bytes: 3180
#print(int('-1'))
result = []

for b in range(0, 4):
    result.append([])
    for f in range(0, 3):
        result[b].append([])
        for r in range(0, 10):
            result[b][f].append(0)

n = int(input())
for i in range(0, n):
    b, f, r, v = input().split()
    result[int(b) - 1][int(f) - 1][int(r) - 1] += int(v)

for b in range(0, 4):
    for f in range(0, 3):
        for r in range(0, 10):
            print(' '+ str(result[b][f][r]), end = '')
        print()
    if (b < 3):
        for m in range(0, 20):
            print('#', end = '')
        print()






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

int main(){
	int S,W;cin >> S >> W;
	if(W>=S){
		cout << "unsafe" << endl;
	}else{
		cout << "safe" << endl;
	}
}


Measured memory_bytes: 3636
import sys
sys.setrecursionlimit(20000000)
# N = 5
# ARR = [
#     [1, 2, 1],
#     [1, 3, 1],
#     [2, 4, 1],
#     [3, 5, 1]
# ]
#
# Q, K = 3, 1
#
# BRR = [
#     [2, 4],
#     [2, 3],
#     [4, 5],
# ]
#
#

N = int(input())

ARR = [list(map(int,input().split())) for i in range(N-1)]

Q, K = map(int,input().split())

BRR = [list(map(int,input().split())) for i in range(Q)]



def prepare(arr, n):
    links = [[] for i in range(n)]
    depth = [0 for i in range(n)]
    for i in range(n - 1):
        startNode = arr[i][0] - 1
        endNode = arr[i][1] - 1
        dist = arr[i][2]

        links[startNode].append((endNode, dist))
        links[endNode].append((startNode, dist))

    return links, depth


def dfs(currentNode, parrentNode=-1, dist=0):
    childNodes = links[currentNode]
    depths[currentNode] = dist
    for (childNode, childDistance) in childNodes:
        if childNode == parrentNode:
            continue

        dfs(childNode, currentNode, dist + childDistance)


links, depths = prepare(ARR, N)

dfs(K - 1)

for i in range(Q):
    p1 = BRR[i][0] - 1
    p2 = BRR[i][1] - 1

    d1 = depths[p1]
    d2 = depths[p2]

    print(d1 + d2)

Measured memory_bytes: 197376
#include<bits/stdc++.h>
///...................................*****.................................................///
///        Author :  MD. Rakibul Islam ( mmdrakibul2912@gmail.com )                         ///
///                  Department of Computer Science                                         ///
///                  & Engineering,                                                         ///
///                  Comilla University , Bangladesh.                                       ///
///...................................*****.................................................///

/*....................................Values................................................*/
#define inf 1<<30
#define p5 100007
#define p6 1000007
#define PI acos(-1)
#define M 1000000007

/*....................................Functions.............................................*/
#define sqr(x) x*x
#define sc scanf
#define pf printf
#define scin(x) sc("%d",&(x))
#define scin2(x,y) sc("d",&(x),&(y))
#define scin3(x,y,z) sc("d%d",&(x),&(y),&(z))
#define scln(x) sc("%lld",&(x))
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(v) v.begin(), v.end()
#define ok cout << "ok" << endl
#define mem(x,y) memset(x,y,sizeof(x))
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

/*...................................Data_Types............................................*/
#define lli long long int
#define ull unsigned long long int
#define pii pair < int, int>
#define pll pair < ll, ll>
#define veci vector<int>
#define vecl vector<long long int>
#define vecp vector< pair<int,int> >
#define mapstrint map< string , int >
#define mapstrstr map< string , string >
#define mapint map< int, int >
#define uset unordered_set
#define umap unordered_map
#define pq priority_queue

#define pb push_back
#define mp make_pair
#define ss stringstream

/*.....................................Loops...............................................*/
#define rep( i , a , b ) for( i=a ; i<b ; i++)
#define rev( i , a , b ) for( i=a ; i>=b ; i--)
#define repx( i ,a,b, x) for( i=a ; i<b ; i+=x)

#define FastRead ios_base::sync_with_stdio(0);cin.tie(0)

//int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
//long power(long int x, long int y){ int temp; if( y == 0) return 1; temp = power(x, y/2); if (y%2 == 0) return temp*temp; else return x*temp*temp; }
/*lli gcd(lli x,lli y)
{
if(x==0) return y;
return gcd(y%x,x);
}*/
/*
int dx[5] = {1, -1, 0, 0 };
int dy[5] = {0, 0, 1, -1};
*/

using namespace std;

int main() {
	int X, Y; cin >> X >> Y;
	if (X <= 8 && Y <= 8) cout << "Yay!" << endl;
	else cout << ":(" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    string t;
    cin >> t;

    rep (i, t.size())
    {
        if (t[i] == '?') t[i] = 'D';
    }

    cout << t<< "\n";
    return 0;
}



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

int main () {
    int n;
    bool flag = false;
    cin >> n;
    for (int i=1; i<10; i++) {
        for (int j=1; j<10; j++) {
            if (i*j==n) {
                flag = true;
                break;
            }
        if (flag==true) {
            break;
        }
        }
    }
    if (flag==true) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,j) for(int i=0;i<j;i++)

int main(void){

   long double a,b;

    cin >> a >> b;

    unsigned int z1 = a / b;
    unsigned int z2 = int(a) % int(b);
    long double z3 = a / b;

    cout << z1 << " " << z2 << " ";
    cout << fixed << setprecision(5) << z3 << endl;

    return 0;
}

Measured memory_bytes: 1292
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M; cin >> N >> M;
	vector<int> v(M); rep(i, 0, M) { cin >> v[i]; }
	vector<int>dp(N + 1, INF);
	dp[0] = 0;
	rep(i, 0, M)rep(j, v[i], N + 1)
		chmin(dp[j], dp[j - v[i]] + 1);
	cout << dp[N] << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i] + 1;
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) a[i] = i;

    do {
        print_line(a);
    } while (next_permutation(a.begin(), a.end()));

}


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

const long long MOD = 1000000007;
ll modpow(ll a,ll n,ll mod){
    ll res = 1;
    while(n>0){
        if(n&1)res=res*a%mod;
        a=a*a%mod;
        n >>= 1;
    }
    return res;
}
void solve(long long N, std::vector<long long> A){
    map<int,int> l{};
    bool ok=false;
    rep(i,N){
        if((N-A[i]+1)%2==0){
            l[A[i]]+=1;
            if (2<l[A[i]]){
                cout<<0<<endl;
                ok=true;
                break;
            }
            else if (A[i]==0 &&l[A[i]]==2){
                cout<<0<<endl;
                ok=true;
                break;
            }
        }
        else{
            cout<<0<<endl;
            ok=true;
            break;
        }
    }
    int a = N/2;
    //cout<<a<<endl;
    if(!ok){
    cout<<modpow(2,a,MOD)<<endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 3328
#include<stdio.h>
#define N 100000
int isIncluded(int);//binary search
int arr[N];//first line
int n;//the number of first line
int main(void)
{
  int i;//counter
  int q;//the number of second line
  int x;//the element of second array
  int ans=0;//output
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&arr[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++)
    {
      scanf("%d",&x);
      ans+=isIncluded(x);
    }
  printf("%d\n",ans);
  return 0;
}
int isIncluded(int x)
{
  int head=0;
  int tail=n;
  int middle;
  while(head<tail)
    {
      middle=(head+tail)/2;
      if(x==arr[middle]) return 1;
      if(x>arr[middle]) head=middle+1;
      if(x<arr[middle]) tail=middle;
    }
  return 0;
}




Measured memory_bytes: 2076
#include<bits/stdc++.h>
#define ll          long long
#define dl          double
#define pb          push_back
#define eb          emplace_back
#define mp          make_pair
#define F           first
#define S           second
#define endl        "\n"
#define rep(i,a,b)  for(i=a;i<b;i++)
#define all(v)      v.begin(),v.end()
#define allr(v)     v.rbegin(),v.rend()
#define mod         998244353
#define CIN(V,s,n)  for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n) for(int i=s;i<n;i++){cout <<  V[i] << " ";}
#define fast        ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);   for(ll i=0;i<V.size();i++) V[i] = 0;
#define N           100005
using namespace std;

bool SbS(const pair<int,int> &a,const pair<int,int> &b)
{return (a.second < b.second);}

ll SUMD(ll n);
ll BS(vector<ll> &PS,ll s,ll e,ll ser);
ll MI(ll a, ll m);
bool P[2002LL];
void Sieve(int n=N);
int nCrModp(int n, int r, int p);
vector<ll> PF(ll n);

ll pow(ll b,ll n)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = pow(b,n/2);
    if(n%2==0){return (temp*temp)%mod;}
    else{return (b*((temp*temp)%mod))%mod;}
}

int main()
{
fast;
ll q=1;
//cin >> q;
while(q--)
{
    ll b,w,n,m,k,t,i,j,l;
     cin >> n >> m;
     if((n+m)%2==0)
        cout << (n+m)/2;
     else
        cout << "IMPOSSIBLE";


}
    return 0;
}


//*****************************************************************************************************************************************

ll SUMD(ll n)
{   ll sum=0;
    while(n>0){sum += n%10;n = n/10;}
    return sum;
}

ll BS(vector<ll> &PS,ll s,ll e,ll ser)
{
    if(s>e)
        return s;
    ll mid = (s+e)/2;
    if(PS[mid]==ser)
    {
        return mid;
    }
    else if(PS[mid] > ser)
    {
        return BS(PS,s,mid-1,ser);
    }
    else
        return BS(PS,mid+1,e,ser);
}
ll MI(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

void Sieve(int n)
{
    memset(P,true,sizeof(P));
    P[0] = false;
    P[1]= false;
    for(ll i=2;i*i<=n;i++)
    {
        if(P[i])
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                P[j]=false;
            }
        }
    }

}

int nCrModp(int n, int r, int p)
{
    int C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = min(i, r); j > 0; j--)

            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

vector<ll> PF(ll n)
{
    vector<ll> pf;
    if(n%2==0)
    {
        pf.pb(2LL);
        n = n/2;
        while(n%2==0)
            n = n/2;
    }
    for(ll i=3;i<=sqrt(n);i+=2)
    {
        ll flag=1;
        while(n%i==0)
        {
            if(flag)
            {
                pf.pb(i);
                flag=0;
            }
            n = n/i;
        }
    }
    if(n>2)
        pf.pb(n);

    //COUT(pf,0,pf.size());
    return pf;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<map>
#include<queue>
#include<stack>

using namespace std;

int main()
{
    char s[1000];
    while(scanf("%s",s)!=EOF)
    {
        printf("%c%d%c\n",s[0],strlen(s)-2,s[strlen(s)-1]);
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int i, t, n; 
	long sum;
	
	for(i=0; i<4; i++){
		sum=0;
		
		scanf(" %d %d", &t, &n);
		if(t==1) sum += n*6000;
		else if(t==2) sum += n*4000;
		else if(t==3) sum += n*3000;
		else if(t==4) sum += n*2000;
		
		printf("%ld\n", sum);
	}
	
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    string ans;
    rep(i,n){
        ans += s[i];
        ans += t[i];
    }
    cout << ans << endl;
}

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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

map<ll, ll> mp;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  ll x,y,z,k;cin>>x>>y>>z>>k;
  vector<ll> as, bs, cs, asbs, res;
  for(int i=0;i<x;i++){ll t;cin>>t;as.push_back(t);}
  for(int i=0;i<y;i++){ll t;cin>>t;bs.push_back(t);}
  for(int i=0;i<z;i++){ll t;cin>>t;cs.push_back(t);}
  for(int i=0;i<x;i++){
    for(int j=0;j<y;j++){
      asbs.push_back(as[i]+bs[j]);
    }
  }
  sort(asbs.begin(), asbs.end(), greater<ll>());
  sort(cs.begin(), cs.end(), greater<ll>());
  for(int i=0;i<3005;i++){
    if(asbs.size() == i)break;
    for (int j=0;j<z;j++){
      res.push_back(cs[j]+asbs[i]);
    }
  }
  sort(res.begin(), res.end(), greater<ll>());
  for(int i=0;i<k;i++){
    cout<<res[i]<<endl;
  }

  return 0;
}


Measured memory_bytes: 43384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;


ll mpow(ll x, ll n, ll mod) {
  ll res=1;
  while(n>0) {
    if(n&1) {
      res=res*x%mod;
    }
    x=x*x%mod;
    n>>=1;
  }
  return res;
}

ll f(ll v) {
  if(v==0) return 0;
  bitset<20> bit(v);
  ll m=bit.count();
  return f(v%m)+1;
}

int main() {
  ll n;
  string s;
  cin >> n >> s;
  ll base=0;
  for(ll i=0;i<n;i++) {
    if(s[i]=='1') base++;
  }
  ll l=base-1;
  ll r=base+1;
  ll low=0,high=0;
  if(l<0) low=-1;
  else if(l==0) {
    low=0;
  }
  else {
    ll tmp=0;
    for(ll i=0;i<n;i++) {
      tmp*=2;
      if(s[i]=='1') tmp++;
      tmp%=l;
    }
    low=tmp;
  }
  {
    ll tmp=0;
    for(ll i=0;i<n;i++) {
      tmp*=2;
      if(s[i]=='1') tmp++;
      tmp%=r;
    }
    high=tmp;
  }
  for(ll i=0;i<n;i++) {
    ll res=0;
    if(s[i]=='1') {
      if(l==0) {
        res=0;
      }
      else {
        ll tmp=(low-mpow(2,n-1-i,l)+l);
        tmp%=l;
        res=f(tmp)+1;
      }
    }
    else {
      ll tmp=high+mpow(2,n-1-i,r);
      tmp%=r;
      res=f(tmp)+1;
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 3688
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>
#include <map>


#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;

//素数num以下のふるい
bool Find[110000] ; // 探索リスト
void furui(int num){
   for(int i = 2; i <= num; i++){
        Find[i] = true;
        if(i%2==0) Find[i] = false;
    }
    for(int i = 2; i*i < num; i++){
        if(Find[i] == false) continue; 
        for(int j = i * 2; j< num; j += i) {
            if(Find[j]) Find[j] = false;
        }
    }
    Find[2]= true; 
}

int main(void){

const int zmax=110000;
int n,sw=0;
	
	furui(zmax);
	while(cin >> n){
		if(n==0 || cin.eof()) break;
		int s=0,sn=0;
		rep2(i,2,zmax){
			if(Find[i]){
				s += i;
				sn++;
			}
			if(sn >= n) break;
		}
		cout << s << endl;
	}
	return 0;
	
	
}

Measured memory_bytes: 1272
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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

  int ab,bc,ac; cin>>ab>>bc>>ac;
  int area = (ab * bc) / 2;
  cout<<area<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;

struct Point{
	double x;
	double y;
};

int Kcurve(int n, Point p1, Point p2){
	if (n==0){
		return 0;
	}
	Point a,b,c;
	a.x=(2.0/3.0)*p1.x+(1.0/3.0)*p2.x;
	a.y=(2.0/3.0)*p1.y+(1.0/3.0)*p2.y;
	b.x=p1.x+(1.0/2.0)*(p2.x-p1.x)-(1.0/(2*sqrt(3)))*(p2.y-p1.y);
	b.y=p1.y+(1.0/(2*sqrt(3)))*(p2.x-p1.x)+(1.0/2.0)*(p2.y-p1.y);
	c.x=(1.0/3.0)*p1.x+(2.0/3.0)*p2.x;
	c.y=(1.0/3.0)*p1.y+(2.0/3.0)*p2.y;
	
	Kcurve(n-1,p1,a);
	cout << a.x << " " << a.y << endl;
	Kcurve(n-1,a,b);
	cout << b.x << " " << b.y << endl;
	Kcurve(n-1,b,c);
	cout << c.x << " " << c.y << endl;
	Kcurve(n-1,c,p2);
	
	return 0;
}
int main(){
	Point a,b;
	a.x=0.0;
	a.y=0.0;
	b.x=100.0;
	b.y=0.0;
	int n;
	cin >> n;
	cout << 0 << " " << 0 << endl;
	Kcurve(n,a,b);
	cout << 100 << " " << 0 << endl;
	return 0;
}

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

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    int k[m];
    int s[10][10];
    int p[m];
    for(int i=0; i<m; i++){
        scanf("%d", &k[i]);
        for(int j=0; j<k[i]; j++){
            scanf("%d", &s[i][j]);
        }
    }
    for(int i=0; i<m; i++){
        scanf("%d", &p[i]);
    }
    int bi = pow(2, n) - 1;
    int ans = 0;
    for(int i=bi; i>=0; i--){
        int buf = i;
        int f=1;
        /*printf("bit : ");
        for(int j=0; j<n; j++){
            printf("%d", buf%2);
            buf = buf/2;
        }
        printf("\n");*/
        for(int j=0; j<m; j++){
            int sum = 0;
            for(int l=0; l<k[j]; l++){
                int t = i;
                for(int q=1; q<s[j][l]; q++){
                    t = t/2;
                }
                if(t % 2){
                    //printf("%d ", (int)pow(2, s[j][l]-1));
                    sum++;
                }
            }
            //printf("sum : %d\n", sum);
            if(sum % 2 != p[j]){
                f = 0;
            }
        }
        //printf("\n");
        if(f){
            ans++;
        }
    }
    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 384
# D - I hate Factorization
x = (int)(input())

flg = False
if x >= 0:
    for i in range(0, x + 1):
        for j in range(-i - 1, i + 1):
            if i ** 5 - j ** 5 == x:
                flg = True
                break

        if flg:
            print(str(i) + " " + str(j))
            break
else:
    for i in range(0, x + 1):
        for j in range(-i - 1, i + 1):
            if i ** 5 - j ** 5 == x:
                flg = True
                break

        if flg:
            print(str(j) + " " + str(i))
            break

Measured memory_bytes: 9212