akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vll path; ll pre = 0;
int main() {
	cin >> N >> M;
	ll P = (N - M) * 100 + M * 1900;
	X = pow(2, M);
	cout << P * X;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var s = Console.ReadLine();
                if (s == "-") break;

                var m = int.Parse(Console.ReadLine());

                for (var i = 0; i < m; i++)
                {
                    var h = int.Parse(Console.ReadLine());
                    var tmp = s.Substring(0, h);
                    s = s.Substring(h) + tmp;
                }
                Console.WriteLine(s);
            }
        }
    }
}



Measured memory_bytes: 17784
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;

int main(){
    int N;
    cin >> N;
    vector<vector<int>> A(2,vector<int>(N));

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

    vector<int> a0(N);
    a0[0]=A[0][0];
    for(int i=1;i<N;i++){
        a0[i]=A[0][i]+a0[i-1];
    }

    vector<int> a1(N);
    a1[N-1]=A[1][N-1];
    for(int i=N-2;i>=0;i--){
        a1[i]=A[1][i]+a1[i+1];
    }

    int ans=0;
    for(int i=0;i<N;i++){
        int a=a0[i]+a1[i];
        if(a > ans){
            ans=a;
        }
    }

    cout << ans << endl;
    return 0;
}



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

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i,n) {
        cin >> v[i];
    }
    sort(v.begin(),v.end());
    double ans = v[0];
    for (int i = 1; i < n; i++) {
        ans = (ans+v[i])/2;
    }
    printf("%.10f\n",ans);
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

X = 0

#print(bin(A[0]))
#print(bin(A[2]))
for i in range(2,N):
    X ^= A[i]
if X>A[0]+A[1]:
    print(-1)
else:
    Y = A[0]+A[1]-X
    bY = bin(Y)[2:][::-1]
    bX = bin(X)[2:][::-1]
    if bY[0]=="1":
        print(-1)
    else:
        flag = True
        for i in range(1,len(bY)):
            if bY[i]=="1":
                if i-1<len(bX):
                    if bX[i-1]=="1":
                        flag = False
                        break
        if flag:
            if Y//2>A[0]:
                #print(X,Y)
                print(-1)
            else:
                a = Y//2
                #print(a)
                #print(bX)
                for i in range(len(bX)):
                    if bX[len(bX)-i-1]=="1":
                        if a + 2**(len(bX)-i-1) <= A[0]:
                            #print(i)
                            a += 2**(len(bX)-i-1)
                            #print(a)
                if a!=0:
                    print(A[0]-a)
                else:
                    print(-1)
        else:
            print(-1)


Measured memory_bytes: 62300
#include <bits/stdc++.h>
using namespace std;
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int H, W, K;
vector<string> fi;

int solve() {
    int res = 1<<29;
    for (int bit = 0; bit < (1<<(H-1)); ++bit) {
        bool gok = true; // そもそも不可能な場合もあるので判定
        int N = 0;
        vector<int> ord(H, 0);
        for (int i = 0; i < H-1; ++i) {
            if (!(bit & (1<<i))) ord[i+1] = ord[i];
            else ord[i+1] = ord[i]+1, ++N;
        }
        int add = 0;
        vector<int> nums(N+1, 0);
        for (int w = 0; w < W; ++w) {
            vector<int> one(N+1, 0);
            bool ok = true;
            for (int h = 0; h < H; ++h) {
                one[ord[h]] += fi[h][w] - '0';
                nums[ord[h]] += fi[h][w] - '0';
                if (one[ord[h]] > K) gok = false;
                if (nums[ord[h]] > K) ok = false;
            }
            if (!ok) ++add, nums = one;
        }
        if (gok) chmin(res, N + add);
    }
    return res;
}

int main() {
    while (cin >> H >> W >> K) {
        fi.resize(H);
        for (int i = 0; i < H; ++i) cin >> fi[i];
        cout << solve() << endl;
    }
}



Measured memory_bytes: 256
#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>;

// lib by snuke
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};


int main() {
	int n;
	long long k;
	cin >> n >> k;
	vector<ll> a(n + 1);
	rep(i, n) {
		ll t;
		cin >> t;
		a[i+1] = a[i] + t - k;
	}
	vector<ll> b = a;
	sort(b.begin(), b.end());
	map<ll, int> trans;
	rep(i, n + 1) trans[b[i]] = i;
	BIT<ll> d(n + 1);
	for(ll v: a) d.add(trans[v]);
	ll ans = 0;
	for(ll v: a) {
		d.add(trans[v], -1);
		ans += d.sum(trans[v], n + 1);
	}
	cout << ans << endl;
}


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

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

    string s; cin >> s;

    for(int i=0;i<s.size()-1;i++){
        if(s[i]==s[i+1]){
            cout << i+1 << " " << i+2;
            return 0;
        }
    }

    for(int i=0;i<s.size()-2;i++){
        if(s[i]==s[i+2]){
            cout << i+1 << " " << i+3;
            return 0;
        }
    }

    cout << "-1 -1";

    return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

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

	int total = 0;

	for(int i=1;i<=n;i++){
		int num = i;
		int sum = 0;
		while(num > 0){
			sum += num%10;
			num /= 10;
		}

		if(a <= sum && sum <= b){
			total += i;
		}
	}

	cout << total << endl;

	return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn

