akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>

using namespace std;

#define ALL(co) co.begin(), co.end()
#define tpl(...) make_tuple(__VA_ARGS__)

typedef long long LL;
typedef pair<int, int> P; typedef pair<int, P> IP; typedef pair<P, P> PP;
typedef vector<int> Array; typedef vector<vector<int> > Array2;
typedef vector<LL> LArray; typedef vector<P> PArray; typedef vector<string> SArray;

const int INF = 1 << 29;
const LL LINF = 1LL << 60;

inline int getInt() { int itiv; return (cin >> itiv, itiv); }
template <typename T> void readAll(vector<T>& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i]; }
template <typename T, typename U> void readAll(vector<pair<T, U> >& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i].first >> vec[i].second; }
template < typename T > inline string toString( const T &a ){ ostringstream oss; oss << a; return oss.str(); };
inline bool between(int min, int max, int n) { return min <= n && n <= max; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }

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

int m, n;

int main(void)
{
	Array w(10), k(10);
	readAll(w); readAll(k);
	sort(ALL(w)); sort(ALL(k));
	int ws = 0, ks = 0;
	for (int i = 0; i < 3; i++)
	{
		ws += w[9 - i];
		ks += k[9 - i];
	}
	cout << ws << ' ' << ks << endl;
	return 0;
}

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int i=0;i<(n);i++)        //repeat n times
#define REP2(i,s,n) for(int i=(s);i<(n);i++)   //repeat from s to n 
#define REPD(i,n) for(int i=(n);i>=0;i--)      //repeat from n to 0
#define REPD2(i,s,e) for(int i=(s);i>=(e);i--) //repeat from s to e
#define RANGE(i,v) for(auto &i:v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T1,typename T2> using P = pair< T1, T2 >;
using Pii = P<int,int>;
using Pll = P<LL,LL>;
using Pdd = P<double,double>;
using Psi = P<string,double>;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

int main(){
    Vi x(5);
    REP(i,5) cin>>x[i];
    
    REP(i,5) if(x[i]==0) cout<<i+1<<endl;

    return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include<stack>


using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SRTVG(v) sort(v.begin(),v.end(),greater<>())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define MOD 1000000007
#define INF INT_MAX/2

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef vector<int> Vi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}


int keta(int n,int m){
    if(n<pow(10,m-1)) return -1;
    int tmp = n/pow(10,m-1);
    tmp %= 10;
    return tmp;
}

int atcoder() {
    int n,k;
    cin >> n >> k;
    map<int,int> mp;
    REP(i,0,k){
        int tmp;
        cin >> tmp;
        mp[tmp]++;
    }
    bool check=true;
    
    for(; check; n++){
        check = false;
        REP(j,1,log10(n)+2){
            if(mp[keta(n,j)]==1) check=true;
        }
    }
    
    cout << n-1 << ENT;
    
    return 0;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    atcoder();
    return 0;
}


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

int main()
{
  int N;
  cin>>N;
  vector<int> X(N);
  for(int i=0; i<N; i++){
    cin>>X.at(i);
  }
  int cost;
  for(int i=1; i<=100; i++){
    int temp=0;
    for(int j=0; j<N; j++){
      temp+=(X.at(j)-i)*(X.at(j)-i);
    }
    if (i==1) cost=temp;
    else if (cost>temp) cost=temp;
  }
  cout<<cost<<endl;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
A = [0] + list(map(int,input().split()))

now = 1
route = []
dic = {}
cnt = 0
entry = []
loop = []

while True:
  cnt += 1
  now = A[now]
  route.append(now)
  if now in dic:
    entry = route[:dic[now]]
    loop = route[dic[now]:]
    break
  dic[now] = cnt

if K <= len(entry):
  print(entry[K - 1])
else:
  K -= 1
  K -= len(entry)
  K %= len(loop)
  print(loop[K])

Measured memory_bytes: 40132
s = input()
ans = 0
ans_l = [0]*len(s)


for i in range(len(s)):
    if s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T":
        ans_l[ans] += 1
    else:
        ans += 1
print(max(ans_l))


Measured memory_bytes: 2940
from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))
a.sort()
if N % 3 == 0:
    i = N // 3
    if a[0] ^ a[i] == a[2 * i]:
        if a[0] == a[i -1] and a[i] == a[2 * i - 1] and a[2 * i] == a[N -1]:
            print("Yes")
            exit(0)
            
d = defaultdict(int)

