akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define endl "\n"


ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
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;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
class segment_tree{
  private:
    ll N = 1;
    vector<ll> data;
    ll def = 0;
  public:

    segment_tree(vector<ll> vec){
      ll m = vec.size();
      while(N < m) N *= 2;
      data.resize(2*N, def);

      for(int i=0;i<m;i++) update(i,vec[i]);
    }

    void update(ll k, ll a){
      k += N - 1;
      data[k] += a;
      while(k > 0){
        k = (k-1) / 2;
        data[k] = data[k * 2 + 1] +  data[k * 2 + 2];
      }
    }

    // [a,b) のクエリを処理する
    int query_(ll a, ll b, ll k, ll l, ll r){
      // [a,b)　と [l,r) が交差しない時
      if(r <= a || b <= l) return def; 

      // 完全に含まれている時
      if(a <= l && r <= b) return data[k];
      else{
        ll mid = (l + r) / 2;
        // 2つの子の最小値
        ll vl = query_(a,b,k*2+1,l,mid);
        ll vr = query_(a,b,k*2+2,mid,r);
        return (vl + vr);
      }
    }

    int query(ll a, ll b){
      return query_(a, b, 0, 0, N);
    }
};

//-----------------------------------------

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

  ll n;
  cin >> n;
  vll v(n,0);
  segment_tree tree(v);
  ll q;
  cin >> q;
  REP(i,q){
    ll com;
    cin >> com;
    if(com == 0){
      ll x, y;
      cin >> x >> y;
      tree.update(x-1,y);
    }
    else{
      ll x, y;
      cin >> x >> y;
      cout << tree.query(x-1,y) <<endl;
    }
  }

  return 0;
}




Measured memory_bytes: 6512
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using mat = vector<vector<ll>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int N; cin >>N;
  vector<vector<int>> a(2, vector<int>(N, 0));
  rep(i, 2) rep(j, N) cin >>a[i][j];
  vector<vector<int>> dp(2, vector<int>(N, 0));
  dp[0][0] = a[0][0];
  dp[1][0] = dp[0][0] + a[1][0];
  for (int j=1; j<N; j++){
    dp[0][j] = dp[0][j-1] + a[0][j];
    dp[1][j] = max(dp[0][j], dp[1][j-1]) + a[1][j];
  }
  int res = dp[1][N-1];
  cout <<res <<endl;
}


Measured memory_bytes: 256
// The moment you think of giving up you have already lost the battle
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
typedef long double dl;
#define PI  3.14159265358979323846
#define M   1000000007
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll r=fast(n/2,a,m);
        if(n%2==0)
        {
            return (((r%m)*(r%m))%m);
        }
        else
        {
            return (((((r%m)*a)%m)*r)%m);
        }

    }
}
int main()
{
    ll n,i;
    cin>>n;
    ll A[n];
    for(i=0;i<n;i++)
    {
        cin>>A[i];
    }
    ll pref[n+1];
    pref[0]=0;
    for(i=1;i<=n;i++)
        pref[i]=(pref[i-1]%M+A[i-1]%M)%M;

    ll ans=0;
    for(i=1;i<=n-1;i++)
    {
        ll d=pref[n]-pref[i];
        if(d<0)
        {
            d+=M;
            d%=M;
        }
        d=((d%M)*(A[i-1]%M))%M;
        ans=(ans%M+d%M)%M;
    }
    cout<<ans;

}


Measured memory_bytes: 6760
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
      	int t = 0;
      	int x = 0;
      	int y = 0;
 
      for (int i=0; i<N; i++) {
        int T = sc.nextInt();
        int X = sc.nextInt();
        int Y = sc.nextInt();
        
        int dt = T - t;
        int dist = Math.abs(X - x) + Math.abs(Y - y);
        if ((dist > dt) || ((dist - dt) % 2 != 0)) {
          System.out.println("No");
          return;
        }
        //移動した場所を設定
        t = T;
        x = X;
        y = Y;
      }
      System.out.println("Yes");
    }
}

Measured memory_bytes: 83840
import java.io.*;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		
		int n = Integer.parseInt(br.readLine().toString());
		int i = 1;
		int x;
		
		do {
			x = i;
			
			if (x % 3 == 0) {
				sb.append(" ").append(i);
				if ((i + 1) <= n) continue;
			} else {
				do {
					if (x % 10 == 3 || String.valueOf(x).matches(".*[3].*")) sb.append(" ").append(i);
					if ((i + 1) <= n) break;
					
					x /= 10;
					
					if (x == 0) {
						continue;
					} else {
						break;
					}
				} while (true);
			}
		} while (++i <= n);
		
		System.out.println(sb);
	}
}

Measured memory_bytes: 37720
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>//cout << fixed からの cout << setprecision(n) << 小数　によって小数を整数部分含めてn桁表示できるようにする
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
  int m,f,r;
  while(1){
  cin >> m >> f >> r;
  if(m == -1 && f == -1 && r == -1) break;
  if(m == -1 || f == -1 || m + f < 30){
    cout << 'F' << endl;
  }else if(m + f >= 80){
    cout << 'A' << endl;
  }else if(m + f >= 65){
    cout << 'B' << endl;
  }else if(m + f >= 50){
    cout << 'C' << endl;
  }else if(r >= 50){
    cout << 'C' << endl;
  }else{
    cout << 'D' << endl;
  }
  }
  return 0;
}



