akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define mm(a,x) memset(a,x,sizeof(a))
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0)
#define ll long long
using namespace std;
const int N=2e5+10;
const ll mod=1e9+7;
int a[N];
ll pre[N];
int main(void)
{
    sync;
    int n;
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        cin>>a[i];
        pre[i]=(pre[i-1]+a[i])%mod;
    }
    ll res=0;
    for(int i=1;i<=n;++i)
        res=(res+a[i]*(pre[n]-pre[i]+mod)%mod)%mod;
    cout<<res<<endl;
    return 0;
}

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

using namespace std;
#define eps = (1e-10);
//点
struct Point{
    double x,y;
    Point(double _x=0,double _y=0):x(_x),y(_y){}
    Point operator + (Point p){return Point(x+p.x,y+p.y);}
    Point operator - (Point p){return Point(x-p.x,y-p.y);}
    Point operator * (double a){return Point(a*x,a*y);}
    Point operator / (double a){return Point(x/a,y/a);}
    double norm(){return x*x+y*y;}//模的平方
    double ABS() {return sqrt(norm());}//模
};
//线段
struct Segment{
    Point p1,p2;
};
//点积
double dot(Point a,Point b){
    return a.x*b.x+a.y*b.y;
}
//叉积
double cross(Point a,Point b){
    return a.x*b.y-a.y*b.x;
}
//p关于s的对称点
Point Reflection(Point p,Segment s){
    Point p1=s.p1;Point p2=s.p2;
    double A=(p1.y-p2.y);
    double B=-(p1.x-p2.x);
    double C=(p1.x-p2.x)*p1.y-p1.x*A;
    return {((B*B-A*A)*p.x-2*A*B*p.y-2*A*C)/(A*A+B*B),((A*A-B*B)*p.y-2*A*B*p.x-2*B*C)/(A*A+B*B)};
}
int main(){
    double x1,y1,x2,y2;
    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
    Point p1={x1,y1};Point p2={x2,y2};
    Segment s={p1,p2};
    int T;scanf("%d",&T);
    double x,y;
    while(T--){
        scanf("%lf %lf",&x,&y);
        Point p={x,y};
        Point ans=Reflection(p,s);
        printf("%.11lf %.11lf\n",ans.x,ans.y);
    }
    return 0;
}


Measured memory_bytes: 3228
def main():
    MOD = 10 ** 9 + 7
    L = input()
    a, b = 0, 1
    for i in L:
        if i == '1':
            a, b = (b + a * 2) % MOD, b * 3 % MOD
        else:
            a, b = (a * 3) % MOD, (b + a * 2) % MOD
    return b

print(main())


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

#define MP make_pair
#define FF first
#define SS second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pie;
const int MOD = 1e9 + 7;
const int INF = 2e9;
const ll LINF = 4e18;
const ll delta = 96181;

ll cnt[30], ans = 1, n;
string s;

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> s;
	for (int i = 0; i < n; i++)
		cnt[s[i] - 'a']++;
	for (int i = 0; i < 30; i++)
		ans = (ans * (cnt[i] + 1)) % MOD;
	cout << (ans - 1 + MOD) % MOD << endl;
}



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

// Define
using ll = int64_t;
using ul = uint64_t;
using ld = long double;
using pii = pair<int, int>;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ul MAX = ULONG_MAX;
const char nl = '\n';

#define elif else if
#define def inline auto
#define run __attribute__((constructor)) def _

// Debug
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i < _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i > _##i; --i)
#define rep(i, n) inc(i, 0, n)
#define be(c) begin(c), end(c)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")

// Math
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

struct UnionFind {
  vector<int> parent; // parent[root] is the negative of the size.
  UnionFind(int n) : parent(n, -1) { };
  bool unite(int u, int v) {
    u = root(u); v = root(v);
    if (u == v) return false;
    // 負の値同士の比較 小さいほうがランクが高い
    if (parent[u] > parent[v]) swap(u, v);
    parent[u] += parent[v]; parent[v] = u;
    return true;
  }
  bool find(int u, int v) { return root(u) == root(v); }
  int root(int u) { return parent[u] < 0 ? u : parent[u] = root(parent[u]); }
  // ランク
  int size(int u) { return -parent[root(u)]; }
};

signed main(){
    int N, M;
    cin >> N >> M;
    vector<int> ps(N);
    UnionFind cs(N);
    rep(i, N) {
        cin >> ps[i];
    }
    rep(i, M) {
        int x, y;
        cin >> x >> y;
        cs.unite(x-1, y-1);
    }

    int ans = 0;
    rep(i, N) {
        if(cs.find(i, ps[i]-1)) ++ans;
    }
    cout << ans << nl;
}


