akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main(){
  int n,x,i,j,k,data,c=0;


  while(1){
    c= 0;
    cin >> n >> x;
    
    if ( n == 0 && x == 0)break;
    else{
      for ( i = 1 ; i <= n ; i++){
	for(j = i+1 ; j <= n ; j++){
	  for( k = j+1; k <= n ; k++){
	    data = i + j + k;
	  if ( data == x){
	    c++;
	  }
	  }
	}
      }
    }
      cout << c<<endl;
  }
			      
  
   



  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include <map>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include"time.h"
using namespace std;

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define dump(x)  cerr << #x << " = " << (x) << endl

//毎回変える場所
#define N_MAX 200


//問題文のとおり
LL N,X,k;

LL gcd(LL a, LL b) {
	LL c;
	while (a != 0) {
		c=a;
		a=b%a;
		b=c;
	}
	return b;
}

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

	k=gcd(N,X);
	cout << (N - k) * 3 << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main(){
	var str string
	fmt.Scan(&str)
	strs := strings.Split(str, "")
	length := len(strs)
	if "s" == strs[length-1]{
		fmt.Println(str+"es")
	}else{
		fmt.Println(str+"s")
	}
}


Measured memory_bytes: 1868
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
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;}

int N,A,B;
inline void solve(){
  IN3(N,A,B);
  OUT(min(A*N,B));
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    ll N,ans;
    cin >> N;
    ans=1;
    while(ans*2<=N){
      ans*=2;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main()
{
    int v, e;
    long long inf = 100000000000000;
    scanf("%d %d", &v, &e);
    vector<vector<long long>> a(v, vector<long long>(v, inf));
    for (int i = 0, s, t, d; i < e; i++)
    {
        scanf("%d %d %d", &s, &t, &d);
        a[s][t] = d;
    }
    for (int i = 0; i < v; i++)
    {
        a[i][i] = 0;
    }
    
    for (int i = 0; i < v; i++)
    {
        for (int j = 0; j < v; j++)
        {
            for (int k = 0; k < v && a[j][i] != inf; k++)
            {
                if (a[i][k] != inf)
                {
                    a[j][k] = min(a[j][k], a[j][i] + a[i][k]);
                }
            }
        }
    }
    for (int i = 0; i < v; i++)
    {
        if (a[i][i] < 0)
        {
            printf("NEGATIVE CYCLE\n");
            return 0;
        }
    }
    for (int i = 0; i < v; i++)
    {
        printf(a[i][0] == inf ? "INF" : "%lld", a[i][0]);
        for (int j = 1; j < v; j++)
        {
            printf(a[i][j] == inf ? " INF" : " %lld", a[i][j]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 3332
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <cassert>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

struct segtree{
  ll M=1, INIT;
  vector<ll> dat;
  segtree(ll N, ll num):INIT(num){
    while(M<N) M*=2;
    dat.resize(M*2-1, num);
  }
  void update(ll x, ll k){
    k+=M-1;
    dat[k] = max(x, dat[k]);
    while(k>0) k = (k-1)/2, dat[k] = max(dat[k*2+1],dat[k*2+2]);
  }
  ll query(ll a, ll b=-1, ll k=0, ll l=0, ll r=-1){
    if(r==-1) r = M;
    if(b==-1) b = M;
    if(r<=a || b<=l) return INIT;
    if(a<=l && r<=b) return dat[k];
    ll A = query(a, b, k*2+1, l, (l+r)/2);
    ll B = query(a, b, k*2+2, (l+r)/2, r);
    return max(A, B);
  }
};

int main(){
  ll n, k;std::cin >> n >> k;
  segtree seg(300004, 0);
  vll a(n);re(i, n) std::cin >> a[i];
  ll ans = 0;
  for(int i=0;i<n;i++){
    ll q = seg.query(max(0LL, a[i]-k), a[i]+k+1) + 1;
    ans = max(ans, q);
    seg.update(q, a[i]);
  }
  std::cout << ans << '\n';
}


Measured memory_bytes: 13832
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[]{sc.nextInt(), sc.nextInt(), sc.nextInt()};
        Arrays.sort(a);
        System.out.println(a[0] + " " + a[1] + " " + a[2]);
    }
}

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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

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

lli is_prime[100001]; // i 番目が素数かどうか
lli prime_count[100001]; // i 番目までに何個の素数が含まれているか

// n以下の自然数に何個素数が含まれるのかを返す
// sieve(10) => 4
lli sieve(lli n) {
    lli p = 0;
    REPE(i, 0, n) {
        is_prime[i] = true;
    }
    is_prime[0] = is_prime[1] = false;

    REPE(i, 2, n) {
        if (is_prime[i]) {
            p++;
            for (lli j = 2*i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
    return p;
}

int main() {
    sieve(100000);
    lli q;
    cin1(q);
    lli l[q], r[q];
    ncin2(q, l, r);
    lli count = 0;
    REPE(i, 2, 100000) {
        if (i % 2 == 0) {
            prime_count[i] = count;
            continue;
        }
        if (is_prime[i] && is_prime[(i+1)/2])
            count++;
        prime_count[i] = count;
    }

    REP(i, 0, q) {
        cout << prime_count[r[i]] - prime_count[l[i]-1] << endl;
    }

}


Measured memory_bytes: 3712
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;

int city[55];

int main(){
	int a,b;
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>a>>b;
		city[a]++;
		city[b]++;
	}
	for(int i=1;i<=n;i++){
		cout<<city[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

struct UnionFind
{
  vector<int> par;

  UnionFind(int n) : par(n, -1) {}

  int root(int x)
  {
    if (par[x] < 0)
      return x;
    else
      return par[x] = root(par[x]);
  }

  bool isSame(int x, int y)
  {
    return root(x) == root(y);
  }

  bool merge(int x, int y)
  {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (par[x] > par[y])
      swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }

  int size(int x)
  {
    return -par[root(x)];
  }
};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K, L;
  cin >> N >> K >> L;
  UnionFind uf1(N);
  for (int i = 0; i < K; i++)
  {
    int p, q;
    cin >> p >> q;
    p--, q--;
    uf1.merge(p, q);
  }
  vector<int> ar(N);
  for (int i = 0; i < N; i++)
  {
    ar[i] = uf1.root(i);
  }

  UnionFind uf2(N);
  for (int i = 0; i < L; i++)
  {
    int r, s;
    cin >> r >> s;
    r--, s--;
    uf2.merge(r, s);
  }
  vector<int> br(N);
  for (int i = 0; i < N; i++)
  {
    br[i] = uf2.root(i);
  }

  map<pair<int, int>, int> mp;
  for (int i = 0; i < N; i++)
  {
    mp[{ar[i], br[i]}]++;
  }

  for (int i = 0; i < N; i++)
  {
    cout << mp[{ar[i], br[i]}] << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 17624
//Moh_K_Imar .......
//26/08/2020  ... 4.00.
//Ya Rab....
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
    ll a,b;
    cin>>a>>b;
    if((a+b)%2==0)cout<<(a+b)/2<<endl;
    else cout<<"IMPOSSIBLE"<<endl;

    return 0;
}



Measured memory_bytes: 3588
// È¥°É£¡Æ¤¿¨Çð! °ÑAC´ø»ØÀ´£¡
//      ¤Ø¡¡¡¡¡¡¡¡¡¡£¯|
// ¡¡¡¡/£Ü7¡¡¡¡¡¡ ¡Ï£ß/
// ¡¡ /¡¡©¦¡¡¡¡ £¯¡¡£¯								AC		AC		AC		AC
//    ©¦¡¡Z £ß,£¼¡¡£¯¡¡¡¡ /`©c						AC		AC		AC		AC
//    ©¦¡¡¡¡¡¡¡¡¡¡©c¡¡¡¡ /¡¡¡¡¡µ					AC		AC		AC		AC
// ¡¡Y¡¡¡¡¡¡¡¡¡¡`¡¡ /¡¡¡¡/  /						AC		AC		AC		AC
// ¡¡Øé¡ñ¡¡.¡¡¡ñ¡¡¡¡¡´¡¡/¡¡/						AC		AC		AC		AC
// ¡¡()¡¡ ¤Ø¡¡¡¡¡¡¡¡|¡¡£Ü¡´							AC		AC		AC		AC
// ¡¡¡¡>- ._¡¡ ¥£¡¡ ©¦ £¯£¯							AC		AC		AC		AC
// ¡¡ / ¤Ø¡¡¡¡ /¡¡/£¼| £Ü£Ü							AC		AC		AC		AC
// ¡¡ ©c_/¡¡¡¡(_£¯¡¡ ©¦£¯£¯							AC		AC		AC		AC
// ¡¡¡¡ 7¡¡¡¡¡¡¡¡¡¡¡¡¡¡|£¯							AC		AC		AC		AC
// ¡¡¡¡ £¾¨Dr£þ£þ`-¨D£ß/							AC		AC		AC		AC
//**************************************Accepted*****************************************//

#include<bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define Unique(x) x.erase(unique(all(x)),x.end());

using namespace std;

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

const int Days[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};

inline int read()
{
	#define gc getchar
	int ans=0;
	bool f=1;
	char ch=gc();
	
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	
	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
	
	return f?ans:-ans;
	
	#undef gc
}

typedef long long ll;

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	
	string s,t;cin>>s>>t;
	
	ll ans=1000000000000000000ll;
	
	for(int i=0;i<=s.size()-t.size();i++)
	{
		ll tans=0ll;
		
		for(int j=0;j<t.size();j++)tans+=(s[i+j]!=t[j]);
		
		ans=min(ans,tans);
	}
	
	cout<<ans;
	
	//printf("Time used = %.12f",(double)(clock())/CLOCKS_PER_SEC);
	return 0;
}

/*  GOD BLESS  */


Measured memory_bytes: 3640
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] monsters = new int[n];
    for (int i = 0; i < n; i++) {
      monsters[i] = sc.nextInt();
    }
    Arrays.sort(monsters);
    long ans = 0;
    for (int i = 0; i < n - k; i++) {
      ans += monsters[i];
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 60908
#include <stdio.h>

int main(void){
    int a,b,c,k,tmp;
    scanf("%d %d %d",&a,&b,&c);
    scanf("%d",&k);
    int max = a;
    if(b > max) max = b;
    if(c > max) max = c;
    tmp = max;
    for(int i=0;i<k;i++){
        tmp *= 2;
    }
    if(max==a){
        printf("%d\n",tmp+b+c);
    }
    else if(max==b){
        printf("%d\n",a+tmp+c);
    }
    else{
        printf("%d\n",a+b+tmp);
    }
    return 0;
}

Measured memory_bytes: 128
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  ll n,m;
  std::cin >> n >> m;
  if(n==m && n==1){
    std::cout << "1" << '\n';
    return 0;
  }
  else if(n==1 && m>=2){
    std::cout << m-2 << '\n';
    return 0;
  }

  else if(m==1 && n>=2){
    std::cout << n-2 << '\n';
    return 0;
  }

  else std::cout << (n-2)*(m-2) << '\n';


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define swap(x,y) do{int t=y;y=x;x=t;}while(0)
using namespace std;

int n,ans;
int p[101000];

int main(){
  cin>>n;

  for(int i=1;i<=n;i++)
    cin>>p[i];

  for(int i=1;i<=n;i++){
    if(p[i]==i){
      if(i==1)
        swap(p[i],p[i+1]);
      else if(i==n)
        swap(p[i],p[i-1]);
      else{
        if(p[i]!=p[i+1])
          swap(p[i],p[i+1]);
        else
          swap(p[i],p[i-1]);
      }
      ans++;
    }
  }

  cout<<ans<<endl;

  return 0;
}
      

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        boolean[] b = new boolean[n+1];
        for(int i = 0; i < k; i++){
            int d = Integer.parseInt(sc.next());
            for(int j = 0; j < d; j++){
                b[Integer.parseInt(sc.next())] = true;
            }
        }
        int ans = 0;
        for(int i = 1; i <= n; i++){
            if(!b[i]) ans++;
        }
        System.out.println(ans);
    }
}

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

void Main()
{
  int N; cin >> N;
  vector<int> a(N);
  int div2 = 0, div4 = 0, nodiv = 0;
  rep(i,N) {
    cin >> a[i];
    if (a[i] % 2 != 0) nodiv++;
    else if (a[i] % 4 == 0) div4++;
    else div2++;
  }
  if (div2 > 0) {
    if (div4 >= 1 + nodiv - 1) cout << "Yes" << endl;
    else cout << "No" << endl;
  } else {
    if (div4 >= nodiv - 1) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 640
N,A,B = map(int, input().split())
H = [int(input()) for i in range(N)]

def check(X):
    """ X回以下の爆発で全滅するか """
    ans = 0
    for h in H:
        cnt = ((h - B * X) + (A - B) - 1) // (A - B)
        ans += max(0, cnt)
    return ans <= X

def main():
    ng = 0
    ok = 10 ** 10
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    print(ok)

if __name__ == "__main__":
    main()

Measured memory_bytes: 50008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll d[MAXn];
int main(){
  IOS();
  ll n;
  cin >> n;
  REP (i,n) cin >> d[i];
  sort(d,d+n);

  ll tg = d[n-1]/2;
  vector<ii> tmp;
  REP (i,n-1) (d[i] > tg ?tmp.eb(d[n-1]-d[i],1):tmp.eb(d[i],0));
  sort(ALL(tmp));
  cout << d[n-1] << ' ' << (tmp.back().Y ?d[n-1]-tmp.back().X:tmp.back().X) << endl;
}


Measured memory_bytes: 3188
N,M=map(int,input().split())
L=[]
ans=0

for i in range(N):
  L.append(list(map(int,input().split())))
  
L.sort(key=lambda x:x[0])
for l in L:
  if l[1]<=M:
    ans+=l[0]*l[1]
    M-=l[1]
  else:
    ans+=l[0]*M
    break

print(ans)

Measured memory_bytes: 29024
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.IOException;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] dice = br.readLine().split(" ");
		String roll = br.readLine();
		ArrayList<Integer> spotY = new ArrayList<Integer>();
		ArrayList<Integer> spotX = new ArrayList<Integer>();
		spotY.add(5); spotY.add(1); spotY.add(2); spotY.add(6);
		spotX.add(4); spotX.add(1); spotX.add(3); spotX.add(6);
		for (int i = 0; i < roll.length(); i++) {
			switch (roll.substring(i, i + 1)) {
			case "N":
				spotY.add(spotY.get(0));
				spotY.remove(0);
				spotX.set(1, spotY.get(1));
				spotX.set(3, spotY.get(3));
				break;
			case "E":
				spotX.add(0, spotX.get(3));
				spotX.remove(4);
				spotY.set(1, spotX.get(1));
				spotY.set(3, spotX.get(3));
				break;
			case "S":
				spotY.add(0, spotY.get(3));
				spotY.remove(4);
				spotX.set(1, spotY.get(1));
				spotX.set(3, spotY.get(3));
				break;
			case "W":
				spotX.add(spotX.get(0));
				spotX.remove(0);
				spotY.set(1, spotX.get(1));
				spotY.set(3, spotX.get(3));
				break;
			}
		}
		System.out.println(dice[spotX.get(1) - 1]);
	}
}

Measured memory_bytes: 24432
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void Yes(bool Yes){cout << (Yes ? "Yes" : "No") << endl;};
void YES(bool YES){cout << (YES ? "YES" : "NO") << endl;};


int main(){
    
    ll a, b, c;
    cin >> a >> b >> c;
    Yes(a <= c && c <= b);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const ll INFLL = 1001001001001001001;  // > 10^18
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {
    
    int n,t; cin >>n>>t;
    vector<int> a(n); rep(i,n) cin >> a[i];

    vector<ll> profit(n);
    int mn = INFLL;
    for (ll i = 0; i < n; i++) {
        mn = min(mn, a[i]);
        profit[i] = a[i] - mn;
    }

    sort(profit.begin(), profit.end(), greater<ll>());

    ll ans = 1;
    ll mp = profit[0];
    for (ll i = 1; i < n; i++) {
        if (profit[i] == mp) {
            ans++;
        } else {
            break;
        } 
    }

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


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

//main code
int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	VL a(n);
	cin >> a;
	map<LL,LL> mp;
	for (auto&& var : a) {
		mp[var]++;
	}
	int even=0;
	for (auto&& var : mp) {
		if (var.second%2==0) {
			even++;
		}
	}
	cout << mp.size() - (even&1) << endl;
	return 0;
}



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

#define int    long long

void fast()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}
//a^n O(log(n))

int power(int a, int n)
{
	int result = 1;
	while (n > 0)
	{
		if (n & 1)
		{
			result = result * a;
		}
		a = a * a;
		n = n >> 1;

	}
	return result;
}


bool compare(string &s1, string &s2)
{
	return s1.size() < s2.size();
}

int32_t main()
{
	fast();
	int n;
	cin >> n;
	vector<int> a(n);

	int cnt = 0;

	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		if (((i + 1) & 1) && (a[i] & 1))
		{
			//cout << i + 1 << '\n';
			cnt++;
		}
	}

	cout << cnt << '\n';

	return 0;
}


Measured memory_bytes: 3576
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

def sumi(i):
	return i * (i - 1) // 2

N = int(input())
mydict = {}

for i in range(N):
	s = input()
	l = list(s)
	l.sort()
	s = ''.join(l)
	#print(s)
	
	if s in mydict:
		mydict[s] += 1
	else:
		mydict[s] = 1
	
#print(mydict)
ans = 0

for i in mydict.values():
	ans += sumi(i)
	
print(ans)

Measured memory_bytes: 60776
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include "bitset"

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

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

const int N = 2e3 + 10, MX = 2e6 + N;

int a[N];
bitset <MX> b[2];

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}

	int sum = 0;
	b[0][0] = 1;
	for (int i = 1; i <= n; ++i) {
		b[i % 2] = b[!(i % 2)] | (b[!(i % 2)] << a[i]);
		sum += a[i];
	}

	for (int i = (sum + 1) / 2; ; ++i) {
		if (b[n % 2][i]) {
			cout << i << endl;
			break;
		}
	}
}

Measured memory_bytes: 1536
#include <cmath>
#include <iostream>
#include <map>
typedef long long ll;

using namespace std;

const int MAX = 210000;
const int MOD = 1e9 + 7;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    ll N, M;

    cin >> N >> M;

    map< ll, ll > prime;
    for (ll i = 2; i < sqrt(M) + 1; i++) {
        while (M % i == 0) {
            prime[i]++;
            M /= i;
        }
    }
    if (M > 1) {
        prime[M]++;
    }

    COMinit();
    ll ans = 1;
    for (auto x : prime) {
        ans = (ans * COM(x.second + N - 1, N - 1)) % MOD;
    }

    cout << ans << endl;
}

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

int main() {
    ll X, K, D;
    cin >> X >> K >> D;
    X = abs(X);
    ll ans;
    if ((X/D) > K) 
        ans = X - K * D;
    else {
        K -= X / D;
        X %= D;
        if (K % 2 == 0) {
            ans = X;
        } else {
            ans = - (X - D);
        }
    }   
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3540
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <algorithm>
#include <iomanip> //cout << fixed << setprecision(12) << ans << endl;
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define loop(i, l, r) for(int i = l; i < r; i++)
#define rloop(i, l, r) for(int i = l; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vec_i;
typedef pair<int,int> pair_ii;
typedef pair<ull,ull> pair_ull;
 
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int INF = 1e9;
const int MOD = 1e9+7;
 
int main()
{
	int a,b;
	cin >> a >> b;
	cout << (b-1+a-2)/(a-1) << endl;
}

Measured memory_bytes: 256
from collections import Counter, defaultdict, deque

class UnionFind(object):
    """Union find tree."""
    def __init__(self, nodes):
        self.par = list(range(nodes + 1))
        self.sizes = [1] * (nodes + 1)

    def root(self, key):
        if key != self.par[key]:
            k0 = key
            while k0 != self.par[k0]:
                k0 = self.par[k0]
            self.par[key] = k0
        return self.par[key]

    def merge(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra != rb:
            sa = self.sizes[ra]
            sb = self.sizes[rb]
            self.par[ra] = rb
            self.sizes[rb] += sa
            return sa * sb
        return 0

N, M = map(int, input().split())
AB = []
for _ in range(M):
    AB.append(list(map(int, input().split())))

uni = UnionFind(N)
comb = N * (N - 1) // 2
anses = [comb]
for a, b in AB[-1:0:-1]:
    red = uni.merge(a, b)
    comb -= red
    anses.append(comb)

for ans in reversed(anses):
    print(ans)

Measured memory_bytes: 37676
#include<bits/stdc++.h>
using namespace std;
int a[10000];
int n;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    sort(a+1,a+n+1);
    cout<<a[n]-a[1]<<endl;
}


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

int main()
{
 int a,b;
  cin >> a >> b;
  bool f= false;
  for (int i = 1; i <= 100000; i++)
  {
   if (floor(i*0.08) == a)
   {
     if (floor(i*0.1) == b){
       cout << i << endl;
       f = true;
       break;
     }
   }
  }
  if (!f)
    cout << -1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;

typedef pair <int, int> pii;

char buf[1000010];

bool cmp(pii a, pii b) {
	return max(-a.se, -a.fi - b.se) < max(-b.se, -b.fi - a.se);
}

int main () {
	int n; scanf("%d", &n);
	int tot = 0;
	vector <pii> p, q;
	for (int i = 0; i < n; i++) {
		scanf("%s", buf);
		int len = strlen(buf);
		int sum = 0, minj = 0;
		for (int i = 0; i < len; i++) {
			sum += buf[i] == '(' ? 1 : -1;
			minj = min(minj, sum);
		}
		tot += sum;
		if (sum >= 0) p.push_back(mp(minj, sum));
		else q.push_back(mp(sum, minj));
	}
	if (tot != 0) {
		printf("No\n");
		return 0;
	}
	sort(p.begin(), p.end());
	int sum = 0;
	while (p.size() && p.back().fi + sum >= 0) {
		sum += p.back().se;
		p.pop_back();
	}
	if (p.size()) {
		printf("No\n");
		return 0;
	}
	sort(q.begin(), q.end(), cmp);
	for (int i = 0; i < q.size(); i++) {
		if (sum + q[i].se < 0) {
			printf("No\n");
			return 0;
		}
		sum += q[i].fi;
	}
	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 11124
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*
    I LOVE CLARICE STARLING

     ♥LOVE♥        ♥LOVE♥
  ♥LOVE♥♥LOVE♥  ♥LOVE♥♥LOVE♥
♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥
   ♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥
      ♥LOVE♥♥LOVE♥♥LOVE♥
         ♥LOVE♥♥LOVE♥
            ♥LOVE♥
               ♥


    EXPLAINATION BELOW->
    1)From every lunlun number we can generate new 3 lunlun numbers ==>10x + (x mod 10) − 1,10x + (x mod 10),10x + (x mod 10) + 1
    But some lunlun numbers get repeated for example
    9=>98,99,100
    10=>99,100,101
    so rules come out like given in editorial
    2)We use Queue since it helps in maintaining the order
    3)We know the first 9 lunlun numbers
      
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
void solve()
{
  int k;cin>>k;
  queue<ll>Q;
  ll i,element;
  foe(i,1,9)Q.push(i);
  while(k--)
  {
      element=Q.front();Q.pop();
      if(element%10!=0)Q.push(10*element+element%10-1);
      Q.push(10*element+element%10);
      if(element%10!=9)Q.push(10*element+element%10+1);
  }
  cout<<element<<"\n";
  
  
}
int main()
{
   fastio
   solve();
  return 0;
}
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/


Measured memory_bytes: 1792
N = int(input())

A = [int(input()) for i in range(N)]

A.sort()

right = A[0]
left = A[0]
index_l = 1
index_r = len(A)-1
ans_l = 0
count = 1
while(1):
	if count % 2 == 1:
		if index_r - index_l >= 1:
			if abs(left-A[index_r])+abs(right-A[index_r-1]) > abs(right-A[index_r])+abs(left-A[index_r-1]):
				ans_l += abs(left-A[index_r])+abs(right-A[index_r-1])
				left = A[index_r]
				right = A[index_r-1]
			else:
				ans_l += abs(right-A[index_r])+abs(left-A[index_r-1])
				left = A[index_r-1]
				right = A[index_r]
			index_r -= 2
		elif index_r - index_l == 0:
			if abs(left-A[index_r]) > abs(right-A[index_r]):
				ans_l += abs(left-A[index_r])
			else:
				ans_l += abs(right-A[index_r])
			index_r -= 1
		else: break
	else:
		if index_r - index_l >= 1:
			if abs(left-A[index_l])+abs(right-A[index_l+1]) > abs(right-A[index_l])+abs(left-A[index_l+1]):
				ans_l += abs(left-A[index_l])+abs(right-A[index_l+1])
				left = A[index_l]
				right = A[index_l+1]
			else:
				ans_l += abs(right-A[index_l])+abs(left-A[index_l+1])
				left = A[index_l+1]
				right = A[index_l]
			index_l += 2
		elif index_r - index_l == 0:
			if abs(left-A[index_r]) > abs(right-A[index_r]):
				ans_l += abs(left-A[index_r])
			else:
				ans_l += abs(right-A[index_r])
			index_l += 1
		else:
			break
	count += 1

A.reverse()

right = A[0]
left = A[0]
index_l = 1
index_r = len(A)-1
ans_r = 0
count = 1
while(1):
	if count % 2 == 1:
		if index_r - index_l >= 1:
			if abs(left-A[index_r])+abs(right-A[index_r-1]) > abs(right-A[index_r])+abs(left-A[index_r-1]):
				ans_r += abs(left-A[index_r])+abs(right-A[index_r-1])
				left = A[index_r]
				right = A[index_r-1]
			else:
				ans_r += abs(right-A[index_r])+abs(left-A[index_r-1])
				left = A[index_r-1]
				right = A[index_r]
			index_r -= 2
		elif index_r - index_l == 0:
			if abs(left-A[index_r]) > abs(right-A[index_r]):
				ans_r += abs(left-A[index_r])
			else:
				ans_r += abs(right-A[index_r])
			index_r -= 1
		else: break
	else:
		if index_r - index_l >= 1:
			if abs(left-A[index_l])+abs(right-A[index_l+1]) > abs(right-A[index_l])+abs(left-A[index_l+1]):
				ans_r += abs(left-A[index_l])+abs(right-A[index_l+1])
				left = A[index_l]
				right = A[index_l+1]
			else:
				ans_r += abs(right-A[index_l])+abs(left-A[index_l+1])
				left = A[index_l+1]
				right = A[index_l]
			index_l += 2
		elif index_r - index_l == 0:
			if abs(left-A[index_r]) > abs(right-A[index_r]):
				ans_r += abs(left-A[index_r])
			else:
				ans_r += abs(right-A[index_r])
			index_l += 1
		else:
			break
	count += 1

		
print(max(ans_l,ans_r))

Measured memory_bytes: 7512
# D dijkstra
N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N-1):
    ai,bi,ci = map(int, input().split())
    edge[ai-1].append((bi-1, ci))
    edge[bi-1].append((ai-1, ci))