Measured memory_bytes: 3100
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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

ll N,K,cnt;

int main(){
    cin>>N>>K;
    if(K>(((N-1)*(N-2))/2))out("-1");
    else{
        out(N-1+(((N-1)*(N-2))/2)-K);
        rep(i,N-1){
            cout<<1<<" "<<i+2<<endl;
        }
        cnt=(((N-1)*(N-2))/2)-K;
        ll i=2;
        ll j=3;
        while(cnt){
            if(j>N){
                i++;
                j=i+1;
            }
            cout<<i<<" "<<j<<endl;
            j++;
            cnt--;
        }
    }


    
    
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include <string.h>

int main(void)
{
	int b;
	int a[4];

	scanf("%d", &b);

	a[0] = b /1000;
	b = b-a[0]*1000;
	a[1] = b /100;
	b = b-a[1]*100;
	a[2] = b /10;
	b = b-a[2]*10;
	a[3] = b;


	if(a[0] == a[1] || a[1] == a[2] || a[2] == a[3]){
		printf("Bad");
	} else{
		printf("Good");
	}

	return 0;
}

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

#define Sort(x) sort(x.begin(), x.end())
#define Sort_rev(x) sort(x.begin(), x.end(), greater<int>())
#define ll long long

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 1;
    for (int i = 0; i < n-1; ++i) {
        if ( s[i] != s[i+1]) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <complex>
#include <assert.h>

using namespace std;

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

static const double EPS = 1e-12;

typedef complex<double> Point;

namespace std {
  bool operator < (const Point& a, const Point& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}

double cross(const Point& a, const Point& b) {
  return imag(conj(a)*b);
}
double dot(const Point& a, const Point& b) {
  return real(conj(a)*b);
}

struct Line : public vector<Point> {
  Line(const Point &a, const Point &b) {
    push_back(a); push_back(b);
  }
};

int ccw(Point a, Point b, Point c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

bool intersectSS(const Line &s, const Line &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
    ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

Point crosspoint(const Line &l, const Line &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
  if (abs(A) < EPS) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
  return m[0] + B / A * (m[1] - m[0]);
}

double compute_area(const Point &l,const Point &m){
  return abs(cross(l,m)) / 2.0;
}

bool is_equal(const Point &l,const Point &m){
  return ((abs(real(l) - real(m)) < EPS) && (abs(imag(l) - imag(m) < EPS)));
}

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

    vector<Line> lines;
    lines.push_back(Line(Point(-100, 100),
                         Point(100, 100)));
    lines.push_back(Line(Point(100, 100),
                         Point(100, -100)));
    lines.push_back(Line(Point(100, -100),
                         Point(-100, -100)));
    lines.push_back(Line(Point(-100, -100),
                         Point(-100, 100)));
    int res = 1;
    for(int i = 0; i < n; i++){
      double x[2],y[2];
      scanf("%lf %lf %lf %lf",&x[0],&y[0],&x[1],&y[1]);
      lines.push_back(Line(Point(x[0],y[0]),Point(x[1],y[1])));

      vector<Point> points;
      for(int i = 0; i < lines.size() - 1; i++){
        if(intersectSS(lines[lines.size()-1],lines[i])){
          Point candidate = crosspoint(lines[lines.size()-1],lines[i]);
          if(abs(candidate.real()) > 100.0
             || abs(candidate.imag()) > 100.0) continue;
          for(int j = 0; j < points.size(); j++){
            if(abs(candidate - points[j]) < EPS) goto next;
          }
          points.push_back(candidate);
        next:;
        }
      }
      
      res += points.size() - 1;
    }
    
    printf("%d\n",res);
  }
}

Measured memory_bytes: 1264
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef pair < ll,ll > pii;
ll n,m;
const ll maxn=1e5+100;
vector < pii > ve;
ll sz[maxn],a[maxn],b[maxn],fa[maxn],dep[maxn];
void myinit(){
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for (ll i=1;i<=m;i++){
		cin >> a[i] >> b[i];
	}
	for (ll i=1;i<=n;i++) fa[i]=i;
	for (ll i=1;i<=n;i++) sz[i]=1;
	for (ll i=1;i<=n;i++) dep[i]=1;
}
ll father(ll x){
	if (fa[x]==x) return x;
	else return father(fa[x]);
}
pii unionn(ll x,ll y){
	if (x==y) return mp(x,y);
	if (dep[x]<=dep[y]){
		if (dep[x]==dep[y]) dep[y]++;
		sz[y]+=sz[x];
		fa[x]=y;
		return mp(x,y);
	}else{
		fa[y]=x;
		sz[x]+=sz[y];
		return mp(y,x);
	}
}
ll ans=0;
void disunionn(ll x,ll y){
	fa[x]=x;
	sz[y]-=sz[x];
	ans+=sz[x]*sz[y];
}
void solve(){
	myinit();
	for (ll i=m;i>=1;i--){
		ve.push_back(unionn(father(a[i]),father(b[i])));
//		for (int j=1;j<=n;j++) cout << sz[j] << ' ';
//		cout << endl;
	}
//	for (int i=0;i<m;i++){
//		cout << ve[i].fi << ' ' << ve[i].se << endl;
//	}
	for (ll i=m-1;i>=0;i--){
		if (ve[i].fi!=ve[i].se) disunionn(ve[i].fi,ve[i].se);
		cout << ans << endl;
	}
}
int main(){
	solve();
	return 0;
}


Measured memory_bytes: 6896
import pdb


def main():
    num = int(input())

    ans = ""
    
    if num == 25:
        ans = "Christmas"
    elif num == 24:
        ans = "Christmas Eve"
    elif num == 23:
        ans = "Christmas Eve Eve"
    elif num == 22:
        ans = "Christmas Eve Eve Eve"
        
    print(ans)

        
if __name__ == '__main__':
    main()


Measured memory_bytes: 5680
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] pList = new int[n];

        for (int i = 0; i < n ; i++) {
            pList[i] = sc.nextInt();
        }

        double ans = 0;

        for (int i = 0; i < k; i++) {
            ans +=  1 + (((double)pList[i] - 1) * 0.5);
        }
        double lastV = ans;

        for (int i = 1; i <= n - k ; i++) {
            double sum = lastV;
            sum -= (1 + (((double)pList[i - 1] - 1) * 0.5));
            sum += (1 + (((double)pList[i + k - 1] - 1) * 0.5));
            ans = Math.max(ans, sum);
            lastV = sum;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 66664
def warshall_floyd(c,d):
    #d[i][j]: iからjへの最短距離
    for i in range(10):
        for j in range(10):
            for k in range(10):
              c[j][k] = min(c[j][k],c[j][i] + c[i][k])
              if k == 1:
                  d[j] = c[j][k]
    return d

H,W = map(int,input().split())
c = [list(map(int,input().split())) for _ in range(10)]
A = [list(map(int,input().split())) for _ in range(H)]
d_list = [0]*10 
ans = 0
warshall_floyd(c,d_list)

for i in range(H):
    for j in range(W):
        if A[i][j] != -1:
            ans += d_list[A[i][j]]
 
print(ans)

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

int ctoi(char c) {
	return c-'0';
}

int main(){
    string s; cin>>s;
    int a=0,b=0;
    string ans;
    a+=ctoi(s[0])*10;
    a+=ctoi(s[1]);
    b+=ctoi(s[2])*10;
    b+=ctoi(s[3]);
    if(a==0){
        if(b==0)ans="NA";
        else if(13<=b)ans="NA";
        else ans="YYMM";
    }else if(13<=a){
        if(b==0)ans="NA";
        else if(13<=b)ans="NA";
        else ans="YYMM";
    }else{
        if(b==0)ans="MMYY";
        else if(13<=b)ans="MMYY";
        else ans="AMBIGUOUS";
    }
    cout<<ans<<endl;
    return 0;  
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		double[] v = new double[N];
		for( int i=0; i<N; i++ ){
			v[i] = sc.nextDouble();
		}
		Arrays.sort(v);
		for( int i=1; i<N; i++ ){
			v[i] = (v[i]+v[i-1])/2;
		}
		System.out.println(v[N-1]);
	}
}


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

#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ll long long
#define ld long double
#define pb push_back
#define MOD 1000000007
#define LLMN LONG_LONG_MIN
#define LLMX LONG_LONG_MAX
#define LDMX LDBL_MAX
#define LDMN LDBL_MIN
#define MAX 1000000

ll mulmod(ll, ll);
ll fastpower(ll, ll);
void getprime(vector<ll>&);
void getfact(vector<ll>&, vector<ll>&);
ll ncr(ll, ll, vector<ll>&, vector<ll>&);


void solve()
{
    ll n, m, res =0;
    cin>>n>>m;
    vector<ll>a(n);
    for(ll i=0;i<n;i++) cin>>a[i];
    sort(all(a));
    for(ll i=0;i<m && i<n;i++)
        res += a[i];
    cout<<res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll t = 1;
    //cin>>t;
    while(t--)
    {
        solve();        
    }
    return 0;
}

ll mulmod(ll a, ll b)
{
    ll res = 0; 
    a = a % MOD;
    while(b > 0)
    {
        if (b % 2 == 1)
            res = (res + a) % MOD;
 
        a = (a * 2) % MOD; 
        b /= 2;
    } 
    return res % MOD; 
}

ll  fastpower(ll a, ll n)
{
    ll res = 1;
    while(n > 0)
    {
        if(n % 2 != 0)
        {
            res = (res * a) % MOD;
        }
        n /= 2;
        a = (a * a) % MOD;
    }
    return res;
}

void getprime(vector<bool>&prime)
{
    prime[0] = false;
    prime[1] = false;
    
    for(ll i = 2;i <= MAX; i++)
    {
        if(prime[i])
        {
            for(ll j = i*i; j <= MAX; j += i)
                prime[j] = false;
        }
    }
}

void getfact(vector<ll> &fact, vector<ll> &ifact)
{
    fact[0] = 1;
    ifact[0] = 1;
    
    for(ll i = 1; i <= MAX; i++)
    {
        fact[i] = (fact[i-1] * i)%MOD;
        ifact[i] = (ifact[i-1] * fastpower(i, MOD -2) )%MOD;
    }
}

ll ncr(ll n, ll r, vector<ll>&fact, vector<ll>&ifact)
{
    ll res;
    res = (((fact[n] * ifact[r]) % MOD) * ifact[n-r]) % MOD;
    return res;
}


Measured memory_bytes: 3640
#include <iostream>

 

using namespace std;

 

int main() 
{
    int a, b, c, i, ans;
    cin >> a >> b >> c;
    ans = 0;
    for(i=a; i<=b; i++)
    {
        if(c % i == 0)
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3112
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in)) {
      while (true) {
        int n = sc.nextInt();
        if (n == 0) { break; }
        int[] scores = new int[n];
        for (int i = 0; i < scores.length; i++) {
          scores[i] = sc.nextInt();
        }
        double average = 0, variance = 0;
        for (int i=0; i < n; i++) average += scores[i];
        average /= n;
        for (int i=0; i < n; i++) variance += (scores[i] - average) * (scores[i] - average);
        variance /= n;
        System.out.println(Math.sqrt(variance));
      }
    }
  }
}



