akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

  vector<vector<vector<long long>>> dp(2, vector<vector<long long>>(n, vector<long long>(16)));
  for (int i = 0; i < 16; i++) {
    dp[0][n - 1][i] = i;
    dp[1][n - 1][i] = i;
  }

  for (int i = 0; i < 2; i++) {
    for (int j = n - 2; j >= 0; j--) {
      int j1 = 0;
      int j2 = 0;
      long long c1 = a[j];
      long long c2 = a[j + 1];
      while (c1 <= c2 && j1 < 16) {
        dp[i][j][j1] = dp[i][j + 1][0] + j1;
        c1 *= 4;
        j1++;
      }
      while (j2 < 16 && c2 < c1) {
        c2 *= 4;
        j2++;
      }
      while (j1 < 16) {
        if (j2 > 15) {
          dp[i][j][j1] = dp[i][j + 1][15] + (j2 - 15) * (n - 1 - j) + j1;
        }
        else {
          dp[i][j][j1] = dp[i][j + 1][j2] + j1;
        }
        j1++;
        j2++;
      }
    }
    reverse(a.begin(), a.end());
  }

  long long ans = 2 * dp[0][0][0];
  for (int i = 1; i < n; i++) {
    long long steps = dp[0][i][0] * 2 + dp[1][n - i][0] * 2 + i;
    ans = min(ans, steps);
  }
  cout << ans;
}


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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

long long INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	string s,t,u;
	cin >> s >> t;
	int a,b; cin >> a >> b >> u;
	if(u==s)a--;
	else b--;
	cout << a << ' ' << b << endl;
}	


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,n) for(ll i=a;i<n;i++)
#define all(x) x.begin(),x.end()
#define bs binary_search
#define gcd(a,b) __gcd(a,b)
#define PI 3.1415926535897932384626
#define lp lower_bound
#define up upper_bound
#define minimum(a)	*min_element(a.begin(), a.end())
#define maximum(a)	*max_element(a.begin(), a.end())
#define UNIQUE(x) (x).resize(unique(all(x))-(x).begin())
#define bp(x)  __bulitin_popcount(x)
using namespace std;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}


const int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
ll f(ll i,ll j,string s){
    ll k=0;
    ll a=i,b=j;
    bool ok=true;
    while(i<j){
        if(s[i++]!=s[j--])ok=false;
        
    }
    if(ok)return 1;
    else return 0;
    
}
int main()
{
boost
string s;
cin>>s;
ll n=s.length();
if((f(0,(n-2)/2 ,s)&&f((n+1)/2 ,n-1,s)&&f(0,n-1,s)&&(n%2==1))||n==1)cout<<"Yes"<<"\n";
else cout<<"No";
return 0;
}


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 puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;

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

  for(int i=0;i<n;i++){
    string str = s;
    for(int j=n-i;j<n;j++){
      str+=t.at(j);
    }

    bool ok = true;

    for(int j=0;j<n;j++){
      if(t.at(j)!=str.at(j+i)) ok= false;
    }

    if(ok){
      cout << n+i << endl;
      return 0;
    }
  }

  cout << 2*n << endl;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
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(a>b){a=b;return 1;}return 0;}
void dump(){cout<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cout<<h<<", ";dump(forward<Ts>(t)...);}
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

void solve1();void solve2();
int main(){
  solve1();
  return 0;
}
template<class T>
class segtree {
private:
  ll n=1,sz;
  T unit;
  std::vector<T> dat;
  std::function<T(T,T)> func;
public:
  segtree(){}
  segtree(std::vector<T>& a,T v,std::function<T(T,T)> f){
    build(a,v,f);
  }
  void build(std::vector<T>& a,T v,std::function<T(T,T)> f){
    sz=a.size();
    unit=v;
    func=f;
    while(n<sz)n<<=1LL;
    dat.resize(2*n-1,unit);
    for(int i=0;i<sz;++i)dat[i+n-1]=a[i];
    for(int i=n-2;i>=0;--i){
      dat[i]=func(dat[i*2+1],dat[i*2+2]);
    }
  }
  void update(ll idx,T val){
    idx+=n-1;
    dat[idx]=val;
    while(idx){
      idx--;idx>>=1LL;
      dat[idx]=func(dat[idx*2+1],dat[idx*2+2]);
    }
  }
  T query(ll a,ll b,ll k=0,ll l=0,ll r=-1){
    if(r<0)r=n;
    if(b>sz)b=sz;
    if(a<0)a=0;
    if( b<=l || r<=a )return unit;
    if( a<=l && r<=b )return dat[k];
    else{
      auto left=query(a,b,2*k+1,l,(l+r)/2);
      auto right=query(a,b,2*k+2,(l+r)/2,r);
      return func(left,right);
    }
  }
};

void solve1(){

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

  vector<ll> a(n+1);
  rep(i,n+1){
    if(s[i]=='0')a[i]=i;
    else a[i]=INF;
  }
  segtree<ll> seg(a,INF,[](auto a,auto b){return min(a,b);});

  ll now = n;
  vector<ll> op;
  while(now>0){
    auto x = seg.query(now-m,now);
    if(x==INF){
      cout<<-1<<endl;
      return;
    }
    op.emplace_back(now-x);
    now = x;
  }
  reverse(op.begin(),op.end());
  for(auto v:op)cout<<v<<" ";
  cout<<endl;

}

Measured memory_bytes: 4344
#include <iostream>
#define MAX 1299711

using namespace std;

bool prime[MAX];

void isPrime(void){

  fill(prime, prime + MAX , true);
  prime[0] = prime[1] = false;
  for(int i = 2 ; i*i < MAX ; i++){
    if(prime[i]){
      for(int j = i*i ; j < MAX ; j += i) prime[j] = false;
    }
  }
}

int main(void){

  isPrime();

  int p;
  while(cin >> p, p){
    int l,r;
    l = r = p;
    while(!prime[l]) l--;
    while(!prime[r]) r++;
    cout << r - l << endl;;
  }
  return 0;
}

