akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)(n),(int)(n))
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
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 initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,s,result=0;
  
  scanf("%lld %lld %lld",&n,&k,&s);
  rep(i,k){
    printf("%lld ",s);
  }
  if(s==(ll)pow(10,9)){
    rep(i,n-k){
      printf("%lld ",s-1);
    }
  }else{
    rep(i,n-k){
      printf("%lld ",s+1);
    }
  }
  return 0;
}



Measured memory_bytes: 1280
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<utility>

using namespace std;

#define SPEEDY cin.tie(0);ios::sync_with_stdio(false);

#define REP(i,n) for(int i=0;i<(n);i++)
#define ARREP(i,n,X) for(int i=0;i<(n);i++)cin>>X[i]
#define FOR(i,X,n) for(int i=(X);i<(n);i++)
#define EREP(i,n) for(int i=1;i<=n;i++)

#define DEB(X) if(mode==1)cout<< #X <<": "<<X<<" ";
#define DEB2(X) if(mode==1)cout<< X <<" ";
#define ARDEB(i,X) if(mode==1)cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define FORDEB(n,X) if(mode==1)for(int i=0;i<(n);i++)ARDEB(i,X)
#define END if(mode==1)cout<<endl;

typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define ALL(X) X.begin(),X.end()
struct edge{int to,cost;};
//struct edge{int from,cost,to;};

const int INF=100000000;
int mode=1;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(abs(a-c)<abs(a-b)){
		cout<<"B"<<endl;
	}
	else{
		cout<<"A"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    double s,l,h,a1,b1,o1,c1,c;
    scanf("%lf %lf %lf",&a1,&b1,&o1);
    o1=(o1*M_PI)/180.0;
    c=sqrt(b1*b1+a1*a1-2.0*a1*b1*cos(o1));
    c1=c;
    s=0.5*a1*b1*sin(o1);
    h=b1*sin(o1);
    l=a1+b1+c1;
    printf("%lf\n%lf\n%lf\n",s,l,h);
    return 0;
}



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

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

