akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define NIL -1
#define MAX 25
 
struct Node {
    int parent, left, right;
};

int n;
vector<Node> T(MAX);
vector<int> D(MAX);
vector<int> H(MAX);
vector<int> Deg(MAX);

int root() {
    int u;
    for (int i = 0; i < n; i++) {
        if (T.at(i).parent == NIL) {
            u = i;
        }
    }

    return u;
}

void setDepth(int u, int d) {
    D.at(u) = d;
    if (T.at(u).left != NIL) {
        setDepth(T.at(u).left, d + 1);
    }
    if (T.at(u).right != NIL) {
        setDepth(T.at(u).right, d + 1);
    }
}

void setDepth() {
    setDepth(root(), 0);
}

int setHeight(int u) {
    int hL, hR;
    hL = 0;
    hR = 0;

    if (T.at(u).left != NIL) {
        hL = setHeight(T.at(u).left) + 1;
    }
    if (T.at(u).right != NIL) {
        hR = setHeight(T.at(u).right) + 1;
    }

    H.at(u) = max(hL, hR);

    return H.at(u);
}

void setHeight() {
    setHeight(root());
}

void setDegree() {
    for (int i = 0; i < n; i++) {
        int count = 0;
        if (T.at(i).left != NIL) {
            count++;
        }
        if (T.at(i).right != NIL) {
            count++;
        }

        Deg.at(i) = count;
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        T.at(i).parent = NIL;
    }
    
    for (int i = 0; i < n; i++) {
        int u, l, r;
        cin >> u >> l >> r;
        T.at(u).left = l;
        T.at(u).right = r;
        if (l != NIL) {
            T.at(l).parent = u;
        }
        if (r != NIL) {
            T.at(r).parent = u;
        }
    }

    setDepth();
    setHeight();
    setDegree();

    for (int u = 0; u < n; u++) {
        int p, l, r, sib, deg, d, h;
        p = T.at(u).parent;
        l = T.at(u).left;
        r = T.at(u).right;
        sib = NIL;
        if (p != NIL) {
            if (T.at(p).left != u && T.at(p).left != NIL) {
                sib = T.at(p).left;
            } else if (T.at(p).right != u && T.at(p).right != NIL) {
                sib = T.at(p).right;
            }
        }
        deg = Deg.at(u);
        d = D.at(u);
        h = H.at(u);
        
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ", u, p, sib, deg, d, h);
        if (p == NIL) {
            cout << "root" << endl;
        } else if (l == NIL && r == NIL) {
            cout << "leaf" << endl;
        } else {
            cout << "internal node" << endl;
        }
    }
}


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

#define rep(i, j, n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define Puts(x) puts(x? "Yes":"No")
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(int n, int m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(int n, int m) {return (n / gcd(n, m) * m);}
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};

struct WarshallFloyd {
  vector<vector<int>> d;
  int v;

  WarshallFloyd(int n) : v(n), d(n, vector<int>(n, INF)) {
    for(int i = 0; i < v; ++i) d[i][i] = 0;
  }

  void add(int from, int to, int cost) {
    d[from][to] = cost;
    d[to][from] = cost;
  }

  void make() {
    for(int k = 0; k < v; ++k) {
      for(int i = 0; i < v; ++i) {
        for(int j = 0; j < v; ++j) {
          d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
      }
    }
  }

  int dist(int i, int j) {
    return d[i][j];
  }
};

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

  int n, m, R;
  cin >> n >> m >> R;
  vt<int> r(R);
  rep(i, 0, R) {
    cin >> r[i];
    r[i]--;
  }

  WarshallFloyd wf(n);
  rep(i, 0, m) {
    int a, b, c;
    cin >> a >> b >> c;
    wf.add(--a, --b, c);
  }
  wf.make();

  int ans = INF;
  sort(all(r));
  do{
    int res = 0;
    rep(i, 1, R) res += wf.dist(r[i - 1], r[i]);
    ans = min(ans, res);
  }while(next_permutation(all(r)));
  cout << ans << endl;
}


Measured memory_bytes: 384
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2,gcd
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    ans=[]
    while 1:
        s1 = input()
        if s1 == '.':
            break
        else:
            s2 = input().split('"')
            s1=s1.split('"')

            ct=0
            flag=0

            if len(s1)!=len(s2):
                flag=2
            else:
                for i in range(len(s1)):
                    if i%2==0 :
                        if s1[i]!=s2[i]:
                            flag=2
                            break
                    else:
                        if s1[i]!=s2[i]:
                            if ct==0:
                                flag=1
                                ct+=1
                            else:
                                flag=2


            if flag==0:
                ans.append('IDENTICAL')
            elif flag==1:
                ans.append('CLOSE')
            else:
                ans.append('DIFFERENT')

    for x in ans:
        print(x)
if __name__ == '__main__':
    main()



Measured memory_bytes: 6768
#include<bits/stdc++.h>
using namespace std;
 
#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
 
