akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int N, K, C[102];
const char *blah = "NO GAME";

int main() {
  while (scanf("%d%d",&N,&K), N) {
    rep(i,N) scanf("%d",C+i);
    
    int Ck = -1;
    for (int i = 0; i < N-K+1; ++i) {
      int tCk = 1;
      for (int j = 0; j < K; ++j) tCk *= C[i+j];
      Ck = max(Ck, tCk);
    }

    int Cdk = -1;
    for (int i = 0; i < N; ++i) {
      for (int j = i+1; j < N; ++j) {
        swap(C[i], C[j]);
        for (int k = 0; k < N-K+1; ++k) {
          int tCdk = 1;
          for (int l = 0; l < K; ++l) tCdk *= C[k+l];
          Cdk = max(Cdk, tCdk);
        }
        swap(C[i], C[j]);
      }
    }

    if (Ck <= Cdk) {
      printf("%d\n", Cdk - Ck);
    } else {
      puts(blah);
    }
  }
  return 0;
}

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

int main()
{
    int64_t N;
    int64_t ans = 1;
    std::cin >> N;
    for (int i = 1; i <= N; ++i) {
        ans *= i;
        ans %= 1000000007;
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String s =scan.next();
        char[] data = s.toCharArray();
        boolean found = false;
        for (int i = 0; i < 3; i++) {
            if (data[i] == data[i+1]) {
                found = true;
                break;
            }
        }
        System.out.println(found ? "Bad" : "Good");
    }
}


Measured memory_bytes: 21712
import sys

input = sys.stdin.readline

N = int(input())
H = list(map(int, input().split()))

pre = H[0]
ans = True

for i in H[1:]:
    if  pre < i: pre = i -1
    elif pre > i:
        ans = False
        break

if ans:print('Yes')
else: print('No')

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define print(a,n)  for(lli i=0;i<n;i++)cout<<a[i]<<' ';br
#define br          cout<<endl;
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define f           first
#define s           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define upar        1000000007
#define fr(i,a,b)   for(int i=a;i<=b;i++)
#define tez         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int a[10000],b[10000];



void solve() {
int a,b;
cin>>a>>b;
cout<<max({(a+b),(a-b),(a*b)});

}

signed main() {

  tez;
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}


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

typedef long long ll;
typedef pair<int,int> p_int;
typedef pair<ll,ll> p_ll;
typedef tuple<ll,ll,ll> t3_ll;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
int prime[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
const ll inf = 1e9+7;

int main() {
	ll n,k;
	cin >> n >> k;
	ll a[n];
	ll b[n];
	map<int,int> dig;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(a,a+n,greater<int>());
	int keta = 0;
	bool ga = false;
	if (a[0] >= k) {ga = true;}
	ll dicdig = max(a[0],k);
	while (dicdig != 0) {
		dig[keta] = 0;
		dicdig/=2;
		keta++;
	}
	for (int i = 0;i < n;i++) {
		if (i == 0 && dicdig) {i++;}
		for (auto itr = dig.begin();itr != dig.end();itr++) {
			if (a[i] != 0) {
				if (a[i]%2==1) {itr->second++;}
				else {itr->second--;}
				a[i]/=2;
			} else {
				itr->second--;
			}
		}
	}
	ll ans = 0;
	ll ANS = 0;
	for (auto itr = dig.rbegin();itr != dig.rend();itr++) {
		//cout << itr->second << endl;
		if (itr -> second <= 0) {
			if (ans + pow(2,itr->first) <= k) {
				ans+=pow(2,itr->first);
			}
		}
	}
	for (int i = 0;i < n;i++) {
		ANS += b[i] ^ ans;
	}
	cout << ANS << endl;
}

Measured memory_bytes: 1792
//B
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	string a,b;
	int c = 0;
	cin >> a >> b;
	for(int i = 0;i < a.size();i++)if(a[i] != b[i])c++;
	cout << c;
	return 0;
}


Measured memory_bytes: 3912
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func dis(a, b []int) float64 {
	l := 0
	for i := 0; i < len(a); i++ {
		l += (a[i] - b[i]) * (a[i] - b[i])
	}

	return math.Sqrt(float64(l))
}

func main() {
	n, d := nextInt(), nextInt()
	x := make([][]int, n)

	for i := 0; i < n; i++ {
		x[i] = make([]int, d)
		for j := 0; j < d; j++ {
			x[i][j] = nextInt()
		}
	}

	c := 0
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			dd := dis(x[i], x[j])
			if math.Ceil(dd) == dd {
				c++
			}
		}
	}

	fmt.Println(c)
}


Measured memory_bytes: 640
#include<stdio.h>
int main(){

  int h,w,i,a;
  
  while(1){
  	 	scanf("%d %d",&h,&w);
		
		if(h == 0 && w == 0)
		break;
  for(i = 1;i <= h;i++){
  	for(a = 1;a <= w;a++)
		putchar('#');
		putchar('\n');
 

	
  }
  	putchar('\n');
  }
return 0;
}




