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

int a[100001], b[100001], par[100001], size[100001];
long long ans[100001];

int find(int x){
    if(par[x] == x){
        return x;
    }else{
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y){
    par[y] = x;
    size[x] += size[y];
    return;
}

int main(){
    int n, m, i, x, y;
    cin >> n >> m;
    for(i=0; i<m; i++){
        cin >> a[i] >> b[i];
    }
    for(i = 1; i<=n; i++){
        size[i] = 1;
        par[i] = i;
    }
    ans[m] = (long long)n*(long long)(n-1)/2;
    for(i=m-1; i>=0; i--){
        x = find(a[i]);
        y = find(b[i]);
        if(x != y){
            ans[i] = ans[i+1] - (long long)size[x]*(long long)size[y];
            unite(x,y);
        }else{
            ans[i] = ans[i+1];
        }
    }
    for(i=0; i<m; i++){
        cout << ans[i+1] << '\n';
    }
    return 0;  
}

Measured memory_bytes: 3712
// https://atcoder.jp/contests/abc126/tasks/abc126_c
#include <bits/stdc++.h>
using namespace std;

int main(void){
  int N, K;
  cin >> N >> K;
  long double prob = 0.0;

  for (int i = 1; i < N + 1; i++){
    int P = i;
    int count = 0;
    while(P < K){
      P *= 2;
      count++;
    }
    prob += (1.0/N * pow(1.0/2.0, count));
  }

  cout << fixed << setprecision(12) << prob << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

using namespace std;

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

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

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];
int a,b,c,d,e,f,index=0;
int main(){
    int sum[100];
    int max_i,max_sugar=0,max_sum=0;
    double ratio=0;
    cin>>a>>b>>c>>d>>e>>f;
    for(int i=0;f>=i*100*a;i++){
        for(int j=0;f>=i*100*a+j*100*b;j++){
            for(int k=0;f>=i*100*a+j*100*b+k*c;k++){
                for(int l=0;f>=i*100*a+j*100*b+k*c+l*d;l++){
                    sum[index]=i*100*a+j*100*b+k*c+l*d;
                    if(double(e)/(100+e)>=(k*c+l*d)/(double)(i*100*a+j*100*b+k*c+l*d)){
                        if(ratio<(double)(k*c+l*d)/(i*100*a+j*100*b+k*c+l*d)){
                            max_i = index;
                            max_sugar = (k*c+l*d);
                            max_sum = sum[max_i];
                            ratio =  (double)max_sugar/(double)sum[max_i];
                        }
                    }
                    index++;
                }
            }
        }
    }
    cout<<((max_sum > 100*a) ? max_sum : 100*a)<<" "<<max_sugar<<endl;
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<unordered_set>
#include<unordered_map>
#include<algorithm>
#include<limits.h>
using namespace std;

const long long TOTALDAYS = 5000000000000000;

int main()
{
	string str;
	long long K;
	cin >> str >> K;
	int len = str.size();
	long long preSumLen = 0;
	for (int i = 0;i < len;i++)
	{
		long long day = 0;
		long long curLen = 1;
		while (day < TOTALDAYS && preSumLen + curLen < K)
		{
			if (str[i] == '1') break;
			curLen = curLen * (str[i] - '0');
			day++;
		}
		if (preSumLen + curLen >= K)
		{
			cout << str[i] << endl;
			break;
		}
		preSumLen += curLen;
	}
	return 0;
}

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

public class Main {
	static BufferedReader br;
	static StringTokenizer tokenizer;

	public static void main(String[] args) throws Exception {
		br = new BufferedReader(new InputStreamReader(System.in));
		int n = nextInt();
		int[] arr = new int[n];
		int[] dp = new int[n];
		for(int i = 0; i < n; i++) {
			arr[i] = nextInt();
			dp[i] = Integer.MAX_VALUE;
		}
		dp[0] = 0;
		for(int i = 0; i < n - 2; i++) {
			dp[i + 1] = Math.min(dp[i + 1], Math.abs(arr[i] - arr[i + 1]) + dp[i]);
			dp[i + 2] = Math.min(dp[i + 2], Math.abs(arr[i] - arr[i + 2]) + dp[i]);
		}
		dp[n - 1] = Math.min(dp[n - 1], Math.abs(arr[n - 2] - arr[n - 1]) +dp[n - 2]);
		System.out.println(dp[n - 1]);
	}

	public static String next() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			String line = br.readLine();
			if (line == null)
				throw new IOException();
			tokenizer = new StringTokenizer(line);
		}
		return tokenizer.nextToken();
	}

	public static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
}


