akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>
#define scanf_s scanf
#define fir first
#define sec second
#define mp make_pair
#define mt make_tuple
#define pub push_back
using namespace std;
typedef long long int llint;
const llint one = 1;
const llint big = (one<<16);
int main(void){
	llint N,i,ans=0,q;
	vector<llint> a;
	scanf("%lld",&N);
	for(i=0;i<3*N;i++){
		scanf("%lld",&q);
		a.pub(q);
	}
	sort(a.begin(),a.end());
	for(i=N;i<3*N;i+=2){
		ans+=a[i];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6256
import java.util.*

fun main() {
    val n= readLine()!!.toInt()
    var x=Array(n+1){IntArray(2){0} }
    val inp= readLine()!!.split(" ").map { it.toInt() }
    var a=IntArray(n*n){0}
    for (i in 1..n){
        x[i][0]=i
        x[i][1]=inp[i-1]-1
        if (x[i][1]<n*n){a[x[i][1]]=i}
    }
    x.sortBy { it[1] }
    var que=ArrayDeque<Int>()
    var cnt=IntArray(2){1}
    var f=true
    var tmp=mutableListOf(x[cnt[1]][0], x[cnt[1]][0]-1)
    for (i in 0 until n*n){
        while (tmp[1]==0 && cnt[1]<=n){
            for (j in 0 until n- x[cnt[1]][0]){
                que.addLast(x[cnt[1]][0])
            }
            cnt[1]++
            if (cnt[1]<=n){
                tmp= mutableListOf(x[cnt[1]][0], x[cnt[1]][0]-1)
            }else{
                tmp= mutableListOf(-1,-1)
            }
        }
        if (cnt[0]<=n&&x[cnt[0]][1]==i){
            cnt[0]++
            continue
        }
        if (cnt[1]<=n&&cnt[0]<=n){
            if (x[cnt[0]][1]>i && tmp[1]>0){
                a[i]=tmp[0]
                tmp[1]--
            }
        }
        if (a[i]==0 && que.isNotEmpty()){a[i]=que.removeFirst()}
    }
    var check=IntArray(n+1){0 }
    var ind=1
    for (i in a.indices){
        check[a[i]]++
        if (a[i]==check[a[i]]){
            if (i!=x[ind][1]){
                f=false
            }else{
                ind++
            }
        }
    }
    if (check[0]!=0){f=false}
    if (f){
        println("Yes")
        println(a.joinToString(separator = " "))
    }else{
        println("No")
    }

}

Measured memory_bytes: 61072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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

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

int main(){
	int i,j;
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin>>n;
	string s;
	cin>>s;
	int m=1<<n;
	int p[m];
	for(i=0;i<m;i++) {
		cin>>p[i];
		p[i]--;
	}
	VVI dp(n+1,VI(m));
	for(i=0;i<m;i++) dp[0][i]=p[i];
	for(i=1;i<=n;i++){
		for(j=0;j<m;j++){
			int x=dp[i-1][j];
			int y=dp[i-1][(j+(1<<(i-1)))%m];
			if(x>y) swap(x,y);
			if(s[y-x-1]=='0') dp[i][j]=x;
			else dp[i][j]=y;
		}
	}
	for(i=0;i<m;i++){
		cout<<dp[n][i]+1<<endl;
	}


}


Measured memory_bytes: 45388
using System;
class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
		long n = long.Parse(input[0]);
		long K = long.Parse(input[1]);
        long[,] doubling = new long[(int)(Math.Log(K,2)+1),n];
        string[] input2 = Console.ReadLine().Split(' ');
        for(int i=0; i<n; i++){
            doubling[0,i] = long.Parse(input2[i])-1;
        }
        for(int k=0; k<(int)(Math.Log(K,2)); k++){
            for(int i=0; i<n; i++){
                doubling[k+1,i] = doubling[k,doubling[k,i]];
                //Console.Write(doubling[k+1,i]+" ");
            }
            //Console.WriteLine();
        }
        int now = 0;
        for(int i=0; i<=(int)(Math.Log(K,2)); i++){
            if((K & ((long)1<<i)) == ((long)1<<i)) now = (int)doubling[i,now];
            //K = K >> 1;
        }
		Console.WriteLine(now+1);
	}
}

Measured memory_bytes: 128244
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <numeric>
#include <vector>
#include <math.h>
#include <string>
#include <queue>

using namespace std;

int map[51][51];
int flg[51][51];


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

	char buff[1024];

	int snum = 0;
	for (int i = 0; i < H; i++)
	{
		cin >> buff;

		for (int j = 0; j < W; j++)
		{
			if (buff[j] == '#')
			{
				map[i][j] = 0;
				snum++;
			}
			else
			{
				map[i][j] = 1;
			}
			flg[i][j] = -1;
		}
	}

	queue<pair<int, int>> q;
	q.push(make_pair(0, 0));
	flg[0][0] = 0;

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

	while (!q.empty())
	{
		int x = q.front().first;
		int y = q.front().second;
		q.pop();

		if (x == W-1 && y == H-1)
		{
			break;
		}

		int d = flg[y][x] + 1;

		for (int i = 0; i < 4; i++)
		{
			int rx = x + dx[i];
			int ry = y + dy[i];

			if (rx < 0 || rx >= W || ry < 0 || ry >= H)
			{
				continue;
			}

			if (map[ry][rx] != 0)
			{
				if (flg[ry][rx] == -1)
				{
					flg[ry][rx] = d;
					q.push(make_pair(rx, ry));
				}
			}

		}
	}

	if (flg[H - 1][W - 1] == -1)
	{
		cout << "-1" << endl;
	}
	else
	{
		int d = W * H - flg[H - 1][W - 1] - 1 - snum;

		cout << d << endl;
	}

	return 0;
}

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