Q,K = map(int, input().split())
K = K-1
x,y = [],[]
for _ in range(Q):
    xi,yi = map(int, input().split())
    x.append(xi-1)
    y.append(yi-1)


dist = [float('inf') for _ in range(N)]
import heapq
def dijkstra(start:int):
    """priority_queue ver. O(|E|log|V|)
    """
    global dist # list dist[|V|]
    global edge # 隣接リスト
    dist[start] = 0
    q = [(0,start)] # （暫定的な距離，頂点）
    while q:
        d_cur,cur = heapq.heappop(q)
        if dist[cur] < d_cur:
            continue
        for nex,cost in edge[cur]:
            if dist[nex] > dist[cur]+cost:
                dist[nex] = dist[cur]+cost
                heapq.heappush(q, (dist[nex], nex))


dijkstra(K)
for xi,yi in zip(x,y):
    print(dist[xi] + dist[yi])

Measured memory_bytes: 54188
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<cmath>

using namespace std;

const int MAXN = 200005;
const int INF = 1000000007;

int n, ind;
int lef[MAXN], rig[MAXN], dp[MAXN], mini[MAXN], suf[MAXN], pot[MAXN];
pair <int, int> pii[MAXN], l[MAXN];
set <int> s;

int add (int a, int b) {
    if (a+b>=INF) return a+b-INF; return a+b;
}