Measured memory_bytes: 2428
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  int ans = 0;
  int pre = 1000000;
  for (int i = 0; i < N - 1; i ++) {
    int b;
    cin >> b;
    ans += min(pre, b);
    pre = b;
  }
  cout << ans + pre << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define IN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long ll;
//////////////////////////////////////////////////////
int main(){
    int N,M; SCD2(N,M);
    static vector<int> ver[200002];
    set<int> S;
    
    
    REP(i,M){
        int a,b; SCD2(a,b);
        ver[a].PB(b);
        if (b==N){
            S.insert(a);
        }
    }
    
    bool flg = false;
    REP(i,ver[1].size()){
        int next = ver[1][i];
        if (IN(next,S)){
            flg = true;
        }
    }
    
    if (flg) printf("POSSIBLE\n");
    else printf("IMPOSSIBLE\n");
    
	return 0;
}


Measured memory_bytes: 13176
#include<bits/stdc++.h>
using namespace std;
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define trace(x) cout << '>' << #x << ':' << x << "\n" 
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << "\n" 
#define trace3(a,b,c) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n" 
#define trace4(a,b,c,d) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n" 
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl '\n' 
typedef vector<int> VI;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
const ll mod=1000000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 1e5 + 10;

int main()
{
    fastIO;
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans;
    if(b >= 0 && d >= 0) ans = max(b * d, a * c);
    else {
        if(b < 0 && d < 0) ans = a * c;
        else if(b < 0) ans = max(a * c,b * c);
        else if(d < 0) ans = max(d * a,c * a);
    }
    cout << ans << endl;
    return 0;
}

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

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

    float x = n / 1.08;

    int p = floor(x);

    int ans  = -1;

    for(int i = p; ; i++){
        x = i * 1.08;
        //cout << i << " -> " << x << endl;
        int tmp = floor(x);

        if(tmp == n){
            ans = i; break;
        }
        if(tmp >= n+1) break;
    }
    
    if(ans != -1) cout << ans << endl;
    else cout << ":(" << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np

# input = sys.stdin.readline

bingo = [list(map(int, input().split())) for ii in range(3)]

n = int(input())

num = []
for ii in range(n):
    num.append(int(input()))

bi = np.full(9, False)

bingo_np = np.array(bingo).reshape(-1)

for number in num:
    for i in range(9):
        if bingo_np[i] == number:
            bi[i] = True
if (np.all(bi[:3])):
    print("Yes")
elif (np.all(bi[3:6])):
    print("Yes")
elif (np.all(bi[6:9])):
    print("Yes")
elif (np.all([bi[0], bi[3], bi[6]])):
    print("Yes")
elif (np.all([bi[1], bi[4], bi[7]])):
    print("Yes")
elif (np.all([bi[2], bi[5], bi[8]])):
    print("Yes")
elif (np.all([bi[0], bi[4], bi[8]])):
    print("Yes")
elif (np.all([bi[2], bi[4], bi[6]])):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 13324
/*     If they say
    Who cares if one more light goes out?
    In a sky of a million stars
    It flickers, flickers
    Who cares when someone's time runs out?
    If a moment is all we are
    We're quicker, quicker
    Who cares if one more light goes out?
    Well I do
*/

#include "bits/stdc++.h"
using namespace std;

#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a) / gcd(a,b)) * (b)
#define all(x)  x.begin(),x.end()

#define ll long long
#define ull unsigned long long
#define VI vector<int>
#define VLL vector<ll>
#define VS vector<string>
#define MPII map<int, int>
#define SET set<int>
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io   ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0);

ll MOD = 1e9+7;

ll add(ll a, ll b){a+=b; a%=MOD;if(a<0) a+=MOD;return a;}
//doesn't work for neg numbers

ll mult(ll a, ll b){if(a>MOD) a%=MOD;if(b>MOD) b%=MOD;ll ans=(a*b)%MOD;if(ans<0) ans+=MOD;return ans;}
//doesn't work for neg numbers

ll pw(ull a, ull b){ll r=1;while(b){if(b&1) r=mult(r,a);a=mult(a,a);b>>=1;}return r;}
//doesn't work for neg numbers

void solve(){
	string s;
	cin>>s;
	int n, flg=0, a=0,b=0;
	cin>>n;
	char c;
	string tmp="";
	while(n--){
		cin>>a;
		if(a==1){
			flg++;
			continue;
		}
		cin>>b>>c;
		if(b==1){
			if(flg%2!=0){
				s+=c;
			}
			else{
				tmp=s;
				s=c+tmp;
			}
		}
		else{
			if(flg%2==0){
				s+=c;
			}
			else{
				tmp=s;
				s=c+tmp;
			}
		}
		//cout<<s<<endl;
	}
	if(flg%2!=0){
        for(int i = s.length()-1 ; i >= 0 ; i--)cout<<s[i];
        cout<<endl;
	}
	else cout<<s<<endl;
}

int main(){
// 	#ifndef ONLINE_JUDGE
// 		freopen("input.txt", "r", stdin);
// 		freopen("output.txt", "w", stdout);
// 	#endif
    fast_io;
    ll t, k=0;
    t=1;
    while(t--){
        //k++;
        //cout<<"Case "<<k<<": ";
        solve();
    }
}


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

using namespace std;
const int N = 1e5 + 5;

int n, s[N];
int dp[N];

int solve(int i) {
    if(i >= n-1) return 0;
    int& res = dp[i];
    if(~res) return res;
    res = abs(s[i+1] - s[i]) + solve(i+1);
    if(i < n-2) {
        res = min(res, abs(s[i+2] - s[i]) + solve(i+2));
    }
    return res;
}

int main() {
    memset(dp, -1, sizeof(dp));
    scanf("%d", &n);
    for(int i=0; i<n; i++) scanf("%d", &s[i]);
    printf("%d\n", solve(0));
    return 0;
}


