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

int main(){
  int n;
  cin >> n;
  vector<P> dot(n);
  for(int i=0; i<n; ++i){
    int x, y;
    cin >> x >> y;
    dot[i] = make_pair(x,y);
  }
  sort(dot.begin(),dot.end());
  int ans = n;
  for(int i=0; i<n; ++i){
    for(int j=i+1; j<n; ++j){
      int nans = n-1;
      int p = dot[j].first -dot[i].first;
      int q = dot[j].second -dot[i].second;
      for(int k=i+1; k<n; ++k) for(int l=k+1; l<n; ++l){
        if(dot[k].first + p == dot[l].first &&
           dot[k].second + q == dot[l].second){
          --nans;
        }
      }
      ans = min(nans, ans);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>
struct tree{
  int key;
  struct tree *parent;
  struct tree *left;
  struct tree *right;
};
struct tree *T,*NIL;
void insert(struct tree *);
int find(int);
void inorder(struct tree *);
void preorder(struct tree *);
int main(){
  int n,k,i;
  char command[10],a;
  struct tree *A;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s%c",command,&a);
    if(!strcmp(command,"insert")){
      scanf("%d",&k);
      A=malloc(sizeof(struct tree));
      A->key=k;
      A->left=NIL;
      A->right=NIL;
      insert(A);
    }
    else if(!strcmp(command,"print")){
      inorder(T);
      printf("\n");
      preorder(T);
      printf("\n");
    }
    else{
      scanf("%d",&k);
      if(find(k)==0)printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}
    void insert(struct tree *z){
  struct tree *x,*y;
  x=T;
  y=NIL;
  while(x!=NIL){
    y=x;
    if(x->key>z->key) x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL){
    T=z;
  }
  else {
    if(y->key<z->key)y->right=z;
    else y->left=z;
  }
}
void inorder(struct tree *A){
  if(A==NIL)return;
  inorder(A->left);
  printf(" %d",A->key);
  inorder(A->right);
}
void preorder(struct tree *A){
  if(A==NIL)return;
  printf(" %d",A->key);
  preorder(A->left);
  preorder(A->right);
}
int find(int k){
  struct tree *x=T;
  while(x!=NIL){
    if(x->key==k)return 0;
    else if(k<x->key)x=x->left;
    else x=x->right;
  }
  return 1;
}



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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

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

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	for(int n;cin>>n&&n;){
		vi a(n);
		rep(i,n) cin>>a[i];
		vi b(n);
		repi(i,1,n) b[i]=max(b[i-1],i-(a[i-1]+1)/2);
		int res=1;
		for(int i=0,j=0;i<n;i++){
			for(;j<n&&b[j]<=i;j++);
			res=res*ll(j-i)%MOD;
		}
		cout<<res<<endl;
	}
}


Measured memory_bytes: 1024
<?php
class AverageLength {
    var $N, $x, $y;
    
    function __construct() {
        fscanf(STDIN, "%d", $this->N);
        for ($i = 0; $i < $this->N; $i++) {
            fscanf(STDIN, "%d %d", $this->x[$i], $this->y[$i]);
        }
    }
    
    function __invoke() {
        $dist = 0;
        for ($i = 0; $i < $this->N - 1; $i++) {
            for ($j = $i + 1; $j < $this->N; $j++) {
                $dist += sqrt(pow($this->x[$i] - $this->x[$j], 2) + pow($this->y[$i] - $this->y[$j], 2));
            }
        }        
        $paths = $this->fact($this->N);
        $path_count = $paths * ($this->N - 1);
        $p = $this->N * ($this->N - 1) / 2;
        $ans = $path_count / $p * $dist / $paths;
        return $ans;
    }
    
    function fact($N) {
        $ret = 1;
        for ($i = 2; $i <= $this->N; $i++) {
            $ret *= $i;
        }
        return $ret;
    }
}

$obj = new AverageLength();
echo $obj();


Measured memory_bytes: 4728
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;


public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int sum = n / 2 + n % 2;
        System.out.println(sum);
    }
}




class Scanner
{
    StringTokenizer st;
    BufferedReader br;

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

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

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

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

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

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

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


}

Measured memory_bytes: 25152
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define pb push_back
#define mp make_pair
 #define mod 1000000007
 const int N=100005;
 const int inf=1e18;
int pow(int a,int b){
    int res=1;
    while(b>0){
        if(b&1){
        	res=res*a;
		}
        a=a*a;
        b>>=1;
    }
    return res;
}
bool compare(const pair<int,int> &p1,const pair<int,int> &p2){
   
    if(p1.first==p2.first){
        return p1.second<p2.second;
    }
     return p1.first>p2.first;
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int n,m1;
    cin>>n>>m1;
    pair<int,int>p[n];
    set<int>m;
    // map<int,int>::iterator itr;
    for(int x=0;x<n;x++){
        cin>>p[x].second>>p[x].first;
    }
    for(int x=1;x<=m1;x++){
        // m[x]=1;
        m.insert(x);
    }
    sort(p,p+n,compare);
    int used[m1+1]={0};
    used[0]=1;
    int ans=0;
	for(int x=0;x<n;x++){
      //  cout<<p[x].first<<" "<<p[x].second<<"\n";
        if(p[x].second<=m1){
            auto itr=m.lower_bound(p[x].second);
            if(itr==m.end())
            	continue;
            if(used[*itr]==0){
                ans+=p[x].first;
                used[*itr]=1;
                m.erase(itr);
            }
            
            if(m.size()==0){
                cout<<ans;
                return 0;
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 7424
import queue


def check_dream(s):
    return s.startswith('dream')


def check_dreamer(s):
    return s.startswith('dreamer')


def check_erase(s):
    return s.startswith('erase')


def check_eraser(s):
    return s.startswith('eraser')


def check_sentence(s, q):
    if check_dream(s):
        q.put(s[5:])

    if check_dreamer(s):
        q.put(s[7:])

    if check_erase(s):
        q.put(s[5:])

    if check_eraser(s):
        q.put(s[6:])

    return q


def search():
    sentence_q = queue.Queue()
    initial_s = input()

    s = initial_s
    while(1):
        if s == '':
            return True

        sentence_q = check_sentence(s, sentence_q)
        if sentence_q.empty():
            return False

        s = sentence_q.get()


if search():
    print('YES')
else:
    print('NO')

Measured memory_bytes: 4528
#include <bits/stdc++.h>
#define LL long long
#define FOR(i,c) for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define F first
#define S second
using namespace std;

const LL mod = 1e9 + 7;

template<typename T> T gcd(T a, T b) { return b == 0?a: gcd(b, a % b); }
template<typename T> T LCM(T a, T b) { return a*(b/gcd(a, b)); }
template<typename T> T expo(T base, T e, T mod) { T res = 1;
  while(e > 0) { if(e&1) res = res * base % mod; base = base * base % mod; e >>= 1; }
  return res;
}
template<typename T, typename S> T expo(T b, S e){if(e <= 1)return e == 0?1: b;\
	return (e&1) == 0?expo((b*b), e>>1): (b*expo((b*b), e>>1));}
template<typename T, typename S> T modinv(T a, S mod) { return expo(a, mod-2, mod); }
template<class T, class S> std::ostream& operator<<(std::ostream &os, const std::pair<T, S> &t) {
	os<<"("<<t.first<<", "<<t.second<<")";
	return os;
}
template<class T> std::ostream& operator<<(std::ostream &os, const std::vector<T> &t) {
	os<<"["; FOR(it,t) { if(it != t.begin()) os<<", "; os<<*it; } os<<"]";
	return os;
}
#define gc getchar_unlocked
template <typename T> void in(T &x) {
	T c = gc(); while(((c < 48) || (c > 57)) && (c!='-')) c = gc();
	bool neg = false; if(c == '-') neg = true; x = 0; for(;c < 48 || c > 57;c=gc());
	for(;c > 47 && c < 58;c=gc())	x = (x*10) + (c - 48); if(neg)	x = -x;
}

const int MAXN = 2e5 + 100;

int n, arr[MAXN], m;
int cnt[MAXN];
int occ[MAXN];
int num_occ;

void add(int val) {
	int pos = val - cnt[val];
	if(pos > 0) {
		if(occ[pos] == 0) num_occ++;
		occ[pos]++;
	}
	cnt[val]++;
}
void rem(int val) {
	int pos = val - cnt[val] + 1;
	if(pos > 0) {
		if(occ[pos] == 1) num_occ--;
		occ[pos]--;
	}
	cnt[val]--;
}

int main() {
	in(n), in(m);
	for(int i = 1; i <= n; i++) {
		in(arr[i]);
		add(arr[i]);
	}
	int a, b;
	while(m--) {
		in(a), in(b);
		rem(arr[a]);
		arr[a] = b;
		add(arr[a]);
		printf("%d\n", n - num_occ);
	}
  return 0;
}


Measured memory_bytes: 3712
#include <cstdio>
 
typedef long long LL;
const int MN = 100005;
 
int N, A[MN];
LL S;
 
int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) scanf("%d", &A[i]), S += A[i];
	if (S % ((LL)N * (N + 1) / 2) != 0) return puts("NO"), 0;
	LL C = S / ((LL)N * (N + 1) / 2);
	for (int i = 1; i <= N; ++i) {
		LL k = C - (A[i % N + 1] - A[i]);
		if (k < 0 || k % N != 0) return puts("NO"), 0;
	}
  
  
	puts("YES");
	return 0;
}

Measured memory_bytes: 2008
H, W, K = map(int, input().split())

c = [0] * H
for i in range(H):
    c[i] = input()

count = 0
for rows in range(1 << H):
    for cols in range(1 << W):
        black = 0
        for i in range(H):
            if (rows >> i) % 2 == 1:
                continue
            for j in range(W):
                if (cols >> j) % 2 == 1:
                    continue
                black += c[i][j] == '#'
        if black == K:
            count += 1
print(count)


Measured memory_bytes: 9156
#include <bits/stdc++.h>
using namespace std;
constexpr int64_t mod = 998244353;

int64_t fact[10000001], finv[10000001];
int64_t mpow(int64_t x, int64_t y){
    if(y==0) return 1;
    if(y==1) return x%mod;
    if(y%2==0) return mpow(x*x%mod, y/2);
    return mpow(x*x%mod, y/2)%mod * x % mod;
}
int64_t comb(int64_t n, int64_t r){
    if(r<0 || r>n) return 0;
    return fact[n]*finv[r]%mod*finv[n-r]%mod;
}
int main(){
    int n;
    cin >> n;
    fact[0] = 1;
    for(int i=1;i<=n;++i) fact[i] = fact[i-1] * i % mod;
    finv[n] = mpow(fact[n], mod-2);
    for(int i=n-1;i>=0;--i) finv[i] = finv[i+1] * (i+1) % mod;

    int64_t ans = mpow(3, n);
    for(int i=n/2+1;i<=n;++i) ans = ((ans+mod) - comb(n,i)*mpow(2,n-i+1)%mod) % mod;
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 156544
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int h,w,m; cin>>h>>w>>m;
    map<P,bool> map;
    vint tate(w,0),yoko(h,0);
    while(m--){
        int a,b; cin >> a >> b; a--; b--;
        tate[b]++; yoko[a]++;
        map[mp(a,b)]=true;
    }

    int m1=0,m2=0;
    m1=MAX(tate); m2=MAX(yoko);
    vint t,y;
    rep(i,w)if(tate[i]==m1)t.pb(i);
    rep(i,h)if(yoko[i]==m2)y.pb(i);

    rep(i,t.size()){
        rep(j,y.size()){
            if(map[mp(y[j],t[i])]==0){
                cout<<m1+m2<<endl;
                return 0;
            }
        }
    }
    cout<<m1+m2-1<<endl;
    // int m1=0,m2=0,i1=0,i2=0;
    // rep(i,w){
    //     if(tate[i]>m1){
    //         m1=tate[i];
    //         i1=i;
    //     }
    // }
    // rep(i,h){
    //     if(yoko[i]>m2){
    //         m2=yoko[i];
    //         i2=i;
    //     }
    // }
    // cout<<m1+m2-(map[mp(i1,i2)]?1:0)<<endl;

    
}

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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    COMinit();
    int N; cin >> N;
    int cnt[N+1] = {};
    int fst, snd;
    int A[N+1];
    rep(i, N+1){
        int a; cin >> a;
        cnt[a]++;
        A[i] = a;
        if(cnt[a] == 2){
            snd = i;
            rep(j, i) if(A[j] == A[i]) fst = j; 
        }
    }

    for(int k = 1; k <= N+1; k++){
        ll res = COM(N+1, k);
        //fstの左側と右側から合わせてk-1個取る
        ll choice = fst + (N - snd);
        res = (res - COM(choice, k-1)) % MOD;
        if(res < 0) res += MOD;
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 13952
import sys
import math

# -*- coding: utf-8 -*-


n = int(input())
a1 = input().split()
a2 = input().split()
amemax = 0
for i in range(n):
    ame = 0
    for j in range(n):
        if j < i:
            ame += int(a1[j])
        elif j > i:
            ame += int(a2[j])
        else:
            ame += int(a1[j]) + int(a2[j])
    if ame > amemax:
        amemax = ame

print(amemax)


Measured memory_bytes: 3060
import java.util.Scanner;
class Main {
	public static void main (String[] args) throws java.lang.Exception {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int H = sc.nextInt(), W = sc.nextInt();
			if(H == 0 && W == 0) break;
			for(int i = 0; i < H; i++) {
				for(int j = 0; j < W; j++) {
					System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}


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

using namespace std;

// typedef
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;

// container util
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

// repetition
#define FOR(i,m,n) for(ll (i) = ((ll) m); (i) < ((ll) n); ++(i))
#define RFOR(i,m,n) for(ll (i) = ((ll) (m)-1); (i) >= ((ll) n); --(i))
#define REP(i,n) FOR(i,0,n)

// i/o
#define TFOUT(b,t,f) cout << ((b)? (t) : (f)) << endl

//constant
const double    EPS     = 1e-10;
const double    PI      = acos(-1.0);
const int       INFTY   = (1<<21);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void){
    int n;
    cin >> n;
    vector<ll> a;
    vector<ll> b;
    ll b0 = 0;
    ll sgn = 1;
    REP(i, n) {
        ll e; cin >> e;
        b0 += sgn*e;
        a.push_back(e);
        sgn *= -1;
    }
    b.push_back(b0);
    FOR(i, 0, n-1) {
        ll e = (a[i] - b[i]/2)*2;
        b.push_back(e);
    }
    REP(i, n-1) cout << b[i] << ' ';
    cout << b[n-1] << endl;
    return 0;
}


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

int main(void){
  int n,ans = 1;
  cin >> n;
  char s[n];
  cin >> s[0];
  for(int i = 1;i < n;i++){
      cin >> s[i];
      if(s[i-1] != s[i]){
          ans += 1;
      }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define MAX 1005
#define INF 123456789
using namespace std;
struct edge{int to;int cost;};
typedef pair<int,int> P;
int V;
vector<edge> G[MAX];
int d[MAX];
void dkstr(int s){
  priority_queue<P,vector<P>,greater<P> >que;
  fill(d,d+V,INF);
  d[s]=0;
  que.push(P(0,s));
  while(!que.empty()){
    P p=que.top();que.pop();
    int v=p.second;
    if(d[v]<p.first)continue;
    for(int i=0;i<G[v].size();i++){
      edge e = G[v][i];
      if(d[e.to]>d[v]+e.cost){
	d[e.to]=d[v]+e.cost;
	//cout << d[e.to]<< endl;
	que.push(P(d[e.to],e.to));
      }
    }
  }
}
    
int main(){
  while(1){
    for(int i=0;i<MAX;i++){
      G[i].clear();
    }
    int s,g,m;
    int mp=0;
    cin >> V ;
    if(V==0)break;
    cin >> s >> g >> m;
    s--;
    g--;
    vector<P> ed(m);
    for(int i=0;i<m;i++){
      int b,e;
      cin >> b >> e;
      b--;
      e--;
      ed[i].first=b;
      ed[i].second=e;
      
      edge bu;
      bu.to=e;
      bu.cost=1;
      G[b].push_back(bu);
    }

    dkstr(s);
    int ma=d[g];
    //cout << ma << endl;
    int od[MAX];
    for(int i=0;i<MAX;i++){
      od[i]=d[i];
    }

    for(int i=0;i<m;i++){
      if(od[ed[i].second]<od[ed[i].first]){
	G[ed[i].second].push_back({ed[i].first,1});
	dkstr(s);
	int maa=ma;
	ma=min(ma,d[g]);
	if(maa!=ma){
	  mp=i+1;
	}
	G[ed[i].second].pop_back();
      }
    }
    cout << ma << " " << mp << endl;
  }
  return 0;
}

Measured memory_bytes: 3348
/*
	有奇数个偶数,先手赢
	有偶数个偶数,先手也不一定会输
*/
#include <iostream>
#include <cstdio>
#define N 100005

using namespace std;

int n;
int a[N];

inline int gcd(int u, int v) { return v ? gcd(v, u % v) : u; }

inline void read(int &x) {
	x = 0; char ch = getchar();
	while(!isdigit(ch)) ch = getchar();
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
}

bool solve() {
	int cntEven = 0;
	bool flagOne = false;
	for(int i = 1; i <= n; ++i) {
		if(~a[i] & 1) {
			++cntEven;
		} else if(a[i] == 1) {
			flagOne = true;
		}
	}
	if(cntEven & 1) {
		return true;
	} else {
		if(flagOne || cntEven != n - 1) return false;
		int Gcd = 0;
		for(int i = 1; i <= n; ++i)
			Gcd = gcd(a[i] & 1 ? a[i] - 1 : a[i], Gcd);
		for(int i = 1; i <= n; ++i)	a[i] /= Gcd;
		bool flag = solve() ^ 1;
		for(int i = 1; i <= n; ++i) a[i] *= Gcd;
		return flag;
	}
}

int main() {
	read(n);
	for(int i = 1; i <= n; ++i) read(a[i]);
	puts(solve() ? "First" : "Second");
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=100010;
int tt;
int head[N],to[N*2],nxt[N*2],sz[N],fa[N],g[N],k[N],v[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
inline void dfs(int x,int f,int d) {
    sz[x]=g[x]=d,fa[x]=f;
    for(int i=head[x];i;i=nxt[i]) {
	int y=to[i];
	if(y!=f) dfs(y,x,-d),sz[x]+=sz[y];
    }
}
inline int find(int x) {return fa[x]==x?x:fa[x]=find(fa[x]);}
int main() {
    int n,m,A,B;
    long long ans=0;
    cin>>n>>m;
    for(int i=1;i<=n;i++) fa[i]=i;
    for(int i=1;i<=m;i++) {
	int x=gi(),y=gi();
	if(find(x)==find(y)) A=x,B=y;
	else {
	    fa[find(x)]=find(y);
	    to[++tt]=y,nxt[tt]=head[x],head[x]=tt;
	    to[++tt]=x,nxt[tt]=head[y],head[y]=tt;
	}
    }
    dfs(1,0,1);
    if(m==n-1) {
	if(sz[1]) return puts("-1"),0;
    }
    else if(g[A]==g[B]) {
	if(sz[1]&1) return puts("-1"),0;
	int t=sz[1]/2;
	ans+=abs(t);
	for(int i=A;i;i=fa[i]) sz[i]-=t;
	for(int i=B;i;i=fa[i]) sz[i]-=t;
    }
    else {
	if(sz[1]) return puts("-1"),0;
	for(int i=A;i;i=fa[i]) ++k[i];
	for(int i=B;i;i=fa[i]) --k[i];
	int tp=1;
	for(int i=1;i<=n;i++) {
	    if(k[i]==1) v[++tp]=-sz[i];
	    if(k[i]==-1) v[++tp]=sz[i];
	}
	sort(v+1,v+1+tp);
	int t=v[(tp+1)/2];ans+=abs(t);
	for(int i=1;i<=n;i++) sz[i]+=k[i]*t;
    }
    for(int i=1;i<=n;i++) ans+=abs(sz[i]);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef vector<int>         vi;
const int mod = 1000000007;






int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,sum,no,ans=1e18;
    cin>>n;
    int pref[n];
    cin>>no;
    pref[0]=no;
    for(int i =1;i<n;i++){
        cin>>no;
        pref[i] = pref[i-1] + no;
    }

    sum = pref[n-1];
    for(int i =0;i < n-1;i++){
        int x = sum - pref[i];
        ans = min(ans,abs(pref[i]-x));
    }

 cout<<ans<<endl;
}












































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

ll c[2][2222][2222],a[1111][1111];
void init(ll n,ll m) {
  rep(k,2) {
    rep(i,n+1)rep(j,m) c[k][i][j+1]+=c[k][i][j];
    rep(j,m+1)rep(i,n) c[k][i+1][j]+=c[k][i][j];
  }
}
ll calc(ll x1,ll y1,ll x2,ll y2,ll k) {return c[k][x2][y2]-c[k][x1][y2]-c[k][x2][y1]+c[k][x1][y1];}

int main() {
  ll n,d,M=0;
  cin >> n >> d;
  rep(i,n) {
    ll x,y;
    cin >> x >> y;
    a[x%d][y%d]++;
  }
  rep(i,d)rep(j,d) M=max(M,(ll)ceil(sqrt(a[i][j])));
  rep(i,d)rep(j,d)rep(k,2) {
    if((M-k)*(M-1)<a[i][j]) {
      c[k][i+1][j+1]++;
      c[k][i+1][j+d+1]++;
      c[k][i+d+1][j+1]++;
      c[k][i+d+1][j+d+1]++;
    }
  } 
  init(d*2,d*2);
  ll k=d;
  rep(i,d)rep(j,d) {
    while(k>0&&!calc(i+k,j,i+d,j+d,0)&&!calc(i,j+k,i+d,j+d,0)&&!calc(i+k,j+k,i+d,j+d,1)) k--;
  }
  cout << (M-1)*d+k << endl;
  return 0;
}


Measured memory_bytes: 82176
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 50;
struct Matrix {
  int a[N][N];
  Matrix() {
    for (int i = 0; i < N; ++i) {
      fill(a[i], a[i] + N, 0);
    }
  }
  Matrix operator +(const Matrix& rhs) const {
    Matrix ret;
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        ret.a[i][j] = (a[i][j] + rhs.a[i][j]) % MOD;
      }
    }
    return ret;
  }
  Matrix operator *(const Matrix& rhs) const {
    Matrix ret;
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        for (int k = 0; k < N; ++k) {
          ret.a[i][j] += (int64)a[i][k] * rhs.a[k][j] % MOD;
          ret.a[i][j] %= MOD;
        }
      }
    }
    return ret;
  }
};

Matrix power(Matrix& a, int64 m) {
  Matrix ret;
  for (int i = 0; i < N; ++i) ret.a[i][i] = 1;
  for (; m; m >>= 1) {
    if (m & 1) {
      ret = ret * a;
    }
    a = a * a;
  }
  return ret;
}

int main() {
  int n;
  int64 m;
  scanf("%d%lld", &n, &m);
  Matrix a;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      scanf("%d", &a.a[i][j]);
    }
  }
  auto b = power(a, m);
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      ret = (ret + b.a[i][j]) % MOD;
    }
  }
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

typedef long long ll;

inline char get(void) {
  static char buf[100000], *S = buf, *T = buf;
  if (S == T) {
    T = (S = buf) + fread(buf, 1, 100000, stdin);
    if (S == T) return EOF;
  }
  return *S++;
}
template<typename T>
inline void read(T &x) {
  static char c; x = 0; int sgn = 0;
  for (c = get(); c < '0' || c > '9'; c = get()) if (c == '-') sgn = 1;
  for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0';
  if (sgn) x = -x;
}

ll a, b, c, x, y, z, ans;

inline int odd(ll x) {
  return x & 1;
}

int main(void) {
  read(a); read(b); read(c);
  while (!odd(a) && !odd(b) && !odd(c)) {
    if (a == b && b == c) {
      puts("-1"); return 0;
    }
    x = a >> 1; y = b >> 1; z = c >> 1;
    a = y + z; b = x + z; c = x + y;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e5 + 5;
#define INF 1000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int a[maxn];
int cnt[maxn];

 int getSum(int n) 
    {  
    int sum = 0; 
    while (n != 0) 
    { 
     sum = sum + n % 10; 
     n = n/10; 
    }  
 return sum; 
 }

int countDigit(long long n) 
{ 
    int count = 0; 
    while (n != 0) { 
        n = n / 10; 
        ++count; 
    } 
    return count; 
} 
char S[110];
char T[110];

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	ll a,b;
	cin >> a >> b;
	for(int i=1; i<=b; i++){
		if((a*i)%b == 0){
			cout << a*i << "\n";
			break;
		}
	}
	return 0;
}






Measured memory_bytes: 3640
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

//nCr mod m
#define MOD 998244353
#define M 2200000
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!h)init();
	if(n<0||r<0||n<r)return 1;//??????
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
	return out;
}
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}

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

	int a,b,n;
	cin>>a>>b>>n;

	int out=a*n/b-a*(n/b);
	int t=n/b*b-1;
	if(t>=0){
		t=a*t/b-a*(t/b);
		cmax(out,t);
	}
	cout<<out<<endl;

}