int sub (int a, int b) {
    if (a-b<0) return a-b+INF; return a-b;
}

int main () {
    pot[0]=1;
    cin >> n;
    for (int i=0; i<n; i++) {
        pot[i+1]=add(pot[i], pot[i]);
        mini[i]=INF;
        int xx, vv;
        scanf("%d%d", &xx, &vv);
        pii[i]=make_pair(xx, vv);
    }
    sort(pii, pii+n);
    for (int i=0; i<n; i++) {
        l[i]=make_pair(pii[i].second, i);
    }
    sort(l, l+n);
    ind=-INF;
    for (int i=0; i<n; i++) {
        ind=max(ind, l[i].second);
        rig[i]=ind;
    }
    ind=INF;
    for (int i=n-1; i>=0; i--) {
        ind=min(ind, l[i].second);
        lef[i]=ind;
    }
    for (int i=0; i<n; i++) {
        mini[lef[i]]=min(mini[lef[i]], rig[i]);
    }
    dp[n]=suf[n]=1, ind=INF;
    for (int i=n-1; i>=0; i--) {
        ind=min(ind, mini[i]);
        if (ind==INF) {
            dp[i]=pot[n-i];
        } else {
            dp[i]=sub(suf[i+1], suf[ind+2]);
        }
        suf[i]=add(suf[i+1], dp[i]);
    }
    cout << dp[0];
    return 0;
}



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

