akhauriyash/Code-Regression huggingface dataset:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left

import sys
# sys.setrecursionlimit(1000000)
# list(map(int, input().split()))
n, k = getList()
# dist
nums = [0] + getList()
cnt = 1
if k == 1:
    print(1)
    exit()
cur = 1
visited = [-1 for i in range(n + 1)]
visited[1] = 1
rooped = False
while True:
    # cur 行き先
    cur = nums[cur]
    cnt += 1

    # １回目に訪れていたら
    if visited[cur] != -1:
        # ループの周期
        roop = cnt - visited[cur]
        # 途中を飛ばす
        k -= ((k-cnt) // roop) * roop
        rooped = True
    if not rooped:
        # １回目に訪れたのであれば
        visited[cur] = cnt

    if cnt == k:
        print(nums[cur])
        break

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

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

using namespace std;

const int MAX_V = 2000;
const int IINF = INT_MAX;
typedef pair<int,int> ii;

map<ii,int> mp; /////////

struct Edge{ int to,cap,rev; };

vector<Edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from,int to,int cap){
  assert( mp.count(ii(from,to)) == 0 );
  mp[ii(from,to)] = (int)G[from].size();
  G[from].push_back((Edge){to,cap,G[to].size()});
  G[to].push_back((Edge){from,0,G[from].size()-1});
}

int dfs(int v,int t,int f){
  if( v == t ) return f;
  used[v] = true;
  for(int i=0;i<G[v].size();i++){
    Edge &e = G[v][i];
    if( !used[e.to] && e.cap > 0 ){
      int d = dfs(e.to,t,min(f,e.cap));
      if( d > 0 ){
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t){
  int flow = 0;
  for(;;){
    memset(used,0,sizeof(used));
    int f = dfs(s,t,IINF);
    if( f == 0 ) return flow;
    flow += f;
  }
}

void init(int _size=MAX_V){ rep(i,_size) G[i].clear(); }

int V,E,Q;


inline void remove_edge(int u,int v){
  G[u][mp[ii(u,v)]].cap = 0;
  G[v][G[u][mp[ii(u,v)]].rev].cap = 0;
  G[v][mp[ii(v,u)]].cap = 0;
  G[u][G[v][mp[ii(v,u)]].rev].cap = 0;
}

inline bool remove(int u,int v,int source,int sink){
  Back:;
  if( G[u][mp[ii(u,v)]].cap == 1 && G[v][mp[ii(v,u)]].cap == 1 ) {
    remove_edge(u,v);
    return false;
  }

  if( G[u][mp[ii(u,v)]].cap == 0 && G[v][mp[ii(v,u)]].cap == 0 ){
    G[u][mp[ii(u,v)]].cap = 1;
    G[v][G[u][mp[ii(u,v)]].rev].cap = 0;
    G[v][mp[ii(v,u)]].cap = 1;
    G[u][G[v][mp[ii(v,u)]].rev].cap = 0;
    goto Back;
  }


  if( G[u][mp[ii(u,v)]].cap == 1 ) swap(u,v);
  memset(used,false,sizeof(used));
  int tmp = dfs(u,v,IINF);
  bool ret = false;
  if( tmp == 0 ) {
    memset(used,false,sizeof(used));
    tmp = dfs(sink,source,1);
    memset(used,false,sizeof(used));
    tmp = dfs(u,v,1);
    assert(tmp);
    ret = true;
  } 
  remove_edge(u,v);
  return ret;
}

int main(){

  set<ii> S;
  scanf("%d %d %d",&V,&E,&Q);
  rep(i,E){
    int F,T;
    scanf("%d %d",&F,&T);
    --F, --T;
    add_edge(F,T,1);
    add_edge(T,F,1);
    if( F > T ) swap(F,T);
    S.insert(ii(F,T));
  }
  int source = 0, sink = V-1;
  int cur_flow = max_flow(source,sink);
  rep(_,Q){
    //cout << "query : " << _ << " ";
    int M,A,B;
    scanf("%d %d %d",&M,&A,&B);
    --A, --B;
    if( A > B ) swap(A,B);
    if( M == 1 ) { // 接続
      int F = A, T = B;
      if( S.count(ii(F,T)) ) {
        int pos = IINF;
        G[A][mp[ii(A,B)]].cap = 1;
        G[B][G[A][mp[ii(A,B)]].rev].cap = 0;
        G[B][mp[ii(B,A)]].cap = 1;
        G[A][G[B][mp[ii(B,A)]].rev].cap = 0;
      } else {
        add_edge(A,B,1);
        add_edge(B,A,1);
        S.insert(ii(F,T));
      }
      memset(used,false,sizeof(used));
      cur_flow += dfs(source,sink,IINF);
    } else {       // 切断
      bool res = remove(A,B,source,sink); //| remove(B,A,source,sink);
      if( res ) cur_flow--;
    }
    printf("%d\n",cur_flow);
  }

  return 0;
}

Measured memory_bytes: 6124
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  bool c=false;
  cin >> N;
  for (int i=0;i<N/7+1;i++){
    if((N-i*7)%4==0){
      cout <<"Yes"<<endl;
      c=true;
      break;
    }
  }
  if(c==false)cout << "No" << endl;

}  

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

using namespace std;

using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000007;
const static int INF = 1<<30;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

template<typename S, typename T, typename U> 
map<S, T> factorization(U p) {
    map<S, T> M;
    U i = 2;
    while (i * i <= p) {
        if (p % i == 0) {
            ++M[i];
            p /= i;
        } else {
            ++i;
        }
    }

    if (p != 1) ++M[p];

    return M;
}

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    llong a;
    string b;
    cin >> a >> b;

    llong b100 = (b[0] - '0')*100 + (b[2] - '0')*10 + (b[3] - '0');

    cout << a*b100/100LL << endl;

    return 0;
}

Measured memory_bytes: 3596
def main():
    N = int(input())
    A = list(map(int,input().split()))
    if 0 in A:
      print(0)
      return
    prod = 1
    for a in A:
      prod *= a
      if prod > 1000000000000000000:
        print(-1)
        return
    print(prod)

main()

Measured memory_bytes: 21480
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INFTY INT_MAX/10

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;


static const int MAX = 310;

int d[MAX][MAX];

void floyd(int (&d)[MAX][MAX], const int& n) {
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      //  経由地点k, スタートi,  目的地jを, 右から(jから)走破していく.
      if (d[i][k] == INFTY) continue;
      for (int j = 0; j < n; j++) {
        if (d[k][j] == INFTY) continue;
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}
// 初期化絶対忘れちゃダメ！！！
// initialization (inside main function)
// for (int i = 0; i < N; i++) {
//   for (int j = 0; j < N; j++) {
//     d[i][j] = (i == j ? 0 : INFTY);
//   }
// }

// for (int i = 0; i < M; i++) {
//   int a, b, t;
//   cin >> a >> b >> t;
//   a--; b--;
//   d[a][b] = t;
//   d[b][a] = t;
// }

int main() {
  int H, W; cin >> H >> W;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> d[i][j];
    }
  }

  floyd(d, 10);
  // for (int i = 0; i < 10; i++) {
  //   for (int j = 0; j < 10; j++) {
  //     cout << d[i][j] << " ";
  //   }
  //   cout << endl;
  // }

  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int m; cin >> m;
      if (m != -1 && m != 1) {
        ans += (d[m][1] == INFTY || d[m][1] < 0 ? 0 : d[m][1]);
      }
    }
  }

  cout << ans << endl;
}


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