Measured memory_bytes: 4096
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))
ans = 0
location = -1
for i in range(len(H)) :
    p = T-H[i]*0.006
    if i == 0 :
        ans = p
        location = 1
    else :
        if abs(A-ans) > abs(A-p) :
            ans = p
            location = 1+i
print(location)


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

int main()
{
  long double a,b,x,angle=0;
  cin>>a>>b>>x;
  if(x>a*a*b) ;
  else{
      /*if(b>a){*/
          if(x>a*a*b/2)
            angle=atan(2*(a*a*b-x)/(a*a*a));
          else
            angle=atan(a*b*b/(2*x));
      /*}
      else
        angle=atan(a*b*b/(2*x));*/
  }
  cout<<setprecision(10)<<angle*180/3.141592653589;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
a = sorted([i for i in map(int,input().split())])
maxi = -1
ans = (n + (n - a[-1]%n))%n + a[0]
#print(ans)
for i in range(1,len(a)):
    maxi = max(maxi,a[i] - a[i - 1])
    ans += a[i] - a[i - 1]
maxi = max(maxi,(n + (n - a[-1]%n))%n + a[0])
ans -= maxi
print(ans)



Measured memory_bytes: 26444
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const int INF = 1<<28;
int n;
int a[200000];

template<typename T>
class SegTree {
  int n;
  vector<T> seg;
  
  // irrelevant value for query
  const T NIL = INF;
  
  // binary operator for query
  T binop(T a, T b) {
    return min(a, b);
  }
  
  void update(int k, int l, int r, int p, T x) {
    if (p < l || r <= p)
      return;
    if (r - l == 1)
      seg[k] = x;
    else {
      update(2*k+1, l, (l+r)/2, p, x);
      update(2*k+2, (l+r)/2, r, p, x);
      seg[k] = binop(seg[2*k+1], seg[2*k+2]);
    }
  }
  T query(int k, int l, int r, int a, int b) {
    if (b <= l || r <= a)
      return NIL;
    if (a <= l && r <= b)
      return seg[k];
    else {
      T ret = NIL;
      ret = binop(ret, query(2*k+1, l, (l+r)/2, a, b));
      ret = binop(ret, query(2*k+2, (l+r)/2, r, a, b));
      return ret;
    }
  }
public:
  SegTree(int n): n(n), seg(4*n) {}
  void init() {
    for (int i = 0; i < 4*n; i++)
      seg[i] = NIL;
  }
  // update p-th value to x
  void update(int p, T x) {
    update(0, 0, n, p, x);
  }
  // query for range [l, r)
  T query(int l, int r) {
    return query(0, 0, n, l, r);
  }
};

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

  cin >> n;
  SegTree<int> seg(n);
  REP (i, n) {
    cin >> a[i];
    seg.update(i, a[i]);
  }

  long long sum = 0;
  REP (i, n) {
    int l, r;

    // find left
    l = -1, r = i;
    while (r - l > 1) {
      int m = (l + r) / 2;
      if (seg.query(m, i+1) == a[i])
        r = m;
      else
        l = m;
    }
    int lv = r;

    // find right
    l = i, r = n;
    while (r - l > 1) {
      int m = (l + r) / 2;
      if (seg.query(i, m+1) == a[i])
        l = m;
      else
        r = m;
    }
    int rv = l;
    sum += (long long)a[i] * (rv - i + 1) * (i - lv + 1); 
  }
  cout << sum << endl;
  
  return 0;
}


Measured memory_bytes: 4224
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <bitset>
#include <list>
#include <iomanip>
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a,n) for(ll i=n;i>=a;i--)
#define elif else if
#define all(s) s.begin(),s.end()
typedef long long ll;
typedef pair<string,ll> P;
const ll INF = 1e+17;
const ll MODcdf = 998244353;
const ll MODatc = 1000000007;
bool pairCompare(const P& firstElof,const P& secondElof){
    return firstElof.first<secondElof.first;
}
bool pairCompare2(P firstElof,P secondElof){
    return (firstElof.second)%1000>(secondElof.second)%1000;
}
bool less_mod1000(int lhs, int rhs) {
  if ((lhs - rhs) % 1000 != 0)
    return lhs % 1000 < rhs % 1000;
  else // 5で割った余りが等しいなら普通に大小比較する
    return lhs < rhs;
}
string A="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string a="abcdefghijklmnopqrstuvwxyz";
ll dp[107000];
ll jump(ll start,ll goal){
  if(dp[start]>=0)return dp[start];
  if(start==goal){
    return 1;
  }elif(start>goal){
    return 0;
  }
  return dp[start]=(jump(start+1,goal)+jump(start+2,goal))%MODatc;
}
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    rep(i,0,100700)dp[i]=-1;
    ll n,m;cin>>n>>m;
    ll a[m+1];
    rep(i,1,m+1)cin>>a[i];
    ll sum[m+1];
    rep(i,0,m+1){
      if(m==0){
        sum[i]=jump(0,n);
        break;
      }
      if(i==0)sum[i]=jump(0,a[i+1]-1);
      elif(i<m)sum[i]=jump(a[i]+1,a[i+1]-1);
      else sum[i]=jump(a[i]+1,n);
    }
    ll ans=1;
    rep(i,0,m+1){
      ans*=sum[i];
      ans%=MODatc;
    }
    cout<<ans<<endl;
}


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

int main(){
  int p, q, r, ans;
  cin >> p >> q >> r;
  
  ans = min(min((p+q), (p+r)), (q+r));
  cout << ans << endl;
}

Measured memory_bytes: 256
import math
N = int(input())
ans = 1000000
for i in range(1,math.ceil(math.sqrt(N))+1):
    if N%i == 0:
        a = i
        b = N//i
        f = max(len(str(a)),len(str(b)))
        if f < ans:
            ans = f
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
 