int main(){
  ll i, j;
  ll h, w;
  cin >> h >> w;
  ll x[h][w], y[h][w];
  ll count = 0;
  
  for(i = 0; i < h; i++)
    for(j = 0; j < w; j++){
      cin >> x[i][j];
      y[i][j] = x[i][j];
    }
        
  for(i = 0; i < h; i++){
    for(j = 0; j < w - 1; j++){
      if(x[i][j] % 2 != 0){
        x[i][j]--;
        x[i][j + 1]++;
        count++;
        
      }
    }
  }
  for(i = 0; i < h - 1; i++){
    if(x[i][w - 1] % 2 != 0){
      x[i][w - 1]--;
      x[i + 1][w - 1]++;
      count++;
    }
  }
  
  cout << count << endl;
  
  for(i = 0; i < h; i++){
    for(j = 0; j < w - 1; j++){
      if(y[i][j] % 2 != 0){
        y[i][j]--;
        y[i][j + 1]++;
        cout << i+1 spa j+1 spa i+1 spa j+2 << endl;
      }
    }
  }
  for(i = 0; i < h - 1; i++){
    if(y[i][w - 1] % 2 != 0){
      y[i][w - 1]--;
      y[i + 1][w - 1]++;
      cout << i+1 spa w spa i+2 spa w << endl;
    }
  }
 
  return 0;
}

Measured memory_bytes: 6016
#include <map>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

//abbreviations
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define vb vector<bool>
#define vvi vector<vector<int>>

