akhauriyash/Code-Regression huggingface dataset:
//E
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool G[20][1010];
int pre[20][1010];
int main(){
	int h,w,k;
	cin >> h >> w >> k;
	for(int i = 1;i <= h;i++){
		string s;
		cin >> s;
		for(int j = 0;j < w;j++){
			G[i][j+1] = s[j]-'0';
			pre[i][j+1] = pre[i][j] + G[i][j+1];
		}
	}
	ll ans = 1e17+10;
	int M = (1<<(h-1));
	for(int d = 0;d < M;d++){
		auto bit = bitset<31>(d);
		ll lst = 0,tans = 0,bcnt = 0;
		for(int i = 0;i < 30;i++)if(bit[i])bcnt++;
		for(int j = 1;j <= w;j++){
			ll cnt = 0,tcnt = 0;
			for(int i = 1;i <= h;i++){
				tcnt += pre[i][j] - pre[i][lst];
				if(bit[i-1]){
					cnt = max(cnt,tcnt);
					tcnt = 0; 
				}
			}
			cnt = max(cnt,tcnt);
			if(cnt > k){
				tans++;
				if(j-1 == lst){
					tans = 1e9;break;
				}
				lst = j-1;
			}
//			else if(cnt == k and j != w){
//				tans++;
//				if(lst == j){
//					tans = 1e9;break;
//				}
//				lst = j;
//			}
		}
		ans = min(ans,tans+bcnt);
//		cout << tans << " " << bcnt << endl;
	}
	cout << ans;
	return 0;
}


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

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

	int min = 10;
	int last = 0;
	int cnt = 0;
	for (int i = 0; i < 5; i++) {
		if (a[i] % 10 != 0) {
			cnt++;
			if (a[i] % 10 < min) {
				min = a[i] % 10;
			}
		}
	}

	int ans = 0;
	if (0 < cnt) {
		ans = (cnt-1) * 10;
	}
	for (int i = 0; i < 5; i++) {
		ans += a[i] / 10 * 10;
	}
	if (1 < cnt) {
		ans += min;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////
ll n,m;
matrix gra(52);
vector<PLL> vp;
Vi seen(52,0);
ll dfs(ll s,ll st,ll en){
    for(auto nxt:gra[s]){
        if(s==st&&nxt==en) continue;
        if(s==en&&nxt==st) continue;
        if(seen[nxt]==0){
            seen[nxt]=1;
            dfs(nxt,st,en);
        }
    }
    ll ctr=0;
    for(auto l:seen){
        if(l==1) ctr++;
    }
    return ctr;
}
void solve(){
    cin >> n >> m;
    rp(i,m){
        ll a,b;
        cin >> a >> b;
        a--; b--;
        gra[a].pb(b);
        gra[b].pb(a);
        vp.pb(mp(a,b));
    }
    ll ans=0;
    rp(i,m){
        ll st=vp[i].first, en=vp[i].second;
        ll num=dfs(0,st,en);
        if(n!=num) {
            ans++;
            //print(i);
        }
        fill(all(seen),0);
    }
    print(ans);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3640
# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))


def solve():

    N = int(input())

    counts = [0] * (N+1)

    for x in range(1, 101):
        for y in range(1, 101):
            for z in range(1, 101):
                n = x*x + x*y + x*z + y*y + y*z + z*z
                if n <= N:
                    counts[n-1] += 1

    return counts[:N]


def main():
    print(*solve())


if __name__ == "__main__":
    main()


Measured memory_bytes: 9132
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define maxn 100005
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define sz(x) (int)((x).size())
# define int ll
using namespace std;

int n,f[105][105],cnt[105],ans = -1e18,p[105][105];

int32_t main(){_
    //freopen("input","r",stdin);
	cin >> n;
	for(int i = 1;i <= n;i++)
	{
		for(int j = 0;j < 5;j++)
		{
			cin >> f[i][j] >> f[i][j + 5];
		}
	}
	for(int i = 1;i <= n;i++)
	{
		for(int j = 0;j <= 10;j++)
		{
			cin >> p[i][j];
		}
	}
	for(int mask = 1;mask < (1 << 10);mask++)
	{
		vector<int>vec;
		memset(cnt,0,sizeof(cnt));
		for(int j = 0;j < 10;j++)
		{
			if(mask & (1 << j))
			{
				for(int i = 1;i <= n;i++)
				{
					cnt[i] += f[i][j];
				}
			}
		}
		int x = 0;
		for(int i = 1;i <= n;i++) x += p[i][cnt[i]];
		ans = max(ans,x);
	}
	rc(ans);
}


Measured memory_bytes: 384
import math

N, K = map(int, input().split())
A = list(map(int, input().split()))

gcd = A[0]

if N == 1:
	if K == A[0]:
		print('POSSIBLE')
		exit()
	else:
		print('IMPOSSIBLE')
		exit()

for i in range (0, N):
	if gcd > 1:
		gcd = math.gcd(gcd, A[i])
	else:
		break
        
if gcd == 1:
	print('POSSIBLE')
elif K%gcd ==0 and K <= max(A):
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')

Measured memory_bytes: 20204
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n,m;
  cin >> n >> m;
  vector<int> l(m);
  vector<int> r(m);
  for(int i=0;i<m;i++)cin >> l[i] >> r[i];
  sort(l.begin(),l.end());
  sort(r.begin(),r.end());
  int ans = r[0] - l[m-1]+1;
  if(ans<0)cout << 0 << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 10000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

signed main() {
	int n, ans = INF;
	cin >> n;
	for (int i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ans = min(ans, (i + n / i) - 2);
		}
	}
	cout << ans << endl;

	return 0;
}


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

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

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define Itr(i, c) for(typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define pb push_back

const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int MAX = 510000;
const int INF = 999999999;
const int MOD = 1000000007;

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.pb(make_pair(p, num));
    }
    if (n != 1) res.pb(make_pair(n, 1));
    return res;
}

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}

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