Measured memory_bytes: 30940
s=list(input())
flag=True
for i in range(1,len(s)+1):
    v=s[i-1]
    if i%2==0:
        if v=="L" or v=="U" or v=="D":
            pass
        else:
            flag=False
            break
    else:
        if v=="R" or v=="U" or v=="D":
            pass
        else:
            flag=False
            break
if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <cstdio>

int main()
{
  int h, w, n;
  scanf("%d%d%d", &h, &w, &n);
  int a[10000];
  for (int i = 0; i < n; ++i)
  {
    scanf("%d", a + i);
  }
  int col = 1;
  int f[100][100];
  for (int i = 0; i < h * w; ++i)
  {
    int y = i / w;
    int x = i % w;
    f[y][y & 1 ? w - 1 - x : x] = col;
    if (--a[col - 1] == 0)
    {
      ++col;
    }
  }
  
  for (int i = 0; i < h; ++i)
  {
    for (int j = 0; j < w; ++j)
    {
      printf("%d ", f[i][j]);
    }
    putchar('\n');
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)


int main() {
   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   int n;
   cin >> n;
   vector<pair<int , int> > a(n);
   for(int i = 0 ; i < n ; ++i){
      cin >> a[i].first;
      a[i].second = i + 1;
   }
   sort(all(a));
   for(auto x : a)
      cout << x.second << ' ';
   cout << "\n";
}

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


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    long long n, m;
    cin >> n >> m;
    long long x = n / 500;
    n %= 500;
    if(m >= n){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
}


Measured memory_bytes: 764
import sys
from bisect import bisect_left, bisect_right

n = int(sys.stdin.buffer.readline())
a = list(map(int, sys.stdin.buffer.readline().split()))
b = list(map(int, sys.stdin.buffer.readline().split()))
c = list(map(int, sys.stdin.buffer.readline().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for j in b:
    ans += (n - bisect_right(c, j))*bisect_left(a, j)
print(ans)

Measured memory_bytes: 27624
import java.util.Scanner;
      
class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    while(true){
      String strin = sc.next();
      if(strin.equals("-")){
        break;
      }
      String str[] = new String[strin.length()];
      for(int i = 0; i < strin.length(); i++){
        str[i] = "";
      }
   
      for(int x = 0; x < strin.length(); x++){
        for(int y = x; y < strin.length(); y++){
          char c = strin.charAt(y);
          str[x] += c;
        }
        for(int z = 0; z < x; z++){
          char c = strin.charAt(z);
          str[x] += c;
        }
      }
      
      int m = sc.nextInt();
      int t = 0;
      for(int x = 0; x < m; x++){
        int h = sc.nextInt();
        t += h;
      }
      System.out.println(str[t%strin.length()]);
    }
  }
}


Measured memory_bytes: 59124
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll mod = 1e9+7;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  int h,w;
  cin >> h >> w;
  vector<string> m(h);
  for(int i = 0; i < h; ++i) cin >> m[i];
  vector<vector<ll>> cnt(h,vector<ll>(w));
  cnt[0][0] = 1;
  for(ll i = 0; i < h; ++i){
    for(ll j = 0; j < w; ++j){
      if(m[i][j] == '#') continue;
      if(j > 0) cnt[i][j] = cnt[i][j-1];
      if(i > 0) cnt[i][j] = (cnt[i][j]+cnt[i-1][j])%mod;
    }
  }
  cout << cnt[h-1][w-1];
  return 0;
}

