akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep2(i,x,n) for(int i=x;i<n;++i)

int main()
{
    int h,w;
    cin >> h >> w;
    vector<vector<int>> s(h, vector<int>(w, 0));
    rep(i,h)
    {
        string si;
        cin >> si;
        rep(j,w) if(si[j] == '#') s[i][j] = 1;
    }

    int max_cnt = 0;
    rep(i, h)
        rep(j, w)
        {
            if(s[i][j] == 1) continue;

            vector<vector<int>> dist(h,vector<int>(w,-1));
            queue<pair<int, int>> que;

            que.push({i,j});
            dist[i][j] = 0;

            int dir4[4][2] = {{1,0}, {-1,0}, {0,1}, {0,-1}};

            while(!que.empty())
            {
                auto qi = que.front();
                que.pop();
                int ci = qi.first;
                int cj = qi.second;
                int dkl = dist[ci][cj];

                for(const auto& dir : dir4)
                {
                    int ni = ci + dir[1];
                    int nj = cj + dir[0];
                    if(ni<0 || ni>=h) continue;
                    if(nj<0 || nj>=w) continue;
                    if(s[ni][nj] == 1) continue;
                    if(dist[ni][nj] >= 0) continue;
                    que.push({ni,nj});
                    dist[ni][nj] = dkl + 1;                    
                    max_cnt = max(max_cnt, dkl+1);
                }
            }
        }

    cout << max_cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if ((A < C && C < B) || (B < C && C < A)){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
bool B(int a,int i){return (a>>i)&1;}
bool b[32];
int main(){
	int N;
	cin>>N;
	int x=0;
	rep(i,N){
		int a;
		cin>>a;
		x^=a;
		int j=0;
		while(!B(a,j)) j++;
		b[j]=1;
	}
	int a=0;
	for(int i=30;i>=0;i--){
		if(B(x,i+1)!=B(x,i)){
			if(!b[i]){
				puts("-1");
				return 0;
			}
			a++;
		}
	}
	cout<<a<<endl;
}


Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

A,B,C=get_i
puts min(B/A,C)

Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;   
int main()
{
long long int  a,b,c,d;
    long long int x[5];
    cin>>a>>b>>c>>d;
    x[0]=a*c;
    x[1]=a*d;
    x[2]=b*c;
    x[3]=b*d;
    sort(x,x+4);
    cout<<x[3]<<endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  int n, q;
  vector<long long> S, T;
  cin >> n;
  rep(i, n) {
    long long s;
    cin >> s;
    S.push_back(s);
  }
  cin >> q;
  rep(i, q) {
    long long t;
    cin >> t;
    T.push_back(t);
  }
  int c = 0;
  for (auto t : T) {
    if (binary_search(S.begin(), S.end(), t)) c++;
  }
  cout << c << endl;
  return 0;
}



Measured memory_bytes: 4576
n, m, c = [int(i) for i in input().split() ]
b = [int(i) for i in input().split() ]
ok = 0
for i in range(n):
    a = [int(i) for i in input().split() ]
    ans = c
    for j in range(m):
        ans += a[j]*b[j]
    if ans > 0:
        ok += 1
print(ok)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<time.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


int n, m, k, c[101010], a[101010], d[101010], ans[101010];
vector<int> v[101010];
int finish[101010];

int main(){
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int x, y;
		cin >> x >> y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	cin >> k;
	for(int i = 0; i < k; i++){
		cin >> a[i] >> d[i] >> c[i];
	}
	
	for(int i = 0; i <= n; i++){
		finish[i] = -1;
	}
	for(int i = k-1; i >= 0; i--){
		queue<P> q;
		q.push(P(a[i], d[i]));
		while(!q.empty()){
			P p = q.front();
			q.pop();
			int pos = p.first, now = p.second;
			if(finish[pos] >= now) continue;
			finish[pos] = now;
			if(ans[pos] == 0) ans[pos] = c[i];
			for(int j = 0; j < v[pos].size(); j++){
				q.push(P(v[pos][j], now-1));
			}
		}
	}
	
	for(int i = 1; i <= n; i++){
		cout << ans[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 9848
/**
 *    author:  FromDihPout
 *    created: 2020-08-01
**/

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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int x, a, b;
    cin >> x >> a >> b;
    
    if (b <= a) {
        cout << "delicious" << '\n';
    }
    else if (b - a <= x) {
        cout << "safe" << '\n';
    }
    else {
        cout << "dangerous" << '\n';
    }
    
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int n, m;
    cin >> n >> m;
    vector<int> S(n + 1);
    S[0] = 0;
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        S[i + 1] = (S[i] + a) % m;
    }
    ll ans = 0;
    map<int, int> mp;
    for(int i = 0; i <= n; ++i){
        ans += mp[S[i]];
        ++mp[S[i]];
    }
    cout << ans << endl;
}

Measured memory_bytes: 6620
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int N; cin>>N;
  vector<vector<int> > F(N,vector<int>(10,0));

  for(int i=0;i<N;i++){
    for(int j=0;j<10;j++){
      cin>>F[i][j];
    }
  }

  vector<vector<long long> > P(N,vector<long long>(11,0));

  for(int i=0;i<N;i++){
    for(int j=0;j<11;j++){
      cin>>P[i][j];
    }
  }
  long long ans=0;
  for(int bit=1;bit<(1<<10);bit++){
    vector<int> S;
    for(int i=0;i<10;i++){
      if(bit&(1<<i)){
        S.push_back(i);
      }
    }
    long long temp=0;
    for(int i=0;i<N;i++){
      int sum=0; 
      for(int j=0;j<S.size();j++){
        sum+=(F[i][S[j]]==1?1:0);
      }
      temp+=P[i][sum];
    }
    if(temp>ans||bit==1){
      ans=temp;
    }
  }

  cout<<ans<<endl;

  return 0;
}


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

int main()
{
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> map(H);
    for(int i = 0; i < H; i++)
    {
        string mapStr;
        cin >> mapStr;
        map.at(i) = mapStr;
    }
    int carryOverHeight = 1;
    int currentCount = 1;
    vector<vector<int>> result(H, vector<int>(W));
    for(int i = 0; i < H; i++)
    {
        int strawberryCount = 0;
        deque<int> strawberryIndexes;
        for(int j = 0; j < W; j++)
        {
            if(map.at(i).at(j) == '#'){
                strawberryCount++;
                strawberryIndexes.push_back(j);
            }
        }
        if(strawberryCount == 0){
            carryOverHeight++;
        } else {
            strawberryIndexes.pop_back();
            int strawberryIndex = W;
            if(!strawberryIndexes.empty()){
                strawberryIndex = strawberryIndexes.front();
                strawberryIndexes.pop_front();
            } 
            for(int j = 0; j < W; j++){
                for(int k = 0; k < carryOverHeight; k++){
                    result.at(i - k).at(j) = currentCount;
                }
                if(j == strawberryIndex){
                    currentCount++;
                    strawberryIndex = W;
                    if(!strawberryIndexes.empty()){
                        strawberryIndex = strawberryIndexes.front();
                        strawberryIndexes.pop_front();
                    } 
                }
            }
            currentCount++;
            carryOverHeight = 1;
        }
    }
    if(carryOverHeight > 1){
        for(int i = H - carryOverHeight + 1; i < H; i++){
            for(int j = 0; j < W; j++){
                result.at(i).at(j) = result.at(H - carryOverHeight).at(j);
            }
        }
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(j > 0){
                cout << ' ';
            }
            cout << result.at(i).at(j);
        }
        cout << endl;
    }
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W,K; cin>>H>>W>>K;
    vector<string> f(H);
    rep(i,H) cin>>f[i];

    ll ans=0;
    rep(i,1<<H)rep(j,1<<W){
        vector<string> g = f;
        int sum=0;
        rep(k,H)if(i>>k&1){
            rep(cnt,W) g[k][cnt]='*';
        }
        rep(k,W)if(j>>k&1){
            rep(cnt,H) g[cnt][k]='*';
        }
        rep(k,H)rep(l,W)if(g[k][l]=='#'){
            sum++;
        }
        if (sum==K) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
using ll = long long;


ll A, B, Q;
ll S[100010];
ll T[100010];
ll X[100010];

ll szs[2];
ll P[2][100010];

int main(){
    cin >> A >> B >> Q;
    szs[0] = A;
    szs[1] = B;
    for(ll i = 0; i < A; i++){
        cin >> S[i];
        P[0][i] = S[i];
    }
    for(ll i = 0; i < B; i++){
        cin >> T[i];
        P[1][i] = T[i];
    }
    for(ll i = 0; i < Q; i++) cin >> X[i];
    for(ll i = 0; i < Q; i++){
        ll ans = 1LL << 60;
        for(int l = 0; l < 2; l++){
            int now = l;
            int nxt = now ^ 1;
            // 一番近い神社に行ってから寺に行く場合
            // 一番近い寺に行ってから神社にいく場合
            // SとTをswapして考える必要あり
            ll pos1 = lower_bound(P[now], P[now] + szs[now], X[i]) - P[now];
            ll pos2 = pos1 - 1;
            for(ll pos : {pos1, pos2}){
                if(pos >= szs[now] || pos < 0) continue;
                ll dist = abs(X[i] - P[now][pos]);
                ll p1 = lower_bound(P[nxt], P[nxt] + szs[nxt], P[now][pos]) - P[nxt];
                ll p2 = p1 - 1;
                for(ll p : {p1, p2}){
                    if(p >= 0 && p < szs[nxt]) 
                        ans = min(ans, dist + abs(P[now][pos] - P[nxt][p]));
                }
            }
        }
        cout<< ans << endl;
    }

    return 0;
}


Measured memory_bytes: 5248
// #pragma GCC optimize(2)
// #pragma G++ optimize(2)
// #pragma comment(linker,"/STACK:102400000,102400000")

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

typedef long long int64;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef double dl;
typedef pair<int,int> pii;
#if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || (WINDOWS)
#define lld "%I64d"
#define llu "%I64u"
#else
#define lld "%lld"
#define llu "%llu"
#endif
#define uint(n) ((unsigned int)(n))
#define int64(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define dl(n) ((double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed<<setprecision(n)

const int INF=1061109567;
const int NINF=-1044266559;
const int64 LINF=4557430888798830399;
const dl eps=1e-15;
#define MOD (1000000007)
#define PI (3.1415926535897932384626433832795028841971)

#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(),(a).end()
#define pall(a) (a).rbegin(),(a).rend()
#define Log(x,y) log(x)/log(y)
#define SZ(a) ((int)(a).size())
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define rep1(i,n) for(int i=1;i<=((int)(n));i++)
#define repd(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define repd1(i,n) for(int i=((int)(n));i>=1;i--)
#define repv(itr,v) for(__typeof((v).begin()) itr=(v).begin();itr!=(v).end();itr++)
#define repV(i,v) for(auto i:v)
#define repE(i,v) for(auto &i:v)
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x) MS(x,0)
#define MINF(x) MS(x,63)
#define MCP(x,y) memcpy(x,y,sizeof(y))
#define UN(v) sort(All(v)),v.erase(unique(All(v)),v.end())
#define filein(x) freopen(x,"r",stdin)
#define fileout(x) freopen(x,"w",stdout)
#define fileio(x)\
	freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout)
#define filein2(filename,name) ifstream name(filename,ios::in)
#define fileout2(filename,name) ofstream name(filename,ios::out)
#define fileio2(filename,name) fstream name(filename,ios::in|ios::out)
#define sqr(x) ((x)*(x))
#define Pause system("pause")
#define Cls system("cls")
#define fs first
#define sc second
#define SF scanf
#define PF printf

const int maxn=200010;

int n,a[maxn];
int64 sum,ans;

int main()
{
	SF("%d",&n);
	for(int i=1;i<=n;i++)
	{
		SF("%d",&a[i]);
		sum=(sum+a[i])%MOD;
	}

	for(int i=1;i<=n;i++)
	{
		sum=(sum-a[i]+MOD)%MOD;
		ans=(ans+sum*a[i]%MOD)%MOD;
	}

	cout<<ans;

	return 0;
}

Measured memory_bytes: 4540
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,p;
signed main()
{
	cin>>n>>m>>p;
	if(abs(p-m)%2==0)
	printf("%lld",abs(p-m)/2);
	else
	printf("%lld",(abs(p-m)+1)/2+min(min(p,m)-1,n-max(p,m)));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1 , number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1 , number1);
    }
}

