akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define F first
#define S second
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define p_b push_back
#define all(c)              c.begin(), c.end()
using namespace std;
typedef long long ll; //printf("%lld ", ll); to out put long
typedef pair <int , int> pii;
typedef pair <ll , ll> pll;
const double eps = 1e-6;
const int MAXN = 1e5 + 5;
const ll MOD = 1e9 + 7;
bool ODD(ll O) {return (O % 2 != 0);}
ll gcd(ll a, ll b) {return __gcd(a , b);}
ll lcm(ll a, ll b) {return a * b / gcd(a , b);}
int dx[] = {1, 0, -1 ,0 , -1 , 0};
int dy[] = {0, 1, 0, -1 , -1 , 0};
ll power (ll x, ll y) {
    if(y == 0) return 1;
    if(ODD(y)) return x * power(x , y / 2) * power(x , y / 2);
    return power(x , y / 2) * power(x , y / 2);
}
/*------ never give up --------*/
int n, w;
ll arr[MAXN][3], dp[105][MAXN][3];
ll solve(int idx , int rem , int cur) {
    if(idx == n || rem == 0) return 0;

    ll &ret = dp[idx][rem][cur];
    if(ret != -1) return ret;

    ll sol1 = 0, sol2 = 0;
    ret = 0;
    if(rem - arr[idx][0] >= 0) {
        sol1 = solve(idx + 1 , rem - arr[idx][0] , 0) + arr[idx][1];
    }
    sol2 = solve(idx + 1 , rem , 1);
    ret = max(sol1 , sol2);
    return ret;

}
int main () {
    int t = 1;
    //cin >> t;
    while(t--) {
        scanf("%d%d" , &n, &w);
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < 2; j++) scanf("%lld", &arr[i][j]);
        }
        memset(dp , -1 , sizeof dp);
        cout << solve(0 , w , 2);

    }

    return 0;
}


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

int n;
vector<int> a;
vector<vector<int>> e;
vector<int> dp;
vector<int> ans;

void dfs(int pre, int crt, int size)
{
  auto ud = lower_bound(dp.begin(), dp.end(), a[crt]);
  int tmp = *ud;
  *ud = a[crt];
  if (tmp == INT_MAX)
    size++;
  ans[crt] = size;
  for (int i : e[crt])
    if (i != pre)
      dfs(crt, i, size);
  *ud = tmp;
}

int main()
{
  cin >> n;
  a.resize(n);
  rep(i, n)
    cin >> a[i];
  e.resize(n);
  rep(i, n - 1)
  {
    int u, v;
    cin >> u >> v;
    e[u-1].push_back(v - 1);
    e[v-1].push_back(u - 1);
  }
  ans.resize(n);
  dp.resize(n);
  fill(dp.begin(), dp.end(), INT_MAX);
  dfs(-1, 0, 0);
  rep(i, n)
    printf("%d\n", ans[i]);
  return 0;
}

Measured memory_bytes: 30744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
int main(){
    ll a,b,c,k;cin>>a>>b>>c>>k;
    if(a>=k){
        cout<<k<<endl;
    }
    else if(a+b>=k){
        cout<<a<<endl;
    }
    else{
        k-=a+b;
        cout<<a-k<<endl;
    }
    return 0;
}

Measured memory_bytes: 3632
def func(l, r, same) -> int:
    """
    X(l,r)X -> same=True
    X(l,r)y -> same=False
    次の送信クエリ候補を返す
    """
    parity = (r - l + 1) % 2
    if parity ^ same:
        ret = (l + r) // 2
    else:
        ret = -1
    return ret


def main():
    n = int(input())

    seat = [''] * n

    print(0, flush=True)
    response = input()
    if response[0] == 'V':
        print(0)
        return
    seat[0] = response[0]

    l, r = 0, n
    x = func(l, r, same=True)
    for _ in range(19):
        print(x, flush=True)
        response = input()
        if response[0] == 'V':
            print(x)
            return
        seat[x] = response[0]

        res = func(l, x, seat[l] == seat[x])
        if res != -1:
            r = x
            x = res
            continue

        res = func(x, r, seat[x] == seat[r % n])
        if res != -1:
            l = x
            x = res


if __name__ == '__main__':
    main()


Measured memory_bytes: 4424
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
vector<int> E[202020];
int vis[202020];
ll ret=1;
ll mo=1000000007;
ll rev[202020];

vector<int> P,LP;
set<int> Vs,IL;
set<pair<int,int>> Es;
map<pair<int,int>,int> O;

void dfs(int cur) {
	int i;
	if(Vs.count(cur)) {
		if(LP.size()) return;
		int add=0;
		FOR(i,P.size()) {
			if(P[i]==cur) add=1;
			if(add) {
				LP.push_back(P[i]);
				IL.insert(P[i]);
			}
		}
		return;
	}
	vis[cur]=1;
	Vs.insert(cur);
	P.push_back(cur);
	FORR(e,E[cur]) if(Es.count({min(e,cur),max(e,cur)})==0) {
		Es.insert({min(e,cur),max(e,cur)});
		dfs(e);
	}
	P.pop_back();
	
}

void dfs2(int cur,int pre) {
	O[{min(cur,pre),max(cur,pre)}]=cur;
	FORR(e,E[cur]) if(e!=pre) dfs2(e,cur);
}