int main()
{
    int n, count = 0, ans = 0;
    long long h;
    std::cin >> n;
    std::vector<long long> vec(n);
    for (int i = 0; i < n; i++) { std::cin >> vec[i]; }
    for (int i = 0; i < n - 1; i++)
    {
        if (vec[i] >= vec[i + 1]) { count++; }
        else
        {
            ans = std::max(ans, count), count = 0;
        }
    }
    ans = std::max(ans, count);
    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int n;cin>>n;
    ll m=0;ll a=0;ll r=0;ll c=0;ll h=0;
    rep(i,n){
        string s;cin>>s;
        if(s[0]=='M')m++;
        if(s[0]=='A')a++;
        if(s[0]=='R')r++;
        if(s[0]=='C')c++;
        if(s[0]=='H')h++;
    }
    ll ans=m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h;
    cout<<ans<<endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 	int N;
  cin >> N;
  	int x=0;
  for (int i = 0; i < N; i++) {
 	int l,r;
    cin >> l >> r;
    x += r;
    x-= l;
    x++;
 }
  cout << x << endl;
}

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

int A,B,i,j,k,l,c,S[200],L=200;
char R[200];
int main()
{
	for(;~scanf("%d%d",&A,&B);)
	{
		A*=10;
		for(c=0;A!=0&&c<L;c++)
		{
			S[c]=A/B;
			if(A%B==0)break;
			A=A%B*10;
		}
		if(c!=L)
		{
			for(i=0;i<=c;i++)printf("%d",S[i]);
			puts("");
			continue;
		}
		for(j=1;j<L;j++)
		{
			for(i=0;i<j+2;i++)
			{
				for(k=j+i;k<L;k++)
				{
					//printf("%d %d\n",S[k-j+i],S[k]);
					if(S[k-j]!=S[k])break;
				}
				if(k==L)
				{
					//printf("%d %d %d\n",j,i,k);
					for(l=0;l<i+j;l++)
						printf("%d",S[l]);
					puts("");
					for(l=0;l<i+j;l++)
						putchar(l<i?' ':'^');
					puts("");
					goto e;
				}
			}
		}
		e:;
	}
	return 0;
}