Measured memory_bytes: 1024
// abc.052 C - Factors of Factorial

//方針：互除法で素数を1000まで求める。素数の配列を作成、バケット法で集めてあとは計算途中に割り算
// Nは1000まで、N!の約数の個数を10^9+7で割る

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

#define MOD 1000000007

int main( void ) {

    int n;
    cin >> n;
    int         root_n = sqrt( n );
    vector<int> prime( n + 1, 1 );

    //配列を入力
    for( int i = 2; i <= n; i++ ) { //階乗
        int x = i;
        int j = 2;
        while( x ) {
            if( x == 1 ) break;

            if( x % j == 0 ) {
                prime.at( j )++;
                x /= j;
                continue;
            }

            j++;
        }
    }
    long long ans = 1;
    for( int i = 2; i <= n; i++ ) {
        if( prime.at( i ) == 1 ) continue;
        ans = ans * prime.at( i ) % MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define itn int
#define gI gi

using namespace std;

typedef long long ll;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline ll gl()
{
	ll f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

int n, m, a[100003];
char s[100003];

int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	n = gi(), m = gi();
	if (n > m) swap(n, m);
	for (int i = 1; i <= m; i+=1) cout << n;
	cout << endl;
	return 0;
}

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

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////


int main() {
   ll X,t;
   cin >>X>>t;
   cout <<max(X-t,0);
}


Measured memory_bytes: 256
#include<cstdio>

int solve(){
  int r,c;
  scanf("%d %d",&r,&c);
  if(r==0&&c==0) return 1;
  int senbei[r][c];
  for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
      scanf("%d",&senbei[i][j]);
    }
  }
  int ans = 0;
  for(int i=0;i<1<<r;i++){
    int x = 0;
    for(int j=0;j<c;j++){
      int t = 0;
      for(int k=0;k<r;k++){
        if(senbei[k][j]==(i>>k)%2) t++;
      }
      if(t<r-t) t = r-t;
      x+=t;
    }
    if(ans<x) ans = x;
  }
  printf("%d\n",ans);
  return 0;
}

int main(){
  while(true) if(solve()) return 0;
}

Measured memory_bytes: 2968
using Atcoder;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            Console.WriteLine(N * N * N);
        }
        //static void Main(string[] args)
        //{
        //    var temp = new Atcoder.ABC130.D();
        //    temp.Run();
        //}

    }
}

Measured memory_bytes: 11092
N = int(input())
S = input()

ans = ''
Z_s = 'Z'
for i in range(len(S)):
    ord_s = ord(S[i]) + N
    if ord_s > ord(Z_s):
        ord_s -= ord('Z') - ord('A') + 1
    ans += chr(ord_s)
print(ans)

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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

vector<VI> G;

int dp[100005][3];

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int N, M;
    cin >> N >> M;
    G.assign(N + 3, VI());
    REP(i, M) {
        int x, y;
        cin >> x >> y;
        G[x].pb(y);
    }
    memset(dp, -1, sizeof(dp));
    int s, t;
    cin >> s >> t;
    queue<PII> Q;
    Q.push({s, 0});
    dp[s][0] = 0;
    while (!Q.empty()) {
        auto p = Q.front();
        Q.pop();
        if (p.first == t && p.second == 0) {
            cout << dp[t][0] / 3 << "\n";
            return 0;
        }
        for (int v : G[p.first]) {
            if (dp[v][(p.second + 1) % 3] == -1) {
                dp[v][(p.second + 1) % 3] = dp[p.first][p.second] + 1;
                Q.push({v, (p.second + 1) % 3});
            }
        }
    }
    cout << "-1\n";
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define rep(i,x) for(long long i=1;i<=x; i++)
typedef long long  ll;
using namespace std;
int main(){
	ll ans=0,N=0;
  
  cin>>N;
  rep(i,N){

    if(i%3==0 || i%5==0){
    	
    }else{
    	ans+=i;
    }
  }
   if(N==1){
   	cout<<1;
   }else{
  cout<<ans;
   }
}

Measured memory_bytes: 3620
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ


int main(){
	int a,b;scanf("%d%d",&a,&b);
	printf("%d\n",a/(2*b+1)+!!(a%(2*b+1)));
}