ll hoge(int cur) {
	LP.clear();
	IL.clear();
	P.clear();
	Vs.clear();
	Es.clear();
	
	dfs(cur);
	if(Vs.size()!=Es.size()) return 0;
	LP.push_back(LP[0]);
	
	ll r[2]={1,1};
	int i,x;
	FOR(i,2) {
		O.clear();
		
		FORR(v,LP) FORR(e,E[v]) if(IL.count(e)==0) dfs2(e,v);
		FOR(x,LP.size()-1) O[{min(LP[x],LP[x+1]),max(LP[x],LP[x+1])}]=LP[x+i];
		map<pair<int,int>,int> cost;
		FORR(p,Es) {
			cost[p]++;
			int take=O[p];
			int oth=p.first+p.second-take;
			FORR(v,E[take]) {
				if(v<oth) cost[p]+=cost[{min(v,take),max(v,take)}];
				if(v>=oth) break;
			}
			(r[i]*=rev[cost[p]])%=mo;
		}
		
	}
	return (r[0]+r[1])%mo;
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	rev[1]=1;
	for(i=2;i<=201000;i++) rev[i] = rev[mo%i]*(mo-mo/i)%mo;
	
	cin>>N;
	FOR(i,2*N) {
		cin>>x>>y;
		E[x-1].push_back(y-1+N);
		E[y-1+N].push_back(x-1);
	}
	FOR(i,2*N) sort(ALL(E[i]));
	
	FOR(i,2*N) {
		if(E[i].size() && vis[i]==0) (ret*=hoge(i))%=mo;
		ret=ret*(1+i)%mo;
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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


int main() {
	ll n, m, x;
	cin >> n >> m >> x;
	vector<vector<int>> a(n, vector<int>(m + 1));
	rep(i, n)rep(j, m + 1) cin >> a[i][j];
	//入力
	int ans = INF;
	rep(bit, 1 << n) {
		int now = 0;
		vector<int> rikai(m);
		rep(i, n) {
			if (bit >> i & 1) {
				now += a[i][0];
				rep(j, m) {
					rikai[j] += a[i][j + 1];
				}
			}
		}
		bool ok = true;
		rep(i, m) {
			if (rikai[i] >= x) continue;
			ok = false;
		}
		if (ok) ans = min(ans, now);
	}
	if (ans == INF)cout << -1 << endl;
	else cout << ans << endl;
}



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

int main(){
  string s;
  cin >> s;
  string fs =s.substr(0,2);
  string ls =s.substr(2);
  
  bool yymm = false;
  bool mmyy = false;

  int f = atoi(fs.c_str());
  int l = atoi(ls.c_str());
  
  if(1 <= l && l <= 12)yymm = true;
  if(1 <= f && f <= 12)mmyy = true;
  
  if(yymm == true && mmyy == true)cout << "AMBIGUOUS" << endl;
  else if(yymm == true && mmyy == false)cout << "YYMM" << endl;
  else if(yymm == false && mmyy == true)cout << "MMYY" << endl;
  else if(yymm == false && mmyy == false)cout << "NA" << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n;
	string s[252];
	int t[252][252];
	cin>>n;
	REP(i, n){
		cin>>s[i];
		REP(j, n){
			t[i][j]=s[i][j]-'0';
		}
	}
	int ans=0;
	REP(x, n){
		queue<pii> q;
		q.push(pii(x, 1));
		int deg[252];
		int tmp=0;
		REP(i, n){
			deg[i]=-1;
		}
		while(q.size()){
			pii a=q.front();
			q.pop();
			if(deg[a.first]>0){
				continue;
			}
			deg[a.first]=tmp=a.second;
			REP(i, n){
				if(t[a.first][i]){
					if(deg[i]>0 && (deg[a.first]==deg[i] || abs(deg[a.first]-deg[i])>1)){
						cout<<-1<<'\n';
						return 0;
					}
					q.push(pii(i, a.second+1));
				}
			}
		}
		CHMAX(ans, tmp);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 740
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    string s, t;
    cin>>s>>t;
    int i, ans = 0;
    FOR0(i, 3) if(s[i] == t[i]) ans++;
    cout<<ans<<endl;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 256
S = input()
n = len(S)
mod = 10**9 + 7
pow10 = [1]
for i in range(1,n):
    x = pow10[-1]
    y = 10*x%13
    pow10.append(y)
dp = [[0 for i in range(13)]for j in range(n+1)]
dp[0][0] = 1
for i in range(n):
    d = S[-i-1]
    if d == '?':
        for j in range(10):
            s = (pow10[i]*j)%13
            for t in range(13):
                r = (s+t)%13
                dp[i+1][r] = (dp[i+1][r] + dp[i][t])%mod
    else:
        j = int(d)
        s = (pow10[i]*j)%13
        for t in range(13):
            r = (s+t)%13
            dp[i+1][r] = (dp[i+1][r] + dp[i][t])%mod
print(dp[n][5])


Measured memory_bytes: 68020
#include <cstdio>
#include <queue>
typedef long long LL;
typedef std::pair<LL,LL> P;
std::priority_queue<P> Q;
const int N=100005;
LL a[N],cnt[N],ans[N];
void add(int i,LL x,LL y){
	cnt[i]+=x/a[i]*y;
	if (x%a[i]) Q.push(P(x%a[i],y));
}
int main(){
	int n,m,q;
	scanf("%d%d\n",&n,&q);
	a[m=1]=n;
	for (int i=1;i<=q;i++){
		long long x;
		scanf("%lld",&x);
		for (;m && x<=a[m];m--);
		a[++m]=x;
	}
	cnt[m]=1;
	for (int i=m-1;i>=1;i--){
		for (;!Q.empty() && Q.top().first>=a[i];Q.pop()){
			P p=Q.top();
			add(i,p.first,p.second);
		}
		add(i,a[i+1],cnt[i+1]);
	}
	ans[a[1]]+=cnt[1];
	for (;!Q.empty();Q.pop())
		ans[Q.top().first]+=Q.top().second;
	for (int i=a[1];i;i--) ans[i]+=ans[i+1];
	for (int i=1;i<=n;i++) printf("%lld\n",ans[i]);
}

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

typedef long long ll;

int main()
{
	ll k, a, b, c;
  	cin >> a >> b >> c >> k;
  	if(a >= k)
    {
    	cout << k << endl;
    }
  	else if(a + b < k)
    {
    	cout << a - (k - a - b) << endl; 
    }
  	else if(a < k && a + b >= k)
    {
    	cout << a << endl;
    }
}


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

int main() {
  int cnt = 0;
  int K;
  string S;
  char c;
  cin >> S >> K;
  
  for(int i=0; i<S.length(); i++) {
    if(S[i] == '1') {
      cnt++;
    } else {
      c = S[i];
      break;
    }
  }

  if(K<=cnt){
    cout << 1 << endl;
  } else {
    cout << c << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
import sys
a = [list(map(int, input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]

for i in range(3):
    ans = True
    for j in range(3):
        if a[i][j] not in b:
            ans = False
    if ans:
        print("Yes")
        sys.exit()
for j in range(3):
    ans = True
    for i in range(3):
        if a[i][j]  not in b:
            ans = False
    if ans:
        print("Yes")
        sys.exit()
if all([a[0][0] in b, a[1][1] in b, a[2][2] in b]) or all([a[0][2] in b, a[1][1] in b, a[2][0] in b]):
    print("Yes")
    sys.exit()

print("No")


Measured memory_bytes: 3064
let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let snuke = Array.make n 1 in
  for i=1 to k do
    Scanf.scanf "%d\n" @@ fun d ->
    for j=1 to d do
      if j<d
      then Scanf.scanf " %d" @@ fun d -> snuke.(d-1) <- 0
      else Scanf.scanf " %d\n" @@ fun d -> snuke.(d-1) <- 0
    done
  done;
  Printf.printf "%d\n" @@
  Array.fold_right (+) snuke 0

Measured memory_bytes: 5884
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<iostream>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

ll gcd(ll a,ll b)
{
   if (a%b == 0) return(b);
   else return(gcd(b,a%b));
}

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

//累乗だってさ
ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}
//逆元だってさ
ll modinv(ll a,ll mod1) {
    return modpow(a, mod1 - 2, mod1);
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m;
    cin>>n>>m;
    cout<<(1900*m+100*(n-m))*modpow(2,m,mod)<<endl;
    return 0;
}


Measured memory_bytes: 256
# ABC 051 B
K, S = [int(x) for x in input().split()]
#print(K,S)#

count = 0
for x in range(K+1):
    for y in range(K+1):
        z = S-x-y
        if z>=0 and z<=K: 
            #print(x,y,z)#
            count += 1
print(count)

Measured memory_bytes: 3060
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        n: usize,
        k: usize,
        r: usize,
        s: usize,
        p: usize,
        mut t: Chars,
    }

    let mut point = 0;
    for i in 0..n {
        match t[i] {
            'r' => if i < k || t[i-k] != 'r' {
                 point+=p
                } else {
                    t[i] = ' ';
                },
            's' =>  if i < k || t[i-k] != 's' {
                 point+=r
                } else {
                    t[i] = ' ';
                },

            'p' => if i < k || t[i-k] != 'p' {
                 point+=s;
                } else {
                    t[i] = ' ';
                },
            _ => {}
        }
        //println!("point {}", point);
    }

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


Measured memory_bytes: 2576
#pragma GCC optimize("-O3")
#include<bits/stdc++.h>
using namespace std;
#define LocalTestAddress "test.txt"
//////////////////////////////////////////////////////////////////////////////
#define endl '\n'
void solve();
signed main(){
#ifdef Sprinkle
    clock_t clock_start=clock();assert(freopen(LocalTestAddress,"r",stdin));
#else
     ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#endif
    solve();
#ifdef Sprinkle
    cerr<<"Running Time: "<<((clock()-clock_start) *1.0 / CLOCKS_PER_SEC)<<"s\n";
#endif
    return 0;
}
#ifdef Sprinkle
void err(){cerr<<"\n";}template<typename T,typename...U>void err(const T&hd,const U&...tl){cerr<<hd<<(sizeof...(tl)?", ":"");err(tl...);}
#define debug(x...) cerr<<""#x" = ";err(x)
#else
#define debug(...) 0
#endif
//////////////////////////////////////////////////////////////////////////////

void solve(){
    int a,b;
    while(cin>>a>>b){
        cout<<a*b<<endl;
    }
}

Measured memory_bytes: 3608
/*input

*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vpii        vector< pii >
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int solve()
{
	ll n;cin>>n;
	double ans = 0.5;
	if((n%2)==1)
	{
		n/=2;
		ans = (double)(n+1)/(double)(2*n+1);
	} 
	cout<<ans<<"\n";
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	// cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 256
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
int main()
{
    vector < vector <int> > report;
    report.resize(12);
    for (int i=0; i<12; i++){
        report[i].resize(10);
        for (int j=0; j<10; j++){
            report[i][j] = 0;
        }
    }
    int n;
    std::cin >> n;
    
    int b, f, r, v;
    for (int i=0; i<n; i++){
        std::cin >> b >> f >> r >> v;
        report[3*(b-1) + (f-1)][r-1] += v; 
    }
    for (int i=0; i<12; i++){
        if(i == 3 || i == 6 || i == 9){
            std::cout << "####################" << endl;
        }
        for (int j=0; j<10; j++){
            if (j == 9){
                std::cout << " " << report[i][j] << endl;
            }
            else {
                std::cout << " " << report[i][j];
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3100
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long int LL;
LL x[100005];
LL y[100005][3];
vector<pair<int,int> > v1;
LL s[100005];
LL p[100005];
LL pn[100005];
queue<int> q1;

int parent(int a){
	int b,c;
	if(p[a]==-1){
		while(!q1.empty()){
			b=q1.front(),q1.pop();
			p[b]=a;
		}
		return a;
	}
	q1.push(a);
	return parent(p[a]);
}

int main(){
	int n,m;
	int i,j,k;
	LL a,b,c,d;
	LL ss=0;
	memset(p,-1,sizeof(p));
	cin>>n>>m;
	for(i=0;i<n;i++){
		cin>>x[i];
	}
	for(i=0;i<m;i++){
		cin>>y[i][0]>>y[i][1]>>y[i][2];
		y[i][0]--,y[i][1]--;
		v1.push_back(make_pair(y[i][2],i));
	}
	sort(v1.begin(),v1.end());
	for(i=0;i<m;i++){
		a=v1[i].first,b=v1[i].second;
		c=parent(y[b][0]),d=parent(y[b][1]);
		if(c==d){
			if(x[c]>=a)s[c]++;
			pn[c]++;
		}else{
			p[d]=c;
			s[c]+=s[d],s[d]=0;
			x[c]+=x[d],pn[c]+=pn[d]+1;
			if(x[c]>=a)s[c]=pn[c];
		}
	}
	for(i=0;i<n;i++){
		ss+=s[i];
	}
	ss=m-ss;
	cout<<ss<<endl;
	return 0;
}
			
	


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

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

	n = N % 10;
	switch (n) {
	case 0:
	case 1:
	case 6:
	case 8:
		cout << "pon" << endl;
		break;
	case 2:
	case 4:
	case 5:
	case 7:
	case 9:
		cout << "hon" << endl;
		break;
	case 3:
		cout << "bon" << endl;
		break;
	}

	return 0;
}

Measured memory_bytes: 3508
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int flow[310],path[310],map[310][310],maps[310][310],arsum[100010];
int start,end,n,m,sum;
int que[2][310],t[2],h[2];
int BFS(void)
{
    int node;
    t[0]=h[0]=0;
    que[0][t[0]++]=start;
    int i=1,j;
    memset(path,-1,sizeof(path));
    flow[start]=110;
    while(i)
    {
        //puts("2");
        h[i&1]=t[i&1]=0;
        while(h[(i-1)&1]<t[(i-1)&1])
        {
            node=que[(i-1)&1][h[(i-1)&1]++];
            for(j=1;j<=n;j++)
                if(j!=start&&map[node][j]>0&&path[j]==-1)
                {
                   // puts("3");
                    if(flow[node]<map[node][j]) flow[j]=flow[node];
                    else flow[j]=map[node][j];
                    path[j]=node;
                    que[i&1][t[i&1]++]=j;
                }
        }
        if(h[i&1]==t[i&1]||path[end]!=-1)
                break;
        i++;
    }
    //printf("%d\n",path[end]);
    if(path[end]==-1)
            return -1;
    return flow[end];
}
int EK(void)
{
    int temp,ans=0,pre,d;
    while((temp=BFS())!=-1)
    {
       // puts("1");
        ans+=temp;
        d=end;
        pre=path[d];
        if(maps[pre][d])arsum[sum++]=maps[pre][d];
        while(d!=start)
        {
            map[pre][d]-=temp;
            map[d][pre]+=temp;
            d=pre,pre=path[d];
            if(maps[pre][d])arsum[sum++]=maps[pre][d];
        }
    }
    return ans;
}
int main()
{
    int i,a,b;

    while(scanf("%d%d",&n,&m)!=EOF)
    {
        memset(map,0,sizeof(map));
        memset(maps,0,sizeof(maps));
        for(i=1;i<=m;i++)
        {
            scanf("%d%d",&a,&b);
            maps[b][a]=i;
            map[a][b]=1;
            map[b][a]=1;
        }
        scanf("%d%d",&start,&end);
        sum=0;
        printf("%d\n",EK());
        sort(arsum,arsum+sum);
        printf("%d\n",sum);
        for(i=0;i<sum;i++)
            if(i==0)
                printf("%d\n",arsum[i]);
            else if(arsum[i]!=arsum[i-1])
                printf("%d\n",arsum[i]);
    }
    return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main() {
	int n, c[27] = {0}, c1[27] = {0};
	scanf ("%d", &n);
	char s[n+1];
	scanf ("%s", &s);
	
	for (int i = 0; i < n/2; i++) {
		if (s[i] >= 'a' && s[i] <= 'z') {
			c[s[i] - 97]++;
		}
	}
	
	for (int i = n / 2; i < n + 1; i++) {
		if (s[i] >= 'a' && s[i] <= 'z') {
			c1[s[i] - 97]++;
		}
	}
	
	int flag = 1;
	for (int i = 0; i <= 26; i++) {
		if (c[i] == c1[i]) {
			//printf ("theres a match at %d\n", i);
			flag = 1;
		}
		else if (c[i] != c1[i]) {
			//printf ("Theres no mactch at %d", i);
			 flag = 0;
			 break;
		}
	}
	//printf ("the flag is %d\n", flag);
	flag == 1 ? printf ("Yes\n") : printf ("No\n");
	return 0;
}

Measured memory_bytes: 1632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,a,b;
    cin>>x>>a>>b;
    if(fabs(x-a)<fabs(x-b))
    {
        cout<<"A"<<endl;
    }
    else
    {
        cout<<"B"<<endl;
    }
}


Measured memory_bytes: 256
n, m = map(int,input().split())
sc = []
for i in range(m):
    sc.append(list(map(int,input().split())))

# 条件の整理
cnt = [0]*4
for i in range(m):
    cnt[sc[i][0]] += 1
    # 最上位桁が0
    # if sc[i][0] == 1 and sc[i][0] == 0 and n > 1:
    #     print(-1)
    #     exit()
    # 同じ桁に違う数字指定
    if cnt[sc[i][0]] > 1:
        
        val = []
        
        for j in range(m):
            if sc[j][0] == sc[i][0]:
                val.append(sc[j][1])
        
        if len(list(set(val))) > 1:
            print(-1)
            exit()


# 全探索
ans = []
for i in range(1000):
    if len(str(i)) == n:
        flg = True
        for j in range(m):
            digit = sc[j][0]
            val = sc[j][1]
            if int(str(i)[digit-1]) != val:
                flg = False
                break
        if flg == True:
            ans.append(i)

if len(ans) == 0:
    print(-1)
    exit()
print(min(ans))

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main()
{
	int n,i,ans=1,p;
	
	cin >> n;
	
	for(i=2;n!=1;i++)
	{
		if(i>sqrt(n))
		{
			ans*=(n-1);
			n=1;
			continue;
		}
		p=1;
		while(n%i==0)
		{
			p*=i;
			n/=i;
		}
		if(p>1) ans*=(p-p/i);
	}
	cout << ans << endl;
	
	return 0;
}

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

int main() {
  long x,k,d;
  cin >> x >> k >> d;
  x=max(x,-x);
  if((x+d-1)/d>k) {
    cout << x-k*d << endl;
  } else {
    if((k-(x+d-1)/d)%2==0) {
      cout << -(x-((x+d-1)/d)*d) << endl;
    } else {
      cout << x-((x+d-1)/d-1)*d << endl;
    }
  }
}

Measured memory_bytes: 3632
#include <stdio.h>

int main() {
char a;
char ch[120];
char c[120];
char b[120];
int i,j,k,l,m,n,o;
m = 0;
n = 0;
i=0;
l=0;

while(1) {
scanf("%c",&a);

if(a == '\n') {
 break;
}

ch[i] = a;
i=i+1;

}

j=0;
while(1) {
scanf("%c",&a);
if(a == '\n') {
break;
}
c[j] = a;
j +=1;
}
/*??????????????§??\??????*/

for(k=0;k<i;k++) {

if(c[0] == ch[k] ) {       /*???????????????????????¨?????????????????? */
 l = k;
n = 0;                         /* ??????????????´???????????????*/
for(m=0;m<i-k;m++) {         /* c[k]????????????????§????????????? */
n = n +1;
l  +=1;
b[m] = ch[l-1];
}
l=0;
for(m=n;m<n+1+k;m++) {
l +=1;
b[m] = ch[l-1];            
}
o=0;
for(n=0;n<j;n++) {
/*printf("b[%d] = %c\n c[%d] = %c\n",n,b[n],n,c[n]); */
if(b[n] == c[n]){
o +=1;
}
}
}

/* printf("i = %d\nj = %d\n",i,j); */


if(o == j) {
printf("Yes\n");
break;
} else if(k==i-1) {
printf("No\n");
}
}
 
return 0;

}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  vector<int> S(1010,0);
  for(int i=0; i<=1000; i++){
    S[i+1] = S[i] + i;
  }
  int N;
  cin >> N;
  while(N != 0){
    int cnt = 0;
    for(int i=1; i<=1000; i++){
      for(int j=i+1; j<=1000; j++){
        if(S[j+1]-S[i] == N) cnt++;
      }
    }
    cout << cnt << endl;
    cin >> N;
  }
  return 0;
}



Measured memory_bytes: 3124
from collections import deque
n=int(input())
graph=[[False for j in range(n)] for i in range(n)]
for i in range(n):
    s=input()
    for j in range(n):
        if s[j]=="1":
            graph[i][j]=True
L=0
def bfs(i):
    longest=0
    global dist
    dist=[-1]*n
    dist[i]=0
    D=deque([i])
    while D:
        v=D.popleft()
        for j in range(n):
            if graph[v][j]==False:continue
            if dist[j]!=-1:
                if abs(dist[v]-dist[j])==1:continue
                else:return -1
            else:
                D.append(j)
                dist[j]=dist[v]+1
                if dist[j]>longest:longest=dist[j]
    return longest
for i in range(n):
    A=bfs(i)
    
    if A==-1:print(-1);exit()
    if A>L:L=A
print(L+1)


Measured memory_bytes: 43632
A,B,C,D=map(int,input().split(" "))
if A<1 or B<A or B >10**18 or C<1 or  D > 10**9:
	print ('Illegal')
else:
	a,b=C,D
	if a < b:
		a, b = b, a
	while a % b != 0:
		a, b = b, a % b
	t=int(C*D/b)
	n=B-A+1-(B//C-(A-1)//C)-(B//D-(A-1)//D)+(B//t-(A-1)//t)
	print(n)


Measured memory_bytes: 3064
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007




h, w, k = LI()
fib_list = [1] * w
for i in range(2, w):
    fib_list[i] = fib_list[i - 1] + fib_list[i - 2]


dp = [[0] * w for _ in range(h + 1)]
dp[0][0] = 1
for i in range(h):
    for j in range(w):
        # そのまま行くパターン
        dp[i + 1][j] = (dp[i + 1][j] + dp[i][j] * fib_list[j] * fib_list[w - j - 1] % mod) % mod
        if j < w - 1:
            # 配るdp
            # 右側に配る
            dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j] * fib_list[j] * fib_list[w - j - 2] % mod) % mod
        if j > 0:
            # 左側に配る
            dp[i + 1][j - 1] = (dp[i + 1][j - 1] + dp[i][j] * fib_list[j - 1] * fib_list[w - j - 1] % mod) % mod




print(dp[-1][k - 1])


Measured memory_bytes: 39920
#include <stdio.h>
#include <stdbool.h>

int main() {
	int i, j, n;
	scanf("%d", &n);
	if (n == 2) {
		int a, b;
		scanf("%d%d", &a, &b);
		for (i=1; i < a ;i++) {
			if (a%i+b%i == 0) printf("%d\n", i);
		}
	} else if (n == 3) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		for (i=1; i < a ;i++) {
			if (a%i+b%i+c%i == 0) printf("%d\n", i);
		}
	}
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <unordered_map>
#include <algorithm>
typedef long long ll;
using namespace std;

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

    unordered_map<string,int> mp;

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

    ll ans = 0;

    for(auto& p: mp){
        int s = p.second;
        ans += (ll)s*(s-1)/2;
    }

    cout << ans;
}

Measured memory_bytes: 10660
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0LL);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }



int main() {
	ll n, k;
	cin >> n >> k;
	ll ans = 0;
	FOR(x2, k, n + 2) {
		ll x = x2;
		ll max = (2 * n - x + 1) * x / 2;
		max;
		ll min = (x * (x - 1)) / 2;
		min;
		ans += max - min + 1;
		ans %= MOD;
	}
	cout << ans << endl;
}




Measured memory_bytes: 3652
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */

int a[1000];

int main(void)
{
    int n;
    double ans;

    scanf("%d",&n);

    for(int i=0;i<n;i++) scanf("%d",&(a[i]));
    ans = 0;
    for(int i=0;i<n;i++) ans += ((double)1/(double)a[i]);
    printf("%g\n", (double)1/ans);
    
    return 0;
}




Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n;
  int r,k,t;
  int p;
  int s,d,b;
  int ans=0;
  int box[111][111];
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      box[i][j]=(1<<21);
    }
  }
  for(int i=0;i<n;i++){
    cin >> r >> k;
    for(int j=0;j<k;j++){
      cin >> t;
      box[r-1][t-1]=1;
    }
  }
  for(int z=0;z<n;z++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	box[i][j]=min(box[i][j],box[i][z]+box[z][j]);
      }
    }
  }
  cin >> p;
  for(int i=0;i<p;i++){
    cin >> s >> d >> b;
    ans=box[s-1][d-1]+1;
    if(ans<=b){
      cout << box[s-1][d-1]+1 << endl;
    }else{
      cout << "NA" << endl;
    }
  }
}