Measured memory_bytes: 612
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
const int M = 210000;
int main()
{
  int n;cin >> n;
  ll k;cin >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  map<int,vector<int>> mp;
  rep(i,n){
    mp[a[i]].push_back(i);
  }
  vector<int> edge(n);
  for(auto m:mp){
    int nn = m.second.size();
    rep(i,nn) edge[m.second[i]] = (m.second[(i+1)%nn]+1)%n;
  }
  //  rep(i,n) cout << i << ":" << edge[i] << "\n";

  vector<int> b(1,0);
  int v = 0;
  while(edge[v] - v >= 2) v = edge[v];
  if(v == n-1 && edge[v] == 0) b.push_back(-1);
  // if(v == n-1 && edge[v] == 0){
  //   b.push_back(-1);
  // }
  v = edge[v];
  b.push_back(v);  
  while(v!=0){
    while(edge[v] - v >= 2) v = edge[v];
    if(v == n-1 && edge[v] == 0) b.push_back(-1);
    v = edge[v];
    b.push_back(v);
  }
  // rep(i,b.size()) cout << b[i] << " ";
  // cout  << "\n";

  ll y = b.size()-1;
  ll x = (k%y + y - 1) % y;
  //  cout << x << "\n";
  int j = b[x];
  
  vector<int> res;
  while(j<n){
    if(j<0) break;
    if(edge[j] - j >= 2) j = edge[j];
    else if(edge[j] == 0 && j != n-1) break;
    else{
      res.push_back(a[j]);
      j++;
    }
  }

  rep(i,res.size()) cout << res[i] << " ";
  cout << "\n";
  
  return 0;
}


Measured memory_bytes: 26612
#include <cstdio>
#include <iostream>
using namespace std;
char s[110];
int n,pos,maxn;
int main()
{
	scanf("%d%s",&n,s+1);
	for(int i=1;i<=n;++i)
	{
		if(s[i]=='I') ++pos;
		else --pos;
		maxn=max(maxn,pos);
	}
	printf("%d\n",maxn);
	return 0;
}

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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


void solve(){
    ll n,m,x;
    cin>>n>>m>>x;

    Array c(n);
    Matrix a(n,Array(m,0));
    REP(i,n){
        cin>>c[i];
        REP(j,m) cin>>a[i][j];
    }

    ll ans=INF;

    ll al=1<<n;
    REP(bit,al){
        ll cost=0;
        Array y(m,0);
        REP(i,n){
            if((bit>>i) & 1){
                cost+=c[i];
                REP(j,m){
                    y[j]+=a[i][j];
                }
            }
        }

        bool flag=true;
        REP(i,m){
            if(y[i]<x){
                flag=false;
                break;
            }
        }
        if(flag) chmin(ans,cost);
    }

    cout<<(ans==INF?-1:ans)<<en;

}

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

    solve();
    //ll t;cin>>t;REP(i,t) solve();

    return 0;
}

Measured memory_bytes: 3664
fn solve(c: char) -> char {
    (c as u8 + 1) as char
}

#[test]
fn solve_test() {
    assert_eq!(solve('a'), 'b');
}

#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let c = read_line!();
    println!("{}", solve(c.chars().collect::<Vec<char>>()[0]));
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <bitset>
#include <stack>

using namespace std;

template<typename T> 
void show(T a){
  for(auto i : a){ cout << i << " "; }
  cout << endl;
}

long long sum = 0;
long long count = 0;

void add_num(string& s, bitset<12>&b ){
  int j = 0;
  for(int i = 0; i < s.size()-1; i++){
    if(b[i] == 1) {
      string num = s.substr(j, i-j+1);
      sum += stoll(num);
      j = i + 1;
    }
  }
  string num = s.substr(j, s.size()-j);
  sum += stoll(num);
}

void dfs(int pos, string& s, bitset<12>& b){
  if(pos >= s.size()) return;
  if(pos == s.size()-1){
    add_num(s, b);
  }
  b[pos] = 1;
  dfs(pos+1, s, b);
  b[pos] = 0;
  dfs(pos+1, s, b);
}