using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    int N, K;
    cin >> N >> K;
    vi H(N);
    rep(i,N)cin>>H[i];
    sort(H.begin(), H.end(), greater<int>());
    ll ans = 0;
    rep(i, N-K){
        ans += H[K+i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
using namespace std;
long long arr[100001] = {0};

int main(){
	long long N, M,K,A,B,C;
	cin >> N >> K;
	for (long long i = 0; i < N; i++){
		long long ai, bi;
		cin >> ai >> bi;
		arr[ai] += bi;
	}
	for (long long i = 1; i <=100000; i++){
		K -= arr[i];
		if (K <= 0){
			cout << i << "\n";
			break;
		}
	}




	return 0;
}

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

int n, m, ans=0, s[50], t[50];
bool mp[50][50], d[50];

void dfs(int pos) {
    d[pos] = true;
    for (int i = 0; i < n; i++) {
        if (mp[pos][i] == false) continue;
        if (d[i] == true) continue;
        dfs(i);
    }
}

int main(void) {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> s[i] >> t[i];
        s[i]--, t[i]--;
        mp[s[i]][t[i]] = mp[t[i]][s[i]] = true;
    }

    for (int i = 0; i < m; i++) {
        mp[s[i]][t[i]] = mp[t[i]][s[i]] = false;
        for (int j = 0; j < n; j++) d[j] = false;
        dfs(0);
        bool flag = false;
        for (int j = 0; j < n; j++) if (d[j] == false) flag = true;
        if (flag) ans++;
        mp[s[i]][t[i]] = mp[t[i]][s[i]] = true;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
int N, K;
cin >> N >> K;
vector<int> h(N);
for (int i = 0; i < N; i++) {
    cin >> h.at(i);
}
int count = 0;

for (int i = 0; i < N; i++) {
    if (h.at(i) >= K) {
        count++;
    }
}
cout << count << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
using namespace std;
 
int main() {
	
	fast;
	
	unsigned ll n, p=1000000000000000000, pdct=1, a;
	cin>>n;
	bool f=true;
	while(n--)
	{
	    cin>>a;
	    
	    if(pdct>=p || a*pdct<pdct)
	    {
	        if(a==0)
	        {
	            pdct*=a;
	            f=true;
	            continue;
	        }
	        f=false;
	        continue;
	    }
	    
	    pdct*=a;
	}
	
	if(pdct>p || !f)
	    cout<<-1;
	else
	    cout<<pdct;
	
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<ll> a(n);
    set<ll> cnt;
    rep(i,n){
      cin>>a[i];
      cnt.insert(a[i]);
    }
    sort(begin(a),end(a));
    if(n%3==0 && len(cnt)==3){
      vector<ll> now;
      bool flag=false;
      for(auto itr:cnt){
        now.push_back(itr);
      }
      do{
        //cout_vec(now);
        ll ch=0;
        if((now[0]^now[1])==now[2]) ch++;
        if((now[2]^now[1])==now[0]) ch++;
        if((now[0]^now[2])==now[1]) ch++;
        if(ch==3) flag=true;
      }while(next_permutation(begin(now),end(now)));
      ll x=0,y=0,z=0;
      rep(i,n){
        if(a[i]==now[0]) x++;
        if(a[i]==now[1]) y++;
        if(a[i]==now[2]) z++;
      }
      if(!(x==y && y==z)) flag=false;
      if(flag){
        cout<<"Yes"<<endl;
        return 0;
      }
    }else if(n%3==0 && len(cnt)<3){
      bool flag=false;
      for(auto itr:cnt){
        if(itr==0) flag=true;
      }
      if(len(cnt)==2){
        ll x=0,y=0;
        rep(i,n){
          if(a[i]==0) x++;
          else y++;
        }
        if(y!=2*x) flag=false;
      }
      if(flag){
        cout<<"Yes"<<endl;
        return 0;
      }
    }else if(len(cnt)==1){
      for(auto itr:cnt){
        if(itr==0){
          cout<<"Yes"<<endl;
          return 0;
        }
      }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 4480
#include <cstdio>
#include <cstring>

typedef unsigned long long int ull;

int N;

const int MAXN=502;

struct info_t{
    ull targets[MAXN];
    int opcat[MAXN];
    int zeroCount[MAXN];
}row,col;

ull matrix[MAXN][MAXN];

bool check(){
    //
    for(int r=1;r<=N;r++){
        ull androw=-1,orrow=0ull,andcol=androw,orcol=orrow;
        for(int c=1;c<=N;c++){
            androw&=matrix[r][c];
            orrow|=matrix[r][c];
            andcol&=matrix[c][r];
            orcol|=matrix[c][r];
        }

        if (row.opcat[r]&&orrow!=row.targets[r]) return false;
        if (!row.opcat[r]&&androw!=row.targets[r]) return false;
        if (col.opcat[r]&&orcol!=col.targets[r]) return false;
        if (!col.opcat[r]&&andcol!=col.targets[r]) return false;
    }

    return true;
}

void simpleInference(int pos){
    for(int r=1;r<=N;r++){
        for(int c=1;c<=N;c++){
            //目標値の対応ビットを取り出す
            auto colBit=(col.targets[c]>>pos)&1;
            auto rowBit=(row.targets[r]>>pos)&1;

            if (colBit^col.opcat[c]) matrix[r][c]|=(colBit<<pos);

            if (rowBit^row.opcat[r]) matrix[r][c]|=(rowBit<<pos);

            if (rowBit==colBit) matrix[r][c]|=(rowBit<<pos);
        }
    }
}

void SpecialInference(info_t& one,info_t& another,bool isRow,int pos){
    ull mask=(ull)1<<(ull)pos;
    for(int r=1;r<=N;r++){
        //今の桁を何にするかを表す
        auto bitTarget=(one.targets[r]>>pos)&one.opcat[r];
        if (!bitTarget||one.zeroCount[r]<N) continue;
        
        int c=1;
        while(c<=N){
            if (another.opcat[c]==0&&(another.targets[c]&mask)==0&&another.zeroCount[c]>1) break;
            c++;
        }
        if (c>N) continue;
        if (isRow)
            matrix[r][c]|=mask;
        else 
            matrix[c][r]|=mask;
        another.zeroCount[c]--;
        one.zeroCount[r]--;
    }
}

int main(){
    scanf("%d",&N);

    for(int i=1;i<=N;i++) scanf("%d",row.opcat+i);
    for(int i=1;i<=N;i++) scanf("%d",col.opcat+i);
    for(int i=1;i<=N;i++) scanf("%llu",row.targets+i);
    for(int i=1;i<=N;i++) scanf("%llu",col.targets+i);

    for(int bit=0;bit<64;bit++){
        ull mask=(ull)1<<(ull)bit;
        simpleInference(bit);

        memset(row.zeroCount,0,sizeof(row.zeroCount));
        memset(col.zeroCount,0,sizeof(col.zeroCount));
        for(int r=1;r<=N;r++)
            for(int w=1;w<=N;w++)
                if ((mask&matrix[r][w])==0) row.zeroCount[r]++,col.zeroCount[w]++;

        SpecialInference(row,col,true,bit);
        SpecialInference(col,row,false,bit);
    }

    if (!check()){
        puts("-1");
        return 0;
    }

    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++)
            printf("%llu ",matrix[i][j]);
            putchar('\n');
    }

    return 0;
}

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

num a, b, c, k;

int main() {
	cin >> a >> b >> c >> k;
	if (k <= a + b) {
		cout << min(a, k) << ln;
	} else {
		num d = k - a - b;
		cout << a - d << ln;
	}
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int a = 0;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
    a += vec.at(i);
  }
  sort (vec.begin(), vec.end());
  reverse (vec.begin(), vec.end());
  if (vec.at(M - 1) * 4 * M < a) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}

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

int main()
{
    int n, cnt = 0, result = 0, i;

    scanf( "%d", &n );

    for( i = 1; i <= n; i++ )
    {
        cnt++;
        if( cnt == 3 )
        {
            result++;
            cnt = 0;

            //printf( "%d %d\n", result, cnt);
        }
        
        
    }

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

Measured memory_bytes: 128
#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>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) {
        cin >> a[i];
    }
    vector<int> id(n+1,-1);
    vector<int> s;
    int len = 0;
    int x = 1;
    while (id[x] == -1) {
        s.push_back(x);
        id[x] = len;
        len++;
        x = a[x-1];
    }

    int c = len-id[x];
    int ans = 0;
    if (k <= len-1) {
        ans = s[k];
    } 
    else {
        k -= len;
        k %= c;
        ans = s[id[x]+k];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5860
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int d[] = new int[N];
		for(int i = 0; i < N; i++) {
			d[i] = sc.nextInt();
		}
		
		Arrays.sort(d);
		
		System.out.println(d[N / 2] - d[N / 2 - 1]);
	}
}


Measured memory_bytes: 50556
#include <bits/stdc++.h>
#include <limits.h>
#include <algorithm>  
#include <numeric>
#include <sys/resource.h>
 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define endl '\n'
using ll = long long;
 
const int precision = 15;
const int modulo =  1000000007; // 10^9 + 7
const ll lmodulo =  1000000007; // 10^9 + 7
 
const double EPS = 1e-9;
const ll inf = 1e18;


void increaseStack() {
	const rlim_t kStackSize = 50 * 1024 * 1024;   // min stack size = 50 MB
	struct rlimit rl;
	int result;

	result = getrlimit(RLIMIT_STACK, &rl);
	if (result == 0) {
		if (rl.rlim_cur < kStackSize) {
			rl.rlim_cur = kStackSize;
		    result = setrlimit(RLIMIT_STACK, &rl);
		    if (result != 0) {
		    	fprintf(stderr, "setrlimit returned result = %d\n", result);
		    }
		}
	}
}


void solve() {
	int n; cin >> n;

	vector<vector<int>> match(n ,vector<int>(n));

	for (auto i = 0; i < n; ++i) {
		for (auto j = 0; j < n; ++j) {
			cin >> match[i][j];
		}
	}

	vector<ll> dp (1 << n);
	dp[0] = 1;

	for (auto mask = 0; mask < (1 << n) - 1; ++mask) {
		auto m = __builtin_popcount(mask); 
		for (auto w = 0; w < n; ++w) {
			if (match[m][w] and !(mask & (1 << w))) {
				auto nextMask =  mask ^ (1 << w);
				dp[nextMask] += dp[mask];
				dp[nextMask] %= lmodulo;
			}	
		}
	}

	 cout << dp[(1 << n) - 1];
}
  
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(precision);
  cout.setf(ios_base::fixed);
  solve();
  return 0;
}


Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b+c){
    cout<<"Yes"<<"\n";
    return(0);
  }
  if(a+b==c){
    cout<<"Yes"<<"\n";
    return(0);
  }
  if(b==c+a){
    cout<<"Yes"<<"\n";
    return(0);
  }
  cout<<"No"<<"\n";
  return(0);
}


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define long long long
#define db double
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
template <class T> inline void chmin(T &a, const T& val) { if (a > val) a = val; }
template <class T> inline void chmax(T &a, const T& val) { if (a < val) a = val; }
template <class T> long sqr(T a) { return 1ll * a * a; }
template <class T> void compress(T &a){
  sort(all(a)); a.resize(unique(all(a)) - a.begin());  
}