Measured memory_bytes: 1212
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		while(true){

			int num = in.nextInt();
			int sum = in.nextInt();
			int count = 0;

			if(num == 0 && sum == 0){

				break;

			}else{

				for(int f = 1; f <= (num-2); f++){

					for(int s = f; s <= (num-2); s++){

						for(int t = s; t <= (num-2); t++){

							int S = s+1;
							int T = t+2;

							String c = f + "+" + S + "+" + T + "+";

							if(f + S + T == sum){

								count++;

						}
					}


					}
				}

				System.out.println(count);
			}
		}
	}
}

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

namespace AtCoderCs
{
    class Program
    {
        static void Main()
        {

            var Len = Console.ReadLine().Split(' ').ToArray();
            Console.WriteLine(Len[2] + " " + Len[0] + " " + Len[1]);

        }

    }
}


Measured memory_bytes: 13268
n,x,y = map(int,input().split())
 
def dist(i,j):
  return min(j - i, abs(x - i) + abs(y - j) + 1)
 
listlist = [0]*(n-1)
 
for i in range(1,n):
    for j in range(i + 1, n + 1):
        distance = dist(i,j)
        listlist[distance-1] = listlist[distance-1] + 1
    
for k in listlist:
  print(k)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x,h,w) (y) < 0 || (h) <= (y) || (x) < 0 || (w) <= (x)
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int n; cin >> n;
    VL a(n); cin >> a;

    int av = 0;
    FOR(i, 0, n)if (abs(a[i]) > abs(a[av]))av = i;

    vector<pair<int, int>> ans;
    if (0 < a[av]) {
        FOR(i, 1, n) {
            while (a[i - 1] > a[i]) {
                a[i] += a[av];
                ans.push_back({ av + 1,i + 1 });
            }
            if (a[av] < a[i])av = i;
        }
    }
    else if (a[av] < 0) {
        rFOR(i, 1, n) {
            while (a[i - 1] > a[i]) {
                a[i - 1] += a[av];
                ans.push_back({ av + 1,i });
            }
            if (a[i - 1] < a[av])av = i - 1;
        }
    }

    cout << ans.size() << "\n";
    FOR(i, 0, ans.size())cout << ans[i].first << " " << ans[i].second << "\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>

