akhauriyash/Code-Regression huggingface dataset:
def modpow(a, n, mod)
  if n > 0 && mod > 1
    exp = Math.log(n, 2).floor
    rep = modpow_cl(a, n, exp, mod)
    return rep[0]
  elsif mod == 1
    return 0
  else
    return 1
  end
end

def modpow_cl(a, n, exp, mod)
  if exp < 0
    rep = [1, a]
  else
    if n >= 2**exp
      rep = modpow_cl(a, n-2**exp, exp-1, mod)
      rep[0] = rep[0]*rep[1] % mod
    else
      rep = modpow_cl(a, n, exp-1, mod)
    end
    rep[1] = rep[1]**2 % mod
  end
  return rep
end

def popcntRec(num, cnt)
  return cnt if num == 1
  maxexp = Math.log(num, 2).floor
  pcnt = 0
  tmp = num
  for i in 0..maxexp
    exp = maxexp - i
    ifdiv = tmp / (2**exp)
    tmp -= ifdiv * (2**exp)
    pcnt += ifdiv
  end
  if num % pcnt == 0
    return cnt
  else
    return popcntRec(num % pcnt, cnt+1)
  end
end

n = gets.to_i
x = gets.split("").map(&:to_i)

cnt1 = 0
x.each{|xe| cnt1 += 1 if xe == 1}

modsLar = Array.new(n,0)
modsSma = Array.new(n,0)

for i in 0..(n-1)
  modsLar[i] = modpow(2, n-1-i, cnt1+1)
  modsSma[i] = modpow(2, n-1-i, cnt1-1) if cnt1 > 1
end

sumorgnLar = 0
sumorgnSma = 0
for i in 0..(n-1)
  sumorgnLar = (sumorgnLar + modsLar[i]) if x[i] == 1
  sumorgnSma = (sumorgnSma + modsSma[i]) if x[i] == 1
end

ans = Array.new(n,0)
for i in 0..(n-1)
  if x[i] == 0
    modrslt = (sumorgnLar + modsLar[i]) % (cnt1+1)
    if modrslt == 0
      ans[i] = 1
    else
      ans[i] = popcntRec(modrslt, 2)
    end
  else
    if cnt1 > 1
      modrslt = (sumorgnSma - modsSma[i]) % (cnt1-1)
      if modrslt == 0
        ans[i] = 1
      else
        ans[i] = popcntRec(modrslt, 2)
      end
    else
      ans[i] = 0
    end
  end
end

for i in 0..(n-1)
  puts ans[i]
end

Measured memory_bytes: 36848
#include<iostream>
using namespace std;
int main() {
	unsigned long long a,b,c;
	a = 2;
	b= 1;
	int n;
	cin >> n;
	for (int i = 0; i < n-1; i++) {
		c = a + b;
		a = b;
		b = c;
	}
	cout << b;
	return 0;
}

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

typedef pair<int,int> P;
const int INF = 1e+8;

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

map<P,int> m;

void init(){
	for(int y = -100 ; y <= 100 ; y++ ){
		for(int x = -100 ; x <= 100 ; x++ ){
			m[P(x,y)] = INF;
		}
	}
}


int solve(int sx, int sy, int t){
	queue<P> q;
	q.push( P(sx,sy) );
	m[P(sx,sy)] = 0;
	while( !q.empty() ){
		int x = q.front().first;
		int y = q.front().second;
		q.pop();

		for(int i=0 ; i < 6 ; i++ ){
			int mx = x + dx[i];
			int my = y + dy[i];
			if( m[P(mx,my)] == -1 ) continue;
			if( m[P(mx,my)] == INF && m[P(x,y)] + 1 <= t ){
				m[P(mx,my)] = m[P(x,y)] + 1;
				q.push( P(mx,my) );
			}
		}
	}
	int cnt = 0;
	for(int y = -100 ; y <= 100 ; y++ ){
		for(int x = -100 ; x <= 100 ; x++ ){
			if( m[P(x,y)] != -1 && m[P(x,y)] != INF )
				cnt++;
		}
	}
	return cnt;
}

int main(){
	int t, n;
	while( cin >> t >> n , t || n ){
		init();
		
		for(int i=0 ; i < n ; i++ ){
			int x,y;
			cin >> x >> y;
			m[P(x,y)] = -1;
		}
		int sx, sy;
		cin >> sx >> sy;
		int ans = solve( sx , sy , t );
		cout << ans << endl;
	}	
}

Measured memory_bytes: 2192
#include <iostream>
#include <cstdio>
#include <algorithm>

#define cmmdc __gcd
#define debug 0

using namespace std;

inline int ab(int a)
{
    return (a < 0 ? -a : a);
}

int n, d, i;
int gcd;
int v[100005];

int main()
{
    #if debug == 1
    freopen("f.in", "r", stdin);
    freopen("f.out", "w", stdout);
    #endif // debug

    cin >> n >> d;

    for(i = 1; i <= n; i ++)
    {
        cin >> v[i];
        v[i] = ab( v[i] - d );
    }
    gcd = v[1];
    for(i = 2; i <= n; i ++)
    {
        gcd = cmmdc(gcd, v[i]);
    }
    cout << gcd;

    return 0;
}


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