int main(){
	int n, m; cin >> n >> m;
	n--;
	ll ans = 1;
	COMinit();
	vector<pair<ll, ll> > vec = prime_factorize(m);
	Rep(i, vec.size()){
		ll t = COM(vec[i].second + n, n);
		ans = (ans * t) % MOD;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 12160
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
ab.sort(key=lambda x: x[1])
c = 0
d = 0
for t in ab:
  if d < t[0]:
    c += 1
    d = t[1]-1
print(c)

Measured memory_bytes: 29084
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
using namespace std;

using ll = long long;
const int INF = 1001001001;

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

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

  vector<int> sosuulist;
  vector<int> epi(55555+1, 0);
  for (int i = 2; i <= 55555; i++) {
    if (epi[i] == 0) {
      for (int j = i; j <= 55555; j += i) {
        epi[j] = -1;
      }
      if (i > 5 && i % 5 == 1) {
        sosuulist.push_back(i);
      }
    }
  }

  for (int i = 0; i < n; i++) {
    cout << sosuulist[i] << " ";
  }
  cout << endl;
}


Measured memory_bytes: 512
loop do
  n = gets.to_i
  break if n.zero?
  cs = n.times.map { gets.split(/,/).map(&:to_f) }
  check = lambda do |a, b, c, d, x, y|
    a <= x && x <= c && b - 1 <= y && y <= d + 1 ||
    b <= y && y <= d && a - 1 <= x && x <= c + 1 ||
    (x-a)**2 + (y-b)**2 <= 1 ||
    (x-a)**2 + (y-d)**2 <= 1 ||
    (x-c)**2 + (y-b)**2 <= 1 ||
    (x-c)**2 + (y-d)**2 <= 1
  end
  r = 1
  rec = lambda do |a, b, c, d|
    p, q = (a+c)/2, (b+d)/2
    [[a, b, p, q], [p, b, c, q], [a, q, p, d], [p, q, c, d]].map {|as| [-cs.count {|x, y| check[*as, x, y] }, as] }.sort!.each do |m, as|
      m = -m
      if m > r
        if as[2] - as[0] < 1e-6
          r = m
          break
        end
        rec[*as]
      else
        break
      end
    end
  end
  rec[0.0, 0.0, 10.0, 10.0]
  p r
end

Measured memory_bytes: 10916
#include<stdio.h>

int main()
{
    int h,w;
    scanf("%d %d", &h, &w);

    while(h!=0 && w!=0) {
      for(int i=0; i<h; ++i) {
        for(int j=0; j<w; ++j)
          printf("#");
        printf("\n");
      }
      
      printf("\n");
      scanf("%d %d", &h, &w);
    }

    return 0;
}



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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> W(N);
  for (int i = 0; i < N; i++) cin >> W[i];
  int total = accumulate(W.begin(), W.end(), 0);
  int left = 0;
  int answer = numeric_limits<int>::max();
  for (int i = 0; i < N; i++) {
    left += W[i];
    int right = total - left;
    answer = min(answer, abs(right - left));
  }
  cout << answer;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long INF = 1LL << 60;
template <class T> bool chmin(T& a, T b){if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b){if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

bool included(vector<string> V, string S)
{
  int N = V.size();
  for (int i = 0; i < N; i++)
  {
    if (V.at(i) == S) return true;
  }
  return false;
}

int main()
{
  int N;
  cin >> N;
  string S0, S1;
  cin >> S0;
  vector<string> history;
  history.push_back(S0);
  
  string ans = "Yes";
  for (int i = 1; i < N; i++)
  {
    cin >> S1;
    if (S0.at(S0.size() - 1) != S1.at(0) || included(history, S1)) 
    {
      ans = "No";
      break;
    }
    history.push_back(S1);
    S0 = S1;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <climits>

#define PI 3.14159265359

using namespace std;
using ll = long long;
using pint = pair<int, int>;

int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	
	ll ans = LLONG_MIN;

	ans = max(ans, a * c);
	ans = max(ans, a * d);
	ans = max(ans, b * c);
	ans = max(ans, b * d);

	cout << ans << endl;

	return 0;
}



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

using namespace std;

#define gc getchar_unlocked
#define foi(i,n) for(int i=0;i<n;i++)
#define Foi(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define fol(i,n) for(ll i=0;i<n;i++)
#define Fol(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pl;
typedef vector<int>     vi;
typedef vector<ll>      vl;
typedef vector<pii>     vpii;
typedef vector<pl>      vpl;
typedef vector<vi>      vvi;
typedef vector<vl>      vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

int mpow(int base, int exp) {
    base %= mod;
    int result = 1;
    while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
    }
    return result;
}

void ipgraph(int n, int m){
    int i, u, v;
    while(m--){
        cin>>u>>v;
        g[u-1].pb(v-1);
        g[v-1].pb(u-1);
    }
}

void dfs(int u, int par){
    for(int v:g[u]){
        if (v == par) continue;
        dfs(v, u);
    }
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s,t;
    cin>>s>>t;
    if(s==t.substr(0,t.length()-1))
        cout<<"Yes\n";
    else
    {
        cout<<"No\n";
    }
    return 0;
}

Measured memory_bytes: 10672
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repk(i,m,n) for(int i=m;i<n;i++)
#define OKawaiiKoto ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const ll INF=2*1e18;
const ld PI=3.14159265358979323846;
int main()
{
    //freopen("running_on_fumes_chapter_1_input.txt","r",stdin);
    //freopen("sol.txt","w",stdout);
    OKawaiiKoto
    ll x;
    cin>>x;
    cout<<10-x/200;
}


Measured memory_bytes: 3652
// 2013/07/05 Tazoe

#include <iostream>
using namespace std;

void DFS(int M[52][52], int y, int x)
{
	M[y][x] = 0;

	if(M[y-1][x]==1)
		DFS(M, y-1, x);
	if(M[y-1][x+1]==1)
		DFS(M, y-1, x+1);
	if(M[y][x+1]==1)
		DFS(M, y, x+1);
	if(M[y+1][x+1]==1)
		DFS(M, y+1, x+1);
	if(M[y+1][x]==1)
		DFS(M, y+1, x);
	if(M[y+1][x-1]==1)
		DFS(M, y+1, x-1);
	if(M[y][x-1]==1)
		DFS(M, y, x-1);
	if(M[y-1][x-1]==1)
		DFS(M, y-1, x-1);
}

int main()
{
	while(true){
		int w, h;
		cin >> w >> h;

		if(w==0 && h==0)
			break;

		int M[52][52];
		for(int y=0; y<h+2; y++){
			for(int x=0; x<w+2; x++){
				M[y][x] = 0;
			}
		}

		for(int y=1; y<=h; y++){
			for(int x=1; x<=w; x++){
				cin >> M[y][x];
			}
		}

		int cnt = 0;

		for(int y=1; y<=h; y++){
			for(int x=1; x<=w; x++){
				if(M[y][x]==1){
					cnt++;
					DFS(M, y, x);
				}
			}
		}

		cout << cnt << endl;
	}

	return 0;
}

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

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

	int count=0;
	for (int i=0;i<q;++i)
	{
		int target=t[i];
		int minimum=0;
		int maximum=s.size();
		bool end_flag=false;
		while (end_flag==false)
		{
			if (maximum-minimum>1)
			{
				int mid=(minimum+maximum)/2;
				if (s[mid]==target)
				{
					++count;
					end_flag=true;
				}
				else if (s[mid]>target)
				{
					maximum=mid;
				}
				else
				{
					minimum=mid+1;
				}
			}
			else
			{
				if ((s[minimum]==target)||(s[maximum]==target))
				{
					++count;
				}
				end_flag=true;
			}
		}
	}
	cout << count << endl;
}









Measured memory_bytes: 3340
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <cassert>
#include <complex>
#include <iomanip>
#include <random>

using namespace std;

typedef long long ll;
#define int long long

int M = (int)1e9 + 7;
#define msum(a, b) ((a) + (b) >= M ? (a) + (b) - M : (a) + (b))
#define msub(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define mmult(a, b) (((a) * (b)) % M)

typedef long double ld;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vlll;
typedef vector<double> vd;
typedef vector<vd> vdd;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpi;
#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SZ(a) ((int)(a).size())
#define watch(x) cout << (#x) << " = " << (x) << endl;

const double PI = 2 * acos(0.0);
const int oo = 1e18 + 100;
const string DIGITS = "0123456789", alph = "abcdefghijklmnopqrstuvwxyz", ALPH = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

//THE END OF TEMPLATE////////////////////////////////////////////////////////////////////////////////

#define N 100100

vi g[N];


int dp[N][2];

void dfs(int v, int pr)
{


	int cher = 1, vse = 1;

	for (int i = 0; i < g[v].size(); i++)
	{
		int to = g[v][i];
		if (to != pr) {
			dfs(to, v);
			cher = mmult(cher, dp[to][1]);
			vse = mmult(vse, msum(dp[to][0], dp[to][1]));
		}
	}

	dp[v][0] = cher;
	dp[v][1] = vse;


}




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

	int n;
	cin >> n;

	for (int i = 0; i < n - 1; i++)
	{
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}


	dfs(1, 0);
	cout << msum(dp[1][0], dp[1][1]);


}