using namespace std;

#define LL long long
#define mod 998244353
const int N = 3e5+10;

LL a,b,n,k,inv[N],ans;

inline LL fast_pow(LL a,LL b,LL p) {
	LL ans = 1;
	while(b) {
		if(b & 1) ans = ans * a % p;
		a = a * a % p;
		b >>= 1;
	}
	return ans % p;
}
inline LL calc(LL a,LL b) {
	return inv[b] * fast_pow(inv[b - a],mod - 2,mod) % mod * fast_pow(inv[a],mod - 2,mod) % mod;
}
void init() {
	inv[0] = 1;
	for(int i = 1 ; i <= N ; i++)
		inv[i] = inv[i - 1] * i % mod;
}

int main() {
	init();
	scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
	//cout<<ans<<endl;
	ans = 0;
	for(int i = 0 ; i <= n ; i++) {
		if(k - i * a < 0) break;
		if((k - i * a) % b == 0) { //j must be an integer
			LL j = (k - i * a) / b;
		//	if(j > n) continue;
			if(j <= n) {
				ans += calc(i,n) * calc(j,n) % mod;
				ans %= mod;
			}
			
		}
	}
	printf("%lld \n",ans);
	return 0;
}

Measured memory_bytes: 2560
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
using namespace std;

const int maxn = 100005;
typedef long long ll;