int main(int argc, char const* argv[]) {
  string s;
  cin >> s;
  if (s[0] == 'S')
    cout << "Cloudy" << endl;
  else if (s[0] == 'C')
    cout << "Rainy" << endl;
  else
	  cout << "Sunny" << endl;

  return 0;
}


Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))

l=[0]+l+[0]

x=0
for i in range(n+1):
    x += abs(l[i]-l[i+1])

for i in range(1,n+1):
    print(x + abs(l[i+1]-l[i-1]) - abs(l[i]-l[i-1]) - abs(l[i+1]-l[i]))

Measured memory_bytes: 14048
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	n, m, x := scanInt(), scanInt(), scanInt()
	c := make([]int, n)
	a := make([][]int, n)
	for i := 0; i < n; i++ {
		c[i] = scanInt()
		a[i] = make([]int, m)
		for j := range a[i] {
			a[i][j] = scanInt()
		}
	}

	ans := math.MaxInt64
	for i := 1; i < 1<<uint(n); i++ {
		csum := 0
		asum := make([]int, m)
		for j := 0; j < n; j++ {
			if b := 1 << uint(j); i&b == b {
				csum += c[j]
				for k := range a[j] {
					asum[k] += a[j][k]
				}
			}
		}

		isOver := true
		for _, av := range asum {
			if av < x {
				isOver = false
				break
			}
		}
		if isOver {
			ans = min(ans, csum)
		}
	}
	if ans == math.MaxInt64 {
		fmt.Println(-1)
	} else {
		fmt.Println(ans)
	}
}