//m1.codeforces.com, m2.codeforces.com или m3.codeforces.com

Measured memory_bytes: 14208
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;

long long h,w,n,uk,veci,manji,ob,br;

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

cin >> h >> w >> n;

uk  = h*w;

if (h>w)
	veci = h;
else 
	veci = w;
	
if (h<w)
	manji = h;
else 
	manji = w;
	
while (ob < n && uk/veci > 0){
	ob+= veci;
	uk -= veci;
	br++;
}
while (ob < n && uk/manji > 0){
	ob+= manji;
	uk -= manji;
	br++;
}

cout << br;
return 0;
}



Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

N = int(input())

lucas = [2, 1]

if N == 1:
    print(1)
    quit()

for n in range(2, N+1):
    tmp = lucas[n-1] + lucas[n-2]
    lucas.append(tmp)

ans = lucas[N]
print(ans)



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

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

	if(s.at(0) != s.at(1) && s.at(1) != s.at(2) && s.at(2) != s.at(0)) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct item
{
	int num , x , y;
};
int n , m , sx , sy , tx , ty , ans[1100][1100] , mp[1100][1100];
int fx[4] = {0 , 1 , 0 , -1} , fy[4] = {1 , 0 , -1 , 0};
string s;
deque< item > q;
void bfs()
{
	q.push_front((item){0 , sx , sy});
	while(!q.empty())
	{
		int x = q.front().x , y = q.front().y , qwq = q.front().num;
		q.pop_front();
		if(ans[x][y] >= 0) continue;
		ans[x][y] = qwq;
		for(int i = 0 ; i < 4 ; i++ )
		{
			if(x + fx[i] > n || x + fx[i] < 0 || y + fy[i] > m || y + fy[i] < 0)
			continue; 
			if(ans[x + fx[i]][y + fy[i]] < 0 && mp[x + fx[i]][y + fy[i]])
			q.push_front((item){ans[x][y] , x + fx[i] , y + fy[i]});
		}
		for(int i = -2 ; i <= 2 ; i++ )
		{
			for(int j = -2 ; j <= 2 ; j++ )
			{
				if(x + i > n || x + i < 0 || y + j > m || y + j < 0) continue; 
				if(ans[x + i][y + j] < 0 && mp[x + i][y + j])
				q.push_back((item){ans[x][y] + 1 , x + i , y + j});
			}
		}
	}
}
int main()
{
	cin.tie(0); cout.tie(0);
	memset(ans , -1 , sizeof(ans));
	scanf("%d%d%d%d%d%d" , &n , &m , &sx , &sy , &tx , &ty);
	for(int i = 1 ; i <= n ; i++ )
	{
		cin >> s;
		for(int j = 1 ; j <= m ; j++ ) mp[i][j] = (s[j - 1] == '.');
	}
	bfs();
	printf("%d" , ans[tx][ty]);
    return 0;
}