Measured memory_bytes: 3656
S = input()


def kaisetsu(S):
    n = len(S)
    K = n
    for i in range(n - 1):
        if S[i] != S[i + 1]:
            k = max(i + 1, n - i - 1)
            K = min(K, k)
    return K
 

print(kaisetsu(S))


Measured memory_bytes: 3188
#include<cstdio>
#include<set>
using namespace std;
int fa[2][200010],__rank[2][200010];
int findroot(bool op,int x)
{
	return x==fa[op][x] ? x : fa[op][x]=findroot(op,fa[op][x]);
}
void Union(bool op,int U,int V)
{
	if(__rank[op][U]<__rank[op][V])
	  fa[op][U]=V;
	else 
	 {
	 	fa[op][V]=U;
	 	if(__rank[op][U]==__rank[op][V])
	 	  ++__rank[op][U];
	 }
}
int n,m,K;
bool vis[200010];
int anss[200010];
set<int>S[2][200010];
typedef set<int>::iterator ITER;
int path[200010],e;
int main()
{
	int x,y;
	scanf("%d%d%d",&n,&m,&K);
	for(int i=1;i<=n;++i)
	  fa[0][i]=fa[1][i]=i;
	for(int i=1;i<=m;++i)
	  {
	  	scanf("%d%d",&x,&y);
	  	int f1=findroot(0,x),f2=findroot(0,y);
	  	if(f1!=f2)
	  	  Union(0,f1,f2);
	  }
	for(int i=1;i<=K;++i)
	  {
	  	scanf("%d%d",&x,&y);
	  	int f1=findroot(1,x),f2=findroot(1,y);
	  	if(f1!=f2)
	  	  Union(1,f1,f2);
	  }
	for(int i=0;i<=1;++i)
	  for(int j=1;j<=n;++j)
	    S[i][findroot(i,j)].insert(j);
	for(int i=1;i<=n;++i) if(!vis[i])
	  {
	  	e=0;
	  	int rt[2];
	  	bool o=0;
	  	rt[0]=findroot(0,i);
	  	rt[1]=findroot(1,i);
	  	if(S[0][rt[0]].size()>S[1][rt[1]].size())
	  	  o=1;
	  	set<int> tS=S[o][rt[o]];
	  	for(ITER it=tS.begin();it!=tS.end();++it)
	  	  if(S[o^1][rt[o^1]].find(*it)!=S[o^1][rt[o^1]].end())
	  	    {
	  	      S[o][rt[o]].erase(*it);
	  	      S[o^1][rt[o^1]].erase(*it);
	  	      path[++e]=(*it);
	  	      vis[*it]=1;
	  	    }
	  	for(int j=1;j<=e;++j)
	  	  anss[path[j]]=e;
	  }
	for(int i=1;i<n;++i)
	  printf("%d ",anss[i]);
	printf("%d\n",anss[n]);
	return 0;
}

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

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

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