vector<ll> v;

int n,q;

ll cnt[maxn];

ll sum[maxn];

void fly(ll x,ll ti)
{
    if(!x)
        return ;
    int p = upper_bound(v.begin(),v.end(),x)-v.begin();
    if(!p)
    {
        sum[x]+=ti;
    }
    else
    {
        cnt[p-1]+=x/v[p-1]*ti;
        fly(x%v[p-1],ti);
    }
}
int main()
{
    ll x;
    scanf("%d%d",&n,&q);
    v.push_back(n);
    for(int i=0;i<q;i++)
    {
        scanf("%lld",&x);
        while(v.size()&&v.back()>=x)
            v.pop_back();
        v.push_back(x);
    }
    cnt[v.size()-1] = 1;
    for(int i=v.size()-1;i>0;i--)
    {
        ll ti = v[i]/v[i-1]*cnt[i];
        cnt[i-1]+=ti;
        fly(v[i]%v[i-1],cnt[i]);
    }
    sum[v[0]] = cnt[0];
    for(int i=v[0];i>=1;i--)
        sum[i]+=sum[i+1];
    for(int i=1;i<=n;i++)
        printf("%lld\n",sum[i]);
}


Measured memory_bytes: 4212
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    N, M, *a = map(int, read().split())
    A = set()
    P = (10**9)+7
    for i in a:
        A.add(i)

    dp = [0 for _ in range(N+1)]
    dp[0] = 1

    if not (1 in A):
        dp[1] = 1
        

    for i in range(2, N+1):
        if i in A:
            continue
        else:
            dp[i] = (dp[i-1] + dp[i-2])%P
    print(dp[N])