#define ll long long

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fill(a,b) memset(a,b,sizeof(a))

#define f first
#define s second

#define inf 1e17
#define ninf -1*1e17
#define mod 1000000007
#define N 500005
#define Ns 5005

string s;
ll n,m,x,y,z,d,k;
ll a[N];

ll mat[Ns][Ns];
ll dp[Ns][Ns][4];

int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
	int t=1;
//	cin>>t;
	while(t--){
	    
	    
	    cin>>n>>m>>k;
	    
	    for(int i=0;i<k;i++){
	        cin>>x>>y>>z;
	        x--;
	        y--;
	        mat[x][y]=z;
	    }
	    
	    ll ans=ninf;
	    
	    for(int i=0;i<n;i++){
	        for(int j=0;j<m;j++){
	            for(int k=0;k<4;k++){
	                dp[i][j][k]=ninf;
	            }
	        }
	    }
	    
	    dp[0][0][0]=0;
	    
	    for(int i=0;i<n;i++){
	        for(int j=0;j<m;j++){
	            
	            if(mat[i][j]>0){
	                for(int k=2;k>=0;k--){
	                    
	                    dp[i][j][k+1]=max(dp[i][j][k+1],dp[i][j][k]+mat[i][j]);
	                }
	            }
	            for(int k=0;k<4;k++){
	                
	                dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k]);
	                
	                dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k]);
	            }
	            
	            
	        }
	    }
	    for(int k=0;k<4;k++){
	        ans=max(ans,dp[n-1][m-1][k]);
	    }
	    cout<<ans<<"\n";
	    
	    
	}
	return 0;
}


Measured memory_bytes: 376848
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FS r = new FS();
		long x = r.nextLong();
		long y = r.nextLong();
		long tmpx = x;
		long tmpy = y;
		long minCount = 1000000500;
		long c = 0;
		// case 1  :  + -> +
		if(tmpx < 0){
			tmpx = -tmpx;
			c++;
		}
		if(tmpy < 0){
			tmpy = -tmpy;
			c++;
		}
		if(tmpy < tmpx) c = minCount+1;
		else c += tmpy - tmpx;
		minCount = Math.min(minCount, c);
		// case 2  :  + -> -
		c = 0;
		tmpx = x;
		tmpy = y;
		if(tmpx < 0){
			tmpx = -tmpx;
			c++;
		}
		if(tmpy > 0){
			tmpy = -tmpy;
			c++;
		}
		if(tmpy < tmpx) c = minCount+1;
		else c+= tmpy - tmpx;
		minCount = Math.min(minCount, c);
		// case 3  :  - -> +
		c = 0;
		tmpx = x;
		tmpy = y;
		if(tmpx > 0){
			tmpx = -tmpx;
			c++;
		}
		if(tmpy < 0){
			tmpy = -tmpy;
			c++;
		}
		if(tmpy < tmpx) c = minCount+1;
		else c+= tmpy - tmpx;
		minCount = Math.min(minCount, c);
		// case 4  :  - -> -
		c = 0;
		tmpx = x;
		tmpy = y;
		if(tmpx > 0){
			tmpx = -tmpx;
			c++;
		}
		if(tmpy > 0){
			tmpy = -tmpy;
			c++;
		}
		if(tmpy < tmpx) c = minCount+1;
		else c+= tmpy - tmpx;
		minCount = Math.min(minCount, c);

		System.out.println(minCount);
	}

	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}

		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public int nextInt() {
			return (int)nextLong();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}