int main()
{
    int n,a = 0;
    cin >> n;
    int l[n];
    rep(i, n)cin >> l[i];
    qsort(l, n, sizeof(int), desc);
    rep(i, n)a += l[i];
    if (l[0] < a - l[0]) {
        Yes;
    }else{
        No;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

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

		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			int[] ans = new int[86401];
			
			for(int i=0;i<n;i++){
				String s = sc.next();
				String t = sc.next();
				int a = Integer.valueOf(s.substring(0,2))*3600 + Integer.valueOf(s.substring(3,5))*60 + Integer.valueOf(s.substring(6,8));
				int b = Integer.valueOf(t.substring(0,2))*3600 + Integer.valueOf(t.substring(3,5))*60 + Integer.valueOf(t.substring(6,8));	
				for(int j=a;j<b;j++) ans[j]++;
			}	
			Arrays.sort(ans);
			System.out.println(ans[86400]);
		}
	}
}

Measured memory_bytes: 70832
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i]
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
int32_t main(){
    SPEED;
    string s;
    cin >> s;
    string s1 = "", s2 = "";
    int n = len(s);
    for(int i = 0; i < n; ++i){
        if(i & 1){
            s1 += '0';
            s2 += '1';
        }
        else{
            s1 += '1';
            s2 += '0';
        }
    }
    int cnt = 0, cnt1 = 0;
    for(int i = 0; i < n; ++i){
        if(s[i] != s1[i]) cnt++;
        if(s[i] != s2[i]) cnt1++;
    }
    cout << min(cnt, cnt1) ;
}