if __name__ == '__main__':
    main()


Measured memory_bytes: 14164
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    int n = s.size();

    rep(i, n) {
        rep(j, n-i+1) {

            string x = s.substr(0, i);

            string y;
            if(j == n-i) {
                y = "";
            }
            else {
                y = s.substr(i+j, n-(i+j));
            }

            if(x + y == "keyence") {
                cout << "YES" << endl;
                return 0;
            }
            
        }
    }

    cout << "NO" << endl;
    return 0;
}

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

int main()
{
    long double w, h, x, y;
    cin >> w >> h >> x >> y;
    long double ma_x, ma_y, mi_x, mi_y;

    if (x == w / 2 && y == h / 2)
    {
        long double ans;
        ans = h / 2 * w;
        cout << fixed << setprecision(10) << ans << " " << 1;
        return 0;
    }
    else
    {
        long double ans;
        ans = h / 2 * w;
        cout << fixed << setprecision(10) << ans << " " << 0;
        return 0;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){

  char S[20];
  int count=0;
  int max=0;
  int len=0;
  
  scanf("%s",S);
  len=strlen(S);
  
  for(int i=0;i<len;i++){
  	 if(S[i]=='A' || S[i]=='C' || S[i]=='G' || S[i]=='T'){
  		count++;
        if(count>max){
        	max=count;
        }
     }else{
     	count=0;
     }
  }

  printf("%d",max);
  
 return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9 + 5;
const ll MOD = 1e9 + 7;

const int MAXN = 2e3 + 5;

vector<pii> g[MAXN];

vector<pair<int, pii> > ee;

int add_w[MAXN];

int mx[MAXN];
void dfs(int s) {
	REP(i, 0, SZ(g[s])) {
		int to = g[s][i]._1, d = g[s][i]._2;
		int new_val = max(d, mx[s]);
		if (mx[to] > new_val) {
			mx[to] = new_val;
			dfs(to);
		}
	}
}

void solve(){
	int n, m;
	ll x;
	scanf("%d%d%lld", &n, &m, &x);
	REP(i, 0, m) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		ee.pb(mp(c, mp(a, b)));
	}
	SORT(ee);
	ll mst_weight = 0;
	for(int i = 0, j = 0; i < SZ(ee); ) {
		int c = ee[i]._1;
		for(; j < SZ(ee) && ee[j]._1 == c; j++);
		for(; i < j; i++) {
			int a = ee[i]._2._1;
			int b = ee[i]._2._2;
			REPN(k, 1, n) {
				mx[k] = INF;
			}
			mx[a] = 0;
			dfs(a);
			if (mx[b] != INF) {
				add_w[i] = mx[b];
			} else {
				add_w[i] = c;
				mst_weight += c;
				g[a].pb(mp(b, c));
				g[b].pb(mp(a, c));
			}
		}
	}
	
	int cnt_mst = 0;
	REP(i, 0, SZ(ee)) {
		if (add_w[i] == ee[i]._1) {
			cnt_mst++;
		}
	}
	
	if (mst_weight > x) {
		printf("0\n");
		return;
	} else if (mst_weight == x) {
		ll ans = 1ll;
		REP(i, 0, cnt_mst) {
			ans = (ans * 2) % MOD;
		}
		ans = (ans + MOD - 2) % MOD;
		REP(i, cnt_mst, SZ(ee)) {
			ans = (ans * 2) % MOD;
		}
		cout << ans << endl;
		return;
	} else {
		ll ans = 2ll;
		ll mul = 1ll;
		REP(i, 0, SZ(ee)) {
			if (add_w[i] != ee[i]._1) {
				if (ee[i]._1 - add_w[i] == x - mst_weight) {
					mul = (mul * 2) % MOD;
				} else if (ee[i]._1 - add_w[i] > x - mst_weight) {
					ans = (ans * 2) % MOD;
				}
			}
		}
		mul = (mul + MOD - 1) % MOD;
		ans = (ans * mul) % MOD;
		cout << ans << endl;
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;

int main() {
    int n,k;
    string s;
    cin >> n >> k >> s;
    int l = 0,r = -1;
    int sum = 0;
    bool cont = false;
    while(true) {
        if(r == n-1) break;
        if(s[r+1] == '1') {
            r++;
            cont = false;
        } else {
            if(cont) r++;
            else {
                cont = true;
                if(sum < k) {
                    r++;
                    sum++;
                } else break;
            }
        }
    }
    int ans = r+1;
    rep2(i,1,n) {
        l = i;
        if(s[i-1] == '0' && s[i] == '1') {
            sum--;
            cont = false;
            while(true) {
                if(r == n-1) break;
                if(s[r+1] == '1') {
                    r++;
                    cont = false;
                } else {
                    if(cont) r++;
                    else {
                        cont = true;
                        if(sum < k) {
                            r++;
                            sum++;
                        } else break;
                    }
                }
            }
        }
        chmax(ans,r-l+1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
S = input()
cp = 0
cg = 0
point = 0
for s in S:
    if s == 'g':
        if cp + 1 <= cg:
            point += 1
            cp += 1
        else:
            cg += 1
    else:
        if cp + 1 <= cg:
            cp += 1
        else:
            point -= 1
            cg += 1
print(point)


Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
 
int n, m, cnt;
int data[22];
int memo[22][50001];
 
int solve(int i, int p){
 
  if(!p) return 0;
  if(p < 0 || i == m) return 1<<28;
  if(memo[i][p]) return memo[i][p];
   
  int ans = 0;
  return memo[i][p] = ans += min(solve(i+1, p), solve(i, p-data[i])+1);
 
}
 
int main(){
 
  cin >> n >> m;
  for(int i=0;i<m;i++) cin >> data[i];
  cout << solve(0, n) << endl;
 
}

Measured memory_bytes: 7596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int tmp = 1;

			int result = 0;
			while(tmp < b) {
				tmp += a - 1;
				result++;
			}

			System.out.println(result);
		}
	}
}


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

int main(){
  double a,b,x;
  cin >> a >> b >> x;
  x = x/a;
  if(2*x >= a*b){
    printf("%.10f", atan(2*(a*b-x)/(a*a))*180/M_PI); 
  } else {
    printf("%.10f", 90-atan((2*x)/(b*b))*180/M_PI); 
  }
  }

Measured memory_bytes: 256