Measured memory_bytes: 2160
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long 
#define int long long 
#define vll vector<long long>
#define pii pair<long long ,long long > 
#define vvi vector< vector<long long > > 
#define vpii vector<pair<int,int>> 
#define pll  pair<long long ,long long > 
#define pb  push_back
#define ff  first 
#define sec second  
#define SORT(a) sort(a.begin(),a.end())
#define SORTR(a) sort(a.rbegin(),a.rend()) 
#define m_p make_pair
#define all(x) (x.begin(),x.end()) 
#define sz(v) ((int)(v.size()))
#define endl '\n'
typedef vector< long long > vi ;
const int MOD=1e9 +7 ;
int size=10000000; 
 
int32_t main(){
  fast; 
 /* #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif 
	*/


  int T=1; //cin>>T; 
  while(T--){

  		string s; string t; 
  		cin>>s; cin>>t; 
  		int n=s.length(); 
  		int m=t.length(); 

  		vector< vi > dp(n+1,vi(m+1)); 
  		vector< vi > path(n+1,vi(m+1)); 

  		for(int i=0;i<=n;i++){
  			for(int j=0;j<=m;j++){

  				if(i==0 || j==0) { dp[i][j]=0; continue; }  

  				if(s[i-1]==t[j-1]){
  					dp[i][j]=dp[i-1][j-1]+1; 
  					path[i][j]=3; 
  				}
  				else if(dp[i-1][j]>dp[i][j-1]){
  					dp[i][j]=dp[i-1][j]; 
  					path[i][j]=2; 
  				}
  				else{
  					dp[i][j]=dp[i][j-1];
  					path[i][j]=1;  
  				}

  			}
  		}

  		string ans=""; int start=m;  
  		for(int i=n;i>=1;i--){
  			for(int j=start;j>=1;j--){

  				if(path[i][j]==3){
  					ans+=s[i-1];
  					start=j-1;  
  					break;  
  				}
  				else if(path[i][j]==2){
  					start=j; 
  					break; 
  				}
  			}
  		}

  		//debug(path); 
  		/*for(int i=0;i<=n;i++){
  			for(int j=0;j<=m;j++){
  				cout<<path[i][j]<<" "; 		
  			}
  			cout<<endl; 
  		}*/
  		reverse(ans.begin(),ans.end()); 
  		cout<<ans<<endl; 



  }
    


  return 0; 
} 


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