Measured memory_bytes: 3928
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<bitset>

#define Vsort(a) sort(a.begin(), a.end())
#define Vreverse(a) reverse(a.bigin(), a.end())
#define Srep(n) for(int i = 0; i < (n); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define Lrep(i,a,n) for(int i = (a); i < (n); i++)
#define vi vector<int>
#define vi64 vector<int64_t>
#define vvi vector<vi>
#define vvi64 vector<vi64>

using namespace std;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    int64_t sum = 0;
    vector<int> a(n);
    Srep(n){
        a[i] = (s[i] - '0');
        sum += a[i];
    }
    sum % 9 == 0 ? cout << "Yes" << endl : cout << "No" << endl;
}

Measured memory_bytes: 4364
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

void debug_out() { cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T Gcd(T a, T b){
    if( b==0 ) return a;
    return Gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/Gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,w; cin >> n >> w;
    vector<vector<ll>> m(4);
    ll l,r; cin >> l >> r;
    m[0].emplace_back(r);
    Rep(i,n-1){
        ll u,v; cin >> u >> v;
        ll x = u-l;
        m[x].emplace_back(v);
    }
    vector<vector<ll>> s(4);
    Rep(i,4){
        sort(rall(m[i]));
        s[i].resize(m[i].size()+1);
        s[i][0] = 0;
        Rep(j,m[i].size()){
            s[i][j+1] = s[i][j]+m[i][j];
        }
    }
    ll ans = 0;
    Rep(i,m[0].size()+1){
        Rep(j,m[1].size()+1){
            Rep(k,m[2].size()+1){
                Rep(t,m[3].size()+1){
                    ll sw = i*l + j*(l+1) + k*(l+2) + t*(l+3);
                    if(sw<=w){
                        chmax(ans,s[0][i]+s[1][j]+s[2][k]+s[3][t]);
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,a=0;
  string S;
  cin>>N>>S;
  for(int i=1;i<N;i++){
    if(S[i]=='E') a++;
  }
  int ans=a;
  for(int i=1;i<N;i++){
    if(S[i-1]=='W') a++;
    if(S[i]=='E') a--;
    if(ans>a) ans=a;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 900
n = int(input())
h = [int(_) for _ in input().split()]
h.append(0)
#print(h)
x = [0]
a = 0
for i in range(0,n):
    #print(h[i], h[i-1])
    if h[i] <= h[i-1]:
        a += 1
        if a > x[0]:
            x[0] = a
        #print(a)
    else: # h[i] > h[i-1]:
        a = 0
print(*x)



Measured memory_bytes: 14252
import java.util.*;
import java.io.*;
import java.lang.*;

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

        int ans = 0;

        for (int i = 0; i<4;i++){
            if (a.charAt(i) == '+')
                ans++;
            else
                ans--;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 35508
N = gets.to_i
A = gets.split.map!(&:to_i)
K = 60
MOD = 10**9 + 7
r = 1
ans = 0
K.times do |k|
  zeros = 0
  ones = 0
  A.each do |a|
    if a[k] == 1
      ones += 1
    else
      zeros += 1
    end
  end

  ans += ones * zeros * r
  ans %= MOD
  r <<= 1
end

puts ans


Measured memory_bytes: 34436
#define _USE_MATH_DEFINES
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REP1(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREP1(i, x) for (int i = ((int)(x)); i > 0; i--)
/*
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

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

using namespace std;

struct Card
{
    char suit;
    int value;
};
void print(Card a[], int n)
{
    REP(i, n)
    {
        if (i)
            cout << " ";
        cout << (char)a[i].suit << a[i].value;
    }
    cout << endl;
}
bool isStable(Card a[], Card b[], int n)
{
    REP(i, n)
    {
        if (a[i].suit != b[i].suit)
            return false;
    }
    return true;
}
void bubbleSort(Card a[], int n)
{
    REP(i, n)
    {
        for (int j = n - 1; j >= i + 1; j--)
            if (a[j].value < a[j - 1].value)
                swap(a[j], a[j - 1]);
    }
}
void selectionSort(Card a[], int n)
{
    REP(i, n)
    {
        int minj = i;
        for (int j = i; j < n; j++)
            if (a[minj].value > a[j].value)
                minj = j;
        swap(a[i], a[minj]);
    }
}

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

    Card a[50];
    Card b[50];
    REP(i, n)
    {
        char x;
        int y;
        cin >> x >> y;
        a[i].suit = x;
        b[i].suit = x;
        a[i].value = y;
        b[i].value = y;
    }

    bubbleSort(a, n);
    selectionSort(b, n);

    print(a, n);
    cout << "Stable" << endl;
    print(b, n);
    cout << (isStable(a, b, n) ? "Stable" : "Not stable") << endl;
}


Measured memory_bytes: 3064
N, M = map(int, input().split())

A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
for x in range(N - M + 1):
    for y in range(N - M + 1):
        isContain = True
        for i in range(M):
            for j in range(M):
                a = A[i + x][j + y]
                b = B[i][j]
                isContain &= (a == b)
        if isContain:
            ans = 'Yes'
            break
    else:
        continue
    break
else:
    ans = 'No'

print(ans)


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Extentions;

class IO
{
    int idx;
    string[] input = In.ReadToEnd().Split(new[] { " ", "\n", "\r" },
        StringSplitOptions.RemoveEmptyEntries);

    T Get<T>(Func<string, T> parser) => parser(input[idx++]);

    public string S => Get(s => s);
    public char C => Get(char.Parse);
    public int I => Get(int.Parse);
    public long L => Get(long.Parse);
    public double F => Get(double.Parse);
    public decimal D => Get(decimal.Parse);
    public BigInteger B => Get(BigInteger.Parse);

    T[] Gets<T>(int n, Func<string, T> parser)
        => input.Skip((idx += n) - n).Take(n).Select(parser).ToArray();

    public string[] Ss(int n) => Gets(n, s => s);
    public char[] Cs(int n) => Gets(n, char.Parse);
    public int[] Is(int n) => Gets(n, int.Parse);
    public long[] Ls(int n) => Gets(n, long.Parse);
    public double[] Fs(int n) => Gets(n, double.Parse);
    public decimal[] Ds(int n) => Gets(n, decimal.Parse);
    public BigInteger[] Bs(int n) => Gets(n, BigInteger.Parse);

    public void Write<T>(params T[] xs) => WriteLine(string.Join(" ", xs));
    public void Write(params object[] xs) => WriteLine(string.Join(" ", xs));
}

static class Extentions
{
}

static class Program
{
    public static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput()) { NewLine = "\n" };
#if DEBUG
        sw.AutoFlush = true;
#else
        sw.AutoFlush = false;
#endif
        SetOut(sw);
        Solve(new IO());
        Out.Flush();
    }

    static void Solve(IO io)
    {
        var s = io.S;
        var t = io.S;

        for (var i = s.Length - t.Length; i >= 0; i--)
        {
            var eq = true;
            for (var j = 0; j < t.Length; j++)
                eq &= s[i + j] == '?' || s[i + j] == t[j];

            if (eq)
            {
                for (var j = 0; j < s.Length; j++)
                    Write(j - i < 0 || t.Length <= j - i ? (s[j] == '?' ? 'a' : s[j]) : t[j - i]);
                WriteLine();
                return;
            }
        }

        WriteLine("UNRESTORABLE");
    }
}

Measured memory_bytes: 11220
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**8) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n = ni()
a = [ni() for _ in range(n)]

cnt = {i+1: ai for i, ai in enumerate(a)}

prev = -100
cur = 0
ans = 0
for key in sorted(cnt.keys()):
    if cnt[key] == 0:
        continue
    
    if prev == -100:
        prev = key
    
    if (key-prev) < 2:
        cur += cnt[key]
    else:
        cur = cnt[key]
        
    ans += cur // 2
    cur -= 2 * (cur//2)
    
    prev = key
        
print(ans)

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

int main(void){
	int n,q;cin>>n>>q;
	vector<string> ns(53);
	for(int i=0;i<n;++i){
		int year;
		string name;
		cin>>year>>name;
		ns[year]=name;
	}
	ns[1]="kogakubu10gokan";
	for(int i=q;i;--i){
		if(ns[i] != ""){
			cout<<ns[i]<<endl;
			break;
		}
	}
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i,n) cin >> a[i];
    int ans = 0;
    rep(i,n){
        if(i==a[a[i]-1]-1) ans++;
    } 
    cout << ans/2 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i = 0 ; i < n ; ++i)
#define rep1(i,n) for(int i = 1 ; i <= n ; ++i)
using namespace std;
int n;
double p[3010];
double dp[3010][3010];
int main()
{
  cin >> n;
  rep(i,n) cin >> p[i];

  rep(i,n+1) rep(j,n+1) dp[i][j] = 0;
  dp[0][0] = 1;

  rep(i,n){
    rep(j,i+1){
      dp[i+1][j] += dp[i][j] * p[i];
      dp[i+1][j+1] +=  dp[i][j] * ( 1 - p[i] );
    }
  }

  double res = 0;
  rep(j,(n+1)/2) res += dp[n][j];
  printf("%.9f\n", res);
  
  
  return 0;
}


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

  int h,w,m;
  cin>>h>>w>>m;
int   r[h+1]={0},c[w+1]={0};
  set<pair<int,int>>p;
while(m--){
    int a,b;
    cin>>a>>b;
    p.insert({a,b});
    r[a]++;
    c[b]++;
}
int x=1,y=1;
for(int i=1;i<=h;i++){
    if(r[i]>r[x])
        x=i;
}
for(int i=1;i<=w;i++){
    if(c[i]>c[y])
        y=i;
}
int ans=0;
for(int i=1;i<=w;i++){
    if(p.find({x,i})!=p.end())
        ans=max(ans,r[x]+c[i]-1);
        else
            ans=max(ans,r[x]+c[i]);
}
for(int i=1;i<=h;i++){
    if(p.find({i,y})!=p.end())
        ans=max(ans,r[i]+c[y]-1);
    else
        ans=max(ans,r[i]+c[y]);
}
cout<<ans;
}


Measured memory_bytes: 19992