akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>
#include <list>
#include <stack>

typedef long long ll;
using namespace std;
const int mod = 1000000007;

static const int N = 100;

vector<int> d(N, 0), f(N, 0);
vector< vector<int> > Adj(N, vector<int>());
int t = 0;
void dfs(int node);

int main() {

    int n; cin >> n;

    for (int i = 0; i < n; i++) {
        int u, k; cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            int v; cin >> v;
            v--;
            Adj[u].push_back(v);
        }
    }

    for (int i = 0; i < n; i++) {
        if (d[i] == 0) {
            dfs(i);
        }
    }

    for (int i = 0; i < n; i++) {
        cout << i + 1 << ' ' << d[i] << ' ' << f[i] << '\n';
    }

}

void dfs(int node) {

    if (!d[node]) {
        t++;
        d[node] = t;
    }
    for (int i = 0; i < Adj[node].size(); i++) {
        int v = Adj[node][i];
        if (d[v] != 0) {
            continue;
        }
        else {
            t++;
            d[v] = t;
            dfs(v);
        }
    }
    t++;
    f[node] = t;
}




Measured memory_bytes: 3168
import java.util.ArrayList;
import java.util.Scanner;




class Main{


	static	ArrayList<Integer> one ;
	static	ArrayList<Integer> two ;
	static	ArrayList<Integer> three ;
	static	ArrayList<Integer> four ;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);			//文字の入力
		String aString = sc.next();
		String bString = sc.next();

		if(aString.charAt(0) == 'H'){
			if(bString.charAt(0) == 'H'){
				System.out.println("H");
			}else{
				System.out.println("D");

			}
		}else{
			if(bString.charAt(0) == 'H'){
				System.out.println("D");
			}else{
				System.out.println("H");

			}
		}




	}
	
	
	
}

class Pair implements Comparable{
	Character from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}




Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;
int main(){
      int X,A,B;
      cin >> X >> A >> B;
      if(abs(A-X) > abs(B-X))cout << "B" << endl;
      else cout << "A" << endl;
        return 0;
}

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

using namespace std;