Measured memory_bytes: 32096
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#define maxn 100005
#define ll long long
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
   priority_queue<int>q;
    for(int i=1;i<=n;i++)
    {
        int c;
        scanf("%d",&c);
        q.push(c);
    }
    ll sum=1;
    int cnt=1;
    ll f1,f2;
    f2=q.top();
    q.pop();
    int cc=0;
    int flag=0;
    while(!q.empty())
    {
        f1=q.top();//cout<<f2<<" "<<f1<<endl;
        q.pop();
        if(f1==f2) cnt++;
        if(f1!=f2||q.empty())
        {
           // cout<<"dsd "<<cnt<<endl;
            if(cnt>=2)
            {
                cc++;
                sum*=f2;
            }
            if(cnt>=4)
            {
                sum=max(f2*f2,sum);
                cc=2;
            }
           if(cc==2)
           {
               flag=1;
               break;
           }
           cnt=1;
        }
        f2=f1;
}
    if(!flag) printf("0\n");
    else
    printf("%lld\n",sum);
    return 0;
}


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

int main()
{
    int N, K;
    cin >> N >> K;
    int snuke[N];
    for (int i = 0; i < N; i++)
    {
        snuke[i] = 0;
    }

    for (int i = 0; i < K; i++)
    {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++)
        {
            int sn;
            cin >> sn;
            snuke[sn - 1]++;
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (snuke[i] == 0)
        {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#define ll long long 
using namespace std;
void isN(int n){
	while(n){
		if(n%10==7)
		  {
		  	cout<<"Yes\n";
		  	return ;
		  }
		  n/=10;
	}
	cout<<"No\n";
	return ;
}
int main(){
	ll A;
	cin>>A;
	ll ans=(1+A)*(A)/2;
	ll a=3;
	ll b=5;
	ll c=15;
	while(a<=A)
	{
		ans-=a;
		a=a+3;
	}
	while(b<=A)
	{
		ans-=b;
		b=b+5;
	}
	while(c<=A)
	{
		ans+=c;
		c=c+15;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  long long w = 0, ans = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'W') {
      ans += i - w;
      w++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
n = int(input())
b= list(map(int, input().split()))

v = []
while b:
    x = -1
    for i in range(len(b)):
        if b[i] == i + 1:
            x = i

    if x == -1:
        print(-1)
        exit()

    v.append(b[x])
    del b[x]

for e in reversed(v):
    print(e)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(){
  int c[3][3];
  int i,j;
  int c_min[3]={100,100,100};
  for(i = 0;i < 3;i++){
    for(j = 0;j < 3;j++){
      cin >> c[i][j];
      if(c_min[i] > c[i][j]) c_min[i] = c[i][j];
    }
  }
  int l,m,n;
  for(i = 0;i < 3;i++){
    l = c[0][i] -c_min[0];
    m = c[1][i] -c_min[1];
    n = c[2][i] -c_min[2];

    if(l != m || m != n){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 400009
#define ll long long
#define mod 998244353
#define cbn(x,y) ((ll)fac[x]*inv[y]%mod*inv[(x)-(y)]%mod)
using namespace std;

int m,n,a[N],b[N],fac[N],inv[N]; char A[N],B[N],C[N],D[N];
int solve(int m,int n,char *A,char *B,char *C,char *D){
	int i,x,y;
	memset(a,0,sizeof(a)); memset(b,0,sizeof(b));
	a[0]=b[n+1]=1;
	for (i=1,y=0; i<=m; i++) if (A[i]=='1') y++;
	for (i=1,x=0; i<=n; i++){
		if (C[i]=='1') x++;
		if (D[i]=='1') x++;
		a[i]=cbn(x+y,x);
		if (x) a[i]=(a[i]-cbn(x+y-1,x-1)+mod)%mod;
		//cout<<i<<' '<<a[i]<<endl;
	}
	for (i=1,y=0; i<=m; i++) if (B[i]=='1') y++;
	for (i=n,x=0; i; i--){
		if (C[i]=='1') x++;
		if (D[i]=='1') x++;
		b[i]=cbn(x+y,x);
		if (x>0) b[i]=(b[i]-cbn(x+y-1,x-1)+mod)%mod;
		//cout<<i<<' '<<b[i]<<endl;
	}
	int tmp;
	for (i=0,tmp=1; i<=n; i++){
		if (i>0 && C[i]=='1' && D[i]=='1') tmp=(ll)tmp*(mod+1>>1)%mod;
		a[i]=(ll)a[i]*tmp%mod;
		if (i<=n && C[i+1]=='0' && D[i+1]=='0') a[i]=0;
	}
	for (i=1; i<=n; i++) a[i]=(a[i]+a[i-1])%mod;
	for (i=tmp=1; i<=n+1; i++){
		b[i]=(ll)b[i]*tmp%mod;
		if (i<=n && C[i]=='1' && D[i]=='1') tmp=tmp*2%mod;
		if (i>1 && C[i-1]=='0' && D[i-1]=='0') b[i]=0;
	}
	int ans=0;
	for (i=1; i<=n; i++) ans=(ans+(ll)b[i+1]*a[i-1])%mod;
	//cout<<ans<<endl;
	return ans;
}
int main(){
	scanf("%d%d",&m,&n);
	scanf("%s%s%s%s",A+1,B+1,C+1,D+1);
	int i;
	for (i=1; i<=m; i++) if (A[i]=='1' || B[i]=='1') break;
	if (i>m){
		for (i=1; i<=n; i++) if (C[i]=='1' || D[i]=='1') break;
		if (i>n){ puts("1"); return 0; }
	}
	fac[0]=inv[0]=inv[1]=1;
	for (i=1; i<=(m+n<<1); i++) fac[i]=(ll)fac[i-1]*i%mod;
	for (i=2; i<=(m+n<<1); i++) inv[i]=mod-(ll)inv[mod%i]*(mod/i)%mod;
	for (i=2; i<=(m+n<<1); i++) inv[i]=(ll)inv[i-1]*inv[i]%mod;
	printf("%d\n",(solve(m,n,A,B,C,D)+solve(n,m,C,D,A,B))%mod);
	return 0;
}

Measured memory_bytes: 6912
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

#[fastout]
pub fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }
    let mut a: Vec<_> = a.into_iter().enumerate().collect();
    a.sort_by_key(|&(_, a)| a);
    println!("{}", a.iter().map(|&(i, _)| format!("{}", i + 1)).join(" "));
}


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

#define N 4
#define N2 16
#define LIMIT 100

int MD[N2][N2];
int limit;
vector<int> path(LIMIT, -1);

static const int dx[4] = {-1, 0, 1, 0};
static const int dy[4] = {0, -1, 0, 1};
static const char dir[4] = {'u', 'l', 'd', 'r'};

struct Puzzle {
    int f[N2];
    string path;
    int space;
};

struct State {
    Puzzle p;
    int estimated;
};

State state;

int getAllMD(Puzzle p) {
    int x, md = 0;
    for (int i = 0; i < N2; i++) {
        x = p.f[i];
        if (x == N2) continue;
        md += MD[x - 1][i];
    }
    return md;
}

bool dfs(int depth, int prev) {
    if (state.estimated == 0) {
        return true;
    }

    if (state.estimated + depth > limit) return false;

    int spaceX = state.p.space / N;
    int spaceY = state.p.space % N;

    int nextX, nextY;
    for (int r = 0; r < 4; r++) {
        nextX = spaceX + dx[r];
        nextY = spaceY + dy[r];
        if (nextX < 0 || nextX >= 4 || nextY < 0 || nextY >= 4) {
            continue;
        }
        if (max(prev, r) - min(prev, r) == 2) continue;

        State tmp = state;
        state.estimated -= MD[nextX * N + nextY][state.p.f[nextX * N + nextY] -1];
        state.estimated += MD[spaceX * N + spaceY][state.p.f[nextX * N + nextY] -1];
        state.p.space = nextX * N + nextY;
        swap(state.p.f[nextX * N + nextY], state.p.f[spaceX * N + spaceY]);
        if (dfs(depth + 1, r)) {
            path[depth] = r;
            return true;
        }

        state = tmp;
    }

    return false;
}

string iterative_deepening(Puzzle start) {
    state.p = start;
    state.estimated = getAllMD(start);

    for (limit = state.estimated; limit <= LIMIT; limit++) {
        if (dfs(0, -100)) {
            string ans = "";
            for (int i = 0; i < limit; i++) {
                if (path[i] == -1) break;
                ans += dir[path[i]];
            }
            return ans;
        }
    }

    return "";
}

int main() {
    for (int i = 0; i < N2; i++) {
        for (int j = 0; j < N2; j++) {
            MD[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
        }
    }

    Puzzle start;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> start.f[i * N + j];
            if (start.f[i * N + j] == 0) {
                start.space = i * N + j;
                start.f[i * N + j] = N2;
            }
        }
    }

    cout << iterative_deepening(start).length() << endl;

    return 0;
}


Measured memory_bytes: 3220
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>

using namespace std;

using ll = long long int; 

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}


ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

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

   string s;
   cin>>s;

    int count = 0;
    int piv = 0;
   for(int i=0;i<n;i++){
       //cout<<s[i]<<" ";
       if(s[i] == s[i+1]){
           piv = 1;
       }else{
           //if(piv == 1){
               count++;
               piv = 0;
           //}
       }
     
   }

   cout<<count<<endl;

    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
		try{
			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			long[] list = new long[N];
			for(int i = 0; i < N; i++){
				list[i] = sc.nextLong();
			}
			StringBuilder result = new StringBuilder(list[N-1]+"");
			int index = N-3;
			for(int i = 1; i < N; i++){
				result.append(" "+list[index]);
				if(index == 0){
					if(N%2 == 0){
						index = 2;
					}else{
						index = 1;
					}
				}else if(index%2 == N%2){
					index += 2;	
				}else{
					if(index != 1){
						index -= 2;
					}else{
						index = 0;
					}
				}
			}
			System.out.println(result.toString());
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 98236
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    ll n;
    cin >> n;
    vector<ll> v(n);
    rep(i, 0, n)
        cin >> v[i];
    vector<ll> dp1(n-1);
    vector<ll> dp2(n-1);
    dp1[0] = v[0];
    dp2[0] = v[n - 1];
    rep(i, 1, n - 1)
        dp1[i] = dp1[i-1] + v[i];
    rep(i, 1, n - 1)
        dp2[i] = dp2[i-1] + v[n-i-1];
    // rep(i, 0, n)
    //     cout << dp1[i] << " ";
    // cout << endl;
    // rep(i, 0, n)
    //     cout << dp2[i] << " ";
    ll ans = INT_MAX;
    rep(i, 0, n-1)
        ans = min(ans, abs(dp1[i]-dp2[n-2-i]));
        // cout << dp1[i] << " " << dp2[n-2-i] << endl;
    
    cout << ans;
    return 0;
}

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

int main() {
  int N, Norg;
  int sum = 0;
  cin >> N;
  Norg = N;
  while (N > 0) {
    sum += N % 10;
    N /= 10;
  }
  if (Norg % sum == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main()
{
    long long n,i,seven=0,rem=0;
    scanf("%lld", &n);
    if(n%2==0) printf("-1");
    else
    {
        for(i=1; i<=1000000; i++)
        {
            seven=seven*10+7;
            seven%=n;
            if(seven==0) {printf("%lld",i); return 0;}
        }
        printf("-1");
    }
}


Measured memory_bytes: 1736
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>

using namespace std;

struct Node{
	int key;
	Node *right,*left,*parent;
};

Node *root,*NIL;

void insert(int k){
	Node *y=NIL;
	Node *x=root;
	Node *z;
	
	z=(Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	
	while(x != NIL){
		y=x;
		if(z->key < x->key){
			x=x->left;
		} else {
			x=x->right;
		}
	}
	
	z->parent = y;
	if(y==NIL){
		root = z;
	}  else {
		if(z->key<y->key){
			y->left=z;
		} else{
			y->right=z;
		}
	}
}

Node * find(Node *u,int k){
	while(u!=NIL && k!= u->key){
		if(k<u->key) u=u->left;
		else u=u->right;
	}
	return u;
} 

void inorder(Node *u){
	if(u==NIL) return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}

void preorder(Node *u){
	if(u==NIL) return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}



int main() {
	
	int n,i,x;
	string com;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		cin>>com;
		if(com[0]=='f'){
			scanf("%d",&x);
			Node *t = find(root,x);
			if(t!=NIL) printf("yes\n");
			else printf("no\n");
		}else if(com=="insert"){
			scanf("%d",&x);
			insert(x);
		}else if(com=="print"){
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 21916
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>*/
 
#define pb push_back
#define mp make_pair
#define sz(s) ((int)(s.size()))
#define all(s) s.begin(), s.end()
#define rep(i, a, n) for (int i = a; i <= n; ++i)
#define per(i, n, a) for (int i = n; i >= a; --i)
#define onlycin ios_base::sync_with_stdio(false); cin.tie(0) 
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
/*typedef tree<
pair < int, int >,
null_type,
less< pair < int, int > >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
// find_by_order() order_of_key()
const int MAXN = (int)5e5+228;
const char nxtl = '\n';
const int mod = (int)1e9+7;
const double eps = (double)1e-7;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

string s;
int g[MAXN][30];
int last[MAXN], dp[MAXN];

int dfs(int x) {
	if(x == -1) return 0;
	if(~dp[x]) return dp[x];
	dp[x] = INT_MAX;
	rep(i, 0, 25) {
		dp[x] = min(dp[x], dfs(g[x][i]) + 1);
	}
	return dp[x];
}
void restore(int x) {
	if(x == -1) return;
	rep(i, 0, 25) {
		if(dfs(x) == dfs(g[x][i]) + 1) {
			cout << (char)(i+'a');
			restore(g[x][i]);
			break;
		}
	}
}

int main() {
	#ifdef accepted
		freopen(".in", "r", stdin);
		freopen(".out", "w", stdout);
	#endif
	onlycin;
	cin >> s;
	memset(last, 255, sizeof last);
	memset(dp, 255, sizeof dp);
	memset(g, 255, sizeof g);
	per(i, sz(s) - 1, 0) {
		rep(alpha, 'a', 'z') {
			if(~last[alpha]) g[i][alpha-'a'] = last[alpha];
		}
		last[s[i]] = i;
	}
	char beg = '.';
	int res = -1;
	rep(alpha, 'a', 'z') {
		if(last[alpha] == -1) {
			cout << (char)alpha << nxtl;
			return 0;
		}
		if(res == -1 || dfs(last[alpha]) < res) {
			res = dfs(last[alpha]); beg = alpha;
		}
	}
	cout << beg;
	restore(last[beg]);
	return 0;
}

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

#define pb push_back
#define mk make_pair
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(S) (S).begin(), (S).end()
#define debug(a) cerr << #a << " = " << a << endl;
#define debug2(a,b) cerr << #a << " = " << a << " --- " << #b << " = " << b << endl;
#define debugM(M, l, c ) rep( i, 0, l ){ rep( j, 0, c ){ cerr << M[i][j] << " "; } cerr << endl; }
#define debugP(p) cerr << #p << " = " << p.x << " --- " << #p << " = " << p.y << endl;
#define MAX 3005

using namespace std;

typedef long long int ll;
typedef pair<int, int> ii;
const int INF = 0x3f3f3f3f;

string a, b;
int pd[MAX][MAX];
int back[MAX][MAX];

int solve(int i, int j) {
	if(i == a.size() || j == b.size())
		return 0;
	
	int &ans = pd[i][j];
	if(ans != -1) return ans;
	
	int x, y, z;
	x = y = z = -INF;
	
	if(a[i] == b[j])
		x = solve(i+1, j+1) + 1;
	else {
		y = solve(i+1, j);
		z = solve(i, j+1);
	}
	
	if(x > y && x > z) back[i][j] = 0;
	else if(y > x && y > z) back[i][j] = 1;
	else back[i][j] = 2;
	
	ans = max(x, max(y, z));
	return ans;	
}

void volta(int i, int j) {
	if(i == a.size() || j == b.size()) return;
	
	if(back[i][j] == 0) {
		cout << a[i];
		volta(i+1, j+1);
	}
	else if(back[i][j] == 1)
		volta(i+1, j);
	else
		volta(i, j+1);
}

int main(void) {
	memset(pd, -1, sizeof(pd));
	cin >> a >> b;	 
	
	solve(0, 0);
	volta(0, 0);
	 		
	return 0;
}

Measured memory_bytes: 71040
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int n, k;

int solve()
{
    ll ans = 0;
    rep(i, 1, n + 1) rep(j, 1, n + 1)
    {
        if (i % j >= k)
        {
            cerr << i << " " << j << endl;
            ans++;
        }
    }
    cerr << ans << endl;
    return ans;
}

int main()
{
    cin >> n >> k;
    ll ans = 0;
    if (k == 0)
    {
        ans = (ll)n * (ll)n;
    }
    else
    {
        rep(i, 1, n + 1)
        {
            if (i <= k)
                continue;
            ll j = 0;
            while (j * i <= n)
            {
                if (i * j + k > n)
                    break;
                ans += min((j + 1) * i, (ll)n + 1) - (i * j + k);
                j++;
            }
        }
    }
    cout << ans << endl;
    //assert(ans == solve());
    return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, '%d', $N);

$ryokans = explode(' ', trim(fgets(STDIN)));
$count = 0;
$highest = -1;
for ($i=0; $i < $N; $i++) {
    if ($ryokans[$i] >= $highest) {
        $count++;
        $highest = $ryokans[$i];
    }
}

echo $count;

echo PHP_EOL;


Measured memory_bytes: 16264
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int g[11][11];
int main(){
    int d,w;
    while(cin>>d>>w,d){
        rep(i,d)rep(j,w) cin>>g[i][j];
        int ans=0;
        rep(dl,d-1)rep(wl,w-1)FOR(dr,dl+1,d)FOR(wr,wl+1,w){
            int mn=1000100010,mx=0,sum=0;
            FOR(i,dl,dr+1)FOR(j,wl,wr+1){
                if(i==dl||i==dr||j==wl||j==wr){
                    mn=min(mn,g[i][j]);
                }
                else{
                    sum+=g[i][j],mx=max(mx,g[i][j]);
                }
            }
            if(mn>mx){
                ans=max(ans,mn*(dr-dl-1)*(wr-wl-1)-sum);
            } 
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

const int INF = 2000000;

struct LineTable{
  int cost;
  int times;
  LineTable(){
    cost = INF;
    times = INF;
  }
};

int main(){

    int n,m;
    while(1){
      cin >> n >> m;
      if(n==0&&m==0){
        break;
      }
      LineTable table[m][m];

      for(int i=0;i<m;i++){
        table[i][i].cost = 0;
        table[i][i].times = 0;
      }

      for(int i=0;i<n;i++){
        int a,b,cost,times;
        cin >> a >> b >> cost >> times;
        table[a-1][b-1].cost = cost;
        table[a-1][b-1].times = times;
        table[b-1][a-1].cost = cost;
        table[b-1][a-1].times = times;
      }

      for(int k=0;k<m;k++){
        for(int i=0;i<m;i++){
          for(int j=0;j<m;j++){
            if(table[i][j].cost > table[i][k].cost + table[k][j].cost){
              table[i][j].cost = table[i][k].cost + table[k][j].cost;
            }
          }
        }
      }

      for(int k=0;k<m;k++){
        for(int i=0;i<m;i++){
          for(int j=0;j<m;j++){
            if(table[i][j].times > table[i][k].times + table[k][j].times){
              table[i][j].times = table[i][k].times + table[k][j].times;
            }
          }
        }
      }

/*      for(int k=m-1;k>=0;k--){
        for(int i=m-1;i>=0;i--){
          for(int j=m-1;j>=0;j--){
            if(table[i][j].cost > table[i][k].cost + table[k][j].cost){
              table[i][j].cost = table[i][k].cost + table[k][j].cost;
            }
          }
        }
      }

      for(int k=m-1;k>=0;k--){
        for(int i=m-1;i>=0;i--){
          for(int j=m-1;j>=0;j--){
            if(table[i][j].times > table[i][k].times + table[k][j].times){
              table[i][j].times = table[i][k].times + table[k][j].times;
            }
          }
        }
      }*/

      int k,p,q,r;
      cin >> k;
      /*cin >> p >> q >> r;
      if(r==0){
        cout << table[p-1][q-1].cost;
      }
      else{
        cout << table[p-1][q-1].times;
      }
      for(int i=1;i<k;i++){
        cin >> p >> q >> r;
        if(r==0){
          cout << ' ' <<table[p-1][q-1].cost;
        }
        else{
          cout << ' ' <<table[p-1][q-1].times;
        }
      }
      cout << endl;*/

      for(int i=0;i<k;i++){
        cin >> p >> q >> r;
        if(r==0){
          cout << table[p-1][q-1].cost << endl;;
        }
        else{
          cout << table[p-1][q-1].times << endl;
        }
      }
    }
    return 0;
}

Measured memory_bytes: 3156
//package com.company;

import java.io.*;
import java.util.*;

public class Main {
    static long TIME_START, TIME_END;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("Test.in"));
        PrintWriter pw = new PrintWriter(System.out);
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.out"));

        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
        System.out.println("Memory increased:" + (usedMemoryAfter - usedMemoryBefore) / 1000000);
        System.out.println("Time used: " + (TIME_END - TIME_START) + ".");
    }

    public static class Task {


        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            int a = sc.nextInt();
            int b = sc.nextInt();
            pw.println(a * b % 2 == 0 ? "No" : "Yes");

        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader s) throws FileNotFoundException {
            br = new BufferedReader(s);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}

Measured memory_bytes: 21460
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: usize,
        b: usize,
    }
    let f = factorize(gcd(a, b));
    println!("{}", f.len() + 1);
}

fn gcd(a: usize, b: usize) -> usize {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn factorize(n: usize) -> Vec<(usize, usize)> {
    let mut v = vec![];
    let mut t = n;

    for i in 2.. {
        if i * i > n {
            break;
        }
        if t % i != 0 {
            continue;
        }
        let mut cnt = 0;
        while t % i == 0 {
            cnt += 1;
            t = t / i;
        }
        v.push((i, cnt));
    }
    if t != 1 {
        v.push((n, 1));
    }
    v
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int n,ans = 0,count = 0;
    cin >> n;
    string s;
    cin >> s;
    rep(i, n){
        if (s[i] == 'I') {
            ++count;
        }else{
            --count;
        }
        if (ans < count) {
            ans = count;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 1
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())

void printYes(){
	cout<<"Yay!"<<endl;
}
void printNo(){
	cout<<":("<<endl;
}

signed main(){

	lli m;
	cin>>m;
	lli sum=0;

	lli ans=-1;

	REP(i,0,m){
		lli d,c;
		cin>>d>>c;
		sum += d*c;
		ans+=c;
	}

	//if(DEBUG)cout<<"sum="<<sum<<"ans="<<ans<<endl;
	lli nextSum=sum;
	/*
	while(nextSum>=10){
		if(DEBUG)cout<<"nextSum="<<nextSum<<"ans="<<ans<<endl;
		lli now=nextSum;
		lli nowSum=0;
		ans--;
		while(now>0){
			nowSum+=now%10;
			ans++;
			if(now==0)break;
			now/=10;
		}
		nextSum=nowSum;
	}
	*/
	ans += sum/9 - ((sum)%9==0);
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

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 {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=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 {
        mint res(*this);
        return res/=a;
    }
};

ostream& operator << (ostream& os, const mint a) {
    os << a.x;

    return os;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    string S;
    cin >> S;

    reverse(ALL(S));

    vector<mint> cnt(13, 0);
    cnt[0] = 1;

    ll car = 1;
    REP(i, S.size()) {
        vector<mint> tmp(13, 0);

        if (S[i] == '?') {
            REP(c, 13) REP(k, 10) {
                tmp[(c + car * k) % 13] += cnt[c];
            }
        } else {
            int k = S[i] - '0';
            REP(c, 13) {
                tmp[(c + car * k) % 13] += cnt[c];
            }
        }

        car = car * 10 % 13;
        cnt = tmp;
    }

    print(cnt[5]);
    
}


Measured memory_bytes: 3656
N = int(input())
ma = 2*(10**9)+1
Ma = 0
mb = 10**9
Mb = 2-10**9
for i in range(N):
  a,b = map(int,input().split())
  tempa = a+b
  ma = min(ma,tempa)
  Ma = max(Ma,tempa)
  tempb = b-a
  mb = min(mb,tempb)
  Mb = max(Mb,tempb)
print(max(Ma-ma,Mb-mb))

Measured memory_bytes: 71016
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
#define fir first
#define sec second
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	ll sum = 0;
	rep(i,0,n){
		cin >> a[i];
		sum += a[i];
	}

	double ave = (double)sum/n;

	int num=a[0],idx=0;
	rep(i,0,n){
		if( abs( ave - (double)a[i] ) < abs( ave - (double)num )){
			num = a[i];
			idx = i;
		}
	}
	
	cout << idx << endl;

	ret 0;
}

Measured memory_bytes: 256
#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 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long int ll;

int main()
{
  int n,w;
  cin >> n >> w;
  ll ws[n], vs[n];
  REP(i,n){
    cin >> ws[i] >> vs[i];
  }
  ll dp[100001];
  REP(i,100001) dp[i]=1e13;
  dp[0]=0;
  FOR(i,1,n+1){
    REPR(j,100000){
      if(j - vs[i-1] >= 0) dp[j] = min(dp[j], dp[j - vs[i-1]] + ws[i-1]);
    }
  }
  ll ans = 0;
  REP(i,100001){
	if(dp[i] <= w) ans = max(ans, (ll)i);
  }
 
  cout << ans << endl;

}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

void solve()
{
	int c[3];
	while(cin >> c[0] >> c[1] >> c[2])
	{
		bool flag[11];
		for(int i = 0; i < 11; ++i)
		{
			flag[i] = true;
		}
		flag[c[0]] = flag[c[1]] = flag[c[2]] = false;
		int sum = c[0] + c[1];
		int count = 0;
		for(int i = 1; i < 11; ++i)
		{
			if(flag[i] == true && sum + i <= 20)
			{
				++count;
			}
		}
		if(count >= 4)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}

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

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main()
{
	
	long long a,b;
	cin>>a>>b;
	if(a>=13)
	{
		cout<<b;
	}
	else if(a>=6)
	{
		cout<<b/2;
	}
	else
		cout<<0;
 
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 45;
const int mod = 1000000007;
//const int mod = 998244353;

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

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
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= 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
  {
    mint res(*this);
    return res /= a;
  }
};
struct key {
  int a;
  int c;
};

int main()
{
  int n, m;
  cin >> n >> m;
  vector<key> keys(m);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    keys[i].a = a;
    int bit = 0;
    rep(j, b) {
      int c; cin >> c; --c;
      bit += 1<<c;
    }
    keys[i].c = bit;
  }
  vector<vector<int>> dp(m+1, vector<int>(1<<n, INF));
  dp[0][0] = 0;
  rep(i, m) {
    for(int bit = 0; bit < 1<<n; ++bit) {
      chmin(dp[i+1][bit], dp[i][bit]);
      chmin(dp[i+1][bit | keys[i].c], dp[i][bit]+keys[i].a);
    }
  }
  if(dp[m][(1<<n)-1] != INF) cout << dp[m][(1<<n)-1] << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 16384
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
  int n;
  int ans;
  
  scanf("%d",&n);
  
  int i=n;
  double d=sqrt(i);
  int comp=(int)sqrt(i);
  while(d!=comp){
    i--;
    d=sqrt(i);
    comp=(int)sqrt(i);
  }
  cout << i << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
int N;
cin >> N;
vector<int> vec(N),a(100000);
int maxi = 0;
for (int i = 0;i < N;i++) {
  cin >> vec.at(i);
  if (vec.at(i) > maxi) maxi = vec.at(i);
  a.at(vec.at(i))++;
}

int ans = a.at(0) + a.at(1);
for (int i = 1;i < maxi;i++) {
  int cnt = 0;
  cnt = a.at(i-1) + a.at(i) + a.at(i+1);
  if (ans < cnt) ans = cnt;
}

cout << ans << endl;

return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((ll)(x).size())

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const int INF = 1e9+10;
const ll mod = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define print(x) cerr << #x << " is " << x << endl;
//#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 

ll dp[200001], sum[200001];
int L[11], R[11];
int main()
{
    ll N, K;
    cin >> N >> K;
    rep(i, K)cin >> L[i] >> R[i];
    dp[1] = 1;
    sum[1] = 1;
    
    
    reps(i, 2, N + 1){
        
        ll tot = 0;
        rep(k, K){
            tot += sum[max(0, i - L[k])] + mod - sum[max(0, i - R[k] - 1)];
            tot %= mod;
        }
            
        dp[i] = tot % mod;
        sum[i] = (sum[i - 1] + dp[i]) %mod;
        
    }
    cout << dp[N];
    return 0;
 
}


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

using namespace std;
using int64 = long long;

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

    int64 ans = 0;
    for (int i=0; i<n; i++) ans += a[i] - 1;
    cout << ans << endl;
}

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

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void solution(String[] args) throws Exception{

		int N = nextInt();
		int M = nextInt();
		int[] A = nextInts();
		TreeMap<Integer,Integer> map = new TreeMap<>();
		long sum = 0;
		//キーの圧縮
		for(int i=0;i<A.length;i++){
			map.put(A[i], map.getOrDefault(A[i], 0)+1);
			sum+=A[i];
		}
		int[][] B = new int[M][2];
		for(int i=0;i<M;i++){
			B[i][0]=nextInt();
			B[i][1]=nextInt();
		}

		//置き換えるものを降順に並べる
		Arrays.sort(B,(s1,s2)->{return s2[1]-s1[1];});

		int min = 0;
		int i=0;
		for(int key:map.keySet()){
			int remain = map.get(key);
			while(i<M){
				if(B[i][1]>key){
					//増えた分の増分を足す
					long sub = Math.min(B[i][0], remain);
					sum+=sub*(B[i][1]-key);
					B[i][0]-=sub;
					remain-=sub;
					if(B[i][0]==0){
						i++;
					}
					if(sub==0){
						break;
					}
				}else{
					i=M;
				}
			}
		}





		pw.println(sum);

	}

	public static void dfs(int n,int cnt,ArrayList<Integer>[] tree,int parent,int[] set){
		if(n!=parent&&tree[n].size()==1){
			set[n]=cnt;
			return;
		}
		for(int x:tree[n]){
			if(x==parent){
				continue;
			}
			dfs(x,cnt+1,tree,n,set);
		}
	}


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

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

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

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

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

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

}



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

int main(){
    int n;  cin>>n;
    long minA=1000000001;
    long a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]<minA)minA=a[i];
    }

    int ans=0;

    for(int i=minA;i>0;i--){
        bool flag=false;
        for(int j=0;j<n;j++){
            if(a[j]%i==0 && a[j]%2==0){
                flag=true;
            }else {
                flag=false;
                break;
            }
        }

        if(flag==true){
            while(i>1){
                ans++;
                i/=2;
            }
            break;
        }
    }

    cout<<ans<<endl;



    return 0;
}


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

struct node{
	char c[10];
};

bool cmp(node a,node b) {
	for(int i=0;i<10;i++)
		if(a.c[i]!=b.c[i]) return 0;
	return 1;
}

bool com(node a,node b) {
	for(int i=0;i<10;i++)
		if(a.c[i]!=b.c[i]) return a.c[i]<b.c[i];
	return 0;
}

int main(int argc,char **argv) {
	long long ans=0;
	int n;
	cin>>n;
	
	node c[n];
	char ch;
	for(int i=0;i<n;i++) {
		for(int j=0;j<10;j++) {
			ch=getchar();
			if(ch>='a' && ch<='z')
				c[i].c[j]=ch;
			else j--;
		}
		sort(c[i].c,c[i].c+10);
	}
	
	sort(c,c+n,com);
	
	long long now,her;
	for(int i=0;i<n;i++) {
		now=0;
		her=i;
		while(i<n && cmp(c[her],c[i]))
			i++,now++;
		ans+=((now-1)*now)/2;
		i--;
	}
	
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define debug int debug = 0;
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<int, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; //10^9+7


int main(){
    ll n;
    ll a[100002] = {};
    ll cnt[100002] = {};
    cin >> n;
    REP(i, n){
        cin >> a[i];
        cnt[a[i]]++;
        a[i]++;
        cnt[a[i]]++;
        a[i] -= 2;
        cnt[a[i]]++;
    }
    ll max_ = 0;
    REP(i, 100000){
        max_ = max(max_, cnt[i]);
    }
    print(max_);
}

Measured memory_bytes: 1920