using namespace std;

int main(){
    string s;
    cin >> s;
    long int a = 0;
    for(int i = 0; i < s.size(); ++i){
        a = (a + s[i] - '0') % 9;
    }

    if(a == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3704
#include <stdio.h>
#include<string.h>
int main()
{
long int a=0,b=0,c=0,d=0,w=0,i,str1=0,str2=0,flag,j,count=1;
char x[101];
scanf("%ld %ld %ld %ld",&a,&b,&c,&d);
if(a*b==c*d)
{
    printf("%ld",a*b);
}
else{
    if(a*b>c*d)
    {
        printf("%ld",a*b);
    }else{
        printf("%ld",d*c);
    }
}
    

 return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

#define INF 0x3fffffff

int n;
int ans=INF;

int work(int x){
    int cnt=0;
    while(x){
        cnt+=x%10;
        x/=10;
    }
    return cnt;
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n/2;i++){
        int j=n-i;
        ans=min(ans,work(i)+work(j));
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main(){
    int k, s, ans=0;
    cin >> k >> s;
    rep(i, k+1){
        rep(j, k+1)if(s-i-j <= k && s-i-j >= 0)ans++;
    }
    cout << ans;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<set>
#include<bitset>
#include<cmath>
#include<numeric>
#include<limits>
#include<functional>
#include <bitset>

#define REP(i, m, n) for(int i = (m); i < (n); i++)
#define rep(i,n) REP(i,0,n)
#define NIL -1
using namespace std;
typedef long long ll;
typedef long long int lli;
static const int MOD = 10000007;
static const int MAX = 100005;
// static const int NMAX = 5005;
static const lli INFTY = 1000000000000;

// typedef priority_queue<int, greater<int>> RevQ;
int N, K;
lli A, B;
// vector<pair<int, int>> a(MAX);

lli gcd(lli a, lli b) {
  return b ? gcd(b, a%b) : a;
}

int main(){
  cin >> A >> B;
  if (A < B) swap(A,B);
  lli d = gcd(A, B);
  // cout << "d: " << d << endl;
  lli D = d;
  int cnt = 1;
  lli i = 2;
  while (i <= sqrt(d)) {
    int flag = 0;
    if (i == 2) {
      while (d % i == 0) {
        flag = 1;
        d /= i;
      }
      if (flag) {
        // cout << "i: " << i << endl;
        cnt++;
      }
      i += 1;
    } else {
      while (d % i == 0) {
        flag = 1;
        d /= i;
      }
      if (flag) {
        // cout << "i: " << i << endl;
        cnt++;
      }
      i += 2;
    }
  }
  if (d != 1) {
    // cout << "i: " << d << endl;
    cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string  a, b, c;
  cin >> a >> b >> c;
  if(a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

int main(){
	int n, m;
	while(cin >> n >> m){
		int sum = 0;
		while(n--){
			int x;
			cin >> x;
			if(x >= m) sum++;
		}
		printf("%d",sum);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
 
using namespace std;

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

    vector<int> V,C;

    int sum = 0;

    for(int i = 0; i < N; i++){
        int v;
        cin >> v;

        V.push_back(v);
    }

    for(int i = 0; i < N; i++){
        int c;
        cin >> c;

        C.push_back(c);
    }

    for(int i = 0; i < N; i++){
        if(V[i] - C[i] > 0){
            sum += V[i] - C[i];
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std ;
bool cmp(int a,int b)
{
	return a>b ;
}
int a[100005] ;
int main()
{
	int m , n ;
	cin >> n >> m ;
	int total = 0 ;
	for(int i = 0 ; i < n ; i++)
	{
		cin >> a[i] ;
		total += a[i] ;
	}
	sort(a,a+n,cmp) ;
	double line = total / (4.00 * m) ;
	if(a[m - 1] >= line)
		cout << "Yes" << endl ;
	else
		cout << "No" << endl ;
	return 0 ;
} 

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int n;
long long ans;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	if (i%3!=0 && i%5!=0) ans+=i;
	printf("%lld\n",ans);
return 0;
}

Measured memory_bytes: 3828
import Control.Applicative

-- 1行をStringとして読む
getStr :: IO String
getStr = getLine

-- 1行をIntとして読む
getInt :: IO Int
getInt = readLn

-- スペース区切りの1行を[String]として読む
getStrList :: IO [String]
getStrList = words <$> getLine

-- スペース区切りの1行を[Int]として読む
getIntList :: IO [Int]
getIntList = map read . words <$> getLine

solve :: Int -> Int -> Int
solve a b = div (a * (a - 1) + b * (b - 1)) 2

main :: IO ()
main = do
    [a, b] <- getIntList
    print $ solve a b

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

using namespace std;

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

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

	P p = P(0, 0);

	long long int tt = 0;
	long long int x, y, t;
	bool hh = true;
	for (long long int i = 0; i < n; i++) {
		cin >> t >> x >> y;
		long long int t2 = abs(x - p.first) + abs(y - p.second);
		long long int t3 = t - tt;

		if (t2 <= t3 && (t3 - t2) % 2 == 0) {

		}
		else {
			hh = false;
		}
		//cout << t2 << ' ' << t3 << endl;
		p = P(x, y);
		tt = t;
	}

	if (hh) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
a=int(input())
b=list(map(int,input().split()))
hantei=0
for i in range(a):
    if b[i]%2==0:
        if (b[i]%3!=0)and(b[i]%5!=0):
            hantei=1
if hantei==0:
    print('APPROVED')
else:
    print('DENIED')  

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <functional>
#include <algorithm>
#include <climits>

using namespace std;

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

struct Edge
{
	int to;
	int cost;
};

struct Node
{
	int city_index;
	int total_cost;
	int current_life;

	bool operator >(const Node &a) const
	{
		return total_cost > a.total_cost;
	}
};

int main()
{
	int city_count, initial_life, cooler_count, road_count, start_index, goal_index;
	while (cin >> city_count >> initial_life >> cooler_count >> road_count >> start_index >> goal_index,
		city_count)
	{
		// input
		vector<int> is_cooler(city_count, false);
		REP(i, cooler_count)
		{
			int cooler_index;
			cin >> cooler_index;
			is_cooler[cooler_index] = true;
		}
		vector<vector<Edge>> roads(city_count);
		REP(i, road_count)
		{
			int from, to, cost;
			cin >> from >> to >> cost;
			roads[from].push_back({ to, cost });
			roads[to].push_back({ from, cost });
		}

		// dijkstra
		vector<vector<int>> d(city_count, vector<int>(initial_life + 1, INT_MAX)); // [city_index][current_life] => total_cost
		d[start_index][initial_life] = 0;
		priority_queue<Node, vector<Node>, greater<Node> > pq;
		pq.push({ start_index, 0, initial_life });
		while (!pq.empty())
		{
			auto current_node = pq.top(); pq.pop();
			if (current_node.city_index == goal_index)
			{
				break;
			}
			for (auto &road : roads[current_node.city_index])
			{
				if (is_cooler[current_node.city_index])
				{
					REP(i, initial_life - current_node.current_life + 1)
					{
						int life = current_node.current_life + i - road.cost;
						if (life < 0)
						{
							continue;
						}
						int cost = current_node.total_cost + road.cost + i;
						if (cost < d[road.to][life])
						{
							d[road.to][life] = cost;
							pq.push({ road.to, cost, life });
						}
					}
				}
				else
				{
					int life = current_node.current_life - road.cost;
					if (life < 0)
					{
						continue;
					}
					int cost = current_node.total_cost + road.cost;
					if (cost < d[road.to][life])
					{
						d[road.to][life] = cost;
						pq.push({ road.to, cost, life });
					}
				}
			}
		}
		auto res = min_element(d[goal_index].begin(), d[goal_index].end());
		if (*res == INT_MAX)
		{
			cout << "Help!" << endl;
		}
		else
		{
			cout << *res << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1600
#include <iostream>

using namespace std;
#include <string>
typedef long long int ll;
#include <algorithm>

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

  sort(gu,gu+N);
  double wa=gu[0];
  for(int i=1;i<N;i++){
    wa = (wa+gu[i])/2;
  }

  cout << wa;



  return 0;
}


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

namespace AOJ
{
    class Program
    {
        static int f(int num)
        {
            int r = 0;
            if (num >= 25) r += (num - 25) / 25 + 1;
            if (num >= 125) r += (num - 125) / 125 + 1;
            if (num >= 625) r += (num - 625) / 625 + 1;
            if (num >= 3125) r += (num - 3125) / 3125 + 1;
            if (num >= 15625) r += (num - 15625) / 15625 + 1;
            return r;
        }
        static void Main(string[] args)
        {
            string line;
            while ((line = Console.ReadLine()) != null)
            {
                if (line == "0") break;
                var n = int.Parse(line);
                Console.WriteLine(n / 5 + f(n));
            }
        }
    }
}

Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;


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

	int a, b; cin >> a >> b;
	int cnt = 1;
	if (b == 1) {
		cout << 0 << endl;
		return 0;
	}
	b -= a;
	while (b > 0) {
		b -= a - 1;
		cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#define _DEBUG 1
#define _GLIBCXX_DEBUG

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

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll N, std::vector<std::string> S) {
  set<string> st;

  rep(i, N) {
    string s = S.at(i);
    if (!st.count(s)) {
      st.insert(s);
    }
  }

  cout << sz(st) << endl;
}

int main() {
  ll N;
  scanf("%lld", &N);
  std::vector<std::string> S(N);
  for (int i = 0; i < N; i++) {
    std::cin >> S[i];
  }
  solve(N, std::move(S));
  return 0;
}


Measured memory_bytes: 25144
import java.util.Scanner;
public class Main{
 public static void main(String args[]){
   Scanner sc=new Scanner(System.in);
   int a=sc.nextInt();
   int b=sc.nextInt();
   int c;
   if(b==100)
       c=a*1000+b;
   else if(b>=10&&b<100)
       c=a*100+b;
   else
       c=a*10+b;

   int square[]=new int [103];


   for (int i=1;i<100;i++)
   {
       square[i]=i*i;

   }
   square[100]=12100;
   square[101]=44100;
   square[102]=96100;
   int start=0,end=102,mid,d=0;
   while(end>=start)
   {
       mid=(start+end)/2;
       if(c==square[mid])
       {
           d=1;
           break;
       }
       else if(c>square[mid])
           start=mid+1;
       else
           end=mid-1;

   }

       if(d==1)
           System.out.println("Yes");
       else
           System.out.println("No");


   



   sc.close();
 }
}


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

const ll MX = 1e18;

int main(){
    ll a;
    double b;
    cin >> a >> b;
    ll ib = b*100+0.5;
    a *= ib;
    a /= 100;
    printf("%lld\n", a);
    return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int,int> P;

const int N=2e5+5;
int n,a[N],pos[N],f[25][N];
priority_queue<pair<int,P>> heap;

int rmq(int l,int r){
	int k=log2((r-l)/2+1); // half of the len cuz we just consider the postions which have the same parity with l
	return min(f[k][l],f[k][r-2*((1<<k)-1)]);
}

void add(int l,int r){
	if(l>r) return;
	int x=rmq(l,r-1);
	heap.push(make_pair(-x,make_pair(l,r)));
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>a[i];
		pos[a[i]]=i;
	}
	for(int i=0;i<n;++i)
		f[0][i]=a[i];
	for(int i=1,l=2;i<20;++i,l<<=1) // f[i][j] = min of elements whose positions bear the same parity with j
		for(int j=0;j<n;++j){
			f[i][j]=f[i-1][j];
			if(j+l<n) f[i][j]=min(f[i][j],f[i-1][j+l]);
		}
	add(0,n-1);
	for(int i=0;i<n/2;++i){
		pair<int,P> seg=heap.top();
		heap.pop();
		int l=seg.second.first,r=seg.second.second;
		int q1=rmq(l,r-1);
		int pos1=pos[q1];
		int q2=rmq(pos1+1,r);
		int pos2=pos[q2];
		cout<<q1<<' '<<q2<<' ';
		add(l,pos1-1);
		add(pos1+1,pos2-1);
		add(pos2+1,r);
	}
	cout<<'\n';
}




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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n,k;
    cin >> n >> k;
    ll MOD = 1e9+7;
    vector<ll> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    vector<vector<ll>> dp(n+1,vector<ll>(k+1,0));
    for(i = 0;i <= n;++i){
        dp.at(i).at(0) = 1;
    }
    for(i = 1;i <= n;++i){
        for(j = 1;j <= k;++j){
            dp.at(i).at(j) = dp.at(i-1).at(j) + dp.at(i).at(j-1);
            dp.at(i).at(j) %= MOD;
            if(j - a.at(i-1) -1 >= 0){
                dp.at(i).at(j) = dp.at(i).at(j) + MOD - dp.at(i-1).at(j - a.at(i-1) -1);
                dp.at(i).at(j) %= MOD;
            }
        }
    }
    cout << dp.at(n).at(k) << endl;
    return 0;
}

Measured memory_bytes: 80256
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy

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

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
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()

n = I()
a = LI()

for i in a:
    if i%2==0:
        if i%3!=0 and i%5!=0:
            print("DENIED")
            exit()
print("APPROVED")

Measured memory_bytes: 5680
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x, y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

template <typename T>void print(T v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<v.size(); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(w)<<*i<<" ";cout<<endl;}
template <typename T>void print_vv(T v){if(v.size()==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<v[0].size(); j++)cout<<setw(w)<<j<<" ";cout<<endl;for(auto i= 0; i<v.size(); i++){cout<<i<<" {";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(w)<<v[i][j]<<",";}cout<<"},"<<endl;}cout<<endl;}
template <class T, class U> void print_m(map<T,U> m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}

int main(){
    int n;
    cin>>n;
    ll sum = 0;
    fore(i,1,n+1){
        if(i%3==0  || i%5==0) continue;
        else sum+=i;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
//#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define BIG_NUM 200000000000
#define NUM 100000


struct Info{
	Info(int arg_to,ll arg_cost){
		to = arg_to;
		cost = arg_cost;
	}
	int to;
	ll cost;
};

struct Data{
	Data(int arg_num,ll arg_cost){
		num = arg_num;
		cost = arg_cost;
	}
	bool operator<(const struct Data &arg) const{
		return cost > arg.cost;
	}
	int num;
	ll cost;
};

vector<Info> rev_G[NUM+1];
ll min_cost[10][NUM+1];


int main(){

	int N,M,R,Q;
	scanf("%d %d %d %d",&N,&M,&R,&Q);

	int from,to;
	ll cost;

	for(int loop = 0; loop < M; loop++){
		scanf("%d %d %lld",&from,&to,&cost);
		rev_G[to].push_back(Info(from,cost));
	}

	for(int i = 0; i < R; i++){
		for(int k = 1; k <= N; k++)min_cost[i][k] = BIG_NUM;
	}

	int next_num;
	ll next_cost;
	priority_queue<Data> PQ;

	for(int start = 0; start < R; start++){

		for(int to = 1; to <= N; to++){
			if(to%R == start){
				min_cost[start][to] = 0;
				PQ.push(Data(to,0));
			}else{
				min_cost[start][to] = BIG_NUM;
			}
		}

		while(!PQ.empty()){

			if(PQ.top().cost > min_cost[start][PQ.top().num]){
				PQ.pop();
				continue;
			}

			for(int i = 0; i < rev_G[PQ.top().num].size(); i++){
				next_num = rev_G[PQ.top().num][i].to;
				next_cost = PQ.top().cost+rev_G[PQ.top().num][i].cost;

				if(min_cost[start][next_num] > next_cost){
					min_cost[start][next_num] = next_cost;
					PQ.push(Data(next_num,next_cost));
				}
			}

			PQ.pop();
		}
	}

	ll ans = 0;
	int x,y;
	ll z,minimum;

	for(int loop = 0; loop < Q; loop++){
		scanf("%d %d %lld",&x,&y,&z);

		if(x%R == y%R){
			ans += z;
			continue;
		}

		minimum = BIG_NUM;
		for(int i = 0; i < R; i++){
			if(min_cost[i][x] == BIG_NUM || min_cost[i][y] == BIG_NUM)continue;
			minimum = min(minimum,min_cost[i][x]+min_cost[i][y]);
		}

		if(z > minimum){
			ans += z-minimum;
		}
	}

	printf("%lld\n",ans);

	return 0;
}



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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

using Tup = tuple<int64, int64, int64>;

vector<int32> dig(int64 x){
	vector<int32> res;
	while(x){
		res.push_back(x%10);
		x /= 10;
	}
	return res;
}

int64 next(int64 x){
	int64 res = 0;
	vector<int32> v = dig(x);
	reverse(all(v));
	FOR(i, 1, v.size()){
		int64 x1 = 0, x2 = 0;
		FOR(j, 0, i){
			x1 = x1*10+v[j];
		}
		FOR(j, i, v.size()){
			x2 = x2*10+v[j];
		}
		res = max(res, x1*x2);
	}
	return res;
}

int main(void){
	int32 Q;
	cin >> Q;
	while(Q--){
		int64 N;
		cin >> N;
		int32 cnt = 0;
		while(dig(N).size() > 1){
			cnt++;
			N = next(N);
		}
		cout << cnt << endl;
	}
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;

#define M 1000000 
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(ll i = a; i<=b; ++i)
#define NFOR(i,a,b) for(ll i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const ll N = 1e5 + 10;
inline ll add(ll x,ll y){
  x += y;
  if(x >= mod) x -= mod;
  return x;
}
inline ll mul(ll x,ll y){
  x = (1LL * x * y) % mod;
  return x;
}


int main()
{
	fast;

	int a,b;cin>>a>>b;
	if((a*b)%2==1)cout << "Yes";
	else cout << "No";

	return 0;
}

Measured memory_bytes: 256
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N = in.nextInt
  val Ls = Array.fill(N)(in.nextInt).sorted
  println((for {
    a <- 0 until Ls.size
    b <- a + 1 until Ls.size
    c <- b + 1 until Ls.size
    if (Ls(a) != Ls(b) && Ls(b) != Ls(c) && Ls(a) + Ls(b) > Ls(c))
  } yield 1).size)
}

Measured memory_bytes: 58200
// B - Counting Roads
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const long double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, m, w, ans = 0, count = 0;
  string s, t;
  cin >> n >> m;
  vi v(n);
  rep(i, 0, m)
  {
    cin >> a >> b;
    a--;
    b--;
    v[a]++;
    v[b]++;
  }
  rep(i, 0, v.size())
  {
    cout << v[i] << endl;
  }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int x, y, z;
int a[200][200], b[200][200];
int c[200][200];
signed main() {
	cin >> x >> y >> z;
	for (int i = 0; i < x; i++) {
		for (int j = 0; j < y; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < y; i++) {
		for (int j = 0; j < z; j++) {
			cin >> b[i][j];
		}
	}
	for (int i = 0; i < x; i++) {
		for (int j = 0; j < y; j++) {
			for (int k = 0; k < z; k++) {
				c[i][k] += a[i][j] * b[j][k];
			}
		}
	}
	for (int i = 0; i < x; i++) {
		for (int j = 0; j < z; j++) {
			cout << (j == 0 ? "" : " ") << c[i][j];
		}
		cout << endl;
	}
}


Measured memory_bytes: 3564
import sys
input = sys.stdin.readline
def main():
  n,m=map(int,input().split())
  ab=[list(map(int,input().split())) for _ in range(m)]
  c=[0]*n
  for a,b in ab:
    c[a-1]+=1
    c[b-1]+=1
  print('NO' if len([ci for ci in c if ci%2==1])>0 else 'YES')
if __name__=='__main__':
  main()


Measured memory_bytes: 28628
def step(arr):
    res = 0
    for i in range(1,len(arr)):
        if arr[i] >= arr[i-1]:
            continue
        else:
            res += abs(arr[i-1] - arr[i])
            arr[i] = arr[i - 1]
    return res

def start():
    n = int(input())
    arr = [int(x) for x in input().split(" ")]
    print(step(arr))
start()

Measured memory_bytes: 32192
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 **/

int main(){
    int mod=1000000007;
    int n,m;
    vector<int> l(10);
    for(auto&e:l) {
        scanf("%d",&e);
    }
    sort(l.begin(),l.end());
    for(int i=9;i>6;i--) {
        printf("%d\n",l[i]);
    }
    return 0;
}

Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx=50;
int n,cnt[maxx][maxx];
// ll a[maxn];
int main()
{
    int i,j,k,l,t1,t2;
    long double x;
    ll a,ans=0,t;
    scanf("%d",&n);
    memset(cnt,0,sizeof(cnt));
    for(i=0;i<n;i++)
    {
        scanf("%Lf",&x); a=(ll)(x*1000000000+.5);
        // printf("%lld\n",a);
        for(t=a,t1=0;t%2==0;t/=2)
            t1++;
        for(t=a,t2=0;t%5==0;t/=5)
            t2++;
        cnt[t1][t2]++;
        // printf("%d %d\n",t1,t2);
    }
    for(i=0;i<maxx;i++)
        for(j=0;j<maxx;j++)
            for(k=0;k<maxx;k++)
                for(l=0;l<maxx;l++)
                    if(i+k>=18 && j+l>=18)
                    {
                        // if(cnt[i][j] && cnt[k][l])
                        //     printf("%d %d %d %d\n",i,j,k,l);
                        if(i==k && j==l)
                            ans+=cnt[i][j]*(ll)(cnt[k][l]-1);
                        else ans+=cnt[i][j]*(ll)cnt[k][l];
                    }
    printf("%lld\n",ans/2);
    return 0;
}

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

void solve(std::string S){
    string s = "Sunny";
    string c = "Cloudy";
    string r = "Rainy";
    if (S == s) cout << c << '\n';
    else if (S == c) cout << r << '\n';
    else cout << s << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
N = int(input())
ABlist = []

for n in range(N):
    a, b = input().split()
    a = int(a)
    b = int(b)
    winP = a + b
    ABlist.append((a, b, winP))

sortedList = sorted(ABlist, key=lambda x: x[2], reverse=True)

# 勝ち点の強いやつから取っていく？
Acount = 0
Bcount = 0

for i,x in enumerate(sortedList):
    if i % 2 == 0:
        Acount = Acount + x[0]
    elif i % 2 == 1:
        Bcount = Bcount + x[1]

print(Acount - Bcount)

Measured memory_bytes: 22900
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
#define MAX_N 100000
Int euler_phi(Int n){
  Int res=n;
  for(Int i=2;i*i<=n;i++){
    if(n%i==0){
      res=res/i*(i-1);
      for(;n%i==0;n/=i);
    }
  }
  if(n!=1) res=res/n*(n-1);
  return res;
}

Int euler[MAX_N];

void euler_phi2(){
  for(Int i=0;i<MAX_N;i++) euler[i]=i;
  for(Int i=2;i<MAX_N;i++){
    if(euler[i]==i){
      for(Int j=i;j<MAX_N;j+=i) euler[j]=euler[j]/i*(i-1);
    }
  }
}


//euler_phi:
signed AOJ_NTL1D(){
  Int n;
  cin>>n;
  cout<<euler_phi(n)<<endl;
  return 0;
}
/*
  verified on 2017/12/31
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_D&lang=jp
*/

signed main(){
  AOJ_NTL1D();
  return 0;
}



Measured memory_bytes: 3088
import std.stdio,std.conv,std.algorithm,std.array;

int[] 		raia(){ return readln().split().map!(to!int).array; }	//read as int[]
string[]	rasa(){ return readln().split(); }				//read as string[]

void main()
{
	auto it = raia();
	auto W = it[0];  auto H = it[1];
	auto x = it[2];  auto y = it[3];  auto r = it[4];

	if( x-r>= 0 && x+r <= W &&
		y-r>= 0 && y+r <= H )
	{	writeln("Yes"); }
	else
	{	writeln("No"); }
}

Measured memory_bytes: 1052
#include<bits/stdc++.h>
using namespace std;
int dp[3005][3005];

void  LCS(string x,string y,int m,int n)
{
    for(int i=0; i<=m; i++)
    {
        for(int j=0; j<=n; j++)
        {
            if(i==0 || j==0)
                dp[i][j]=0;


        }
    }
    for(int i=1; i<=m; i++)
    {
        for(int j=1; j<=n; j++)
        {
            if(x[i-1]==y[j-1])
            {
                dp[i][j]=1+dp[i-1][j-1];
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }


        }
    }

}
int main()
{
    string s,t;
    cin>>s;
    cin>>t;
    LCS(s,t,s.size(),t.size());



    int i=s.size(),j=t.size();
    string st;

    while(i>0 && j>0)
    {
        //cout<<s[i-1]<<" "<<t[j-1]<<" "<<dp[i][j]<<endl;
        if(s[i-1]==t[j-1])
        {
            st+=t[j-1];
            i--;
            j--;

        }
        else
        {
            if(dp[i][j-1]>=dp[i-1][j])
            {
                j--;
            }
            else
            {
                i--;
            }
        }
    }
    reverse(st.begin(),st.end());
    cout<<st<<endl;

}



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

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

  vector<int> v;
  int a;
  for (int i = 0; i < n; i++)
  {
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end());

  int b, c;
  vector<vector<int>> sousa;
  for (int i = 0; i < m; i++)
  {
    cin >> b >> c;
    vector<int> temp = {b, c};
    sousa.push_back(temp);
  }
  sort(sousa.begin(), sousa.end(), [](auto &x, auto &y) { return x[1] > y[1]; });

  vector<int>::iterator it = v.end();
  vector<int>::iterator be = v.begin();
  for (int i = 0; i < m; i++)
  {
    it = lower_bound(be, it, sousa[i][1]);
    if (it != be)
    {
      int count = 0;
      for (auto t = be; t != it; t++)
      {
        if (count < sousa[i][0])
        {
          *t = sousa[i][1];
          count++;
          be++;
        }
        else
        {
          break;
        }
      }
    }
    else
    {
      break;
    }
  }

  ll res = 0;
  for (int i = 0; i < n; i++)
  {
    res += v[i];
  }

  cout << res << endl;
}

Measured memory_bytes: 7152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll, ll, ll>>>;

// MOD確認

int main(){
   ll X;
   cin >> X;
   FOR(i,2,10){
      if(200 * i <= X && X < (i+1) * 200) cout << 10 - i << endl;
   }
}

Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  string s;cin>>s;
  	if(s[2]==s[3]&&s[4]==s[5]){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  
  return 0;
}


Measured memory_bytes: 256
n, m, q = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(q)]
s = [[1]]
res = []
while s:
    l = s.pop()
    if len(l) == n + 1:
        res.append(l)
    else:
        for i in range(l[-1], m + 1):
            s.append(l + [i])
ans = 0
for row in res:
    t = 0
    for a, b, c, d in li:
        if row[b] - row[a] == c:
            t += d
    ans = max(ans, t)
print(ans)


Measured memory_bytes: 24428
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int MAX_N = 100000;
int N;
vector<int> G[MAX_N];
bool visited[MAX_N];

int serch_path(int u, vector<int> &v) {
  if (u == 0) {
    v.push_back(0);
    return 0;
  }
  visited[u] = true;
  for (int i = 0; i < G[u].size(); ++i) {
    if (!visited[G[u][i]]) {
      if (serch_path(G[u][i], v) >= 0) {
        v.push_back(u);
        return u;
      }
    }
  }
  return -1;
}

ll dfs(int u) {
  visited[u] = true;
  ll res = 0;
  for (int i = 0; i < G[u].size(); ++i) {
    if (!visited[G[u][i]]) {
      res += dfs(G[u][i]);
    }
  }
  return res+1;
}

int main() {
  cin >> N;
  rep(i, N-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  vector<int> direct_path;
  serch_path(N-1, direct_path);


  memset(visited, 0, sizeof(visited));
  for (int i = 0; i < direct_path.size(); ++i) visited[direct_path[i]] = true;

  ll sunuke = 0;
  int size = direct_path.size();
  int sn = size / 2;
  for (int i = 0; i < sn; ++i) sunuke += dfs(direct_path[size-i-1]);


  if (sunuke >= N-sunuke) cout << "Snuke" << endl;
  else cout << "Fennec" << endl;
}


Measured memory_bytes: 12668
#include<bits/stdc++.h>
#define int long long
#define PB push_back
#define FI first
#define SE second
using namespace std;
typedef pair<int,int> pii;
static const int inf = 1ll<<60;
static const int MAX_N = 10000;
int N;
int a[MAX_N+5];
int dp[2][MAX_N/2+5][2];
int ans=inf;

signed main(){
    cin>>N;
    for(int i=1;i<N;++i)cin>>a[i];
    for(int i=0;i<2;++i)for(int j=0;j<N/2;++j)for(int k=0;k<2;++k)dp[i][j][k]=inf;
    dp[0][0][0]=0;
    for(int i=0;i<N;++i){
        for(int j=0;j<N/2;++j){
            dp[(i+1)%2][j+1][0]=min(dp[i%2][j][0],dp[i%2][j][1]+a[i+1]);
            dp[(i+1)%2][j][1]=min(dp[i%2][j][0]+a[i+1],dp[i%2][j][1]);
        }
        for(int j=0;j<N/2;++j)dp[i%2][j][0]=dp[i%2][j][1]=inf;
    }
    cout<<min(dp[N%2][N/2][0],dp[N%2][N/2][0])<<endl;
}

Measured memory_bytes: 1392
n,x=map(int,input().split())
a=[0]*n
a=list(map(int,input().split()))
a=sorted(a)
num=0
ans=0
al=x
for i in range(n):
  num+=a[i]
  al=al-a[i]
  if (num>x):
    break
  if (i==n-1 and num<x):
    break
  ans+=1

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <queue>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
using namespace std;

constexpr int INF       = 1000000000;/* 1e+9a */
constexpr int MODULO    = 1000000007;

typedef int64_t ll;

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

#define SPRE(x) setprecision(x) // 精度を指定

int main()
{
	cin.tie(0);
    ios::sync_with_stdio(false);
	priority_queue<ll, vector<ll>, greater<ll>> a,b;
	int n;
	ll asum,bsum;
	asum = bsum = 0;
	vector<ll> v;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		a.push(tmp);
		asum += tmp;
	}
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		v.push_back(tmp);
	}
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		b.push(-tmp);
		bsum -= tmp;
	}

	vector<ll> sumsa, sumsb;

	sumsa.push_back(asum);
	for(int k = 0; k < n; k++) {
		a.push(v[k]);
		asum += v[k] - a.top();
		a.pop();
		sumsa.push_back(asum);
	}
	sumsb.push_back(bsum);
	for(int k = n-1; k >= 0; k--) {
		b.push(-v[k]);
		bsum += -v[k] - b.top();
		b.pop();
		sumsb.push_back(bsum);
	}

	ll maxim = -1e+15;
	for (int k = 0; k <= n; k++) {
		maxim = max(sumsa[k]+sumsb[n-k],maxim);
	}
	cout << maxim << endl;

}



Measured memory_bytes: 4980
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
using namespace std;
#define FASTNIBBA   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll          long long
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define mii         map<int,int>
#define vi          vector<int>
#define vll         vector<long long>
#define lbnd        lower_bound
#define ubnd        upper_bound
#define all(a)      (a).begin(),(a).end()
#define clz(a)      __builtin_clz(a) // count leading zeroes
#define ctz(a)      __builtin_ctz(a) // count trailing zeroes
#define popc(a)     __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define SIZE        1000005
#define F           first
#define S           second
#define debug(x)    cerr << #x << " = " << x << endl;
#define mod         998244353
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
#define endl        '\n'
const ld PI = acos(-1.0);

void solve()
{
   int n,k; cin>>n>>k;
   mii m;
   rep(i,1,n+1)
   {
     if(!(k&1))
     {
       if(i%k==k/2) m[k/2]++;
     }
     if(i%k==0) m[0]++;
   }
   ll ans=0;
   for(auto i:m)
   {
     ll x=i.S;
     ans+=x*x*x;
   }
   cout<<ans; 
}
int main()
{
    FASTNIBBA;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    while(t--){
       solve();
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;


public static class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        HashSet<string> words = new HashSet<string>();
        char lastChar = '*';
        for (int i = 0; i < n; i++)
        {
            var s = Console.ReadLine();
            if ((lastChar != '*' && lastChar != s.First()) || !words.Add(s))
            {
                Console.WriteLine("No");
                return;
            }
            lastChar = s.Last();
        }
        Console.WriteLine("Yes");
    }
}


Measured memory_bytes: 13280
#include <iostream>
#include <set>
#include <vector>
using namespace std;
int N, t_max = 0, ans = 0;
multiset<int> t;
vector<int> divisor;
int main() {
  // Input
  cin >> N;
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    t.insert(tmp);
  }
  t_max = *(--t.end());
  // Divisor
  for (int i = 1; i <= t_max; i++) {
    if (t_max % i == 0) {
      divisor.push_back(i);
    }
  }
  // Answer
  auto ti = t.begin();
  for (int i = 0; i < divisor.size() && ti != t.end();) {
    if (divisor[i] < *ti) {
      i++;
      continue;
    }
    ans += divisor[i] - *ti;
    ti++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 7852
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  unsigned long long answer = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 3 && i % 5) {
      answer += i;
    }
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int one,five,ten,n,y,a,b,c;
bool inrange (int l, int r, int x){
    if(l<=x && x<=r)return true;
    return false;
}
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>y;
    a=-1;b=-1;c=-1;
    five = -1;
    for(int i=y/1000;i>=0;i-=5){
        one = i;
        five ++;
        int r = one + five;
        int l = r - (five/2);
        if(inrange(l,r,n)){
            int sel = r - n;
            a = sel;
            b = five - 2*sel;
            c = one;
            break;
        }
    }
    cout<<a<<" "<<b<<" "<<c<<newl;
}


Measured memory_bytes: 256