int main(void){

    int n, c, k;
    cin >> n >> c >> k;
    vector<int> t(n);
    for(int i = 0;i < n;i++) cin >> t[i];
    int ans = 0;

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

    int min = 0;

    for(int i = 0;i < n;i++){
        if(i - min + 1 > c || t[i] - t[min] > k){
            ans++;
            min = i;
        }
    }

    cout << ++ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll int,ll int>
#define pb push_back
#define sbit __builtin_popcount
#define vec vector <int>
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define bg begin()
#define en end()
#define endl "\n"
#define ff first
#define ss second
#define all(x) x.bg,x.en
#define sz(a) (int)a.size()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define sp(x) setprecision(x)
#define fill(a,b) memset(a,b,sizeof(a))
#define fr(i,n) for(int i=0;i<n;i++)
#define rp(i,a,b) for(int i=a;i<b;i++)
#define rr(i,a,b) for(int i=a;i>=b;i--)
#define ft(it,x) for(auto it : x)
#define dbg(x) cerr<<#x<<" "<<x<<endl;
#define dbga(arr,n) cerr<<#arr<<": "; rep(tt,0,n)cerr<<arr[tt]<<" "; cerr<<endl;
#define mapi map<int,int>
#define mapl map<ll int,ll int>
#define val_at(x) find_by_order(x)
#define idx_of(x) order_of_key(x)
#define scni(x) scanf("%d",&x)
#define prt(x) printf("%d\n",x)
#define test(t) int t;cin>>t;while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> myset;
const int mod=1e9+7;
const int mex=1e6+1;
inline ll power(ll a,ll b)
{
    ll ans=1,temp=a;
    while(b!=0)
    {
        if(b&1)
        ans=ans*temp;
        ans=ans%mod;
        temp=temp*temp;
        temp=temp%mod;
        b/=2;
    }
    return ans;
}
int pr[mex];
vec prime;
inline void seive()
{
    rp(i,2,mex) pr[i]=1;
    for(int i=2;i*i<mex;i++)
    {
        if(pr[i])
        for(int j=i*i;j<mex;j+=i)
        pr[j]=0;
    }
    vec prime;
    rp(i,2,mex)
    {
        if(pr[i]) prime.pb(i);
    }
}
ll int xx,xy,d1;
void exeu(ll int a1,ll int b1)
{
    if(b1==0)
    {
        xx=1;
        xy=0;
        d1=a1;
    }
    else
    {
        exeu(b1,a1%b1);
        ll int temp=xx;
        xx=xy;
        xy=temp-(a1/b1)*xy;
    }
}
ll int modinv(ll int A,ll int M)
{
    exeu(A,M);
    return (xx%M+M)%M;
}
int main()
{
    fast
    int n,k;
    cin>>n>>k;
    ll int fact[n+1],inv[n+1];
    fact[0]=1;
    rp(i,1,n+1)
    {
        fact[i]=(fact[i-1]*i)%mod;
    }
    inv[0]=1;
    rp(i,1,n+1)
    {
        inv[i]=modinv(fact[i],mod)%mod;
    }
    ll int a[n];
    fr(i,n)
    cin>>a[i];
    sort(a,a+n);
    ll int ans=0;
    rp(i,k-1,n)
    {
        ll int ans1=((fact[i]*inv[i-k+1])%mod*inv[k-1])%mod;
        //cout<<ans1<<" ";
        ans1=(ans1*abs(a[i]))%mod;
        //cout<<ans1<<" ";
        if(a[i]>0)
        ans=(ans+ans1)%mod;
        else ans=(ans-ans1+mod)%mod;
        //cout<<ans<<endl;
    }
    //cout<<ans<<endl;
    rr(i,n-k,0)
    {
        ll int ans1=((fact[n-i-1]*inv[n-i-k])%mod*inv[k-1])%mod;
        ans1=(ans1*abs(a[i]))%mod;
        if(a[i]>0)
        ans=(ans-ans1+mod)%mod;
        else
        ans=(ans+ans1)%mod;
    }
    cout<<ans%mod<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
 
#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)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
/* (๑╹◡╹) */
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll MOD = 1000000007;
template<class T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
 /* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)*/
template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹) */
///////////////////////////////////////////////

int main() {
   ll ans = 0;
   int N;
   string S;
   cin >> N >> S;
   vector<ll> A(N); 
   rep(i,N)
   {
	   if(i==0)continue;
	   if(S[i] == 'E') A.at(0) ++;
   }
	rep(i,N)
	{
		if(i == 0)continue;
		A.at(i) = A.at(i-1);
		if(S[i-1] == 'W') A.at(i) ++;
		if(S[i]   == 'E') A.at(i) --;
	}
   sort(ALL(A));
   ans = A.at(0);
   

   cout << ans << endl;
}

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


int main(){
	// sengen
	int k;
	// nyuryoku
	cin >>  k;
	// keisan
	long long sum=0;
	for(int i=1;i<k+1;i++){
		for(int j=1;j<k+1;j++){
			for(int m=1;m<k+1;m++){
				sum += gcd(i,gcd(j,m));
			}
		}
	}
	cout << sum;
}

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

int main()
{
    ll n,m;
    cin>>n>>m;
    if(n==1&&m==1){
        cout<<1;
    }
    else if(n==1||m==1){
        cout<<min(n,m)*(max(n,m)-2);
    }
    else{
        cout<<(n-2)*(m-2);
    }
}


Measured memory_bytes: 256
include Math

POSITIVE = 0
NEGATIVE = 1

# P P
# P N
# N N
# N P
def add_pow2(v, sign, n)
  place = log2(n).round.to_i
  if place % 2 == sign
    if v[place] == 0
      v[place] = 1
    else
      v[place] = 0
      add_pow2(v, sign, n*2)
    end
  else
    if v[place] == 1
      v[place] = 0
    else
      v[place] = 1
      add_pow2(v, sign, n*2)
    end
  end
  v
end

def add_num(v, n)
  if n == 0
    v
  elsif n < 0
    inpow2(-n).each do |k|
      add_pow2(v, NEGATIVE,k)
    end
    v
  else
    inpow2(n).each do |k|
      add_pow2(v, POSITIVE,k)
    end
    v
  end
end

def inpow2(n)
  fail if n < 0
  exp = 0
  res = []
  while n > 0
    res << (1 << exp) if n & 1 == 1
    n >>= 1
    exp += 1
  end
  res
end

def zero
  [0] * 64
end

def tostr(v)
  s = v.join.reverse.sub(/\A0+/,'')
  if s.empty?
    '0'
  else
    s
  end
end

fail unless tostr(zero) == '0'
fail unless tostr(add_num(zero, 1)) == '1'
fail unless tostr(add_num(zero, -9)) == '1011'
fail unless tostr(add_num(zero,123456789)) ==
            "11000101011001101110100010101"

n = gets.to_i
puts tostr add_num(zero, n)

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define ll long long

int main(int argc, char** argv) {
	int H,W,N;
	cin>>H>>W>>N;
	if(H<W)swap(H,W);	
	for(int i=1;i<=W;i++)
	{
		if(i*H>=N)
		{
		cout<<i;
		return 0;	
		}
	}
	return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var dic = new Dictionary<string, int>();
        var cookTimes = new int[5];
        var indexList = new int[5];
        for(int i = 0; i <cookTimes.Length; i++)
        {
            cookTimes[i] = int.Parse(Console.ReadLine());
            indexList[i] = i;
        }

        var perm = GetPermutation(indexList).ToList();
        var minTime = int.MaxValue;
        foreach(var indexPerm in perm)
        {
            int t = 0;
            foreach(var index in indexPerm)
            {
                while (t % 10 != 0) t++;
                t += cookTimes[index];
            }

            minTime = Math.Min(minTime, t);
        }

        Console.WriteLine(minTime);
    }

    public static IEnumerable<T[]> GetPermutation<T>(IEnumerable<T> items)
    {
        if (items.Count() == 1)
        {
            yield return new T[] { items.First() };
            yield break;
        }
        foreach (var item in items)
        {
            var leftside = new T[] { item };
            var unused = items.Except(leftside);
            foreach (var rightside in GetPermutation(unused))
            {
                yield return leftside.Concat(rightside).ToArray();
            }
        }
    }

}



