akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

int main () {
  string S, T; cin >> S >> T;

  int ans = 0;
  REP(i,3) {
    if (S[i]==T[i]) ans++;
  }

  cout << ans << endl;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n, m, q; scanf("%d%d%d", &n, &m, &q);
	std::vector<i64> a(n), b(m), ans(q);
	std::vector<std::pair<i64, int>> vec;
	for(int i = 0; i < n; i++) scanf("%lld", &a[i]);
	for(int i = 0; i < m; i++) scanf("%lld", &b[i]);
	for(int i = 0; i < q; i++) {
		i64 x; scanf("%lld", &x);
		
		vec.push_back({x, i});
	}
	sort(begin(vec), end(vec));
	a.push_back(1LL << 60);
	b.push_back(1LL << 60);
	
	i64 curA = 0, curB = 0, A = -1, B = -1;
	const i64 INF = 1LL << 60;
	for(int i = 0; i < q; i++) {
		i64 T = vec[i].first, p = vec[i].second;
		while(curA < n and a[curA] <= T) A = a[curA++];
		while(curB < m and b[curB] <= T) B = b[curB++];
		i64 X = *lower_bound(begin(a), end(a), T);
		i64 Y = *lower_bound(begin(b), end(b), T);
		
		i64 cost = 1LL << 60;
		if(X != INF and Y != INF) cost = std::min(cost, std::max(X, Y) - T);
		if(A != -1 and B != -1) cost = std::min(cost, T - std::min(A, B));
		if(A != -1 and Y != INF) cost = std::min(cost, std::min((T - A) * 2 + (Y - T), (T - A) + (Y - T) * 2));
		if(X != INF and B != -1) cost = std::min(cost, std::min((T - B) * 2 + (X - T), (T - B) + (X - T) * 2));
		ans[p] = cost;
	}
	for(auto v: ans) printf("%lld\n", v);
	return 0;
}


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

int n;

void dfs(string s, char mx) {
	if (s.length() == n)
		cout << s << endl;
	else {
		for (char c = 'a'; c <= mx; c++)
			dfs(s + c, ((c == mx) ? (char)(mx + 1) : mx));
	}
}

int main()
{
	cin >> n;
	dfs("", 'a');
}


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