object Main{
  def main(args: Array[String]){
    var list = List[Int]()

    for(in <- StdIn.readLine.split(" ").map(_.toInt)){
      list = in :: list
    }

    printf("%d %d %10.8f\n", list(1) / list(0), list(1) % list(0),list(1).toDouble / list(0).toDouble)
  }
}

Measured memory_bytes: 44240
#include <cstdio>

typedef long long LL;

int N, A, B;
LL C, D;

int main() {
	scanf("%d%d%d%lld%lld", &N, &A, &B, &C, &D), --N;
	for (int k = 0; k <= N; ++k)
		if (A + k * C - (N - k) * D <= B && B <= A + k * D - (N - k) * C) return puts("YES"), 0;
	puts("NO");
	return 0;
}

Measured memory_bytes: 1636
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;



class A
{
    static int[,] G;
    static internal int n;
    const int INFTY = int.MaxValue;
    public static void Main() {
        n = int.Parse(Console.ReadLine());
        G = new int[n, n];
        for (int i = 0; i < n; i++) {
            string[] input = Console.ReadLine().Split(' ');
            for(int j = 0; j < n; j++) {
                 
                G[i, j] = (int.Parse(input[j+1])==-1)?INFTY:int.Parse(input[j+1]);
            }
        }
        MST();
    }

    public static void MST() {
        var d = Enumerable.Repeat(INFTY, n).ToArray();
        var parent = Enumerable.Repeat(-1, n).ToArray();
        var Color = Enumerable.Repeat("WHITE", n).ToArray();
        d[0] = 0;
        while (true) {
            int mincost = INFTY;
            int u = -1;
            for (int i = 0; i < n; i++) {
                if (Color[i] != "BLACK" && d[i] < mincost) {
                    mincost = d[i];
                    u = i;
                }
            }
            if (mincost == INFTY) {
                break;
            }
            Color[u] = "BLACK";
            for (int v = 0; v < n; v++) {
                if (Color[v] != "BLACK" && G[u, v] != INFTY) {
                    if (G[u,v] < d[v]) {
                        d[v] = G[u, v];
                        parent[v] = u;
                        Color[v] = "GRAY";
                    }
                }
            }
        }
        int sum=0;
        for(int i = 0; i < n; i++) {
            if (parent[i] != -1) {
                sum += G[i, parent[i]];
            }
        }
        Console.WriteLine(sum);
    }
}


Measured memory_bytes: 18344
N = int(input())
An = [ int(input()) for _ in range(N)]

current_partition_cnt = 0
ans = 0
for a in An:
    if a == 0:
        ans += current_partition_cnt//2
        current_partition_cnt = 0
    else:
        current_partition_cnt += a
ans += current_partition_cnt//2
print(ans)

Measured memory_bytes: 50908
import collections
from operator import itemgetter

while True:
    max_value = 1
    num_people,num_border = map(int,raw_input().split())
    if (num_people == 0) and (num_border == 0):
        break
    list2 = []
    for i in range(num_people):
        line = raw_input()
        list1 = line.split()
        list1 = [int(s) for s in list1]
        if list1[0] != "0":
            del list1[0]
            list2.extend(list1)
    counter = collections.Counter(list2)
    if counter == {}:
        print "0"
    s = sorted(counter.items(), key=itemgetter(0))
    for key,value in sorted(s,key= itemgetter(1),reverse = True):
        if value >= num_border:
            print key
            break
        else:
            print "0"
            break

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

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

using Weight = int;
struct Edge {
    int src, dst;
    Weight weight;
    Edge(int src, int dst, Weight weight): src(src), dst(dst), weight(weight) {}
};
using Vertex = vector<Edge>;
using Graph = vector<Vertex>;

bool augment(const Graph& graph, vector<bool>& visited, vector<int>& match, int u) {
    if (u == -1) return true;
    for (auto& e : graph[u]) {
        if (!visited[e.dst]) {
            visited[e.dst] = true;
            if (augment(graph, visited, match, match[e.dst])) {
                match[e.src] = e.dst;
                match[e.dst] = e.src;
                return true;
            }
        }
    }
    return false;
}

int bipartie_matching(const Graph& graph, int n_left) {
    vector<int> match(graph.size(), -1);
    int n_match = 0;
    REP(u, n_left) {
        vector<bool> visited(graph.size());
        if (augment(graph, visited, match, u)) ++n_match;
    }
    return n_match;
}

vector<vector<Weight>> warshall_floyd(Graph graph) {
    static const Weight inf = numeric_limits<Weight>::max() / 10;
    vector<vector<Weight>> dist(graph.size(), vector<Weight>(graph.size(), inf));
    REP(u, graph.size()) dist[u][u] = 0;
    REP(u, graph.size()) for (auto& e : graph[u]) dist[e.src][e.dst] = e.weight;
    REP(w, graph.size()) REP(u, graph.size()) REP(v, graph.size())
        dist[u][v] = min(dist[u][v], dist[u][w] + dist[w][v]);
    return dist;
}

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

    int N, M, L;
    while (cin>>N>>M>>L, N|M|L) {
        Graph graph1(N);
        REP(i, M) {
            int u, v, d; cin >> u >> v >> d;
            graph1[u].emplace_back(u, v, d);
            graph1[v].emplace_back(v, u, d);
        }
        vector<int> positions(L), times(L);
        REP(i, L) cin >> positions[i] >> times[i];

        vector<vector<Weight>> dist = warshall_floyd(graph1);

        Graph graph2(2*L);
        REP(i, L) {
            int t1 = times[i], p1 = positions[i];
            REP(j, L) if (i != j) {
                int t2 = times[j], p2 = positions[j];
                if (dist[p1][p2] <= t2-t1) {
                    graph2[i].emplace_back(i, j+L, 0);
                }
            }
        }
        cout << L - bipartie_matching(graph2, L) << '\n';
    }
}