Measured memory_bytes: 13408
import sys
A,B=map(int,sys.stdin.readline().split())
S=sys.stdin.readline().strip()
if len(S)==(A+B+1) and S[A]=='-' and all(map(lambda c: '0'<=c<='9',S[:A]+S[A+1:])):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,m,r;
	int d[201][201]={};
	vector<int> v;
	LL obj[9]={};
	cin>>n>>m>>r;
	FOR(i,0,r)v.PB(i);
	FOR(i,0,r)cin>>obj[i];
	FOR(i,0,n)FOR(j,0,n)d[i][j]=mod;
	FOR(i,0,n)d[i][i]=0;
	FOR(i,0,m){
		int a,b,c;
		cin>>a>>b>>c;
		d[a-1][b-1]=c;
		d[b-1][a-1]=c;
	}
	for (int i = 0; i < n; i++)      // 経由する頂点
    for (int j = 0; j < n; j++)    // 開始頂点
      for (int k = 0; k < n; k++)  // 終端
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
	LL ans=mod;
	//cout<<d[1][3]<<endl;
	do{
		LL ds=0;
		FOR(i,0,r-1){
			ds+=d[obj[v[i]]-1][obj[v[i+1]]-1];
		}
		ans=min(ans,ds);
	}while(next_permutation(v.begin(),v.end()));
	cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>

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

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

using std::vector;

int N;
vector<int> A;
vector<int> B;
vector<int> C;

int main(){
    scanf("%d",&N);
    //cin >> N;
    A=vector<int>(N);
    for(int i=0;i<N;i++){
        scanf("%d",&A[i]);
        //cin >> A[i];
    }
    B=vector<int>(N);
    for(int i=0;i<N;i++){
        scanf("%d",&B[i]);
        //cin >> B[i];
    }
    C=vector<int>(N);
    for(int i=0;i<N;i++){
        scanf("%d",&C[i]);
        //cin >> C[i];
    }

    std::sort(A.begin(),A.end());
    std::sort(B.begin(),B.end());
    std::sort(C.begin(),C.end());

    long ans=0;

    vector<long> ans_b(N);
    ans_b[0]=std::lower_bound(A.begin(),A.end(),B[0])-A.begin();
    for(int i=1;i<N;i++){
        ans_b[i]=std::lower_bound(A.begin(),A.end(),B[i])-A.begin() + ans_b[i-1];
    }

    for(int c : C){
        auto low_b=std::lower_bound(B.begin(),B.end(),c);
        if(low_b!=B.begin()){
            ans+=ans_b[low_b-B.begin()-1];
        }
    }

    printf("%ld\n",ans);
    //cout << ans << endl;
    return 0;
}



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

#define ll long long
#define fr(i,a,b) for (int i=a ; i<b ; i++)
#define fre(i,a,b) for (int i=a ; i<=b ; i++)
#define mem(a, b) memset(a, (b), sizeof(a))
#define mp make_pair
#define pb push_back
#define inf (int)1e9
#define pii 3.1415926535897932384626433832795
#define mod 1000000007
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pi> vii;
typedef map<int,int> mi;
typedef set<int> si;

int a[100005];
int dp[100005];

int solve(int i, int n) {
	if(i==n-1)
		return 0;
	if(i>=n)
		return INT_MAX;
	if(dp[i]!=-1)
		return dp[i];
	int l = abs(a[i]-a[i+1]) + solve(i+1,n);
	int r = INT_MAX;
	if(i+2<n)
		r = abs(a[i]-a[i+2]) + solve(i+2,n);
	return dp[i] = min(l,r);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n; cin>>n;
    fr(i,0,n)
    	cin>>a[i];
    mem(dp,-1);
    cout<<solve(0,n)<<endl;
}