int main(){
    int h,w,ans=0;
    cin>>h>>w;
    vector<vector<char>> grid(h, vector<char>(w, '\0'));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>grid[i][j];
        }
    }
    vector<vector<int>> h_up(h, vector<int>(w, 0));
    vector<vector<int>> h_down(h, vector<int>(w, 0));
    vector<vector<int>> w_ri(h, vector<int>(w, 0));
    vector<vector<int>> w_le(h, vector<int>(w, 0));
    //int h_up[100][100],h_down[100][100],w_le[100][100],w_ri[2010][2010];
    for(int i=0;i<w;i++){
        int tmp=0;
        for(int j=0;j<h;j++){
            if(grid[j][i]=='#'){
                tmp=0;
                h_down[j][i]=0;
            }else{
                h_down[j][i]=tmp+1;
                tmp++;
            }
        }
    }
    for(int i=0;i<w;i++){
        int tmp=0;
        for(int j=h-1;j>=0;j--){
            if(grid[j][i]=='#'){
                tmp=0;
                h_up[j][i]=0;
            }else{
                h_up[j][i]=tmp+1;
                tmp++;
            }
        }
    }
    for(int i=0;i<h;i++){
        int tmp=0;
        for(int j=0;j<w;j++){
            if(grid[i][j]=='#'){
                tmp=0;
                w_ri[i][j]=0;
            }else{
                w_ri[i][j]=tmp+1;
                tmp++;
            }
        }
    }
    for(int i=0;i<h;i++){
        int tmp=0;
        for(int j=w-1;j>=0;j--){
            if(grid[i][j]=='#'){
                tmp=0;
                w_le[i][j]=0;
            }else{
                w_le[i][j]=tmp+1;
                tmp++;
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(grid[i][j]=='.') ans=max(ans,h_up[i][j]+h_down[i][j]+w_le[i][j]+w_ri[i][j]-3);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 67072
# https://atcoder.jp/contests/abc101/tasks/arc099_a
import math


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    # print("{}, {}, {}".format(N-1, K-1, (N-1)/(K-1)))
    print(math.ceil((N-1)/(K-1)))


if __name__ == '__main__':
    main()
    

Measured memory_bytes: 13812
#include <iostream>

using namespace std;

int main()
{
    int s=1000000000, x=0, n;
    cin>>n;
    int v[n];
    for(int i=0; i<n; i++){
        cin>>v[i];
    }
    for(int i=-100; i<=100; i++){
        x=0;
        for(int j=0; j<n; j++)
            x+=(v[j]-i)*(v[j]-i);
        if(x<s)
            s=x;
    }
    cout<<s;

    return 0;
}


Measured memory_bytes: 256
<?php
$index = array();

while ($line = trim(fgets(STDIN))) {
	list($word, $page) = explode(' ', $line);
	if (isset($index[$word])) {
		$index[$word][] = $page;
	} else {
		$index[$word] = array($page);
	}
}

ksort($index, SORT_STRING);

foreach ($index as $word => $list) {
	echo "$word\n";
	sort($list);
	echo implode(' ', $list) . "\n";
}

Measured memory_bytes: 6640
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        System.out.println(power(n, m));
     }
     
     static long power(long x, int p) {
         if (p == 0) {
             return 1;
         }
         if (p % 2 == 0) {
             return power(x * x % MOD, p / 2);
         } else {
             return power(x, p - 1) * x % MOD;
         }
     }
}


Measured memory_bytes: 26404
S_ = gets.chomp
T = gets.chomp
N = S_.length

idx_cands = (0...N).select{|i|
  (0...T.length).all?{|j|
    c = S_[i+j] 
    c == T[j] || c == "?"
  }
}

if idx_cands.empty?
  puts "UNRESTORABLE"
else
  puts idx_cands.map{|idx|
    s = ""
    N.times do |i|
      if i >= idx && i < (idx+T.length)
        s << T[i-idx]
      else
        c = S_[i]
        if c == "?"
          s << "a"
        else
          s << c
        end
      end
    end
    s
  }.sort.first
end


Measured memory_bytes: 1788
#include <stdio.h>

int main()
{   int i = 0 ,count = 0;
	 char a[3];
	scanf("%s",a);
	
	if(a[0]=='1') count ++;
	if(a[1]=='1')count++;
	if(a[2]=='1')count++;
	
	printf("%d  \n",count);
	return 0;
}


Measured memory_bytes: 128
//30
#include<iostream>
#include<set>
#include<vector>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int h[100];
    for(int i=0;i<n+1;i++){
      cin>>h[i];
    }
    for(int i=0;;i++){
      vector<int> v(h,h+n+1);
      v.erase(v.begin()+i);
      set<int> s;
      for(int j=0;j<v.size()-1;j++){
	s.insert(v[j+1]-v[j]);
      }
      if(s.size()==1){
	cout<<h[i]<<endl;
	break;
      }
    }
  }
  return 0;
}

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


