akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <sstream>
#include <iomanip>
 
#define INPUT_FROM_FILE (0)
#if INPUT_FROM_FILE
#include <fstream>
#endif

int f(long n){
	return n * n;
}

int main(int argc, char **argv){
	std::string buf;
	long d = 0;
	long max = 0;
	long s = 0;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif

#if INPUT_FROM_FILE
	while(std::getline(ifs, buf)){
#else
	while(std::getline(std::cin, buf)){
#endif
		d = std::stoi(buf);
		max = 600 - d;

		s = 0;
		for(int i = d; i <= max; i += d){
			s += d * f(i);
		}
		std::cout << s << std::endl;
	}
	return 0;
}


Measured memory_bytes: 3068
from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))
b = list(accumulate(a))
ll, rr = 0, 2
ans = float("INF")

for i in range(1, n-2):
  while True:
    p = b[ll]
    q = b[i]-b[ll]
    r = b[rr]-b[i]
    s = b[n-1]-b[rr]
    lt = abs(p-q)
    rt = abs(r-s)
    if abs(b[ll+1]-(b[i]-b[ll+1]))<lt:
      ll+=1
    elif abs((b[rr+1]-b[i])-(b[n-1]-b[rr+1]))<rt:
      rr+=1
    else:
      break
  ans = min(ans, abs(max(p, q, r, s)-min(p, q, r, s)))
print(ans)

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


int main(){
	int n;
	cin>>n;
	vector<double> v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	vector<vector<double> > dp(n+1,vector<double>(n+1,0));
	dp[0][0]=1.0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=i;j++){
			if(j==0){
				dp[i][j]=dp[i-1][j]*(1-v[i-1]);
			}
			else{
				dp[i][j]=dp[i-1][j-1]*v[i-1] + dp[i-1][j]*(1-v[i-1]);
			}
		}
	}
	double ans=0.0;
	for(int i=0;i<=n;i++){
		int t=n-i;
		if(i>t){
			ans+=dp[n][i];
		}
	}
	printf("%.10lf\n",ans);
}

Measured memory_bytes: 70656
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	char C;

	cin >> C;
	printf("%c\n", C + 1);

	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll x;
    cin >> x;
    ll b = 2;
    ll ans = 1;
    while(b*b <= x){
      ll temp = b;
      ll pwr = 0;
      while(temp <= x){
        pwr ++;
        temp *=b;
      }
      temp /=b;
      if(pwr > 1 && ans < temp) ans = temp;
      b++;
    }
    cout << ans << endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;
typedef pair<ll  ,ll > pll;

const ll maxn =2e6;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define ms(x , y) memset(x , y , sizeof x);
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}

ll a , b;

int main(){
    migmig
    cin >> a >> b;
    cout << a*b/__gcd(a , b);


    return(0);
}


//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI acos(-1.0)
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n,m;cin>>n>>m;
  int path[51][51]={};
  REP(i,m){
    int a,b;cin>>a>>b;
    path[a][b]++;
    path[b][a]++;
  }
  for(int i=1;i<=n;i++){
    int path_num=0;
    for(int j=1;j<=n;j++){
      path_num+=path[i][j];
    }
    P(path_num);
  }
  return 0;
}


Measured memory_bytes: 256
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
fn main() {
    input! {
    a:i64,
    b:i64,
    c:i64,
    }
    println!("{}", b + min(c, a + b + 1));
}


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