Measured memory_bytes: 10660
import java.util.Scanner;
public class Main {
	public static int f(int n) {
		int ans;
		ans=(n*n)+n+2;
		return ans/2;	
	}
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n;
		while(sc.hasNext()){
			n=sc.nextInt();
			System.out.println(f(n));
		}
	}
}

Measured memory_bytes: 11000
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <math.h>
using namespace std;

int main()
{
    int n,k,f,sum=0;
    cin>>n>>k;

    if(n==k || abs(n-k)==1)
        cout<<"Yay!"<<endl;
    else
        cout<<":("<<endl;

    return 0;
}



Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
#define MAXE 2010
#define MAXV 1010
#define INF 1e9

struct edge{int from, to, cost;};

edge es[MAXE];
int d[MAXV];
int V, E, r;

void shortest_path(int s) {
    for (int i = 0; i < V; i++) d[i] = INF;
    d[s] = 0;
    int count = 0;
    while (1) {
        bool update = false;
        for (int i = 0; i < E; i++) {
            edge e = es[i];
            if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                update = true;
            }
        }
        if (!update) break;
        count++;
        if (count > V) {
            cout << "NEGATIVE CYCLE" << endl;
            return;
        }
    }
    for (int i = 0; i < V; i++) {
        if (d[i] < INF) cout << d[i] << endl;
        else cout << "INF" << endl;
    }
    return;
}

int main(void) {
    cin >> V >> E >> r;
    for (int i = 0; i < E; i++) {
        cin >> es[i].from >> es[i].to >> es[i].cost;
    }
    shortest_path(r);
    return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision; // int64_tは9*10^18まで、intは2*10^9まで

int main() {
  string s;
  cin >> s;
  int n=s.length(), res;
  int a;
  for(int i=0; i<n; i++){
    a=(int)(s[i]-'0');
    res+=a;
    res%=9;
  }
  if(res==0) cout << "Yes";
  else cout << "No";
  return 0;
}

Measured memory_bytes: 3748
#include <iostream>
#include <vector>
#include <algorithm>

#define REP(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;

void dfs(
        const vector<vector<pair<int, int>>> &graph,
        vector<unsigned long long> &dist_from_K,
        int current_vertex,
        int prev_vertex,
        unsigned long long current_cost )
{
    auto &connected = graph[current_vertex];

    for( auto p : connected )
    {
        if( p.first == prev_vertex ) continue;

        dist_from_K[p.first] = current_cost + p.second;

        dfs( graph, dist_from_K, p.first, current_vertex, dist_from_K[p.first] );
    }
}

int main()
{
    const int INF = 987654321;
    int N; cin >> N;

    vector<vector<pair<int, int>>> graph(N);

    REP(i, N - 1)
    {
        int a, b, c; cin >> a >> b >> c;
        a--;
        b--;

        graph[a].push_back(make_pair(b, c));
        graph[b].push_back(make_pair(a, c));
    }

    // Kが根になるような経路ができる
    // その経路の和がそれ

    int Q, K; cin >> Q >> K;
    K--;

    vector<unsigned long long> dist_from_K(N, INF);
    dist_from_K[K] = 0;

    dfs( graph, dist_from_K, K, K, 0 );

    REP(i, Q)
    {
        int x, y; cin >> x >> y;
        x--;
        y--;

        cout << dist_from_K[x] + dist_from_K[y] << endl;
    }

    return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int T; cin >> T; 
	int inf = 1145141919; 
	while(T--){
		int N; cin >> N; 
		long long ans = 0; 
		vector<pair<long long, int>> left, right; 
		for(int i = 0; i < N; i++){
			int K; long long L, R; 
			cin >> K >> L >> R; 
			ans += min(L, R); 
			if(L >= R) left.emplace_back(L - R, K); 
			else right.emplace_back(R - L, N - K); 
		}		
		sort(left.begin(), left.end(), greater<pair<long long, int>>()); 
		sort(right.begin(), right.end(), greater<pair<long long, int>>()); 
		int a = left.size(); int b = N - a; 
		set<int> A, B; 
		for(int i = 1; i <= a; i++) A.insert(i); 
		for(int i = 1; i <= b; i++) B.insert(i); 
		A.insert(-inf); A.insert(inf); 
		B.insert(-inf); B.insert(inf); 
		for(auto p : left){
			auto it = A.upper_bound(p.second); 
			it--; 
			if(*it == -inf) continue;
			ans += p.first; 
			A.erase(it); 			
		}
		for(auto p : right){
			auto it = B.upper_bound(p.second); 
			it--; 
			if(*it == -inf) continue;
			ans += p.first; 
			B.erase(it); 			
		}
		cout << ans << "\n"; 
	}
}

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

int main(int argc, const char * argv[]) {
    const int cake = 4;
    const int donut = 7;
    int N;
    
    cin >> N;
    for(int i = 0; i * cake <= 100 ; ++i){
        for(int j = 0; j * donut <= 100; ++j){
            if(cake * i + donut * j == N){
                cout << "Yes";
                
                return 0;
            }
        }
        
    }
    cout << "No";
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#define RU 5
#define LIMIT 100
using namespace std;

int main () {

	int ru[RU];	

	
	string in;
	int n;
	cin >> n;
	for ( int j=0; j<n; j++ ) {
		for ( int i=0; i<RU; i++ ) {
			ru[i] = 0;
		}
		int out = 0;
		int score = 0;
		while ( true ) {
			cin >> in;
			if ( in.compare("HIT") == 0 ) {
				for ( int i=2; i>=0; i-- ) {
					ru[i+1] = ru[i];
				}
				ru[0] = 1;
				if ( ru[3] != 0 ) {
					score++;
					ru[3] = 0;
				}
			}
			if ( in.compare("HOMERUN") == 0 ) {

				for ( int i=0; i<3; i++ ) {
					if ( ru[i] != 0 )
						score++;
					ru[i] = 0;
				}
				score++;
			}
			if ( in.compare("OUT") == 0 ) {
				//cout << "T OUT" << endl;
				out++;
			}
			if ( out == 3) {
				cout << score << endl;
				break;
			}
		}
	}


}

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

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

    int k = -1;

    for (int i = 1; i <= 10000; i++){

        //完全グラフであれば条件を満たす
        if (i * (i-1) == 2 * n){
            k = i;
            break;
        }
    }

    if (k == -1){
        cout << "No" << endl;
        return 0;
    }

    vector<vector<int>> S(k);
    int cnt = 1;
    for (int i = 0; i < k; i++){
        for (int j = i+1; j < k; j++){
            S[i].push_back(cnt);
            S[j].push_back(cnt);
            cnt++;
        }
    }

    cout << "Yes" << endl;
    cout << k << endl;

    for (auto s : S){
        //完全グラフ上における, ある頂点からの辺の本数がk-1である
        cout << k-1 << " ";

        for (int v : s){
            cout << v << " ";
        }
        cout << endl;

    }
}

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

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

	vector <int> v;
	int t,res = 0;

	for(int i=0;i<3;i++)
	{
		cin >> t;
		v.push_back(t);
	}

	sort(v.begin(),v.end());

	for(int i=1;i<v.size();i++)
	{
		res += (v[i]-v[i-1]);
	}

	cout << res << '\n';

	return 0;	
}