ll i,j,k,ii,jj;
ll n,m;
ll a,b,c,d,e,g,h,r,w;
ll l,ans,sum;
ll num;
ll x[500005],y[500005],z[500005];
double p[3000];
double dp[3005][3005];
bool dame,flag,ok;

int main(){
	cin >> n;
	for(i=0;i<n;i++){
		cin >> p[i];
	}
	dp[0][0] = 1;
	for(i=1;i<=n;i++){
		for(j=0;j<=n;j++){
			//dp[i][j]
			if(i < j){
				dp[i][j] = 0.0f;
			}else if(j == 0){
				dp[i][j] = dp[i-1][j] * (1.0f - p[i-1]);
			}else{
				dp[i][j] = dp[i-1][j] * (1.0f-p[i-1]) + dp[i-1][j-1] * p[i-1];
			}
			//ps(dp[i][j]);
		}
	}
	double ans = 0;
	for(i=0;i<=n;i++){
		if(i > n - i){
			ans += dp[n][i];
		}
	}
	ps(ans);
	return 0;
}

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

using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 1010;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

//union-find木について
ll par[101010];
ll rank2[101010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 0;
	}
}

ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(ll x, ll y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rank2[x] < rank2[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rank2[x] == rank2[y]) {
			rank2[x]++;
		}
	}
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