int main() {
    int A,B,C;
    cin>>A>>B>>C;

    if(A==B && A!=C || A==C && A!=B || B==C && A!=B){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}
    

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
int pt[123456], n, m, x, y, z;
void f() {
	for (int i = 1; i <= n; i++)pt[i] = i;
	return;
}
int root(int i) {
	if (pt[i] == i)return i;
	else return pt[i] = root(pt[i]);
}
void unite(int a, int b) {
	pt[root(b)] = root(a);
	root(b);
	return;
}
signed main() {
	cin >> n >> m; f();
	for (int i = 0; i < m; i++) {
		cin >> x >> y >> z;
		unite(x, y);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (root(i) == i)ans++;
	}
	cout << ans << endl;
	cin >> n;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
/*
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>
#include<stack>
#include<cassert>
#include<functional>
*/
#define int long long int
#define double long double
using namespace std;
#define INT_DMAX 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i,n) for(int (i)=0, i##_len = (n);(i)<i##_len;(i)++)
#define reps(i,x) for(int (i)=1;(i)<=(int)(x);(i)++)
#define rrep(i,x) for(int (i)=((int)(x)-1);(i)>=0;(i)--)
#define rreps(i,x) for(int (i)=((int)(x));(i)>0;(i)--)
#define FOR(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1)<<(n))
#define all(x) (x).begin(),(x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl 
#define nint int
using namespace std;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
typedef pair<int,int> p;
typedef pair<double,double> dop;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;


signed main()
{
int n,t;
std::cin >> n >> t;
std::vector<int> a(n,0);
rep(i,n){
    int temp;
    std::cin >> a[i];
}
int out = 0;
for(int i = 1; i < n; i++){
    out += min(t,a[i] - a[i - 1]);
}
out += t;
std::cout << out << std::endl;
return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int N;
  vector<int> As,Bs,Cs;
  int x;
  cin >> N;
  for(int i=0;i<N; i++){
    cin >> x;
    As.push_back(x);
  }
  for(int i=0;i<N; i++){
    cin >> x;
    Bs.push_back(x);
  }
  for(int i=0;i<N; i++){
    cin >> x;
    Cs.push_back(x);
  }
  sort(As.begin(),As.end());
  sort(Cs.begin(),Cs.end());
  long long ans=0;
  for(auto itr=Bs.begin();itr!=Bs.end();++itr){
//    cout << "B=" << *itr << endl;
//    cout << lower_bound(As.begin(),As.end(),*itr)-As.begin() << "*" ;
//    cout << Cs.end()-upper_bound(Cs.begin(),Cs.end(),*itr) << endl;
    ans+=(lower_bound(As.begin(),As.end(),*itr)-As.begin())*
      (Cs.end()-upper_bound(Cs.begin(),Cs.end(),*itr));
  }
  cout << ans << endl;
}

Measured memory_bytes: 1784
package main

import "fmt"

func main() {	
	var N int;
	fmt.Scanf("%v", &N)
	
	if N % 2 == 0 {
		fmt.Printf("%.10f\n", 1.0 / 2.0)
	} else {
		fmt.Printf("%.10f\n", float64(N/2 + 1) / float64(N))
	}
}


Measured memory_bytes: 512
#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 REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--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 SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&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 VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#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 SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
///////////////////////////////////////////////
int main(){
	int N;
	SCD(N);
	static int a[100002] = {};
	static int b[100002] = {};
	static int c[100002] = {};

	static int dp[100002][3] = {};

	FORq(i,1,N){
		SCD3(a[i],b[i],c[i]);
	}

	dp[1][0] = a[1];
	dp[1][1] = b[1];
	dp[1][2] = c[1];

	FORq(i,2,N){
		dp[i][0] = max(dp[i-1][1] + a[i] , dp[i-1][2] + a[i]);
		dp[i][1] = max(dp[i-1][0] + b[i] , dp[i-1][2] + b[i]);
		dp[i][2] = max(dp[i-1][0] + c[i] , dp[i-1][1] + c[i]);
	}

	PRINTD(max({dp[N][0],dp[N][1],dp[N][2]}));

}


Measured memory_bytes: 2560
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    int ans = INT_MAX;
    while(--n >= 0){
        int a;
        cin >> a;

        int cnt = 0;
        while(a % 2 == 0){
            ++ cnt;
            a /= 2;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Apolloliu
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

void get() {

}

int sum[510][510];
typedef pair<int,int> pii;

class DAtCoderExpress2 {
public:
	void solve(std::istream& in, std::ostream& out) {
		int n, m, q, x, y;
		in >> n >> m >> q;
		memset(sum, 0, sizeof(sum));

		for (int i = 0; i < m; ++i) {
			in >> x >> y;
			sum[x][y] ++;
		}

		for (int i = 1; i <= n ; ++i) {
			for (int j = 1; j <= n ; ++j) {
				sum[i][j] += sum[i][j-1];
				sum[i][j] += sum[i-1][j];
				sum[i][j] -= sum[i-1][j-1];
			}
		}
		for (int i = 0; i < q; ++i) {
			in >> x >> y;
			out << sum[y][y] - sum[y][x-1] - sum[x-1][y] + sum[x-1][x-1] << '\n';
		}
	}
};


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	DAtCoderExpress2 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1920
#include <iostream>

using namespace std;

int main() {
    int n, d;   cin >> d >> n;
    int tmp = 1;
    while (d--) {
        tmp *= 100;
    }

    if (n != 100)
        cout << n * tmp << endl;
    else 
        cout << (n+1) * tmp << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
int main() {
  int N, Q;
  cin >> N >> Q;
  dsu d(N + 1);
  REP(i, Q) {
    int t, u, v;
    cin >> t >> u >> v;
    if (t) {
      printf("%d\n", d.same(u, v) ? 1 : 0);
    } else {
      d.merge(u, v);
    }
  }
}

Measured memory_bytes: 3964
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = 0

for i in range(n, 0, -1):
  if b[i-1] < a[i]:
    cnt += b[i-1]
    a[i] -= b[i-1]
    b[i-1] = 0
    if b[i-1] < a[i-1]:
      cnt += b[i-1]
      a[i-1] -= b[i-1]
    elif b[i-1] >= a[i-1]:
      cnt += a[i-1]
      a[i-1] = 0
  
  elif b[i-1] >= a[i]:
    cnt += a[i]
    b[i-1] -= a[i]
    a[i] = 0
    if b[i-1] < a[i-1]:
      cnt += b[i-1]
      a[i-1] -= b[i-1]
    elif b[i-1] >= a[i-1]:
      cnt += a[i-1]
      a[i-1] = 0
    
print(cnt)


Measured memory_bytes: 18476
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;

int main() {
int n;
cin >> n;
double x[n],y[n];
int cnt = 1;
REP(i,n) {
  cin >> x[i] >> y[i];
  cnt*=i+1;
}
double root=0;
double temp;
REP(i,n-1) {
  for(int j=i+1;j<n;j++) {
    temp=pow(x[i]-x[j],2)+pow(y[i]-y[j],2);
    root+=sqrt(temp);
  }
}
cout << fixed << setprecision(10) <<  (root*2)/n << endl;
return 0;
}


Measured memory_bytes: 256
S = input()[:4]

mae = S[:2]
ato = S[2:]

if mae.isnumeric() and ato.isnumeric():
    mae, ato = int(mae), int(ato)
    maeY, maeM, atoY, atoM = False, False, False, False
    
    if 1 <= mae <= 12:
        if  1 <= ato <= 12:
            print("AMBIGUOUS")
        else:
            print("MMYY")
    elif 1<= ato <= 12:
        print("YYMM")
    else:
        print("NA")
else:
    print("NA")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll k,a,b;
	cin>>k>>a>>b;
	ll now=1;
	if(1<b-a && a-1<=k){//日本円を介して増幅可能な場合
		k-=a-1;
		ll x=k/2;
		now=x*b-(x-1)*a;
		if(k%2){
			now++;
		}
	}else{
		now+=k;
	}
	cout<<now<<endl;
}

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




int main()
{
	long long int N, K,  b, ans=0;
	cin >> N >> K;

	if (K == 0)
		ans = N * N;
	else for (b = K+1 ; b <= N; b++) {
		ans += (b - K)*(N / b);
		if (N / b * b + K <= N)
			ans += N - (N / b * b + K) + 1;

	}

	cout <<ans<< endl;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nmxy = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var n = nmxy[0];
        var m = nmxy[1];
        var xa = nmxy[2];
        var yb = nmxy[3];
        var xn = Console.ReadLine().Split().Select(x => int.Parse(x)).Max();
        var y1 = Console.ReadLine().Split().Select(x => int.Parse(x)).Min();

        Console.WriteLine(Math.Max(xa, xn) < Math.Min(yb, y1) ? "No War" : "War");
    }
}

Measured memory_bytes: 13396
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int N, S, A[3005];
ll DP[3005][3005];

int main(){
  cin >> N >> S;
  for (int i = 1; i <= N; i++) cin >> A[i];

  DP[0][0] = 1;
  for (ll i = 1; i <= N; i++){
    for (int j = 0; j <= S; j++){
      DP[i][j] = DP[i-1][j];
    }
    
    if (A[i] > S) continue;
    if (A[i] == S){
      DP[i][S] += i * (N - i + 1);
      DP[i][S] %= Mod;
    }else{
      DP[i][A[i]] += i;
    }

    for (int j = 1; j + A[i] < S; j++){
      DP[i][j + A[i]] += DP[i-1][j];
    }
    if (A[i] < S) DP[i][S] += DP[i-1][S - A[i]] * (N - i + 1);

    for (int j = 0; j <= S; j++){
      DP[i][j] %= Mod;
    }
  }
  cout << DP[N][S] << endl;

  return 0;
}


Measured memory_bytes: 70656
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
#include <assert.h>

using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef  unsigned long long  ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

ll inf=(ll)2e18;
const int mod=1000000007;
//const int mod=998244353;

int n,m;
const int N=2e5+10;




int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    int q,t,k,u,v;
    ll x,a,b,c,d,y,p,z;
    cin >> n;
    vi vv(n);
    for(int i=0; i<n; i++){
        cin >> vv[i];
    }
    auto lo = [&](int i){
        if(i==0)return vv[i]<vv[i+1];
        else if(i==n-1)return vv[i]<vv[i-1];
        else return (vv[i]<=vv[i+1]&&vv[i]<vv[i-1])||(vv[i]<vv[i+1]&&vv[i]<=vv[i-1]);
    };
    auto hi = [&](int i){
        if(i==0)return vv[i]>vv[i+1];
        else if(i==n-1)return vv[i]>vv[i-1];
        else return (vv[i]>=vv[i+1]&&vv[i]>vv[i-1])||(vv[i]>vv[i+1]&&vv[i]>=vv[i-1]);
    };
    a=1000;
    for(int i=0; i<n; i++){
        if(lo(i)){
            for(int j=i+1; j<n; j++){
                if(hi(j)){
                    a=a/vv[i]*vv[j]+a%vv[i];
                    i=j;
                    break;
                }
            }
        }
    }
    cout << a << el;
    
    return 0;
}






Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[]) {
  map<char,string> s;
  string sa, sb, sc;
  cin >> sa >> sb >> sc;
  transform(sa.begin(), sa.end(), sa.begin(), ::toupper);
  transform(sb.begin(), sb.end(), sb.begin(), ::toupper);
  transform(sc.begin(), sc.end(), sc.begin(), ::toupper);
  s['A'] = sa;
  s['B'] = sb;
  s['C'] = sc;
  char idx = 'A';
  while (true) {
    if (s[idx].size()==0) break;
    else {
      char temp = s[idx][0];
      s[idx].erase(s[idx].begin()+0);
      idx = temp;
    }
  }
  cout << idx << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        System.out.println(sc.next().matches("^A[a-z]+C[a-z]+$") ? "AC" : "WA");
    }

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


Measured memory_bytes: 23764
//Author rahuliitkgp

/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void cpp(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main(){
    cpp();
    ll n;
    cin>>n;
    unordered_map<string, ll> mapp;
    while(n--){
        string s;
        cin>>s;
        mapp[s]++;
    }
    cout<<"AC x "<<mapp["AC"]<<endl;
    cout<<"WA x "<<mapp["WA"]<<endl;
    cout<<"TLE x "<<mapp["TLE"]<<endl;
    cout<<"RE x "<<mapp["RE"]<<endl;
    return 0;
}





Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

// #define amari(x) ((x) % 1000000007)
#define amari(x) ((x) % 998244353)

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<int>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(long i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

std::vector<ll> enum_div(ll n)//nの約数を列挙
{
	std::vector<ll> ret;
	for(ll i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}

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

  int n, k;

  cin >> n >> k;

  double score = 0;
  int now = 1;

  for (int i = n; i > 0; i--) {
    while (i * now < k) {
      now*=2;
    }
    score += 1.0 / now;
  }

  cout << setprecision(12) << score/n << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,flag=0;
	int a[1000]={0};
	cin>>n>>x;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int count=0;
	sort(a,a+n);
	for(int i=0;i<n;i++)
	{
		if(x-a[i]>=0)
		{
			count++;
			x-=a[i];
		}
		else
		{  flag=1;
				break;
		}
	
	}
	if(!flag)
	{
		if(x)
		count--;
	}
	cout<<count;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  string s;
  cin >> s;

  int ans = INF;
  for (char c = 'a'; c <= 'z'; c++) {
    vector<int> pos;
    pos.pb(-1);
    rep(i, len(s)) {
      if (s[i] == c)
        pos.pb(i);
    }
    pos.pb(len(s));

    int m = len(pos);
    int temp = 0;
    rep(i, m - 1) {
      chmax(temp, pos[i + 1] - pos[i] - 1);
    }
    chmin(ans, temp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second
int n;
void dfs(string s, char mx){
	if(s.size()==n){ 
		cout << s << endl;
		return;
	}
	for(char c='a'; c<=mx; c++){
		if(c==mx) dfs(s+c,mx+1);
		else dfs(s+c,mx);
	}
}

int main(void) {
	cin >> n;
	dfs(string(""),'a');
}




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

const int INF = 1e9;


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

  int dp[n];
  for(int i=0;i<=n;i++){
    dp[i]=i;
  }
  for(int i=1;pow(9,i)<=n;i++){
    dp[(int)pow(9,i)]=1;
  }
  for(int i=1;pow(6,i)<=n;i++){
    dp[(int)pow(6,i)]=1;
  }
  for(int i=7;i<=n;i++){
    if(dp[i]==1){
      continue;
    }
    int tmp=dp[i];
    int a=1;
    while(i-pow(9,a)>=0){
      tmp=min(tmp,dp[i-(int)pow(9,a)]+1);
      ++a;
    }
    int b=1;
    while(i-pow(6,b)>=0){
      tmp=min(tmp,dp[i-(int)pow(6,b)]+1);
      ++b;
    }
    for(int j=i-8;j<i;j++){
      tmp=min(tmp,dp[j]+i-j);
    }
    dp[i]=tmp;
  }


  cout<<dp[n]<<endl;
}

Measured memory_bytes: 1148
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1e9;
#define put(n) cout<<(n)<<endl
#define rep(i,N) for(int(i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>=(0);--(i))
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define pb(n) push_back(n)
#define int long long

signed main(){
    int N; cin>>N;
    vector<int> A(N);

    int a=0,b=0,sum = 0;
    rep(i,N) cin>>A[i];

    rep(i,N){
        sum += A[i];
        if(i%2 == 0 && sum <= 0) a -= (sum-1),sum = 1;
        else if(i%2 && sum >= 0) a += (sum+1),sum = -1;
    }

    sum = 0;
    rep(i,N){
        sum += A[i];
        if(i%2 && sum <= 0) b -= (sum-1),sum = 1;
        else if(i%2 == 0 && sum >= 0) b += (sum+1),sum = -1;
    }

    cout << (a>b?b:a) << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
ll cnt [100010] ;
const ll MOD = 1e9+7 ;
ll fst(int a, int b){
    if (!b) {
        return 1;
    }
    ll sq=fst(a, (b>>1LL));
    sq*=sq;

    if (b&1) {
        sq%=MOD;
        sq*=a;
    }

    return sq%MOD;
}

int main()
{

int n , k ; cin >>n>> k ;
ll ans = 0 ;
for (int i=k ; i>=1 ; i--){
    int m=k/i;
    cnt[i]= fst(m,n) ;
    for (int j=2 ; j*i<=k ; j++){
        cnt[i]-=cnt[j*i];
        cnt[i]%=MOD;
        if (cnt[i]<0)cnt[i]+=MOD;
    }
    cnt[i]%=MOD;
    ans+=(i*cnt[i])%MOD;
    ans%=MOD;
    //cout << ans <<endl;
}

cout << ans%MOD ;

}


Measured memory_bytes: 4428
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N,K=get_i
ans=0
min=0
max=N
MOD=10**9+7
1.upto(K-1) do|i|
  min+=i
  max+=N-i
end
ans=max-min+1
(K).upto(N) do|i|
    min+=i
    max+=N-i
    ans+=max-min+1
    ans%=MOD
end
puts ans

Measured memory_bytes: 14412
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

int main(){
	int N, M;
	cin >> N >> M;
	vector<pair<int, int>> v;
	for(int i=0; i<N; i++){
		int a, b;
		cin >> a >> b;
		v.PB(MP(a, b));
	}
	sort(v.begin(), v.end());

	int ans = 0;
	int j = 0;
	priority_queue<int> que;
	for(int i=1; i<=M; i++){
		while(j < N && v[j].first <= i){
			que.push(v[j].second);
			j++;
		}
		if(que.size() > 0){
			ans += que.top();
			que.pop();
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1908
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main(){
	double x1, x2, y1, y2, x, y;
	cin >> x1 >> y1 >> x2 >> y2;
	x = abs(x2-x1);
	y = abs(y2-y1);
	cout << fixed << setprecision(5) << sqrt(pow(x, 2)+pow(y, 2)) << endl;
	return 0;
}


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


int* g;

long long int_pow(long long a, long long b, const int& mod) {
    long long ans(1);
    while (b) {
        if (b % 2) ans = ans * a % mod;
        a = a * a % mod;
        b /= 2;
    }
    return ans;
}

void pre_calc(const int& n) {
    bool* is_c = new bool[n + 1];
    vector<int> p;
    //vector<int> g(n + 1);
    g = new int[n + 1];
    g[1] = 1;

    for (int i = 2; i <= n; ++i) {
        if (!is_c[i]) {
            p.push_back(i);
            // phi: i-1, mu: -1, lcm: i - i * i
            g[i] = i - 1;
        }
        
        for (int j = 0; j < p.size() && p[j] * i <= n; ++j) {
            is_c[i * p[j]] = true;
            // for mobius function: 
            // g[i] * (i % p[j] ? g[p[j]] : 0)
            g[i * p[j]] = g[i] * (i % p[j] ? g[p[j]] : p[j]);
            if (i % p[j] == 0) break;
        }
    }

    delete[] is_c;
}

int main() {
    // time :k log(n)
    // space k
    int n, k;
    cin >> n >> k;
    const int mod(1000000007);
    long long ans(0);
    pre_calc(k);
    //for (int i = 0; i <= n; ++i) cout << g[i] << ' ';

    //cout << endl;
    for (int i = 1; i <= k; ++i)
        ans = (ans + int_pow(k / i, n, mod) * g[i] % mod) % mod;
    delete[] g;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3808
import math

prime = {}

N = int(input())

def judge(N):

    if N==1:
        print(1)
        return 0

    isPrime = [True]*(N+1)
    isPrime[0] = False
    isPrime[1] = False
    for i in range(2,int(math.sqrt(N))+2):
        if isPrime[i]:
            n = 2*i
            while n<=N:
                isPrime[n] = False
                n += i
    
    for i in range(N+1):
        if isPrime[i]:
            prime[i] = 0
    
    key_list = list(prime.keys())
    
    for num in range(2,N+1):
        res = num
        idx = 0
        while res>1:
            k = key_list[idx]
            if res%k == 0:
                prime[k] += 1
                res = res//k
            else:
                idx += 1
        
    ans = 1
    for v in prime.values():
        ans *= (v+1) 
        ans = ans % (10**9+7)
        if ans==0:
            ans = 1
        
    print(ans)
    return 0

judge(N)

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



int main()
{

    int N, M, K, tmp, find;

    while(1) {
        std::cin >> N;
        if (N == 0) break;
        std::cin >> M >> K;
        std::vector<int> rests;
        rests.reserve(M);
        rests.push_back(0);
        for (int i = 0; i < M-1; i++) {
            std::cin >> tmp;
            rests.push_back(tmp);
        }
        std::sort(rests.begin(), rests.end());
        int sum = 0;

        for (int i = 0; i < K; i++) {
            std::cin >> tmp;
            find = std::upper_bound(rests.begin(), rests.end(), tmp) - rests.begin() - 1;
            if (tmp == rests[find]) {
                continue;
            }
            else if (find == M-1) {
                sum += std::min(N- tmp, tmp - rests[find]);
            }
            else {
                sum += std::min(tmp - rests[find], rests[find+1] - tmp);
            }
        }
        std::cout << sum << std::endl;
    }

    return 0;
}



Measured memory_bytes: 3432
#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];
	}

	int gcd = A[0];
	for (int i = 1; i < N; i++) {
		gcd = __gcd(gcd, A[i]);
	}

	cout << gcd << endl;

	return 0;
}


Measured memory_bytes: 640
//written by newbiechd
#include <cstdio>
#include <cctype>
#include <algorithm>
#define BUF 1000000
using namespace std;
const int N = 100003;
char buf[BUF], *p1, *p2;
inline char gc() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2) ? EOF : *p1++; }
inline int rd() {
    register int f = 0;
    register char c;
    while (!isdigit(c = gc())) {}
    do
        f = f * 10 + (c ^ 48);
    while (isdigit(c = gc()));
    return f;
}

int main() {
    register int a = rd(), b = rd(), c = rd();
    if (a > b)
        swap(a, b);
    printf(a < c && c < b ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int n,k;cin>>n>>k;
    int ans=0;
    rep(i,0,n){
        int h;cin>>h;
        if(h>=k)ans++;
    }
    cout<<ans<<endl;
}


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

ll mod_pow(ll x, ll n){
    if (n == 0) return 1;
    ll res = mod_pow(x * x %MOD, n / 2);
    // x^n = ((x^2)^(n/2)) * x
    if(n & 1) return res = res * x %MOD;
    // x^n = (x^2)^(n/2)
    return res %MOD;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    vector<ll> mod_cnt(k+1);
    ll ans = 0;
    for(ll g=k;g>=1;g--){
        if(k / g == 1){
            mod_cnt[g] = 1;
            ans = (ans + g) % MOD;
            continue;
        }
        ll cnt = mod_pow((k / g), n);
        for(ll t=g*2;t<=k;t+=g){
            cnt = (cnt - mod_cnt[t] + MOD) % MOD;
        }
        mod_cnt[g] = cnt;
        ans = (ans + (g * cnt) % MOD) % MOD;
        // cout << ans << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3988
#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 <unordered_set> // unordered_set
#include <bitset> // bitset

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
	int N;
	string s = "";

	cin >> N;
	cin >> s;

	string out_s = "";
	for (int i = 0; i < N; i++)
	{
		if (s[i] != s[i + 1]) {
			out_s.append(1, s[i]);
		}

	}

	if (s[N - 1] != s[N]) {
		out_s.append(1, s[N]);
	}

	cout << out_s.length() - 1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  char a, b, c, d, e, f, g, h, i;
  in3(a, b, c);
  in3(d, e, f);
  in3(g, h, i);
  out(a);
  out(e);
  out(i);
  memi;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int h = scanner.nextInt();
        final int w = scanner.nextInt();

        final int[][] table = new int[h][w];
        for (int i = 0; i < h; i++) {
            final String line = scanner.next();
            for (int j = 0; j < line.toCharArray().length; j++) {
                table[i][j] = line.charAt(j) == '.' ? 0 : -1;
            }
        }

        int longestDistance = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (table[i][j] == -1) {
                    continue;
                }

                final int[][] tmp = new int[h][w];
                for (int k = 0; k < tmp.length; k++) {
                    System.arraycopy(table[k], 0, tmp[k], 0, w);
                }

                tmp[i][j] = 1;
                longestDistance = Math.max(getLongestDistance(tmp, h, w, j, i), longestDistance);
            }
        }
        System.out.println(longestDistance - 1);
    }

    private static int getLongestDistance(final int[][] table, final int h, final int w, final int initX, final int initY) {
        final Deque<Point> points = new ArrayDeque<>();
        final Point initPoint = new Point(initX, initY);
        points.add(initPoint);

        while (!points.isEmpty()) {
            final Point point = points.pollFirst();
            final int x = point.x;
            final int y = point.y;
            if (x > 0 && table[y][x - 1] == 0) {
                table[y][x - 1] = table[y][x] + 1;
                points.add(new Point(x - 1, y));
            }

            if (x < w - 1 && table[y][x + 1] == 0) {
                table[y][x + 1] = table[y][x] + 1;
                points.add(new Point(x + 1, y));
            }

            if (y > 0 && table[y - 1][x] == 0) {
                table[y - 1][x] = table[y][x] + 1;
                points.add(new Point(x, y - 1));
            }

            if (y < h - 1 && table[y + 1][x] == 0) {
                table[y + 1][x] = table[y][x] + 1;
                points.add(new Point(x, y + 1));
            }
        }

        int max = 0;
        for (final int[] array : table) {
            for (final int i : array) {
                max = Math.max(i, max);
            }
        }

        return max;
    }

    static class Point {
        final int x;
        final int y;

        Point(final int x, final int y) {
            this.x = x;
            this.y = y;
        }
    }
}


Measured memory_bytes: 27208
#include <iostream> 
#include <numeric> 
#include <cstdlib> 
#include <climits> 
#include <cmath> 
#include <cstdio> 
#include <cfloat> 
#include <map> 
#include <utility> 
#include <set> 
#include <memory> 
#include <algorithm> 
#include <functional> 
#include <sstream> 
#include <complex> 
#include <memory.h>
#include <stack> 
#include <queue> 
#include <string> 
#include <vector> 
#include <memory>
using namespace std; 

#define rep(i, n) for(int i = 0; i < n; i++) 
#define rep2(i, m, n) for(int i = m; i < n; i++) 
const double EPS = 1E-9; 
typedef long long ll; 
typedef pair<int, int> P; 
typedef pair<int, P> PP; 
typedef complex<double> xy_t; 
const int INF = 1 << 30; 

string nums[1000];
int memo[1 << 22];

int n, m;

int calc(int state){
  if(memo[state] != -1) return memo[state];
  else{
    int rest = 0;
    rep(i, n){
      bool ok = true;
      rep(j, m){
	int s = (state >> (j * 2)) & 3;
	if(s == 2 && nums[i][j] == '0') ok = false;
	if(s == 1 && nums[i][j] == '1') ok = false;
      }
      if(ok) rest++;
    }
    if(rest == 0){
      return memo[state] = INF;
    }else if(rest == 1){
      return memo[state] = 0;
    }
  }
  int res = INF;
  rep(i, m){
    int s = (state >> (i * 2)) & 3;
    if(s == 0){
      int a = calc(state | (1 << (i * 2)));
      int b = calc(state | (2 << (i * 2)));
      if(a == INF && b != INF) res = min(res, b + 1);
      else if(b == INF && a != INF) res = min(res, a + 1);
      else if(a != INF && b != INF) res = min(res, max(a, b) + 1);
    }
  }
  return memo[state] = res;
}

int main(){
  while(cin >> m >> n && (m || n)){
    memset(memo, -1, sizeof(memo));
    rep(i, n){
      cin >> nums[i];
    }
    cout << calc(0) << endl;;
  }
  return 0;
}
  

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
int main()
{
	int n;
	int i;
	stack<int> in;
	while(scanf("%d",&i) != EOF){
		if(i != 0){
			in.push(i);
		}
		else {
			cout << in.top() << endl;
			in.pop();
		}
	}
}

Measured memory_bytes: 1212
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <fstream>

using namespace std;

ifstream fin("../data.txt");

int x, maxi, n;
string s;

int main() {

  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'I') x++;
    else x--;
    if (x > maxi) maxi = x;
  }

  cout << maxi;

  return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#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=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b) << endl;
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

const int MAX = 600;

int N, M;
ld prob[MAX];
vi edge[MAX];
ld dp[MAX];

ld solve() {
    prob[N-1] = 0;
    REPR (i, N-1) {
        FORE (e, edge[i]) prob[i] += (1 + prob[e]);
        prob[i] /= edge[i].size();
    }

    ld ans = prob[0];
    REP (block, N-1) {
        FOR (j, block+1, N) dp[j] = prob[j];
        int cut = -1;
        ld mx = -1;
        FORE (e, edge[block]) if (prob[e] > mx) {
            cut = e;
            mx = prob[e];
        }
        dp[block] = 0;
        FORE (to, edge[block]) if (cut != to) {
            dp[block] += (1 + dp[to]);
        }
        dp[block] /= (edge[block].size() - 1);
        REPR (j, block) {
            dp[j] = 0;
            FORE (to, edge[j]) dp[j] += (1 + dp[to]) / edge[j].size();
        }
        if (dp[0] > 0) ans = min(ans, dp[0]);
    }
    return ans;
}

int main() {
    cin >> N >> M;
    REP (i, M) {
        int s, t; cin >> s >> t;
        edge[s-1].push_back(t-1);
    }
    cout << setprecision(12) << solve() << endl;
}

Measured memory_bytes: 2560