Measured memory_bytes: 256
# dpB
def main():
    n, k = tuple(map(int, input().rstrip().split()))
    A = tuple(map(int, input().rstrip().split()))
    dp = [0] + [float("inf")] * (n - 1)
    for i in range(1, n):
        for j in range(1, k + 1):
            if i - j >= 0:
                dp[i] = min(dp[i], dp[i - j] + abs(A[i] - A[i - j]))
    print(dp[-1])


if __name__ == "__main__":
    main()

Measured memory_bytes: 58592
#include <bits/stdc++.h>
#define LL long long
#define Accel ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Re(a,b) memset(a,b,sizeof a)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
#define REP(I, N) for (int I = 0; I < (N); I++)
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define SZ(a) ((int)a.size())
#define endl "\n"
//#pragma GCC optimize(2)
using namespace std;
const int N=1e6+1;
const int M=1e9+7;
const double eps=1e-6;
typedef complex<double>C;
const double PI(acos(-1.0));
//__gcd, atan2(y,x)=y/x , __int128
//c(n,k)=c(n-1,k-1)+c(n-1,k)
//c(i,r),i for r to n =c(n+1,r+1)
//void add(int x){while(x<N)BIT[x]++,x+=x&-x;}
//int sum(int x){return x?BIT[x]+sum(x-(x&-x)):0;}
//int find(int x){return x==p[x]?x:p[x]=find(p[x]);}
//LL pw(LL a, LL b,LL M) { return b ? b & 1 ? a*pw(a, b - 1,M) % M : pw(a*a%M, b>>1,M) : 1; }
//log() = ln() , log(x)/log(y)=log(y)-base-x
//INT_MAX 127,INT_MIN 128
//int dw[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
//int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
int n,x[201],y[201];
double p[201];
int main(){
	cin>>n;
	FOR(i,1,n)cin>>x[i]>>y[i];
	
	FOR(i,1,n){
		int c=0;
		FOR(j,1,n)
			if(i!=j)
				p[c++]=atan2(y[j]-y[i],x[j]-x[i]);
		sort(p,p+c);
		double ans=0;
		REP(j,c)
			p[j+c]=p[j]+2*PI;	
		REP(j,c)ans=max(PI-p[j+c-1]+p[j],ans);
		printf("%.8lf\n",ans/2.0/PI);
			
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
#include <queue>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

int main(int argc, char const *argv[]) {
    ll Q, H, S, D, N;
    cin >> Q >> H >> S >> D >> N;
    ll ans = 0;
    ll q = N*4;
    ll h = N*2;
    ll s = N;
    ll d = N/2;
    if (N == 1) ans = min({Q*q, H*h, S});
    else if (N%2 == 0) ans = min({Q*q, H*h, S*s, D*d});
    else {
        if (Q*8 <= D || H*4 <= D || S*2 <= D) ans = min({Q*q, H*h, S*s});
        else ans = min({D*d+S, D*d+H*2, D*d+Q*4});
    }
    cout << ans << std::endl;
    return 0;
}


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

void solve()
{
    int n;
    cin>>n;
    int h[n];
    for(int i=0; i<n; i++){
        cin>>h[i];
    }
    int dp[n];
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2; i<n; i++){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t=1;
    while(t--){
        solve();
        cout<<endl;
    }
}


Measured memory_bytes: 4372
fun main(args: Array<String>) {
    val s = readString()
    var ans = true
    s.forEachIndexed { index, c ->
        when {
            index % 2 == 0 -> if (c == 'L') ans = false
            else -> if (c == 'R') ans = false
        }
    }
    println(if (ans) "Yes" else "No")
}

// Tools
fun readString() = readLine()!!

Measured memory_bytes: 34308
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
//#include<bits/extc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pdd pair<double,double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi acos(-1)
#define index Index
#define Line pll
typedef long long LL;
LL dp[3005][3005];
int mod=1e9+7;
int main(){
    int n;
    scanf("%d",&n);
    char c[3005];
    scanf("%s",c+2);
    dp[1][1]=1;
    for(int i=2;i<=n;i++){
        if(c[i]=='<'){
            LL sum=0;
            for(int j=1;j<=i;j++){
                dp[i][j]=sum;
                sum+=dp[i-1][j];
                sum%=mod;
             //   printf("%d ",dp[i][j]);
            }
        }
        else{
            LL sum=0;
            for(int j=i;j>=1;j--){
                sum+=dp[i-1][j];
                dp[i][j]=sum;
                sum%=mod;
                //printf("%d ",dp[i][j]);
            }
        }
       // printf("\n");
    }
    LL ans=0;
    for(int i=1;i<=n;i++)
    ans+=dp[n][i];
    printf("%lld\n",ans%mod);
}


Measured memory_bytes: 68992
#include <iostream>
#define ll long long
using namespace std;

int main(){
	ll N,K,X,Y;
	cin>>N>>K>>X>>Y;
	ll sum=0;
	if(N>K)
		sum+=K*X+(N-K)*Y;
	else
		sum+=N*X;
	cout<<sum<<endl;
	return 0;
}

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

int main() {
  int64_t K, S, ans;
  cin >> K >> S;
  ans=0;
  for (int X=0; X<=K; X++) {
    for (int Y=0; Y<=K; Y++) {
      if (0<=S-X-Y && S-X-Y<=K) {
        ans=ans+1;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3636
import heapq

N,M = map(int,input().split())

tasks = [[] for _ in range(100001)]
#tasks = [[] for _ in range(11)]
for n in range(N):
	A,B = map(int,input().split())
	tasks[A].append(B)
#print(tasks)

ans = 0
h = []
for day in range(1,M+1):
	for gain in tasks[day]:
		heapq.heappush(h,-gain)
	#print(h)
	if h:
		gain = -heapq.heappop(h)
		#print('\t{:02d}: gain={}'.format(day,gain))
		ans += gain
print(ans)


Measured memory_bytes: 72480
h,w=map(int,input().split())
s=[input() for i in range(h)]

flag=True
count=0
for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            if h==1:
                count+=1
            elif i!=0 and i!=h-1:
                if s[i-1][j]=="#" or s[i+1][j]=="#":
                    continue
            elif i==0:
                if s[i+1][j]=="#":
                    continue
            elif i==h-1:
                if s[i-1][j]=="#":
                    continue
            
            if w==1:
                count+=1
            elif j!=0 and j!=w-1:
                if s[i][j-1]=="#" or s[i][j+1]=="#":
                    continue
            elif j==0:
                if s[i][j+1]=="#":
                    continue
            elif j==w-1:
                if s[i][j-1]=="#":
                    continue
            flag=False

if flag:
    print("Yes")
else:
    print("No")

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

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

    switch (D)
    {
        case 25:
            cout << "Christmas" << endl;
            break;
    
        case 24:
            cout << "Christmas Eve" << endl;
            break;

        case 23:
            cout << "Christmas Eve Eve" << endl;
            break;

        case 22:
            cout << "Christmas Eve Eve Eve" << endl;
            break;
            
        default:
            break;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const ll MOD = 1e9+7;
/*int dfs(vector<int> &T, vector<int> &C, int i, int sum, int g, int count){
   
}*/
bool dif_ch(int64_t x){
  int64_t r = x%10;
  int64_t r2;
  x /= 10;
  while(x>0){
    r2 = x%10;
    int64_t a = abs(r-r2);
    if(a>1) return false;
    r = r2;
    x /= 10;
  }
  return true;
}

int main(){
  int w, h, n, i, j;
  cin >> w >> h >> n;
  vector<vector<int>> data(h, vector<int>(w));
  int a, x, y;
  rep(p, n){
    cin >> x >> y >> a;
    if(a==1){
      for(i=x-1; i>=0; i--){
        for(j=0; j<h; j++){
          data[j][i] = 1;
        }
      }
    }
    else if(a==2){
      for(i=x; i<w; i++){
        for(j=0; j<h; j++){
          data[j][i] = 1;
        }
      }
    }
    else if(a==3){
      for(i=0; i<w; i++){
        for(j=y-1; j>=0; j--){
          data[j][i] = 1;
        }
      }
    }
    else{
      for(i=0; i<w; i++){
        for(j=y; j<h; j++){
          data[j][i] = 1;
        }
      }
    }
  }
  int ch = 0;
  for(i=0; i<w; i++){
    for(j=0; j<h; j++){
      if(data[j][i]!=1) ch++;
    }
  }
  cout << ch << endl;
}



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

int main(){
  long long m,n,j,k;
cin>>n>>m;
  j=1;
  k=1;
 if(n==m){
  for(int i=1;i<n+1;i++){
    j*=i;
      j%=1000000007;
  }
   j=(j*j*2)%1000000007;
   cout<<j<<endl;
 }
  else if(abs(n-m)==1){
      for(int i=1;i<n+1;i++){
    j*=i;
      j%=1000000007;
  }
      for(int i=1;i<m+1;i++){
    k*=i;
      k%=1000000007;
  }
  j=(j*k)%1000000007;
    cout<<j<<endl;
  }
  else{
    cout<<0<<endl;
  }
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef set<int> si;
typedef set<ll, ll> sll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef map<int, int> mii;
typedef map<int, ll> mil;
typedef map<ll, int> mli;
typedef map<ll, ll> mll;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort((c).begin(),(c).end())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define PB push_back

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

template<class T> T read() {
	T t;
	cin >> t;
	return t;
}

int main(){
	int n = read<int>();
	REP(i, n){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		int p = a*c+b*d;
		int q = (a*max(5,c) + b*max(2,d))*4/5;
		cout << min(p, q) <<endl;
	}
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>

using namespace std;
#define SAY_YES cout<<"YES"<<endl;
#define SAY_Yes cout<<"Yes"<<endl;
#define SAY_NO cout<<"NO"<<endl;
#define SAY_No cout<<"No"<<endl;
#define IFYES(TRUE_OR_FALSE) if(TRUE_OR_FALSE){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;} 
#define IFYes(TRUE_OR_FALSE) if(TRUE_OR_FALSE){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} 
#define IFyes(TRUE_OR_FALSE) if(TRUE_OR_FALSE){cout<<"yes"<<endl;}else{cout<<"no"<<endl;} 
#define DEBUG_OUTPUT_ARRAY(XXX,ONE) for(int i=0;i<(ONE);i++){cout<<"DEBUG: i = "<<i<<" -> "<<XXX[i]<<endl;}
#define DEBUG_OUTPUT_ARRAY2(XXX,ONE,TWO) for(int i=0;i<(ONE);i++){cout<<"<<< i = "<<i<<" >>>"<<endl;for(int j=0;j<(TWO);j++){cout<<"DEBUG: j = "<<j<<" -> "<<XXX[i][j]<<endl; } }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX,ONE,TWO) for(int i=0;i<(ONE);i++){cout<<i<<"  ";for(int j=0;j<(TWO);j++){cout<<XXX[i][j]<<" "; } cout<<endl;}

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


const long long int mod=1000000007;
const long long int INF=99999999999999999;

long long int N,M,sum=0,res=0,X[1000],tmp;

string str;

int main() {
	cout << fixed << setprecision(18);
    
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>X[i];
    }
    res=INF;
    for(int i=1;i<=100;i++){
        tmp=0;
        for(int j=0;j<N;j++){
            tmp+=(X[j]-i)*(X[j]-i);
        }
        res=min(res,tmp);
    }
    cout<<res;
} 


Measured memory_bytes: 256
#if 1
  #include <bits/stdc++.h>
#else
  #include "../../bits/stdc++.h"
#endif

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

using namespace std;

typedef pair<int, int> P;
#define pb push_back
#define mp make_pair
#define ft first
#define sd second

int r0 ,w0, c, r;

bool input(){
  cin>>r0>>w0>>c>>r;
  return r0|w0|c|r;
}

void solve(){
  REP(i, 1<<20) {
    if((r0+i*r)/w0>=c) {
      cout<<i<<endl;
      return ;
    }
  }
}

int main(){
  cin.tie(0);
  
  while (input()){
      solve();
  }
  
  return 0;
}

Measured memory_bytes: 3084
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int main()
{
	 string ch1;
	 int tot=0,sum=0,ans;
	 int n,m;
	 cin>>ch1;
	 n=ch1.length();
	 m=n/2;
	 for(int i=0;i<=n;i++)
	 {
	 if(ch1[i]=='g') tot++;
	 if(ch1[i]=='p') sum++;
	 }
	 if(tot<sum) cout<<" ";
	 else
	 ans=m-sum;
	 cout<<ans;
	 return 0;
	 }
 

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

int main()
{
  int a,b,ans;
  cin>>a>>b;
  ans=0;
  ans+=max(a,b);
  if(ans==a)
  {
    a--;
  }
  else
  {
    b--;
  }
  ans+=max(a,b);
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=j; i<=k; i++)
#define FFOR(i, j, k) for(int i=j; i<k; i++)
#define DFOR(i, j, k) for(int i=j; i>=k; i--)
#define bug(x) cerr<<#x<<" = "<<x<<'\n'
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define taskname "E"
int n;
int m;
struct edge{
    int u, v;
    int c;
} e[200001];
vector <int> g[100001];
vector <pair <int, int> > h[300001];
bool cmp(int a, int b){
    return e[a].c<e[b].c;
}
int r[200001];
int root(int u){
    if(r[u]<0) return u;
    return r[u]=root(r[u]);
}
void uni(int u, int v){
    u=root(u); v=root(v);
    if(u!=v){
        if(r[u]>r[v]) swap(u, v);
        r[u]+=r[v];
        r[v]=u;
    }
}
int to[200001];
int f[300001];
bool done[300001];
deque <int> q;
void bfs(){
    q.pb(1);
    done[1]=1;
    while(!q.empty()){
        int u=q.front();
        q.pop_front();
        for(pair <int, int> p: h[u]) if(!done[p.first]){
            f[p.first]=f[u]+p.second;
            done[p.first]=1;
            if(p.second==0) q.push_front(p.first);
            else q.pb(p.first);
        }
    }
}
int main(){
    #ifdef Megumin
        if(fopen(taskname".inp", "r"))
            freopen(taskname".inp", "r", stdin);
    #endif // Megumin
    read(n);
    read(m);
    FOR(i, 1, m){
        r[i]=-1;
        read(e[i].u);
        read(e[i].v);
        read(e[i].c);
        g[e[i].u].pb(i);
        g[e[i].v].pb(i);
    }
    FOR(i, 1, n){
        sort(g[i].begin(), g[i].end(), cmp);
        FFOR(j, 1, g[i].size()) if(e[g[i][j]].c==e[g[i][j-1]].c) uni(g[i][j], g[i][j-1]);
    }
    int p=n;
    FOR(i, 1, m){
        int x=root(i);
        if(to[x]==0) to[x]=++p;
        h[to[x]].pb(mp(e[i].u, 0));
        h[to[x]].pb(mp(e[i].v, 0));
        h[e[i].u].pb(mp(to[x], 1));
        h[e[i].v].pb(mp(to[x], 1));
    }
    bfs();
    if(done[n]) writeln(f[n]);
    else writeln(-1);
}

Measured memory_bytes: 30976
#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 = 1000001;

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

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

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

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

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


///////////////////////////
ll H, W;

ll v(ll i, ll j) {
	return (i - 1)*W + j;
}

ll N;

vector<vector<ll>> g;
vector<char> col;

vector<ll> see;

pair<ll, ll> bw(ll w) {
	see[w] = 1;
	pair<ll, ll> ret = {0,0};

	for (ll u : g[w]) {
		if (see[u] == 1) { continue; }
		pair<ll, ll> x = bw(u);
		ret.first += x.first;
		ret.second += x.second;
	}

	if (col[w] == '#') { ret.first++; }
	else { ret.second++; }

	return ret;
}



int main() {
	
	cin >> H >> W;

	N = H * W;

	vector<vector<char>> S(H + 1, vector<char>(W + 1));

	repn(i, H)repn(j, W) cin >> S[i][j];

	g.resize(N + 1);
	see.assign(N + 1, 0);
	col.assign(N + 1,'#');
	
	repn(i, H)repn(j, W) {
		col[v(i, j)] = S[i][j];

		
		if(i<H&&S[i][j]!=S[i+1][j]){
			g[v(i, j)].push_back(v(i + 1, j));
			g[v(i + 1, j)].push_back(v(i, j));
		}

		if (j < W&&S[i][j] != S[i][j + 1]) {
			g[v(i, j)].push_back(v(i, j + 1));
			g[v(i, j + 1)].push_back(v(i, j));
		}
	}

	
	ll ans = 0;

	repn(i, N) {
		if (see[i] == 1) { continue; }

		pair<ll, ll> x = bw(i);

		ans += x.first*x.second;
	}

	cout << ans;
	system("PAUSE");
}


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

#if DEBUG && !ONLINE_JUDGE
    #include "/home/tushar_garg/Desktop/cpp/debug.h"
#else
    #define dbg(x...)
#endif

typedef     long long                            ll; 
typedef		long double							 ld;
typedef     pair<ll, ll>                         pl; 
typedef     vector<ll>                           vl;
typedef     vector<ld>                           vld;
typedef     vector<char>                         vc;
typedef     vector<bool>                         vb; 
typedef     vector<vl>                           vvl; 
typedef     vector<pl>                           vll; 
typedef     map<ll, ll>                          dict; 
typedef     map<ll, ll, greater <ll> >           sdict; 
typedef     map<char, ll>                        mcl;
typedef     priority_queue<ll>                   pqi;
typedef     priority_queue<pl>                   pqii;
typedef     priority_queue<ll, vl, greater<ll>>  pqmini;

#define rep(i, a, n) for (auto i=(a)-((a)>(n)); i!=(n)-((a)>(n)); i+=1-2*((a)>(n)))
#define trav(i, a) for(auto &i:a)
#define fi first 
#define se second 
#define mp make_pair 
#define pb push_back
#define eb emplace_back
#define flash ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define QuickSilver cin.exceptions(cin.failbit),setprecision(12),cout.precision(12);
#define fill(a, b) memset(a, b, sizeof(a)
#define get(a) rep(i,0,sz(a))cin>>a[i];
#define sz(a) (ll)(a.size())
#define all(a) a.begin(), a.end()
#define mod 1000000007

void dfs(int s, int p, vl adj[], vvl &dp){
	for(int i:adj[s])
		if(i!=p){
			dfs(i, s, adj, dp);
			dp[s][0]=(dp[s][0]*(dp[i][0]+dp[i][1]))%mod;
			dp[s][1]=(dp[s][1]*dp[i][0])%mod;
		}
}

int main(){
	flash; QuickSilver;
	int n; cin>>n;
	vl adj[n];
	rep(i,0,n-1){
		int x,y; cin>>x>>y;
		x--; y--;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	vvl dp(n, vl(2,1));
	dfs(0, 0, adj, dp);
	cout<<(dp[0][0]+dp[0][1])%mod<<"\n";
	return 0;
}

Measured memory_bytes: 19584
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define maxl __LONG_LONG_MAX__
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define rep(i, n) for(int i = 0; i < n; i++)
#define rev(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i=1; i < n; i++)
#define rev1(i, n) for(int i=n ; i > 0; i--)
#define FOR(i, a, b) for(int i=a ; i < b; i++)

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vector<ll>> vvll;
typedef stack<ll> stk;
typedef queue<ll> que;
typedef map<ll,ll>::iterator mit;
typedef set<ll>::iterator sit;
typedef vector<ll>::iterator vit;

ll mod = 1e9 + 7;

void solve()
{
	ll n, w;
	cin>>n>>w;
	vll dp(w+1, 0);
	rep1(i, n+1)
	{
		ll W, V;
		cin>>W>>V;
		for(ll i = w; i >= W; i--)
			dp[i] = max(dp[i], dp[i-W] + V);
	}
	ll ans = 0;
	for(ll i = 0; i <= w; i++)
	{
		ans = max(ans, dp[i]);
	}
	cout<<ans<<endl;
	return;
}


int main()
{
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
	ll t = 1;
	//cin>>t;
	rep(i, t)
	{
		solve();
	}
	return 0;	
}

Measured memory_bytes: 1024
N = int(input())
A = sorted([int(i) for i in input().split()])[::-1]

k = -1
sum1 = 0
sum2 = 0
for i in A:
  if k==-1:
    sum1+=i
  else:
    sum2+=i
  k*=-1
print(sum1 -sum2)



Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	N, K, Q := getStdinInt3()
	Pt := make([]int, N)
	for i := 0; i < Q; i++ {
		A := getStdinInt()
		Pt[A-1]++
	}
	for i := 0; i < N; i++ {
		Pt[i] = K - (Q - Pt[i])
		//fmt.Printf("val=%d\n", Pt[i])
		if Pt[i] > 0 {
			fmt.Printf("Yes\n")
		} else {
			fmt.Printf("No\n")
		}
	}
}

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt2() (int, int) {
	list := getStdinIntArr()
	return list[0], list[1]
}
func getStdinInt3() (int, int, int) {
	list := getStdinIntArr()
	return list[0], list[1], list[2]
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinIntU64() uint64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return uint64(rtn)
}
func getStdinInt64_2() (int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1]
}
func getStdinInt64_3() (int64, int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1], list[2]
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}
func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}
func getStdinIntArrU64() []uint64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]uint64, len(list))
	for idx, val := range list {
		r, _ := strconv.ParseInt(val, 10, 64)
		rtn[idx] = uint64(r)
	}
	return rtn
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}
func abs64(n int64) int64 {
	if n < 0 {
		return -n
	}
	return n
}
func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, _ := sc.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 5224
/*
   Author: Shivam Shukla
   Problem URL: 
*/
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pair<ll,ll> > vpll;
 
const int MOD=1e9+7;
const int MAX=1e5+5;
const double PI= acos(-1.0);
const long double EPS=1e-10;
const int64_t INF=1e18+10;
 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0)
#define trace(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vi vector<int>
#define vl vector<ll>
#define vs vector<str>
#define vc(x) vector<x>
#define mapll map<ll,ll>
#define mapib map<int,bool>
#define mapiv map<int,vector>
#define mapsi map<string,int>
#define repa(i,n) for(ll i=0;i<n;i++)
#define dowa(i,n) for(ll i=n;i>=0;i--)
#define reps(i,j,k,s) for(ll i=j;i<k;i+=s)
#define downs(i,j,k,s) for(ll i=j;i>=k;i-=s)
#define trv(i,x) for(auto i:x)
#define pb push_back
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define str string 
#define dub double
#define pqmax priority_queue<ll>
#define pqmin priority_queue<ll,vl,greater<ll> >
 
template<typename t> t lcm(t a, t b) {return (a*b)/__gcd(a,b);}
template<typename t> t gcd(t a, t b) {return __gcd(a,b);}
template<typename t> t mul_mod(t a, t b, t m){t res=((a%m)*(b%m)%m); return res;}
template<typename t> t add_mod(t a, t b, t m){t res=((a%m)+(b%m))%m; return res;}
template<typename t> t pow(t a,t b,t m) {t res=1;while(b){if(b&1) res=mul_mod(res,a,m);a=mul_mod(a,a,m), b>>=1;} return res%m;}
template<typename t> vc(t) num_vec(t num) {t res; while (num) res.pb(num%10), num/=10; return res;}
template<typename t> t vec_num(t vec) {t res=0; ll mul=1; repa(i,sz(vec)) res=vec[i]*mul, mul*=10; return res;}
 

ll possible(vl& a){
	unordered_map<int,int> mp;
	bool val = true;
	for(int i=0;i<sz(a);i++)
			mp[a[i]]++;

	if(sz(a) & 1){
		if(mp[0] != 1) val = false;
		for(auto i : mp)
			if(i.ss != 2 && i.ff>0)
				val=false;	
	}
	else{
        for(auto i : mp)
        	if(i.ss!=2)
        		val = false;
	}
    long long ans = 1;
    ll mod = 1e9+7;
	repa(i,sz(a)>>1) 
       ans = (ans<<1) % mod;

    return (val) ? (ans % mod) : 0;
}
int32_t main(int argc,char** argv){
	fastio();
	auto tstart= clock();
    
    /* Code Starts Here */
    ll n;cin>>n;
    vl a(n); repa(i,n) cin>>a[i];

    cout<<possible(a)<<endl;   
    /* Code Ends Here */

    cerr<<setprecision(2)<<fixed<<"Time elapsed: "<<(double)(clock() - tstart)/CLOCKS_PER_SEC<<endl; 
    return 0; 
}

Measured memory_bytes: 4492