Measured memory_bytes: 12148
from collections import deque
k = int(input())

def bfs():
    q = deque([1,2,3,4,5,6,7,8,9])
    cnt = 0
    while q:
        num = q.popleft()
        cnt += 1
        if cnt == k:
            return num
        else:
            if str(num)[-1] == "0":
                q.append(num*10)
                q.append(num*10+1)
            elif str(num)[-1] == "9":
                q.append(num*10+8)
                q.append(num*10+9)
            else:
                q.append(num*10+int(str(num)[-1])-1)
                q.append(num*10+int(str(num)[-1]))
                q.append(num*10+int(str(num)[-1])+1)


print(bfs())


Measured memory_bytes: 12004
<?php
fscanf(STDIN, "%d", $n);

$gacha = array();
$count = 0;
for ($i=0; $i < $n; $i++) {
  fscanf(STDIN, "%s", $s);

  if (!isset($gacha[$s])) {
    $gacha[$s] = $s;
    $count++;
  }
}

echo $count;


Measured memory_bytes: 32064
#include <bits/stdc++.h>
    #define rep(i,n) for(int i = 0; i < (n); i++)
     
    using namespace std;  
    
    int main() {
    int count = 1;
    
     while(true){
     int x;
     cin >> x;
     
     if(x!=0){
      cout << "Case " << count <<": "<< x << '\n';
      count++;
      } else{
      
       return 0;
      
      }
      
     }
     return 0;
    }


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define ull unsigned long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) (int)(x).size()
using namespace std;