int main() {
	int n;
	cin >> n;
	vector<int> input;
	for(int i=0; i<2*n; i++) {
		int p;
		cin >> p;
		input.push_back(p);
	}
	sort(input.begin(), input.end());
	int ans = 0;
	for(int i=0; i<input.size(); i+=2) {
		ans += min(input[i], input[i+1]);
		
		
	}
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 200000;
const LL INF = 3e18;
const int MOD = 1e9 + 7;
int n; LL a, b;
LL si[N];
int pA[N], pB[N];
int main()
{
    cin >> n >> a >> b;
    for (int i = 1; i <= n; ++ i) cin >> si[i];
    si[0] = -INF; si[n + 1] = INF;
    pA[1] = pB[1] = 1;
    for (int i = 2, lA = 1, rA = 1, lB = 1, rB = 1; i <= n + 1; ++ i)
    {
        while (si[i] - si[rA] >= a && rA < i - 1) rA ++;
        if (si[i - 1] - si[i - 2] < b) lA = i - 1;
        while (si[i] - si[rB] >= b && rB < i - 1) rB ++;
        if (si[i - 1] - si[i - 2] < a) lB = i - 1;
        pA[i] = (0ll + pA[i - 1] + (lA <= rA? pB[rA] - pB[lA - 1]: 0) + MOD) % MOD;
        pB[i] = (0ll + pB[i - 1] + (lB <= rB? pA[rB] - pA[lB - 1]: 0) + MOD) % MOD;
    }
    cout << (0ll + pA[n + 1] - pA[n] + pB[n + 1] - pB[n] + 2ll * MOD) % MOD << endl;
}


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

typedef long long ll;

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

#define vl vector<ll>
#define pll pair<ll,ll>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;
/*}}}*/

int main() {
  ll a,b;
  cin >> a >> b;
  cout << a*b << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
long long p=1000000007;
long long rui(long long a,long long b){
    if(b==0)return 1;
    if(b==1)return a;
    if(b==2)return (a*a)%p;
    if(b%2)return (rui(rui(a,(b-1)/2),2)*a)%p;
    else return rui(rui(a,b/2),2)%p;
}
int main(void){
   long long n,m;
   scanf("%lld%lld",&n,&m);
   int a[32000];
   for(int i=0;i<32000;i++){
       a[i]=0;
   }
   int x;
   while(x){
       x=0;
       for(int i=2;i*i<=m;i++){
           if(m%i==0){
               x=1;
               m/=i;
               a[i]++;
               break;
           }
       }
   }
   long long ans=1;
   if(m<32000)a[m]++;
   else ans*=n;
   long long inv[40];
   for(int i=1;i<40;i++){
       inv[i]=rui(i,p-2);
   }
   for(int i=2;i<32000;i++){
       if(a[i]){
           for(int j=1;j<=a[i];j++){
               ans*=inv[j];
               ans%=p;
               ans*=n+a[i]-j;
               ans%=p;
           }
       }
   }
   printf("%lld\n",ans);
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{ int A,B,C,D,area1,area2;
cin>>A;
cin>>B;
cin>>C;
cin>>D;
area1=A*B;
area2=C*D;
if(area1>=area2)
{cout<<area1;}
else 
cout<<area2;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;

ll func(ll a,ll b,ll x){
    return ((a * x) - (a * x % b)) / b;
};

int main(){
    ll a, b, n;
    cin >> a >> b >> n;
    ll x = min(n, b-1);

    cout << func(a, b, x) << endl;

    return 0;
}

Measured memory_bytes: 3556
fun main(args: Array<String>) {
    val (k, t) = readLine()!!.split(' ').map(String::toInt)
    val a = readLine()!!.split(' ').map(String::toInt).sorted()
    val mx = a[t - 1]
    println(Math.max(0, k - 1 - 2 * (k - mx)))
}

Measured memory_bytes: 22692
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int N = S.size();
  vector<int>count(N+2);
  count.at(0) = -1;
  count.at(1) = 0;
  count.at(2) = 1;
  for (int i = 3; i < N+2; i++) {
    if (S.at(i-2) == S.at(i-3)){
      count.at(i) = count.at(i-3) + 2;
    }
    else{
      count.at(i) = count.at(i-1) + 1;
    }
  }
  cout << count.at(N+1) << endl;
}




Measured memory_bytes: 4432
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(int argc, char* argv[]){
    int n, m, x, y;
    int line[300];
    cin >> n >> m >> x >> y;
    int mx = x, my = y;
    int tmp = 0;
    rep(i, n){
        cin >> tmp;
        mx = max(mx, tmp);
    }
    rep(i, m){
        cin >> tmp;
        my = min(my, tmp);
    }

    if(mx < my && x < y) cout << "No War" << endl;
    else cout << "War" << endl;
}



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

int main(){
  ll n;
  cin>>n;
  ll a[n];
  for(int i=0;i<n;i++)cin>>a[i];
  ll mother=a[0];
  for(int i=1;i<n;i++)mother^=a[i];
  for(int i=0;i<n;i++){
    cout<<(a[i]^mother)<<" ";
  }
  cout<<endl;
}


Measured memory_bytes: 5100
fun main(args: Array<String>) = ABC164B.main()

object ABC164B {
    fun log(message: Any?) {
        println(message)// TODO: ←消す
    }

    fun main() {
        var (hpA, atkA, hpB, atkB) = readInts()

        var aTurn = true
        while (hpA > 0 && hpB > 0) {
            if (aTurn) {
                hpB -= atkA
            } else {
                hpA -= atkB
            }
            aTurn = !aTurn
        }
        val ans = (hpA>0).yesOrNo()
        println(ans)
    }


    /*####################################################################################*/

    fun readString() = readLine()!!
    fun readStrings() = readLine()!!.split(" ")
    fun readInt() = readLine()!!.toInt()
    fun readInts() = readLine()!!.split(" ").map { it.toInt() }
    fun readLong() = readLine()!!.toLong()
    fun readLongs() = readLine()!!.split(" ").map { it.toLong() }
    fun readMatrixRows(height: Int) = (1..height).map { readLine()!!.toList() }

    fun Boolean.yesOrNo() = if (this) "Yes" else "No"
    fun Double.toNaturalExpr() = println("%f".format(this))
}

Measured memory_bytes: 36504
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;


ll po (ll b, ll p) { return !p?1:po(b*b%MOD,p/2)*(p&1?b:1)%MOD; }
ll inv (ll b) { return po(b,MOD-2); }

void ad(int& a, int b) { a = (a+b)%MOD; }
ll sub(ll a, ll b) { return (a-b+MOD)%MOD; }
ll mul(ll a, ll b) { return a*b%MOD; }
ll divi(ll a, ll b) { return mul(a,inv(b)); }

int N,K, ans = 0;
vi prob = {1}, PROB;

void AD(int ind, int z) {
    while (sz(PROB) <= ind) PROB.pb(0);
    ad(PROB[ind],z);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    cin >> N >> K;
    ll in = inv(K+1);
    FORd(i,1,N+1) {
        PROB.clear();
        F0R(j,sz(prob)) {
            F0R(k,K+1) {
                ll pr = mul(prob[j],in);
                if (k <= i) {
                    ad(ans,mul((j+k)%i,pr));
                    AD((j+k)/i+j,pr);
                } else {
                    ad(ans,mul(j+k,pr));
                    AD(j,pr);
                }
            }
        }
        swap(prob,PROB);
    }
    
    cout << mul(ans,po(K+1,N));
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 256
N, K = map(int, input().split())
As = list(map(int, input().split()))
Fs = list(map(int, input().split()))
As.sort()
Fs.sort(reverse=True)
def check(x):
  k = 0
  for i in range(N):
    k += max(0, As[i]-x//Fs[i])
  return k <= K
a = 0
b = As[-1]*Fs[0]
while a < b:
  i = (a + b)//2
  if check(i):
    b = i
  else:
    if a == i:
      break
    a = i
r = b
print(r)


Measured memory_bytes: 119884
n = int(input())

for i in range(n):
    a,b,c = map(int,input().split(" "))
    if a**2 == b**2 + c**2:
        print("YES")
    elif b**2 == a**2 + c**2:
        print("YES")
    elif c**2 == a**2 + b**2:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 7656
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

const int MOD = 1e9 + 7;

int add(int x, int y) {
    x += y;
    if (x >= MOD)
        return x - MOD;
    return x;
}

int sub(int x, int y) {
    x -= y;
    if (x < 0)
        return x + MOD;
    return x;
}

int mul(int x, int y) {
    return (1LL * x * y) % MOD;
}

int bin_pow(int a, int p) {
    if (!p)
        return 1;
    if (p % 2)
        return (1LL * bin_pow(a, p - 1) * a) % MOD;
    int t = bin_pow(a, p / 2);
    return (1LL * t * t) % MOD;
}

int inv(int x) {
    return bin_pow(x, MOD - 2);
}

vector <vector <int>> gr;
vector <vector <int>> dp;

void dfs(int v, int p = -1) {
    dp[v][0] = dp[v][1] = 1;
    for (int u : gr[v]) {
        if (u == p)
            continue;
        dfs(u, v);
        dp[v][0] = mul(dp[v][0], add(dp[u][0], dp[u][1]));
        dp[v][1] = mul(dp[v][1], dp[u][0]);
    }
}


int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    gr.resize(n);
    forn (i, 1, n) {
        int v, u;
        cin >> v >> u, --v, --u;
        gr[v].pb(u), gr[u].pb(v);
    }
    dp.resize(n, vector <int> (2));
    dfs(0);
    cout << add(dp[0][0], dp[0][1]);
    return 0;
}

Measured memory_bytes: 14720
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

int main(void){
    long double a,b,c;
    cin >> a >> b >> c;
    
    long double ab2 = 2.0*sqrtl(a*b);
    
    if((a+ab2+b) < c){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
}


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

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	ld W, H, w, h, x, y;
	cin >> W >> H >> w >> h >> x >> y;
	ld tx[] = { x - w / 2, x + w / 2, x - w / 2, x + w / 2 };
	ld ty[] = { y - h / 2, y - h / 2, y + h / 2, y + h / 2 };
	for (int i = 0; i < 4; i++) {
		tx[i] = min(tx[i], W / 2);
		tx[i] = max(tx[i], -W / 2);
		ty[i] = min(ty[i], H / 2);
		ty[i] = max(ty[i], -H / 2);
	}
	ld gx = 0, gy = 0;
	for (int i = 0; i < 4; i++) {
		gx += tx[i];
		gy += ty[i];
	}
	cout << fixed << setprecision(10) << (ld)gy / gx << endl;
	return 0;
}



Measured memory_bytes: 3300
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,h[100001],min_cost[100001];
int mincost(int i)
{
    if(i==0) return 0;
    if(i==1) return abs(h[1]-h[0]);
    if(min_cost[i-1]==-1) min_cost[i-1]=mincost(i-1);
    if(min_cost[i-2]==-1) min_cost[i-2]=mincost(i-2);
    return min(abs(h[i]-h[i-1])+min_cost[i-1],abs(h[i]-h[i-2])+min_cost[i-2]);
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    cin>>n;
    for(int i=0;i<n;i++) cin>>h[i];
    for(int i=0;i<n;i++) min_cost[i]=-1;
    cout<<mincost(n-1);
    return 0;
}

Measured memory_bytes: 4992
# 2019 6/22
# ABC 131 B Bite Eating

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

apple_pie = N * ( 2 * L + N - 1) / 2

if L >= 0:
    print("%d" % (apple_pie - L))

elif L <= 0 and (L + N - 1) >= 0:
    print("%d" % apple_pie)

else:
    print("%d" % (apple_pie - (L + N - 1)))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  for (;;){
    int h, w; cin >> h >> w;
    if (h == 0) return 0;
    for (int i = 0; i < h; i++){
      if (i == 0 || i == h - 1){
        for (int j = 0; j < w; j++) cout << "#";
        cout << endl;
      }
      else{
        for (int j = 0; j < w; j++){
          if (j == 0 || j == w - 1) cout << "#";
          else cout << ".";
        }
        cout << endl;
      }
    }
    cout << endl;
  }
}


Measured memory_bytes: 3072
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	n := nextInt()
	ans := 0
	for i := 1; i <= n; i += 2 {
		tmp := 0
		for j := 1; j <= i; j++ {
			if i%j == 0 {
				tmp += 1
			}
		}
		if tmp == 8 {
			ans += 1
		}
	}
	fmt.Fprintln(out, ans)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;using L = long long;using V= pair<L,L>;
#define F first
#define S second
#define I XH[i]
#define R for(L i=0;i<N;i++)
L N,D,A,n=0,r=0,t;V XH[200005];queue<V>P;
int main() {cin>>N>>D>>A;R cin>>I.F>>I.S;sort(XH,XH+N);R{while(!P.empty()&P.front().F<I.F){n-=P.front().S;P.pop();}I.S-=n;if(I.S>0){t=(I.S+A-1)/A;r+=t;P.push({I.F+2*D,t*A});n+=t*A;}}cout<<r;} 

Measured memory_bytes: 4992
#include<iostream>
using namespace std;
#define MAX 100000
typedef long long llong;

int n,k;
llong T[MAX];
int check(llong P){
	int i=0;
	for( int j=0; j<k; j++ ){
		llong s=0;
		while( s+T[i]<=P ){
			s += T[i];
			i++;
			if( i==n ) return n;
		}
	}
	return i;
}

int solve(){
	llong left = 0;
	llong right = 100000 * 10000;
	llong mid;

	while( right - left > 1 ){
		mid = (left+right)/2;
		int v=check(mid);
		if( v>=n ) right=mid;
		else left = mid;
	}

	return right;
}


int main(){
	cin >> n >>k;
	for( int i=0; i<n; i++) cin >> T[i];
	llong ans = solve();
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3872
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
 
int main()
{
    int n,m;
    cin >> n >> m;
    int flag[40] = {};
    for(int i = 0; i < n; i++){
        int k;
        cin >> k;
        for(int j = 0; j < k; j++){
            int a;
            cin >> a;
            flag[a]++;
        }
    }
    int ans = 0;
    for(int i = 1; i <= m; i++){
        if(flag[i] == n) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Solve is
   M1 : Integer;
   D1 : Integer;
   M2 : Integer;
   D2 : Integer;
begin
   Get (M1);
   Get (D1);
   Get (M2);
   Get (D2);
   if M1 = M2 then
      Put_Line ("0");
   else
      Put_Line ("1");
   end if;
end Solve;

Measured memory_bytes: 3684
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int l, r, d;
  cin >> l >> r >> d;
  int ans = 0;
  for (int i = l; i <= r; i++) {
    if (i%d == 0)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3612
def kaibun(s):
  ans = True
  for i in range(int(len(s) /2)):
    if s[i] != s[-1 * i - 1]:
      ans = False
      break
  return(ans)


inp = input()
N = len(inp)
a = int((N - 1) / 2)
b = int((N + 3) / 2 -1)
inp_a = inp[:a]
inp_b = inp[b:]
if kaibun(inp) and kaibun(inp_a) and kaibun(inp_b):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rkc ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
#define fl(i,a,b) for(ll i=a;i<b;i++)
#define rfl(i,a,b) for(ll i=a;i>b;i--)
#define pb push_back
#define mp make_pair
#define test ll t;cin>>t;while(t--)
#define lld long double
const ll M = 1e9 + 7;
const double pi  =3.141592653589793238463;
int main()
{
    rkc;
    ll a,b;
    cin>>a>>b;
    if(a>=13)
    cout<<b;
    else if(a>=6)
    cout<<b/2;
    else cout<<0;
}

Measured memory_bytes: 256
#!/usr/bin/perl -w
use warnings;

$a = <STDIN>;
chomp $a;
@letters = split //,$a;
$length = @letters;
#$F = -1;
$C = -1;
foreach ($i = 0; $i<$length; $i++) {
   if($letters[$i] =~ 'C' && $C == -1 ){
        $C = $i;
        next;
   } 
   if($letters[$i] =~ 'F' && $C != -1 ){
        print "Yes\n";
        exit;
   }
}
print "No\n";

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

int n, m, ct, val[40];
bool s;
char ans[40000];
long long get_dis(pair <int, int> x, pair <int, int> y)
{
	return (long long) abs(x.first - y.first) + abs(x.second - y.second);
}
int main()
{
	m = 32;
	val[1] = 1;
	for (int i = 2; i <= m; i++)
		val[i] = 1 << (i - 2);
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		pair <int, int> now, goal, to;
		scanf("%d%d", &goal.first, &goal.second);
		if (i == 1) s = (goal.first + goal.second) & 1;
		else if (s != ((goal.first + goal.second) & 1))
		{
			puts("-1");
			return 0;
		}
		for (int j = m; j >= (s ? 2 : 1); j--)
		{
			char ch;
			long long mini = 0x3f3f3f3f3f3f3f3fLL, tmp;
			if (mini > (tmp = get_dis(goal, make_pair(now.first, now.second + val[j])))) ch = 'U', mini = tmp, to = make_pair(now.first, now.second + val[j]);
			if (mini > (tmp = get_dis(goal, make_pair(now.first, now.second - val[j])))) ch = 'D', mini = tmp, to = make_pair(now.first, now.second - val[j]);
			if (mini > (tmp = get_dis(goal, make_pair(now.first + val[j], now.second)))) ch = 'R', mini = tmp, to = make_pair(now.first + val[j], now.second);
			if (mini > (tmp = get_dis(goal, make_pair(now.first - val[j], now.second)))) ch = 'L', mini = tmp, to = make_pair(now.first - val[j], now.second);
			now = to;
			ans[++ct] = ch;
		}
		ans[++ct] = '\n';
	}
	printf("%d\n", m - s);
	for (int i = m; i >= (s ? 2 : 1); i--)
		printf("%d ", val[i]);
	puts("");
	for (int i = 1; i <= ct; i++)
		putchar(ans[i]);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int n,a,ans=0;
  scanf("%d",&n);
  map<int,int> mp;
  rep(i,n){
    scanf("%d",&a);
    mp[a]++;
  }
  for(auto i=mp.begin();i!=mp.end();i++)
    ans+=i->second-(i->first>i->second?0:i->first);
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 4736
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {

		int N = nextInt();
		int W = nextInt();
		int[] weight = new int[N];
		int[] v = new int[N];
		for(int i=0;i<N;i++){
			weight[i]=nextInt();
			v[i]=nextInt();
		}
		long[][] dp = new long[N+1][W+1];
		for(int i=0;i<dp.length;i++){
			Arrays.fill(dp[i], 0);
		}
		for(int i=0;i<N;i++){
			for(int w=0;w<=W;w++){
				if(w-weight[i]>=0){
					dp[i+1][w]=Math.max(dp[i+1][w],dp[i][w-weight[i]]+v[i]);
				}
				dp[i+1][w]=Math.max(dp[i+1][w],dp[i][w]);
			}
		}

		System.out.println(dp[N][W]);

	}

	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}

Measured memory_bytes: 126932
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n, k, d, ans;
		boolean hate[] = new boolean[10];
		boolean judge;
		
		n = sc.nextInt();
		k = sc.nextInt();
		
		for (int i = 0; i < k; i++) {
			d = sc.nextInt();
			hate[d] = true;
		}
		
		for (int i = n; ; i++) {
			judge = true;
			String str = String.valueOf(i);
			
			for (int j = 0; j < str.length(); j++) {
				if(hate[str.charAt(j) - '0']) {
					judge = false;
				}
			}
			
			if (judge) {
				ans = i;
				break;
			}
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 14164
r, c = map(int, input().split())
a = []

for i in range(r):
    a.append(list(map(int, input().split())))
    a[i].append(sum(a[i]))

for i in range(r):
    print(" ".join(list(map(str, a[i]))))

col_sum = []
for j in range(c+1):
    su = 0
    for i in range(r):
        su += a[i][j]
    col_sum.append(su)

print(" ".join(list(map(str, col_sum))))


Measured memory_bytes: 5700
n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
sum_=[]
total=0
for i in range(n):
    total+=a[i]
    sum_.append(total)
a=sorted(a,reverse=True)
ans=1
max_=a[0]
for i in range(1,n):
    if max_<=a[i]*2:
        ans+=1
        max_=a[i]
    else:
        if max_<=sum_[(n-1)-i]*2: #自分以下の数を吸収
            ans+=1
            max_=a[i]
        else:
            break
print(ans)

Measured memory_bytes: 65896
# include <cstdio>
# include <iostream>
# include <cstring>
# include <string>
# include <cmath>
# include <queue>
# include <algorithm>
using namespace std;
int main()
{
	string a;
	cin>>a;
	int len=a.size();
	bool flag=0;
	int p;
	for(int i=0;i<len;i++)
		if(a[i]=='C')
		{
			flag=1;
			p=i;
			break;
		}
	for(int i=p+1;i<len;i++)
		if(a[i]=='F')
		{
			cout<<"Yes";
			return 0;
		} 
	cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	long long ans = 0;
	if (n == 1) ans = a[0] / 2;
	else {
		for (int i = 1; i < n; i++) {
			long long k = a[i] + a[i - 1];
			ans += k / 2;
			if (a[i]) a[i] = k % 2;
		}
	}
	cout << ans << endl;
		
	return 0;	
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<pair<int, int>> P(n);
  vector<int> id(n);
  rep(i, n) {
    cin >> P[i].first >> P[i].second;
    id[i] = i;
  }
  sort(all(id), [&](int i, int j) {
    return P[i] < P[j];
  });
  vector<int> A(n);
  rep(i, n) A[i] = P[id[i]].second;
  dsu uf(n);
  map<int, int> mp;
  rrep(i, n) {
    auto itr = mp.lower_bound(A[i]);
    if(itr != mp.end()) {
      vector<pair<int, int>> tmp;
      for(; itr!=mp.end(); itr++) {
        uf.merge(id[i], itr->second);
        tmp.push_back(*itr);
      }
      for(auto p: tmp) mp.erase(p.first);
      mp[tmp.back().first] = tmp.back().second;
    } else {
      mp[A[i]] = id[i];
    }
  }
  vector<int> ans(n);
  rep(i, n) {
    ans[id[i]] = uf.size(id[i]);
  }
  rep(i, n) cout << ans[i] << endk;
  return 0;
}


Measured memory_bytes: 8232
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

int main(){
    string S;
    cin>>S;
    ll N = S.size();
    vector<vector<ll>> dp(N,vector<ll>(13,0));

    if(S[0]=='?'){
        for(ll i=0;i<10;i++){
            dp[0][i]=1;
        }
    }else{
        dp[0][S[0]-'0']=1;
    }
    for(ll i=1;i<N;i++){
        if(S[i]=='?'){
            for(ll j=0;j<13;j++){
                ll num = dp[i-1][j];
                for(ll k=0;k<10;k++){
                    dp[i][(j*10%13+k)%13]+=num%MOD;
                    dp[i][(j*10%13+k)%13]%=MOD;
                } 
            }
        }else{
            ll s = S[i]-'0';
            for(ll j=0;j<13;j++){
                ll num = dp[i-1][j];
                dp[i][(j*10%13+s)%13]+=num%MOD;
                dp[i][(j*10%13+s)%13]%=MOD;  
            }
        }
    }
    cout<<(dp[N-1][5]%MOD)<<endl;
}

Measured memory_bytes: 13696
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using vl = vector<long long>;
using P = pair<long long,long long>;
 
int main(){
	ll n,k; cin >> n >> k;
	ll m = n%k;
	cout << min(m,k-m) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,a;cin >> n >> a;
	vector<int> x(n);
	rep(i,n) cin >> x.at(i);
	vector<vector<vector<ll>>> dp(n + 1, vector<vector<ll>>(n + 1, vector<ll>(3000)));
	dp[0][0][0] = 1;
	rep(i,n){
		rep(j,n){
			rep(k,2501){
				dp[i + 1][j + 1][k + x.at(i)] += dp[i][j][k];
				dp[i + 1][j][k] += dp[i][j][k];
			}
		}
	}
	ll ans = 0;
	for(int i = 1; i <= n; i++){
		ans += dp[n][i][a * i];
	}
	cout << ans << endl;
}


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

char m[105][105];

int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    for(int i=0;i<100;i++)
    {
        for(int j=0;j<100;j++)
        {
            m[i][j]=i<50?'.':'#';
        }
    }
    for(int i=0;i<50&&b>1;i+=2)
    {
        for(int j=0;j<100&&b>1;j+=2)
        {
            m[i][j]='#';
            b--;
        }
    }
    for(int i=51;i<100&&a>1;i+=2)
    {
        for(int j=1;j<100&&a>1;j+=2)
        {
            m[i][j]='.';
            a--;
        }
    }
    printf("100 100\n");
    for(int i=0;i<100;i++)
    {
        printf("%s\n",m[i]);
    }
    return 0;
}


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

using namespace std;
typedef long long  ll;

int main() {
	ll N;
	cin >> N;
	vector<ll> s(13), h(13), c(13), d(13);
	for (ll i = 0; i < N; i++)
	{
		string str;
		ll num;
		cin >> str >> num;
		if (str == "S") s[num - 1] = 1;
		else if (str == "H") h[num - 1] = 1;
		else if (str == "C") c[num - 1] = 1;
		else d[num - 1] = 1;
	}
	for (ll i = 0; i < 13; i++)
	{
		if (s[i] != 1) cout << "S " << i + 1 << endl;
	}
	for (ll i = 0; i < 13; i++)
	{
		if (h[i] != 1) cout << "H " << i + 1 << endl;
	}
	for (ll i = 0; i < 13; i++)
	{
		if (c[i] != 1) cout << "C " << i + 1 << endl;
	}
	for (ll i = 0; i < 13; i++)
	{
		if (d[i] != 1) cout << "D " << i + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=201000;
char s[N];
ll ans;
int main() {
	scanf("%s",s);
	int n=strlen(s),od=0,ev=0;
	for (int i=0;i<n;i++) if (s[i]=='1') {
		if (i%2==0) od++; else ev++;
	}
	bool par=1;
	rep(i,0,n) {
		if (s[i]=='1') {
			if (par) ans+=n-i;
			od--;
			par^=1;
		} else {
			if (par) ans+=od;
			else par^=1;
		}
		swap(od,ev);
		//printf("%lld\n",ans);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 3956
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

struct Memo {
	int fact = 0;
	int fact_inv = 0;
	int inv = 0;
};
class Combination {
private:
	int m_module = 1000000007;
	vector<struct Memo> memo;
public:
	int calculate(int, int);
	Combination(int, int);
};
int Combination::calculate(int n, int k) {
	return (memo[n].fact * memo[k].fact_inv * memo[n - k].fact_inv) % m_module;
}
Combination::Combination(int memo_max, int module = 1000000007) {
	m_module = module;
	memo.push_back({ 1,1,0 });
	memo.push_back({ 1,1,1 });
	for (int loop = 2; loop <= memo_max; loop++) {
		struct Memo temp;
		temp.fact = (memo[loop - 1].fact * loop) % m_module;
		temp.inv = m_module - memo[m_module % loop].inv * int(m_module / loop) % m_module;
		temp.fact_inv = (memo[loop - 1].fact_inv * temp.inv) % m_module;
		memo.push_back(temp);
	}
}

void A_Kth_Term(void) {

	int num[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int K;
	cin >> K;
	cout << num[K - 1] << flush;
	return;
}

void B_Bishop(void) {

	long long H, W;
	cin >> H >> W;

	if (H % 2 == 0 || W % 2 == 0)	cout << H * W / 2 << flush;
	else							cout << (H * W + 1) / 2 << flush;
	return;
}

void C_Sqrt_Inequality(void) {

	long long a, b, c;
	cin >> a >> b >> c;

	cout << ((a + b < c && (c - a - b) * (c - a - b) - 4 * a * b > 0) ? "Yes" : "No") << flush;
	return;
}

int main(void) {

	//A_Kth_Term();
	//B_Bishop();
	C_Sqrt_Inequality();
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int judge_right_triangle(int a, int b, int c);

int main(void)
{
    int number;
    scanf("%d", &number);
    for(int j = 0; j < number; j = j + 1){
      int print_right_triangle;
      int x, y, z;
      scanf("%d %d %d", &x, &y, &z);
      print_right_triangle = judge_right_triangle(x, y, z);
      if (print_right_triangle == 1) {
        printf("YES\n");
      } else if (print_right_triangle == 0) {
          printf("NO\n");
        }
    }
  return 0;
}

int judge_right_triangle(int a, int b, int c)
{
    int t;
    if (a * a + b * b == c * c){
      t = 1;
    } else if (a * a + c * c == b * b) {
      t = 1;
    } else if ( b * b + c * c == a * a) {
      t = 1;
    }
  //三平方の定理を満たすときt=１を返す                                                                                                                                               
    else{
      t = 0;
    }
    return t;
}

Measured memory_bytes: 1008
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    ll mod = 998244353;
    int n, s;
    cin >> n >> s;
    vector<int> arr(n, 0);
    for(int& val: arr)
        cin >> val;
    vector<ll> dp(s+1, 0);
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        vector<ll> new_dp = dp;
        for(int j = 1; j <= s; j++) {
            if (dp[j] > 0 && j+arr[i] <= s) {
                new_dp[j+arr[i]] += dp[j];
                new_dp[j+arr[i]] %= mod;
            }
        }
        if (arr[i] <= s) { // multiply first element to extend LHS
            new_dp[arr[i]] += i+1;
        }
        dp = new_dp;
        ans += dp[s]; // extend right each time
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N; string S; cin >> N >> S;
    int left = 0, right = 0;
    REP(i, 0, N) {
        if (S[i] == '(') left++;
        else {
            if (left > 0) left--;
            else right++;
        }
    }
    REP(i, 0, right) cout << '(';
    cout << S;
    REP(i, 0, left) cout << ')';
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int node[10];
int route[205][205];
int dp[1<<10][10];
int main(void)
{
    int n,m,k;
    scanf("%d %d %d",&n,&m,&k);
    for(int i = 0; i < k; i++)
        scanf("%d",&node[i]);
    memset(route,0x3f,sizeof(route));
    while(m--)
    {
        int x,y,cost;
        scanf("%d %d %d",&x,&y,&cost);
        route[y][x] = route[x][y] = cost;
    }
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            for(int s = 1; s <= n; s++)
            {
                route[j][s] = min(route[j][s],route[j][i] + route[i][s]);
            }
        }
    }
    memset(dp,0x3f,sizeof(dp));
    int maxx = dp[0][0];
    for(int i = 0; i < k; i++)
    {
        dp[(1<<i)][i] = 0;
    }
    for(int i = 1; i < 1<<k; i++)
    {
        for(int j = 0; j < k; j++)
        {
            for(int s = 0; s < k; s++)
            {
                if(j!=s&&!(i&(1<<s)))
                {
                    dp[i|(1<<s)][s] = min(dp[i|(1<<s)][s],dp[i][j] + route[node[j]][node[s]]);
                }
            }
        }
    }
    for(int i = 0; i < k; i++)
    {
        maxx = min(dp[(1<<k)-1][i],maxx);
    }
    printf("%d\n",maxx);
    return 0;
}


Measured memory_bytes: 512
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#include<list>
#define ll long long int
#define MOD 1000000007LL
using namespace std;

int main() {
    int n,z,w;
    cin>>n>>z>>w;
    int a[2001]={};
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    if(n<2){
        cout<<abs(w-a[n-1]);
    }else{
        cout<<max(abs(w-a[n-1]),abs(a[n-1]-a[n-2]));
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
#define INF           1e9
#define INFL          static_cast<lint>(INF)
#define REP(i,n)      for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)     for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPI(i,ini,n) for(lint i=(ini),i##_len=(n);i<i##_len;++i)
#define REPC(i,obj)   for(auto i:obj)
#define R_UP(a,b)     (((a)+(b)-1)/(b))
#define ALL(obj)      (obj).begin(),(obj).end()
int main()
{
	int a = in(), b = in(), c = in();
	cout << min({ a,b,c }) << ' ' << max({ a,b,c }) << endl;
}


Measured memory_bytes: 3072
package main
 
import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
 
const m = 1000000007
 
func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
 
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
		
	c := make([]int64, 60, 60)
	for i := 0; i < 60; i++ {
		c[i] = 0
	}
 
	for i := 0; i < n; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
 
		for j := 0; j < 60; j++ {
			c[j] += int64((a >> (uint32(j) + 1) << 1) ^ (a >> uint32(j)))
		}
	}
 
	var answer int64 = 0
	for i := 0; i < 60; i++ {
		answer += (((int64(n) - c[i]) * c[i] % m) * (1 << uint32(i) % m)) % m
		answer %= m
	}
	fmt.Println(answer)
}

Measured memory_bytes: 7572
#include <bits/stdc++.h>
using namespace std;
int N;
int memo[100100];

int rec(int N){
  if(N == 0) return 0;
  if(memo[N] != -1) return memo[N];
  int num = N;
  for(int i = 0; pow(6, i) <= N; i++) num = min(num, rec(N - pow(6, i)) + 1);
  for(int i = 0; pow(9, i) <= N; i++) num = min(num, rec(N - pow(9, i)) + 1);
  return memo[N] = num;
}

signed main(){
  cin >> N;
  for(int i = 0; i <= N; i++) memo[i] = -1;
  cout << rec(N) << endl;
}


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

#define rep_0(i, end) for(int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for(int i = (fr); i <= (ba); ++i)
#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define overload_rep(arg_0, arg_1, arg_2, name, ...) name
#define all(box) box.begin(), box.end()

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

typedef long long lint;

int main() {

    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    bool all_neg = true;
    lint odd = 0, even = 0;
    rep(i, N) {
        if(A[i] > 0) {
            all_neg = false;
            (i % 2 == 0 ? odd : even) += A[i];
        }
    }

    if(all_neg) {
        int maxi = -(1 << 30), pos = 0;
        rep(i, N) if(chmax(maxi, A[i])) pos = i + 1;
        cout << maxi << '\n' << N - 1 << '\n';
        for(int i = N; i > pos; --i) cout << i << '\n';
        rep(i, pos - 1) cout << "1\n";
        return 0;
    }

    lint answer, idx = 0;
    vector<int> use[2];
    if(odd > even) {
        answer = odd;
        rep(i, N) if(i % 2 == 0 && A[i] > 0) {
            use[idx].push_back(i + 1);
        }
    } else {
        answer = even;
        rep(i, N) if(i % 2 == 1 && A[i] > 0) {
            use[idx].push_back(i + 1);
        }
    }

    cout << answer << '\n';
    cout << (use[idx].back() - use[idx].front()) / 2 + (use[idx].front() - 1) + (N - use[idx].back()) << '\n';

    int dimin = 0;
    for(int i = N; i > use[idx].back(); --i) cout << i << '\n';
    rep(i, use[idx].front() - 1) { cout << "1\n"; ++dimin; }
    while(use[idx].size() > 1) {
        use[idx].front() -= dimin;
        use[1 - idx].push_back(use[idx].front());
        for(int i = 0; i + 1 < use[idx].size(); ++i) {
            use[idx][i + 1] -= dimin;
            cout << (use[idx][i] + use[idx][i + 1]) / 2 << '\n';
            dimin += 2;
            use[idx][i + 1] -= 2;
            if(use[idx][i + 1] != use[idx][i]) {
                use[1 - idx].push_back(use[idx][i + 1]);
            }
        }
        use[idx].clear();
        idx = 1 - idx;
        dimin = 0;
    }
    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <queue>
#define ll long long
#define N 10000
#define mod 1000000007
#define LL 100
using namespace std;

int main(){
    string a,b;
    cin>>a>>b;
    int l=a.size();
    bool ans=true;
    for (int i=0; i<l; i++){
        if (a[i]!=b[i]) ans=false;
    }
    if (ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3628
import math
import copy




def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input().split())
def func():
    res1=min(n[1],n[2])
    if n[1]+n[2]<=n[0]:
        res2=0
    else:
        res2=res2=n[1]+n[2]-n[0]
    return str(res1)+" "+str(res2)


print(func()) 







Measured memory_bytes: 3700
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M, K = mapint()
s = set()
for i in range(N+1):
    for j in range(M+1):
        s.add(i*M+j*N-i*j*2)

if K in s:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 109156
#include<cmath>
#include<cstdio>
#include<algorithm>

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

using namespace std;

// 三角形が作れるかどうか
bool tri(int a,int b,int c){
	int p[]={a,b,c};
	sort(p,p+3);
	return p[0]+p[1]>p[2];
}

double volume(double U,double V,double W,double u,double v,double w){
	double X=(w-U+v)*(U+v+w);
	double x=(U-v+w)*(v-w+U);
	double Y=(u-V+w)*(V+w+u);
	double y=(V-w+u)*(w-u+V);
	double Z=(v-W+u)*(W+u+v);
	double z=(W-u+v)*(u-v+W);
	double a=sqrt(x*Y*Z);
	double b=sqrt(y*Z*X);
	double c=sqrt(z*X*Y);
	double d=sqrt(x*y*z);
	return sqrt((-a+b+c+d)*(a-b+c+d)*(a+b-c+d)*(a+b+c-d))/(192*u*v*w);
}

int main(){
	for(int n;scanf("%d",&n),n;){
		int L[15];
		rep(i,n) scanf("%d",L+i);

		double ans=0;
		int p[15]={1,1,1,1,1,1};
		do{
			int m=0,q[6];
			rep(i,n) if(p[i]==1) q[m++]=i;
			do{
				int a=L[q[0]];
				int b=L[q[1]];
				int c=L[q[2]];
				int d=L[q[3]];
				int e=L[q[4]];
				int f=L[q[5]];
				if(tri(a,b,c) && tri(a,e,f) && tri(b,f,d) && tri(c,d,e)) ans=max(ans,volume(a,b,c,d,e,f));
			}while(next_permutation(q,q+5)); // 一つの辺は固定していい
		}while(prev_permutation(p,p+n));

		printf("%.9f\n",ans);
	}

	return 0;
}

Measured memory_bytes: 816
#include <stdio.h>

int main(){

  int n;

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

    int t[n+1][n+1];
    int i,j;
    for(i=0;i<n;i++) for(j=0;j<n;j++) scanf("%d", &t[i][j]);

    t[n][n] = 0;

    for(i=0;i<n;i++){
      t[n][i] = 0;
      for(j=0;j<n;j++) t[n][i] += t[j][i];
      t[n][n] += t[n][i];
    }

    for(i=0;i<n;i++){
      t[i][n] = 0;
      for(j=0;j<n;j++) t[i][n] += t[i][j];
      t[n][n] += t[i][n];
    }

    t[n][n] /= 2;

    for(i=0;i<=n;i++){
      for(j=0;j<=n;j++) printf("%5d", t[i][j]);
      puts("");
    }
  }

  return 0;
}

Measured memory_bytes: 0