Measured memory_bytes: 8148
#include <bits/stdc++.h>
using namespace std;
int main(){

    int N,h=0;
    cin >> N;
    int s[N][2];
    for(int i = 0; i < N; i++) {
        cin >> s[i][0] >> s[i][1];
    }

    for(int i = 0; i < N; i++){
        h += s[i][1] - s[i][0] + 1;
    }

    cout << h << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    string S,T;
    cin >> S >> T;
    string T_po = T;
    T_po.pop_back();
    if (S == T_po)
    {
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 3628
#define _USE_MATH_DEFINES
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int main(){
  double a,b,c,deg,S;
  cin >> a >> b >> deg;
  S = (0.5) * a * b * sin(M_PI * deg / 180);
  c = sqrt(a * a + b * b - 2 * a * b * cos(M_PI * deg /180));

  cout << setprecision(10) << S << endl;
  cout << a + b + c << endl;
  cout << 2 * S / a << endl;
}


Measured memory_bytes: 3620
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<iomanip>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(int i = a;i < b; i++)

int main() {

	int n;
	cin >> n;

	vector<double> v(n);
	rep(i, 0, n) cin >> v[i];

	double ans;

	sort(v.begin(), v.end());

	rep(i, 0, n - 1) {
		v[i + 1] = v[i] + v[i + 1];
		v[i + 1] /= 2;
	}

	cout << v[n - 1] << endl;

	return 0;
}

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

using namespace std;

struct Process {
  char name[10];
  int time;
};

static const int MAX = 100000;
Process P[MAX];
int tail, head;

void enqueue (struct Process& p) {
  P[tail] = p;
  tail = (tail + 1) % MAX;
}

void dequeue (struct Process& p) {
  p = P[head];
  head = (head + 1) % MAX;
}

int main () {
  int n, q;

  cin >> n >> q;

  for (int i = 0; i < n; i++) {
    cin >> P[i].name >> P[i].time;
  }

  int count = 0;

  tail = n;

  struct Process p;

  while (head != tail) {
    dequeue(p);
    p.time -= q;
    if (p.time <= 0) {
      count += q + p.time;
      cout << p.name << " " << count << endl;
    } else {
      count += q;
      enqueue(p);
    }
  }

}

Measured memory_bytes: 4584
#include <iostream>
#include <vector>
using namespace std;
int chk[10],N,M,len,flag,visit[1000001],ans=987654321;
vector<int> su;
int dfs(int x,int sum)
{
	if(visit[sum]||sum>100000)
	return 0;
	
	if(sum>=N)
	ans=min(ans,sum);
	
	visit[sum]=1;
	for(int i=0; i<len; i++)
	{
		dfs(i,sum*10+su[i]);
	}

}
int main()
{
	cin >> N >> M;
	
	for(int i=0; i<M; i++)
	{
		int x;
		cin >> x;
		
		chk[x]=1;
	}
	
	for(int i=0; i<10; i++)
	{
		if(!chk[i])
		su.push_back(i);
	}
	
	len=su.size();
	for(int i=0; i<len; i++)
	{
		dfs(i,su[i]);
	}
	cout << ans;
}

Measured memory_bytes: 640
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

x,y = LI()
print(x+y//2)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=LLONG_MAX,mod=1000000007,BS,k;

int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
        ll n,k;cin>>n>>k;
        ll arr[n],val[n];
        for(ll i=0;i<n;i++)cin>>arr[i];
        for(ll i=0;i<n;i++)cin>>val[i];
        ll vis[n],dp[n][n+1],curr,coun;
        for(ll i=0;i<n;i++)
        for(ll j=0;j<=n;j++)dp[i][j]=0;
        ll sum[n];
        for(ll i=0;i<n;i++){
            // for(ll j=0;j<n;j++)vis[j]=0;
            curr=i;coun=0;
            while(1){
                // if(vis[curr])break;
                // vis[curr]=1;
                dp[i][coun]+=val[arr[curr]-1];
                if(coun-1>=0)
                dp[i][coun]+=dp[i][coun-1];
                curr=arr[curr]-1;
                coun++;
                if(curr==i)break;
            }
            sum[i]=coun;
            // cout<<sum[i]<<" ";
        }
        ll ma=-inf,num,tem;
        // cout<<dp[1][0]<<" ";
        for(ll i=0;i<n;i++){num=-inf;
            curr=0;
            tem=k;
            if(sum[i]<k&&dp[i][sum[i]-1]>0){
                curr=((k-1)/sum[i])*(dp[i][sum[i]-1]);
                // if(i==0)cout<<curr;
                k=(k-1)%sum[i]+1;
            }
            for(ll j=0;j<min(sum[i],k);j++)
            num=max(num,dp[i][j]);
            // if(i==0)cout<<curr<<" ";
            if(num!=-inf)
            curr+=num;
            // if(i==2)cout<<curr<<" ";
            k=tem;
            ma=max(ma,curr);

            // curr=0;num=-inf;
            // for(ll j=0;j<min(k,sum[i]);j++)
            // num=max(num,dp[i][j]);
            // curr+=num;
            // ma=max(ma,curr);
        }
        cout<<ma;

}


Measured memory_bytes: 199096
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int ans = 0, b = 0, ab = 0, a = 0;
    int n;
    cin >> n;
    for (int _ = 0; _ < n; _++) {
        string s;
        cin >> s;
        if (s[0] == 'B' && s.back() == 'A') {
            ab++;
        } else if (s[0] == 'B') {
            b++;
        } else if (s.back() == 'A'){
            a++;
        }
        for (int i = 0; i < sz(s) - 1; i++) {
            if (s[i] == 'A' && s[i + 1] == 'B') {
                ans++;
            }
        }
    }
    if (ab > 0) {
        ans += ab - 1;
        if (b > 0) {
            ans++;
            b--;
        }
        if (a > 0) {
            ans++;
            a--;
        }
    }
    ans += min(a, b);
    cout << ans << "\n";
}
    


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

public class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int L=sc.nextInt();
		int J=sc.nextInt();
		int M=sc.nextInt();
		int JS=sc.nextInt();
		int MS=sc.nextInt();
		pl(L-Math.max((J+JS-1)/JS, (M+MS-1)/MS));
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}