int main() {
	int i, j, k, f = 0, n, s, t, m;
	int a, b, c, d, e, x = 0, y = 0, z;
	int aa[25][25];
	int bb[25];

	scanf("%d %d %d", &n, &m, &c);
	
	for (i = 0;i < m;i++) {
		scanf("%d ",&bb[i]);
	}

	for (i = 0;i < n;i++) {
		for (j = 0;j < m;j++) {
			scanf("%d", &aa[i][j]);
		}
	}


	for (i = 0;i < n;i++) {
		y = 0;
		for (j = 0;j < m;j++) {
			y = y + aa[i][j] * bb[j];
		}
		y = y + c;
		if (y > 0) {
			x = x + 1;
		}
	}

	printf("%d", x);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <map>
using namespace std;
string z(int i){string s="";if(i>25){s+='a'+i/25;i%=25;}s+='a'+i;return s;}
string c(char c){string s="";s+=c;return s;}
int main(){
	string s;
	map<string,int>m;
	int i;
	cout<<"?shiritori"<<endl;
	for(i=0;i<100;i++){
		cin>>s;
		if(s[0]!='i'||m[s]){cout<<"!OUT"<<endl;return 0;}
		m[s]=1;
		cout<<"?"+c(s[s.size()-1])+z(i)+"i"<<endl;
	}
	return 1; //RE
}

Measured memory_bytes: 0
#include <iostream>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <iomanip>
#include <math.h>
#include <map>
#include <algorithm>
#define M_PI 3.14159265358979323846264338327950288
#define oo 998244353
#define maxN 200007
using namespace std;

int col[4*maxN], row[4*maxN];

void updateIT_col(int root, int left, int right, int pos, int x) {
    if (left == right) {
        col[root] = x;
        return;
    }

    int mid = (left+right)/2;
    if (pos <= mid) updateIT_col(2*root, left, mid, pos, x);
    else updateIT_col(2*root+1, mid+1, right, pos, x);

    col[root] = max(col[2*root], col[2*root+1]);
}

void updateIT_row(int root, int left, int right, int pos, int x) {
    if (left == right) {
        row[root] = x;
        return;
    }

    int mid = (left+right)/2;
    if (pos <= mid) updateIT_row(2*root, left, mid, pos, x);
    else updateIT_row(2*root+1, mid+1, right, pos, x);

    row[root] = max(row[2*root], row[2*root+1]);
}

int queryIT_col(int root, int left, int right, int val) {
    if (left == right) return left;
    int mid = (left+right)/2;
    if (val <= col[2*root]) return queryIT_col(2*root, left, mid, val);
    return queryIT_col(2*root+1, mid+1, right, val);
}


int queryIT_row(int root, int left, int right, int val) {
    if (left == right) return left;
    int mid = (left+right)/2;
    if (val <= row[2*root]) return queryIT_row(2*root, left, mid, val);
    return queryIT_row(2*root+1, mid+1, right, val);
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n, q;
    cin >> n >> q;


    updateIT_col(1, 1, n, n, n);
    updateIT_row(1, 1, n, n, n);

    long long ans = (long long)(n-2)*(n-2);

    for (int i = 1; i <= q; ++i) {
        int type, x;
        cin >> type >> x;
        if (type == 1) {
            int k = queryIT_row(1, 1, n, x);
            updateIT_col(1, 1, n, x, k);
            ans -= k-2;
        }
        else {
            int k = queryIT_col(1, 1, n, x);
            updateIT_row(1, 1, n, x, k);
            ans -= k-2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7252
#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
        (cons (subseq str 0 pos)
              (split x (subseq str (+ pos size))))
        (list str))))

(defmacro collect-times (time body)
  `(loop repeat ,time collect ,body))

(defun read-times (time)
  (collect-times time (read)))

(defun main (m line)
  (let ((sum (apply #'+ line)))
    (>= (count-if (lambda (x) (>= x (/ sum 4 m))) line) m)))


(let* ((n (read))
       (m (read))
       (line (read-times n)))
  (princ (if (main m line) "Yes" "No")))


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

int main() {
    ll n, m;
    cin >> n >> m;
    ll sum = 0;
    rep(i,m) {
        ll input;
        cin >> input;
        sum += input;
    }
    if (sum>n) {
        cout<<-1<<endl;
    } else {
        cout<<n-sum<<endl;
    }

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    string a,b;
    cin >> a >> b;
    bool fla = false;

    string s;

    for(int i = 0;i < a.size();i++){
        if(a == b){
            fla = true;
            break;
        }else{
            s = a;
            for(int k = 0;k < s.size();k++){
                if(k == 0){
                    a.at(k) = s.at(s.size() - 1); 
                }else{
                    a.at(k) = s.at(k-1);
                }
            }
        }
    }
    
    if(fla){
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
    

}

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

int main() {
  int N, M;

  while (true) {
    cin >> N >> M;
    if (N == 0 && M == 0) return 0;
    int ans = 0;
    for (int i = 1; i <= N - 2; i++) {
      for (int j = i + 1; j <= N - 1; j++) {
        for (int k = j + 1; k <= N; k++) {
          if (i + j + k == M) ans++;
        }
      }
    }

    cout << ans << endl;
  }
}


Measured memory_bytes: 3088
def main():
    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N, K = [int(x) for x in input().strip().split()]
    A = {i:int(x) for i, x in enumerate(input().strip().split(), start=1)}
    dic = {}
    p = 1
    cnt = 0
    dic[p] = cnt
    while K > 0:
        p = A[p]
        cnt += 1
        K -= 1
        if p in dic:
            K %= (cnt - dic[p])
        else:
            dic[p] = cnt

    print(p)

if __name__ == '__main__':
    main()

Measured memory_bytes: 50696
#include <bits/stdc++.h>
using namespace std;
 
// in-short-use macros
 
#define all(c) (c).begin(),(c).end()
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define PI 3.14159265
#define sizes 1000010
 
//main function here
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	ll n,ans =0 ;
	cin>>n;
	for(ll i=1;i<=n-1;i++)
	{
		ans+=n/i;
		if(n%i==0)
			ans--;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
typedef long long ll;
bool dp[10000025][2];
int arr[305],n;
int dfs(int k,int t)
{
    if(dp[k][t]>0) return dp[k][t];
    int ans = 0;
    for(int i = 1;i<=n;++i)
        if(k>=arr[i])   
		ans|= !dfs(k-arr[i],!t);
    return dp[k][t] = ans;
}
int main(){
	 int k;
    scanf("%d%d",&n,&k);
    for(int i = 1;i<=n;++i) 
		scanf("%d",&arr[i]);
    if(dfs(k,0)==false) 
		printf("Second\n");
    else 
		printf("First\n");

	return 0;
}

Measured memory_bytes: 8628
#include <stdio.h> 
 
 
 int main(){ 
     int h, w; 
     int i, j; 
     while(1){ 
         scanf("%d %d ", &h, &w); 
         if(h==0&&w==0)break; 
         for(i=0;i<h;i++){ 
             for(j=0;j<w;j++){ 
                 if((i%2==0&&j%2==0)||(i%2==1&&j%2==1)){ 
                     printf("#"); 
                 }else{ 
                     printf("."); 
                 } 
             } 
             printf("\n"); 
         } 
         printf("\n"); 
     } 
 
 
     return 0; 
 } 



Measured memory_bytes: 2100
(let* ((w (read))
       (h (read))
       (x (read))
       (y (read)))
  (format t "~F ~A~%"
          (/ (* w h) 2)
          (if (and (= w (* 2 x)) (= h (* 2 y)))
              1
              0)))
(let* ((w (read))
       (h (read))
       (x (read))
       (y (read)))
  (format t "~F ~A~%"
          (/ (* w h) 2)
          (if (and (= w (* 2 x)) (= h (* 2 y)))
              1
              0)))


Measured memory_bytes: 24152
s = input("")
l = len(s)
s1 = s[:int((l-1)/2)]
s2 = s[int((l+3)/2) - 1:]
if (s1 == s1[::-1]) and (s2 == s2[::-1]) and (s == s[::-1]):
    print("Yes")
else :
    print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
const int mod=1e9+7;
using LL=long long;
using std::cout;using std::endl;using std::cin;
using std::vector;using std::string;using std::set;using std::multiset;
using std::pair;using std::map;
using std::min;using std::max;
using std::make_pair;
std::ostream& operator<<(std::ostream& os,std::map<int,int>& obj){for(std::map<int,int>::iterator itr=obj.begin();itr!=obj.end();itr++){os<<itr->first<<"^"<<itr->second<<" ";}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<std::map<int,int>>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<std::endl;}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<int>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<endl;}return os;}

namespace ndifix{
template<class T>void sort(T &v){std::sort(v.begin(),v.end());}
}

int main(){
  string s;cin>>s;
  int ans=0;
  for(int i=0;i<6;i++)if(s[i]=='1')ans++;
  cout<<ans<<endl;

  return 0;
}

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

#define ff        first
#define ss        second
#define int       long long
#define pb        push_back
#define mp        make_pair
#define vi        vector<int>
#define pii       pair<int,int>
#define mii       map<int,int>
#define w(x)      int x; cin>>x; while(x--)
#define all(x)      (x).begin(),(x).end()
#define rep(i,a,b)  for(int i=(a);i<(b);i++)
#define mod       1000000007

int a[100001][3],dp[100001][3],n;

void c()
{
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}

//maximum possible total points of happiness from day till N-1th day
int solve(int day,int last)
{
    if(day>=n)
        return 0;

    if(dp[day][last]!=-1)
        return dp[day][last];

    int res=INT_MIN;
    rep(i,0,3)
    {
        if(i!=last)
            res = max(res,a[day][i]+solve(day+1,i));
    }

    return dp[day][last] = res;
}

int32_t main() {

    //c();
    memset(dp,-1,sizeof(dp));
    cin>>n;
    rep(i,0,n)
        rep(j,0,3)
            cin>>a[i][j];
    int ans = max(solve(0,1),solve(0,2));
    ans= max(ans,solve(0,0));
    cout<<ans;            
    return 0;
}

Measured memory_bytes: 12800
from collections import defaultdict
from sys import setrecursionlimit # 再帰エラー対策
setrecursionlimit(10 ** 7)

n,q = map(int,input().split())

node = [[] for _ in range(n+1)]
counter = [0 for _ in range(n+1)]
visited = [0 for _ in range(n+1)]
point_dic = defaultdict(int)

for _ in range(n-1):
    a,b = map(int,input().split())
    node[a].append(b)
    node[b].append(a)

# 各ノードの加算値を記録
for _ in range(q):
    p,x = map(int,input().split())
    point_dic[p] += x

# 現在のノード(now)とそれまでに加算された値(before_point)
def dfs(now,before_point):
    if visited[now]:
        return
    
    # 現在のノードの加算値を足す
    if point_dic[now]:
        point = point_dic[now]+before_point
    else:
        point = before_point
    
    # 訪問済みにする
    visited[now] = 1
    counter[now] += point

    for i in node[now]:
        if visited[i]:
            continue

        dfs(i,point) # 再帰して子ノードに引き継ぐ

dfs(1,0)

print(' '.join(map(str, counter[1:])))

Measured memory_bytes: 252976
H, W = map(int, input().split())
S = []
for _ in [0]*H:
    S.append(list(input().rstrip()))

delta = [[-1, -1], [-1, 0], [-1, 1],
        [0, -1], [0, 1],
        [1, -1], [1, 0], [1, 1]]
for x in range(H):
    for y in range(W):
        if S[x][y] == '.':
            cnt = 0
            for dx, dy in delta:
                if 0 <= x + dx < H and 0 <= y + dy < W:
                    if S[x+dx][y+dy] == '#':
                        cnt += 1
            S[x][y] = str(cnt)

for line in S:
    print(''.join(line))

Measured memory_bytes: 3188
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;
int main()
{
    int n, k;
    cin >> k >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    int sum = 0, ans = INT_MIN;
    for (int i = 0; i < n - 1; i++)
    {
        sum += v[i + 1] - v[i];
        ans = max(ans, v[i + 1] - v[i]);
    }
    int lastsector = k - sum;
    ans = max(ans, lastsector);
    cout << k - ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define reg(i,a,b) for(int i=a;i<=b;i++)
#define reh(i,a,b) for(int i=a;i>b;i--)
#define in(x) scanf("%d",&x)
#define fro freopen("D:\\testdata.in", "r", stdin)
#define il inline
#define lson(q) q<<1
#define rson(q) q<<1|1
using namespace std;
typedef long long ll;
const int mx=1e5+10;
double x[10];
double y[10];
int a[10];
int idx;
double res;
double f(double x1,double y1,double x2,double y2){
	return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main() {
	int n;
	scanf("%d",&n);
	reg(i,1,n){
		a[i]=i;
		scanf("%lf %lf",&x[i],&y[i]);
	}
	do{
		reg(i,1,n-1){
			res+=f(x[a[i]],y[a[i]],x[a[i+1]],y[a[i+1]]);
		}
		idx++;
	}while(next_permutation(a+1,a+1+n));
	printf("%lf\n",res/idx*1.0);
	return 0;
}




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

using namespace std;
typedef long long llong;

#define MAX 110

int main()
{
  int X, N;
  int P[MAX];

  scanf("%d%d", &X, &N);

  for (int i = 0; i < N; i++)
  {
    scanf("%d", &P[i]);
  }
  sort(P, P + N);

  int i;
  int exist = 0;
  int lt = 0, gt = N;
  for (i = 0; i < N; i++)
  {
    if (P[i] == X)
      exist = 1;
    if (P[i] > X)
    {
      gt = i;
      break;
    }
    lt = i;
  }
  if (exist == 0)
  {
    printf("%d\n", X);
    return 0;
  }

  int mi = X;

  for (int i = lt; i >= 0; i--)
  {
    if (mi - P[i] > 1)
    {
      mi -= 1;
      break;
    }
    mi = P[i];
    if (i == 0)
      mi--;
  }

  int ma = X;
  if (gt == N)
    ma++;
  else
  {

    for (int i = gt; i < N; i++)
    {
      if (P[i] - ma > 1)
      {
        ma += 1;
        break;
      }
      ma = P[i];
      if (i == N - 1)
        ma++;
    }
  }

  if (ma - X >= X - mi)
  {
    printf("%d\n", mi);
  }
  else
  {
    printf("%d\n", ma);
  }

  return 0;
}

Measured memory_bytes: 1716
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>

//#define DEBUG

#ifdef DEBUG

#define printd printf

#else

#define printd(...)

#endif

std::vector<uint64_t> facto(1e7, 1);
std::vector<uint64_t> ifacto(1e7, 1);

uint64_t modpow(uint64_t base, uint64_t exp, uint64_t mod)
{
    base %= mod;

    uint64_t ans = 1;
    while (exp > 0)
    {
        if (exp % 2 == 1)
        {
            ans = ans * base % mod;
        }
        base = base * base % mod;
        exp >>= 1;
    }

    return ans;
}

uint64_t modinv(uint64_t a, uint64_t b, uint64_t mod)
{
    return (a * modpow(b, mod - 2, mod)) % mod;
}

void precompute_facto(uint64_t n, uint64_t mod)
{
    for (uint64_t i = 1; i <= n; i++)
    {
        facto[i] = facto[i - 1] * i % mod;
    }

    ifacto[n] = modinv(1, facto[n], mod);
    for (uint64_t i = n; i > 0; i--)
    {
        ifacto[i - 1] = ifacto[i] * i % mod;
    }
}

uint64_t choose(uint64_t a, uint64_t b, uint64_t mod)
{
    return facto[a] * ifacto[a - b] % mod * ifacto[b] % mod;
}

uint64_t multichoose(uint64_t a, uint64_t b, uint64_t mod)
{
    return choose(a + b - 1, b, mod);
}

std::unordered_map<uint64_t, uint64_t> primes;

void store_primes(uint64_t num, uint64_t &max_count)
{
    max_count = 0;

    auto original_num = num;
    for (auto i = 2ull; i * i < original_num; ++i)
    {
        if (num % i != 0)
            continue;

        auto count = 0ull;
        while (num % i == 0)
        {
            count++;
            num /= i;
        }

        primes[i] = count;
        if (count > max_count)
        {
            max_count = count;
        }
    }

    if (num > 1)
        primes[num] = 1;
}

int main()
{
    uint64_t m, n;
    std::cin >> n >> m;

    uint64_t max_count = 0;
    store_primes(m, max_count);

#ifdef DEBUG
    std::cout << "n: " << n << "m: " << m << std::endl;
    for (auto &v : primes)
    {
        std::cerr << v.first << ": " << v.second << std::endl;
    }
#endif

    const uint64_t mod = 1e9 + 7;

    precompute_facto(max_count + n, mod);

    uint64_t result = 1;
    for (auto &v : primes)
    {
        auto c = choose(v.second + n - 1, v.second, mod);
        result = result * c % mod;
    }

    std::cout << result << std::endl;

    return 0;
}


Measured memory_bytes: 158932
#include <bits/stdc++.h>
using namespace std;
#define ll long long int

int main() {
	// your code goes here
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	ll n,r;
	cin>>n>>r;
    ll dig = (int)(floor( log(n) /log(r)) + 1);
    cout<<dig;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> pos;
    rep(i, n){ int tmp; cin >> tmp; pos.push_back(tmp);}
    pos.push_back(x);

    sort(pos.begin(), pos.end());

    vector<int> sa;
    rep(i, pos.size()-1){
        sa.push_back(pos[i+1]-pos[i]);
    }

    int gcd_ = sa[0];
    rep(i, sa.size()){
        gcd_ = gcd(sa[i], gcd_);
    }
//    show(sa);
    cout << gcd_ << endl;

}



Measured memory_bytes: 1400
#include <stdio.h>
const int MAX_V = 10000;
int prime[10000];
int main(){
int i, k, v ,n;
  for(i = 2; i <= MAX_V; i++) {
    prime[i] = 1;
  }
  for(i = 2; i*i <= MAX_V; i++) {
    if(prime[i]) {
      for(k = 2 * i; k <= MAX_V; k += i) {
        prime[k] = 0;
      }
    }
  }
  while(scanf("%d", &n)){
    if(n==0)break;
    int fir=0 , sec=0;
    for(i=n ;i>3 ;i--){
      if(prime[i] && prime[i-2]){
        fir=i-2;
        sec=i;
        break;
      }
    }
    printf("%d %d\n" ,fir ,sec);
  }
  return 0;
}

Measured memory_bytes: 2636
import math


def main():
    nvertices, nedges, s = map(int, input().split())
    E = []
    for i in range(nedges):
        u, v, w = map(int, input().split())
        E.append((u, v, w))
    INF = float('inf')
    weights = [INF] * nvertices
    weights[s] = 0
    for i in range(nvertices - 1):
        for u, v, w in E:
            if weights[v] > weights[u] + w:
                weights[v] = weights[u] + w
    for u, v, w in E:
        if weights[v] > weights[u] + w:
            print("NEGATIVE CYCLE")
            return

    for w in weights:
        if math.isinf(w):
            print("INF")
        else:
            print(w)


main()

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

/// Constant:
#define         eps         10e-9
#define         pi          2*acos(0)
#define         P1          1e9+7
#define         P2          1e9+9

#define         lli         long long int
#define         PB          push_back
#define         pb          pop_back
#define         mk          make_pair
#define         I           insert
/// Loop:
#define         f1(a,b)     for (int i=a; i<=b; i++)
#define         f2(a,b)     for (int j=a; j<=b; j++)
#define         f-1(a,b)     for (int i=b; i>=a; i--)
#define         f-2(a,b)     for (int j=b; j>=a; j--)
///Print:
#define         pY          cout<<"YES"<<endl;
#define         pN          cout<<"NO"<<endl;
#define         py          cout<<"Yes"<<endl;
#define         pn          cout<<"No"<<endl;

using namespace std;
///ISNNJB

/// Functions:
//lli bigmod(lli b, lli p, lli m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ lli res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//lli mod_inverse(lli a, lli mod) { return bigmod(a,mod-2,mod); }
//lli LCM(lli a, lli b){ return a*b/ __gcd(a,b);}

///Global Variable:
int ara[400005],brr[400004];

/**int fx[]={+1,-1,+0,+0};
int fy[]={+0,+0,+1,-1};
int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};*/

int main() {

    /**freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    lli a,b,c,d,k,t,n,m,x,y,q,ctn=0,l1,l2,total=0;
    //string s,p,q;
    cin>>n;
    f1(1,n)
    cin>>ara[i];
    sort(ara+1, ara+n+1);

    a=n-1;
    f1(1,n) {
        total+=ara[a];
        total+=ara[a+1];
        a--;
        if(i==a)
            break;
        else if(i>a) {
            total-=ara[i];
            break;
        }
    }
    cout<<total<<endl;

    return 0;
}


Measured memory_bytes: 4384
n,k = map(int,input().split())

cnt = [0,1]
tmp = [[0,1]]

for i in range(n):

    tmp.append([cnt[0] * 2 + 2,cnt[1] * 2 + 1])
    cnt[0] = cnt[0] * 2 + 2
    cnt[1] = cnt[1] * 2 + 1

"""
半分に区切ってジャスト半分なら前の分+1を出力
大きければ前の分+1を足して次
小さければ数える数を1小さくしてレベルを下げる
"""
num = 0
for i in range(n,0,-1):
    if (sum(tmp[i])+1)/2 == k:
        num += tmp[i-1][1]+1
        break
    elif (sum(tmp[i])-1)/2 == k:
        num += tmp[i-1][1]
        break
    elif sum(tmp[i]) == k or sum(tmp[i])-1 == k:
        num += tmp[i][1]
        break
    elif (sum(tmp[i])-1)/2 < k:
        num += tmp[i-1][1]+1
        k = k - sum(tmp[i-1]) - 2
    elif (sum(tmp[i])-1)/2 > k:
        k = k - 1
print(num)


Measured memory_bytes: 3064
"use strict";
function I(s,f){this._s=s.split("\n");this._c=0;this._l=0;this._f=f||Number}I.prototype.a=function(){var l=this._s[this._l];if(!l)return;var t=l.trim().split(" ");var a=t[this._c];this._c++;if(t.length===this._c){this._c=0;this._l++}return this._f(a)};I.prototype.l=function(){var l=this._s[this._l];if(!l)return;this._c=0;this._l++;return l.split(" ").map(this._f)};module.exports=I;

function main(input) {
  const o = new I(input, String);

  const N = Number(o.a());
  const Q = Number(o.a());

  const S = o.a();

  const l = [];
  const r = [];
  for (let i = 0; i<Q;i++) {
    l.push(Number(o.a()));
    r.push(Number(o.a()));
  }

  // console.log({N,Q,S,l,r})

  let start = [0];
  let count = 0;
  for (let i=0; i < N-1; i++) {
    if (S[i]==="A" && S[i+1] ==="C") {
      count += 1;
    }
    start.push(count);
  }

  let end = [];
  let endCount = 0;
  for (let i=0; i < N; i++) {
    if (S[i - 1]==="A" && S[i] ==="C") {
      endCount += 1;
    }
    end.push(endCount);
  }

  // console.log(start);
  // console.log(end);

  for (let i=0;i<Q;i++) {
    console.log(end[r[i] - 1] - start[l[i] - 1]);
  }
  




}


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


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 305;
ld dp[N][N][N];
int n, t[4];

void table() {
	for (int t3 = 0; t3 <= t[3]; t3++)
		for (int t2 = 0; t2 + t3 <= t[2] + t[3]; t2++)
			for (int t1 = 0; t1 + t2 + t3 <= n; t1++) {

				int t0 = n - (t1 + t2 + t3);
				ld &ans = dp[t1][t2][t3];
				if (t0 == n)
					ans = 0;
				else {
					ans = 1;
					if (t1)
						ans += dp[t1 - 1][t2][t3] * ((ld) t1 / n);
					if (t2)
						ans += dp[t1 + 1][t2 - 1][t3] * ((ld) t2 / n);
					if (t3)
						ans += dp[t1][t2 + 1][t3 - 1] * ((ld) t3 / n);
					ans /= (1 - ((ld) t0 / n));
				}
			}
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		t[a]++;
	}
	table();
	cout << fixed << setprecision(12) << dp[t[1]][t[2]][t[3]];
	return 0;
}


Measured memory_bytes: 215672