const int N = 1007;
const int X = 5007;

int n;

VI G[N];

bool dp[N][X];
int ple[2][N][X];
int x[N];

void dfs(int v)
{
	memset(ple[0][v], inf16, sizeof ple[0][v]);
	memset(ple[1][v], inf16, sizeof ple[1][v]);
	ple[0][v][0] = 0;

	int curr = 0, d = 0;

	for(auto it:G[v])
	{
		dfs(it);

		for(int i = X-1; i >= 0; --i)
		{
			if(dp[it][i])
			{
				for(int j = curr; j >= 0; --j)
				{
					ple[d^1][v][min(j+i, X-1)] = min(ple[d^1][v][min(j+i, X-1)], ple[d][v][j]+x[it]);

					if(ple[d^1][v][min(j+i, X-1)]<=x[v])
						curr = max(curr, min(j+i, X-1));

					ple[d^1][v][min(j+x[it], X-1)] = min(ple[d^1][v][min(j+x[it], X-1)], ple[d][v][j]+i);

					if(ple[d^1][v][min(j+x[it], X-1)]<=x[v])
						curr = max(curr, min(j+x[it], X-1));
				}
			}
		}

		memset(ple[d][v], inf16, sizeof ple[d][v]);
		d ^= 1;
	}

	for(int i = 0; i < X; ++i)
	{
		if(ple[d][v][i]<=x[v])
			dp[v][i] = 1;
	}
}

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> n;

	for(int i = 2; i <= n; ++i)
	{
		int p;
		cin >> p;
		G[p].pb(i);
	}

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

	dfs(1);

	for(int i = 0; i < X; ++i)
	{
		if(dp[1][i])
		{
			cout << "POSSIBLE";
			return 0;
		}
	}

	cout << "IMPOSSIBLE";
}


Measured memory_bytes: 44416
let arr=readLine()!.characters.split{$0==" "}.map{String($0)}
var myDictionary: [Character: Int]  = [:]

var o = "No"
var count = 0

for ch in arr[0].characters {
  if( myDictionary[ch]  == nil ) {
  	myDictionary[ch] = 0
  } else {
    myDictionary[ch]! += 1
    if( myDictionary[ch]! > 2 ) {
      count = 1
    }
  }
}

if( ( myDictionary.count == 2 )  && ( count != 1 )) {
	o = "Yes"
}

print( o )
 

Measured memory_bytes: 6000
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i=0; i<N; i++)
			a[i] = sc.nextInt()-1;
		
		int ans = 0;
		for(int i=0; i<N; i++)
			if(a[a[i]]==i)
				ans++;
		
		System.out.println(ans/2);
		
		sc.close();
	}
}


Measured memory_bytes: 32284
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<ctime>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define N 4003

int parent[N];
int root(int x) {
  if(x != parent[x]) x = parent[x] = root(parent[x]);
  return x;
}
void unite(int x, int y) {
  int px = root(x), py = root(y);
  if(px < py) {
    parent[py] = px;
  } else {
    parent[px] = py;
  }
}

vector<P> g[N];
ll maxi[N][N];
void dfs(int s, int v, int prev, int cost) {
  maxi[s][v] = cost;
  rep(i, g[v].size()) {
    P &e = g[v][i];
    if(prev != e.first) {
      dfs(s, e.first, v, maxd(cost, e.second));
    }
  }
}

int main() {
  int n, m; cin >> n >> m;
  vector<IP> v;
  ll su = 0;
  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    v.push_back(IP(c, P(a, b)));
  }
  sort(ALL(v));
  rep(i, n) parent[i+1] = i+1;
  rep(i, m) {
    IP &e = v[i];
    int a = e.second.first, b = e.second.second, c = e.first;
    if(root(a) != root(b)) {
      unite(a, b);
      su += c;
      g[a].push_back(P(b, c));
      g[b].push_back(P(a, c));
    }
  }
  rep(i, n) {
    dfs(i+1, i+1, -1, 0);
  }
  int q;cin >> q;
  rep(i, q) {
    int s, t; cin >> s >> t;
    cout << su - maxi[s][t] << endl;
  }
  return 0;
}


Measured memory_bytes: 131436
N, K = map(int, input().split())
a = list(map(int, input().split()))
ans = None
s = None

for i in range(0, N - K + 1):
    s = sum(a[i:i+K]) + K if s is None else s - a[i - 1] + a[i + K - 1]

    if ans is None or ans < s:
        ans = s

print(ans/2)

Measured memory_bytes: 24804
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int INF = 1001001001;

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

template<typename O, typename Edge> struct Dijkstra
{
	using P = pair<O, int>;
	int V;
	int s;
	const O O_INF;
	const vector<vector<Edge>> &g;
	vector<O> dist;
	vector<int> previous;

	Dijkstra(const vector<vector<Edge>> &g, O O_INF) : V(g.size()), O_INF(O_INF), g(g) {}

	void calc(int s, O initial_state) {
		this->s = s;
		dist.assign(V, O_INF);
		previous.assign(V, -1);
		dist[s] = initial_state;
		priority_queue<P, vector<P>, greater<P>> pque;
		pque.emplace(initial_state, s);
		while (!pque.empty()) {
			P p = pque.top(); pque.pop();
			int v = p.second;
			if (dist[v] < p.first) continue;
			for (const Edge &e : g[v]) {
				O d = e.f(dist[v]);
				if (d < dist[e.to]) {
					dist[e.to] = d;
					previous[e.to] = v;
					pque.emplace(dist[e.to], e.to);
				}
			}
		}
	}
};