const db pi = acos(-1.00);
const db eps = 1e-6;
const long INF = 1e18;
const int MOD = 1e9+7;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};

int main()
{
  fastio;
  long cur = 1;
  int n; cin >> n;
  vector <long> a(n);
  for (long &x : a){
    cin >> x;
    if (x == 0) return cout << 0, 0;
  }
  for (long x : a){
    if (INF / x < cur) return cout << -1, 0;
    cur *= x;
  }
  cout << (cur <= INF ? cur : -1);
  return 0;
}

Measured memory_bytes: 3980
import sys
sys.setrecursionlimit(1000000)
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque, Counter as cnt

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]
def nlist(n, v):
    if not n: return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]

# エントリーポイント
def main():
    S = input(str)
    for s in S[::2]:
        if s == "R" or s == "U" or s == "D":
            continue
        print("No")
        return

    for s in S[1::2]:
        if s == "L" or s == "U" or s == "D":
            continue
        print("No")
        return
    print("Yes")
    return

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


Measured memory_bytes: 3528
list=list(input())
for i in range(4):
    list[i]=int(list[i])
for x in range(2):
    for y in range(2):
        for z in range(2):
            if x==0:
                p=list[1]
                P="+"+str(list[1])
            else:
                p=-list[1]
                P="-"+str(list[1])
            if y==0:
                q=list[2]
                Q="+"+str(list[2])
            else:
                q=-list[2]
                Q="-"+str(list[2])
            if z==0:
                r=list[3]
                R="+"+str(list[3])
            else:
                r=-list[3]
                R="-"+str(list[3])
            if list[0]+p+q+r==7:
                print(str(list[0])+P+Q+R+"=7")
                exit()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <bitset>
#include <sstream>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <climits>
#include <ctype.h>
using namespace std;

#define PI acos(-1.0)
#define EPS 1e-8
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second

typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

struct Matrix {
    vvi data;
    int r, c;
    Matrix(int row, int col, bool identity = false) : r(row), c(col) {
        data.assign(row, vector<int>(col, 0));
        if (identity) {
            for (int i = 0; i < r; ++i) {
                data[i][i] = 1;
            }
        }
    }
    Matrix operator * (Matrix& other) {
        int m = r, n = c, p = other.c;
        Matrix res(m, p);
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < p; ++j) {
                for (int k = 0; k < n; ++k) {
                    res.data[i][j] += data[i][k] * other.data[k][j];
                }
            }
        }
        return res;
    }
};

// 扩展欧几里得算法 res[1] * a + res[2] * b = res[0] = gcd(a, b)
vector<int> extendGcd(int a, int b) {
    if (b == 0) {
        return {a, 1, 0};
    } else {
        vector<int> tmp = extendGcd(b, a % b);
        return {tmp[0], tmp[2], tmp[1] - (a / b) * tmp[2]};
    }
}

// 矩阵快速幂
Matrix matrix_power(Matrix base, ll exp) {
    int n = base.r;
    Matrix res(n, n, true);
    while (exp) {
        if (exp & 1) {
            res = res * base;
        }
        base = base * base;
        exp >>= 1;
    }
    return res;
}

// 带模快速幂
template <typename T>
T power_mod(T base, int exp, int mod = MOD) {
    T res = 1;
    while (exp) {
        if (exp & 1) res = res * base % mod;
        base = base * base % mod;
        exp >>= 1;
    }
    return res;
}

// 快速幂
template <typename T>
T power(T base, int exp) {
    T res = 1;
    while (exp) {
        if (exp & 1) res *= base;
        base *= base;
        exp >>= 1;
    }
    return res;
}

// 求逆元
ll inv(ll a) {
    return power_mod(a, MOD - 2);
}

/******************************** template ********************************/
const int MAXN = 1e5 + 10;
int dist[MAXN];

int main() {
    memset(dist, -1, sizeof(dist));
    int n;
    cin >> n;
    deque<int> q;
    dist[1] = 1;
    q.push_back(1);
    while (!q.empty()) {
        int val = q.front();
        q.pop_front();
        int cur = val*10 % n;
        if (dist[cur] == -1 || dist[cur] > dist[val]) {
            dist[cur] = dist[val];
            q.push_front(cur);
        }
        cur = (val+1) % n;
        if (dist[cur] == -1 || dist[cur] > dist[val] + 1) {
            dist[cur] = dist[val] + 1;
            q.push_back(cur);
        }
    }
    cout << dist[0] << endl;
}