Measured memory_bytes: 2036
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
typedef long long ll;
using namespace std;
int main(void){
    ll a,b,c;cin>>a>>b>>c;
    if(c-a-b<0){
        cout<<"No"<<endl;
        return 0;
    }
    ll buf=c-a-b;
    buf*=buf;
    if(buf>4*a*b)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

typedef pair<double,double> P;

double cross(P a, P b){
  return a.first * b.second - a.second * b.first;
}

bool check(P a, P b, P c){
  
  b.first -= a.first;
  b.second -= a.second;

  c.first -= a.first;
  c.second -= a.second;
  
  if( cross( b, c ) > (1e-8) ) return false;
  
  return true;
}

int n;
vector<P> points[2], ans[2], S;

void cal(int idx, P start){
  
  for(int i=0;i<n;i++){
    
    if( idx == 0 ) points[idx][i].second *= -1;
    else points[idx][i].first *= -1;
    
  }
  
  int flg = 0;
  
  for(int i=0;i<n;i++){
    
    if( idx == 1 && start == points[idx][i] ){
      flg = 1;
      ans[idx].push_back( points[idx][i] );
      continue;
    }
    
    if( idx == 1 && flg == 0 ) continue;
    
    if( ans[idx].size() <= 1 ){
      
      ans[idx].push_back( points[idx][i] );
      
    }
    else{

      while( ans[idx].size() >= 2 ){
      
	P a = ans[idx][ans[idx].size()-2];
	P b = ans[idx][ans[idx].size()-1];
	P c = points[idx][i];
      
	if( check( a, b, c ) == true ) break;
	else ans[idx].pop_back();
	
      }
      
      ans[idx].push_back( points[idx][i] );
      
    }

  }
  
}

signed main(){
  
  cin>>n;
  
  for(int i=0;i<n;i++){
    
    int x, y;
    cin>>x>>y;
    
    points[0].push_back(P( x, -y ));
    
    points[1].push_back(P( -x, y ));

    S.push_back(P( y, x ));
    
  }
  
  sort( S.begin(), S.end() );
  
  for(int i=0;i<n;i++) swap( S[i].first, S[i].second );
  
  for(int i=0;i<2;i++) sort( points[i].begin(), points[i].end() );
  
  cal( 0, points[0][0] );
  
  cal( 1, ans[0][ans[0].size()-1] );
  
  for(int i=0;i<2;i++){
    
    for(int j=0;j<ans[i].size();j++){
      
      if( ans[i][j].first == -0 ) ans[i][j].first = 0;
      if( ans[i][j].second == -0 ) ans[i][j].second = 0;
    }
    
  }
  
  vector<P> Ans;
  set<P> used;
  
  int flg = 0;
  
  for(int i=ans[1].size()-1;i>=0;i--){
    
    if( S[0] == ans[1][i] ) flg = 1;
    
    if( flg == 0 ) continue;
    
    if( used.count( ans[1][i] ) ) continue;
    
    used.insert( ans[1][i] );
    
    Ans.push_back( ans[1][i] );
    
  }
  
  for(int i=ans[0].size()-1;i>=0;i--){
    
    if( used.count( ans[0][i] ) ) continue;
    
    used.insert( ans[0][i] );
    
    Ans.push_back( ans[0][i] );
    
  }
  
  for(int i=ans[1].size()-1;i>=0;i--){
    
    if( used.count( ans[1][i] ) ) continue;
    
    used.insert( ans[1][i] );
    
    Ans.push_back( ans[1][i] );
    
  }

  cout<<Ans.size()<<endl;
    
  for(P p : Ans) cout<<p.first<<' '<<p.second<<endl;
  
  return 0;
}



Measured memory_bytes: 14156
// Why I am so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

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

#define fi first
#define se second

using namespace std;

typedef long long ll;

int arr[105];

bool u[105];

int n, ans;

void solve() {                   
	scanf("%d", &n);

	for (int i = 1; i <= n; ++i) {
		scanf("%d", &arr[i]);
	}    
	
	for (int i = 2; i <= n; ++i) {
		if (arr[i] == arr[i - 1] && !u[i - 1]) {
			++ans;
			u[i] = 1;
		}
	}

	printf("%d\n", ans);
}

int main() {    
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int A[100];
  int N;
  int i,j,minj,temp;
  int count=0;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<=N-1;i++){
    minj = i;
    for(j=i;j<=N-1;j++){
      if(A[j]<A[minj]){
        minj=j;
      }
    }
    if(A[i]!=A[minj]){
    temp = A[i];
    A[i] = A[minj];
    A[minj] = temp;
    count++;
    }
  }
  for(i=0;i<N-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[N-1]);
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2128
package main

import (
	"fmt"
)

func solution(s string) string {
	for i := 1; i < 3; i++ {
		if s[i-1] != s[i] {
			return "Yes"
		}
	}
	return "No"
}

func main() {
	var s string
	fmt.Scan(&s)
	fmt.Println(solution(s))
}


Measured memory_bytes: 512
#include<stdio.h>
 
int main(void){
  int N,K,i,count;
  int a[100000];
  
  scanf("%d %d",&N,&K);
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
  }
  if((N-1)%(K-1)==0){
    count=(N-1)/(K-1);
  }
  else count=(N-1)/(K-1)+1;
  printf("%d",count);
}

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

int selectionSort(int A[], int N){
	int sw=0, minj=0;
	for(int i=0; i<N-1; i++){
		minj = i;
		for(int j=i; j<N; j++){
			if(A[j]<A[minj]) minj = j;
		}
		swap(A[i], A[minj]);
		if(i != minj) sw++;
	}
	return sw;
}