int main(){
  long long a,b,c,d;
  cin >> a >> b >> c >> d;
   
  long long divc = b/c - (a-1)/c;
  long long divd = b/d - (a-1)/d;
  
  long long lcm = c*d;
  if(c > d)swap(c,d);
  for(long long i = 1;i*i <= c;i++){
    if(c%i == 0 && d%i == 0)lcm = min(lcm,(c*d)/i);
    if(d%(c/i) == 0 && c%i == 0)lcm = min(lcm,(c*d)/(c/i));
  }
  long long divl = b/lcm - (a-1)/lcm;
  
  cout << (b - a + 1) - (divc + divd - divl) << endl;
}
  


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

namespace _0642
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int ret = 1; int count = 1;
            for (int i = 0; i < n; i++)
            {
                if (x[i] == 1)
                {
                    count++;
                    ret = Math.Max(ret, count);
                }
                else count = 1;
            }
            Console.WriteLine(ret);
        }
    }
}


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

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  --a, --b, --c, --d;
  string t;
  cin >> t;
  auto reachable = [&](int s, int f) {
    if (t[s] == '#' || t[f] == '#') return false;
    for (int i = s + 1; i <= f; ++i) {
      if (t[i] == t[i - 1] && t[i] == '#') {
        return false;
      }
    }
    return true;
  };
  auto hasg3 = [&](int s, int f) {
    for (int i = s; i <= f - 2; ++i) {
      if (t[i] == t[i + 1] && t[i] == t[i + 2] && t[i] == '.') {
        return true;
      }
    }
    return false;
  };
  bool can = true;
  if (!reachable(a, c) || !reachable(b, d)) {
    can = false;
  }
  if (c > d) {
    if (!hasg3(b - 1, d + 1)) {
      can = false;
    }
  }
  cout << (can ? "Yes" : "No") << endl;
  return 0;
}


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