Measured memory_bytes: 13388
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
const ll inf = 1e16;
const ll md = 1000000007;

int main() {
  int n,a,b;
  cin>>n>>a>>b;
  int ans=0;
  for(int x0=1;x0<=n;x0++){
    int sum_digi=0;
    int x=x0;
    rep(i,5){
      sum_digi+=x%10;
      x/=10;
    }
    if(a<=sum_digi && sum_digi<=b) ans+=x0;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

ll lcm(ll x, ll y){
    return x/__gcd(x,y)*y;
}

int main(){
    int n,m,d;
    cin >>n >>m >>d;

    vector<int> a(m);
    rep(i,m) cin >>a[i];

    vector<vector<int>> r(d, vector<int>(m));
    rep(i,d)rep(j,m) cin >>r[i][j];

    ll now = n;
    rep(i,d){
        ll nx = now;
        ll L = 1;
        rep(j,m){
            if(r[i][j] == -1) continue;

            vector<bool> vis(a[j]);
            while(nx>=0 && !vis[nx%a[j]] && nx%a[j]!=r[i][j]){
                vis[nx%a[j]] = true;
                nx -= L;
            }

            if(nx<0 || nx%a[j]!=r[i][j]){
                cout << -1 << endl;
                return 0;
            }

            L = lcm(L, a[j]);
        }
        now = nx;
    }
    cout << now << endl;
    return 0;
}



Measured memory_bytes: 3176
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect_left

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

s1 = input()
s2 = input()

def EditDistance(S, T):
    dp = [[INF]*(len(T)+1) for _ in range(len(S)+1)]
    dp[0][0] = 0
    for i in range(-1, len(S)):
        for j in range(-1, len(T)):
            if i == -1 and j == -1:
                continue
            if i >= 0 and j >= 0:
                if S[i] == T[j]:
                    dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j])
                else:
                    dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + 1)
            if i >= 0:
                dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j+1] + 1)
            if j >= 0:
                dp[i+1][j+1] = min(dp[i+1][j+1], dp[i+1][j] + 1)
    return dp[len(S)][len(T)]