for c in a[1:]:
    d[c] += 1
for i in range(1, N):
    x = a[0]
    y = a[i]
    d[y] -= 1
    for _ in range(N - 2):
        z = x ^ y
        if z in d and d[z] > 0:
            d[z] -= 1
            x = y
            y = z
        else:
            break
    else:
        if a[0] == x ^ y and a[i] == y ^ a[0]:
            print("Yes")
            exit(0)

print("No")

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

int main() {
	int x,y,y1,z,s;
	while(cin >> x >> y) {
		if (x==0 && y==0) break;
		if (x<y) { z=x; x=y; y=z;}
		s=y1=0; 
		while(y!=0){ z=x % y; y1=y; x=y; y=z; s++;}
		cout << y1 << ' ' << s << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		List<String> list = new ArrayList<String>();
		String[] mark ={"S","H","C","D"};

		for(int i=0;i<=3;i++){
			for(int j=0;j<=12;j++){
				list.add(mark[i]+" "+(j+1));
			}
		}
		for(int i=0;i<=n-1;i++){
			list.remove(sc.nextLine());
		}
		for(String ans:list){
			System.out.println(ans);
		}
	}
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

pll T[100005];

int main()
{
    int N;
    ll K;
    cin >> N >> K;
    REP(i, N)
    {
        cin >> T[i].first >> T[i].second;
    }
    sort(T, T + N, [](pll a, pll b) { return a.first < b.first; });
    REP(i, N)
    {
        K -= T[i].second;
        if (K <= 0)
        {
            cout << T[i].first << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int h1 = sc.nextInt();
    int m1 = sc.nextInt();
    int h2 = sc.nextInt();
    int m2 = sc.nextInt();
    int k = sc.nextInt();

    int min = 0;
    int ans = 0;

    if(m2 > m1){
      min = (h2 - h1) * 60 + (m2 - m1);
    } else {
      min = (h2 - 1 - h1) * 60 + (m2 + 60 - m1);
    }

    ans = min - k;

    System.out.println(ans);
  }
}


Measured memory_bytes: 35768
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define MODNUM (static_cast<int>(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

template <typename T>
int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T>
T square(T x) {
	return x * x;
}

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main() {
	char s[101];
	int n;
	scanf("%s", s);
	n = strlen(s);
	int result = 0;
	int i, j;
	i = 0;
	j = n - 1;
	while(i <= j) {
		if(s[i] != s[j]) {
			result++;
		}
		i++;
		j--;
	}

	printf("%d\n", result);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
long long num[200050];
long long sum[200050];
int main() {
	scanf("%d",&n);
	sum[0]=0;
	for(int i=1;i<=n;i++) {
		scanf("%lld",&num[i]);
		sum[i]=sum[i-1]+num[i];
	}
	long long mi=1e18;
	for(int i=1;i<=n-1;i++) {
		mi=min(mi,abs((sum[i]-sum[0])-(sum[n]-sum[i])));
	}
	printf("%lld\n",mi);
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#define M 100005
#define N 100005
using namespace std;
int n,m;
struct query{
    int x,y;
}a[M];
bool red_possible[N];
int ball_number[N];
int ans=0;
int main(){
    cin>>n>>m;
    for(int i=1;i<=m;i++)
        cin>>a[i].x>>a[i].y;
    for(int i=1;i<=n;i++)
        ball_number[i]=1;
    red_possible[1]=true;
    for(int i=1;i<=m;i++){
        if(ball_number[a[i].x]==0)//没球跳过
            continue;
        if(red_possible[a[i].x]){//有球且有红球的可能性
            if(!red_possible[a[i].y])
                red_possible[a[i].y]=true;
            if(ball_number[a[i].x]==1)
                red_possible[a[i].x]=false;
        }
        ball_number[a[i].x]--;
        ball_number[a[i].y]++;
    }
    for(int i=1;i<=n;i++)
        if(red_possible[i])
            ++ans;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1536
#include<stdio.h>

int main() {
    int m,d;
    int count = 0;
    scanf("%d%d", &m,&d);
    for(int i = 1; i <= m; i++) {
        for(int j = 1; j <= d; j++) {
            if(i == ((j/10)*(j%10)) && j/10 > 1 && j%10 > 1) {
                count++;
            }
        }
    }
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 128
#include "iostream"
using namespace std;
int main()
{
	int jueleValue[20], jueleCost[20], ans=0, n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> jueleValue[i];
	}
	for (int i = 0; i < n; i++)
	{
		cin >> jueleCost[i];
	}
	for (int i = 0; i < n; i++)
	{
		if (jueleValue[i] > jueleCost[i])
		{
			ans += (jueleValue[i] - jueleCost[i]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
N, K = gets.split.map(&:to_i)
D    = gets.split.map(&:to_i)

NUMS = []
0.upto(9){ |i| NUMS << i.to_s unless D.include?(i) }

def dfs(s)
  #p "s     : #{s}"
  #p "s.to_i: #{s.to_i}"
  if s.to_i >= N
  #p "       ------> over"
    return s.to_i
  else
    anss = []
    NUMS.each do | n |
      next if s == '0' && n == '0'
      ans = dfs(s + n)
      anss << ans if ans >= N
    end
    return anss.min
  end
end

p dfs('0')

Measured memory_bytes: 1788
n, m, X, Y = map(int, input().split())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]

for Z in range(X+1, Y+1):
   if (max(x) < Z and min(y) >= Z):
      print('No War')
      exit()
print('War')


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

namespace arc078_a
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = GetInt();
            var al = GetLongList();
            var ar = new List<long>();

            ar.Add(al[0]);

            for (int i = 1; i < N; i++)
                ar.Add(ar[i - 1] + al[i]);

            var rm = long.MaxValue;
            for (int i = 0; i < N - 1; i++)
            {
                var r = Math.Abs(ar[i] - (ar.Last() - ar[i]));
                if (r < rm) rm = r;
            }

            Console.WriteLine(rm);
                
        }

        public static string GetStr() => Console.ReadLine();
        public static int GetInt() => int.Parse(Console.ReadLine());
        public static long GetLong() => long.Parse(Console.ReadLine());
        public static double GetDouble() => double.Parse(Console.ReadLine());
        public static decimal GetDecimal() => decimal.Parse(Console.ReadLine());

        public static List<string> GetStrList() => Console.ReadLine().Split(' ').ToList();
        public static List<int> GetIntList() => Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
        public static List<long> GetLongList() => Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
        public static List<double> GetDoubleList() => Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToList();
        public static List<decimal> GetDecimalList() => Console.ReadLine().Split(' ').Select(x => decimal.Parse(x)).ToList();

    }
}


Measured memory_bytes: 36804
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;
const double PI = acos(-1);

bool comb(pair<int, int> a, pair<int, int> b) {
	return a.second < b.second;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> ab(m);
	rep(i, m) {
		cin >> ab[i].first >> ab[i].second;
	}
	sort(ab.begin(), ab.end(), comb);

	int ans = 0;
	int end = 0;
	rep(i, m) {
		if (ab[i].first >= end) {
			end = ab[i].second;
			ans++;
		}
	}

	out(ans);

	return 0;
}

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

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector<int> ans;
    for (int i = N-1; i >= 0; i -= 2) {
        ans.push_back(A[i]);
    }
    for (int i = N%2; i < N; i += 2) {
        ans.push_back(A[i]);
    }
    cout << ans[0];
    for (int i = 1; i < N; i++) {
        cout << " " << ans[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
/* END OF TEMPLATE */

// 隣接リスト
vvll g(100010, vll());
vi visited0(100010, 0);
vi visited1(100010, 0);
vi visited2(100010, 0);

ll n;

// グラフに対する幅優先探索
ll bfs(ll start, ll goal){
    queue<pll> q;
    visited0[start] = 1;
    q.push(make_pair(start, 0));
    while (!q.empty()) {
        ll now = q.front().first;
        ll depth = q.front().second;
        //dump2(now, depth);
        q.pop();
        if(now == goal && depth % 3 == 0){
            return depth / 3;
        }
        rep(i, SZ(g[now])){
            ll next = g[now][i];
            if((depth) % 3 == 0 && !visited1[next]){
                visited1[next] = 1;
                q.push(make_pair(next, depth+1));
            }
            if((depth) % 3 == 1 && !visited2[next]){
                visited2[next] = 1;
                q.push(make_pair(next, depth+1));
            }
            if((depth) % 3 == 2 && !visited0[next]){
                visited0[next] = 1;
                q.push(make_pair(next, depth+1));
            }
            /*if(depth <= 3*n+5 && (visited[next] < 0 || (visited[next] >= 0 && (depth+1-visited[next])%3 != 0))){
                visited[next] = depth+1;
                q.push(make_pair(next, depth+1));
            }*/
        }
    }
    return -1;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll m;
    cin >> n >> m;
    vll u(m), v(m);
    rep(i, m){
        cin >> u[i] >> v[i];
        g[u[i]].emplace_back(v[i]);
    }
    ll s, t;
    cin >> s >> t;
    cout << bfs(s, t) << endl;
    return 0;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define PP pair<P,P>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	random_device rnd;
	mt19937_64 mt64(rnd());
	uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/

string s;
int dp[222222][2];
signed main() {
	cin >> s;
	dp[1][0] = 1; dp[2][1] = 1;
	REP(i, s.size()) {
		if (i > 1) {
			chmax(dp[i + 1][0], dp[i][1] + 1);
		}
		if (s[i - 1] != s[i]) {
			chmax(dp[i + 1][0], dp[i][0] + 1);
		}
		chmax(dp[i + 2][1], dp[i][0] + 1);
	}
	cout << max(dp[s.size()][0], dp[s.size()][1]) << endl;
}

Measured memory_bytes: 3716
# -*- coding: utf-8 -*-
#深さ優先探索　再帰
#
import sys
sys.setrecursionlimit(200000)

N=input()


a=[[] for i in range(N+1)]

#隣接リスト
for i in range(N-1):
	x,y,z=list(map(int,raw_input().split()))
	a[x].append((y,z))
	a[y].append((x,z))

#print a
	

Q,K=list(map(int,raw_input().split()))


b=[]
for i in range(Q):
	b.append(map(int, raw_input().split()))
#print b



#訪問判別フラグ
F=(N+1)*[0]

#距離
dist=[0 for i in range(N+1)]

#深さ優先探索　再帰
#現在の頂点 v, v の親 p, スタート地点Kから現在の頂点vまでの距離 d
def dfs(v,p,d):
	F[v]=1
	dist[v]=d
	for i,j in a[v]:
		#頂点 v に隣接しているかつ未訪問 
		if F[i]==0:
			#DFS(次の頂点i, 次に親となる頂点v, d+ 頂点vと頂点iの間の辺のコスト)
			dfs(i,v,d+j)


dfs(K,-1,0)

for x in range(len(b)):
	print dist[ b[x][0] ]+ dist[ b[x][1] ]



Measured memory_bytes: 144796
#include<bits/stdc++.h>
#define test int t; cin>>t; while(t--)
#define fast ios::sync_with_stdio(false);
#define pi 3.14159265358979323846264338327950288419716939937510
#define pb push_back
typedef long long ll;
using namespace std;
int main()
{
   fast
   ll n;
   cin>>n;
   cout<<n+(n*n*n)+(n*n)<<endl;
return 0;
}


Measured memory_bytes: 3600
# -*- coding: utf-8 -*-
import sys, re, copy, math, itertools
from copy import *
from collections import deque, defaultdict
from heapq import *
from bisect import *
#import numpy as np
#import scipy as sp

# 読み込み
R = int( input() )
G = int( input() )

print(2*G-R)

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

int insertion_sort(int,int[],int,int);
int shellSort(int,int[]);
void printArray(int[],int);
int main(int argc, char** argv) {
    int size;
    scanf("%d\n", &size);
    int array[size];
    for(int i = 0; i < size; i++)
        scanf("%d", &array[i]);
    
    int count = shellSort(size,array);
    printf("%d\n", count);
    printArray(array,size);
    
    return (EXIT_SUCCESS);
}

int insertion_sort(int size, int array[size], int gap, int count){
    int temp, j;
    for(int i = gap; i < size; i++){
        temp = array[i];
        j = i - gap;
        while(j >= 0 && array[j] > temp){
            array[j+gap] = array[j];
            j -= gap;
            if(size != 1) count++;
        }
        array[j+gap] = temp;
    }
    return count;
}

int shellSort(int size, int array[size]){
    int count = 0;
    int m;
    for(int i = 1; (pow(3,i)-1)/2 <= size; i++)
        m = i;
    int gap[m]; //Pratt 1971 Gap sequence
    for(int i = m; i > 0; i--)
        gap[i-1] = (pow(3,i)-1)/2;
    printf("%d\n", m);
    for(int i = m-1; i >= 0; i--){
        if(size >= gap[i] || gap[i] == 1){
            count = insertion_sort(size, array, gap[i], count);
            if(i != 0)
                printf("%d ", gap[i]);
            else
                printf("%d\n", gap[i]);
        }
    }
    return count;
}

void printArray(int array[], int count){
    for(int i = 0; i < count; i++){
        printf("%d\n", array[i]);
    }
}



Measured memory_bytes: 5832
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){ T x; cin >> x; return (x); }
template<typename T=int,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return move(x); }

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){ return graph.size(); }
};

class BellmanFord{
	vector<ll> dist;
	set<ll> visit;
	bool ignore_unrelated_loop{false};

	bool CanReachImpl(int start,int end,ConnectNodeInfo& connect){
		bool reach=false;
		if(start==end) return true;

		for(int i=0,ei=connect[start].size();i<ei;i++){
			auto res = visit.emplace(connect[start][i].first);
			if(!res.second) continue;
			reach |= CanReachImpl(connect[start][i].first,end,connect);
		}
		return reach;
	}
	bool CanReach(int start,int end,ConnectNodeInfo& connect){
		visit.clear();
		visit.emplace(start);
		return CanReachImpl(start,end,connect);
	}
public:
	pair<ll,bool> CalcShortestPath(int start,int end,ConnectNodeInfo& connect){
		dist.resize(connect.size(),1LL<<60);

		dist[start] = 0;
		for(int i=0,ei=dist.size();i<ei;i++){
			for(int u=0,eu=connect.size();u<eu;u++){
				for(int v=0,ev=connect[u].size();v<ev;v++){
					auto& e = connect[u][v];

					if(dist[e.first]>dist[u]+e.second){
						dist[e.first] = dist[u]+e.second;
						if(i==ei-1){
							if(!ignore_unrelated_loop || (CanReach(start,u,connect) && CanReach(u,end,connect))){
								return make_pair(dist[end],false);
							}
						}
					}
				}
			}
		}
		return make_pair(dist[end],true);
	}
	void SetIgnoreUnrelatedLoop(bool flag){ ignore_unrelated_loop=flag; }
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in(),M=in();
	ConnectNodeInfo connect(N);
	REP(i,M){
		ll u=in()-1,v=in()-1,c=in();
		connect.AddDirectionalConnection(u,v,-c);
	}
	
	BellmanFord BF;
	BF.SetIgnoreUnrelatedLoop(true);
	auto res = BF.CalcShortestPath(0,N-1,connect);
	if(!res.second) out("inf");
	else out(-res.first);
	return 0;
}


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

int main(){
  
  int n,t;
  cin>>n>>t;
  int a[t];
  int ans;
  for(int i=0;i<t;i++) cin>>a[i];
  sort(a,a+t);
  reverse(a,a+t);
  
  ans=a[0];
  ans--;
  for(int i=1;i<t;i++){
    ans-=a[i];
  }
  if(ans<0) ans=0;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<int> a(N);
    vector<int> b(N);
    vector<int> c(N);
    rep(i,N)cin >> a[i] >> b[i] >> c[i];
    int tmp;
    vector<vector<int>> dp(N+1,vector<int> (3,0));
    rep(i,N) rep(j,3) rep(k,3){
        if(k == j)continue;
        if(j == 0)tmp = a[i];
        if(j == 1)tmp = b[i];
        if(j == 2)tmp = c[i];
        chmax(dp[i+1][j],dp[i][k] + tmp);
    }
    int ans = dp[N][0];
    ans = max(ans,dp[N][1]);
    ans = max(ans,dp[N][2]);
    cout << ans << endl;
}

// 

Measured memory_bytes: 6912
# 最終的に.......#####の並びになると想定
# それぞれの累積和の足し算が最小になる境目を求める
N = int(input())
S = list(input())
b = [0] * N
w = [0] * N
x, y = 0, 0
ans = 0
# 累積和
for i in range(N):
    if S[i] == '#':
        x += 1
    else:
        y += 1
    b[i] = x
    w[i] = y

ans = float('inf')
for i in range(N):
    ans = min(ans, b[i] + w[N-1] - w[i])
print(min(ans, b[N-1], w[N-1]))


Measured memory_bytes: 14116
import os
import sys
from io import BytesIO, IOBase


def solution():
    pass


def main():
    n, k = r_array()
    res = [0] * n
    for _ in range(k):
        d = r_int()
        darr = r_array()
        for x in darr:
            res[x - 1] += 1

    write(sum(u == 0 for u in res))


# fast-io region

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)


def input():
    return sys.stdin.readline().rstrip("\r\n")


def write(*args, end='\n'):
    for x in args[:-1]:
        sys.stdout.write(str(x) + ' ')
    sys.stdout.write(str(args[-1]))
    sys.stdout.write(end)


def r_array():
    return [int(x) for x in input().split()]


def r_int():
    return int(input())


if __name__ == "__main__":
    main()


Measured memory_bytes: 67488
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vll2 = vector<vector<ll>>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int n;
string s;
vll2 G;
vll cnt, lb, ub;
void dfs(int i, int p) {
    cnt[i] = s[i] - '0';
    lb[i] = 0;
    ub[i] = 0;
    ll sum = 0;
    if (G[i].size() == 1 && p != -1) {
        return;
    }
    for (auto &e : G[i]) {
        if (e == p) {
            continue;
        }
        dfs(e, i);
        lb[e] += cnt[e];
        ub[e] += cnt[e];
        ub[i] += ub[e];
        cnt[i] += cnt[e];
        sum += ub[e];
    }
    ll ma = -INF;
    for (auto &e : G[i]) {
        if (e == p) {
            continue;
        }
        chmax(ma, lb[e] - (sum - ub[e]));
    }
    if (ma <= 0) {
        lb[i] = sum % 2;
    } else {
        lb[i] = ma;
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    cin >> s;
    G.resize(n);
    cnt.resize(n);
    lb.resize(n);
    ub.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    ll res = INF;
    for (int i = 0; i < n; i++) {
        dfs(i, -1);
        if (lb[i] == 0) {
            chmin(res, ub[i] / 2LL);
        }
    }
    if (res == INF) {
        cout << -1 << endl;
    } else {
        cout << res << endl;
    }
}

/*
集める頂点を決め打ちし、根として考える。
ここで、操作は、「ある頂点を選び、異なる子の部分木に属する2頂点をそこに近づける」ということに等しい。
各部分木について、「その部分木内の深さの和が達成できる値の範囲」を知りたい。
2ずつ減っていくので、[lb,ub]間のある偶奇のものはすべて達成可能。
明らかに、ub=(今の深さの和)である。このとき、lbは、(maxlb)<=sumubかつ深さ和が偶数ならば必ず0。
偶奇のみダメならば1.そうでなければ、maxlb-sumub.*/

Measured memory_bytes: 512
H,W=map(int,input().split())
S=[[0 for i in range(0,W)] for i in range(0,H)]
for i in range(0,H):
    S[i]=input().split()

load=[]
for i in range(0,H):
    for j in range(0,W):
        if S[i][0][j]=='.':
            load.append((i,j))

ans=0
dp=[[500 for i in range(0,W)] for i in range(0,H)]
dp[0][0]=0
q=[]
q.append((0,0))
sub=[]
while q!=[]:
    while q!=[]:
        x=q[0]
        q.remove(x)
        s=x[0]
        t=x[1]
        if (s+1,t) in load and dp[s+1][t]>dp[s][t]+1:
            sub.append((s+1,t))
            dp[s+1][t]=dp[s][t]+1
        if (s,t+1) in load and dp[s][t+1]>dp[s][t]+1:
            sub.append((s,t+1))
            dp[s][t+1]=dp[s][t]+1
        if (s-1,t) in load and dp[s-1][t]>dp[s][t]+1:
            sub.append((s-1,t))
            dp[s-1][t]=dp[s][t]+1
        if (s,t-1) in load and dp[s][t-1]>dp[s][t]+1:
            sub.append((s,t-1))
            dp[s][t-1]=dp[s][t]+1
        if q==[]:
            q=sub
            sub=[]
            break
if dp[H-1][W-1]==500:
    print(-1)
else:
    print(len(load)-dp[H-1][W-1]-1)

Measured memory_bytes: 41580
import sys
import numpy as np 

n, l = map(int, sys.stdin.readline().split())

def main():
    f = l + np.arange(1, n+1) - 1
    s = f.sum()
    a = np.absolute(f)
    mi = np.amin(a)
    i = np.argwhere(a == mi)[0, 0]
    return s - f[i]

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 12488
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Contest20191031
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] sInput = Console.ReadLine().Split(' ');
            int n = int.Parse(sInput[0]);
            int k = int.Parse(sInput[1]);
            int[] h = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int count = 0;
            foreach(int i in h)
            {
                if (i >= k)
                    count++;
            }
            Console.WriteLine(count);

        }
    }
}


Measured memory_bytes: 17248
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
   return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
   os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n,m,k;cin>>n>>m>>k;
  rep(i,0,n+1){
    rep(j,0,m+1){
      if(i*j + (n-i)*(m-j)==k){
        cout<<"Yes"<<ENDL;
        return 0;
      }
    }
  }
  cout<<"No"<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
   int W,H,x,y,r;
   cin>>W>>H>>x>>y>>r;

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


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

typedef long long ll;

int gcd(int a, int b){
  if(b==0) return a;
  else return gcd(b, a%b);
}

int multi(int a, int b, int c){
  if (a!=b && b!=c) return 6;
  else if (a==b && b==c) return 1;
  else return 3;
}

int main(){
  int K;
  cin >> K;
  int sum=0;
  for(int i=1; i<=K; i++){
    for(int j=1; j<=i; j++){
      for(int k=1; k<=j; k++){
        int g=gcd(gcd(i,j),k);
        sum+=g*multi(i,j,k);
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <string>

using namespace std;

void solve();

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

void solve() {
    int n;
    cin >> n;
    int a[n];
    int a_0,a_1,a_2;
    a_0 = a_1 = a_2 = 0;
    for(int i = 0 ;i < n; i++) {
        cin >> a[i];
        if(a[i] % 3 == 0) a_0++;
        else if(a[i] % 3 == 1) a_1++;
        else a_2++;
    }
    int a_0c = a_0;
    int a_1c = a_1;
    int a_2c = a_2;

    int sum = 0;
    int now = 0;
    if(a_1 != 0) {
        now = 1;
        sum++;
        a_1--;
    } else if(a_2 != 0) {
        now = 2;
        sum++;
        a_2--;
    } else {
        now = 0;
        sum++;
        a_0--;
    }
    while(1) {
        if(now == 0 || (a_0 == 0 && a_1 == 0 && a_2 == 0)) break;
        if(now == 1) {
            if(a_0 != 0) {
                now = 1;
                sum++;
                a_0--;
            } else if(a_1 != 0) {
                now = 2;
                sum++;
                a_1--;
            } else if(a_2 != 0){
                now = 0;
                sum++;
                a_2--;
            }
        } else {
            if(a_0 != 0) {
                now = 2;
                sum++;
                a_0--;
            } else if(a_2 != 0){
                now = 1;
                sum++;
                a_2--;
            } else if(a_1 != 0) {
                now = 0;
                sum++;
                a_1--;
            }
        }
    }

    int sumcp = sum;
    sum = 0;
    now = 0;
    a_2 = a_2c;
    a_1 = a_1c;
    a_0 = a_0c;

    if(a_2 != 0) {
        now = 2;
        sum++;
        a_2--;
    } else if(a_1 != 0) {
        now = 1;
        sum++;
        a_1--;
    } else {
        now = 0;
        sum++;
        a_0--;
    }
    while(1) {
        if(now == 0 || (a_0 == 0 && a_1 == 0 && a_2 == 0)) break;
        if(now == 1) {
            if(a_0 != 0) {
                now = 1;
                sum++;
                a_0--;
            } else if(a_1 != 0) {
                now = 2;
                sum++;
                a_1--;
            } else if(a_2 != 0){
                now = 0;
                sum++;
                a_2--;
            }
        } else {
            if(a_0 != 0) {
                now = 2;
                sum++;
                a_0--;
            } else if(a_2 != 0){
                now = 1;
                sum++;
                a_2--;
            } else if(a_1 != 0) {
                now = 0;
                sum++;
                a_1--;
            }
        }
    }
    cout << max(sum,sumcp) << endl;
}

Measured memory_bytes: 5164
n, m = map(int, input().split())

ab = [list(map(int, input().split())) for _ in range(n)]
sorted_ab = sorted(ab, key=lambda x: x[0])

i,ans,cnt = 0,0,0

while cnt < m:
    ans += sorted_ab[i][0]*min(m-cnt,sorted_ab[i][1])
    cnt += min(m-cnt,sorted_ab[i][1])
    i+=1
print(ans)

Measured memory_bytes: 29796
var input = ""
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
 
process.stdin.on('end', function() {
  input = input.split("\n");

  var text = input[0];
  var q = parseInt(input[1], 10);

  for (i = 2; i <= q + 2; i++) {
    var order = input[i].split(" ");
    var a = parseInt(order[1], 10);
    var b = parseInt(order[2], 10);

    switch (order[0]) {
      case "print":
        console.log(text.slice(a, b + 1));
        break;
      case "reverse":
        text = text.slice(0, a) + text.slice(a, b + 1).split("").reverse().join("")
                + text.slice(b + 1);
        break;
      case "replace":
        text = text.slice(0, a) + order[3] + text.slice(b + 1);
        break;
    }
  }
});

Measured memory_bytes: 16772
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/

int main() {
  int n;
  cin >> n;
  rep(i,1000){
    int res = i*(i-1)/2;
    if(n!=res) continue;
    cout << "Yes" << endl;
    cout << i << endl;
    vector<int> v[i];
    int cnt=1;
    rep(j,i)REP(k,j+1,i){
      v[j].emplace_back(cnt);
      v[k].emplace_back(cnt);
      cnt++;
    }
    rep(j,i){
      cout << v[j].size() << " ";
      for(auto it:v[j]) cout << it << " ";
      cout << endl;
    }
    return 0;
  }

  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 2304
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}

use input::*;

fn main() {
    let (a, b): (usize, usize);
    input!(a, b);
    p(std::cmp::max(a, b) + std::cmp::max(std::cmp::max(a, b) - 1, std::cmp::min(a, b)));
}



Measured memory_bytes: 4352
x = input().split()
a = int(x[0])
b = int(x[1])
c = int(x[2])
d = int(x[3])
e = int(a + b)
f = int(c + d)
if e < f :
    print('Right')
if e == f :
    print('Balanced')
if e > f :
    print('Left')
    


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <utility>
#include <numeric>
#include <functional>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <deque>
#include <queue>
#include <map>

#define rep(i, m, n) for (int (i)(m); (i)<(n); ++(i))
#define repr(i, m, n) for (int (i)(m - 1); (i)>=(n); --(i))
#define repv(i, v) for (unsigned (i)(0); (i)<(v.size()); ++(i))
#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define sortgi(v) sort(all(v), greater<int>())
#define sortgd(v) sort(all(v), greater<double>())
#define sortgll(v) sort(all(v), greater<ll>())
#define debug(x) cerr << #x << ": " << x << '\n'

using namespace std;
using pii = pair<int, int>;
using pss = pair<string, string>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using ll = long long;
using pllll = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using pqi = priority_queue<int>;
using pqd = priority_queue<double>;
using pqll = priority_queue<ll>;
using pqvi = priority_queue<vi>;
using pqvll = priority_queue<vll>;

ll mod = 1e9 + 7;

int main() {
	string s;
	cin >> s;
	ll n = 1;
	ll a = 0;
	ll ab = 0;
	ll abc = 0;
	repv(i, s) {
		if (s[i] == 'A') {
			a += n;
			a %= mod;
		}
		else if (s[i] == 'B') {
			ab += a;
			ab %= mod;
		}
		else if (s[i] == 'C') {
			abc += ab;
			abc %= mod;
		}
		else if (s[i] == '?') {
			abc += 2 * abc + ab;
			abc %= mod;
			ab += 2 * ab + a;
			ab %= mod;
			a += 2 * a + n;
			a %= mod;
			n *= 3;
			n %= mod;
		}
	}
	cout << abc << endl;
}


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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int[] a = new int[30];

		for (int i = 0 ; i < 28 ; i++){
			int no = sc.nextInt();
			a[no-1] = no;
		}
		for(int j = 0 ; j < 30 ; j++){
			if (a[j] == 0){
				System.out.println(j+1);
			}
		}
		
		sc.close();
	}

}

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

int main(){
	string S;
	cin >> S;
  
  int s = S.size();
    char a = S.at(s - 1);
  if(a == 's'){
  cout << S << "es" << endl;
  }
  else{
  cout << S << "s" << endl;
  }
}


Measured memory_bytes: 3560
use std::io::Read;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();

    let mut a: Vec<usize> = vec![0; n];
    let b0: usize = iterator.next().unwrap().parse().unwrap();
    a[0] = b0;
    a[1] = b0;
    for i in 1..(n-1) {
        let bi: usize = iterator.next().unwrap().parse().unwrap();
        a[i + 1] = bi;
        a[i] = min(a[i], bi);
    }

    let answer = a.iter().fold(0, |acc, &x| acc + x);

    return answer.to_string();
}

#[test]
fn test() {
    assert_eq!(
        solve(
            r"6
0 153 10 10 23"
        ),
        "53"
    );
    assert_eq!(
        solve(
            r"2
3"
        ),
        "6"
    );
    assert_eq!(
        solve(
            r"3
2 5"
        ),
        "9"
    );
}


Measured memory_bytes: 4352