char c[1010][1010];
ll dp[101010][110];
ll v[110], w[110];

//long longしか使わない
//素数は1より大きい
int main() {
	ll N, W;
	cin >> N >> W;
	rep(i, N) {
		cin >> v[i] >> w[i];
	}
	rep(i, W+1) {
		rep(j, N) {
			if (i - w[j] < 0)dp[i][j] = dp[i][j - 1];
			else {
				dp[i][j] = max(dp[i][j - 1], dp[i - w[j]][j - 1] + v[j]);
			}
		}
	}
	ll ans = 0;
	rep(i, W + 1) {
		ans = max(ans, dp[i][N - 1]);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 11696
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[] a = in.ii();
        out.println(a[2] + " " + a[0] + " " + a[1]);
    }

    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: 21716
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        a: i64,
        v: i64,
        b: i64,
        w: i64,
        t: i64,
    }

    if (a - b).abs() <= t * (v - w) {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define EPS (int)1e-9
typedef long long ll;
typedef vector<int> vi;
#define sz(v)		((int)((v).size()))
#define OO 0x3f3f3f3f
#define  ed  '\n'
#define watch(x) cerr << '>' << #x << ':' << x << '\n';
#define in_range(x, y, r, c) ((x >= 0 && x < r && y >= 0 && y < c))
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline int two(int n) { return 1 << n; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
#define IOS std::ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
const ll mod=1e18+9;
const int N=200;
ll arr[N];
int main(){
IOS;
int n;
cin>>n;


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

ll cost=1e16;
for (int i = -100; i < 101;++i)
{
	ll tmp=0;
	for (int j = 0; j < n; ++j)
	{
		ll t=(i-arr[j]);
		tmp+=(t*t);
	}
	cost=min(tmp,cost);
}
cout<<cost;
return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int a,b,c,tmp;

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

  if(a>b){
    tmp=a;
    a=b;
    b=tmp;
  }
  if(b>c){
    tmp=b;
    b=c;
    c=tmp;
  }
  if(a>b){
    tmp=a;
    a=b;
    b=tmp;
  }
  printf("%d %d %d\n",a,b,c);
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static const int MAX=(int) 1e5;
int N,rest;
ll A[MAX+2],sum;

int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];
    
    for(int i=0;i<N;i++){
        if(A[i]%2){
            if(i<N-1 && A[i+1]>0) {
                sum += (A[i] +1)/2;
                A[i+1]--;
            }else sum += A[i]/2;
        }else sum += A[i]/2;
    }
    cout << sum <<"\n";
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll div_num(ll n){
  vl div(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      div[i]++;
    }
  }
  if(n!=1)div[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=div[i];
  }
  return num;
}
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}
long long lopow(ll a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a ;
        a = a * a ;
        n >>= 1;
    }
    return res;
}