struct O
{
	int kaki;
	int d;

	bool operator <(const O &r) const {
		if (kaki == r.kaki) return d < r.d;
		return kaki < r.kaki;
	}
};

static const O O_INF = {INF, INF};

struct Edge
{
	int to;
	int type;
	static int k;
	O f(O &x) const {
		if (type == 0) {
			if (x.d == k) return {x.kaki+1, 1};
			return {x.kaki, x.d+1};
		} else {
			return {x.kaki+1, 0};
		}
	}
};
int Edge::k;

int main() {
	int h, w;
	cin >> h >> w >> Edge::k;
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	x1--; y1--; x2--; y2--;
	vector<string> c(h);
	for (int i = 0; i < h; i++) {
		cin >> c[i];
	}
	vector<vector<Edge>> g(4*h*w+1);
	auto idx = [&](int x, int y, int state) {
		return 4 * (x*w+y) + state;
	};
	int s = 4*h*w;
	for (int i = 0; i < 4; i++) {
		g[s].push_back({idx(x1, y1, i), 1});
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (c[i][j] == '@') continue;
			for (int k1 = 0; k1 < 4; k1++) {
				for (int k2 = 0; k2 < 4; k2++) {
					if (k1 != k2) g[idx(i,j,k1)].push_back({idx(i,j,k2), 1});
				}
			}
			for (int k = 0; k < 4; k++) {
				int nx = i + dx[k];
				int ny = j + dy[k];
				if (nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
				if (c[nx][ny] == '@') continue;
				g[idx(i,j,k)].push_back({idx(nx,ny,k), 0});
			}
		}
	}
	Dijkstra<O, Edge> D(g, O_INF);
	D.calc(s, O{0, 0});
	int ans = INF;
	for (int i = 0; i < 4; i++) {
		ans = min(ans, D.dist[idx(x2,y2,i)].kaki);
	}
	if (ans >= INF) ans = -1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 331020
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int cnt(int n){
	int rtn=0;
	while(n>0){
		if(n%2==1) rtn++;
		n/=2;
	}
	return rtn;
}

int main(){
	int n, k;
	cin >> n >> k;
	ll a[n];
	for(int i=0; i<n; i++) cin >> a[i];

	ll ans=-1;
	for(int i=0; i<(1<<(n-1)); i++){
		if(cnt(i)!=k-1) continue;
		int t=i;
		ll curr=a[0], cost=0;
		for(int j=1; j<n; j++){
			if(t%2==0){
				if(curr<a[j]){
					cost+=a[j]-curr+1;
					curr=a[j]+1;
				}
			}else{
				if(curr>=a[j]){
					cost+=curr-a[j]+1;
					curr++;
				}else{
					curr=a[j];
				}
			}
			t/=2;
		}
		if(ans==-1) ans=cost;
		else ans=min(ans, cost);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;} 
int main(void)
{
  
  long h,w,ans;
  scanf("%ld %ld",&h,&w);
 
  if(h%2==0)
    ans=h/2*w;
  if(h%2!=0&&w%2==0)
    ans=h*w/2;
  if(h%2!=0&&w%2!=0)
    ans=h*w/2+1;
   if(h==1||w==1)
    ans=1;
  
  printf("%ld",ans);
}

Measured memory_bytes: 128
#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
//#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e8;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};

int main() {
  int w, h;
  while (cin >> w >> h) {
    if (h == 0 && w == 0) break;
    bool mp[50][50][4] = {};
    rep(i, 2 * h - 1) {
      int x;
      if (i % 2 == 0) {
        rep(j, w - 1) {
          cin >> x;
          if (x == 1) {
            mp[i / 2][j][1] = 1;
            mp[i / 2][j + 1][3] = 1;
          }
        }
      } else {
        rep(j, w) {
          cin >> x;
          if (x == 1) {
            mp[i / 2][j][2] = 1;
            mp[i / 2 + 1][j][0] = 1;
          }
        }
      }
    }
    // rep(i, h) {
    //   rep(j, w) { rep(k, 4) cout << mp[i][j][k] << ' '; }
    //   cout << endl;
    //   cout << endl;
    // }

    int ans[50][50];
    bool used[50][50] = {};
    rep(i, 50) rep(j, 50) ans[i][j] = INF;
    ans[0][0] = 0;
    queue<pair<int, int>> q;
    q.push({0, 0});
    while (!q.empty()) {
      pair<int, int> p = q.front();
      q.pop();
      int y = p.first;
      int x = p.second;
      if (used[y][x]) continue;
      used[y][x] = 1;

      if (y == h - 1 && x == w - 1) break;
      rep(i, 4) {
        int ny = y + dy[i];
        int nx = x + dx[i];
        if (0 <= nx && nx < w && 0 <= ny && ny < h && mp[y][x][i] == 0 && used[ny][nx] == 0) {
          cmin(ans[ny][nx], ans[y][x] + 1);
          q.push({ny, nx});
        }
      }
    }
    // cout << endl;
    // rep(i, h) {
    //   rep(j, w) { cout << ans[i][j] << ' '; }
    //   cout << endl;
    // }
    cout << (ans[h - 1][w - 1] == INF ? 0 : ans[h - 1][w - 1] + 1) << endl;
  }
  return 0;
}



Measured memory_bytes: 3168
#include<iostream>
#include<algorithm>
#include<cstdlib>

typedef  long long ULL;
using namespace std;
int main(){
    ULL N;
    ULL *X;
    ULL *A;
    ULL sum;
    ULL a,b,c;
    ULL d;
    int i;
    
    cin >> N;
    A = new ULL[N];
    X = new ULL[N];
    sum = 0;
    for(i=0;i<N;i++){
        cin >> A[i];
        sum += A[i];
    }
    X[0] = sum;
    for(i=1;i<N-1;i+=2){
        X[0] -= 2*(A[i]);
    }
    for(i=0;i<N-1;i++){
        X[i+1] = 2*A[i] - X[i];
    }
    for(i=0;i<N;i++){
        cout << X[i] << " ";
    }
    cout << endl;
}


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

int a, b;
int n;
int x, y;
//     y   x
int dp[17][17];

signed main()
{
	while (true)
	{
		cin >> a >> b;
		if (a == 0 && b == 0) break;
		cin >> n;

		rep(i,17) rep(j,17) dp[i][j] =  -1;

		rep(i,n) {
			cin >> x >> y;
			dp[y][x] = 0;
		}

		bool zero_flag = false;
		for (int i=1; i<=a; i++) {
			if (dp[1][i] == 0) zero_flag = true;
			if (zero_flag) dp[1][i] = 0;
			else dp[1][i] = 1;
		}
		zero_flag = false;
		for (int i=1; i<=b; i++) {
			if (dp[i][1] == 0) zero_flag = true;
			if (zero_flag) dp[i][1] = 0;
			else dp[i][1] = 1;
		}

		for (int i=2; i<=a; i++) {
			for (int j=2; j<=b; j++) {
				if (dp[j][i] == -1) {
					dp[j][i] = dp[j-1][i] + dp[j][i-1];
				}
			}
		}

		/*
		for (int i=1; i<=b; i++) {
			for (int j=1; j<=a; j++) {
				printf("% 3d ", dp[i][j]);
			}
			cout << endl;
		}
		*/

		cout << dp[b][a] << endl;
	}
}

Measured memory_bytes: 1160
def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split(sep)))