print(EditDistance(s1, s2))



Measured memory_bytes: 43188
#include <cstdio>
#include <cmath>

using namespace std;

int main()
{
	int n, a[1000], min, temp;

	while (true)
	{
		scanf("%d", &n);
		if (n == 0)
		{
			break;
		}

		min = 1000000;

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

		for (int i = 0; i < n; ++i)
		{
			for (int j = 0; j < n; ++j)
			{
				if (j == i)
				{
					continue;
				}

				temp = abs(a[i] - a[j]);
				min = min > temp ? temp : min;
			}
		}

		printf("%d\n", min);
	}
}


Measured memory_bytes: 2772
k,n=(int(x) for x in input().split())
a_list=[int(x) for x in input().split()]
b_list=[]

first_element=k-a_list[n-1]+a_list[0]
b_list.append(first_element)
for b in range(n-1):
    b_list.append(a_list[b+1] - a_list[b])

max_value = max(b_list)

print(k-max_value)

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

int main(){
    int a[6];
    int sum=0;
    for(int i=0;i<6;i++){
        cin>>a[i];
        sum+=a[i];
    }
    
    int min=100;
    for(int j=0;j<4;j++){
        if(min>a[j])min=a[j];
    }
   
    sum=sum-min;
    
    if(a[4]>a[5])sum=sum-a[5];
    else sum=sum-a[4];
    
    cout<<sum<<endl;
}