//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;

int main(){
  int X,Y;cin>>X>>Y;
  bool ok =false;
  for(int i =0;i<X+1;i++){
    if(X-i>=0 && i*2 +(X-i)*4==Y){ok=true;break;}
  }
  if(ok) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll int MOD=1e9+7;
#define INF 2*1e9
#define N 310000 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");
ll int inv[N*2],comb[N*2];
void calc_inv(ll n){
    inv[1]=1;
    rep2(i,2,n*2){
        inv[i]=((-(MOD/i)*inv[MOD%i])%MOD+MOD)%MOD;
    }
    return;
}

main(){
    ll n;
    ll x,y;
    cin>>n>>x>>y;
    pii p[N];
    vector<pii> v;
    ll m1=MOD,m2=MOD;
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        p[i].first=a;p[i].second=b;
        m2=min(m2,b);
        if(m2<m1) swap(m1,m2);
        v.pb(p[i]);
    }
    sort(v.begin(),v.end());
    ll num[N]={};
    ll sum=0;
    rep2(i,1,n){
        int l=lower_bound(v.begin(),v.end(),(pii){i,0})-v.begin();
        int r=lower_bound(v.begin(),v.end(),(pii){i+1,0})-v.begin();
        ll t=v[l].second;
        if(t!=m1){
            rep2(j,l,r-1){
                if((t+v[j].second<=x&&t+m1<=y)||v[j].second+m1<=y)
                num[i]++;
            }
        }
        else{
            rep2(j,l,r-1){
                if((t+v[j].second<=x&&t+m2<=y)||v[j].second+m2<=y)
                num[i]++;
            }
        }
        sum+=num[i];
    }
    calc_inv(n);
    ll ans=1;
    for(ll i=1;i<=sum;i++){
        ans=(ans*i)%MOD;
    }
    rep2(i,1,n){
        rep2(j,1,num[i]) ans=(ans*inv[j])%MOD;
    }
    cout<<(ans+MOD)%MOD;
    
}