def main():
    t = read()
    for _ in range(t):
        n, d = reads()
        
        if n == 1:
            print(d)
        elif n % 2 == 0:
            print(127*(n-1) + (d^127))
        else:
            print(127*(n-1) + d)
        
        # 3,  1 [1] -> [126, 127] -> [127, 1, 127]
        # 4,108 [108] -> [19, 127] -> [127, 127, 108] -> [127, 127, 127, 19]

main()

Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
char S[200111];

void MAIN() {
    scanf("%s", S);
    N = strlen(S);

    LL ans = 0;
    int black = 0;
    int white = 0;

    REP (i, N) {
	if (S[i] == 'W') {
	    if (black) {
		ans += i - white;
	    }
	    white++;
	}
	if (S[i] == 'B') {
	    black++;
	}
    }
    printf("%lld\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 1020
n, m = gets.split.map(&:to_i)
keys = []
m.times do
  price = gets.to_i
  jewels = gets.split.map(&:to_i)
  keys << [price, jewels]
end
max_num = 2 ** n
dp = Array.new(m + 1) { Array.new(max_num, nil) }
dp[0][0] = 0
m.times do |current|
  dp_current = dp[current]
  dp_next = dp[current + 1]
  price, jewels = keys[current]
  max_num.times do |current_num|
    next unless current_price = dp_current[current_num]
    dp_next[current_num] = current_price if dp_next[current_num].nil? || dp_next[current_num] > current_price
    next_num = jewels.inject(current_num) { |res, num| res | (2 ** (num - 1)) }
    tmp_price = current_price + price
    dp_next[next_num] = tmp_price if dp_next[next_num].nil? || dp_next[next_num] > tmp_price
  end
end
puts dp.last.last.nil? ? -1 : dp.last.last


Measured memory_bytes: 46620
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let r = read::<i64>();
    println!("{}", r * r);
}


Measured memory_bytes: 2100
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() (int, error) {
	sc.Scan()
	s := sc.Text()
	return strconv.Atoi(s)
}

func main() {
	for i := 1; ; i++ {
		a, _ := nextInt()
		if a == 0 {
			return
		}

		fmt.Printf("Case %d: %d\n", i, a)
	}
}



Measured memory_bytes: 1308
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin >> n; map<int,int> mp;
    for(int i=0;i<n-1;i++){
        int x; cin >> x;
        mp[x]++;
    }
    for(int i=1;i<=n;i++) cout << mp[i] << '\n';
}


Measured memory_bytes: 13040
n = int(input())
a = list(map(int,input().split()))
count = [0]*n
for i in range(n):
    count[a[i]-1] += 1
ans = 0
for i in range(n):
    ans += count[i]*(count[i]-1)//2
for i in a:
    before = count[i-1]*(count[i-1]-1)//2
    after = (count[i-1]-1)*(count[i-1]-2)//2
    print(ans - before + after)