Measured memory_bytes: 3068
int main()
{
    int H, W;
    int h, w;
 
    while (1) {
        scanf("%d%d", &H, &W);
        if (H == 0 && W == 0) break;
        for (h = 0; h < H; h++) {
            for (w = 0; w < W; w++) {
                putchar(((h & 1) ^ (w & 1)) == 0 ? '#' : '.');      }
            putchar('\n');
        }
        putchar('\n');
    }
    return 0;
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int a,b,i,cnt=0,n,m,c;
	cin>>a>>b;
	for(i=a;i<=b;i++)
	{
		m=i;
		n=i;
		c=0;
		while(n>0)
		{
			c=(c*10)+(n%10);
			n=n/10;
		}
		if(m-c==0)
		cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3560
#include<stdio.h>
int main() {
	int n, m, k,t;
	m = 0;
	k = 3000;
	int s[1004][2] = {};
	int ans[1004] = {};
	scanf("%d%d", &n,&t);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &s[i][0], &s[i][1]);
		if (t >= s[i][1]) {
			ans[m] = s[i][0];
			m++;
		}
	}
	if (m == 0) {
		printf("TLE");
		return 0;
	}
	for (int i = 0; i < m; i++) {
		if (ans[i] <= k)k = ans[i];
	}
	printf("%d", k);
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;
const ll INF = 1LL << 60;


int main() {
    int a,b,c; cin >> a >> b >> c;
    if(a <= c && c <= b) cout << "Yes" << endl;
    else if(b <= c && c <= a) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3576
#include<iostream>
#include<cstdio>
#include<map>
#include<vector>
#include<set>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#define maxn zhi5968
typedef long long ll;
using namespace std;

map<int,int> mp;
int a[200000+10],b[50];
bool cmp(int a,int b)
{
	return a>b;
}
void init ()
{
	b[0]=1;
	for(int i=1;i<40;i++)
		b[i]=b[i-1]*2;
}
int main()
{
	init();
	ll n,i,j,ans=0;
	scanf("%lld",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		mp[a[i]]++;
	}
	sort(a,a+n,cmp);
	for(i=0;i<n;i++)
	{
		if(!mp[a[i]])
			continue;
		else
			mp[a[i]]--;
		for(j=30;j>=0;j--)
		{
			if(mp[b[j]-a[i]])
			{
				ans++;
				mp[b[j]-a[i]]--;
				break;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 300160
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a=nxt(),b=nxt(),c=nxt();
    if(a+b+c>=22)
        cout<<"bust\n";
    else
        cout<<"win\n";
    
    

    return 0;   
}


 
 


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int a, b, c;
  cin >> a >> b >> c;

  if (a == b && b == c) {
    cout << "1" << endl;
  } else if (a == b || b == c || c == a) {
    cout << "2" << endl;
  } else {
    cout << "3" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
using namespace std;
#define ll long long
int main(){
    ll n, k, x, y, sum=0, mx=0;
    vector<ll> a, b;
    cin >> k >> n;
    for (int i=0; i<n; i++){
    	cin >> y;
    	a.push_back(y);
    }
    a.push_back(k+a[0]);
    for (int i=1; i<a.size(); i++){
    	b.push_back(a[i]-a[i-1]);
    }
    for (int i=0; i<b.size(); i++){
    	//cout << b[i] << " ";
    	sum+=b[i];
    	mx=max(mx,b[i]);
    }
    cout << sum-mx;
    return 0;
}

Measured memory_bytes: 4848
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    X = LI()
    ans = [0] * N
    sorted_X = sorted([(x, i) for i, x in enumerate(X)], key=lambda x: x[0])
    l = sorted_X[N//2 - 1][0]
    r = sorted_X[N//2][0]
    for i, (x, org_ix) in enumerate(sorted_X):
        if i < N//2:
            _ans = r
        else:
            _ans = l
        ans[org_ix] = _ans
    for a in ans:
        print(a)
main()



Measured memory_bytes: 123852
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m;i>n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl
#define Vecpr(K,L1,L2,N) vector<pair<L1,L2>> K(N)
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,R) vector<vector<L>> K(N, vector<L>(M,R))
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
   lli L,R,N,M,sum=0,num=0;
   cin >> L >> R;
   if(L/2019!=R/2019)Out(0);
   else{
      sum=INF;
      rep(i,L,R)rep(j,i+1,R+1)sum=min(sum,(i%2019*j%2019)%2019);
      Out(sum);
   }
}

Measured memory_bytes: 256
// E - This Message Will Self-Destruct in 5s
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	vector<ll> A(N+1);
	rp(i, 1, N+1) cin>>A[i];
	map<ll,ll> add,del;
	rp(i, 1, N+1){
		add[i+A[i]]++;
		del[i-A[i]]++;
	}
	ll ans = 0;
	for(auto a:add)
		ans += del[a.first] * a.second;
	cout<< ans <<endl;
}

Measured memory_bytes: 39008
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

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

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

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 / gcd(a, b) * b;
}

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

class mint {
    long long x;
public:
    mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
    mint operator-() const {
        return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res *= a;
    }

    mint operator^(const ll& t)const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD - 2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res /= a;
    }

    friend ostream& operator<<(ostream& os, const mint& m) {
        os << m.x;
        return os;
    }
};

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



int main() {
   
    ll N;
    cin >> N;
    vector<ll> A(N + 1);
    repn(i, N) cin >> A[i];

    ll ans = 0;
    ll v = 0;

    for (ll i = N; i >= 1; i--) {
        if (v > A[i]) { ans = -1; break; }
        else if (v < A[i]) { v = A[i]; ans +=A[i]; }
        v = max(v - 1, 0);
        
    }

    if (A[1]!=0) { ans = -1; }

    cout << ans;

	system("PAUSE");
}

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

Measured memory_bytes: 1744
import math
a,b,h,m=map(int,input().split())
c=h*60+m
d=(5.5*c)%360
num=0
if d>180:
    num=360-d
else:
    num=d
if num==0:
    print(abs(a-b))
elif num==180:
    print(a+b)
else:
    num2=(a*a)+(b*b)
    num3=(math.cos(math.radians(num)))*a*b*-2
    print(math.sqrt(num2+num3))


Measured memory_bytes: 9460
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;  cin>>n;
    string a="kougekida";
    string d="mamoru";
    string c="tameru";
    vector<string>v,u;
    rep(i,n){
        string temp;  cin>>temp;
        v.push_back(temp);
    }
    rep(i,n){
        string temp; cin>>temp;
        u.push_back(temp);
    }
    int vat=0,uat=0;
    for(int i=0; i<n;i++){
        string _u=u[i];
        string _v=v[i];
        if(_u=="kougekida"&&_v=="kougekida"){
            if(uat!=0&&vat==0)return puts("Nakajima-kun")*0;
            else if(uat==0&&vat!=0)return puts("Isono-kun")*0;
            else if(uat==vat){uat=0;vat=0; continue;}
            else{
                cout<<(vat>uat?"Isono-kun":"Nakajima-kun")<<endl;
                return 0;
            }
        }
        //one player atk and other player def
        if((_u==d&&_v==a)||(_v==d&&_u==a)){
            if(_u==d&&_v==a){
                if(vat==5){return puts("Isono-kun")*0;}
                if(vat==0)return puts("Nakajima-kun")*0;
                else vat=0;
            }else{
                if(uat==5)return puts("Nakajima-kun")*0;
                if(uat==0)return puts("Isono-kun")*0;
                else uat=0;
            }
        }
        //both player deffence or charge
        if((_u==d&&_v==c)||(_u==c&&_v==d)||(_u==d&&_v==d)||(_u==c&&_v==c)){
            if(_u==c)cmin(++uat,5);
            if(_v==c)cmin(++vat,5);
        }
        if((_v==a&&_u==c)||(_v==c&&_u==a)){
            if(_v==a&&vat==0)return puts("Nakajima-kun")*0;
            else if(_u==a&&uat==0)return puts("Isono-kun")*0;
            if(_v==a)return puts("Isono-kun")*0;
            else return puts("Nakajima-kun")*0;
        }
    }
    cout<<"Hikiwake-kun"<<endl;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    for (int i = 1; i <= x / 100; i++) {
        int t = x - i * 100;
        if (0 <= t && t <= i * 5) {
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 1004;
int a[maxn];
int main(){
	int n, k;
	cin >> n >> k;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	sort(a, a + n);
	int sum = 0;
	for(int i = 0; i < k; i++){
		sum += a[i];
	}
	cout << sum << endl;
	return 0;
} 

Measured memory_bytes: 3128
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> vll;
typedef deque<ll> dqll;

#define MOD 1000000007

int main() {
  ll N;

  cin >> N;

  ll Nslm = 1LL << N;

  vll slmLst(Nslm, 0);
  for (int i = 0; i < Nslm; i++) {
    cin >> slmLst[i];
  }

  sort(slmLst.begin(), slmLst.end());
  reverse(slmLst.begin(), slmLst.end());

  dqll curgen(1, slmLst[0]);
  slmLst[0] = -1;
  for (int i = 0; i < N; i++) {
    dqll pregen = curgen;
    sort(pregen.begin(), pregen.end());
    reverse(pregen.begin(), pregen.end());
    int j = 0;
    while (pregen.size() > 0 && j < Nslm) {
      if (slmLst[j] == -1) {
      } else if (pregen[0] > slmLst[j]) {
        pregen.pop_front();
        curgen.push_back(slmLst[j]);
        slmLst[j] = -1;
      }
      j++;
    }
    if (pregen.size() > 0) {
      puts("No");
      return 0;
    }
  }  // i

  puts("Yes");

  return 0;
}


Measured memory_bytes: 4480
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main(){ 
    int n; cin >> n;
    vector<ll> A(n); rep(i, n) cin >> A[i];

    vector<int> memo(1000100);
    bool is_pc = true;
    rep(i, n){
        if(A[i] > 1 && memo[A[i]])is_pc = false;
        memo[A[i]] = true;
    }
    for(int i=2; i<=1000000; i++){
        int cnt = 0;
        for(int j=i; j<=1000000; j+=i){
            if(memo[j])cnt++;
        }
        if(cnt>1)is_pc = false;
    }
    if(is_pc)cout <<  "pairwise coprime" << ln;
    else{
        ll GCD = A[0];
        rept(i, 1, n){
            GCD = __gcd(GCD, A[i]);
        }
        if(GCD==1)cout << "setwise coprime" << ln;
        else cout << "not coprime" << ln;
    }
}



Measured memory_bytes: 14728
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Ki | diff Ki.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Ki.cpp && ./a.out

/*
 
 8/18/2019
 
 21:06-
 
 */

const int MAX_N=1e6+1;
LL P[MAX_N];
VI G[MAX_N];
int N,Q;

LL res[MAX_N];
void dfs(int u, int pre, LL sum) {
  sum+=P[u];
  res[u]=sum;
  FORR(v,G[u])if(v!=pre) {
    dfs(v,u,sum);
  }
}

void solve() {
  dfs(0,-1,0LL);
  REP(u,N) printf("%lld ", res[u]);
  println("");
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>Q;
  REP(i,N-1) {
    int u,v; cin>>u>>v;
    --u,--v;
    G[u].push_back(v),G[v].push_back(u);
  }
  REP(i,Q) {
    int u,x; cin>>u>>x;
    --u;
    P[u]+=x;
  }
  solve();
  
  return 0;
}


Measured memory_bytes: 48000
using System;
class c
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int all = 0;
        for (int i = 0; i < n; i++)
        {
            all ^= a[i];
        }
        for (int i = 0; i < n; i++)
        {
            Console.Write("{0} ", all ^ a[i]);
        }
        Console.WriteLine();
    }
}

Measured memory_bytes: 50900
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int sum = 0;
		int[] A = new int[N + 2];
		int[] B = new int[N + 2];
		int[] C = new int[N + 2];
		A[0] = 0;
		A[N + 1] = 0;
		for (int i = 1; i < N + 1; i++) {
			A[i] = sc.nextInt();
		}
		if (A[1] < A[0]) {
			B[1] = A[0] - A[1];
		} else {
			B[1] = A[1] - A[0];
		}
		sum += B[1];

		for (int i = 2; i < N + 2; i++) {
			if (A[i] < A[i - 1]) {
				B[i] = A[i - 1] - A[i];
			} else {
				B[i] = A[i] - A[i - 1];
			}
			sum += B[i];
			if (A[i] < A[i - 2]) {
				C[i] = A[i - 2] - A[i];
			} else {
				C[i] = A[i] - A[i - 2];
			}
		}

		for (int i = 1; i < N + 1; i++) {
			System.out.println(sum - B[i] - B[i + 1] + C[i + 1]);
		}
	}
}

Measured memory_bytes: 65152
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
constexpr int mo2 = 998244353;
constexpr ll infl = 1ll<<60;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int x,y;
    cin>>x>>y;
    int ans = 0;
    if(x == 1 and y == 1) ans += 400000;
    if(x == 1)ans += 300000;
    else if(x== 2)ans += 200000;
    else if(x == 3)ans += 100000;
        if(y == 1)ans += 300000;
    else if(y== 2)ans += 200000;
    else if(y == 3)ans += 100000;
    cout << ans << endl;
    return 0;
}



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

using namespace std;

int main(){
    int n; 
    int l;
    cin>>n;
    cin>>l;
    int flag = 0;
    if( l > 0 ){
        flag = 1;
    }
    int end = 0; 
    if ( l +n -1 < 0)
        end = 1;
    
    int s = 0;
    for(int i =  flag  ; i <  n - end ; i ++)
    {
        s+= l + i;

    }
        
        cout<<s;

  

  

    return 0;
}

Measured memory_bytes: 256