Measured memory_bytes: 24476
#![allow(unused_imports)]
use proconio::{input, fastout};
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
    x: usize,
    y: usize
    }
    let mut ans = "No";
    for i in 0..=x {
        if y == i * 2 + (x - i) * 4 {
            ans = "Yes";
            break;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2120
#include <stdio.h>

int main(void){
  int n,a,b;
  int ans = 0;
  scanf("%d %d %d",&n,&a,&b);
  for(int i = 1;i <= n;i++){
    int x = i;
    int sum = 0;
    while(x != 0){
      int r = x % 10;
      sum += r;
      x /= 10;
    }
    if(sum >= a && sum <= b){
      ans += i;
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
S = input()

flg = False
Z = [0,0]
N = len(S)
ans = [0] * N
for i, s in enumerate(S):
    if (flg and s == "R"):
        flg = False
        if tmp_R%2 == 0:
            ans[tmp_R] = Z[0]
            ans[tmp_L] = Z[1]
        else:
            ans[tmp_R] = Z[1]
            ans[tmp_L] = Z[0]
        Z = [0, 0]

    if (not flg) and s == "L":
        flg = True
        tmp_R = i-1
        tmp_L = i

    if i%2 == 0:
        Z[0] += 1
    else:
        Z[1] += 1

    if i == N-1:
        if tmp_R%2 == 0:
            ans[tmp_R] = Z[0]
            ans[tmp_L] = Z[1]
        else:
            ans[tmp_R] = Z[1]
            ans[tmp_L] = Z[0]

print(*ans)


Measured memory_bytes: 10748
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   string s;
   cin >> s;
   char c = s[s.length()-1];
   if(c == '3') {
       cout << "bon" << endl;
   } else if (c=='0'||c=='1'||c=='6'||c=='8') {
       cout << "pon" << endl;
   } else {
       cout << "hon" << endl;
   }
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
using namespace std;

int main(){

    int n;
    cin >> n;
    n = n * 3;

    vector<long long>v(n);
     
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }

    sort(v.begin(), v.end());

    long long ans = 0;
    for(int i = n / 3; i < n; i += 2){
        ans += v[i];
    }
    cout << ans << endl;


}

Measured memory_bytes: 2560
N,K=map(int,input().split())
cnt=[0]*N
for i in range(K):
    d=int(input())
    A=list(map(int,input().split()))
    for a in A:
        cnt[a-1]=cnt[a-1]+1
ans=0
for i in range(N):
    if cnt[i]==0:
        ans=ans+1
print(ans)




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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    int n;cin>>n;
    vl a(n),b(n);
    rep(i,n){
        cin>>a[i];
    }
    sort(all(a));
    ll GCD=a[0];
    rep(i,n)GCD=gcd(GCD,a[i]);
    rep(i,n)a[i]/=GCD;
    ll GCD2=a[1];
    for(int i=1;i<n;++i){
        GCD2=gcd(a[i],GCD2);
    }
    if(GCD2>1){
        cout<<GCD*GCD2<<endl;
    }
    else{
        ll GCD3=a[0];
        for(int i=1;i<n;++i){
            GCD3=gcd(GCD3,a[i]);
            if(GCD3==1){
                a[i]=a[i-1];
                break;
            }
        }
        ll GCD4=a[0];
        rep(i,n)GCD4=gcd(GCD4,a[i]);
        cout<<GCD4*GCD<<endl;
    }
}


Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define POW_10_9 1000000000
#define INF (numeric_limits<int>::max()/2)
#define int long long

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

const int costs[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int N, M;
int A[9];
string ans;

// 数、桁数
int dp[10001];

signed main() {
  cin >> N >> M;
  REP(i, M) { cin >> A[i]; }

  sort(A, A+M, greater<int>());
  FOR(i, 1, N) {
    REP(j, M) {
      int k = i - costs[A[j]];
      if (k >= 0) { dp[i] = MAX(dp[i], dp[k]+1); }
    }
    if (dp[i] == 0) { dp[i] = -INF; }
  }

  int i = N;
  REP(j, M) {
    int k = i-costs[A[j]];
    while (k >= 0 && dp[i] == dp[k]+1) {
      ans.push_back('0'+A[j]);
      i -= costs[A[j]];
      k = i-costs[A[j]];
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <stdlib.h>
using namespace std;

char s[4];
int A,B,C,D;

void print_ans(char op1, char op2, char op3){
	cout << A << op1 << B << op2 << C << op3 << D << "=7" << endl;
}

int solve(){
	if(A+B+C+D==7){
		print_ans('+','+','+');
		return 0;
	}

	if(A+B+C-D==7){
		print_ans('+','+','-');
		return 0;
	}

	if(A+B-C+D==7){
		print_ans('+','-','+');
		return 0;
	}

	if(A+B-C-D==7){
		print_ans('+','-','-');
		return 0;
	}

	if(A-B+C+D==7){
		print_ans('-','+','+');
		return 0;
	}

	if(A-B+C-D==7){
		print_ans('-','+','-');
		return 0;
	}

	if(A-B-C+D==7){
		print_ans('-','-','+');
		return 0;
	}

	if(A-B-C-D==7){
		print_ans('-','-','-');
		return 0;
	}

	return 0;

}

int main(){
	int s;
	cin >> s;
	D = s%10; s/=10;
	C = s%10; s/=10;
	B = s%10; s/=10;
	A=s;
	solve();

	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>

int cal_n_digits(int n)
{
  int n_digits = 0;
  if ( n == 0 ) return 1;

  while ( n > 0 ) {
    n /= 10;
    n_digits++;
  }

  return n_digits;
}

int main()
{
  long N;
  std::cin >> N;
  long limit = std::sqrt(N);
 
  int min = 3000;
  int f;
  for ( long A = 1; A <= limit; A++ ) {
    if ( N % A != 0 ) continue;
    long B = N / A;
    f = std::max(cal_n_digits(A), cal_n_digits(B));
    if ( f < min ) {
      min = f;
    }
  }
  std::cout << f << std::endl;
  return 0;
}


Measured memory_bytes: 256
import collections
import sys

N=int(input())
A=list(map(int, input().split()))
A_dict=collections.Counter(A)
ANS=1
if 0 in A_dict.keys():
    print("0")
    sys.exit()
    
for key, value in A_dict.items():
    ANS=ANS*(key**value)
    if ANS>10**18:
        print(-1)
        sys.exit()

print(ANS)


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

using namespace std;

#define ll long long
#define ar array

int x, n;
int a[101];


void solve(){

    cin >> x >> n;

    for (int i = 0; i < 100; i++)
    {
        a[i] = 0;
    }
    

    int tmp;
    for (int i = 0; i < n; i++)
    {
        cin >> tmp;
        a[tmp] = 1;
    }
    
    int upper = 101;
    for (int i = x; i <= 100; i++)
    {
        if(a[i] == 0){
            upper = i;
            break;
        }
    }
    
    int lower = 0;
    for (int i = x; i > 0 ; i--)
    {
        if(a[i] == 0){
            lower = i;
            break;
        }
    }
    
    int ans;
    if( (x - lower) <= (upper-x)){
        ans = lower;
    }
    else{
        ans = upper;
    }

    cout << ans << endl;
}





int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();

}

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

typedef long long ll;
int flag[10000000];

ll next(ll x){
  ll y=x%10;
  ll ret=0;
  ll cnt=10;
  x/=10;
  while(x!=0){
    if(ret<x*y)ret=x*y;
    y=(x%10)*cnt+y;
    x/=10;
    cnt*=10;
  }
  return ret;
}

int main(){
  int Q;
  cin>>Q;
  for(int i=0; i<Q; i++){
    memset(flag, 0, sizeof(flag));
    int N;
    cin>>N;
    ll cnt=0;
    while(true){
      flag[N]=1;
      if(N<10){cout<<cnt<<endl; break;}
      N=next(N);
      if(flag[N]==1){cout<<"-1"<<endl; break;}
      cnt++;
    }
  }
  return 0;
}

Measured memory_bytes: 40228
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;
import java.lang.Math.*;
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int n = in.nextInt();
        int[] diff = new int[n+1];
        int[] amount = new int[n+1];
        int start = 0;
        int mod = (int)1e9+7;
        for(int i=1;i<=n;i++){
            diff[in.nextInt()]+=1;
            int next = Math.abs((n-start)-start-1);
            amount[next]+=1;
            start++;
        }
        int ans = 1;
        for(int i=0;i<=n;i++){
            if (diff[i]!=amount[i]){
                out.println(0);
                out.close();
                return;
            }
            else {
                if(diff[i]>0)
                    ans*=diff[i];
                    ans%=mod;
            }


        }
        out.println(ans);
        out.close();



    }
}

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

int main() {
	int A,B,C,K;
	cin >> A >> B >> C >> K;

	int cnt=0;
	while(B <= A){
		cnt++;
		B *= 2;
	}
	while(C <= B){
		cnt++;
		C *= 2;
	}
	if(cnt <= K){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

}


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

int main(){
  int N;
  cin >> N;
  int a;
  for (int i=0; i<N; i++){
    scanf("%d", &a);
    if (a%2==0){
    	if (a%3==0 || a%5==0) continue;
      	else {
          cout << "DENIED" << endl;
          return 0;
        }
    }
  }
  cout << "APPROVED" << endl;
 return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define nl cout<<"\n"
#define fr(n) for(int i = 0; i<n; i++)
#define frr(j, n) for(int i = j; i<n; i++)
#define Mem(x) memset(x, 0, sizeof(x))
using namespace std;
typedef long long int lli;
int visited[200005] = {0};
int dfs(vector<int> tree[], int x, int p){
    visited[x] = 1;
    int count = 1;
    for(auto i: tree[x]){
        if(i!=p && visited[i]==0){
            count += dfs(tree, i, x);
        }
    }
    return count;
}
int main(){
    int n, m;
    cin>>n>>m;
    vector<int> tree[n+1];
    int a, b;
    fr(m){
        cin>>a>>b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    int nodes = 0;
    fr(n+1){
        if(!visited[i]){
            nodes = max(nodes, dfs(tree, i, 0));
        }
    }
    cout<<nodes;
}

Measured memory_bytes: 30792
#include <bits/stdc++.h>
using namespace std;
double eps = 0.0000001;
struct P {
  double x, y;
};
struct L {
  P p1, p2;
  double x() { return p2.x - p1.x; }
  double y() { return p2.y - p1.y; }
};
double prod(L l1, L l2) { return l1.x() * l2.y() - l1.y() * l2.x(); }
pair<double, double> interP(L l1, L l2) {
  double a = l1.x();
  double b = -l2.x();
  double c = l1.y();
  double d = -l2.y();
  double inv = 1. / (a * d - c * b);
  double e1 = -l1.p1.x + l2.p1.x;
  double e2 = -l1.p1.y + l2.p1.y;
  return make_pair((d * e1 - b * e2) * inv, (-c * e1 + a * e2) * inv);
}
bool intersect(L l1, L l2) {
  if (fabs(prod(l1, l2)) < eps) {
    return false;
  }
  auto p = interP(l1, l2);
  return eps < p.first && p.first < 1 - eps && eps < p.second &&
         p.second < 1 - eps;
}
int main() {

  int n, m;
  cin >> n >> m;
  vector<vector<P>> p(n);
  for (int i = 0; i < n; i++) {
    int l;
    cin >> l;
    for (int j = 0; j < l; j++) {
      double x, y;
      cin >> x >> y;
      p[i].push_back(P{x, y});
    }
  }
  vector<P> hum(m);
  for (int i = 0; i < m; i++) {
    cin >> hum[i].x >> hum[i].y;
  }
  vector<L> line;
  for (int i = 0; i < m; i++) {
    for (auto &poly : p) {
      for (int j = 0; j < poly.size(); j++) {
        line.push_back(L{hum[i], poly[j]});
      }
    }
  }
  vector<P> ps;
  for (int i = 0; i < line.size(); i++)
    for (int j = i + 1; j < line.size(); j++) {
      if (fabs(prod(line[i], line[j])) < eps)
        continue;
      auto rs = interP(line[i], line[j]);
      ps.push_back(P{line[i].p1.x + line[i].x() * rs.first,
                     line[i].p1.y + line[i].y() * rs.first});
    }

  if (n == 0) {
    cout << m << endl;
    return 0;
  }
  if (m == 1) {
    cout << 1 << endl;
    return 0;
  }

  int ans = 0;
  for (int i = 0; i < ps.size(); i++) {
    int score = m;
    for (int j = 0; j < m; j++) {
      L l1{ps[i], hum[j]};
      bool ng = false;

      for (auto &poly : p) {
        for (int k = 0; k < poly.size(); k++) {
          P p1 = poly[k];
          P p2 = poly[(k + 1) % poly.size()];
          L l2{p1, p2};
          if (intersect(l1, l2)) {
            ng = true;
          }
        }
      }

      if (ng) {
        score--;
      }
    }
    ans = max(ans, score);
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3544
#include <cstdio>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)

const int N_MAX = 100000;
const int K_MAX = N_MAX * 2;

int N, x;
bool ng;
int a[K_MAX];

void solve() {
  int k = N * 2 - 1;
  if (x < 2 || x > k - 1) {
    ng = true;
  } else {
    ng = false;
    int xi = x - 1;
    int ii = N - 2;
    int xx = x + 1;
    int ix = N;
    if (N >= 3 && x + 2 <= k) {
      a[ii = N - 3] = xx = x + 2;
    }
    a[N - 2] = x - 1;
    a[N - 1] = x;
    a[N    ] = x + 1;
    if (N >= 3 && x - 2 >= 1) {
      a[ix = N + 1] = xi = x - 2;
    }
    int y = 0;
    FOR(i, 0, ii - 1) {
      if (++y == xi) y = xx + 1;
      a[i] = y;
    }
    FOR(i, ix + 1, k - 1) {
      if (++y == xi) y = xx + 1;
      a[i] = y;
    }
  }
  if (ng) {
    puts("No");
  } else {
    puts("Yes");
    REP(i, k) printf("%d\n", a[i]);
  }
}

void input() {
  scanf("%d%d", &N, &x);
}

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


Measured memory_bytes: 2176
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <map>
#include <random>
#include <string>
#include<vector>
#include<stack>
#include <cstdlib>


using namespace std;

int main() {
	int k, x;
	cin >> k >> x;
	if (k * 500 >= x) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {

	//int D = 365;
	int D; cin >> D;

	vector<int> c(26,0);
	vector<vector<int>> s(D,vector<int>(26,0));
	vector<int> t(D,0);

	for (int i = 0; i < 26; i++) {
		cin >> c[i];
	}

	for (int i = 0; i < D; i++) {
		for (int j = 0; j < 26; j++) {
			cin >> s[i][j];	
		}
	}

	vector<int> MAX(D,0);
	for (int i = 0; i < D; i++) {
		int ans =0;
		int idx = 0;
		for (int j = 0; j < 26; j++) {
			if (MAX[i] < s[i][j]) {
				MAX[i] = s[i][j];	
				t[i] = j+1;	
			}
		}
	}

	int ANSER = 0;
	vector<int> last(26,0);
	for (int i = 0; i < D; i++) {
		ANSER += s[i][t[i]-1];	
		last[t[i]-1] = i+1;
		for (int j = 0; j < 26; j++) {
			ANSER -= c[j] * ((i+1) - last[j]) ;
		}
	}

	int cnt = 10000;
	while(cnt > 0) {
		vector<int> last(26,0);
		int d = (rand() % 365);
		int q = (rand() % 26) + 1;
		int old = t[d];
		t[d] = q;
		int ans = 0;
		for (int i = 0; i < D; i++) {
			ans += s[i][t[i]-1];	
			last[t[i]-1] = i+1;
			for (int j = 0; j < 26; j++) {
				ans -=	c[j] * ((i+1) - last[j]) ;
			}
		}
		if (ans < ANSER) {
			t[d] = old;	
		}else {
			ANSER = ans;
		}
		//cout << ANSER << endl;
		cnt--;
	}

	for (int i = 0; i < D; i++) {
		cout << t[i] << endl;
	}



	return 0;
}


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

using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  int pl, pr, l[M], r[M];  
  for(int i=0; i<M; ++i){
    cin >> l[i] >> r[i];
    if(i == 0)
     pl = l[i], pr = r[i];
  }
  int res = 0;
  for(int i=1; i<M; ++i){
    if(l[i] > pl)
      pl = l[i];
    if(r[i] < pr)
      pr = r[i];
  }
  if(pl > pr)
    res = 0;
  else
    res = pr - pl + 1;
  cout << res << "\n";
  return 0;
} 


Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        TreeMap<Integer, Integer> map = new TreeMap<>(Collections.reverseOrder());
        for(int i = 0; i < n; i++) {
            int num = sc.nextInt();
            map.put(num, map.getOrDefault(num, 0) + 1);
        }
        int count = 2;
        long area = 1;
        Iterator entries = map.entrySet().iterator();
        while(entries.hasNext()) {
            Map.Entry entry = (Map.Entry)entries.next();
            int value = (Integer)entry.getValue();
            while(value >= 2 && count != 0) {
                area *= (Integer) entry.getKey();
                value -= 2;
                count--;
            }
            if(count == 0) break;
        }
        if(count == 0) {
            System.out.println(area);
        } else {
            System.out.println(0);
        }
    }
}


Measured memory_bytes: 64232
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define forn(i,a,n) for(int i=a; i < n; i++)
typedef long long int lli;
typedef long double Double;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int maxn = 2000005;
const int mod = 998244353;
const int inf = 1<<30;

void solve(){
	int ans=0;
	int n;
	cin >> n;
	vi a(n);
	//a+b > c
	for(int i=0; i < n; i++) cin >> a[i];
	sort(all(a));
	for(int i=0; i < n; i++){
		for(int j=i+1; j < n; j++){
			for(int k=j+1; k < n; k++){
				if(a[i] == a[j] || a[i] == a[k] || a[j] == a[k]) continue;
				if(a[i] + a[j] > a[k]){
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
}

int main(){__
	int t=1;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define ll long long
#define db double
using namespace std;
const db PI=acos(-1.);
db sqr(db x){return x*x;}
db get_cos_len(db a,db b,db ang)
{return sqrt(sqr(a)+sqr(b)-2*cos(ang)*a*b);}
db A,B,H,M;
int main()
{
    scanf("%lf%lf%lf%lf",&A,&B,&H,&M);
    db ang=fabs(2*PI/60.*M-(2*PI/12.*H+2*PI/12./60.*M));
    printf("%.10f\n",get_cos_len(A,B,ang));
    return 0;
}


Measured memory_bytes: 4188
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <bitset>
#include <list>
#include <iomanip>
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a,n) for(ll i=n;i>=a;i--)
#define elif else if
#define all(s) s.begin(),s.end()
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF = 1e+17;
const ll MODcdf = 998244353;
bool pairCompare(const P& firstElof,const P& secondElof){
    return firstElof.first<secondElof.first;
}
string A="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string a="abcdefghijklmnopqrstuvwxyz";
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n,m;cin>>n>>m;
    ll l[m],r[m];
    rep(i,0,m)cin>>l[i]>>r[i];
    ll st=l[0];
    ll gl=r[0];
    rep(i,0,m){
        st=max(st,l[i]);
        gl=min(gl,r[i]);
    }
    ll ans=gl-st+1;
    if(ans<0)ans=0;
    cout<<ans<<endl;
}


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


int main(){
  string S;
  cin >> S;
  int redc=0;
  int bluec=0;
  for(int i=0; i<S.size(); ++i){
    if(S.at(i)=='0'){
      redc++;}
    else if(S.at(i)=='1'){
      bluec++;}
    }
    int res=min(redc, bluec)*2;
      
   cout << res << endl;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
    public static void Main()
    {
        var n = ReadLine().Split(' ');
        var a = long.Parse(n[0]);
        var b = (long)(double.Parse(n[1]) * 100d);
        if(a == 0L || b == 0L)
        {
            WriteLine("0");
            return;
        }
        long result = a * b / 100L;
        WriteLine(result);
    }
}

Measured memory_bytes: 27544
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main() {
  ll N;

  cin >> N;

  if (N % 2) {
    cout << 0 << endl;
  } else {
    ll ans2 = 0, ans5 = 0;
    ll e18 = 1e18;

    for (ll i=2; i<=e18; i*=2) {
      ans2 += N / i;
    }

    for (ll i=10; i<=e18; i*=5) {
      ans5 += N / i;
    }

    cout << min(ans2, ans5) << endl;
  }

  return 0;
}


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

using namespace std;

vector<int> v,w;

int main(){
	ostringstream out;

	int N,W,v,w,m=0;
	cin >> N >> W;
	vector<int> list(W+1);

	for(int i=0;i<N;i++){
		cin >> v >> w;
		for(int i=list.size()-1;i>=0;i--){
			if(i+w<list.size()&&(list[i]||i==0)){
				list[i+w]=max(list[i+w],list[i]+v);
				m=max(m,list[i+w]);
			}
		}
	}

	out << m << endl;

	cout << out.str();
	return 0;
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>  // ver2.1.9
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define Pii pair<int,int>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lW,0,a.size()){Vout(a[lW]);}
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;
 
int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void uniq(Vi &v){sort(ALL(v)); v.erase(unique(ALL(v)),v.end());}  //  uniqのやつ
 
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
 
signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n;
  cin >> n;
  rep(i,1,3501){
    rep(j,i,3501){
      if(4*i*j < n*(i+j)) continue;
      rep(k,j,3501){
        if(4*i*j*k > n*(i*j+j*k+k*i)) break;
        if(4*i*j*k == n*(i*j+j*k+k*i)) {cout<<i<<' '<<j<<' '<<k<<endl;return 0;}
      }
    }
  }
  return 0;
}

Measured memory_bytes: 384
import numpy as np
import math

N = int(input())
ave = []
ans = 0.0

x = np.zeros(N)
y = np.zeros(N)
for i in range(N):
    x[i], y[i] = map(int, input().split())

for i in range(N):
    Sum = 0
    for j in range(N):
        if(i == j):
            continue
        else:
            Sum += math.sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2)

    ans += (Sum / float(N))

print(ans)

Measured memory_bytes: 21484
<?php
$s=str_split(trim(fgets(STDIN))."ox");
$s=array_count_values($s);
if($s["o"]+$s["x"]==17){
  if($s["o"]>=9){
    echo "YES";
  }else{
    echo "NO";
  }
}elseif($s["o"]+$s["x"]==16){
  if($s["o"]>=8){
    echo "YES";
  }else{
    echo "NO";
  }
}else{
  $n=15-$s["o"]-$s["x"]+1;
  if($n+$s["o"]>=8){
    echo "YES";
  }else{
    echo "NO";
  }
}


Measured memory_bytes: 4728
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
	long long int a,b,c,d,e,f;
	cin>>a>>b>>c>>d;
	e=c/b;
	f=a/d;
	if(c%b!=0){
		e++;
	}
	if(a%d!=0){
		f++;
	}
	if(e>f){
		cout<<"No"<<endl;
	}
	else{
		cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    bool f = false;
    rep(i, 0, s.size() - 1) if(s[i] == s[i + 1]) f = true;
    if(f) cout << "Bad" << endl;
    else cout << "Good" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cassert>

using namespace std;

struct Node {
  Node* l, * r;
};

Node nodes[256];
int counter;

void Init() {
  memset(nodes, 0, sizeof(nodes));
  counter = 0;
}

Node* Parse(const char*(& s)) {
  if (*s != '(') {
    return nullptr;
  }
  s++;
  Node* node = &nodes[counter++];
  node->l = Parse(s);
  assert(*s == ',');
  s++;
  node->r = Parse(s);
  assert(*s == ')');
  s++;
  return node;
}

Node* Intersect(Node* a, Node* b) {
  if (a->l && b->l) {
    a->l = Intersect(a->l, b->l);
  } else {
    a->l = nullptr;
  }
  if (a->r && b->r) {
    a->r = Intersect(a->r, b->r);
  } else {
    a->r = nullptr;
  }
  return a;
}

Node* Union(Node* a, Node* b) {
  if (a->l && b->l) {
    a->l = Union(a->l, b->l);
  } else if (b->l) {
    a->l = b->l;
  }
  if (a->r && b->r) {
    a->r = Union(a->r, b->r);
  } else if (b->r){
    a->r = b->r;
  }
  return a;
}

Node* Solve(const string& type, Node* a, Node* b) {
  Node* r;
  if (type == "i") {
    r = Intersect(a, b);
  } else {
    r = Union(a, b);
  }
  return r;
}

void Print(const Node* a) {
  cout << "(";
  if (a->l) {
    Print(a->l);
  }
  cout << ",";
  if (a->r) {
    Print(a->r);
  }
  cout << ")";
}

int main() {
  string type, a, b;
  while (cin >> type >> a >> b) {
    Init();
    const char* pa = a.c_str();
    const char* pb = b.c_str();
    Node* ta = Parse(pa);
    Node* tb = Parse(pb);
    Print(Solve(type, ta, tb));
    cout << endl;
  }
}

Measured memory_bytes: 3052
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int N;
  cin >> N;
  string S;
  cin >> S;
  int a[26] = {};
  REP(i, N)
  a[S[i] - 'a']++;
  ll ans = 1;
  REP(i, 26)
  {
    ans *= (a[i] + 1);
    ans %= MOD;
  }
  cout << ans - 1 << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<=(end);i++)
#define REP(i, n) FOR(i,1,n)
#define IFOR(i, begin, end) for(int i=(end);i>=(begin);i--)
#define IREP(i, n) IFOR(i,1,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())

#define ll long long
using namespace std;

bool is_prime(int k)
{
    for(int j=2;j*j<=k;j++){
        if(k%j==0) {
            return false;
        }
    }
    return true;
}

int main()
{
	stringstream ss;
    // 入力
    int N;
    cin>>N;
    ll x[N+1],y[N+1],h[N+1];
    int hindex=-1;
    FOR(i,1,N){
        cin>>x[i]>>y[i]>>h[i];
        if(h[i]>0) hindex=i;
    }
    if(N==1){
        cout<<x[1]<<" "<<y[1]<<" "<<h[1];
        return 0;
    }

    ll hans[101][101];
    int ansnum=101*101;
    FOR(i,0,100){
        FOR(j,0,100){
            hans[i][j]=h[hindex]+abs(i-x[hindex])+abs(j-y[hindex]);
        }
    }
    FOR(n,1,N){
    FOR(i,0,100){
        FOR(j,0,100){
        if(max(hans[i][j]-abs(i-x[n])-abs(j-y[n]),(ll)0)!=h[n]){
            hans[i][j]=-1;
        }
        }
    }
    }



    FOR(i,0,100){
        FOR(j,0,100){
            if(hans[i][j]!=-1) cout<<i<<" "<<j<<" "<<hans[i][j]<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cstddef>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

auto f(const vector<uint64_t>& A, uint64_t X) {
    auto output = 0ull;
    for (auto Ai: A) {
        output += Ai^X;
    }
    return output;
}

auto solve(const vector<uint64_t>& A, const uint64_t K) {
    auto X = 0ull;
    for (auto d = 41; d >= 0; d--) {
        auto numOnes = 0u;
        const auto mask = (1ull << d);
        for (const auto Ai: A) {
            if (Ai & mask) numOnes++;
        }
        //cout << "digit " << d << " has " << numOnes << " ones" << endl;
        if (numOnes <= A.size()/2 && (X | mask) <= K) {
            X |= mask;
        }
    }
    return f(A, X);
}

int main()
{
    uint64_t N, K;
    cin >> N >> K;
    vector<uint64_t> A;
    for (auto i = 0u; i < N; i++) {
        uint64_t Ai;
        cin >> Ai;
        A.push_back(Ai);
    }
    cout << solve(A, K) << endl;
    return 0;
}

Measured memory_bytes: 1400