int main() {
	int A[100], N, sw;
	cin >> N;
	for(int i=0; i<N; i++) cin >> A[i];
	
	sw = selectionSort(A, N);
	
	for(int i=0; i<N; i++){
		if(i>0) cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << sw << endl;
	return 0;
}


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

void solve() {
    string s, t;
    cin >> s >> t;
    int k = (int) t.size();
    int n = (int) s.size();
    bool ok = 0;
    int i = n - 1;
    while(i >= 0) {
        ok = 1;
        for (int j = 0; j < k; j++) {
            if(s[i + j - k + 1] != t[j]) {
                if(s[i + j - k + 1] != '?') {
                    ok = 0;
                    break;
                }
            }
        }
        if(ok) {
            for (int q = i, p = k - 1; p >= 0; q--, p--) {
                s[q] = t[p];
            }
            break;
        }
        i--;
    }
    if(ok) {
        int j = 0;
        while (j < n) {
            if(s[j]  == '?') {
                cout << 'a';
            }
            else {
                cout << s[j];
            }
            j++;
        }
    }
    else {
        cout << "UNRESTORABLE";
    }
}


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


Measured memory_bytes: 3624
#include <stdio.h>
#include <assert.h>
#include <iostream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

string _s;
unsigned _ix;

char token() { return _ix < _s.size() ? _s[_ix] : 0; }
void next() { _ix++; }

int vars;

bool expr() {
    if (token() == 'T') { next(); return true; }
    if (token() == 'F') { next(); return false; }
    if (islower(token())) {
        const int ix =  token() - 'a';
        next();
        return vars & (1<<ix);
    }
    if (token() == '-') {
        next();
        return !expr();
    }
    assert(token() == '(');
    next();
    const bool a = expr();
    int op = -1;
    if (token() == '*') op = 0;
    if (token() == '+') op = 1;
    if (token() == '-') op = 2, next();
    next();
    const bool b = expr();
    assert(token() == ')');
    next();
    if (op == 0) return a&b;
    if (op == 1) return a|b;
    if (op == 2) return (!a)|b;
    assert(false);
    return false;
}

bool parse(const string& s) {
    _s = s;
    _ix = 0;
    return expr();
}

int main() {
    for (;;) {
        string src;
        getline(cin, src);
        if (src == "#") return 0;
        const int pos = src.find('=');
        const string left = src.substr(0, pos), right = src.substr(pos+1);
        bool ans = true;
        rep (b, 1<<11) {
            vars = b;
            if (parse(left) != parse(right)) { ans = false; break; }
        }
        puts(ans ? "YES" : "NO");
    }
}

Measured memory_bytes: 1212
#include<iostream>
#include<cstdio>
#define _USE_MATH_DEFINES
#include<math.h>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<map>
#include<unordered_map>
#include<set>
#include <algorithm>
#include <utility>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::set;
using std::vector;
using std::pair;
using std::make_pair;
using std::priority_queue;

typedef unsigned long long ull;
typedef long long ll;

#define Prime1 1000000007
#define Prime2 9999973

#define INF 0x7fffffffffffffff

ull i, j, k, l, m, n;
ull H, W, Q,S,D;
ull a, b, c, x, y;
ull K, L, N, M;
string str;

int main()
{
	cin >> Q >> H >> S >> D >> N;
	ull need1, need2;
	need1 = std::min(4 * Q, std::min(2 * H, S));
	need2 = std::min(2 * need1, D);
	cout << need2*(N / 2) + (N & 1)*need1 << '\n';
	return 0;
}


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

int dp[1005][10005];
const int INF = 1001001001;

int main() {
    int h, n;
    cin >> h >> n;
    rep(i,1005)rep(j,10005) dp[i][j] = INF;
    dp[0][0] = 0;
    //rep(i,n) dp[i][0] = 0;
    rep(i,n) {
        int a, b;
        cin >> a >> b;
        rep(j,h+1) {    
            chmin(dp[i+1][j], dp[i][j]);
            chmin(dp[i+1][j], dp[i+1][max(j-a,0)]+b);
        }
    }
    cout << dp[n][h] << endl;
    return 0;
}

Measured memory_bytes: 42920
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

int N;
vector<vint> G;
ll dp[112345];

void dfs(int v,int par){
  int cnt=0;
  for(int chi:G[v])if(chi!=par){
    dfs(chi,v);
    cnt++;
    dp[v] += dp[chi];
    cnt -= dp[chi]>0;
  }
  dp[v] += max(0,cnt-1);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>N;
  G.resize(N);
  repeat(i,N-1){
    int a,b;cin>>a>>b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int root=-1;
  repeat(i,N){
    if(G[i].size()>=3){
      root = i;
      break;
    }
  }
  if(root<0){
    cout << 1 << endl;
    return 0;
  }
  dfs(root,-1);
  cout << dp[root] << endl;
  return 0;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}
struct Edge{
    int to;
      long long cost;
};

struct NODE{
  int pos;
  long long cost;
};
bool operator < (const NODE &a,const NODE &b){
  return a.cost > b.cost;
}
vector<Edge> g[100000],rg[100000];

int N;
const ll INF = 1e15;
vector<ll> dijkstra(vector<Edge> g[100000],int s){
  priority_queue<NODE> Q;
  Q.push({s,0});
  vector<ll> res(N+1,INF);
  while(Q.size()){
    NODE q= Q.top();Q.pop();
    if(res[q.pos] == INF){
      res[q.pos] = q.cost;
    }
    else{
      continue;
    }
    for(auto n : g[q.pos]){
      Q.push({n.to,q.cost+n.cost});
    }
  }
  return res;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,r,k,t,p;
  int s,d,v;
  cin >> n;
  N = n;
  REP(i,1,n+1){
    cin >> r >> k;
    rep(j,k){
      cin >> t;
      g[r].push_back(Edge{t,1});
    }
  }
  cin >> p;
  rep(i,p){
    cin >> s >> d >> v;
    auto rt = dijkstra(g,s);
//     debug(rt[d]);
    if(rt[d] >= v){
      cout << "NA"<<endl;
    }
    else{
      cout << rt[d]+1<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 7772
S = input()
m = 10**9+7
d = "ABC".index

dp = [0]*4
dp[0] = 1

for c in S:
	if(c == '?'):
		dp = [(3*dp[0])%m, (3*dp[1]+dp[0])%m, (3*dp[2]+dp[1])%m, (3*dp[3]+dp[2])%m]
	else:
		i = d(c)
		dp[i+1] += dp[i]%m 
print(dp[3]%m)

Measured memory_bytes: 3188
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion


void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    ll X;
    cin >> X;
    if(X==2){
        cout << 2 << el;return;
    }
    for(int i=X+1-(X%2); ;i+=2){
        bool flg = true;
        for(int j=3, j_len=sqrt(i); j<=j_len; j+=2){
            if(i%j==0){
                flg = false;
                break;
            }
        }
        if(flg){
            cout << i << el;
            return;
        }
    }
}



Measured memory_bytes: 256
n,m = map(int,input().split())
a = [list(map(int,input().split())) for i in range(m)]
target = list(map(int,input().split()))

#n,m = 2,3
#a = [[2,1,2], [1,1],[1,2]]
#target = [0,0,1]

ans = 0
s = [0] * n
for i in range(2**n):
  x = format(i,'b').zfill(n)

  for num,j in enumerate(x):
    s[num] = int(j)

  ck = 1
  for num,alist in enumerate(a):
    count = 0
    for j in range(1,alist[0]+1):
      count += s[alist[j]-1]
    if(count%2 != target[num]):
      ck = 0
  ans += ck

print(ans)

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

int main(){

    while(1){
        string g; int y,m,d;

        cin>>g;

        if( g == "#") break;

        cin>>y>>m>>d;



        if(y == 31 && m >= 5){

            cout<<'?'<<" "<<y-30<<" "<<m<<" "<<d<<endl;
        }

        else if( y > 31){

            cout<<'?'<<" "<<y-30<<" "<<m<< " "<<d<<endl;
        }

        else cout<<g<<" "<<y<<" "<<m<<" "<<d<<endl;


    }

    return 0;
}


Measured memory_bytes: 3172
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int a;
    cin >> a;
    if(a < 1200){
        cout << "ABC";
    }
    else if(a < 2800){
        cout << "ARC";
    }
    else
    {
        cout << "AGC";
    }
    cout << endl;
}


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

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()

    N = int(next(tokens))  # type: str
    K = int(next(tokens))  # type: str
    # print(N, K)
    g = set()
    for _ in range(K):
        d = int(next(tokens))
        g = g | set([int(next(tokens)) for i in range(d)])

    print(N - len(g))    

    return


if __name__ == '__main__':
    main()


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

using namespace std;

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

    int n;
    cin >> n;

    vector<tuple<string, int, int>> s(n);
    for (int i = 0; i < n; ++i) {
        cin >> get<0>(s[i]) >> get<1>(s[i]);
        get<1>(s[i]) *= -1;
        get<2>(s[i]) = i + 1;
    }
    sort(s.begin(), s.end());

    for (int i = 0; i < n; ++i)
        cout << get<2>(s[i]) << '\n';

    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
//#pragma GCC optimize("unroll-loops")

#ifdef __APPLE__
    # include <iostream>
    # include <cmath>
    # include <algorithm>
    # include <stdio.h>
    # include <cstdint>
    # include <cstring>
    # include <string>
    # include <cstdlib>
    # include <vector>
    # include <bitset>
    # include <map>
    # include <queue>
    # include <ctime>
    # include <stack>
    # include <set>
    # include <list>
    # include <random>
    # include <deque>
    # include <functional>
    # include <iomanip>
    # include <sstream>
    # include <fstream>
    # include <complex>
    # include <numeric>
    # include <immintrin.h>
    # include <cassert>
    # include <array>
    # include <tuple>
    # include <unordered_map>
    # include <unordered_set>
    # include <thread>
#else
    # include <bits/stdc++.h>
#endif

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define files(name) name!=""?freopen(name".in","r",stdin),freopen(name".out","w",stdout):0
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define elif else if
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;
#define int long long

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

const int arr=2e5+10;
const int ar=2e3+10;
const ld pi=acos(-1);
const ld eps=1e-10;
const ll md=1e9+7;
const ll inf=1e18+10;

///---program start---///

signed main()
{
    #ifdef __APPLE__
        files("barik");
        freopen("debug.txt","w",stderr);
    #endif

    int n;
    cin>>n;
    vi a(n);
    map<int,int> cnt;
    for (auto& i:a){
        cin>>i;
        cnt[i]++;
    }
    int MAX=*max_element(all(a));
    for (int i=0;i<=MAX;i++){
        if (cnt[max(i,MAX-i)]==0){
            cout<<"Impossible"<<"\n";
            return 0;
        }
        cnt[max(i,MAX-i)]--;
    }
    a.clear();
    for (auto i:cnt){
        for (int j=0;j<i.sec;j++){
            a.pb(i.fir);
        }
    }
    if (!a.empty()&&*min_element(all(a))<(MAX+1)/2+1){
        cout<<"Impossible"<<"\n";
        return 0;
    }
    cout<<"Possible"<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
string s;
LL ans,len;
LL count(LL a,LL i)
{
	LL s=0;
	LL cnt=i;
	i=pow(2,i);
	s+=i;
	for(int j=1;j<=len-cnt-1;j++)
	{
		s=s*10+i;
		i*=2;
	}
	return a*s;
}
int main()
{
	cin>>s;
	len=s.length();
	for(LL i=0;i<s.length();i++)
	{
		ans+=count(s[i]-'0',i);
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 512
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

from collections import deque

N = int(input())
S = [input() for _ in range(N)]

def bfs(start):
    res = 0
    dist = [-1] * N
    dist[start] = 1
    q = deque()
    q.append([start, 1])
    st = set()
    st.add((start, 1))

    while q:
        i, d = q.popleft()
        if dist[i] == -1:
            dist[i] = d
            res = max(res, d)
        elif dist[i] != d:
            res = -1
            break
        for j in range(N):
            if S[i][j] == '1' and dist[j] != d-1:
                if (j, d+1) not in st:
                    q.append([j, d+1])
                    st.add((j, d+1))
    return res

ans = -1
for i in range(N):
    k = bfs(i)
    if k == -1:
        break
    else:
        ans = max(ans, k)

print(ans)

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

using namespace std;

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

int can[21][21];
const int MOD = 1000000007;
int dp[21][1<<21];
bool seen[21][1<<21];
int n;

int solve(int r, int m) {
  if(r < 0) return 1;
  if(seen[r][m]) return dp[r][m];
  seen[r][m] = true;
  for(int j = 0; j < n; j++) {
    if(can[r][j] && m&(1<<j)) {
      dp[r][m] += solve(r-1, m ^ (1 << j));
      if(dp[r][m] >= MOD) dp[r][m] -= MOD;
    }
  }
  return dp[r][m];
}

void solve() {
  cin >> n;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      cin >> can[i][j];
    }
  }
  cout << solve(n-1, (1<<n)-1) << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
}


Measured memory_bytes: 203008
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#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 ALL(a) (a).begin(), (a).end()

vector<int> G[100000];
int parent[100000];
int in[100000];

int main() {
    int N, M, A, B;
    cin >> N >> M;
    REP(i, N + M - 1) {
        cin >> A >> B;
        in[B - 1]++;
        G[A - 1].push_back(B - 1);
    }
    int root = -1;
    REP(i, N) if (in[i] == 0) root = i;
    REP(i, N) parent[i] = -1;

    queue<int> q;
    q.push(root);
    while (!q.empty()) {
        vector<int> vi;
        while (!q.empty()) {
            vi.push_back(q.front());
            q.pop();
        }
        for (int v : vi) {
            for (int n : G[v]) {
                if (--in[n] == 0) {
                    parent[n] = v;
                    q.push(n);
                }
            }
        }
    }

    REP(i, N) cout << parent[i] + 1 << endl;
    return 0;
}

Measured memory_bytes: 7040
def read_input():
    n, x = map(int, input().split())
    mlist = []

    for i in range(n):
        mlist.append(int(input()))

    return n, x, mlist

def submit():
    n, x, mlist = read_input()

    base = n
    rest = x - sum(mlist)

    min_d = min(mlist)
    print(base + rest//min_d)


if __name__ == '__main__':
    submit()


Measured memory_bytes: 3060
#include <iostream>
#include <cstring>

using namespace std;


const int MAX_TIME = 10;
int W, H;
int map[21][21];

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

int solver(int cx, int cy, int time) {
	if (time > MAX_TIME) return MAX_TIME + 1;
	
	int ret = MAX_TIME + 1;
	for (int d=0; d<4; d++) {
		if (map[cy + dy[d]][cx + dx[d]] == 1) continue;
		
		bool stop = true;
		int stopx = cx, stopy = cy;
		
		while (1) {
			if (map[stopy + dy[d]][stopx + dx[d]] == 1) break;
			
			stopy += dy[d]; stopx += dx[d];
			
			if (stopy < 0 || stopy >= H || stopx < 0 || stopx >= W) {
				stop = false;
				break;
			}
			if (map[stopy][stopx] == 3) {
				stop = false;
				if (time < MAX_TIME) ret = min(ret, time + 1);
				break;
			}
		}
		
		if (stop) {
			map[stopy+dy[d]][stopx+dx[d]] = 0;
			ret = min(ret, solver(stopx, stopy, time + 1));
			map[stopy+dy[d]][stopx+dx[d]] = 1;
		}
	}
	return ret;
}

int main() {
	while (1) {
		cin >> W >> H; if (W==0 && H==0) break;
		
		memset(map, 0, sizeof(map));
		
		int sx, sy;
		for (int y = 0; y < H; y++) {
			for (int x = 0; x < W; x++) {
				cin >> map[y][x];
				if (map[y][x] == 2) {
					sx = x; sy = y;
				}
			}
		}
		
		int ans = solver(sx, sy, 0);
		if (ans == MAX_TIME + 1) cout << -1 << endl;
		else cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int n;
  cin>>n;
  int a[n];
  rep(i, n) cin>>a[i];
  ll positive = 0;
  ll negative = 0;
  ll sum = 0;
  rep(i,n) {
    sum += a[i];
    if(i % 2 == 0 && sum <= 0) {
      positive += 1 - sum;
      sum = 1;
    } else if (i % 2 == 1 && sum >= 0) {
      positive += sum + 1;
      sum = -1;
    }
  }
  sum = 0;
  rep(i,n) {
    sum += a[i];
    if(i % 2 == 1 && sum <= 0) {
      negative += 1 - sum;
      sum = 1;
    } else if (i % 2 == 0 && sum >= 0) {
      negative += sum + 1;
      sum = -1;
    }
  }
  cout << min(positive, negative) << endl;


  return 0;
}


Measured memory_bytes: 768
#include <stdio.h>

int main() {
    int N;
    scanf("%d", &N);
    int even[100001] = {0};
    int odd[100001] = {0};
    int v, i;
    for (i = 0; i<N>> 1; i++) {
        scanf("%d", &v);
        even[v]++;
        scanf("%d", &v);
        odd[v]++;
    }
    int even_max[2][2] = {{0,0},{0,0}};
    int odd_max[2][2] = {{0,0},{0,0}};
    for (i = 0; i < 100001; i++) {
        if (even[i] > even_max[0][1]) {
            even_max[1][0] = even_max[0][0];
            even_max[1][1] = even_max[0][1];
            even_max[0][0] = i;
            even_max[0][1] = even[i];
        } else if (even[i] > even_max[1][1]) {
            even_max[1][0] = i;
            even_max[1][1] = even[i];
        }
        if (odd[i] > odd_max[0][1]) {
            odd_max[1][0] = odd_max[0][0];
            odd_max[1][1] = odd_max[0][1];
            odd_max[0][0] = i;
            odd_max[0][1] = odd[i];
        } else if (odd[i] > odd_max[1][1]) {
            odd_max[1][0] = i;
            odd_max[1][1] = odd[i];
        }
    }
    // printf("%d: %d, %d: %d\n", even_max[0][0], even_max[0][1], even_max[1][0], even_max[1][1]);
    // printf("%d: %d, %d: %d\n", odd_max[0][0], odd_max[0][1], odd_max[1][0], odd_max[1][1]);

    /*
    for (i=0; i < N; i++) {
        printf("%d: %d, ", i, even[i]);
        printf("%d: %d, ", i, odd[i]);
    }
    puts("");
    */
    if (even_max[0][0] == odd_max[0][0]) {
        printf("%d\n", N - (even_max[0][1] + ((even_max[1][1] > odd_max[1][1]) ? even_max[1][1] : odd_max[1][1])));
    } else {
        printf("%d\n", N - (even_max[0][1] + odd_max[0][1]));
    }
}


Measured memory_bytes: 896
#include <stdio.h>
#define MAX 25
#define NIL -1 /*use to show there no anything*/

typedef struct{
  int parent,left,right;
}Record;
int dep[MAX],heig[MAX];

void depth(int, int, Record*);
int  height(int, Record*);
int main(){
  int i,j,num,id,root,lef,rig,deg[MAX];
  Record data[MAX];
  scanf("%d",&num);
  for(i=0;i<num;i++) {
    data[i].parent=NIL;
    deg[i]=0;
  }
  
  for(i=0;i<num;i++){
    scanf("%d%d%d",&id,&lef,&rig);
    data[id].left=lef;
    data[id].right=rig;
      
    if(lef!=NIL) {
      data[lef].parent=id;
      deg[id]++;
    }
    if(rig!=NIL){
      data[rig].parent=id;
      deg[id]++;
    }
  }
  for(i=0;i<num;i++){
    if(data[i].parent==NIL){
      root=i;
      break;
    }
  }
  depth(root,0,data);
  height(root,data);
  for(i=0;i<num;i++){
    printf("node %d: parent = %d, ",i,data[i].parent);
    printf("sibling = ");
    if(data[i].parent==NIL)printf("%d, ",NIL);
    else if(data[data[i].parent].left!=NIL && data[data[i].parent].left!=i){
      printf("%d, ",data[data[i].parent].left);
    }
    else if(data[data[i].parent].right!=NIL && data[data[i].parent].right!=i){
      printf("%d, ",data[data[i].parent].right);
    }
    else printf("%d, ",NIL);
    printf("degree = %d, ",deg[i]);
   
    printf("depth = %d, ",dep[i]);
    printf("height = %d, ",heig[i]);
    if(i==root) printf("root");
    else if(data[i].left==NIL && data[i].right==NIL) printf("leaf");
    else printf("internal node");
   
    printf("\n");
  }
  return 0;
}	

void depth(int x, int y, Record *data){
  if(x==NIL) return;
  dep[x]=y;
  depth(data[x].left,y+1,data);
  depth(data[x].right,y+1,data);
 
}

int height(int x, Record *data){
  int height1=0,height2=0;
  if(data[x].left!=NIL) height1=height(data[x].left,data)+1;
  if(data[x].right!=NIL) height2=height(data[x].right,data)+1;
  if(height1>height2) heig[x]=height1;
  else heig[x]=height2;
  return heig[x];
}



Measured memory_bytes: 2148
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    let n: usize = read!();
    let t: isize = read!();
    let mut ans:isize=100000;
    for _i in 0..n {
        let a:isize = read!();
        let b:isize = read!();
        if b<=t&&a<ans{ans=a;}
    }
    if ans==100000 {println!("TLE")}
    else {println!("{}",ans);}
}

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

int main(){
  int N;
  cin>>N;
  vector<pair<int,int>> vec(N);
  for (int i=0;i<N;i++){
    cin >> vec[i].first>>vec[i].second;
  }
  sort(vec.begin(),vec.end());
  cout<<vec[N-1].first+vec[N-1].second<<endl;
  return 0;
}

  

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    ld w, h, x, y; cin >> w >> h >> x >> y;

    ld s = w * h / 2.0;
    if(x * 2 != w || y * 2 != h){
        cout << fixed << setprecision(6) << s;
        cout << " " << 0 << endl;
    }else{
        cout << fixed << setprecision(6) << s;
        cout << " " << 1 << endl;
    }


    return 0;
}


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

int main()
{
    string s;
    cin >> s;
    set<char> s_set;
    ll n = s.size();
    rep(i, n){
        s_set.insert(s[i]);
    }
    ll ans = LLONG_MAX;
    for(auto x: s_set){
        string s_(s);
        ll cnt = 0;
        while (true)
        {
            ll s_n = s_.size();
            bool flg = true;
            rep(i, s_n){
                if (s_[i] != x){
                    flg = false;
                }
            }
            if (flg){
                ans = min(ans, cnt);
                break;
            }

            cnt++;
            rep(i, s_n-1){
                if (s_[i] != x && s_[i+1] == x){
                    s_[i] = x;
                }
            }
            s_.pop_back();
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Main {
	static void add(Map<Integer, Integer> map, int v){
		if(!map.containsKey(v)){
			map.put(v, 1);
		}else{
			int c = map.get(v);
			map.put(v, c + 1);
		}
	}
	static int max(Map<Integer , Integer> map){
		int m = 0;
		for(int v : map.values()){
			m = Math.max(m, v);
		}
		return m;
	}
	static int maxNum(Map<Integer , Integer> map, int max){
		int m = 0;
		for(int v : map.values()){
			if(v == max){
				++m;
			}
		}
		return m;
	}
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		String arr[] = line.split(" ");
//		int H = Integer.parseInt(arr[0]);
//		int W = Integer.parseInt(arr[1]);
		int M = Integer.parseInt(arr[2]);
		int xs[] = new int[M];
		int ys[] = new int[M];
		Map<Integer, Integer> rcount = new HashMap<Integer, Integer>();
		Map<Integer, Integer> ccount = new HashMap<Integer, Integer>();
		for(int i = 0 ; i < M ; ++i){
			line = br.readLine();
			arr = line.split(" ");
			int h = Integer.parseInt(arr[0]) - 1;
			int w = Integer.parseInt(arr[1]) - 1;
			add(rcount , h);
			add(ccount , w);
			xs[i] = w;
			ys[i] = h;
		}
		int mr = max(rcount);
		int mc = max(ccount);
		int mr_num = maxNum(rcount, mr);
		int mc_num = maxNum(ccount, mc);
		long cnt = 0;
		for(int i = 0 ; i < M ; ++i){
			int h = ys[i];
			int w = xs[i];
			if(mr == rcount.get(h) && mc == ccount.get(w)){
				++cnt;
			}
		}
		long cross = (long)mr_num * (long) mc_num;
		if(cross > cnt){
			System.out.println(mr+mc);
		}else{
			System.out.println(mr+mc - 1);			
		}
	}
}


Measured memory_bytes: 94724
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol a,b,c,d;
int i[100000];
bool ca[110000];
bool ac[110000];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s,w;
  cin >>a>>b;
  lol ans=0,pe=0;
  for(int n=0;n<b;n++){
    cin >>c>>s;
    if(s=="AC"){
      if(!ac[c]) ans++;
      ac[c]=true;
    }
    else{
      if(!ac[c]) i[c]++;
    }
  }
  for(int n=1;n<=a;n++){
    if(ac[n]) pe+=i[n];
  }
  cout <<ans<<' '<<pe<<'\n';
  return (0);
}


Measured memory_bytes: 768
#include <stdio.h>
#define N 100000
int binarySearch();
int S[N], n, key;
int main(){
  int i, q, C=0;
  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d", &S[i]);
  }
  scanf("%d", &q);
  for(i=0; i<q; i++){
    scanf("%d", &key);
    if( binarySearch(key) == 1 ){
      C++;
    }
  }
  printf("%d\n", C);
  return 0;
}

int binarySearch(){
  int left=0;
  int right=n;
  int mid;
  while(left < right){
    mid = (left + right) / 2;
    if(S[mid] == key){
      return 1;
    }
    else if(S[mid] > key){
      right = mid;
    }
    else
      left = mid + 1;
  }
  return 0;
}
    





Measured memory_bytes: 2120
n,*t=`dd`.split.map &:to_i
z=[j=s=m=0]*1e5
t.map!{|e|e*2}.pop(n).map{|v|z[j]=[z[j],v].min;(j+1..j+=t.shift).map{|k|z[k]=[z[k-1]+1,v].min}}
j.times{|i|s+=m=[m+1,z[j+~i]].min}
p s/4.0

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD =   1000000007;

/// Lib
vector<long long> calc_divisor(long long n) {
    vector<long long> res;
    for (long long i = 1LL; i*i <= n; ++i) {
        if (n % i == 0) {
            res.push_back(i);
            long long j = n / i;
            if (j != i) res.push_back(j);
        }
    }
    sort(res.begin(), res.end());
    return res;
}
///
bool check(ll key, const vector<ll>& vec, ll maxtry){
    vector<ll> distance(vec.size());
    for(ll i = 0; i < vec.size(); ++i){
        distance[i] = vec[i] % key;
    }
    sort(distance.begin(), distance.end());

    ll cost = 0;
    ll last = vec.size()-1;
    for(ll i = 0; i < vec.size(); ++i){
        if(distance[i] == 0) continue;
        cost += distance[i];
        distance[last] += distance[i];

        bool flag = true;
        while(flag){
            if(distance[last] >= key){
                ll res = distance[last] - key;
                distance[last] = 0;
                --last;
                distance[last] += res;
            }
            else{
                flag = false;
            }
        }
    }

    if(cost <= maxtry){
        return true;
    }
    return false;
}

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    ll n, k; cin >> n >> k;
    vector<ll> a(n);
    for(ll i = 0; i < n; ++i){
        cin >> a[i];
    }
    ll sum = 0;
    for(ll i = 0; i < n; ++i){
        sum += a[i];
    }
    vector<ll> div = calc_divisor(sum);
    ll ans = 0;
    for(auto it : div){
        if(check(it, a, k)){
            ans = max(ans, it);
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(int argc, char const *argv[])
{
    int r, c;
    cin >> r >> c;
    int table[101][101]{};
    rep(i, r){
        rep(j, c){
            int x;
            cin >> x;
            table[i][j] = x;
        }
    }

    rep(i, r){
        rep(j, c) {
            table[i][c] += table[i][j];
        }
    }
    
    rep(i, c+1) {
        rep(j, r) {
            table[r][i] += table[j][i];
        }
    }

    rep(i, r+1) {
        rep(j, c+1) {
            cout << table[i][j];
            if(j != c) cout << ' ';
        }
        cout << endl;
    }
    
    return 0;
}



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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int dp[3002][3002];
int before[3002][3002];
int direc_i[3] = {-1, 0, -1};
int direc_j[3] = {0, -1, -1};
int main() {
    //cout.precision(10);
    string s, t;
    cin >> s >> t;
    s = "#" + s;
    t = "#" + t;
    for(int i = 1; i < s.size(); i++){
        for(int j = 1; j < t.size(); j++){
            before[i][j] = 0;
            dp[i][j] = dp[i - 1][j];
            if(dp[i][j - 1] > dp[i][j]){
                before[i][j] = 1;
                dp[i][j] = dp[i][j - 1];
            }
            if(s[i] != t[j]) continue;
            if(dp[i - 1][j - 1] + 1 > dp[i][j]){
                before[i][j] = 2;
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
        }
    }
    string ans = "";
    int i = s.size() - 1;
    int j = t.size() - 1;
    while(i > 0 && j > 0){
        int k = before[i][j];
        if(k != 2){
            i += direc_i[k];
            j += direc_j[k];
            continue;
        }
        ans = s[i] + ans;
        i--;
        j--;
    }
    cout << ans << endl;
    /*
    for(int i = 1; i < s.size(); i++){
        for(int j = 1; j < t.size(); j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    cout << dp[s.size() - 1][t.size() - 1] << endl;
    */
    return 0;
}


Measured memory_bytes: 70656
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
cost_0, cost_n = 0, 0

# if max(a) <= x or min(a) >= x:
#     print(0)
#     exit(1)

for i in range(1, x):
    if i in a:
        cost_0 += 1

for i in range(x + 1, n):
    if i in a:
        cost_n += 1

print(min(cost_0, cost_n))

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

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define rep(i,a) for(i = 0 ; i < a ; i++)
#define repr(i,a) for(i = a ; i >= 0 ; i--)
#define REP(i,a,b) for(i = a ; i <= b ; i++)
#define REPR(i,a,b) for(i = a ; i >= b ; i--)

#define scan(N) scanf("%lld",&N)
#define print(N) printf("%lld",N)
#define scan2(N1,N2) scanf("%lld %lld",&N1,&N2)
#define print2(N1,N2) printf("%lld %lld",N1,N2)
#define scan3(N1,N2,N3) scanf("%lld %lld %lld",&N1,&N2,&N3)
#define print3(N1,N2,N3) printf("%lld %lld %lld",N1,N2,N3)

#define mem(a,b)memset(a,b,sizeof(a))
#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*((b)/gcd(a,b)))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl

#define endl '\n'

const long long INF = 2000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

template<class T> bool is_prime(T n)
{
	if((n%2 == 0 and n > 2) or n < 2 )
		return false;
	for(T i = 3; i*i <= n ; i += 2)
	{
		if( n % i == 0)
			return false;
	}
	return true;
}
lli power(lli a,lli b)
{
    lli value;
    if(!b)
    	return 1;
    else if(b%2==0)
    {
        value = power(a,b/2)%MOD;
        return (value * value)%MOD;
    }
    else
    {
        value = power(a,b/2)%MOD;
        return ((a*value)%MOD*(value))%MOD;
    }
}

int main()
{
	opt;
    lli c,x,a,b;
    cin >> a >> b >> c >> x;
    lli i,j,k,ans = 0;
    REP(i,0,a)
    {
        REP(j,0,b)
        {
            k = (x - (500*i) - (100*j)) / 50;
            if( k <= c and k >= 0)
                ans++;
        }
    }
    cout << ans ;
	return 0;
}










Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count = sc.nextInt();
		sc.nextLine();
		int[] array = new int[count];
		
		for (int i = 0; i < count; i++) {
			array[i] = sc.nextInt();
		}
		sc.close();
		
		Arrays.sort(array);
		
		System.out.println(array[count - 1] - array[0]);
	}
}

Measured memory_bytes: 22228