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

using namespace std;

#define ff first
#define ss second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double EPS = 1e-6;
const int MAX_LENGTH = 3005;

string s, t;
int dp[MAX_LENGTH][MAX_LENGTH];
pi pre[MAX_LENGTH][MAX_LENGTH];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> s >> t;
	for (int i = 1; i <= s.size(); ++i) {
		for (int j = 1; j <= t.size(); ++j) {
			dp[i][j] = -1;
			if (s[i - 1] == t[j - 1] && dp[i - 1][j - 1] + 1 > dp[i][j]) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
				pre[i][j] = {i - 1, j - 1};
			}
			if (dp[i - 1][j] > dp[i][j]) {
				dp[i][j] = dp[i - 1][j];
				pre[i][j] = {i - 1, j};
			}
			if (dp[i][j - 1] > dp[i][j]) {
				dp[i][j] = dp[i][j - 1];
				pre[i][j] = {i, j - 1};
			}
		}
	}

	vector<char> ans;
	pi cur = {s.size(), t.size()};
	while (cur.ff > 0 && cur.ss > 0) {
		pi p = pre[cur.ff][cur.ss];
		if (p.ff < cur.ff && p.ss < cur.ss) ans.push_back(s[cur.ff - 1]);
		cur = p;
	}
	
	for (int i = ans.size() - 1; i >= 0; --i) {
		cout << ans[i];
	}
	cout << '\n';

	return 0;
}

Measured memory_bytes: 105984
#include <iostream>

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: 4624
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  string S;
  cin >> S;
  int N = S.size();
  vector<int> s(N);
  rep(i,N)
  {
    s[i] = S[i]-48;
  }
  int m = 753;
  for(int i=0;i<N-2;i++)
  {
    m = min(m,abs(100*s[i]+10*s[i+1]+s[i+2]-753));
  }
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

const int N = 15;
int main()
{
	int a[N] = {0};
	for(int i = 0; i < 10; i++)
	{
		scanf("%d", &a[i]);
	}
	for(int i = 0; i < 10; i++)
	{
		for(int j = i; j < 10; j++)
		{
			if(a[i] < a[j])
			{
				int temp = a[i];
				a[i] = a[j];
				a[j] = temp;
			}
		}
	}
	for(int i = 0; i < 3; i++)
	{
		printf("%d\n", a[i]);
	}
}


Measured memory_bytes: 2680
#include<bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const int N_MAX = 1000005;
const int LOG_MOD = 30;//ceil(log2(MOD))
long long int table_n_k[LOG_MOD+1],table_k[LOG_MOD+1];
//(n-k!)^1,(n-k!)^2,(n-k!)^4...を保存するテーブル
//k!^1,k!^2,k!^4...を保存するテーブル
long long int kaijo[N_MAX+1];
//kaijo[1]=1!,kaijo[2]=2!...というように階乗の値を保存しておく配列

//階乗配列を初期化する関数
void initKaijo(){
  kaijo[0]=1;
  for(int i=0;i<N_MAX;i++){
    kaijo[i+1]=kaijo[i]*(i+1)%MOD;
  }
}

long long int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    table_n_k[0]=kaijo[n-k];
    table_k[0]=kaijo[k];
    //下のfor文で((n-k)!)^1,((n-k)!)^2,((n-k)!)^3....を計算
    for(int i=0;i<LOG_MOD+1;i++){
      table_n_k[i+1]=(table_n_k[i]*table_n_k[i])%MOD;
      table_k[i+1]=(table_k[i]*table_k[i])%MOD;
    }

    long long int ruijo_kaijo_n_k=1;//n-kの階乗の(MOD-2)乗を入れる変数
    long long int ruijo_kaijo_k=1;//kの階乗の(MOD-2)乗を入れる変数
    int count = 0;
    for(long long int i=MOD-2;i!=0;i=i>>1){//初期値をMOD-2とし、ループごとに右シフト
      if(i&1){//もし一桁目が1であれば該当する位の累乗テーブルを掛け合わせる。
        ruijo_kaijo_n_k = ruijo_kaijo_n_k*table_n_k[count]%MOD;
        ruijo_kaijo_k = ruijo_kaijo_k*table_k[count]%MOD;
      }
      count++;
    }
    return kaijo[n]*(ruijo_kaijo_n_k*ruijo_kaijo_k% MOD) % MOD;
}
int main(){
  int X,Y;
  cin >> X >> Y;
  if ((X+Y)%3!=0){
    cout << 0;
    return 0;
  }
  int r=(X+Y)/3;
  X-=r;
  Y-=r;
  initKaijo();
  cout << COM(X+Y,Y)%MOD;
}

Measured memory_bytes: 8064
#include<stdio.h>

int n, F[44+1];

void fibonacci(){
  int i;
  
  F[0]=1;
  F[1]=1;
  for(i=2; i<=44; i++){
    F[i] = F[i-2]+F[i-1];
  }
}