Measured memory_bytes: 10580
using System;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var line = Console.ReadLine().Split(' ');

            var N = int.Parse(line[0]);
            var R = int.Parse(line[1]);

            var amari = 0;
            var count = 1;

            while (N > R || N == R)
            {
                N = (N / R);
                amari = (N % R);
                count += 1;
                
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define LL long long

int main(){
	// sengen
	int a,b,c;
	// nyuryoku
	cin >> a >> b >> c;
	// keisan
	cout << a*b*c/max(a,max(b,c))/2 << endl;
	// syutsuryoku
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,x,y;
	cin>>n;
	long long int a[n+1],f[n+1];
	for(int i=1;i<=n;i++)
	cin>>a[i];
	f[1]=0;
	x=abs(a[2]-a[1]);
	f[2]=x;
	for(int i=3;i<=n;i++)
	{
		x=abs(a[i]-a[i-1]);
		y=abs(a[i]-a[i-2]);
		f[i]=min(f[i-1]+x,f[i-2]+y);
	}
	cout<<f[n]<<endl;
}

Measured memory_bytes: 1792
from collections import deque


def main():
    k = int(input())
    if k <= 9:
        print(k)
    else:
        queue = deque()
        for i in range(1, 10):
            queue.append(i)
        flag = 1
        cnt_lunlun = 9
        while flag:
            first_element = queue.popleft()
            lunlun_nums = extend_lunlun(first_element)
            for n in lunlun_nums:
                queue.append(n)
                cnt_lunlun += 1
                if cnt_lunlun == k:
                    flag -= 1
                    break
        print(queue.pop())


def extend_lunlun(num):
    lunlun_nums = []
    last_digit = num % 10
    for i in range(-1, 2):
        d = last_digit + i
        if d >= 0 and d <= 9:
            lunlun_nums.append(num*10+d)
    return lunlun_nums


if __name__ == "__main__":
    main()

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

using namespace std;
typedef long long ll;
const int MAX_N=1e6;

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

  int a,b,c;cin>>a>>b>>c;
  if(a==b&&b==c) cout<<1<<endl;
  else if(a==b || b==c || c==a)cout<<2<<endl;
  else cout<<3<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

struct job{
    int a;
    int b;
};


int main(void){
    int n; cin >> n;
    int m; cin >> m;
    dump(n) dump(m)
    vector <vector <int>> jobs(1e5+2, vector<int>());
    REP(i, n){
        int a; cin >> a;
        int b; cin >> b;
        jobs[a].push_back(b);
        cerr << a << " " << b << endl;
    }
    ll ans = 0;
    priority_queue <int> jobs2;
    dumpline
    for(int a=1; a<=m; a++){
        for(auto j: jobs[a]){
            jobs2.push(j*1);
        }
        if (!jobs2.empty()){
            cerr << a << " " << jobs2.top() << endl;
            ans += jobs2.top();
            jobs2.pop();
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5632
# AtCoder Beginner Contest 162: C (2020/04/12)
import math
K = int(input())
S = 0
for a in range(1,K+1):
    for b in range(a,K+1):
        for c in range(b,K+1):
            x = [a, b, c]
            ans = x[0]
            for i in range(1, 3):
                ans = math.gcd(ans, x[i])
            if a == b and b == c:
                S = S + ans
            elif a == b or b == c:
                S = S + 3*ans
            else:
                S = S + 6*ans
print(S)

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
int x,p,q;
bool dfs(int i,int k,int sum){//iは買った個数（そのまま上3桁に直結）,kは現在目をつけている品物、sumは下3桁の合計額
    if(i==q)return p==sum;
    
    for(int j=k;j<=5;j++){
        if(dfs(i+1,j,sum+j))return true;
    }
    return false;
}
int main(void){
    cin>>x;
    p = x%100;//pは下3桁
    q = x/100;//qは上3桁
    //cout<<p<<q<<endl;
    bool res = dfs(0,0,0);
    if(res)cout<<"1"<<endl;
    else cout<<"0"<<endl;
}


Measured memory_bytes: 256
'''ika tako
制約条件を見て、戦略を決める（制約が戦略を決める）
配列の添え字を、なるべくシンプルにする（KISS）
広義単調増加（同じ数もOK）なので、重複順列（仕切り板で分ける）
求める数列の候補である　重複順列を列挙し、重複順列毎にscoreを求め、
そのscoreの最大値が答（数列を求めるのではなく、数列を点検する）
入力は空のリストにappendで追加
入力の際、0-indexとなるように、引く1をする（後で考えるのはメンドウ）
重複順列毎に回し、更に、クエリ毎に条件式で得点を求める、二重ループ
scoreは、答の候補である重複順列毎の得点
求めるansは、そのscoreの最大値
この二つを区別すること
'''

from itertools import combinations_with_replacement
 
n, m, q = map(int, input().split())
queries = []
for _ in range(q):
    a, b, c, d = map(int, input().split())
    a -= 1
    b -= 1
    queries.append((a, b, c, d))

ans = 0
for arr in combinations_with_replacement(range(m), n):
    score = 0
    for a, b, c, d in queries:
        if arr[b] - arr[a] == c:
            score += d
    ans = max(ans, score)

print(ans)

Measured memory_bytes: 9188
#include<iostream>
using namespace std;
int H,W,h,w;
int A[500][500];
main()
{
	cin>>H>>W>>h>>w;
	if(h*w==1)
	{
		cout<<"No"<<endl;
		return 0;
	}
	int cnt=0;
	for(int i=h-1;i<H;i+=h)for(int j=w-1;j<W;j+=w)A[i][j]=-1,cnt++;
	long a=(1e9-1)/(h*w-1),b=1e9;
	if(a*(H*W-cnt)>b*cnt&&b*cnt>a*cnt*(h*w-1))
	{
		cout<<"Yes"<<endl;
		for(int i=0;i<H;i++)
		{
			for(int j=0;j<W;j++)cout<<(A[i][j]<0?-b:a)<<(j==W-1?"\n":" ");
		}
	}
	else cout<<"No"<<endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;

int main() {
	ll n, a,pos=0,index=0;
	ll k;
	cin >> n >> k;
	set<int>cycle;
	vector<int>city;
	vi tere;
	rep(i, n) {
		cin >> a;
		city.push_back(--a);
	}
	pos = 0;
	for (int s:city) {
		cycle.insert(pos);
		tere.push_back(pos);
		pos = city[pos];
		if (cycle.count(pos))break;
	}
	for (int s : tere) {
		if (s == pos) break;
		else index++;
	}
	if (k <= index) {
		cout << tere[k] + 1 << endl;
	}
	else {
		k -= index;
		cout << tere[index + (k % (tere.size() - index))] + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 14088
import string

S = string.ascii_lowercase
N = int(input())


def a(s="", distinct=0):
  if len(s) == N:
    print(s)
    return

  for i in range(distinct + 1):
    c = S[i]
    a(s + c, distinct + (1 if c not in s else 0))


a()


Measured memory_bytes: 4988
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        System.out.println(Math.min(a, b) + Math.min(Math.max(a, b), c));
    }
}

Measured memory_bytes: 21840
n, k = STDIN.gets.split(' ').map(&:to_i)

trees = n.times.map do
  STDIN.gets.to_i
end

trees.sort!

# p trees

diff = 10 ** 9

(n - k + 1).times do |i|
  selected = trees[i..(i + k -1)]
  # p selected[-1] - selected[0]
  if diff > (selected[-1] - selected[0])
    diff = selected[-1] - selected[0]
  end
end

puts diff


Measured memory_bytes: 3832
#include <iostream>

using namespace std;

uint64_t count(uint64_t n, uint64_t a, uint64_t b) {

  if (b < a)
    return 0;

  if (n == 1 && a != b)
    return 0;

  uint64_t s = a * n + (b - a);
  uint64_t l = b * n - (b - a);

  return l - s + 1;
}

int main() {
  uint64_t N, A, B;
  cin >> N >> A >> B;

  cout << count(N, A, B) << endl;

  return 0;
}


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

int main() 
{
    string s;
    int answer = 0;
    cin >> s;//改行を気にしない
    if(s[0] == '1') answer++;
    if(s[1] == '1') answer++;
    if(s[2] == '1') answer++;
    cout << answer << endl;
    
    
}


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

int main(){
  int n, m;  cin >> n >> m;
  vector<int> g(n, 1e9);
  while(m--){
    int a, b;  cin >> a >> b;
    a--, b--;
    g[a] = min(g[a], b);
  }

  int x = 1e9, ans = 0;
  for(int i=0; i<n; i++){
    if(i == x)  x = 1e9, ans++;
    x = min(x, g[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3780
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = 1;
    int ans =0;
    while(c<b){
    	c=c+(a-1);
      ans=ans+1;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
    ll n,x;
    cin>>n>>x;
    V<ll> a(n),b(n,inf);
    for(int i=0;i<n;i++)cin>>a[i];
    ll ans=inf;
    for(int k=0;k<n;k++){//色変の回数固定
    ll c=k*x,sum=0;
    for(int i=0;i<n;i++){
        chmin(b[i],a[(i+n-k)%n]);
        sum+=b[i];
    }
    chmin(ans,sum+c);
    }
    cout<<ans<<"\n";
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

int main() {
  int a, b; cin >> a >> b;
  
  if(a > b) cout << a-1 << endl;
  else cout << a << endl;

  return 0;
}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())
#define all(a) (a).begin(), (a).end()

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

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;


ll f(string s){

	ll cnt = 0;
	ll tmp = 1;
	FOR(i,1,s.length()){
		if(s[i] == s[i-1]) tmp++;
		else{
			cnt += tmp/2;
			tmp = 1;
		}
	}
	if(tmp != 0) cnt += tmp / 2;
	return cnt;
}

int main(void){

	string s; cin >> s;
	int K; cin >> K;

	set<char> st;
	REP(i,s.length()){
		st.insert(s[i]);
	}

	ll ans = 0;
	if(st.size() == 1) ans =  s.length() * (ll)K / 2;
	else{
		ll prev = f(s);
		ll next = f(s+s);
		ans = prev + (K-1)*(next-prev);
	}

	cout << ans << endl;


	return 0;

}


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    int a[3], b, i, c, d, e, f, g;
    e = 1;
    
    

    scanf("%d %d %d", &a[1], &a[2], &a[3]);
        if(a[1] > a[2]) {
            f = a[1];
            a[1] = a[2];
            a[2] = f;
        }

        if(a[2] > a[3]) {
            f = a[2];
            a[2] = a[3];
            a[3] = f;
        }

        if(a[1] > a[2]) {
            f = a[1];
            a[1] = a[2];
            a[2] = f;
        }

        if(a[2] > a[3]) {
            f = a[2];
            a[2] = a[3];
            a[3] = f;
        }

        printf("%d %d %d\n", a[1], a[2], a[3]);

           return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solve();
	}
	int r,g,b;
	
	void solve(){
		Scanner sc=new Scanner(System.in);
		r=sc.nextInt();
		g=sc.nextInt();
		b=sc.nextInt();
		int sum=r*100+g*10+b;
		
		if(sum%4==0)System.out.println("YES");
		else System.out.println("NO");
	}

}


Measured memory_bytes: 21332
#include <iostream>
#include <string>
using namespace std;
int main (void) {
	int flag  = 0;
	string a, b; cin >> a >> b;
	int size1 = (int) a.size();
	int size2 = (int) b.size();

	if (size1 < size2)
		cout << "LESS" << endl;
	else if (size1 > size2)
		cout << "GREATER" << endl;
	else {
		for (int i = 0; i < size1; i++) {
			if (a[i] < b[i]) {
				cout << "LESS" << endl;
				flag = 1;
				break;
			}
			else if (a[i] > b[i]) {
				flag = 1;
				cout << "GREATER" << endl;
				break;
			}
		}
		if (flag == 0)
			cout << "EQUAL" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int s(char n[10]){
    int ret=0;
    for(int i=0;i<strlen(n);i++)ret+=n[i];
    return ret-strlen(n)*'0';
    }
int main(){
    char n[10];cin>>n;
    cout<<(atoi(n)%s(n)?"No":"Yes")<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String, Integer> hash = new HashMap<String, Integer>();
        String line = sc.nextLine();
        String line1 = sc.nextLine();
        String[] s = line.split("");
        String[] p = line1.split("");
        String answer = "No";
        for(int i = 0; i < s.length; i++) {
            if(s[i].equals(p[0])) {
                String ans = "";
                for(int j = 0; j < p.length; j++) {
                    if(i + j < s.length) {
                        ans += s[i + j];
                    }else {
                        ans += s[i + j - s.length];
                    }
                }
                if(ans.equals(line1)) {
                    answer = "Yes";
                }
            }
        }
        System.out.println(answer);

    }
 }


Measured memory_bytes: 26596
/*
 * ex 5_4
 * kamecha
 */
#include <stdio.h>
#include <string.h>

int max(int a, int b){
    return (a>b)?a:b;
}

int main(void){
    char str[20];
    scanf("%s", str);
    int ptr = -1;   //部分文字列の左側
    int ans = 0;
    int i = 0;
    int flag = 0;   //0:最後がACGTではない　1:ACGTである
    for(; str[i] != '\0'; i++){
        switch(str[i]){
            case 'A':
            case 'C':
            case 'G':
            case 'T':
                flag = 1;
                break;
            default:
                ans = max(ans, i-1-ptr);
                ptr = i;
                flag = 0;
                break;
        }
    }
    if(flag){
        ans = max(ans, i-1-ptr);
    }
    printf("%d\n", ans);
    return 0;
}


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(auto &e : A) cin >> e;
    auto OK = [&](int x) -> bool {
        int cnt = 0;
        for(auto &a : A) {
            if(a == x) continue;
            cnt += (a / x);
        }
        return cnt <= K;
    };
    int l = 0, r = 1e9;
    while(r - l > 1) {
        int c = (l + r) / 2;
        if(OK(c)) r = c;
        else l = c;
    }
    cout << r << '\n';
    return 0;
}


Measured memory_bytes: 3976
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char const* argv[])
{
	string s;
	int w;
	cin >> s;
	cin >> w;
	int i = 0;
	while(i < s.size()){
			cout << s[i];
			i += w;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
public static void main(String[]args){
Scanner scan=new Scanner(System.in);
int i=0;
int a[]=new int[100];
int b[]=new int[100];
int x=0;
int y=0;
do {
	a[i]=scan.nextInt();
	b[i]=scan.nextInt();
	if(b[i]==0&&a[i]==0) {
		break;
	}
	i++;
}while(true);
i=0;
do {
	x=0;
	y=0;
	if(a[i]==0&&b[i]==0) {break;}
	do {
		if(x==b[i]) {break;}
		System.out.print("#");
		x++;
	}while(true);
	x=0;
	System.out.println();
	do {System.out.print("#");
		do {
			System.out.print(".");
		x++;
		if(x==b[i]-2) {break;}
		}while(true);
		System.out.print("#");
		y++;
		if(y==a[i]-2) {break;}
		x=0;
		System.out.println();
	}while(true);
	y=0;
	x=0;
	System.out.println();
	do {
		if(x==b[i]) {break;}
		System.out.print("#");
		x++;
	}while(true);
	x=0;
	System.out.println("\n");
	i++;
}while(true);
}
}



Measured memory_bytes: 33636
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
int main()
{
	int n, k; cin>>n>>k;
	ll p2[2001];
	p2[0]=1;
	for(int i=1; i<=n; i++) p2[i]=p2[i-1]*2%MOD;
	ll comb[2001][2001];
	comb[0][0]=1;
	for(int i=1; i<=n; i++){
		comb[i][0]=comb[i][i]=1;
		for(int j=1; j<i; j++){
			comb[i][j]=(comb[i-1][j-1]+comb[i-1][j])%MOD;
		}
	}
	ll dp[2001]; dp[0]=1;
	ll s[2001]; s[0]=1;
	for(int i=1; i<=k-1; i++){
		for(int j=0; j<=i; j++){
			if(j-2<0) dp[j]=s[i-1];
			else dp[j]=(s[i-1]-s[j-2]+MOD)%MOD;
		}
		s[0]=dp[0];
		for(int j=1; j<=i; j++) s[j]=(s[j-1]+dp[j])%MOD;
	}
	if(n==k){
		cout<<dp[0]<<endl;
		return 0;
	}
	ll ans=0;
	for(int x=n-k+1; x<=n; x++){
		if(x==n-k+1){
			ans+=dp[0]*p2[n-k-1];
			ans%=MOD;
			continue;
		}
		ans+=dp[x-1-n+k]*comb[x-2][n-k-1]%MOD*p2[n-k-1]%MOD;
		ans%=MOD;
	}
	cout<<ans<<endl;
	return 0;
}

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

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

  int n, q;
  bool a[2001] = {0};
  int x;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    for (int j = 2000; j >= 0; j--) {
      if (a[j]) {
        a[j + x] = true;
      }
    }
    a[x] = true;
  }

  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> x;
    if (a[x]) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1184
n = int(input())
r = [[["0" for i in range(10)] for j in range(3)] for k in range(4)]
for i in range(n):
    m = list(map(int,input().split()))
    r[m[0]-1][m[1]-1][m[2]-1] = str(int(r[m[0]-1][m[1]-1][m[2]-1])+m[3])
for i,l in enumerate(r):
    for j in l:
        print(" " + " ".join(j))
    if i != 3:
        print("####################")


Measured memory_bytes: 5612
s,M=60,D;I(h,m){scanf(D="%d %d %d\n",&h,&m,&s);s+=m*M+h*M*M;}F(S){I();I(S=s);s-=S;printf(D,s/M/M,s/M%M,s%M);}main(){s=!F(F(F()));}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(int i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

int main(void){
  cout << setprecision(10);
  int N;cin >> N;
  double p[N];
  REP(i,N)cin >> p[i];
  //dp[i+1][j+1]:i枚目までを見てj枚面になる確率
  double dp[N+1][N+1];
  REP(j,N+1)dp[0][j] = 0.0;
  REP(i,N+1)dp[i][0] = 1.0;
  REP(i,N){
    REP(j,N){
      dp[i+1][j+1] = p[i]*dp[i][j] + (1-p[i])*dp[i][j+1];
    }
  }
  cout << dp[N][N/2+1] << endl;
  return 0;
}


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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

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

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;

signed main(){
    int n;
    cin >> n;
    PRINT((n + 1) / 2);
    return 0;
}

Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
vector<lpair> tree[100010];
ll color[100010] = {};

void dfs(ll cur, ll par, ll d){
    if(d % 2 == 0){
        color[cur] = 0;
    }else{
        color[cur] = 1;
    }
    for(auto &e: tree[cur]){
        if(e.first == par) continue;
        dfs(e.first, cur, d + e.second);
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll u[100010], v[100010], w[100010];
    rep(i,0,N-1){
        cin >> u[i] >> v[i] >> w[i];
        u[i]--; v[i]--;
        tree[u[i]].push_back({v[i], w[i]});
        tree[v[i]].push_back({u[i], w[i]});
    }
    dfs(0, -1, 0);
    rep(i,0,N) print(color[i]);
    

}

Measured memory_bytes: 12416
#include <stdio.h>

int main() {
	char s[1000001] = {0};

	unsigned int g = 0;
	unsigned int p = 0;
	unsigned int w = 0;
	unsigned int l = 0;

	scanf("%s", s);

	for(int i = 0; s[i] != '\0'; i++) {
		if(g == p) {
			g++;
			if(s[i] == 'p') {
				l++;
			}
		} else if(g > p ) {
			p++;
			if(s[i] == 'g') {
				w++;
			}
		}
	}

	printf("%d\n", w - l);

	return 0;
}

Measured memory_bytes: 1152
h = -1
w = -1

while (h != 0) and (w != 0):
  input = map(int, raw_input().split(" "))
  h = input[0]
  w = input[1]
  if (h == 0 and w == 0):
    break

  i = 0
  j = 0
  line = ""

  while j < w:
    line += "#"
    j += 1

  while i < h:
    print line
    i += 1

  print ""

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

int main() {
  int n;
  int a, b, c;
  int *s1, *s2, *l;
  cin >> n;
  while (n--) {
    cin >> a >> b >> c;
    if (a>=b && a>=c) {
      l = &a;
      s1 = &b;
      s2 = &c;
    } else if (b >= c) {
      l = &b;
      s1 = &a;
      s2 = &c;
    } else {
      l = &c;
      s1 = &a;
      s2 = &b;
    }
    cout << (((*l)*(*l)==(*s1)*(*s1)+(*s2)*(*s2)) ? "YES" : "NO") << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
#include<stdio.h>

int main(void)
{
        int a,b,n,cnt ;
    
        scanf("%d %d",&a,&b);

        n = 0 ; 
        while(n*(a-1)+1 < b){ 
                n++;
        }   

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

        return 0;
}


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

const int INF = 1000000000;

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

  vector<int> dp(n + 1, INF);
  dp.at(0) = 0;
  for (int i = 1; i <= n; i++){
    int p = 1;
    while (p <= i){
      dp.at(i) = min(dp.at(i), dp.at(i - p) + 1);
      p *= 6;
    }
    int q = 1;
    while (q <= i){
      dp.at(i) = min(dp.at(i), dp.at(i - q) + 1);
      q *= 9;
    }
  }
  cout << dp.at(n) << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    int n, x;
    cin >> n >> x;
    int size = 2 * n - 1;
    if ((x == 1) || (x == size)) {
        cout << "No" << endl;
        return 0;
    }
    set<int> s;
    rep(i, size) s.insert(i + 1);
    vector<int> ans(size, INT_MIN);
    if (x == 2) {
        ans[n - 2] = x + 1;
        ans[n - 1] = x;
        ans[n] = x - 1;
        rep(i, 3) s.erase(i + (x - 1));
        if (n > 2) {
            ans[n + 1] = x + 2;
            s.erase(x + 2);
        }
    }
    else {
        ans[n - 2] = x - 1;
        ans[n - 1] = x;
        ans[n] = x + 1;
        rep(i, 3) s.erase(i + (x - 1));
        if (n > 2) {
            ans[n + 1] = x - 2;
            s.erase(x - 2);
        }
    }
    rep(i, size) {
        if (ans[i] != INT_MIN) continue;
        auto it = s.begin();
        ans[i] = *it;
        s.erase(it);
    }
    cout << "Yes" << endl;
    rep(i, size) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 11648
#import heapq
#import itertools
#import math
#import numpy as np
#import sys

#S = input()
A,B = list(map(int, input().split()))
#S = [input() for _ in range(H)]
#T = [list(map(int,input().split())) for _ in range(N)]
#sys.exit()
ans = A - 2*B
if(ans <= 0) :
    print(0)
else :
    print(ans)

Measured memory_bytes: 2940
#include<iostream>

#include<cstdio>

#include<cstring>

#include<string>

#include<algorithm>

#include<set>

#include<map>

#include<stack>

#include<queue>

#include<deque>

#include<cmath>

#include<vector>

using namespace std;

template<typename T>void scan(T &x)

{

	char ch;

	bool f=1;

	x=0;

	ch=getchar();

	while(!isdigit(ch)&&ch!='-') ch=getchar();

	if(ch=='-') f=0,ch=getchar();

	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();

	if(f==0) x=-x; 

}

int a,b;

int main()

{

	scan(a),scan(b);

	printf("%d\n",a+b/2);

	return 0;

}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            char[] inp = input.ToCharArray();
            char[] charset = new char[4];
            charset[0] = inp[0];
            charset[1] = inp[0];
            int[] count = new int[2];
            count[0] = 1;
            for (int i = 1; i < 4; i++)
            {
                if (inp[i] == charset[0]) count[0]++;
                else if (inp[i] == charset[1]) count[1]++;
                else
                {
                    charset[1] = inp[i];
                    count[1] = 1;
                }
            }
            if (count[0] == 2 && count[1] == 2)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }

}   

Measured memory_bytes: 13140
/* ***********************************************
Author        :yang12138
Created Time  :2018/5/26 20:06:27
File Name     :A.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;

const int N=3e5+10;

int l[N],r[N];
char s[N];

void solve(){
	int n;
	scanf("%d%s",&n,s+1);

	for(int i=1;i<=n;i++) l[i]=l[i-1]+(s[i]=='W');
	for(int i=n;i>=1;i--) r[i]=r[i+1]+(s[i]=='E');
	int ans=2*N;
	for(int i=1;i<=n;i++){
		ans=min(ans,l[i-1]+r[i+1]);
	}
	printf("%d\n",ans);

}

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
	solve();
    
    return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;
typedef long long ll;

ll n, k, ans, M=1e9+7, c[N];

ll pow(ll p, ll q) {
	ll re = 1;
	while(q) {
		if(q&1) re = re * p % M;
		p = p * p % M;
		q >>= 1;
	}
	return re;
}

int main() {
	ll i, j;
	cin >> n >> k;
	for(i=k; i; i--) {
		c[i] = pow(k/i, n);
		for(j=2*i; j<=k; j+=i) c[i] -= c[j];
		ans += c[i] * i % M;
	}
	cout << ans % M;
	return 0;
}


Measured memory_bytes: 4376
#include <bits/stdc++.h>
using namespace std;
#define X 1000000007LL

int main()
{
    int n;
    long long ans = 1;
    cin >> n;
    for (long long i = 1; i <= n; i++)
    {
        ans *= i;
        ans %= X;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3568
n = gets.to_i
card = Array.new(13*4,0)

n.times do
  inp = gets.split(" ")
  i = inp[0].tr("SHCD","0123").to_i
  j = inp[1].to_i - 1
  card[i*13+j] = 1
end

0.upto(13*4-1) do |i|
  if(card[i] == 0) then
    type = (i / 13).to_s.tr("0123","SHCD")
    num = i % 13 + 1
    printf "%s %d\n", type, num
  end
end

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

string s;

int main(){

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

    cin>>s;
    for(int i=0;i+1<s.size();i++)if(s[i]==s[i+1]){
        cout<<"Bad"<<endl;
        return 0;
    }
    cout<<"Good"<<endl;

    return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  ll n;cin>>n;
  ll h[n];rep(i,0,n)cin>>h[i];

  vector<ll>cost(n,INF);
  cost[0]=0;
  cost[1]=abs(h[0]-h[1]);
  rep(i,2,n){
    cost[i]=min(cost[i-1]+abs(h[i]-h[i-1]),cost[i-2]+abs(h[i]-h[i-2]));
  }
  out(cost[n-1]);
  // vector<ll>s(n,0);
  // rep(i,0,n-1){
  //   if(i+2>=n){
  //     s[i+1]=min(s[i+1],s[i]+abs(h[i]-h[i+1]));
  //     s[i+2]=min(s[i+2],s[i]+abs(h[i]-h[i+2]));
  //   }else{
  //     s[i+1]=min(s[i+1],s[i]+abs(h[i]-h[i+1]));
  //   }
  // }
  // out(s[n-1]);

  return 0;
}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

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

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

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int main() {
	int n; cin >> n;
	string s; cin >> s;
	
	int cnt = 0, now = 0;
	REP(i, s.size()) {		
		if (s[i] == ')') {
			if (now == 0) cnt++;
			else now--;
		}
		else now++;
	}
	
	REP(i, cnt) putchar('(');
	REP(i, s.size()) putchar(s[i]);
	
	REP(i, s.size()) if (s[i] == '(') cnt++; else cnt--;
	REP(i, cnt) putchar(')');
	
	return 0;
}


Measured memory_bytes: 256
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    println(length(sort(collect(Set([parseInt(readline()) for i in 1:n])))))
end
main()

Measured memory_bytes: 113388
def main():
    from itertools import combinations
    a, b, c, d, e, f = map(int, input().split())
    a *= 100
    b *= 100

    water = [a * i + b * j for i in range(f // a + 1) for j in range(f // b + 1)]
    sugar = [c * i + d * j for i in range(f // c + 1) for j in range(f // d + 1)]
    water.sort()
    sugar.sort(reverse=True)

    tmp = 0
    x, y = 0, 0
    for w in water:
        if w == 0:
            continue
        for s in sugar:
            if s + w > f:
                continue
            if s * 100 <= e * w and tmp <= s / (s + w):
                tmp = s / (s + w)
                x = s + w
                y = s
    print(x,y)


if __name__ == '__main__':
    main()


Measured memory_bytes: 24400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    double node = -1;
    int ans1 = 0, ans2 = 0;
    for (int i = 0; i * 100 * A <= F; i++) {
        for (int j = 0; j * 100 * B <= F; j++) {
            // 溶ける量
            int sugar = (i * A + j * B) * E;
            for (int k = 0; k * C <= sugar; k++) {
                for (int l = 0; l * D <= sugar; l++) {
                    if (k * C + l * D > sugar) continue;
                    if (i * 100 * A + j * 100 * B + k * C + l * D > F) continue;
                    double n = 100 * (k * C + l * D) / (double)(i * 100 * A + j * 100 * B + k * C + l * D);
                    if (node < n) {
                        node = n;
                        ans1 = i * 100 * A + j * 100 * B + k * C + l * D;
                        ans2 = k * C + l * D;
                    }
                }
            }
        }
    }
    cout << ans1 << " " << ans2 << endl;
    return 0;
}


Measured memory_bytes: 256