// #define int long long // intで書いたけど心配なときにlong longに変換する
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << endl;}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}


signed main() {
    //my-code
    int R; cin >> R;
    cout << fixed;
    cout << setprecision(12) << 2*R*1.0*3.1415926535 << endl;

    return 0;
}

// https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて
// http://www.creativ.xyz/dump-cpp-652 dump()について
// https://gist.github.com/rigibun/7905920 色々

Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int>P;
#define PI 3.14159265359
#define MOD 1000000007

int main(){
  int N,flag=0;
  cin >>N;
  vector<P>memo(N);
  rep(i,N){
    int a,b;
    cin >>a>>b;
    memo[i]=P(b,a);
  }
  sort(memo.begin(),memo.end());
  ll time=0;
  rep(i,N){
  	auto t=memo[i];
    int a=t.second,b=t.first;
    time+=a;
    if(time>b){flag=1;break;}
  }
  if(flag){cout<<"No";}
  else{cout<<"Yes";}
}

Measured memory_bytes: 1792
import java.io.*;
import java.util.Scanner;

public class Main {

// JAG Team Coding Source

	public static void main(String[] args) {
//		System.setOut(new PrintStream(new File("result.txt")));
		Scanner stdIn = new Scanner(System.in);
		
		while(true){
			int n = stdIn.nextInt();
			if(n==0){
				return;
			}
			int[][] know = new int[n+1][];
			for(int i=1;i<=n;i++){
				int m = stdIn.nextInt();
				know[i] = new int[m+1];
				for(int j=1;j<=m;j++){
					know[i][j] = stdIn.nextInt();
				}
			}
			int k = stdIn.nextInt();
			int[] lost = new int[k];
			for(int i=0;i<k;i++){
				lost[i] = stdIn.nextInt();
			}
			// Solve
			int ans = -1;
			for(int i=1;i<=n;i++){
				int cnt = 0;
				for(int j=0;j<k;j++){
					boolean flag = false;
					for(int m=1;m<know[i].length;m++){
						if(lost[j]==know[i][m]){
							flag = true;
							break;
						}
					}
					if(flag){
						cnt++;
						if(cnt==k){
							break;
						}
					}
				}
				if(cnt==k){
					if(ans==-1){
						ans = i;
					}
					else{
						ans = -1;
						break;
					}
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 13000