int main(){
  int Ans;
  scanf("%d",&n);
  fibonacci();
  printf("%d\n",F[n]);
  return 0;
}

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

int main(){
  int k,s;
  int cnt = 0;
  cin >> k >> s;
  
  for(int x = 0;x <= k;x++){
    for(int y = 0;y <= k;y++){
      if(s - x - y >= 0 && s - x - y <= k) cnt++;
      
    }
  }
  
  cout << cnt << endl;
  
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int n = N;
        int c = 0;
        for (int i = N; i > 0; i--) {
            int ic = cnt(i);
            if (ic > c) {
                c = ic;
                n = i;
            }
        }
        System.out.println(n);
    }

    static int cnt(int n) {
        int c = 0;
        while (n > 0) {
            if (n % 2 != 0) {
                break;
            }
            n /= 2;
            c++;
        }
        return c;
    }
}

Measured memory_bytes: 21972
#include<stdio.h>

int main(){
    int H,W,i,j;
    while(true){
        scanf("%d %d",&H,&W);
        if(H==0 && W==0){
            break;
        }
        else{
            for(i=0;i<H;i++){
                for(j=0;j<W;j++){
                    if(i % 2 == 1){
                        if(j % 2 == 1){
                            printf("#");
                        }
                        else{
                            printf(".");
                        }
                    }
                    else{
                        if(j % 2 == 0){
                            printf("#");
                        }
                        else{
                            printf(".");
                        }
                    }
                }
                printf("\n");
            }
            printf("\n");
        }
    }
}


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

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

    if(N%max(H,W) == 0){
        cout << (N/max(H,W));
    }else{
    cout << (N/max(H,W)) +1;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
int main() { 
	int a,b,c;
	cin>>a;
	if(a==1)
	{
		cout<<"Hello World";
		return 0;
	}
	else
	{
		cin>>b>>c;
		cout<<b+c;
	}
    return 0; 
} 

Measured memory_bytes: 256
import heapq

n, m = map(int, input().split())

# delay, reword
jobs = [list(map(int, input().split())) for i in range(n)]
jobs_days = [[] for i in range(m)]
for job in jobs:
    if job[0] - 1 < m:
        jobs_days[job[0] - 1].append(-job[1])

reward = 0
h = []
heapq.heapify(h)

for i in range(m):
    for job in jobs_days[i]:
        heapq.heappush(h, job)
    if len(h) > 0:
        reward += heapq.heappop(h)

print(-reward)


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

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadInts();
            var x = input[0] + "" + input[1] + "" + input[2];
            var z = int.Parse(x);
            if (z % 4 == 0)
            {
                WriteLine("YES");

            }
            else
            {
                WriteLine("NO");
            }
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11220
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007


int main(int argc, char const *argv[]) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
 
    int x = x2 - x1;
    int y = y2 - y1;
 
    cout << x2 - y << " " << y2 + x << " " << x1 - y << " " << y1 + x << endl;
  return 0;
}


Measured memory_bytes: 256
/* Simplicity and Goodness */

#include <bits/stdc++.h>
using namespace std;
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define deb(x) cout << #x << ' ' << x << '\n'
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define per(i,ini) for(int i=ini;i>=0;i--)
#define tc int tt; scn(tt); while(tt --)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int N = 1e5+2;


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

    if(s.size() <= k)
    cout << s;
    else
    {
        s = s.substr(0, k);
        s += "...";
        cout << s;
    }
    return 0;   
}

Measured memory_bytes: 3596
import java.util.Scanner;


public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N ; i++) A[i] = sc.nextInt();
		int max = (K - A[N-1]) + A[0];
		for (int i = 1; i < N; i++) {
				int m = A[i] - A[i-1];
				if (max < m) max = m;
		}
		System.out.println(K - max);
	}
}

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

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz size
// #define f first
// #define s second
ll s[2001];
ll t[2001];
ll dp[2001][2001];

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll mod = 1000000007;

    ll n, m;
    cin >> n >> m;
    FOR(i,1,n+1)
        cin >> s[i];
    FOR(i,1,m+1)
        cin >> t[i];
    // dp[0][0] = 1;
    F0R(i,n+1)
    {
        F0R(j,m+1)
            dp[i][j]=0;
    }
    FOR(i,1,n+1)
    {
        FOR(j,1,m+1)
        {
        
            if(s[i] == t[j])
                dp[i][j] = (dp[i-1][j]+dp[i][j-1]+1+mod)%mod;
            else
                dp[i][j] = (dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+mod)%mod;
            // cout << dp[i][j] << " ";
        }
        // cout << endl;
    }
    cout << (dp[n][m]+1)%mod;

    return 0;
}


Measured memory_bytes: 31616
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
void inline swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
void inline swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }


class C {
	int n;
	int cnt[100001];
	const int MAX{ 100000 };
public:
	C()
	{
		memset(cnt, 0, sizeof cnt);
		cin >> n;
		
		REP(i, n)
		{
			int a;
			cin >> a;
			++cnt[a];
		}

	}
	void solve()
	{

		int ans{ 0 };

		int ma{ -1 };

		REPC(i, MAX)
		{
			int tmp = cnt[i];

			if (i - 1 >= 0)
				tmp += cnt[i - 1];

			if (i + 1 <= MAX)
				tmp += cnt[i + 1];

			chmax(ans, tmp);
		}

		cout << ans << endl;

	}
};


int main()
{
	C solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#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;
        }
    }
}

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 == "insert"){
            scanf("%d", &x);
            insert(x);
        }else if(com == "print"){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}


Measured memory_bytes: 26632
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//const int MAX=;



int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<(a-c)*(b-d);
}

Measured memory_bytes: 256
let br x y b = if b then x else y
let rec for_all_int a b f = if a >= b then true else f a && for_all_int (a+1) b f
let () =
  let h, w = Scanf.scanf "%d %d" (fun a b -> a, b) in
  let s = Array.init h (fun _ -> Scanf.scanf " %s" (fun x -> x)) in
  for_all_int 0 h (fun x -> for_all_int 0 w (fun y ->
    [1, 0; 0, 1; -1, 0; 0, -1] |> List.exists (fun (dx, dy) ->
      let nx, ny = x + dx, y + dy in
      (0 <= nx) && (nx < h) && (0 <= ny) && (ny < w) && (s.(x).[y] = '.' || s.(nx).[ny] = '#'))))
  |> br "Yes" "No" |> print_endline


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int A, B;
    cin >> A >> B;
    string s;
    cin >> s;
    rep(i, A){
        if(!(s[i] >= '0' && s[i] <= '9')) {
            output("No");
            return 0;
        }
    }
    if(s[A] != '-'){
        output("No");
        return 0;
    }
    
    rep(i, A + 1, A + B + 1){
        if(!(s[i] >= '0' && s[i] <= '9')) {
            output("No");
            return 0;
        }
    }
    output("Yes");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