Measured memory_bytes: 15724
#include<bits/stdc++.h>
using namespace std;
#define D(x)    cout << #x " = " <<(x) << endl
#define MAX     1000
typedef long long int LL;

int k;
int cost[33];
const double INF = 1e100;

double solve(int n);
double dp[MAX+5][33], dp_solve[MAX+5];


double F(int n, int t){
    double ret = INF;
    if(t == 0){
        if(n == 1) return cost[0];
        return cost[0] + solve(n);
    }
    if(!n) return INF;

    if(dp[n][t] == dp[n][t]) return dp[n][t];

    for(int p1 = 1; p1 < n; p1++){
        double current = 0;
        current = ((n - p1) / (double) n) * F(n - p1, t - 1) + (p1 / (double) n) * (cost[t] + solve(p1));
        ret = min(ret, current);
    }

    return dp[n][t] = ret;
}

double solve(int n){
    if(n == 1) return 0;
    if(dp_solve[n] == dp_solve[n]) return dp_solve[n];

    double ret = numeric_limits<double>::max();
    for(int t = 1; t <= k; t++)
        ret = min(ret, F(n, t));

    return dp_solve[n] = ret;
}

int main()
{
//    freopen("in.txt", "r", stdin);
    int st, ed, i, n;
    memset(dp, -1, sizeof(dp));
    memset(dp_solve, -1, sizeof(dp_solve));

    scanf("%d %d %d", &st, &ed, &k);
    for(i = 0; i <= k; i++) scanf("%d", &cost[i]);
    n = ed - st;


    printf("%0.10f\n", solve(n));
    return 0;
}




Measured memory_bytes: 3732
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];
            List<long[]> addCards = new List<long[]>();

            List<int> numbers = new List<int>();

            string[] strNums = Console.ReadLine().Split(' ');
            foreach (var item in strNums)
            {
                numbers.Add(int.Parse(item));
            }
            numbers.Sort();

            for (int i = 0; i < M; i++)
            {
                long[] BC = Read(Console.ReadLine());
                addCards.Add(BC);
            }
            addCards.Sort((x,y) => (int)(x[1]-y[1]));

 

            int count = 0;
            long ans = 0;

            while (count!=N)
            {
                if (addCards.Count==0||numbers[numbers.Count - 1] > addCards[addCards.Count - 1][1])
                {
                    ans += numbers[numbers.Count - 1];
                    numbers.RemoveAt(numbers.Count - 1);
                }
                else
                {
                    ans += addCards[addCards.Count - 1][1];
                    addCards[addCards.Count - 1][0]--;
                    if (addCards[addCards.Count - 1][0] < 1) addCards.RemoveAt(addCards.Count - 1);
                }
                count++;
            }


            Console.WriteLine(ans);
            Console.ReadLine();
        }

        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: 30544
//29
#include<iostream>
#include<cmath>

#define PI acos(-1)

using namespace std;

int main(){
  for(double d;cin>>d,d;){
    for(int i=1;;i++){
      int r=PI*i;
      if(PI-r*1./i>(r+1)*1./i-PI){
	r++;
      }
      if(fabs(PI-r*1./i)<d){
	cout<<r<<'/'<<i<<endl;
	break;
      }
    }
  }
  return 0;
}

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

constexpr int MOD = 998'244'353;

template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    constexpr ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u);
    }
    ModInt pow(long long e){
        long long a = 1, p = x;
        while(e > 0) {
            if (e & 1) {a = (a * p) % mod; e--;}
            else {p = (p * p) % mod; e /= 2;}
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

int main() {
	int n, s;
	cin >> n >> s;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	
	ModInt<MOD> dp[n + 1][s + 1];
	dp[0][0] = 2;
	dp[0][0] = dp[0][0].pow(n);
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= s; j++) {
			dp[i + 1][j] += dp[i][j];
		}
		for (int j = 0; j <= s; j++) {
			if (j + a[i] <= s) {
				dp[i + 1][j + a[i]] += dp[i][j] / 2;
			}
		}
	}
	
	cout << dp[n][s] << '\n';
	
	return 0;
}
	