Measured memory_bytes: 896
def solve():
    A = [list(map(int, input().split())) for _ in range(3)]
    B = []
    for i in range(3):
        for j in range(3):
            B.append(A[i][j])

    N = int(input())
    for _ in range(N):
        a = int(input())
        for i in range(9):
            if B[i] == a:
                B[i] = 0

    bingo = [
        [0,1,2],
        [3,4,5],
        [6,7,8],
        [0,3,6],
        [1,4,7],
        [2,5,8],
        [0,4,8],
        [2,4,6],
        ]
    
    ans = 'No'
    
    for a, b, c in bingo:
        if B[a] == 0 and B[b] == 0 and B[c] == 0:
            ans = 'Yes'

    return ans

print(solve())

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

int a, b, k;	

int main() {
	cin >> k >> a >> b;
	for (int i=a; i<=b; i++) {
		if (i % k == 0) {
			cout << "OK\n";
			exit(0);
		}
	}
	cout << "NG\n";
}

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

const int MAXN = 3e5;
int N;
int M;
set<int> adj[MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N >> M;
	for (int e = 0; e < M; e++) {
		int a, b; cin >> a >> b;
		adj[a].insert(b);
		adj[b].insert(a);
	}

	for (int i = 2; i <= N-1; i++) {
		if (adj[i].count(1) && adj[i].count(N)) {
			cout << "POSSIBLE" << '\n';
			exit(0);
		}
	}
	cout << "IMPOSSIBLE" << '\n';

	return 0;
}

Measured memory_bytes: 33024
import math

HW = input().split()

H = int(HW[0])
W = int(HW[1])


result = int(0)

y1 = 0
y2 = 0
if W%2 == 1:
    y1 = int(W/2) + 1
    y2 = int(W/2)
else:
    y1 = int(W/2)
    y2 = y1


if H%2 == 1:
    result += y1 * (int(H/2) + 1)
    result += y2 * int(H/2)
else:
    result += y1 * int(H/2)
    result += y2 * int(H/2)

if H == 1 or W == 1:
    result = 1

print(result)



Measured memory_bytes: 3064
def add_i1():
	abc[i1]+=1
	abc[i2]-=1
	res[i]=i1
	return

def add_i2():
	abc[i1]-=1
	abc[i2]+=1
	res[i]=i2

n,*abc=map(int,input().split())
ip=[0]*n
dic={0:"A",1:"B",2:"C"}
for i in range(n):
	tmp=input()
	if tmp=="AB":
		ip[i]=[0,1]
	elif tmp=="BC":
		ip[i]=[1,2]
	else:
		ip[i]=[0,2]
ans="Yes"
res=[0]*n
s=sum(abc)
if s==0:
	ans="No"
elif s==1:
	for i in range(n):
		i1=ip[i][0]
		i2=ip[i][1]
		ABC=[abc[i1],abc[i2]]
		if ABC==[0,0]:
			ans="No"
		elif ABC==[0,1]:
			add_i1()
		else:
			add_i2()
else:
	i1=ip[0][0]
	i2=ip[0][1]
	if [abc[i1],abc[i2]]==[0,0]:
		ans="No"
	else:
		for i in range(n):
			i1=ip[i][0]
			i2=ip[i][1]
			if abc[i1]==0:
				add_i1()
			elif abc[i2]==0:
				add_i2()
			elif i+1<n and ip[i+1]!=ip[i]:
				c=list(set(ip[i])&set(ip[i+1]))[0]
				if i1==c:
					add_i1()
				else:
					add_i2()
			else:
				add_i1()
print(ans)
if ans=="Yes":
	for i in range(n):
		print(dic[res[i]])

Measured memory_bytes: 18656
def solve(str)
  max, min = 0, 0
  numbers = str.split.map(&:to_i)

  numbers.each_cons(2) do |n|
    val = n[0] - n[1]
    max = val if val > max
    min = val if val < min
  end
  puts "#{-min} #{max}"
end
num = STDIN.gets.to_i
num.times do
  STDIN.gets
  line = STDIN.gets
  solve(line)
end

Measured memory_bytes: 6104
#include <stdio.h>
#include <stdlib.h>