int main()
{
    ll N,A,B;
    cin >> N >> A >> B;
    if(B < A || (A != B && N == 1)){
        cout << 0 << endl;
        return 0;
    }
    if(A == B){
        cout << 1 << endl;
    }else{
        cout << ((B-A)*(N-2) + 1) << endl;
    }

}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const int Nmax=200010;
int main() {
	ll n;
	cin >> n;
	
	ll a[n][20]={};
	for(int i=0;i < n;i++){
		int num;
		cin >> num;
		int bit = 0;
		while(num != 0){
			a[i][bit]=(num%2);
			num /= 2;
			bit++;
		}
	}
	ll ans=0;
	ll s[20]={0};
	ll count = 0;
	ll index = 0;
	for(int i=0;i < n;i++){
		int flag = 1;
		for(int j=0;j < 20;j++){
			s[j] += a[i][j];
			if(s[j] >= 2) flag = 0;
		}
		if(flag == 1){
          	count ++;
			ans += count;
		}else{
			int Flag = 0;
			while(Flag == 0){
				Flag = 1;
				for(int j=0;j < 20;j++){
					s[j] -= a[index][j];
					if(s[j] >= 2) Flag = 0;
				}
              if(Flag==0){
              	count--;
             	index++;
              }else{
                index++;
                ans+=count;
              }
			}
		}
	}
	
	cout << ans << endl;
	return 0;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;
using PP = pair<P, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main() {
	llong N, Q;
	vector<PP> event;

	cin >> N >> Q;
	event.resize(N*2 + Q);

	llong S, T, X;
	for (int i = 0; i < N; i++) {
		cin >> S >> T >> X;
		event[i] = PP(P(S-X,1), X);
		event[i+N] = PP(P(T-X,0), X);
	}
	llong D;
	for (int i = 0; i < Q; i++) {
		cin >> D;
		event[N*2 + i] = PP(P(D,2), 0);
	}

	sort(ALL(event));
	set<llong> s;
	for (auto eve : event) {
		int tm = eve.first.first;
		int id = eve.first.second;
		int pos = eve.second;

		if (id == 0) {
			s.erase(pos);
		} else if (id == 1) {
			s.insert(pos);
		} else {
			if (s.size() == 0)
				cout << -1 << endl;
			else
				cout << *s.begin() << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 26496
/****************************************************************************************************
                                        SUBMITTED BY-

                                            AISH_07

****************************************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ll long long
#define sl set<ll>
#define vs vector<string>
#define pb push_back
#define vl vector<ll>
#define vi vector<int>
#define PI  3.14159265
#define mod 998244353
int main()
{
    int n;
    cin>>n;
    double a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);

    double res=(a[0]+a[1])/2.0;

    for(int i=2;i<n;i++)
    {
        res+=a[i];
        res/=2.0;
    }
    cout<<res<<"\n";
   return 0;
}


Measured memory_bytes: 3764
// D - Sum of Large Numbers
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll sigma_n(ll s, ll e){
	s--;
	return e*(e+1)/2 - s*(s+1)/2;
}
ll sigma_n2(ll s, ll e){
	s--;
	return e*(e+1)*(2*e+1)/6 - s*(s+1)*(2*s+1)/6;
}

int main(){
	ll N, K, MOD = 1'000'000'007;
	cin>>N>>K;
	ll n = sigma_n(K, N+1);
	ll n2 = sigma_n2(K, N+1);
	ll c = N - K + 2;
	ll ans = ((N+1)*n - n2 + c) % MOD;
	cout<< (ans + MOD) % MOD <<endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
using namespace std;

class UnionFind
{
    private:
        std::vector<int> parent;  // parent[x]: x の根の番号
                                  //            x が根の場合はその連結成分の大きさ
        std::vector<int> rank;    // rank[x]  : x が属する木の高さ
        std::size_t sz;           // 連結成分の数

    public:
        // x が親の場合、parent[x] = -(その連結成分の大きさ)
        UnionFind( std::size_t n ): parent(n, -1), rank(n, 0), sz(n) {}

        // x が属する集合の親を返し、x を親に直接繋ぎ直す(経路圧縮)
        int find( int x )
        {
            if( parent[x] < 0 ) return x;
            else return parent[x] = find( parent[x] );
        }

        // x が属する集合と y が属する集合を統合する
        bool unite( int x, int y )
        {
            x = find( x );
            y = find( y );
            if( x == y ) return false;

            // 大きい方(x)に小さい方(y)を繋げる
            if( rank[x] < rank[y] ) std::swap( x, y );

            parent[x] += parent[y];  // x に連結している成分の大きさを更新する
            parent[y] = x;           // y を x に繋ぐ
            if( rank[x] == rank[y] ) rank[x]++;
            sz--;

            return true;
        }

        bool same( int x, int y ) { return find(x) == find(y); }
        std::size_t size()        { return sz; }
        std::size_t size( int x ) { return - parent[find(x)]; }
};

struct edge{
    int from, to, cost;
    edge(int i, int j, int c): from(i), to(j), cost(c) {}
};

bool operator> (const edge& edge1, const edge& edge2){
    return edge1.cost > edge2.cost;
}

int main()
{
    int N;
    cin >> N;
    vector<pair<int,int>> x(N), y(N);  // (coordinate, index)
    for(int i = 0; i < N; ++i){
        int x_in, y_in;
        cin >> x_in >> y_in;
        x[i] = make_pair(x_in, i);
        y[i] = make_pair(y_in, i);
    }

    // 変の候補を priority_queue に挿入
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    priority_queue<edge, vector<edge>, greater<edge>> q;
    for(int i = 0; i < N-1; ++i){
        q.push(edge(x[i].second, x[i+1].second, abs(x[i].first-x[i+1].first)));
        q.push(edge(y[i].second, y[i+1].second, abs(y[i].first-y[i+1].first)));
    }

    UnionFind uni(N);
    long long ans = 0;
    while(!q.empty()){
        auto tmp = q.top();
        q.pop();
        if(uni.same(tmp.from, tmp.to)) continue;
        uni.unite(tmp.from, tmp.to);
        ans += tmp.cost;
    }
    cout << ans << endl;

    return 0;
} 

Measured memory_bytes: 6388
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int N, x;
    cin >> N >> x;
    vector<int> a(N);
    for (auto& i : a) cin >> i;
    sort(a.begin(), a.end());
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (x >= a[i]) {
            ans++;
            x -= a[i];
        }
        else {
            x = 0;
            break;
        }
    }
    cout << ans - (x == 0 ? 0 : 1) << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
def gcd(m, n):
  while n != 0:
    m, n = n, m % n
  return m
gl = [A[0]]
gr = [A[N-1]]
x, y = A[0], A[N-1]
for i in range(1, N):
  x = gcd(x, A[i])
  gl.append(x)
  y = gcd(y, A[N-i-1])
  gr.append(y)
gg = [gr[N-2]]
for i in range(1, N-1):
  gg.append(gcd(gl[i-1], gr[N-i-2]))
gg.append(gl[N-2])
if N != 2:
  print(max(gg))
else:
  print(max(A[0], A[1]))


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

public class Main implements Runnable {
    public static void main(String[] args) {
        new Thread(null,new Main(), "" ,Runtime.getRuntime().maxMemory()).start();
    }

    public void run() {
        FastScanner sc = new FastScanner();
        int x = sc.nextInt();
        while(true) {
            if(x % 2 == 0) {
                if(x == 2) {
                    System.out.println(x);
                    break;
                }
                else{
                    x++;
                    continue;
                }
            }
            boolean isPrime = true;
            for(int i = 3;i < x;i++) {
                if(x % i == 0) {
                    isPrime = false;
                    break;
                }
            }
            if(isPrime) {
                System.out.println(x);
                break;
            }
            else x++;
        }
    }

}

class FastScanner {
    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() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; 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 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();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 23252
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define IREP(i, v) for(auto i = (v).begin(); i != (v).end(); ++i)
#define IRREP(i, v) for(auto i = (v).rbegin(); i != (v).rend(); ++i)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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


int main(){
    string S; cin >> S;
    VI cnt(3, 0);
    REP(i, S.length()) ++cnt[S[i] - 'a'];
    REP(i, 3)
        REP(j, 3)
            if(abs(cnt[i] - cnt[j]) > 1){
                cout << "NO" << endl;
                return 0;
            }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 512
#include<cstdio>
using namespace std;

typedef const int& cint;
typedef long long ll;

const ll mod = 1e9 + 7;
const int MAXN = 2010, MAXM = 4000010;

int f[MAXN][MAXN], fsum[MAXN][MAXN];
int fac[MAXM], finv[MAXM];

inline ll fpow(ll a, ll b){
	ll res = 1;
	while (b){
		if (b & 1)
			res = res * a % mod;
		a = a * a % mod, b >>= 1;
	}
	return res;
}

inline ll C(cint n, cint m){
	return 1ll * fac[n] * finv[n - m] % mod * finv[m] % mod;
}

inline ll g(cint n, cint m){
	return C(m + n - 1, m - 1);
}

void init(cint n){
	fac[0] = 1;
	for (int i = 1; i <= n; ++i)
		fac[i] = 1ll * fac[i - 1] * i % mod;
	finv[n] = fpow(fac[n], mod - 2);
	for (int i = n - 1; i >= 0; --i)
		finv[i] = 1ll * finv[i + 1] * (i + 1) % mod;
}

int main(){
	int N, K;
	scanf("%d %d", &N, &K);
	if (K == 1){
		printf("1");
		return 0;
	} 
	init(4000000);
	f[0][0] = fsum[0][0] = 1;
	for (int i = 1; i <= N; ++i){
		for (int j = 1; j <= i; ++j)
			f[i][j] = 1ll * fsum[i - 1][j - 1] * g(K - 2, K * (i - 1) - (j - 1) + 1) % mod;
		for (int j = i; j >= 0; --j)
			fsum[i][j] = (fsum[i][j + 1] + f[i][j]) % mod;
	}
	printf("%lld", 1ll * fsum[N][1] * fac[N] % mod);
	return 0;
}


Measured memory_bytes: 62848
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
bool flag[10];
bool check(int x){
	char s[100];
	sprintf(s,"%d",x);
	for(int i=0;s[i];i++)
		if(flag[s[i]-'0'])
			return false;
	return true;
}
int main(){
	int n,m;
	while(~scanf("%d%d",&n,&m)){
		int temp;
		for(int i=0;i<m;i++){
			scanf("%d",&temp);
			flag[temp]=1;
		}
		int ans;
		for(int i=n;;i++)
			if(check(i)){
				ans=i;
				break;
			}
			printf("%d\n",ans);
	}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  vector<ll> P(A);
  rep(i, A) cin >> P[i];
  vector<ll> Q(B);
  rep(i, B) cin >> Q[i];
  vector<ll> R(C);
  rep(i, C) cin >> R[i];
  sort(P.begin(), P.end(), greater<ll>());
  sort(Q.begin(), Q.end(), greater<ll>());
  rep(i, X) R.push_back(P[i]);
  rep(i, Y) R.push_back(Q[i]);
  sort(R.begin(), R.end(), greater<ll>());
  // ll ans = 0;
  // rep(i, X+Y) ans += R[i];
  ll ans = accumulate(R.begin(), R.begin() + X + Y, 0LL);
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 7776
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		ArrayList<String> lines = new ArrayList<String>();

		String string = "";
		int cn = 0;
		while (true) {
			string = sc.nextLine();
			lines.add(string);
			cn++;
			if (string.equals("0 0")) {
				break;
			}
		}
		
		String[] kari1 = new String[2];

		for (int i = 0; i < cn; i++) {
			kari1 = lines.get(i).split(" ");
			int[] kari2 = {Integer.parseInt(kari1[0]),Integer.parseInt(kari1[1])};
			Arrays.sort(kari2);
			if (kari2[0] == 0 && kari2[1] == 0) {
				break;
			} else {
				System.out.print(kari2[0]);
				System.out.print(" ");
				System.out.println(kari2[1]);
			}
		}
	}
}

Measured memory_bytes: 36096
#!/usr/bin/env python3
import sys

sys.setrecursionlimit(10**9)

N = int(input())
# XY_L = [[int(_) for _ in input().split()] for __ in range(N)]
X_L = [None] * N
Y_L = [None] * N
for i in range(N):
    _x, _y = map(int, input().split())
    X_L[i] = [_x, i]
    Y_L[i] = [_y, i]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# class UnionFind():
#     def __init__(self, n):
#         self.rank = [1] * n
#         self.par = [int(_) for _ in range(n)]

#     def find(self, x):
#         if self.par[x] == x:
#             return x
#         else:
#             self.par[x] == self.find(self.par[x])
#             return self.par[x]

#     def unite(self, x, y):
#         p_x = self.find(x)
#         p_y = self.find(y)
#         if p_x == p_y:
#             return False
#         if self.rank[p_x] < self.rank[p_y]:
#             self.par[p_x] = p_y
#         else:
#             self.par[p_y] = p_x
#             if self.rank[p_x] == self.rank[p_y]:
#                 self.rank[p_x] += 1
#         return True
    
#     def same(self, x, y):
#         if self.find(x) == self.find(y):
#             return True
#         else:
#             return False

X_L.sort()
Y_L.sort()
dx_l = [None] * (N-1)
dy_l = [None] * (N-1)
for i in range(N-1):
    dx_l[i] = [X_L[i+1][0] - X_L[i][0], X_L[i][1], X_L[i+1][1]]
    dy_l[i] = [Y_L[i+1][0] - Y_L[i][0], Y_L[i][1], Y_L[i+1][1]]

tmp_l = dx_l+dy_l
tmp_l.sort()

UF = UnionFind(N)
ans = 0

for _ in range(2*N-2):
    _d, _i, _j = tmp_l[_]
    if UF.same(_i, _j):
        continue
    UF.unite(_i, _j)
    ans += _d
    # if _ % 1000 == 0:
    #     print(_,ans)



print(ans)



Measured memory_bytes: 65496
#include <iostream>
//#include <algorithm>
using namespace std;

int main() {
  char c;
  cin >> c;

  if(c == 'A'){
    cout << 'T' << endl;
  }else if(c == 'T'){
    cout << 'A' << endl;
  }else if(c == 'G'){
    cout << 'C' << endl;
  }else if(c == 'C'){
    cout << 'G' << endl;
  }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  vector<int> v(3);
  for(int i = 0; i < 3; i++) cin >> v[i];
  sort(v.begin(),v.end());

  int cnt = 0;
  while(v[0] != v[2]){
    if(v[0] == v[1]){
      v[0]++;
      v[1]++;
      cnt++;
    }
    else {
      v[0] += 2;
      cnt++;
    }
    sort(v.begin(),v.end());
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
using System;

namespace ABC075B
{
    class Program
    {
        static void Main(string[] args)
        {
            var target = Console.ReadLine().Split(' ');
            int H = int.Parse(target[0]);
            int W = int.Parse(target[1]);
            char[,] map = new char[H, W];
            for(int i=0;i<H;i++) {
                var target1 = Console.ReadLine().ToCharArray();
                for(int j=0;j<W;j++) map[i,j] = target1[j];
            }
            for(int i=0;i<H;i++) {
                for(int j=0;j<W;j++) {
                    if(map[i,j] == '.'){
                        int count = 0;
                        int[] d = new int[3]{-1, 0, 1}; 
                        int[] e = new int[3]{-1, 0, 1}; 
                        foreach(var h in d){
                            foreach(var g in e){
                                if(i+h >= 0 && i+h < H && j+g >= 0 && j+g < W){
                                    if(h != 0 || g != 0)
                                        if(map[i+h, j+g] == '#') count++;
                                }
                            }
                        }
                        map[i,j] = count.ToString()[0];
                    }
                }
            }
            for(int i=0;i<H;i++) {
                for(int j=0;j<W;j++) Console.Write(map[i,j]);
                Console.WriteLine();
            }
        }
    }
}


Measured memory_bytes: 13140
N = int(input())
H = [int(line) for line in input().split()]

ans = []
for i in range(1,N):
    count = 0
    for j in range(i):
        if H[i] >= H[j]:
            count += 1
    if count == i:
        ans.append(i)
print(len(ans)+1)

Measured memory_bytes: 38384
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

int main()
{
	int n, m;
	while (scanf("%d %d", &n, &m), n | m)
	{
		int d[2][101][101];
		for (int i = 0; i <= m; ++i)
			for (int j = 0; j <= m; ++j)
				d[0][i][j] = d[1][i][j] = 100000000;
		for (int i = 0; i <= m; ++i)
			d[0][i][i] = d[1][i][i] = 0;

		for (int i = 0; i < n; ++i)
		{
			int a, b, cost, time;
			scanf("%d %d %d %d", &a, &b, &cost, &time);
			d[0][a][b] = d[0][b][a] = cost;
			d[1][a][b] = d[1][b][a] = time;
		}
		for (int k = 0; k <= m; ++k)
			for (int i = 0; i <= m; ++i)
				for (int j = 0; j <= m; ++j)
					for (int l = 0; l < 2; ++l)
						d[l][i][j] = min(d[l][i][j], d[l][i][k] + d[l][k][j]);

		int queries;
		scanf("%d", &queries);
		for (int i = 0; i < queries; ++i)
		{
			int p, q, r;
			scanf("%d %d %d", &p, &q, &r);
			printf("%d\n", d[r][p][q]);
		}
	}

	return 0;
}

Measured memory_bytes: 960
#include<stdio.h>
#include<algorithm>
#include<set>
using namespace std;
char in[3];
set<int> S[5];
set<int> U;
int cur;
char str[110000];
set<int>expr();
set<int>term(){
    if(str[cur]=='('){
        cur++;
        set<int>ret=expr();
        cur++;
        return ret;
    }
    if(str[cur]=='c'){
        cur++;
        set<int>tmp=term();
        set<int>ret;
        for(set<int>::iterator it=U.begin();it!=U.end();it++){
            if(!tmp.count(*it))ret.insert(*it);
        }
        return ret;
    }
    if(str[cur]=='U'){
        cur++;
        return U;
    }
    return S[str[cur++]-'A'];
}
set<int>expr(){
    set<int>ret=term();
    while(str[cur]=='u'||str[cur]=='i'||str[cur]=='d'||str[cur]=='s'){
        char c=str[cur];
        cur++;
        set<int>tmp=term();
        set<int>to;
        if(c=='i'){
            for(set<int>::iterator it=ret.begin();it!=ret.end();it++){
                if(tmp.count(*it))to.insert(*it);
            }
        }
        if(c=='u'){
            for(set<int>::iterator it=ret.begin();it!=ret.end();it++){
                to.insert(*it);
            }
            for(set<int>::iterator it=tmp.begin();it!=tmp.end();it++){
                to.insert(*it);
            }
        }
        if(c=='d'){
            for(set<int>::iterator it=ret.begin();it!=ret.end();it++){
                if(!tmp.count(*it))to.insert(*it);
            }
        }
        if(c=='s'){
            for(set<int>::iterator it=ret.begin();it!=ret.end();it++){
                if(!tmp.count(*it))to.insert(*it);
            }
            for(set<int>::iterator it=tmp.begin();it!=tmp.end();it++){
                if(!ret.count(*it))to.insert(*it);
            }
        }
        ret=to;
    }
    return ret;
}
int main(){
    int n;
    while(~scanf("%s%d",in,&n)){
        for(int i=0;i<5;i++)S[i].clear();
        U.clear();
        cur=0;
        for(int i=0;i<n;i++){
            int p;scanf("%d",&p);
            S[in[0]-'A'].insert(p);
            U.insert(p);
        }
        while(1){
            scanf("%s%d",in,&n);
            if(in[0]=='R')break;
            for(int i=0;i<n;i++){
                int p;scanf("%d",&p);
                S[in[0]-'A'].insert(p);
                U.insert(p);
            }
        }
        scanf("%s",str);
        set<int>res=expr();
        bool f=true;
         
        for(set<int>::iterator it=res.begin();it!=res.end();it++){
            if(!f)printf(" ");
            printf("%d",(*it));
            f=false;
        }
        if(f)printf("NULL");
        printf("\n");
    }
}


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

const int MAXN = 1005;

int h, w, ci, cj, di, dj;
char g[MAXN][MAXN];
int d[MAXN][MAXN];
bool vis[MAXN][MAXN];

int Di[] = {-1, 1, 0, 0};
int Dj[] = {0, 0, 1, -1};

int main(){
	scanf("%d %d %d %d %d %d", &h, &w, &ci, &cj, &di, &dj);
	for(int i = 0; i < h; i++)
		scanf("%s", g[i]);
		
	ci--, cj--, di--, dj--;
	
	memset(d, -1, sizeof d);
	deque < pair <int, int> > q;
	
	q.push_front(make_pair(ci, cj));
	d[ci][cj] = 0;
	
	while(!q.empty()){
		pair <int, int> t = q.front();
		q.pop_front();
		
		if(vis[t.first][t.second])continue;
		vis[t.first][t.second] = true;
		
		for(int dir = 0; dir < 4; dir++){
			int ni = t.first + Di[dir], nj = t.second + Dj[dir];
			
			if(ni < 0 || ni >= h || nj < 0 || nj >= w)continue;
			if(g[ni][nj] == '#')continue;
			
			if(d[ni][nj] == -1 || d[t.first][t.second] < d[ni][nj]){
				d[ni][nj] = d[t.first][t.second];
				q.push_front(make_pair(ni, nj));
			} 
		}
		
		for(int xi = -2; xi <= 2; xi++)
		for(int yi = -2; yi <= 2; yi++){
			int ni = t.first + xi, nj = t.second + yi;
			
			if(ni < 0 || ni >= h || nj < 0 || nj >= w)continue;
			if(g[ni][nj] == '#')continue;
			
			if(d[ni][nj] == -1 || d[t.first][t.second] + 1 < d[ni][nj]){
				d[ni][nj] = d[t.first][t.second] + 1;
				q.push_back(make_pair(ni, nj));
			}
		}
	}
	
	printf("%d\n", d[di][dj]);

	return 0;
}


Measured memory_bytes: 9748
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

ll STOL(string s){
    ll ret=0;
    rep(i,0,s.size()){
        ret+=(s[s.size()-i-1]-'0')*pow(10,i);
    }
    return ret;
}

int main(){
    int n;
    cin>>n;
    rep(i,0,n){
        int ans=0;
        int x; cin>>x;
        while(1){
            
            string s=to_string(x);
            if(s.size()==1){
              cout<<ans<<endl;
              break;
            }
            ll max_num=0;
            rep(i,1,s.size()){
                max_num=max(max_num,STOL(s.substr(0,i))*STOL(s.substr(i,s.size()-i)));
            }
            x=max_num;
            ans++;
            if(ans==1000000){
                cout<<-1<<endl;
                break;
            }
        }
    }
    
    return 0;
}



Measured memory_bytes: 3396
//---------- begin union_find ----------
pub struct DSU {
    p: Vec<i32>,
}
impl DSU {
    pub fn new(n: usize) -> DSU {
        DSU { p: vec![-1; n] }
    }
    pub fn init(&mut self) {
        for p in self.p.iter_mut() {
            *p = -1;
        }
    }
    pub fn root(&self, mut x: usize) -> usize {
        while self.p[x] >= 0 {
            x = self.p[x] as usize;
        }
        x
    }
    pub fn same(&self, x: usize, y: usize) -> bool {
        self.root(x) == self.root(y)
    }
    pub fn unite(&mut self, x: usize, y: usize) -> Option<(usize, usize)> {
        let mut x = self.root(x);
        let mut y = self.root(y);
        if x == y {
            return None;
        }
        if self.p[x] > self.p[y] {
            std::mem::swap(&mut x, &mut y);
        }
        self.p[x] += self.p[y];
        self.p[y] = x as i32;
        Some((x, y))
    }
    pub fn parent(&self, x: usize) -> Option<usize> {
        let p = self.p[x];
        if p >= 0 {
            Some(p as usize)
        } else {
            None
        }
    }
    pub fn get_size(&self, x: usize) -> usize {
        let r = self.root(x);
        (-self.p[r]) as usize
    }
}
//---------- end union_find ----------

use proconio::*;

#[fastout]
fn run() {
    input! {
        n: usize,
        q: usize,
    }
    let mut u = DSU::new(n);
    for _ in 0..q {
        input! {
            op: u8,
            a: usize,
            b: usize,
        }
        if op == 0 {
            u.unite(a, b);
        } else {
            let ans = u.same(a, b) as u8;
            println!("{}", ans);
        }
    }
}

fn main() {
    run();
}


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

#define int long long

#define rep(i,s,n) for(int i = (s);i<(n);i++)
#define repe(i,s,n) for(int i = (s);i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
const ll MOD=1000000007,INF=1e18;

int a,b;
int l[200010];

signed main(){
    cin>>a>>b;
    if(a<=0&&b>=0){
        puts("Zero");
        return 0;
    }
    if(b<0){
        if((b-a)%2==0){
            puts("Negative");
            return 0;
        }
    }
    puts("Positive");
    return 0;
    
    
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif

static void C_task();

int main()
{
	C_task();
	
	fflush(stdout);
	return 0;
}

static void C_task()
{
	int N, M;
	scanf(" %d %d", &N, &M);

	int L, R;
	int LMax = 0, RMin = N + 1;
	for (int i = 0; i < M; i++) {
		scanf(" %d %d", &L, &R);
		if (LMax < L) {
			LMax = L;
		}
		if (RMin > R) {
			RMin = R;
		}
	}
	printf("%d\n", std::max(RMin - LMax + 1, 0));
}


Measured memory_bytes: 256
def run():
  N, W = map(int, input().split())
  vw = [list(map(int, input().split())) for n in range(N)]
  dp = [0]*(W+1)
  for w in range(W+1):
    for n in range(N):
      if w < vw[n][1]:
        continue
      else:
        dp[w] = max(dp[w], dp[w-vw[n][1]]+vw[n][0])
  print(dp[-1])
    
if __name__ == '__main__':
    run()


Measured memory_bytes: 5920