Measured memory_bytes: 38784
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>



void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}


int gcd(int a, int b){
  int c;

  while (b > 0){
    c = a % b;
    a = b;
    b = c;
  }

  return a;
}

long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}

int main(void){
  int a,b;
  scanf("%d%d",&a,&b);
  char s[a+b+10];
  scanf("%s",s);
  for(int i=0;i<a;i++){
    if(s[i]<'0'||'9'<s[i]){
      printf("No\n");
      return 0;
    }
  }
  if(s[a]!='-'){
    printf("No\n");
    return 0;
  }
  for(int i=a+1;i<a+b+1;i++){
    if(s[i]<'0'||'9'<s[i]){
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 1628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;}
ll lcm(ll x, ll y) {return x/gcd(x,y)*y;}

// 素因数分解 O(√n)
// たとえば 60 = 2^2 x 3 x 5 だったら {(2, 2), (3, 1), (5, 1)} を返す
// 素因数の個数はlogn
vector<pair<ll,ll>> prime_factorize(ll n){
    vector<pair<ll,ll>> res;
    for(ll p=2;p*p<=n;p++){
        if(n%p!=0) continue;
        int num=0; // 指数
        while(n%p==0){
            num++;
            n/=p;
        }
        res.push_back({p,num});
    }
    if(n!=1) res.push_back({n,1});
    return res;
}


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

    ll x=gcd(a,b);
    if(x==1){
        cout<<1<<endl;
        return 0;
    }

    auto pf=prime_factorize(x);

    cout<<pf.size()+1<<endl;

}


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

using namespace std;

int main(){
  string s,t;
  cin >> s >> t;
  bool good = true;
  for(int i = 0; i < s.length(); i++){
    if(s[i] != t[i]) good = false;
  }
  if(good) cout << "Yes\n";
  else cout << "No\n";
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    int n,k; cin>>n>>k;
    vector <int> a(n); 
    rep(i,n) cin>>a[i];
    vector <int> b(2*n);
    rep(i,2*n) b[i] = a[i%n];
    vector <int> data(201000,-1);
    
    map <int,int> ma;
    rep(i,2*n){
        int mae = data[b[i]];
        data[b[i]] = i;
        if(mae == -1) continue;
        //cout<<mae<<' '<<i<<' '<<b[i]<<endl;
        ma[mae] = i%n;
    }
    /*rep(i,n){
        cout<<a[i]<<"の次"<<ma[i]<<endl;
    }*/
    int shuuki = 1; // nowがk+1になる直前にやめて、答えをだす
    int now = 0;
    for(;;){
        //cout<<now<<endl;
        int ne = ma[now];
        if(now >= ne) shuuki++;
        ne += 1;
        if(ne == n) break;
        now = ne;
    }
    //cout<<shuuki<<endl;
    k %= shuuki;
    int cnt = 1;
    now = 0;
    
    for(;;){
        int ne = ma[now];
        if(now >= ne) cnt++;
        ne += 1;
        if(cnt == k+1) break;
        now = ne;
    }
    //cout<<now<<endl;
    for(int i=now;i<n;i++){
        if(ma[i]<=i){
            cout<<a[i]<<' ';
        }else{
            i = ma[i];
        }
    }
}


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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    ll A[N]; rep(i, N) cin >> A[i];
    bool zero = false;
    int numneg = 0;
    ll minabs = mod;
    ll acc = 0;
    rep(i, N){
        if(A[i] == 0) zero = true;
        if(A[i] < 0) numneg++;
        if(minabs > abs(A[i])) minabs = abs(A[i]);
        acc += abs(A[i]);
    }
    if(zero) cout << acc << endl;
    else{
        if(numneg%2){
            cout << acc - minabs*2 << endl;
        }
        else cout << acc << endl;
    }
    return 0;
}

Measured memory_bytes: 4360
import sys


def main():
    N = int(input())
    TXY = [[int(x) for x in input().split()] for _ in range(N)]
    TXY.insert(0, [0, 0, 0])

    for i in range(N):
        dt = TXY[i+1][0] - TXY[i][0]
        dl = abs(TXY[i+1][1] - TXY[i][1])
        dl += (TXY[i+1][2] - TXY[i][2])

        if dt < dl or (dt-dl) % 2 == 1:
            print('No')
            sys.exit()

    print('Yes')