Measured memory_bytes: 32308
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<string.h>
#include<vector>
#include<math.h>
#include<queue>
#include <algorithm>
#include<functional>
#include<cstdlib>
#include<cmath>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;

int N;

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

bool W_b[10] = { false };
int W[] = { 1, 2, 4, 8 ,16, 32, 64, 128, 256, 512 };

void input(void) {
	CI N;
	return;
}


int main(void) {
	int nn = 0;
	while (CI N) {
		for (int i = 9; i >= 0; i--) {
			if (W[i] <= N) {
				N -= W[i];
				W_b[i] = true;
				nn++;
			}
		}
		int x = 0;
		for (int i = 0; i < 10; i++) {
			if (W_b[i] == true) {
				x++;
				CO W[i];
				if (x < nn)CO " ";
				W_b[i] = false;
			}
		}
		CO "\n";
	
		nn = 0;
	}
	

	
	return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    int ans = max(0,a-2*b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3560
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 100
#define MAXL 100

int n;
char s[MAXN][MAXL];
char ct[26][MAXN];

int input() {
	if (scanf("%d", &n) < 0) return 0;
	for (int i=0; i<n; i++) {
		scanf("%s", s[i]);
	}
	return 1;
}

void init() {
	memset(ct, 0, sizeof(ct));
}

long solve() {
	for (int i=0; i<n; i++) {
		for (int j=0; s[i][j]; j++) {
			ct[s[i][j]-'a'][i]++;
		}
	}
	return 1;
}

void output(long ans) {
	for (int i=0; i<26; i++) {
		int k = *min_element(ct[i], ct[i]+n);
		for (int j=0; j<k; j++)
			printf("%c", i+'a');
	}
	printf("\n");
}

void cleanup() {
}

int main() {
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,p,mi=1000000,cnt=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>p;
		if(p<=mi){
			mi=p;
			cnt++;
		}
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>

int doPartition(int *arr, int startPos, int endPos);

int main(int argc, char** argv) {
    int length;
    int *inputArr;

    scanf("%d", &length);
    inputArr = (int *) calloc(sizeof(int), length + 1);
    for (int i = 0; i < length; i++) {
        scanf("%d", inputArr + i);
    }

    int pos = doPartition(inputArr, 0, length - 1);

    if (pos == 0) {
        printf("[%d]", *inputArr);
    } else {
        printf("%d", *inputArr);
    }
    for (int i = 1; i < length; i++) {
        if (i == pos) {
            printf(" [%d]", *(inputArr + i));
        } else {
            printf(" %d", *(inputArr + i));
        }
    }
    printf("\n");

    free(inputArr);
    return 0;
}

int doPartition(int *arr, int startPos, int endPos) {
    int sml = startPos - 1, cur = startPos;
    int ref = *(arr + endPos);
    
    while (cur < endPos) {
        if (*(arr + cur) <= ref) {
            if (++sml != cur) {
                int tmp = *(arr + sml);
                *(arr + sml) = *(arr + cur);
                *(arr + cur) = tmp;
            }
        }
        cur++;
    }

    if (cur == endPos) {
        sml++;
        int tmp = *(arr + sml);
        *(arr + sml) = *(arr + cur);
        *(arr + cur) = tmp;
    }

    return sml;
}


Measured memory_bytes: 3376
N = int(input())
AB = 0
LA = 0
FB = 0
LAFB = 0

for i in range(N):

    s = input()
    fbf = False
    laf = False

    for j in range(len(s)):

        

        if j == 0 and s[j] == "B":
            fbf = True

        if j == len(s) - 1:
            if s[j] == "A":
                laf = True

        elif s[j] == "A" and s[j+1] == "B":
            AB += 1


    if fbf and laf:
        LAFB += 1
    elif laf:
        LA += 1
    elif fbf:
        FB += 1

if LAFB > 0:
    AB += LAFB - 1

    if LA > 0:
        LA -= 1
        AB += 1

    if FB > 0:
        FB -= 1
        AB += 1

print (AB + min(FB,LA))


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

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

  string S2 = S;
  char c;
  int can = 1;
  while (can) {
    c = S[0];
    S.erase(S.begin());
    S.push_back(c);
    if (S == T) break;
    if (S == S2) can = 0;
  }

  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

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

#define MAX 200010
long long mod = 1000000007;
long long inv[MAX],fact[MAX],fi[MAX];

void inverse(){
	int i;
	inv[1] = 1;
	for(i=2;i<MAX;i++){
		inv[i] = mod - (mod/i)*inv[mod%i]%mod;
	}
}

void factinv(){
	int i;
	fact[0] = fi[0] = 1;
	for(i=1;i<MAX;i++){
		fact[i] = fact[i-1]*i%mod;
		fi[i] = (fi[i-1]*inv[i])%mod;
	}
}

long long comb(int n,int k){
	if(n<0 || k<0 || n<k){
		return 0;
	}else{
		return fact[n]%mod*fi[k]%mod*fi[n-k]%mod;
	}
}

int main(){
	int i=0,h,w,a,b;
	long long ans=0;
	cin >> h >> w >> a >> b;
	inverse();
	factinv();
	while(b+i<=h-a+b-1 && w-i-1-b>=0){
		ans += comb(h-a+b-1,b+i)*comb(w+a-b-1,w-i-1-b);
		i++;
		ans = ans%mod;
	}
	cout << ans << endl;
}
	
	
	
	

Measured memory_bytes: 4992