int main(int argc, char *argv[]){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  long long num;
  cin >> num;
  s = to_string(num);
  bitset<12> b(0);
  dfs(0, s, b);
  cout << sum << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef ONLINE_JUDGE
#define trace(...)
#endif

using LL = long long;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n, k; cin >> n >> k;
	int ans = 0;
	while (n--) {
		int x; cin >> x;
		if (x >= k) ans++;
	}
	cout << ans << endl;
	return 0;
}


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

int main()
{
   int x, y;
   cin >> x >> y;
   if(x==1)
   {
       if(y==2)
        cout << "3";
       else
        cout << "2";
   }
   else if(x==2)
   {
       if(y==1)
        cout << "3";
       else
        cout << "1";
   }
   else
   {
       if(y==1)
        cout << "2";
       else
        cout << "1";
   }
   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<climits>
#include<algorithm>
using namespace std;
int ans=INT_MAX;
int main(void){
int n;
  cin>>n;
  vector<int> a(n);
  for(int i =0;i<n;i++)cin>>a[i];
  for(int i =-100;i<=100;i++){
      int tmp=0;
        for(int j =0;j<n;j++)tmp+=(a[j]-i)*(a[j]-i);
      ans=min(ans,tmp);
    }
  cout <<ans<<endl;
  return 0; 
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn = 2e6 + 10;
using namespace std;
int n, m, k, t, h[maxn], tot, ans[maxn];
set<int>comp[maxn];
struct node
{
        int to, nxt, com;
} e[maxn << 2];
void add(int x, int y, int z)
{
        tot++;
        e[tot].to = y;
        e[tot].com = z;
        e[tot].nxt = h[x];
        h[x] = tot;
}
priority_queue<pair<int, int> >p;
int main()
{
        int i, j;
        while (scanf("%d %d", &n, &m) == 2)
        {
                //cout << n << " " << m << endl;
                for (int i = 1; i <= n; i++)
                {
                        h[i] = 0;
                        ans[i] = inf;
                        comp[i].clear();
                }
                tot = 0;
                while (m--)
                {
                        int a, b, c;
                        scanf("%d%d%d", &a, &b, &c);
                        add(a, b, c);
                        add(b, a, c);
                }
                p.push({0, 1});
                ans[1] = 0;
                while (!p.empty())
                {
                        int now = p.top().se, ca = -p.top().fi;
                        p.pop();
                        if (ans[now] < ca)
                        {
                                continue;
                        }
                        for (i = h[now]; i; i = e[i].nxt)
                        {
                                int to = e[i].to, to_com = e[i].com;
                                int to_ca = ca + (!comp[now].count(to_com));
                                if (ans[to] > to_ca)
                                {
                                        ans[to] = to_ca;
                                        p.push({ -to_ca, to});
                                        comp[to].clear();
                                        comp[to].insert(to_com);
                                }
                                else if (ans[to] == to_ca)
                                {
                                        comp[to].insert(to_com);
                                }
                        }
                }
                printf("%d\n", ans[n] == inf ? -1 : ans[n]);
        }
        //system("Pause");
        return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

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

#define int long long
signed main(){
//int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,wlim;
    cin >> n >> wlim;
    vector<int> w(n);
    vector<int> v(n);
    for(int i = 0; i < n; i++) {
        cin >> w[i] >> v[i];
    }

    int dp[n+5][n+5][3*n+15];

    for(int i = 0; i < n; i++) {
        for(int j = 0; j <= i; j++) {
            for(int k = 0; k <= 3*n; k++) {
                int rem=w[i]-w[0];
                chmax(dp[i+1][j][k], dp[i][j][k]);
                chmax(dp[i+1][j+1][k+rem], dp[i][j][k] + v[i]);
            }
        }
    }

    int ans=0;
    for(int j = 0; j <= n ; j++) {
        for(int k = 0; k <= 3*n ; k++) {
            if(j*w[0]+k <= wlim) ans=max(ans,dp[n][j][k]);
        }
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 16420
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long int H, N;
  cin >> H >> N;
  for (int i = 0; i < N; i++)
  {
    int a;
    cin >> a;
    H -= a;
  }
  if (H <= 0)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import Data.List

solve :: Int -> Int -> Int
solve n k
  | k == 0 = n
  | otherwise = solve (n * 2) (k - 1)

main = do
  ss <- (map read . words) <$> getLine
  k <- readLn :: IO(Int)
  print $ (solve (maximum ss) k) + (sum (take 2 (sort ss)))

Measured memory_bytes: 3932
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x1 uvuvwevwevwe
#define y1 onyetenyevwe
#define x2 ugwemubwem
#define y2 ossas
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
template <typename T> void scan(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void scan(T1 &angka1,T2 &angka2){
	scan(angka1);scan(angka2);
}
int digit;
char respon;
bool benar;
void tanya(LL angka){
	cout<<"? "<<angka<<endl;
	fflush(stdout);
	cin>>respon;
	benar=(respon=='Y');
}
int caripanjangdigit(){
	int angka=1;
	for(int i=1;i<=10;i++)
	{
		tanya(angka);
		if(!benar)
			return i-1;
		angka*=10;
	}
	angka=2;
	for(int i=1;i<=10;i++)
	{
		tanya(angka);
		if(benar)
			return i;
		angka*=10;
	}
	assert(false);
}
int main()
{
	digit=caripanjangdigit();
	LL bawah=1,atas=9,mid;
	for(int i=0;i<digit-1;i++)
	{
		bawah*=10LL;
		atas=atas*10LL+9;
	}
	while(bawah<=atas)
	{
		mid=(bawah+atas)>>1;
		tanya(mid*10LL);
		if(benar)
			atas=mid-1;
		else
			bawah=mid+1;
	}
	cout<<"! "<<bawah<<endl;
}

Measured memory_bytes: 596
// https://atcoder.jp/contests/abc121/tasks/abc121_c

#include <bits/stdc++.h>
#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 INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

ll N, M, A, B, j, sum, csum;
vector<pll> d;
int main()
{
  sum = csum = 0;

  cin >> N >> M;

  REP(i, N)
  {
    cin >> A >> B;
    d.push_back(make_pair(A, B));
  }

  sort(ALL(d));

  REP(i, N)
  {
    if (M < sum + d[i].second)
    {
      csum += d[i].first * (M - sum);
      break;
    }
    else
    {
      sum += d[i].second;
      csum += d[i].first * d[i].second;
    }
  }

  cout << csum << '\n';

  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int Mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007

#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

vi adj[Mx];
bool vis[Mx];

void dfs ( int u )
{
    vis[u] = 1;
    for ( auto v : adj[u] ) {
        if ( !vis[v] ) dfs ( v );
    }
}


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

    for ( int i = 1; i <= m; i++ ) {
        int u, v;
        cin >> u >> v;

        adj[u].pb ( v );
        adj[v].pb ( u );
    }

    int cnt = 0;
    for ( int i = 1; i <= n; i++ ) {
        if ( !vis[i] ) {
            dfs ( i );
            cnt++;
        }
    }

    cout << cnt-1 << nl;
}

int main()
{
    fio;
    solve();
    return 0;
}


Measured memory_bytes: 30720
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	void run() {
		Scanner sc = new Scanner (System.in);
		while(sc.hasNext()) {
			String line = sc.nextLine();
			String[] elements = line.split(" ");
			LinkedList<Double> stack = new LinkedList<Double>();
			for(String element: elements) {
				if( element.equals("/") ) {
					double s = stack.removeLast();
					double f = stack.removeLast();
					double v = f / s;
					stack.addLast(v);
				}
				else if( element.equals("*") ) {
					double s = stack.removeLast();
					double f = stack.removeLast();
					double v = f * s;
					stack.addLast(v);
				}
				else if( element.equals("+") ) {
					double s = stack.removeLast();
					double f = stack.removeLast();
					double v = f + s;
					stack.addLast(v);
				}
				else if( element.equals("-") ) {
					double s = stack.removeLast();
					double f = stack.removeLast();
					double v = f - s;
					stack.addLast(v);
				}
				else stack.addLast(Double.parseDouble(element));
			}
			System.out.println(stack.removeLast());
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
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()))
MOD = 10**9 + 7

n = INT()
a = LIST()

res = 0
for i in range(n):
    res = res ^ a[i]

for i in range(n):
    print(res ^ a[i], end = " ")

Measured memory_bytes: 97780
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD1 1000000007


int main() {
  string s;
  cin >> s;

  int l=0,m=-200000,ans=0;
  bool f = true;

  for(int i=0; i < s.size();i++){
    if(s[i] == 'A' && f){
      l = i;
      f = false;
    }
    if(s[i] == 'Z'){
      m = i;
      ans = max(ans,m-l+1);
    }
  }

  cout << ans << endl;  

}


Measured memory_bytes: 640
#include <math.h>
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX / 2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using psi = pair<string, int>;

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a%b);
}

void prime_factorize(map<ll,ll>& fac, ll n) {
    for(ll p = 2; p*p <= n; p++) {
        //if (is_prime(p)) {
        if (n%p != 0) continue; // p is not n's devisor
        else {
            while(n%p == 0) {
              fac[p]++;
              n /= p;
            }
        }
    }
    if (n > 1) fac[n]++;
}


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

  ll A,B; cin >> A >> B;

  ll C = gcd(A, B);
  
  map<ll,ll> mp;
  prime_factorize(mp, C);

  int ans = mp.size() + 1;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main()
{
    char c[4];
    for(int i=0;i<4;i++)    scanf("%c",&c[i]);
    if(c[0]==c[1]&&c[1]==c[2]||c[1]==c[2]&&c[2]==c[3])
         printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

long long n, a, dp[2005][2005];
vector <pair<int, int> > v;

long long solve(int l, int r){
    if (~dp[l][r]) return dp[l][r];
    if (l > r) return dp[l][r] = 0;
    int idx = (r-l);
    return dp[l][r] = max(solve(l+1, r) + (long long)abs(v[idx].second-l)*v[idx].first , solve(l, r-1) + (long long)abs(r-v[idx].second)*v[idx].first);
}

int main() {
    cin >> n;
    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < n; i++){
        cin >> a;
        v.push_back({a, i});
    }
    sort(v.begin(), v.end());
    cout << solve(0, n-1) << "\n";
}


Measured memory_bytes: 35152
x,y=map(int,input().split())

if ((4*x-y)%2==0 and (-2*x+y)%2==0) and (1<=(4*x-y)//2<=100 and 1<=(-2*x+y)//2<=100):
    print('Yes')
elif ((4*x-y)%2==0 and (-2*x+y)%2==0) and (1<=(4*x-y)//2<=100 and (-2*x+y)//2==0):
    print('Yes')
elif ((4*x-y)%2==0 and (-2*x+y)%2==0) and ((4*x-y)//2==0 and 1<=(-2*x+y)//2<=100):
    print('Yes')
else :
    print('No')


Measured memory_bytes: 9172
#include <iostream>
#include <string>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int main()
{
  string s;
  cin >> s;
  while (true) {
    s.erase(s.end() - 1);
    int len = s.length();
    if (len % 2 != 0) continue;
    // cout << s.substr(0, len / 2) << " " << s.substr(len / 2) << endl;
    if (s.substr(0, len / 2) == s.substr(len / 2)) {
      cout << len << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
//LETS START AGAIN
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define F first 
#define S second
#define int long long int
int h,w;
char mat[51][51];
int visit[51][51];
int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};
signed main() 
{ 
    fast;
    cin>>h>>w;
    int b = 0;
    int dist[h+1][w+1];
    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++)
        {
            cin>>mat[i][j];
            if(mat[i][j] == '#')
                b++;
            dist[i][j] = 1e18;
        }
    queue<pii> q;
    q.push({1,1});
    dist[1][1] = 0;
    while(!q.empty())
    {
        pii u = q.front();
        int x = u.first;
        int y = u.second;
        if(x == h && y == w)
            break;
        if(visit[x][y])
        {
            q.pop();
            continue;
        }
        visit[x][y] = 1;
        q.pop();
        for(int i = 0;i<4;i++)
        {
            int nx = x+dx[i];
            int ny = y+dy[i];
            if(nx>=1 && nx<=h && ny>=1 && ny<=w)
            {
                if(!visit[nx][ny] && mat[nx][ny] == '.')
                {
                    dist[nx][ny] = 1+dist[x][y];
                    q.push({nx,ny});
                }
            }
        }
    }
    if(dist[h][w] == 1e18)
        cout<<-1;
    else
    {
        //cout<<dist[h][w];
        int wrem = (h*w-b)-(dist[h][w]+1);
        cout<<wrem;
    }

} 



Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll n,k,ans=0;
  cin >> n >> k;
  vector<ll> a(n),s(n+1,0);
  map<ll,ll> mp;
  for(int i=0;i<n;i++){
    cin >> a[i];
    s[i+1] = s[i]+a[i];
  }
  mp[0]++;
  for(int i=1;i<=n;i++){
    ll v = i-k,vv=(s[i]-i)%k;
    if(v>=0) mp[(s[v]-v)%k]--;
    ans += mp[vv];
    mp[vv]++;
  }
  cout << ans << endl;
}


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

bool Palindrome(string s) {
  string t = s;
  reverse(t.begin(), t.end());
  return s == t;
}

int main() {

  string s;
  cin >> s;
  bool ans = true;
  if (!Palindrome(s)) ans = false;
  if (!Palindrome(s.substr(0, s.size()/2))) ans = false;
  
  cout << (ans ? "Yes" : "No") << endl;   

}


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

const ll INF = 1LL << 60;

class UnionFind {
    public:
        vector<ll> Parent;
        UnionFind(ll N) {
            Parent = vector<ll>(N, -1);
        }

        ll root(ll A) {
            if (Parent[A] < 0) return A;
            return Parent[A] = root(Parent[A]);
        }

        ll size(ll A) {
            return -Parent[root(A)];
        }

        bool unite(ll A, ll B) {
            A = root(A);
            B = root(B);

            if (A == B) {
                return false;
            }

            if (size(A) < size(B)) swap(A, B);

            Parent[A] += Parent[B];
            Parent[B] = A;

            return true;
        }
};

ll N, M;
int main() {
    cin >> N >> M;
    vector<P> v;
    rep(i, M) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        v.push_back(P(a, b));
    }

    ll ans = 0;
    rep(i, M) {
        UnionFind uf2 = UnionFind(N);
        rep(j, M) {
            if (i == j) continue;
            uf2.unite(v[j].first, v[j].second);
        }
        if (uf2.size(v[i].first) == N) continue;
        // if (uf2.size(v[i].second) == N) continue;

        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/*
 * zyrch - Rupanshu Yadav
 */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <utility>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <cassert>
#include <sstream>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

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

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

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

#define forn(i,a,b) for (int i = (a); i < ll(b); ++i)
#define fo(i,a) forn(i,0,ll(a))
#define rforn(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define ro(i,a) rforn(i,0,a)
#define trav(a,x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define s second

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

const ll INF = 1e18;

ll mod = 1000000007;
inline ll fast_expo(ll base,ll power,ll modulo=mod){
    base%=modulo;
    if (base<0) base+=modulo;
    ll x=base,cnt=power,ans=1;
    while(cnt){
        if (cnt&1) ans=(ans*x)%modulo;
        x=(x*x)%modulo;
        cnt>>=1;
    }
    return ans;
}

ll takemod(ll a, ll mo){
	a %= mo;
	if(a < 0) a+=mo;
	return a;
}

// if mod is prime
ll modinv(ll a, ll mo){
	return takemod(fast_expo(takemod(a,mo), mo-2, mo), mo);
}

//=========================CODE STARTS HERE=============================//

int main() {
	
	db l;
	cin >> l;
	l/=3;
	cout << setprecision(10) << double(pow(l, 3.0)) << endl;
	
	return 0; 
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int N;
    cin >> N;
    
    vector<vector<long long int> > vec(10, vector<long long int>(10, 0));
    for(int n=1; n<=N; n++) {
        int sn=n;
        while(sn/10!=0) {
            sn/=10;
        }
        vec[sn][n%10]++;
    }
    
    long long int ans=0;
    for(int i=1; i<10; i++) {
        for(int j=1; j<10; j++) {
            ans += vec[i][j]*vec[j][i];
        }
    }
    
    cout << ans << endl;


    return 0;
    
}

Measured memory_bytes: 256
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
template <typename T>
void ContainerError(T &v){cout<<"{";for(auto &x:v){cout<<x<<',';}cout<<"}"<<endl;return;}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll mpow(ll base,ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return (res);}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    vector<ll> v(n);
    map<ll,ll> m;
    for(auto &x:v)
    {
        cin>>x;
        m[x]++;
    }
    vector<ll> pre;
    for(auto &x:m)
    {
        pre.pb(x.se);
    }
//    ContainerError(pre);
    sort(pre.begin(),pre.end());
    ll N = pre.size();
    vector<ll> pre2(N,0);
    pre2[0] = pre[0];
    for(ll i=1;i<N;i++)
    {
        pre2[i] = pre2[i-1] + pre[i];
    }
    cout<<n<<endl;
    for(ll k=2;k<=n;k++)
    {
        ll be = 1;
        ll op = 0;
        ll en = n;
        if(N<k)
        {
            cout<<0<<endl;
            continue;
        }
        while(be<=en)
        {
            ll mid = (be+en)/2;
            ll in = N;
            ll start = 0;
            ll end = N-1;
            while(start<=end)
            {
                ll Mid = (start+end)/2;
                if(pre[Mid]>=mid)
                {
                    in = Mid;
                    end = Mid-1;
                }
                else
                {
                    start = Mid+1;
                }
            }
            ll z = N-in;
            z += (pre2[in-1]/mid);
            if(z >= k)
            {
                be = mid+1;
                op = mid;
            }
            else
            {
                en = mid-1;
            }
        }
        cout<<op<<endl;
    }
    return 0;
}































Measured memory_bytes: 26860
#include<bits/stdc++.h>
using namespace std; 
//Important observation about this question is, it's enough
//to know whether given subset of rabits either belong
//to any group or doesn't belong to any group, in that way
//you will have 2^n subsets (where 0 represents they donot
//belong to any group and 1 represents they belong to some
//group, keep in mind we don't care which group, because
//in the process of transition we would have considered
//the best way to group all those already grouped rabbits)
//going from 0 to 2^n-1, first we will have none of them
//belonging to any group, i.e 0 and we find all the subsets
//of rabbits not belonging to any group and update the 
//max of the current mask, which also contains all the already
//available rabbits. This works because if the current group
//of rabbits which were formed from non-grouped rabbits 
//is better than including both these and already grouped rabbits
//then we can just put those already grouped rabbits
//in different groups and their max score of the group
//they belong will be 0
//Time complexity : O(2^(2n)+2^(n)n^2)
//Source : Errichto's youtube stream
vector<long long> dp;
vector<long long> pre;
long long score_so_far;
void group(int i,const vector<int>& not_grouped,int mask,int cur_group){
    if(i==not_grouped.size()){
        dp[mask] = max(dp[mask],score_so_far+pre[cur_group]);
        return;
    }
    group(i+1,not_grouped,mask,cur_group);
    group(i+1,not_grouped,mask^(1<<not_grouped[i]),cur_group^(1<<not_grouped[i]));
}
int main(){
    int n;
    cin>>n;
    int a[n][n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>a[i][j];
        }
    }
    dp.resize(1<<n,LONG_LONG_MIN);
    pre.resize(1<<n,0);
    for(int mask=0;mask<(1<<n);mask++){
        for(int i=0;i<n;i++){
            if(mask&(1<<i)){
                for(int j=i+1;j<n;j++){
                    if(mask&(1<<j)){
                        pre[mask]+=a[i][j];
                    }
                }
            }
        }
    }
    dp[0] = 0;
    for(int mask=0;mask<(1<<n);mask++){
        vector<int> not_grouped;
        for(int i=0;i<n;i++){
            if(!(mask&(1<<i))){
                not_grouped.push_back(i);
            }
        }
        score_so_far = dp[mask];
        group(0,not_grouped,mask,0);
    }
    cout<<dp[(1<<n)-1]<<"\n";
    return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

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

int n;
vector<int> g[100000];
int dp[100000];

int dfs(int v) {
	if(dp[v]!=-1) return dp[v];
	if(g[v].size()==0) return dp[v]=0;
	vector<int> vec;
	for(auto u:g[v]) vec.pb(dfs(u));
	sort(ALL(vec));reverse(ALL(vec));
	int ma=0;
	REP(i,vec.size()) ma=max(ma,vec[i]+i+1);
	return dp[v]=ma;
}

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

	cin>>n;
	FOR(i,1,n) {
		int a;cin>>a;
		a--;
		g[a].pb(i);
	}
	REP(i,n) dp[i]=-1;
	cout<<dfs(0)<<endl;

	return 0;
}


Measured memory_bytes: 15488
T1,T2,A1,A2,B1,B2=map(int, open(0).read().split())
C1,C2=A1-B1,A2-B2
if C1<0: C1,C2=-C1,-C2
Y1=C1*T1
Y2=Y1+C2*T2
if Y2>0:
    print(0)
elif Y2==0:
    print("infinity")
else:
    print(1+Y1//(-Y2)*2-(Y1%(-Y2)==0))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int d = sc.nextInt();
		switch (d) {
		case 25:
			System.out.println("Christmas");
			break;
		case 24:
			System.out.println("Christmas Eve");
			break;
		case 23:
			System.out.println("Christmas Eve Eve");
			break;
		case 22:
			System.out.println("Christmas Eve Eve Eve");
			break;
		default:
			break;
		}
	}
}

Measured memory_bytes: 22100
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;

int gcd(int x, int y);

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    ll x, y;
    cin >> x >> y;
    int ans = 0;
    for (ll i = x; i <= y; i *= 2) {
        ans++;
    }

    cout << ans << endl;
    return 0;
}
/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    int N;
    cin >> N;
    int sum = 0;
    int remove_num = 0;
    int mx = 0;
    //入力が1の場合はコーナーケースとして処理
    if(N == 1){
        cout << 1 << endl;
        return 0;
    }
    //入力が2以上の場合
    for(int i = 1; i <= N; i++){
        sum += i;
        mx = i;
        if(sum == N) break;
        else if(sum > N){
            remove_num = sum - N;
            break;
        }
    }
    for(int i = 1; i <= mx; i++){
        if(i == remove_num) continue;
        else{
            cout << i << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3604