main()


Measured memory_bytes: 21156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define vec(x) vector<x>
#define IINF INT_MAX
#define LLINF LLONG_MAX
ll gcd(ll a,ll b){while(b){ll tmp = a % b;a = b;b = tmp;}return a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define split_str(str, sp_word) istringstream stream(str); string res; for(int cnt = 0; getline(stream,res,sp_word); cnt++)
#define digit(x) ((int)log10((double)(x)) + 1)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define out(x) for(auto i : x) cout << i << " "; cout << endl;
#define outln(x) for(auto i : x) cout << i << " " << endl;
#define vec_cpy(to,from) copy(all(to),back_inserter(from))
#define ary_cpy(to,from) memcpy(to, from, sizeof from)
#define MOD = 1000000007; 
#define DEBUG false

int main(){
  int n;cin >> n;
  int p1 = 0,p2 = 0,a[n],b[n],dis1[n] = {},dis2[n] = {};
  vec(int) w[n + 1];

  REP(i,1,n){
    cin >> a[i] >> b[i];
    w[a[i]].pb(i);
    w[b[i]].pb(i);
  }

  function<void(int,int,int)> dfs = [&](int point,int cost,int befor){
    if(DEBUG) cout << "p:" << point << endl;
    for(int i : w[point]){
      if(a[i] == point && b[i] != befor){
        dfs(b[i], cost + 1, point);
      }else if(b[i] == point && a[i] != befor){
        dfs(a[i], cost + 1, point);
      }
      dis1[point - 1] = cost;
    }
  };

  dfs(1,0,0);
  ary_cpy(dis2,dis1);
  dfs(n,0,0);
  rep(i,n){
    if(dis1[i] < dis2[i]) p1++;
    else p2++;
  }

  cout << (p1 < p2 ? "Fennec" : "Snuke");
  return 0;
}

Measured memory_bytes: 18176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long INF = 1LL << 60;

int main(){
  ll N, Y;
  cin >> N >> Y;
  for (int i = 0; i <= N; i++){
    for (int j = 0; i + j <= N; j++){
      ll k = N - i - j;
      if(10000*i+5000*j+1000*k==Y){
        cout << i << " " << j << " " << k << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}

Measured memory_bytes: 3596
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] nums = new int[N];
    for (int i = 0; i < N; i++) {
      nums[i] = sc.nextInt();
    }
    int[] newNums = new int[N];
    System.arraycopy(nums, 0, newNums, 0, N);
     Arrays.sort(newNums);
    
    for (int i = 0; i < N; i++) {
      if (nums[i] > newNums[N / 2 - 1]) {
        System.out.println(newNums[N / 2 - 1]);
      } else {
         System.out.println(newNums[N / 2]);
      }
    }  
  }
}

Measured memory_bytes: 89428
#include <iostream>
#include <vector>

void show_cells(std::vector<std::vector<char>>& cells) {
    for (auto &&row : cells) {
        for (auto && elem : row) {
            std::cout << elem;
        }
        std::cout << std::endl;
    }
}

void delete_row(std::vector<std::vector<char>>& cells) {
    size_t idx = 0;
    auto row = std::begin(cells);
    while (row != cells.end()) {
        //std::cout << "idx: " << idx << std::endl;
        bool all_white = true;
        for (auto && elem : *row) {
            if (elem != '.') {
                all_white = false;
                break;
            }
        }
        if (all_white) {
            //std::cout << "all white column found!" << std::endl;
            row = cells.erase(std::begin(cells) + idx); 
        } else {
            idx++;
            row++;
        } 
        //std::cout << "next iteration!" << std::endl;
    }
}

void delete_column(std::vector<std::vector<char>>& cells) {
    bool delete_list[100];
    for (auto &&e : delete_list) e = true;
    
    for (size_t row=0; row<cells.size(); ++row) {
        for (size_t i=0; i<cells[row].size(); ++i) {
            if (cells[row][i]=='#') {
                delete_list[i] = false;
            }
        }
    }
    
    for (size_t row=0; row<cells.size(); ++row) {
        size_t idx = 0;
        //for (auto iter = cells[row].begin(); iter != cells[row].end(); iter++) {
        auto iter = cells[row].begin();
        while (iter != cells[row].end()) {
            if (delete_list[idx]) {
                iter = cells[row].erase(iter);
                //std::cout << "delete: row " << row << ", column " << idx << std::endl;
            } else {
                iter++;
            }
            idx++;
        }
    }
}

int main() {
    std::vector<std::vector<char>> cells;
    std::vector<char> c_vector;
    
    int H, W;
    char temp;
    std::cin >> H >> W;
    
    for (int row=0; row<H; row++) { 
        for (int column=0; column<W; column++) {
            std::cin >> temp;
            c_vector.push_back(temp);
        }
        cells.push_back(c_vector);
        c_vector = {};
    }
    delete_row(cells);
    delete_column(cells);
    show_cells(cells); 
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    s=chomp(readline())
    day=Dict{String,Int}("MON"=>6,"TUE"=>5,"WED"=>4,"THU"=>3,"FRI"=>2,"SAT"=>1,"SUN"=>7)
    println(day[s])
end
main()

Measured memory_bytes: 110372
import std;

// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}
T[] lreads(T=long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}
void arywrite(T=long)(T[] ary){ary.map!(text).join(' ').writeln;}
void scan(TList...)(ref TList Args){auto line = readln.split;
foreach (i,T;TList){T val=line[i].to!(T);Args[i]=val;}}
void dprint(TList...)(TList Args){debug{auto s=new string[](TList.length);
static foreach(i,a;Args) s[i]=text(a);s.map!(text).join(' ').writeln;}}
alias sread=()=>readln.chomp();enum MOD =10^^9+7;
alias PQueue(T,alias less="a<b") = BinaryHeap!(Array!T,less);
// dfmt on

void main()
{
    long N = lread();
    auto A = aryread();
    long ans;
    auto diff = new long[](N);
    foreach (i; 0 .. N)
        diff[i] = (i + 1) - A[i];
    auto l = new long[][](2 * 10 ^^ 5 + 1);
    foreach (i; 0 .. N)
        if (diff[i] < l.length)
            l[diff[i]] ~= i;
    foreach (i; 0 .. N)
    {
        if (A[i] + i + 1 < l.length)
            ans += assumeSorted(l[A[i] + i + 1]).upperBound(i).length;
    }
    writeln(ans);
}


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

int main(){
    long double a,b,c;
    cin >> a >> b >> c;
    cout << ((a+b+2*sqrt(a*b)<c)?"Yes":"No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
void solve() {
  int n;
  cin >> n;
  vector<int> w(n);
  rep(i, n) cin >> w[i];
  int ans = 100000;
  for(int t = 0; t < n; t++) {
    int s1 = 0;
    int s2 = 0;
    rep(j, n) {
      if (j <= t) s1 += w[j];
      else s2 += w[j];
    }
    ans = min(ans, abs(s1-s2));
  }
  cout << ans << endl;
}
 
int main() {
  solve();
  return 0;
}

Measured memory_bytes: 256
using System;

public class p1000
{
	p1000(){
		string str;
		string[] st;
		
		while((str=Console.ReadLine()) != null){
			st = str.Split(' ');
			Console.WriteLine("{0}", (int.Parse(st[0])+int.Parse(st[1])));
		}
	}
	
	public static int Main(string[] args){
		new p1000();
		return 0;
	}
}

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

int main() {
  string s;
  cin >> s;
  int co=0;
  int ans=0;
  rep(i,s.size()){
    if(s.at(i)=='T'){
      co++;
    }
    else{
      co--;
    }
    ans=max(ans,co);
  }
 
  cout<<ans*2<<endl;
  
  
 
}






Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int cnt[4];

signed main() {
	int a, b;
	
	for (int i = 0; i < 3; i++) {
		cin >> a >> b;
		a--; b--;
		cnt[a]++;
		cnt[b]++;
	}
	
	for (int i = 0; i < 4; i++) {
		if (cnt[i] >= 3) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))
k = 0
for i in a:
    if i % 2 == 0:
        if i % 3 == 0 or i % 5 == 0:
            pass
        else:
            k += 1
    else:
        pass

if k != 0:
    print('DENIED')
else:
    print('APPROVED')

Measured memory_bytes: 2940
n,q=[int(i) for i in input().split(" ")]
A=[[] for i in range(n)]

for _ in range(q):
    query=[int(i) for i in input().split(" ")]
    if query[0]==0:
        A[query[1]].append(query[2])
    elif query[0]==1:
        print(" ".join([str(j) for j in A[query[1]]]))
    else:
        A[query[1]]=[]



Measured memory_bytes: 60512