Measured memory_bytes: 128
//By Tushar Gautam
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define leadzero(a) __builtin_clz(a) // count leading zeroes
#define trailzero(a) __builtin_ctz(a) // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln "\n"
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long int  ll;
typedef long double  ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM = 1e5+5, MOD = 1e9+7;
int t,n,m,k,x,y;
int a[22][22];
vv64 dp;
int lim;
ll solve(int i,int mask){
	if(i==n) return mask==lim;
	if(dp[i][mask]!=-1) return dp[i][mask];
	ll c=0;
	forn(j,n){
		if(a[i][j] && ((mask&(1<<j))==0)){
			c+=solve(i+1,mask|(1<<j));
		}
	}
	return dp[i][mask]=c%MOD;
}
int main(){
	fastio;
	cin>>n;
	forn(i,n){
		forn(j,n){
			cin>>a[i][j];
		}
	}
	lim = (1<<n)-1;
	dp.assign(n,v64(lim,-1));
	cout << solve(0,0) << ln;
	return 0;
}

Measured memory_bytes: 360832
#include <stdio.h>

int main(void){
	int n, k, s[100], b, i, j, ans;
	while(1){
		scanf("%d %d", &n, &k);
		if(n == k && n == 0) break;
		for(i = 0; i < k; i++) scanf("%d", &s[i]);
		ans = 1;
		for(i = 0; i < n; i++){
			for(j = 0; j < k; j++){
				scanf("%d", &b);
				s[j] -= b;
				if(s[j] < 0){
					ans = 0;
				}
			}
		}
		if(ans == 1) printf("Yes\n");
		else if(ans == 0)printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long

LL GCD(LL x ,LL y){//最大公約数
	LL r;
	while(r=x%y){
		x=y;
		y=r;
	}
	return y;
}

LL LCM(LL x,LL y){
	return (x*y/GCD(x,y));
}

int cnter(int a, int m){
	int t=0;
	int x=1;
	while(true){
		t++;
		x=a*x%m;
		if(x==1)break;
	}
	return t;
}

int main(){
	int a1,m1,a2,m2,a3,m3;
	while(cin>>a1>>m1>>a2>>m2>>a3>>m3){
		if(a1==0)break;
		int t1=cnter(a1,m1),t2=cnter(a2,m2),t3=cnter(a3,m3);
		cout<<LCM(LCM(t1,t2),t3)<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,m;
  cin >> n >> m;
  string s[n];
  rep(i,n) R s[i];
  int d[n][m];
  rep(i,n)rep(j,m) d[i][j]=MAX;
  d[0][0]=1;
  queue<P> que;
  que.push(P(0,0));
  while(!que.empty()) {
    P p=que.front();que.pop();
    int x=p.F,y=p.S;
    rep(i,4) {
      int xx=x+dx[i],yy=y+dy[i];
      if(!check(n,m,xx,yy)||d[xx][yy]<=d[x][y]+1||s[xx][yy]=='#') continue;
      d[xx][yy]=d[x][y]+1;
      que.push(P(xx,yy));
    }
  }
  if(d[n-1][m-1]==MAX) pr(-1);
  else {
    int cnt=n*m;
    rep(i,n)rep(j,m) {
      if(s[i][j]=='#') cnt--;
    }
    pr(cnt-d[n-1][m-1]);
  }
}

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


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

using namespace std;

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree < int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update >
#define smallk order_of_key
#define kth find_by_order
*/

#define nl '\n'
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb push_back

typedef long long ll;

const int N = (int)1e5 + 123;
const int M = 1e9 + 7;
const int K = 500;

int n;
double a[3003];
double dp[3003][3003];
int main(){

    //ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

    #ifdef LOCAL
        freopen("B.txt", "r", stdin);
    #endif // LOCAL

    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    dp[0][0] = 1;
    for(int i = 1; i <= n; ++i){
        double h = a[i], t = 1 - a[i];
        dp[0][i] = t * dp[0][i - 1];
        for(int j = 1; j <= i; ++j){
            dp[j][i] = h * dp[j - 1][i - 1] + t * dp[j][i - 1];
        }
    }
    double ans = 0;
    for(int i = n / 2 + 1; i <= n; ++i){
        ans += dp[i][n];
    }
    cout << fixed << setprecision(9) << ans;
    return 0;
}



Measured memory_bytes: 70016
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int32_t main()
{
	IOS;
	int l, r, d;
	cin >> l >> r >> d;
	int ans = r / d - (l - 1) / d;
	cout << ans;
	return 0;
}

Measured memory_bytes: 3648
import collections
N = int(input())
S = input()

c = collections.Counter(S)
R = c['R']
G = c['G']
B = c['B']
ans = R*G*B
delans = 0
for i in range(1,N-1):
    for l in range(min(i,N-i-1)):
        if S[i]!=S[i-l-1] and S[i]!=S[i+l+1] and S[i-l-1]!=S[i+l+1]:
            delans += 1
ans -= delans
print(ans)

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

int N;
vector<vector<int> > G;
vector<ll> dp[2];//dp[0]:black,dp[1]:white
vector<bool> used;

void dfs(int n,int par=-1){
    if(used[n]){
        return;
    }
    used[n]=true;
    int child = 0;
    ll &black = dp[0][n],&white = dp[1][n];
    black=1,white=1;
    for(auto nv : G[n]){
        if(nv==par){
            continue;
        }
        child++;
        dfs(nv,n);
        ll &nblack = dp[0][nv],&nwhite = dp[1][nv];
        black *= nwhite;
        black %= MOD;
        white *= (nblack+nwhite);
        white%=MOD;
    }
//    cout<<"dfs:"<<n<<" ";
//    cout<<"black:"<<black<<" white:"<<white<<endl;
    return;
}

int main(){
    cin>>N;
    G.resize(N);
    dp[0].resize(N,-1);
    dp[1].resize(N,-1);
    used.resize(N,false);
    rep(i,N-1){
        int a,b;
        cin>>a>>b;
        a--,b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(0);
    cout<<(dp[0][0]+dp[1][0])%MOD<<endl;
}



Measured memory_bytes: 14208
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {

		Scanner sc= new Scanner(System.in);
		double r = sc.nextDouble();
		double e = 2 * r * Math.PI;
		double m = r * r * Math.PI;

		System.out.println(String.format("%.6f", m) + " "  + String.format("%.6f", e));
	}
}


Measured memory_bytes: 28448
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <map>


const int mod = 1000000007;
//const int mod = 998244353;
int maximum(int a, int b) { return a < b ? b : a; }
int main() {
	int A, B, C;
	scanf("%d %d %d", &A, &B, &C);
	bool eq = false;
	if (A == B || B == C || C == A)eq = true;
	if (A == B && B == C)eq = false;
	printf(eq ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define print(x,y) (cout << (x) << (y))
#define inf INT_MAX
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,bool> pib;
typedef vector<pii> vii;
typedef vector<pib> vib;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<string,string> pss;
typedef vector<pss> vss;
const int MOD = 1e9 + 7; //998244353;

int main(){
    boost;
    int x , y, z;
    cin >> x >> y >>z ;
    cout << z <<" "<<  x <<" "<< y ;
}



Measured memory_bytes: 256
using System;
 
class main{
	static int[] p = new int[1000001];
	static int max;

	static void Prime(int n){
		for (int i = max; i*i <= n; ++i){
			if(p[i] == 1) continue;
			for (int j = i * 2; j < 1000001; j += i)
				p[j] = 1;
		}
	}

	static void Main(){
		string s;
		int count;
		
		p[0] = 1;
		p[1] = 1;
		max = 2;
		while((s = Console.ReadLine()) != null){
			int n = int.Parse(s);
			Prime(n);
			count = 0;
			for (int i = 0; i <= n; i++)
				if (p[i] == 0) count++;
			Console.WriteLine(count);
		}
	}
}

Measured memory_bytes: 12988
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,a,b) for(i64 i=(int64_t)(a);i<(int64_t)(b);i++)
#define repn(i,n) rep(i,0,n)
#define sort(i,t) qsort(i.data(),i.size(),sizeof(t),[](const void*a, const void*b)->int{if((*(t*)a)>(*(t*)b))return 1;if((*(t*)a)<(*(t*)b))return -1;return 0;})
void din() {} void dout() { cout << endl; }
template <typename T, typename ... Args> inline void din(T& head, Args& ... rest) { cin >> head; din(rest...); }
template <typename T, typename ... Args> inline void dout(T& head, Args& ... rest) { cout << head; if (sizeof...(rest)) cout << ' '; dout(rest...); }
int main()
{
	int a, b, c;
	din(a, b, c);
	vector<int> v = { a,b,c };
	sort(v, int);
	cout << v[2] * 10 + v[1] + v[0] << endl;;
}

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

typedef long long ll;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

int main(){
    int A,B;
    cin >> A;
    cin >> B;
    cout << 6-A-B << endl;
    return 0;
}

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

using namespace std;

#define MAX 100000

struct TRAMP{
    char mark;
    int number,inputed_order;
};

TRAMP cards[MAX];

int n;

int Partition(int left,int right){
    int i = left-1,pivot = cards[right].number;
    for(int start = left; start < right; start++){
        if(cards[start].number <= pivot){
                i++;
                std::swap(cards[i],cards[start]);
        }
    }

    std::swap(cards[i+1],cards[right]);

    return i+1;
}

void quickSort(int left,int right){
    if(left < right){
        int q = Partition(left,right);
        quickSort(left,q-1);
        quickSort(q+1,right);
    }
}


int main(){

    bool stableFLG = true;
    scanf("%d",&n);

    for(int i = 0; i < n; i++){
        scanf("%s %d",&cards[i].mark,&cards[i].number);
        cards[i].inputed_order = i;
    }

    quickSort(0,n-1);

    for(int i = 1; i < n; i++){
        if(cards[i].number == cards[i-1].number && cards[i].inputed_order < cards[i-1].inputed_order){
        	stableFLG = false;
        	break;
        }
    }

    if(stableFLG){
        printf("Stable\n");
    }else{
        printf("Not stable\n");
    }

    for(int i = 0; i < n; i++)   printf("%c %d\n",cards[i].mark,cards[i].number);
}



Measured memory_bytes: 4284
n = int(input())

bList = []
#offset
bList.append(-1)
for i in range(n):
  bList.append(int(input()))


nxt = 1
for i in range(n):
  nxt = bList[nxt]
  if nxt == 2:
    print(i+1)
    exit(0)
  
print(-1)


Measured memory_bytes: 7084
#include <bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007
#define INF 99999999 
using namespace std;
 
int main()
{
    ll X;
    cin >> X;
    int cnt = 0;
    ll money = 100;
    while(money < X){
        money *= 1.01;
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3644
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;


int main(){
    int n, d;
    double x[20][20];

    cin >> n >> d;
    for(int i=0;i<n;i++){
        for(int j=0; j<d; j++){
            cin >> x[i][j];
        }
    }

    int ans=0;
    

    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){

            double tmp=0;
            for(int z=0;z<d;z++){
                tmp+=(x[i][z]-x[j][z])*(x[i][z]-x[j][z]);
            }
            if(ceil(sqrt(tmp))==floor(sqrt(tmp))){
                ans++;
            }

        }
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
    int k;cin>>k;
    queue<string> q;
    for (int i=1;i<=9;i++)
        q.push(to_string(i));
    while (q.size()) {
        string s=q.front();q.pop();
        k--;
        if (k==0) {
            cout<<s<<endl;
            break;
        }
        char c=s.back();
        if (c>='1') q.push(s+char(c-1));
        q.push(s+s.back());
        if (c<='8') q.push(s+char(c+1));
    }
    return 0;
}

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

int main(){

int n,x=0,m=0;
cin>>n;
while(n-500>=0){

    x++;
    n=n-500;
}


while(n-5>0){
    m++;
    n=n-5;
}

cout<<(x*1000)+(m*5);

return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<sstream>
#include<iomanip>
#include<cstdlib>
#include<cmath>
#include<cstdio>
using namespace std;

int main()
{
	int n;
	while (cin >> n)
	{
		int sum = 0;
		for (int i = 0; i < 10; i++)
		{
			for (int j = 0; j < 10; j++)
			{
				for (int k = 0; k < 10; k++)
				{
					for (int l = 0; l < 10; l++)
					{
						if (i + j + k + l == n)sum++;
					}
				}
			}
		}
		cout << sum << endl;
	}
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> a(h, vector<char>(w));
  vector<bool> hh(h,0), ww(w,0);
  rep(i,h) rep(j,w){
    cin >> a.at(i).at(j);
    if(a.at(i).at(j) == '#'){
      hh.at(i) = 1;
      ww.at(j) = 1;
    }    
  }
  rep(i,h){
    rep(j,w) if(hh.at(i) && ww.at(j)) cout << a.at(i).at(j);
    cout << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
S = [0]*5
D = {"M": 0, "A": 1, "R": 2, "C": 3, "H": 4}
for i in range(N):
  name = input()
  if name[0] in "MARCH":
    S[D[name[0]]] += 1
ans = 0
for i in range(0, 3):
  for j in range(i+1, 4):
    for k in range(j+1, 5):
      ans += S[i]*S[j]*S[k]
print(ans)

Measured memory_bytes: 9204
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

vector<pair<int,ll>> v[100000];
vector<bool> visit(100000, 0);

int n, t, s, e;
bool ok = true;

void dfs(int pos){
    visit[pos] = true;
    for(int i = 0; i < v[pos].size(); i++){
        v[pos][i].second -= t;
        if(v[pos][i].second <= 0){
            if(!visit[v[pos][i].first]){
                ok = false;
            }else{
                continue;
            }
        }
        if(v[pos][i].first == e)    continue; // add
        if(visit[v[pos][i].first])  continue;
        dfs(v[pos][i].first);
        v[pos][i].second -= t;
    }
}

int main(){
    cin >> n >> t >> s >> e;
    s--, e--;
    for(int i = 0; i < n-1; i++){
        int a, b, w;
        cin >> a >> b >> w;
        a--, b--;
        v[a].push_back({b, w});
        v[b].push_back({a, w});
    }

    dfs(s);
    dfs(e);

    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 12176
def main():
	while True:
		n, x = (int(a) for a in input().split())
		answer = 0
		if n == 0 and x == 0:
			break
		for a in range(1, n + 1):
			for b in range(a + 1, n + 1):
				c = x - a - b
				if b >= c:
					break
				if  0 < c <= n and a != c and b != c:
					answer += 1
			if a >= c:
				break
		print(answer)

main()



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

namespace ConsoleApp2
{
    public class Program
    {
        static long mod = (long)Math.Pow(10, 9) + 7;

        public static void Main(string[] args)
        {
            long[] NM = Read(Console.ReadLine());
            long N = NM[0];
            long M = NM[1];

            var ds = GetDivisor(M);
            ds.Sort((x, y) => (int)(x-y));
            long min = ds.Max();

            for (int i = 0; i < ds.Count; i++)
            {
                long test = ds[i];
                if (test >= N)
                {
                    min = test;
                    break;
                }
            }
            

            Console.WriteLine(M/min);
            Console.ReadLine();
        }

        static List<long> GetDivisor(long N)
        {
            List<long> ans = new List<long>();
            int max = (int)Math.Sqrt(N);
            for (int i = 1; i < max; i++)
            {
                if (N % i == 0)
                {
                    ans.Add(i);
                    ans.Add(N / i);
                }
            }

            if(N%max == 0)
            {
                if (N / max == max) ans.Add(max);
                else
                {
                    ans.Add(max);
                    ans.Add(N / max);
                }
            }
            return ans;
        }

        private static long[] Read(string input)
        {
            string[] strings = input.Split(' ');
            long num = strings.Length;
            long[] ints = new long[num];
            for (int i = 0; i < num; i++)
            {
                ints[i] = long.Parse(strings[i]);
            }

            
            return ints;
        }
    }
}


Measured memory_bytes: 13524
//It's time to be who I am, rather than who I am supposed to be.
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int inf = 1e12;
const int N = 105;
const int maxVal = 1e5;
int weight[N], value[N], dp[maxVal + 5][N], n, total;

int giveMinWeight(int item, int currVal){
	if(currVal < 0)
		return inf;
	if(currVal == 0)
		return 0;
	if(item == 0)
		return inf;

	int &ans = dp[currVal][item];
	if(ans != 0)
		return ans;

	int take = weight[item] + giveMinWeight(item - 1, currVal - value[item]);
	int dont_take = giveMinWeight(item - 1, currVal);

	ans = min(take, dont_take);
	return ans;
}

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

	cin >> n >> total;
	for(int i = 1; i <= n; i++)
		cin >> weight[i] >> value[i];

	int ans = 0;

	for(int i = maxVal; i >= 0; i--){
		if(giveMinWeight(n, i) <= total){
			ans = i;
			break;
		}
	}

	cout << ans << '\n';
    
}


Measured memory_bytes: 82304
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import math
import cmath

A, B, H, M = map(int, input().split())

def to_arg(rate):
    return - 2 * math.pi * rate

short_rate = (H * 60 + M) / 720
long_rate = M / 60

short = cmath.rect(A, math.pi / 2.0)
short *= cmath.rect(1.0, to_arg(short_rate))

long = cmath.rect(B, math.pi / 2.0)
long *= cmath.rect(1.0, to_arg(long_rate))

print("{:.20f}".format(abs(long - short)))




Measured memory_bytes: 9596
#include <bits/stdc++.h>
namespace shl {
	int m, d, ans;
	int main() {
		scanf("%d%d", &m, &d);
		for (register int i = 1; i <= m; ++i) {
			for (register int j = 22; j <= d; ++j) {
				if (j % 10 >= 2 && j / 10 >= 2 && (j % 10) * (j / 10) == i) ans++;
			}
		}
		printf("%d\n", ans);
		return 0;
	}
}
int main() {
	shl :: main();
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main{
    static MyReader in = new MyReader();

    public static void main(String[] args){
        int N, M; {int[] a = in.ii(); N = a[0]; M = a[1];}
        MyGraph graph = new MyGraph(N, M);
        int[] parent = graph.bfs(1);
        StringBuilder ans = new StringBuilder("Yes\n");
        for (int i = 2; i < parent.length; i++) {
            ans.append(parent[i]).append('\n');   
        }
        out.print(ans);
    }

    static class MyGraph{
        int V; // 頂点数
        int E; // 辺数
        ArrayList<Integer>[] T; // 連結関数
        final static int INF = Integer.MAX_VALUE;

        MyGraph(int V, int E){
            this.V = V;
            this.E = E;
            T = new ArrayList[V+1];
            for(int i = 1; i < T.length; i++){
                T[i] = new ArrayList<>();
            }
            for(int i = 0; i < E; i++){
                int u, v; {int[] a = in.ii(); u = a[0]; v = a[1];}
                T[u].add(v);
                T[v].add(u);
            }
        }

        int[] bfs(int s){
            int[] parent = new int[V+1];
            LinkedList<Integer> A = new LinkedList<>();
            boolean[] B = new boolean[V+1];
            A.add(s);
            B[s] = true;
            int rest = V - 1;
            while(rest != 0) {
                int v = A.pollFirst();
                for(Integer u : T[v]){
                    if(!B[u]){
                        A.add(u);    
                        B[u] = true;
                        parent[u] = v;
                        rest--;
                    }
                }
            }
            return parent;
        }
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        ArrayList<Integer> li(){
            String[] ss = ss();
            ArrayList<Integer> li = new ArrayList<>();
            for(int j = 0; j < ss.length; j++) li.add(Integer.parseInt(ss[j]));
            return li;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


Measured memory_bytes: 64908
#include<stdio.h>
int main()
{
int k;
int a;
int b;
int c;
int ans;

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

if(k<=a){printf("%d",k);}
else if(k<=(a+b)){ printf("%d",a);}
else { printf("%d",a-(k-(a+b)));}

return 0;
}

Measured memory_bytes: 2152
#include <iostream>
#include <string>
#include <cctype>
#include <cstdio>

using namespace std;

int main(){
    string str;
    getline(cin,str);
    for(int i = 0; str[i] != NULL; i++){
        if(islower(str[i]) ){
            printf("%c", str[i]-32);
        }else if(isupper(str[i])){
            printf("%c",str[i] + 32);
        }else{
            cout << str[i];
        }
    }
    cout << endl;
}



Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
struct node{
	int u,v,w;
}a[200005];
int fa[200005];
int find(int x){
	if(x!=fa[x])
		return fa[x]=find(fa[x]);
	return fa[x];
}
int cmp(node a,node b){
	return a.w<b.w;
}
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int u,v,w;
	int cnt=0;
	for(int i=0;i<m;i++){
		scanf("%d%d%d",&a[cnt].u,&a[cnt].v,&w);
		a[cnt++].w=0;
	}
	for(int i=1;i<=n;i++)
		a[cnt].u=n+1,a[cnt].v=i,a[cnt++].w=1;
	for(int i=1;i<=n;i++)
		fa[i]=i;
	sort(a,a+cnt,cmp);
	int ans=0;
	for(int i=0;i<cnt;i++){
		int fx=find(a[i].u),fy=find(a[i].v);
		if(fx!=fy){
			ans+=a[i].w;
			fa[fy]=fx;
		}
		else continue;
	}
	printf("%d\n",ans); 
}

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

using namespace std;

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

    if(n == 1)
    {
        cout << 1 << "\n";
        return 0;
    }

    long long a = 2, b = 1, c;

    for(int i = 0; i < n - 1; i++)
    {
        c = b + a;
        // cout << c << "\n";
        a = b;
        b = c;
    }
    cout << c << "\n";
    return 0;
}


Measured memory_bytes: 256
// Package main provides
//
// File:  a.go
// Author: ymiyamoto
//
// Created on Fri Jan  4 15:33:22 2019
//
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	fmt.Println((a + b + 1) / 2)
}


Measured memory_bytes: 512
//
// Created on 2020/05/31.
//


#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
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


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


Measured memory_bytes: 3624
#include <iostream>
using namespace std;
typedef long long ll;

int arr[100];

int calc(int l, int r) {
	if(l==r) return 0;
	/*
	cout << l << "," << r << endl;
	for(int i = l; i < r; i++) {
		cout << arr[i] << " ";
	}
	cout << endl;
	*/
	int ans = 0;

	int h_max = 1<<30;
	for(int i = l; i < r; i++) {
		h_max = min(h_max,arr[i]);
	}
	ans += h_max;
	for(int i = l; i < r; i++) {
		arr[i] -= h_max;
	}

	int _h = -1;
	int _l = l;
	for(int i = l; i < r; i++) {
		if(arr[i]==0) {
			if(_h!=-1) {
				ans += calc(_l,i);
				_l = i+1;
			}else {
				_l++;
			}
		}else {
			if(_h==-1) {
				_h = arr[i];
			}
		}
	}
	if(_h!=-1) {
		ans += calc(_l,r);
	}

	//cout << " " << ans << endl;
	return ans;
}

int main() {
	ll n;
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	int ans = calc(0,n);
	cout << ans << endl;
	return 0;
}


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

int main() {
  int n; cin >> n;
  vector<int> cards(n);
  for (int i = 0; i < n; i++) {
    cin >> cards.at(i);
  }

  sort(cards.begin(), cards.end(), greater<int>());
  if (cards.size() % 2 == 1) {
    cards.push_back(0);
  }
  
  int diff = 0;
  for (int i = 0; i < n; i = i + 2) {
    diff += cards.at(i) - cards.at(i+1);
  }
  
  cout << diff << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	ll N, A, B;
	cin >> N >> A >> B;
	if (A > B)
		cout << 0 << endl;
	else if (N == 1 && A != B)
		cout << 0 << endl;
	else
	{
		ll ans = (N - 2) * (B - A) + 1;
		cout << ans << endl;
	}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
typedef long long ll;
typedef pair<char, char> c_c;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
const int INF = 1000000007;
const ll LLINF = 1000000000000000007LL;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    int cnt = 0;
    stack<int> stc;
    rep(i,n){
        if(stc.size() == 0 ){
            if(a[i] == 1) stc.push(a[i]);
            //cout << stc.top() << endl;
        }
        else{
            if(a[i] == stc.top()+1){
                stc.push(a[i]);
            }
        }
        //cout << stc.top() << endl;
    }
    if(stc.size() != 0) cout << n-stc.size() << endl;
    else cout << -1 << endl;
    
    return 0;
}

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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int main() {
  int A, B;
  cin >> A >> B;
  int ans = 0;
  for (int i = A; i <= B; i++) {
    int a = i / 10000, b = (i / 1000) % 10, c = (i / 10) % 10, d = i % 10;

    if (a == d && b == c)
      ans++;
  }
  cout << ans << endl;
}


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

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

  string prev = "";
  int cnt = 0;
  for (int i = 0; i < s.size(); i++) {
    string c(1, s[i]);
    if (prev == c) {
      if (i + 1 < s.size()) {
        i++;
        prev = "";
      } else {
        break;
      }
    } else {
      prev = c;
    }
    cnt++;
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 640
import sys

n,m = map(int,input().split())
a = [[] for i in range(n)]
b = [[] for j in range(m)]
for i in range(n):
    a[i] = input()
for i in range(m):
    b[i] = input()
    
mal = n-m+1
for i in range(mal):
    for j in range(mal):
        fl = 1
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l] != b[k][l]:
                    fl = 0
                    
        if fl == 1:
            print("Yes")
            sys.exit()
            
print("No")

Measured memory_bytes: 39920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=505,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,K;cin>>N>>K;
    vector<int> cnt(26);
    for(int i=0;i<N;i++){
        string S;cin>>S;
        cnt[S[0]-'A']++;
    }
    
    int ans=0;
    
    while(1){
        sort(all(cnt));
        reverse(all(cnt));
        
        for(int i=0;i<K;i++){
            if(cnt[i]) cnt[i]--;
            else{
                cout<<ans<<endl;
                return 0;
            }
        }
        ans++;
    }
}



Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c<'0' || c>'9'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	ll f=1;
	while((c=getchar())!='-' && (c<'0' || c>'9'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
int main(){
	int T=read();
	while(T--){
		int A=read(),B=read();
		ll sum=1ll*A*B;
		if(sum<=27) sum=(ll)sqrt(sum-1);
		else{
			sum=(ll)sqrt(sum)-5;
			while((sum+1)*(sum+1)<=1ll*A*B-1) ++sum;
		}
		if(sum==0){
			printf("0\n");
			continue;
		}
		printf("%lld\n",2ll*sum-((A<=sum)+(B<=sum)+(sum==(1ll*A*B-1)/sum)));
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

ll a[100000];
ll b[100000] = {};
int main()
{
	ll N; cin >> N;

	rep(i, 0, N)cin >> a[i];

	ll c = 1;
	ll cnt = 0;
	while (c != 2) {
		if (b[c - 1]) {
			cout << -1 << endl;
			return 0;
		}
		b[c - 1] = true;

		c = a[c - 1];
		cnt++;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 1792
gets
monsters = gets.split.map(&:to_i)
heros = gets.split.map(&:to_i) + [0]

count = 0
prev = 0
heros.zip(monsters).each{|h, m|
    count += [m, prev + h].min
    if prev > m
        prev = h
    elsif prev + h > m
        prev = prev + h - m
    else
        prev = 0
    end
}
puts count


Measured memory_bytes: 30852
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N, M = list(map(int, sys.stdin.buffer.readline().split()))
ok = N == M
if ok:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 25448
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		int a = y+z, lo = 0;
		lo = x - z;
		lo = lo / a;
		System.out.println(lo);
	}
}

Measured memory_bytes: 23764