int main()
{
    char s[4];
    int n,a,b,c;
    while(gets(s))
    {
        n=0;
        for(a=0;a<4;a++)
        {
            if(s[a]=='+')
            {
                n++;
            }
            else
            {
                n--;
            }
        }
        printf("%d\n",n);
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    while(true){
        c -= b;
        if(c<=0){
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
        if(a<=0){
            cout << "No" << endl;
            return 0;
        }
    }
}

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

int main(){

        int a[3],i,j,M=0;
        int c=2;

        cin >> a[0] >> a[1] >> a[2];


        for(i=0;i<3;i++){
                        for(j=0;j<3;j++){
                                if(i<j){
                                        if(M<(a[i]*10)+a[j]+a[c]){
                                        M=(a[i]*10)+a[j]+a[c];
                                        }
                                        c--;
                                }
                        }
        }

        c=2;

        for(i=0;i<3;i++){
                for(j=0;j<3;j++){
                        if(i<j){
                                if(M<(a[j]*10)+a[i]+a[c]){
                                M=(a[j]*10)+a[i]+a[c];
                                }
                                c--;
                        }
                }
        }

        cout << M <<endl;


        return 0;
}

Measured memory_bytes: 256
n = int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ma=sum(b)
for i in range(0,n-1):
    if a[i+1]-a[i]==1:
        ma+=c[a[i]-1]
print(ma)

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

int main()
{
  int64_t N, M, k, s, ans = 0;
  cin >> N >> M;
  vector<vector<int>> A(M);
  for (int i = 0; i < M; i++)
  {
    cin >> k;
    for (int j = 0; j < k; j++)
    {
      cin >> s;
      s--;
      A.at(i).push_back(s);
    }
  }
  vector<int> P(M);
  for (int i = 0; i < M; i++)
  {
    cin >> P.at(i);
  }
  for (int bit = 0; bit < (1 << N); bit++)
  {
    bool on = true;
    for (int i = 0; i < M; i++)
    {
      int cnt = 0;
      for (int j = 0; j < A.at(i).size(); j++)
      {
        if (bit & (1 << A.at(i).at(j)))
          cnt++;
      }
      if (cnt % 2 != P.at(i))
      {
        on = false;
        break;
      }
    }
    if (on)
      ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;



public class Main{
	public static void main(String[] args){

		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
		String str, text;
		int num, position;

		try{

			while(true){
				str=reader.readLine();

				if(str.equals("-"))break;

				num=Integer.parseInt(reader.readLine());

				for(int i=0;i<num;i++){
					position=Integer.parseInt(reader.readLine());

					text=str.substring(0, position);
					str+=text;
					str=str.substring(text.length(), str.length());
				}
				System.out.println(str);

			}


		}catch(IOException e){
			System.out.print(e);
		}
	}

}

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

int main() {
	ll result = 0;

	ll N = 1, K = 0;
	cin >> N >> K;

	vector<ll> H(N * 10);
	for(ll i = 0; i < N; i++) {
		cin >> H[i];
		result += H[i];
	}

	sort(H.begin(), H.end(), greater<ll>());
	for(ll i = 0; i < K; i++) {
		result -= H[i];
	}

 	cout << result << endl;
	return 0;
}


Measured memory_bytes: 15872
def solve(n)
  dp = Array.new(n, 0)
  (0...n).each do |i|
    if i == 0
      dp[i] = 1
    elsif i == 1
      dp[i] = 2
    elsif i == 2
      dp[i] = 4
    else
      dp[i] = dp[i-1] + dp[i-2] + dp[i-3]
    end
  end

  dp[-1]
end

def to_days(n)
  q = n / 10
  r = n % 10

  r > 0 ? q + 1 : q
end

def to_years(n)
  n = to_days(n)

  q = n / 365
  r = n % 365

  r > 0 ? q + 1 : q
end

loop do
  i = gets.chomp.to_i
  if i == 0
    break
  else
    puts(to_years(solve(i)))
  end
end



Measured memory_bytes: 6864
#include "bits/stdc++.h"
using namespace std;
//debug() << imie(x) imie(y);
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int main()
{
int n;
cin>>n;
cout<<n*800-((n/15)*200);

return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>

using namespace std;

int main(){
  int N, ans=1;

  cin >> N;

  for(int i = 1; i < N; i++){
    ans = i * i;
    if(N < ans){
      ans = (i - 1) * (i - 1);
      break;
    }
  }

  cout << ans << endl;

	return 0;
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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; }



int n;
void solve(){
	cin >> n;
	
	cout << 10-n/200 << endl;
}

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

Measured memory_bytes: 3644
#include<iostream>
#include<vector>
using namespace std;
class DisjointSet {
private:
	vector<int> rank, p;
public:
	DisjointSet(){}
	DisjointSet(int size) {
		rank.resize(size, 0);
		p.resize(size, 0);
		for(int i = 0; i < size; ++i ) makeSet(i);
	}
    void makeSet(int x) {
    	rank[x] = 0;
    	p[x] = x;
    }

    bool same(int x, int y) {
    	return findSet(x) == findSet(y);
    }
    int findSet(int x) {
    	if( x != p[x]) p[x] = findSet(p[x]);
    	return p[x];
    }
    void unite(int x, int y) {
    	int a = findSet(x);
    	int b = findSet(y);
    	if ( a != b ) {
    		if( rank[a] < rank [b] )
    			p[a] = b;
    		else {
    			p[b] = a;
    			if( rank[a] == rank[b] ) rank[a]++;
    		}
    	}
    }
};

int main(){
 	int n, q;
 	int c, x, y;
 	cin >> n >> q;
 	DisjointSet ds = DisjointSet(n);
 	while( q-- ) {
      cin >> c >> x >> y;
      if ( c == 0 ) ds.unite(x, y);
      else if( c == 1 ) {
      	if ( ds.same(x, y) ) cout << 1 << endl;
      	else cout << 0 << endl;
      }
 	}
 	return 0;
}


Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>

using namespace std;
using ll=long long int;
const ll MOD=1000000007;

int main(){
  int H,W,K;
  cin>>H>>W>>K;
  K--;

  ll dp[H+1][W]; //dp[h][k]=横線h段からなるあみだくじで、0がkに来る者の数
  fill(dp[0],dp[H+1],0); //0からH+1まで0で埋める
  dp[0][0]=1;

  for (int h=0; h<H; ++h) {
    for (int b=0; b<(1<<(W-1)); ++b) {
      //横線が隣り合っていないかチェック
      bool judge = true;
      for (int i=0; i<W-2; ++i){
        if ((b>>i)%4==3) judge=false;
      }
      if (!judge) continue; //continue以下の処理を飛ばして次のループへ

      int perm[W]; //各支店がどこに移動するのかを管理する
      for (int i=0; i<W; ++i) perm[i]=i;
      for (int i=0; i<W-1; ++i) {
        //あみだくじのルールに従って位置をswap
        if ((b>>i)&1) swap(perm[i],perm[i+1]);
      }
      //配る
      for (int i=0; i<W; ++i){
        dp[h+1][perm[i]] += dp[h][i];
        dp[h+1][perm[i]] %= MOD;
      }
    }
  }

  cout << dp[H][K] <<endl;

  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
using ll=long long;
using namespace std;
int main(){
  ll inf=1e18;
  int n,m;
  cin>>n>>m;
  ll d[n];
  d[0]=0;
  for(int i=1;i<n;++i)d[i]=inf;
  vector<vector<int> >a(m,vector<int>(3));
  for(int i=0;i<m;++i){
    int l,r,c;
    cin>>l>>r>>c;
    a[i][0]=l-1;
    a[i][1]=r-1;
    a[i][2]=c;
  }
  sort(a.begin(),a.end());
  for(int i=0;i<m;++i){
    int l=a[i][0],r=a[i][1],c=a[i][2];
    for(int j=l;j<r;++j){
      ll t=d[j]+c;
      if(t<d[r])d[r]=t;
    }
  }
  cout<<(d[n-1]==inf?-1:d[n-1])<<'\n';
}

Measured memory_bytes: 6400
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <utility>
typedef long long ll;
using namespace std;
const int mod=1e9+7;

ll solve(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    return max({a*c,a*d,b*c,b*d});
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    int t=1;
    //cin>>t;
    while(t--) cout<<solve()<<'\n';
    //while(t--) solve(),cout<<'\n';
    return 0;
}


Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

#define int long long



int n,ans;


signed main(){
	read(n);
	ans+=n/500*1000;
	n%=500;
	ans+=n/5*5;
	write(ans);
}

Measured memory_bytes: 256
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    n = I()
    if n == 1:print(1)
    elif n%2 == 0:print(0.5)
    else:print((n//2+1)/n)

Measured memory_bytes: 3064
import math

N=int(input())
NP=list(range(N+1)[1:])
NQ=list(range(N+1)[1:])
P=list(map(int,input().split()))
Q=list(map(int,input().split()))

a=0
b=0

for n in range(N):
    a+=(math.factorial(N-n-1))*NP.index(P[n])
    b+=(math.factorial(N-n-1))*NQ.index(Q[n])
    NP.pop(NP.index(P[n]))
    NQ.pop(NQ.index(Q[n]))

print(abs(a-b))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(n) n.begin(),n.end()
#define yn(x) cout << (x ? "Yes":"No") << endl;

int main() {
  int n;
  cin >> n;
  bool ans = false;
  rep(i,10){
    rep(j,10){
      if(n==i*j) ans = true;
    }
  }
  yn(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int main(){
  int n;
  cin>>n;
  vector<int> vec(n);
  rep(i,n) cin>>vec[i];
  deque<int> dq;
  rep(i,n){
    if(i%2==0) dq.push_front(vec[i]);
    else dq.push_back(vec[i]);
  }
  vector<int> ans(all(dq));
  if(n%2==0) reverse(all(ans));

  rep(i,n) cout<<ans[i] << " \n"[i==n-1];

  return 0;
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

ll a[100010], b[100010];

vector<ll> v;

int main(){
    ll n, k;
    cin >> n >> k;
    rep(i, n) cin >> a[i] >> b[i];
    
    int r = 0;
    rep(i, 35) if (k&1ll<<i) r = i;


    v.push_back(k);
    rep(i, r){
        ll tmp = k;
        if (1ll<<(r-i) & k) {
            tmp -= 1ll<<(r-i);
            rep(j, r-i) tmp |= 1ll<<j;
        }
        v.push_back(tmp);
    }

    ll ans = 0;
    for(auto e : v) {
        // cout << e << endl;
        ll res = 0;
        rep(i, n) {
            if ((e|a[i]) == e) res += b[i];
            // cout << e << " " << a[i] << " " << (e|a[i]) << endl;
        }
        ans = max(ans, res);
    }

    cout << ans << endl;
    return 0;

}


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

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<ll,pi >
#define ppi pair<pi,ll>
#define ppp pair<pi,pi >
#define ex(str,a,b) str.substr((int)(a),min((int)str.size()-a,(int)(b-a+1))) 
#define all(X) X.begin(),X.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   __builtin_popcount(n) : no. of set bits in n.
*/

const int M = (1<<20)+5;
const int md = 1e9+7;

priority_queue<ll,vector<ll >,greater<ll > > pq;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

ll val[M];

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

	ll n,i,v,ans = 0,c;

	cin >> n;

	for(i=1;i<=1000;++i)
	{
		v = (i*(i+1))/2;
		val[v] = i;
	}

	for(i=1;i<=1000000;++i)
		val[i] = max(val[i-1],val[i]);

	for(i=2;i*i<=n;++i)
	{
		if(n%i==0)
		{
			c = 0;
			while(n%i==0)
			{
				n = n/i;
				c++;
			}
			ans += val[c];
		}
	}

	if(n>1)
		ans++;

	cout << ans << "\n";
}

Measured memory_bytes: 11472
#include <atcoder/all>
#include <bits/stdc++.h>

using namespace atcoder;
using namespace std;
 
#define REP(i,n) for(int i = 0;i < n;i++)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()

template<class T> bool chmax(T& a,T b){ if(a < b){ a = b; return true; }else return false; }
template<class T> bool chmin(T& a,T b){ if(a > b){ a = b; return true; }else return false; }
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;
using vpi = vector<Pi>;
using vpl = vector<Pl>;
 
#define debug(arr) cout << #arr << " = " << arr << '\n'
#define debug2(a,b) cout << "[" << #a << "," << #b << "] = " << "[" << a << "," << b << "]" << '\n'
template<class T> ostream &operator << (ostream& out, const vector<T>& arr) {
	cout << "{"; for (int i = 0; i < arr.size(); i++)cout << (!i ? "" : ", ") << arr[i]; cout << "}";
	return out;
}
template<class T> ostream &operator << (ostream& out, const vector<vector<T> >& arr) {
	cout << "{\n"; for (auto& vec : arr)cout << "  " << vec << ",\n"; cout << "}";
	return out;
}
template<class S,class T> ostream &operator << (ostream& out, const pair<S,T>& p){
  cout << "{" << p.first << "," << p.second << "}" << '\n';
  return out;
}
template<class T> istream &operator >> (istream& in, vector<T>& arr) {
	for (auto& i : arr)cin >> i; return in;
}

/////////////////////////////////////////////////////
ll extgcd(ll a, ll b, ll &x, ll &y) {
    ll g = a;
    x = 1;
    y = 0;
    if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
    return g;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //cout << fixed << setprecision(20);
  
  ll n;cin >> n;
  if(n == 1){
    cout << 1 << '\n';
    return 0;
  }
  n *= 2;
  map<ll,int> pf;
  for(ll i = 2;i <= 31622780;i++){
    if(n == 1)break;
    if(n % i == 0){
      while(n % i == 0){
        n /= i;
        pf[i]++;
      }
    }
  }
  if(n != 1)pf[n]++;
  vector<ll> p;
  for(auto e : pf) {
    ll ele = e.first;
    REP(i,e.second-1) ele *= e.first;
    p.pb(ele);
  }
  int sz = pf.size();
  ll x,y;
  ll ans = LONG_MAX;
  REP(mask,(1 << sz)){
    ll a = 1,b = 1;
    REP(j,sz){
      if(mask >> j & 1) a *= p[j];
      else b *= p[j];
    }
    extgcd(a,b,x,y);
    if(x == 0 || y == 0)continue;
    if(abs(a*x) > abs(b*y)){
      chmin(ans,abs(b*y));
    }else{
      chmin(ans,abs(a*x));
    }
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3692
#include <iostream>
#include <queue>
#include <cmath>
#include <set>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

typedef long double ld;

ld xs, ys, xt, yt;

int n;

ld x[1010],y[1010],r[1010];

typedef pair<ld,int> P;

vector<P> edges[1020];


void input()
{
	cin >> xs >> ys >> xt >> yt;

	cin >> n;

	x[0] = xs;
	y[0] = ys;

	x[n + 1] = xt;
	y[n + 1] = yt;

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

	cout << fixed << setprecision(10);
}

ld dist[1010];

ld zero = 0;

int main()
{
	input();

	for(int i = 0;i <= n + 1;i++)
	{
		for(int j = i + 1;j <= n + 1;j++)
		{
			ld dx = x[i] - x[j];
			ld dy = y[i] - y[j];
			ld len = sqrt(dx * dx + dy * dy);
			len = max(len - r[i] - r[j] , zero);
			edges[i].push_back(P(len,j));
			edges[j].push_back(P(len,i));

			cerr << i << "-" << j << "=" << len << endl;
		}
	}

	priority_queue<P,vector<P>,greater<P>> que;

	que.push(P(0,0));

	fill(dist,dist + 1010,1e11);

	while(!que.empty())
	{
		ld d = que.top().first;
		int v = que.top().second;
		que.pop();

		if(d > dist[v]) continue;

		for(P& p : edges[v])
		{
			if(d + p.first < dist[p.second])
			{
				dist[p.second] = d + p.first;
				que.push(P(dist[p.second],p.second));
			}
		}

	}

	cout << dist[n + 1] << endl;
	return 0;
}



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

using namespace std;

int main() {
    string ans = "";
    int arr[20] = {0}, max = -1;
    int n, m;
    cin >> n >> m;
    if(m == 0 && n > 1){
        cout << 1;
        for(int i = 1; i < n; ++i)cout << 0;
        return 0;
    }
	for(int i = 0; i < m; ++i){
        int tmp, tmp1;
        cin >> tmp >> tmp1;
        if(tmp1 == 0) tmp1 = -10;
        if(arr[tmp] != 0 && arr[tmp] != tmp1){
            cout << - 1;
            return 0;
        }
        arr[tmp] = tmp1;
        if(max <= tmp){
            max = tmp;
        }
	}
    if(arr[1] == -10 && n > 1){
        cout << -1;
        return 0;
    }
    else{
        if(arr[1] == 0) arr[1] = 1;
        for(int i = 1; i <= max; ++i){
            if(arr[i] == -10) ans += '0';
            else if(arr[i] != 0) ans += to_string(arr[i]);
            else ans += '0';
        }
    }
    if(ans.length() > n)cout << -1;
    else if(ans.length() == n)cout << ans;
    else{
        for(int i = ans.length(); i < n; ++i){
            ans += '0';
        }
        cout << ans;
    }
	return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;
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[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        boolean[] dp = new boolean[K + 1];
        Arrays.fill(dp, false);
        for (int stones = 0; stones <= K; stones++) { // stones
            for (int num : A) {
                if (stones >= num && !dp[stones - num]) {
                    dp[stones] = true;
                }
            }
        }

        if (dp[K] == true) {
            System.out.println("First");
        } else {
            System.out.println("Second");
        }
    }

}

Measured memory_bytes: 24276