int	main()
{
	int	N;
	cin >> N;
	if (N % sum_of_digits(N) == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <cassert>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

#define rep(i, l, r) for (ll i = (l); i <= (r); i++)
#define irep(i, r, l) for (ll i = (r); i >= (l); i--)
#define vec(t) vector<int>

using namespace std;
using ll = long long;
using veci = vec(int);
using vecll = vec(ll);

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

    int N;

    cin >> N;

    veci H(N);
    rep(i, 0, N - 1) cin >> H[i];
    reverse(H.begin(), H.end());
    int c = 0;
    int ma = H[N - 1];
    irep(i, N - 1, 0) {
        if (H[i] >= ma) {
            c++;
        }
        ma = max(ma, H[i]);
    }

    cout << c << endl;
}

Measured memory_bytes: 256
import datetime

h1,m1,h2,m2,k = map(int, input().split())

dt1 = datetime.datetime(year=2017, month=10, day=10, hour=h1, minute=m1)
dt2 = datetime.datetime(year=2017, month=10, day=10, hour=h2, minute=m2)

t = abs(dt2 - dt1)
print((t.seconds - k*60) // 60)

Measured memory_bytes: 9432
#include <stdio.h>
int main(void)
{
    int a,b,c;
    long int x,y;
    scanf("%d %d %d %ld %ld",&a,&b,&c,&x,&y);
    c=2*c;
    long long int ans=0;
    if(a+b>c)
    {
        if(x>y)
        {
            ans+=y*c;
            if(a>c)ans+=(x-y)*c;
            else ans+=(x-y)*a;
        }
        else
        {
            ans+=x*c;
            if(b>c)ans+=(y-x)*c;
            else ans+=(y-x)*b;
        }
    }
    else ans+=x*a+y*b;
    printf("%lld",ans);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define IOS {ios :: sync_with_stdio(false); cin.tie(0);cout.tie(0); }
#define F first
#define S second
#define pb push_back
typedef long double ld;
#define deci(n) cout << fixed << setprecision(n);
typedef long long ll;

#define mem0(x)  memset(x,0,sizeof(x));
#define memm1(x) memset(x,-1,sizeof(x));
#define all(a) a.begin(), a.end()
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define fori2(n) for(ll i=1;i<=n;i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define forj2(n) for(ll j=1;j<=n;j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define fork2(n) for(ll k=1;k<=n;k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
const ll md = 1e9 + 7;

#define BSET(a, p) ((a) | (1ll << (p)))
#define BCHK(a, p) ((a) & (1ll << (p)))
#define BXOR(a, p) ((a) ^ (1ll << (p)));
#define BREM(a, p) (BCHK(a, p)?(BXOR(a, p)):(a))
#define BSHO(a, N) (bitset<N>(a))
// const ll N = 100005;
// ll fac[N] = {1};
// #define calfac for(ll i=1  ;i<N;i++) fac[i] = (fac[i-1]*i)%md;
// ll C[N+1][M+1]; 
// void  ncr(){
//     ll n = N,k = M; 
//     for (ll i = 0; i <= n; i++) { 
//         for (ll j = 0; j <= min(i, k); j++) { 
//             if (j == 0 || j == i)  C[i][j] = 1; 
//             else C[i][j] = C[i - 1][j - 1] +  C[i - 1][j]; 
//         } 
//     } 
// } 


#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update> 
// Ordered set docs:
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}
ll modInv(ll a)
{
    return pow(a,md-2);
}
 
// ll nCr(ll n,ll r)
// {
//     return (fac[n]*modInv((fac[r]*fac[n-r])%md))%md;
// }

 
ll po(ll x,ll n){
    if(n==0) return 1;
    if(n%2==1) return (x*po(x,n-1));
    else {
        ll k=po(x,n/2);
        return (k*k);
    }
}
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
}
 
int32_t main(){
    IOS;
    ll n,x,t;
    cin >> n >> x >> t;
    cout << (n/x)*t + ((n%x!=0)?t:0) <<"\n";
} 

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

int main() {
    int H, W; cin >> H >> W;
    int count = 0;
    for (int i = 0; i < H; ++i) {
        string S; cin >> S;
        for (auto c : S) if (c == '#') ++count;
    }
    if (count == H + W - 1) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define INF INT_MAX;
typedef long long ll;
using namespace std;
int main(){
  int N ,M ;
  cin >> N >> M;
  int sx[N],sy[N],cx[M],cy[M],ans[N];
  for(int i=0;i<N;i++){
    cin >> sx[i] >> sy[i];
  }

  for(int i=0;i<M;i++){
    cin >> cx[i] >> cy[i];
  }

  rep(i,N){
    int min=INF;
    rep(j,M){
      int m=abs(sx[i]-cx[j])+abs(sy[i]-cy[j]);
      if(m<min){
        min = m;
        ans[i]=j;
      }
    }
  }

  rep(i,N) cout << ans[i]+1 << endl;

}

Measured memory_bytes: 384
#include <iostream>

int main(){
    int n;
    std::cin >> n;
    int xs[n];
    for (int i = 0; i < n; i++){
        std::cin >> xs[i];
    }
    for (int i = n - 1; i > 0; i--){
        std::cout << xs[i] << ' ';
    }
    std::cout << xs[0] << '\n';
    return 0;
}



Measured memory_bytes: 3088
n=int(input())
l=list(map(int,input().split()))
box=[0]*(n+1)
for i in range(n):
    k=n-i
    count=0
    for j in range(k,n+1,k):
        count+=box[j]
    if count%2!=l[k-1]:
        box[k]=1
ll=[]
for i in range(1,n+1):
    if box[i]==1:
        ll.append(i)
print(box.count(1))
print(*ll) 

Measured memory_bytes: 97688
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<string>
#include<sstream>
using namespace std;
int inf = 1000000000;

int main(){

  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++) cin >> a[i];

  int cnt = 0;
  for(int i=0; i<n; i++){
    while(a[i] % 2 == 0){
      a[i] /= 2;
      cnt++;
    }
  }
  cout << cnt << endl;

  return 0;
}



//


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <iomanip>
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
using Graph = vector<vector<int>>;
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; }
const int INF = 1000000000;
const int MOD = 1000000007;

typedef pair<int, int> P;
int myAbs(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

/*vector<bool> seen;
void dfs(const Graph& G, int v, int count) {
    seen[v] = true;
    count = 0;
    for (auto next_v : G[v]) {
        if (seen[next_v]) continue;
        if (count > 2) continue;
        count++;
        cout << count << ":" << next_v << endl;
        dfs(G, next_v, count);
    }
}*/

int main() {
    long double A, B, C;
    cin >> A >> B >> C;
    long double a, b, c;
    a = sqrtl(A);
    b = sqrtl(B);
    long double AB = a*b;
    //double ab = pow(AB, 0.5);
    //cout << AB << endl;
    if (A + B + (AB * 2) - C < 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using namespace std;

typedef long long int ll;

int mask;

bool cmp(const vector<ll> &a, const vector<ll> &b){
    ll aVal = 0;
    for (int i = 0; i < 3; i++){
        if (mask & (1 << i)) aVal += a[i];
        else aVal -= a[i];
    }

    ll bVal = 0;
    for (int i = 0; i < 3; i++){
        if (mask & (1 << i)) bVal += b[i];
        else bVal -= b[i];
    }

    return aVal > bVal;
}

int main()
{
    int n, m; scanf("%d %d", &n, &m);

    vector< vector<ll> > a(n, vector<ll>(3));

    for (int i = 0; i < n; i++) scanf("%lld %lld %lld", &a[i][0], &a[i][1], &a[i][2]);

    ll ans = 0;
    ll res[3] = {0, 0, 0};
    for (mask = 0; mask < 8; mask++){
        res[0] = 0, res[1] = 0, res[2] = 0;
        sort(a.begin(), a.end(), cmp);
        for (int i = 0; i < m; i++){
            res[0] += a[i][0];
            res[1] += a[i][1];
            res[2] += a[i][2];
        }
        ans = max(ans, abs(res[0]) + abs(res[1]) + abs(res[2]));
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define tc printf("Case %d: ", cs)
#define tcn printf("Case %d:\n", cs);
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);

#define dbg1(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;
#define dbg4(w,x, y, z) cerr << #w << " = " << w << ", " <<#x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
  return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if ( it != v.begin() ) os << ", ";
    os << *it;
  }
  return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if ( it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if ( it != v.begin() ) os << ", ";
    os << it -> first << " = " << it -> second ;
  }
  return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () { cerr << endl; }

template <typename T>
void faltu( T a[], int n ) {
  for (int i = 0; i < n; ++i) cerr << a[i] << ' ';
  cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) { cerr << arg << ' '; faltu(rest...); }
// Program showing a policy-based data structure.
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less 
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
// GNU link : https://goo.gl/WVDL6g
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;

/**___________________________________________________**/



int main()
{
  FASTIO
  /*
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
//*/
  long double a, b, x;
  cin >> a >> b >> x;
  if (x * 2 > a * a * b) {
    x = a * a * b - x;
    cout << setprecision(20) << (long double) 90 / (long double) asin(1) * atan(x / a / a / a * 2) << endl;
  }
  else {
    long double val = x / a / b / b;
    val *= 2;
    val = atan(val);
    long double pi = asin(1) * 2;
    val *= 90;
    val /= pi / 2;
    val = 90 - val;
    cout << setprecision(20) << val << endl;
  }
}

Measured memory_bytes: 256
def examC():
    N, x  = LI()
    A = LI()
    ans = 0
    cur = A[0]
    if A[0]>x:
        ans += A[0]-x
        cur = x
    for i in range(1,N):
        if cur+A[i]<=x:
            cur = A[i]
            continue
        ans += cur+A[i]-x
        cur = A[i]-(cur+A[i]-x)
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = 10**18

if __name__ == '__main__':
    examC()


Measured memory_bytes: 60252
import java.util.*

fun main() {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val good = BooleanArray(n+1){true}
    val h = IntArray(n+1)
    good[0] = false
    for(i in 1..n) {
        h[i] = sc.nextInt()
    }

    for(i in 0 until m) {
        val a = sc.nextInt()
        val b = sc.nextInt()
        if(h[a] > h[b]) {
            good[b] = false
        } else if(h[a]==h[b]) {
            good[a] = false
            good[b] = false
        } else {
            good[a] = false
        }
     }

    print(good.count { it })

}

Measured memory_bytes: 60032
#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef int ftype;
typedef complex<ftype> point;
 
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define FAIL0 {cout << "0\n"; return 0;}
#define FAIL1 {cout << "-1\n"; return 0;}
#define FAILNO {cout << "No\n"; return 0;}
#define YES {cout << "Yes\n"; return 0;}

const int MAXN = 1e5+3;
const int MOD = 1e9+7;

LL N;

int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N;
    cout << N*(N-1)/2 << endl;
    return 0;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

ll com[51][51];

int main() {
    com[0][0] = 1;
    for (int i = 1; i < 51; ++i) {
        for (int j = 0; j <= i; ++j) {
            com[i][j] += com[i-1][j];
            if (j > 0) com[i][j] += com[i-1][j-1];
        }
    }

    int N, A, B;
    cin >> N >> A >> B;
    vector<ll> v(N);
    rep(i, N) cin >> v[i];
    sort(v.rbegin(), v.rend());

    double avg = 0;
    rep(i, A) avg += v[i];
    avg /= A;

    int cnt = 0; // 平均値に使用される数字の中で一番小さい数字の個数
    rep(i, N) if (v[i] == v[A - 1]) cnt++;
    ll ans = 0;
    if (v[0] == v[A - 1]) { // 平均値に使用される数値がすべて同じ場合
        for (int i = A; i <= B; i++) {
            if (cnt < i) break; // cnt個以上は選べない
            ans += com[cnt][i]; // cnt個から平均値に使用される数値をi個選ぶ
        }
    } else {
        int cnt2 = 0;
        rep(i, A) if (v[i] == v[A - 1]) cnt2++;
        ans = com[cnt][cnt2]; // 平均値に使用される一番小さい数字が数列中にcnt個あり、その中のcnt2個を平均値の計算に採用する
    }

    cout << fixed << setprecision(10) << avg << endl;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;
vi a;

int main(){
	cin>>n;
	int N=2*n,S=N,cnt=0;
	a=vi(N);
	for(int i=0;i<N;i++) cin>>a[i];
	vi b(N,1);
	for(int i=0;i<N;i+=2){
		if(a[i]>0&&a[i+1]>0){
			b[a[i]-1]--;
			b[a[i+1]-1]--;
			S-=2;
		}
		else if(a[i]>0||a[i+1]>0) b[a[i]+a[i+1]]=2,cnt++;
	}
	vvl dp(n+1,vl(n+1));
	dp[0][0]++;
	for(int i=0;i<N;i++) if(b[i]>0){
		vvl DP(n+1,vl(n+1));
		if(b[i]==1){
			for(int j=0;j<=n;j++) for(int k=0;k<=n;k++) if(dp[j][k]){
				int x=(S-2*cnt+j-k)/2;
/*				if((S-2*cnt+j-k)%2==1) cout<<S<<' '<<cnt<<' '<<j<<' '<<k<<endl;
				assert((S-2*cnt+j-k)%2==0);
				if(i==0&&j==0&&k==0) cout<<S<<' '<<cnt<<' '<<j<<' '<<k<<endl;*/
				if(k<n) (DP[j][k+1]+=dp[j][k]*x)%=mod;
				if(k) (DP[j][k-1]+=dp[j][k])%=mod;
				if(j<n) (DP[j+1][k]+=dp[j][k])%=mod;
			}
			S--;
		}
		if(b[i]==2){
			for(int j=0;j<=n;j++) for(int k=0;k<=n;k++) if(dp[j][k]){
				if(j) (DP[j-1][k]+=dp[j][k]*j)%=mod;
				if(k<n) (DP[j][k+1]+=dp[j][k])%=mod;
			}
			cnt--;S--;
		}
		dp=DP;
/*		for(int j=0;j<=n;j++){
			for(int k=0;k<=n;k++) cout<<dp[j][k]<<' ';
			cout<<endl;
		}
		cout<<endl;*/
	}
	cout<<dp[0][0]<<endl;
}

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

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

    int a=0, b=0;
    rep(i, N) if(c[i] == 'R') ++a;
    int ans = max(a, b);
    rep(i, N){
        if(c[i] == 'R') --a;
        else ++b;
        int now = max(a, b);
        ans = min(ans, now);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3728
//Abhinav ---IIIT_A
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
#define vpii vector<pair<int,int>> 
ld pie=3.141592653589793238462643383279;
int mod=1e9+7;
int dx[]={-1,1,0,0};
int dy[]={0,0,1,-1};


int dig(int a){
  int r=0;
  while(a!=0){
    int xp=a%10;
    a/=10; if(xp==1) ++r;
  }
  return r;
}

int sp(int a){
  int s=0;
  int ano=a-1;
  while(a!=0){
    s+=a%10;
    a/=10;
  }
  while(ano!=0){
    s+=ano%10;
    ano/=10;
  }
  return s;
}

int fun(int a){
  int r=1;
  f(i,0,10) r*=a;
  return r;
}

void q1(){
  int n,b,q; cin>>n>>b>>q;
  int a[n];  f(i,0,n) a[i]=i/b;
  int curr=-1;
  int load=0;
  while(q--){
    int x; cin>>x;
    if(a[x]!=curr){
      curr=a[x];
      load++;
    }
  }
  cout<<load<<"\n";
}
void q2(){
  int t; cin>>t;
  while(t--){
    int n; cin>>n;
    int a[2*n+5];
    f(i,0,2*n) cin>>a[i];
    int o=0,e=0;
    vector<int> odd,even;
    f(i,0,2*n) if(a[i]%2==1) {
      ++o; odd.pb(i+1);
    }
    else {
      ++e; even.pb(i+1);
    }
    vpii vt;
    if(o&1){
      for(int i=0;i<odd.size()-1;i+=2)
        vt.pb({odd[i],odd[i+1]});
      for(int i=0;i<even.size()-1;i+=2)
        vt.pb({even[i],even[i+1]});
    }else{
      if(o>0){
        for(int i=2;i<odd.size();i+=2)
        vt.pb({odd[i],odd[i+1]});
      for(int i=0;i<even.size();i+=2)
        vt.pb({even[i],even[i+1]});
      }else{
          for(int i=2;i<even.size();i+=2)
        vt.pb({even[i],even[i+1]});
      }
    }
    for(auto it : vt) cout<<it.ff<<" "<<it.ss<<"\n";
  }
}
void q3(){
  int t; cin>>t;
  vector<int> xx;
  int pr[100005]={0};
  f(i,2,100005) if(pr[i]==0){
    if(i&1){
      xx.pb(i); for(int j=2*i;j<100005;j+=i) pr[j]=i;
   }
  }
  while(t--){
    int n; cin>>n;
    if(n==1) cout<<"FastestFinger\n";
    else if (n&1) cout<<"Ashishgup\n";
    else{
      int curr=0;
      while(n!=1){
        if(n&1){
          ++curr;
          break;
        }
        int mx=-1;
        for(auto it : xx) if(n%it==0) mx=it;
        if(mx==-1){
          if(n==2){
            break;
          }else{
            ++curr;
            break;
          }
        }else{
          n/=mx;
          curr++;
        }
      }
      if(curr%2==0) cout<<"Ashishgup\n";
      else cout<<"FastestFinger\n";
    }
  }
}
int32_t main(){
#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n; cin>>n;
  string ret="";
  while(n!=0){
    n--;
    ret+=('a'+n%26);
    n/=26;
  }
  reverse(ret.begin(),ret.end());
  cout<<ret;
  return 0;
}


Measured memory_bytes: 3636
n = gets.to_i

m = a = r = c = h = 0
cm = ca =cr = cc = ch =0
for i in 1..n
  s = gets
  case s[0]
    when "M"
    	m = m + 1
		when "A"
		  a = a + 1
		when "R"
			r = r + 1
		when "C"
			c = c + 1
		when "H"
			h = h + 1
	end
end

sum = m*a*(r+c+h)+(m+a)*r*(c+h)+(m+a+r)*c*h

puts sum


Measured memory_bytes: 1788
// DP F

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1e9;
const long long INFL = 1LL<<60;

void dump(const vector<pair<int, int>>& a)
{
  for (auto v : a) {
    cerr << v.first << " " << v.second << endl;
  }
}

void dump(const vector<int>& a)
{
  for (auto v : a) {
    cerr << v << " ";
  }
  cerr << endl;
}

int main() {
  vector<int> rank(8, 0);
  int other = 0;
  int n;
  cin >> n;
  rep(i, n) {
    int a;
    cin >> a;
    if (a < 400) {
      rank[0]++;
    } else if (a < 800) {
      rank[1]++;
    } else if (a < 1200) {
      rank[2]++;
    } else if (a < 1600) {
      rank[3]++;
    } else if (a < 2000) {
      rank[4]++;
    } else if (a < 2400) {
      rank[5]++;
    } else if (a < 2800) {
      rank[6]++;
    } else if (a < 3200) {
      rank[7]++;
    } else {
      other++;
    }
  }

  int ans = 0;
  rep(i, 8) {
    if (rank[i] != 0) {
      ans++;
    }
  }

  int ansMin = ans;
  int ansMax = ans;
  if (ansMin == 0) {
    ansMin = 1;
  }
  ansMax += other;
  cout << ansMin << " " << ansMax << endl;

  return 0;
}


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

vector<vector<int>> graph;
bool visited[2002] = {false,};
int dist[2002] = {0,};


void dfs2(int s, int depth){
    depth++;
    dist[s] = depth;
    for (auto v1: graph[s]) {
        if(dist[v1] == -1){
            dfs2(v1, depth);
        }
    }
    depth--;
    return;
}

void dfs3(int s, int prev, int depth, pair<int,int> ex){
    if(ex.first == s && ex.second == prev){}
    else if(ex.first == prev && ex.second == s){}
    else{depth++;}
    dist[s] = depth;
    for (auto v1: graph[s]) {
        if(dist[v1] == -1){
            dfs3(v1, s, depth, ex);
        }
    }
    if(ex.first == s && ex.second == prev){}
    else if(ex.first == prev && ex.second == s){}
    else{depth--;}
    return;
}

int main(){
    int n, k;
    cin >> n >> k;
    graph.resize(n);
    vector<int> ina(n-1), inb(n-1);
    for(int i = 0; i < n-1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        ina[i] = a; inb[i] = b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    int ans = 99999;
    if(k&1){
        for(int i = 0; i < n-1; i++){
            pii ex(ina[i],inb[i]);
            int num = 0;
            for(int j = 0; j < n; j++){
                dist[j] = -1;
            }
            dfs3(ina[i],-1,-1,ex);
            for(int j = 0; j < n; j++){
                if(dist[j] > k/2){
                    num++;
                }
            }
            ans = min(num,ans);

        }
    }else{
        for(int i = 0; i < n; i++){
            int num = 0;
            for(int j = 0; j < n; j++){
                dist[j] = -1;
            }
            dfs2(i,-1);
            for(int j = 0; j < n; j++){
                if(dist[j] > k/2){
                    num++;
                }
            }
            ans = min(num,ans);
        }
    }
    cout << ans << endl;

    return 0;
}


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

typedef long long lli;

lli mod = 1e9 +7;
lli dp[100001], presum[100001], a[100002], n, k;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin >> n >> k;
    for(int i=1; i<=n; i++)cin>>a[i];
	for(int i=1; i<=k+1; i++)presum[i]=1;
    for(int i=1; i<=n; i++)
    {
    	for(lli j=0; j<=k; j++)
    		dp[j] = (presum[j+1] - presum[max(0LL, j-a[i])] + 2*mod)%mod;
    	for(int x=1; x<=k+1; x++)
    		presum[x] = (presum[x-1]+dp[x-1])%mod;
    }
    cout << dp[k];
}

Measured memory_bytes: 5168
'use strict'
function Main(input) {
  const inputArray = input.split(' ').map(n => Number(n));
  const k = inputArray[0];
  const x = inputArray[1];
  const first = x - k + 1;
  const last = x + k - 1;
  var result = '';
  for (var i = first; i <= last; i++) {
    if (i == first) {
      result += i;
    } else {
      result += ` ${i}`;
    }
  }
  
  console.log(result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int n;
string s[100010];
map<string, int> M;
long long ans;

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

    cin >> n;

    for(int i=0; i<n; i++) {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());

        if(M.find(s[i]) == M.end()) M[s[i]] = 1;
        else M[s[i]]++;
    }

    map<string,int>::iterator it = M.begin();

    for(it; it != M.end(); it++) {
        long long t = it->second;
        ans += t * (t-1) / 2;
    }

    cout << ans;
}


Measured memory_bytes: 16640
using System;
using System.Linq;

namespace AtCoderContest
{
    class Program
    {
        static void Main()
        {
            var firstLine = Console.ReadLine();
            var n = int.Parse(firstLine.Split(" ")[0]);
            var d = int.Parse(firstLine.Split(" ")[1]);

            var origin = new Point(0, 0);
            var answer = Enumerable.Range(1, n)
                      .Select(i => Console.ReadLine())
                      .Select(line => new Point(int.Parse(line.Split(" ")[0]), int.Parse(line.Split(" ")[1])))
                      .Count(point => point.Distance(origin) <= d);

            Console.WriteLine(answer);
        }
    }

    class Point
    {
        public int X { get; set; }
        public int Y { get; set; }

        public Point(int x, int y)
        {
            X = x;
            Y = y;
        }

        public double Distance(Point other)
        {
            var distanceSquare = Math.Pow(X - other.X, 2) + Math.Pow(Y - other.Y, 2);
            return Math.Sqrt(distanceSquare);
        }
    }
}


Measured memory_bytes: 41608
#include<stdio.h>

int main(void) {
	int k, a, b, i, frg = 0;

	scanf("%d", &k);
	scanf("%d %d", &a,&b);

	for (i = a; i <= b; i++) {
		if (i%k == 0) {
			frg = 1;
			break;
		}
	}
	if(frg==1) printf("OK\n");
	else printf("NG\n");

	return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e5+10;
int n,a,b,h[maxn],H[maxn];
main()
{
    cin>>n>>a>>b;int i,r=0;
    for(i=1;i<=n;i++){
        scanf("%lld",&h[i]);
        r=max(r,(int)ceil((double)h[i]/b));
    }
    int l=0,mid,ret;
    while(l+1<r){
        mid=(l+r)>>1;ret=0;
        for(i=1;i<=n;i++)
            H[i]=h[i]-b*mid;
        for(i=1;i<=n;i++)
            ret+=max(0ll,(int)ceil((double)H[i]/(a-b)));
        if(ret<=mid) r=mid;
        else l=mid;
    }
    cout<<r;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> retu(N);
  for(int i = 0; i < N; i++){
    cin >> retu.at(i);
  }
  vector<int> kazu(N);
   for(int i = 0; i < N; i++){
    kazu.at(i) = retu.at(i);
  }
  sort(kazu.begin(), kazu.end());
  int count = 0;
   for(int i = 0; i < N; i++){
    if(kazu.at(i) != retu.at(i)){
      count++;
    }
  }
  if(count == 2){
    cout << "YES" << endl;
    return 0;
  }
  if(count == 0){
    cout << "YES" << endl;
    return 0;
  }
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const long long INF = 1LL<<60;

vector<ll> load[100005];

typedef pair<ll,ll> Pair;

int main(){
ll N,M;
cin >> N >> M;

for(ll i = 0;i < M;++i){
    ll A,B;    
    cin >> A >> B;
    A--;B--;
    load[A].push_back(B);
    load[B].push_back(A);
}

    // BFS のためのデータ構造
    vector<ll> dist(N, -1); // 全頂点を「未訪問」に初期化
    vector<ll> pre(N,-1);
    queue<ll> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;
    que.push(0); // 0 を頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        ll v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : load[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            pre[nv] = v;
            que.push(nv);
        }
    }

bool flg = true;

for(ll i = 0;i < N;++i) if(dist[i] == -1) flg = false;

if(flg){

    cout << "Yes" << endl;

    // 結果出力 (各頂点の頂点 0 からの距離を見る)
    for (ll v = 0; v < N; ++v){

        if(v == 0) continue;
        ll ans = pre[v];
        ans++;
        cout << ans << endl;

    } 

}
else cout << "No" << endl;

return 0;

}   


Measured memory_bytes: 13652
N, A = map(int, input().split())
*x, = map(int, input().split())
l = N * A + 1

# dp[n枚選ぶ][m枚目まで][総和]
dp = [[[0] * l for _ in range(N + 1)] for _ in range(N + 1)]
dp[0][0][0] = 1
for n in range(0, N + 1):
    for m in range(N):
        for s in range(0, l):
            dp[n][m + 1][s] += dp[n][m][s]
            if s >= x[m]:
                dp[n][m + 1][s] += dp[n - 1][m][s - x[m]]

print(sum([dp[n][N][n * A] for n in range(1, N + 1)]))

Measured memory_bytes: 92892
#include <set>
#include <cstdio>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

const int MAX = 100000 + 10;
bool flag[MAX];
int g[MAX];
int next[MAX];
int n;
int memo[MAX];

int calcNext(int pos){
  if(next[pos] != -2) return next[pos];
  if(g[pos] == 0){
    next[pos] = pos;
  }else{
    if(flag[pos]){
      next[pos] = -1;
    }else{
      flag[pos] = true;
      next[pos] = calcNext(pos + g[pos]);
      flag[pos] = false;
    }
  }
  return next[pos];
}

int main(){
  n = getInt();
  REP(i,n) memo[i] = -1;
  REP(i,n) next[i] = -2;
  REP(i,n) g[i] = getInt();
  REP(i,n) if(next[i] == -2)
    next[i] = calcNext(i);

  queue<int> q;
  memo[0] = 0;
  q.push(0);

  while(q.size()){
    int pos = q.front(); q.pop();
    int cnt = memo[pos];

    if(pos == n - 1){
      printf("%d\n", cnt);
      break;
    }

    for(int i = 1; i <= 6; i++){
      int nx = pos + i;
      if(nx >= n) nx = n - 1;
      nx = next[nx];

      if(nx != -1 && memo[nx] == -1){
        memo[nx] = cnt + 1;
        q.push(nx);
      }
    }
  }

  return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
int f[226];
ll ans=1;
int main(){
	ios::sync_with_stdio(false);
	int n;cin >> n;
	string s;
	cin >> s;
	for(auto c:s) f[c]++;
	for(int i=1; i<=225 ;i++) ans=ans*(f[i]+1)%mod;
	cout << (ans+mod-1)%mod << endl;
}

Measured memory_bytes: 512
N, K = input().split()
N = int(N)
K = int(K)
S = input()
A = []
for i in range(len(S)-1):
    if (S[i]=="0" and S[i+1]=="1") or (S[i]=="1" and S[i+1]=="0"):
        A.append(i+1)
A.insert(0, 0)
A.append(N)
M = []
if S == "0"*N:
    M.append(len(S))
elif S[0] == "0":
    if K > len(A)//2:
        K = len(A)//2
    M.append(A[K*2]-A[0])
    a = 1
    b = a + K*2 + 1
elif S[0] == "1":
    if K > (len(A)-1)//2:
        K = (len(A)-1)//2
    a = 0
    b = a + K*2 + 1
if S == "0"*N:
    pass
elif S[-1] == "1":
    while b <= len(A):
        M.append(A[b]-A[a])
        a += 2
        b = a + K*2 + 1
elif S[-1] == "0":
    while b <= len(A)-1:
        M.append(A[b]-A[a])
        a += 2
        b = a + K*2 + 1
    M.append(A[-1]-A[-1-K*2])
print(max(M))

Measured memory_bytes: 8688
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
#define dout(n) cout<<# n<<" = "<<n<<endl;


struct diameter{
    struct edge{int to, cost;};
    vector< edge > g[200020];
    long long dist[200020];

    void dfs1(int idx, int par){
    for(edge &e : g[idx]) {
        if(e.to == par) continue;
        dfs1(e.to, idx);
        dist[idx] = max(dist[idx], dist[e.to] + e.cost);
    }
    }

    int dfs2(int idx, int d_par, int par){
    vector< pair< int, int > > d_child;
    d_child.emplace_back(0, -1); // 番兵みたいなアレ
    for(edge &e : g[idx]) {
        if(e.to == par) d_child.emplace_back(d_par + e.cost, e.to);
        else d_child.emplace_back(e.cost + dist[e.to], e.to);
    }
    sort(d_child.rbegin(), d_child.rend());
    int ret = d_child[0].first + d_child[1].first; // 最大から 2 つ
    for(edge &e : g[idx]) {
        if(e.to == par) continue;
        // 基本は d_child() の最大が d_par になるが, e.to の部分木が最大値のときはそれを取り除く必要がある
        ret = max(ret, dfs2(e.to, d_child[d_child[0].second == e.to].first, idx));
    }
    return (ret);
    }

    int get(){
        dfs1(1,-1);
        return dfs2(1,0,-1);
    }
};

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

    int n;
    cin>>n;
    diameter d;
    for(int i = 0; i < n - 1; i++) {
        int a, b, w;
        cin >> a >> b >> w;
        d.g[a].push_back({b, w});
        d.g[b].push_back({a, w});
    }
    cout << d.get() << endl;
}



Measured memory_bytes: 27268
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define iter(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end();++it)
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int INF = ~(1<<31);
const double pi = acos(-1);

int main() {
	cin.sync_with_stdio(false);
	int n;
	cin >> n;
	map<char,int> og;
	string s;
	cin >> s;
	rep(i,0,s.size()) og[s[i]]++;
	rep(i,0,n-1) {
		cin >> s;
		map<char,int> ne;
		rep(a,0,s.size()) ne[s[a]]++;
		iter(it,og) {
			og[it->first] = min(it->second, ne[it->first]);
		}
	}
	string best = "";
	iter(it,og) {
		char da = it->first;
		rep(i,0,it->second) best+=da;
	}
	cout << best << endl;
	return 0;
}



Measured memory_bytes: 256
import math
def prime(n): # nまでの素数を列挙
    import math
    if n == 1:
        return []
    else:
        num_list = [i + 1 for i in range(2,n,2)]
        list_prime = [2]
        limit = math.sqrt(n)
        if n == 2:
            return list_prime
        else:
            while True:
                p = num_list[0]
                if p >= limit:
                    return list_prime + num_list
                list_prime.append(p)
                num_list = [num for num in num_list if num % p != 0]

def primeFactorization(n):
    if n == 1:
        return {}
    list_prime = prime(int(x))
    i = 0
    dict_pF = {}
    dict_primeFactorization = {}
    for pri in list_prime:
        dict_pF[pri] = 0
    while True:
        if n == 1:
            for key, value in dict_pF.items():
                if value != 0:
                    dict_primeFactorization[key] = value
            return dict_primeFactorization
        elif i >= len(list_prime):
            dict_pF[n] = 1
            for key, value in dict_pF.items():
                if value != 0:
                    dict_primeFactorization[key] = value
            return dict_primeFactorization
        p = list_prime[i]
        if n % p == 0:
            n //= p
            dict_pF[p] += 1
            continue
        else:
            i += 1


x = int(input())
ans_dict = primeFactorization(math.factorial(x))
ans = 1
for value in ans_dict.values():
    ans *= value+1
print(ans%(10**9 + 7))


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;

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

    set<int> d;
    for (int i = a; i < min(a + k, b); i++) {
        d.insert(i);
    }
    for (int i = max(b-k+1, a); i <= b; i++) {
        d.insert(i);
    }
    for (const auto& i : d) {
        cout << i << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
/*
*/

//#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd

#define eps 1e-8
#define M_PI 3.141592653589793
#define bsize 512

#define ldouble long double
using namespace std;

#define bs 1000000007

const int N = 600031;

int n;
vector<int> g[N];
int root;
int used[N];
int ans;

int cnt_chains[N];

void make_move(int &cur,int &par){
	int othr=-1;
	for (int i=0;i<g[cur].size();i++){
		int to=g[cur][i];
		if (to==par)
			continue;
		othr=to;
	}
	par=cur;
	cur=othr;
}

int main(){
//	freopen("apache.in","r",stdin);
//	freopen("apache.out","w",stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
//	cin.tie(0);

	cin>>n;
	if (n==2){
		cout<<1<<endl;
		return 0;
	}

	for (int i=1;i<n;i++){
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	int is_chain=1;

	for (int i=0;i<n;i++){
		if (g[i].size()>2)
			is_chain=0;
	}

	if (is_chain){
		cout<<1<<endl;
		return 0;
	}

	for (int i=0;i<n;i++){
		if (g[i].size()>1)
			continue;
		int cur=i;
		int par=-1;
		while (g[cur].size()<=2){
			//cout<<cur<<endl;
//			cout<<cur<<"$"<<par<<" "<<endl;
		//	cin.get();
			make_move(cur,par);
		}
		cnt_chains[cur]++;
	}

	for (int i=0;i<n;i++){
		if (cnt_chains[i]>0)
			ans+=cnt_chains[i]-1;
	}
	cout<<ans<<endl;

//	cin.get(); cin.get();
	return 0;
}


Measured memory_bytes: 20992
A, B, C, X, Y = gets.split.map(&:to_i)

min = A * X + B * Y

2.step([X, Y].max * 2 , 2).each do |i|
    c_sum = C * i
    a_sum = 0
    b_sum = 0

    if (X - (i / 2)) >= 1
        a_sum = A * (X - (i / 2))
    end

    if (Y - (i / 2)) >= 1
        b_sum = B * (Y - (i / 2))
    end

    sum = a_sum + b_sum + c_sum

    if sum <= min
        min = sum
    end
end

puts min


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

int main(){
  int N;
  cin >> N;
  
  vector<int> p(N),q(N),v(N);
  rep(i,N) cin >> p.at(i);
  rep(i,N) cin >> q.at(i);
  rep(i,N) v.at(i)=i+1;
  
  int a=1,b,i=1;
  do{
    if(p == v) a = i;
    if(q == v) b = i;
    i ++;
   
  }while (next_permutation(v.begin(), v.end()));
  
  cout << abs(a-b);
}
          


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    ll n,k; cin >> n >> k;
    cout << min(k-n%k,n%k) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	REP(i, t) fact[i+1]=fact[i]*(i+1)%MOD;
	fact_inv[t]=power(fact[t], MOD-2);
	FORR(i, 0, t) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}
  
int main()
{
  string S; cin >> S;
  int i,Len=0,ans=0;
  rep(i,S.length()){
      if(S[i]=='A' || S[i]=='T' || S[i]=='G' || S[i]=='C'){
          Len++;
      }
      else{
          ans = max(ans, Len); Len = 0;
      }
  }
  if(Len > ans){ans = Len;}
  cout << ans << endl;

  return 0;
}


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

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

int main()
{
    while (1)
    {
	int n,f=0,id,f2[4001];
	ll price,num,p[4001];
	rep(i,4001){p[i]=0;f2[i]=0;}
	cin >> n;
	if (n==0)break;
	rep(i,n)
	{
	    cin >> id >> price >> num;
	    p[id]+=price*num;
	    if (p[id] >= 1000000 && f2[id]==0)
	    {
		cout << id << endl;
		f=1;
		f2[id]=1;
	    }
	}
	if (f==0)cout << "NA" << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Blue ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,n) for(int i=a;i<n;++i)
typedef vector<int> vi;
typedef long long ll;
const int mod=1e9+7;
 
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
vector<ll>q;

ll getAns(ll m){
	ll x=0;
	auto it=upper_bound(all(q),m)-q.begin()-1;
	return it;
}

void solve(){
	ll n;
	cin>>n;
	ll ans=0;
	for(ll i=0;i<=8;i++){
		q.pb(((i+1)*i)/2);
	}
	for(ll i=2;i*i<=n;i++){
		ll cnt=0;
		while(n%i==0){
			cnt++;
			n/=i;
		}
		ans+=getAns(cnt);
	}
	if(n>1)ans++;
	cout<<ans;
 
}
 
 
int main(){
	Blue;
	int test=1;
	//cin>>test;
	while(test--)
		solve();
	return 0;
}

Measured memory_bytes: 3640
n=int(input())
a=list(map(int, input().split()))
b=sorted(a)
c=0
for i in range(n):
 x=a.index(b[i])
 j=0
 while x>i:
  j+=1
  y=a.index(b[x])
  c+=a[y]
  a[x],a[y]=a[y],a[x]
  x=y
 c+=min(b[i]*j,b[i]*2+b[0]*(j+2))
print(c)


Measured memory_bytes: 5624
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int> vec(n);
    REP(i,n)cin>>vec[i];
    sort(vec.begin(),vec.end());
    int ans=0;
    REP(i,k){
        ans += vec[n-1-i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int n = sc.nextInt();

		if (n == 1) {
			System.out.println("Hello World");
			return;
		}

		System.out.println(sc.nextInt() + sc.nextInt());

		sc.close();

	}
}



Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
vector<int> v[100001];
int level[100001];
bool visited[100001];
void dfs(int u){
    visited[u]=true;
    for(int i=0;i<v[u].size();i++){
        if(!visited[v[u][i]])dfs(v[u][i]);
         level[u]=max(level[v[u][i]]+1,level[u]);
    }
}
int main(){
 int n,m;
 cin>>n>>m;
 for(int i=0;i<=n;i++){level[i]=0;visited[i]=false;}
 for(int i=0;i<m;i++){
     int a,b;
     cin>>a>>b;
     v[a].push_back(b);
 }
 for(int i=1;i<=n;i++){
     if(!visited[i])dfs(i);
 }
 int ans=0;
 for(int i=1;i<=n;i++){
     
     ans=max(ans,level[i]);
 }
 cout<<ans<<endl;
 return 0;
}


Measured memory_bytes: 8192