akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

int main(){
    int n;cin>>n;
    map<int,int>mp;
    rep(i,n){
        int a;cin>>a;
        mp[a-1]++;
        mp[a]++;
        mp[a+1]++;
    }
    int res,mx = 0;
    for(auto m : mp){
        if(m.second>mx){
            res = m.first;
            mx = m.second;
        }
    }
    cout<<mx<<endl;
}



Measured memory_bytes: 4736
#include <iostream>
#include <complex>
#include <cmath>
#include <cstdio>
using namespace std;

int main() {
	typedef complex<double> com;
	double s = 0.0;
	int n, x0, y0, x1, y1, x2, y2;
	cin >> n >> x0 >> y0 >> x1 >> y1;
	for ( int i = 0; i < n - 2; i++ ) {
		cin >> x2 >> y2;
		s += ( conj( com( x1 - x0, y1 - y0 ) ) * com( x2 - x0, y2 - y0 ) ).imag() * 0.5;
		x1 = x2;
		y1 = y2;
	}
	printf( "%.1f\n", s );
}

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

int main() {
    string S;
    cin >> S;

    bool found[26] = {};
    for (char ch : S) {
        found[ch - 'a'] = true;
    }

    string ans = "None";
    for (int i = 0; i < 26; i++) {
        if (!found[i]) {
            ans = char('a' + i);
            break;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
{
    int ans=1,n,k,t=0;
    cin>>n>>k;
    while(t<n)
    {
        if (ans>=k)
        ans=ans+k;
        else
        ans=ans+ans;
        t=t+1;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
 UL N; scanf("%u",&N);
 UL A[1<<20]; A[0]=0;
 rep(i,N){
  UL a; scanf("%u",&a);
  rep(j,1<<i) A[j+(1<<i)] = (A[j]+a);
 }
 UL NN=1<<N;
 sort(A,A+NN);
 UL Q; scanf("%u",&Q);
 rep(q,Q){
  UL x; scanf("%u",&x);
  UL l,r; l=0;r=NN+1;
  while(l+1<r){ UL m=(l+r)>>1;
   if(A[m-1]<x) l=m; else r=m;
  }
  if(A[l]==x) printf("yes\n");
  else printf("no\n");
 }
 return 0;
}



Measured memory_bytes: 7248
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

int main() {
    ll n, k;
    cin >> n >> k;

    ll a = (n-1)*(n-2)/2;
    ll b = a-k;

    if(a < k) {
        out(-1);
        re0;
    }

    out( (n-1) + b );

    exrep(i, 1, n-1) {
        cout << n << " " << i << "\n";
    }

    ll cnt = 0;
    exrep(i, 1, n-2) {
        exrep(j, i+1, n-1) {
            if(cnt == b) {
                re0;
            }
            cout << i << " " << j << "\n";
            cnt++;
        }
    }
    
}

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

typedef unsigned long long ull;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
const ull mod = 1e9 + 7;

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int A,N;	cin>>N;
	
	FOR(i,0,N){
	cin>>A;
	if(A%2==0){
		if(A%3==0||A%5==0);
		else {
          cout<<"DENIED"<<endl;
          return 0;
        	}
		}
	}
	
	cout<<"APPROVED"<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX 200005
using namespace std;
 
int main(){
  int n, m, a, b, cnt = 0;
  bool is[MAX];
  fill(is, is+MAX, false);
  char s[MAX];
  set<int> p[2][MAX];
  scanf("%d%d%s", &n, &m, s);
  for(int i = 0; i < m; i++){
    scanf("%d%d", &a, &b);
    a--; b--;
    p[s[b] == 'B'][a].insert(b);
    p[s[a] == 'B'][b].insert(a);
  }
  for(int i = 0; i < n; i++){
    queue<int> q;
    q.push(i);
    while(!q.empty()){
      int j = q.front(); q.pop();
      if(is[j] || !(p[0][j].empty() || p[1][j].empty())) continue;
      int k = p[0][j].empty();
      cnt++;
      is[j] = true;
      for(auto it = p[k][j].begin(); it != p[k][j].end(); it++){
        p[s[j] == 'B'][*it].erase(j);
        q.push(*it);
      }
    }
  }
  puts(cnt == n ? "No" : "Yes");
}

Measured memory_bytes: 37504
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define erep(i, n) for (int i = 0; i <= (int)(n); i++)

int main() {
    const int MAX_V = 100010;
    const ll INF = 1LL<<60;
    int n, w;
    cin >> n >> w;
    vector<int> weights(n), values(n);
    rep (i, n) cin >> weights[i] >> values[i];

    vector< vector<ll> > dp(n + 1, vector<ll>(MAX_V, INF));
    dp[0][0] = 0;

    rep (i, n) {
        rep (j, MAX_V) {
            if (j >= values[i]) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - values[i]] + weights[i]);
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        }
    }
    ll ans = INF;
    rep (i, MAX_V) {
        if (dp[n][i] <= w) ans = i; 
    }
    cout << ans << endl;
}


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

using namespace std;

#define inf 210000000
#define int long long

bool cmp(int a,int b){
		return a > b;
}

signed main() {
		int x,a,b;
		cin >> x >> a >> b;
		if(abs(a-x) > abs(b-x)) cout << 'B' << endl;
		else cout << 'A' << endl;
}


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

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

using namespace std;

int main(){
	int n; scanf("%d",&n);
	pair<int,int> a[200000];
	rep(i,n) scanf("%d%d",&a[i].second,&a[i].first);

	sort(a,a+n);

	int t=0;
	rep(i,n){
		t+=a[i].second;
		if(a[i].first<t){
			puts("No");
			return 0;
		}
	}
	puts("Yes");

	return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

    static int[] dp;

    static int min(int a,int b){
        if(a<b)
            return a;
        return b;
    }
    static int calculate(int n,int[] arr, int k){
        if(n < 1){
            return Integer.MAX_VALUE;
        }
        if(dp[n] != -1){
            return dp[n];
        }
        if(n == 1){
            dp[n] = 0;
            return dp[n];
        }else if(n == 2){
            dp[n] = Math.abs(arr[n]-arr[n-1]);
            return dp[n];
        }
        dp[n] = Math.abs(arr[n]-arr[n-1])+calculate(n-1,arr,k);
        for(int i = 2; i <=k; i++){
            if(n-i>=1){
                dp[n] = min(dp[n],Math.abs(arr[n]-arr[n-i])+calculate(n-i,arr,k));
            }
        }
        return dp[n];
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] arr = new int[n+1];

        dp = new int[n+1];

        for(int i =1; i <= n; i++){
            dp[i] = -1;
            arr[i] = sc.nextInt();
        }
        System.out.println(calculate(n,arr,k));
    }
}


Measured memory_bytes: 74672
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()

ans = n ** 3
up = [0] * n
mid = [0] * n
bottom = [0] * n

p = 0
for i in range(n):
    while p < n and A[i] >= B[p]:
        p += 1
    mid[i] = p

p = 0
q = 0
for i in range(n):
    while p < n and B[i] >= C[p]:
        p += 1
    while q < n and B[i] > A[q]:
        q += 1
    bottom[i] = p
    up[i] = q

for m in mid:
    ans -= m * n

for u, b in zip(up, bottom):
    ans -= u * b

print(ans)


Measured memory_bytes: 27892
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int, int>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) FOR(i, 0, n)
#define SZ(v) ((int)v.size())
#define FILL(a, x) fill(begin(a), end(a), (x));
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define FINF(a) memset(a, 0x3f, sizeof(a))
#define POW(n) (1LL << (n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i, a, b) ((a) <= (i) && (i) <= (b))
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a > b) { a = b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a < b) { a = b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(begin(a), end(a)); }
template <typename T> inline void REV(T& a) { reverse(begin(a), end(a)); }
template <typename T> inline void UNI(T& a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }
template <typename S, typename T> inline T LB(S& v, T a) { return *lower_bound(begin(v), end(v), a); }
template <typename S, typename T> inline int LBP(S& v, T a) { return lower_bound(begin(v), end(v), a) - begin(v); }
template <typename S, typename T> inline T UB(S& v, T a) { return *upper_bound(begin(v), end(v), a); }
template <typename S, typename T> inline int UBP(S& v, T a) { return upper_bound(begin(v), end(v), a) - begin(v); }
template <typename S, typename T> ostream& operator << (ostream& os, const pair<S, T>& p) { os << p.first << " " << p.second; return os; }
template <typename S, typename T> istream& operator >> (istream& is, pair<S, T>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator << (ostream& os, const vector<T>& v) { for (int i = 0; i < v.size(); ++i) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator >> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

int A, B, C;

void _main() {
    cin >> A >> B >> C;
    cout << (A + B + C >= 22 ? "bust" : "win") << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i')) freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o')) freopen("output.txt", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void) {
	int h,w;
	while (true) {
		scanf("%d %d", &h, &w);
		if ((h == 0) && (w == 0)) {
			break;
		}
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 2588
#include <iostream>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <map>
#include <cstring>
#include <utility>
#include <vector>
#include <cmath>

using namespace std;

typedef pair<int,vector<bool> > P;
typedef long long int ll;

int N,Ma,Mb;
int a[41],b[41],c[41];
int dp[41][401][401];

int solve(){

  for(int i=0;i<N+1;i++){
    for(int j=0;j<N*10+1;j++){
      for(int k=0;k<N*10+1;k++){
	if(j==0 && k==0) dp[i][j][k]=0;
	else dp[i][j][k]=INT_MAX/3;

      }
    }
  }
  dp[0][a[0]][b[0]] = c[0];

  for(int i=1;i<N;i++){
    for(int j=0;j<N*10+1;j++){
      for(int k=0;k<N*10+1;k++){
	//dp[i][j][k] = min(dp[i][j][k],dp[i-1][j][k]);
	dp[i][j][k] = dp[i-1][j][k];
	if(j-a[i]>=0 && k-b[i]>=0)
	  dp[i][j][k]=min(dp[i][j][k],dp[i-1][j-a[i]][k-b[i]]+c[i]);
      }
    }
  }
  int mincost = INT_MAX/3;
  for(int j=1;j<N*10+1;j++)
    for(int k=1;k<N*10+1;k++){
      if(j*Mb==k*Ma && dp[N-1][j][k]<mincost){
	mincost = dp[N-1][j][k];
      }
    }

  return mincost;
}
	
int main(){

  cin>>N>>Ma>>Mb;
  for(int i=0;i<N;i++){
    cin>>a[i]>>b[i]>>c[i];

  }
  
  int ret = solve();
  if(ret==INT_MAX/3) cout<<"-1"<<endl;
  else cout<<ret<<endl;
  /*
  for(int i=0;i<N;i++){
    for(int j=0;j<N*10+1;j++){
      for(int k=0;k<N*10+1;k++){
	if(dp[i][j][k]==INT_MAX/3) cout<<"N ";
	else cout<<dp[i][j][k]<<" ";
      }
      cout<<endl;
    }
    cout<<endl;
  }
  */

  return 0;
}



Measured memory_bytes: 25984
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int N,L;
    cin >> N >> L;
    vector<string> S(N);
    for(int i=0;i<N;i++){
        cin >> S.at(i);
    }
    sort(S.begin(),S.end());
    string result="";
    for(int i=0;i<N;i++){
        result+=S.at(i);
    }
    cout << result << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef pair<pair<int, int>, int> PP;
typedef long long ll;
typedef priority_queue<int> pq;
int main(void) {
    int X, Y;
    cin >> X >> Y;
    cout << X + (Y/2) << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

func main() {
	solve(os.Stdin, os.Stdout)
}

func solve(in io.Reader, out io.Writer) {
	var bs = NewBufScanner(in)
	var bw = NewBufWriter(out)
	defer bw.w.Flush()

	line := strings.Split(bs.Scan(), " ")
	a, _ := strconv.Atoi(line[0])
	b, _ := strconv.Atoi(line[1])

	r := ""
	if (a * b) % 2 == 1 {
		r = "Odd"
	} else {
		r = "Even"
	}

	bw.Printf("%s\n", r)
}

// BufScanner original scanner
type BufScanner struct {
	s *bufio.Scanner
}

// NewBufScanner constructer
func NewBufScanner(in io.Reader) *BufScanner {
	s := bufio.NewScanner(in)
	return &BufScanner{
		s: s,
	}
}

// Scan Scan Data
func (b *BufScanner) Scan() string {
	b.s.Scan()
	return b.s.Text()
}

// BufWriter original writer
type BufWriter struct {
	w *bufio.Writer
}

// NewBufWriter constructer
func NewBufWriter(out io.Writer) *BufWriter {
	w := bufio.NewWriter(out)
	return &BufWriter{
		w: w,
	}
}

// Printf Output file
func (b *BufWriter) Printf(format string, a ...interface{}) {
	fmt.Fprintf(b.w, format, a...)
}

Measured memory_bytes: 640
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  int a, b, c;
  cin >> a >> b >> c;
  int r = a-b;
  cout << max(c-r, 0) << endl;
}


Measured memory_bytes: 256
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    H = list(map(int, input().split()))

    A = [0] * N
    ch = 0
    for i, h in enumerate(H):
        if ch >= h:
            A[i] = A[i-1] + 1
            ch = h
        else:
            ch = h

    return max(A)


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 14172
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        T_Permutation solver = new T_Permutation();
        solver.solve(1, in, out);
        out.close();
    }

    static class T_Permutation {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.ni();
            String s = in.ns();
            long mod = (int) 1e9 + 7;
            long[][] dp = new long[n][n + 1];
            dp[0][1] = 1;
            for (int i = 1; i < n; i++) {
                if (s.charAt(i - 1) == '<') {
                    long sum = 0;
                    for (int j = 1; j <= i; j++) {
                        sum += dp[i - 1][j];
                        dp[i][j + 1] = (dp[i][j + 1] + sum) % mod;
                    }
                } else {// >
                    long sum = 0;
                    for (int j = i; j >= 1; j--) {
                        sum += dp[i - 1][j];
                        dp[i][j] = (dp[i][j] + sum) % mod;
                    }
                }
            }
            long ans = 0;
            for (int i = 1; i < n + 1; i++) {
                ans += dp[n - 1][i];
            }
            out.println(ans % mod);
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(ns());
        }

    }
}



Measured memory_bytes: 129876
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

	int n;
	cin >> n;
	map<int,int> a;
	vi b(n);
	rep(i, n)cin >> b[i];
	sort(all(b));
	int t;
	ll ans1 = 0, ans2 = 0;
	rep(i, n) {
		t = b[i];
		a[t]++;
		if (a[t] >= 2 && t > ans1) {
			ans2 = ans1;
			ans1 = t;
		}
		if (a[t] >= 4 && t >= ans1) {
			ans1 = t;
			ans2 = t;
		}
	}
	
	cout << (ans1*ans2) << endl;

	return 0;
}



Measured memory_bytes: 5376
import sys
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    x = list(map(int, input().split()))
    ans = abs(x[0]) + abs(x[K-1] - x[0])
    ans = min(ans, abs(x[K-1]) + abs(x[0] - x[K-1]))
    for i in range(1, N-K+1):
        ans = min(ans, abs(x[i]) + abs(x[i+K-1] - x[i]))
        ans = min(ans, abs(x[i+K-1]) + abs(x[i] - x[i+K-1]))
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 14596
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int dp[101][101];
int table[101][101];

const int INF = 100000000;

int main(){

	for(int i = 0; i < 101; i++){
		fill(table[i],table[i]+101,INF);
		fill(dp[i],dp[i]+101,0);
	}

	string str;
	int depth=0;
	while(getline(cin,str)){
		int idx=0;
		for(int i = 0; i < str.size(); i++){
			if(str[i]>='0'&&str[i]<='9'){
				for(int j = i+1; j <= str.size(); j++){
					if(j==str.size()||!(str[j]>='0'&&str[j]<='9')){
						table[depth][idx]=atoi(str.substr(i,j-i).c_str());
						idx++;
						i=j;
						break;
					}
				}
			}
		}
		depth++;
	}

	dp[0][0]=table[0][0];
	for(int i = 1; i < depth; i++){
		int wide;
		if((depth/2)>=i){
			wide=i+1;
		}
		else{
			wide=depth-i;
		}


		if((depth/2)>=i){
			for(int j = 0; j < wide; j++){
				if(j-1>=0){
					dp[i][j]=max(dp[i][j],dp[i-1][j-1]+table[i][j]);
				}
				if(table[i-1][j]!=INF){
					dp[i][j]=max(dp[i][j],dp[i-1][j]+table[i][j]);
				}
			}
		}
		else{
			for(int j = 0; j < wide; j++){
				dp[i][j]=max(dp[i][j],dp[i-1][j]+table[i][j]);
				if(table[i-1][j+1]!=INF){
					dp[i][j]=max(dp[i][j],dp[i-1][j+1]+table[i][j]);
				}
			}

		}
	}
	cout<<dp[depth-1][0]<<endl;

	return 0;
}

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

int N;
int res;

void dfs(long long x, bool seven, bool five, bool three) {
    if (x > N) return;
    if (seven && five && three) res++;
    dfs(10 * x + 7, true, five, three);
    dfs(10 * x + 5, seven, true, three);
    dfs(10 * x + 3, seven, five, true);
}

int main() {
    cin >> N;
    dfs(0, false, false, false);
    cout << res << endl;
    return 0;
}

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

int main() {
	int n,o=0,d=0,f=0;
	cin>>n;
	int a[n+3];
	for(int i=0;i<n;i++)
	{
	 cin>>a[i];
	 if(a[i]%4==0)f++;
	 else if(a[i]%2==0) d++;
	 else o++;
	}
	if(d==0)
	{
		if(o<=f+1)
		cout<<"Yes";
		else
		cout<<"No";
	}
	else
	{
		if(o<=f)
		cout<<"Yes";
		else
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 640
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    bs <- getIntList
    let ans = reverse $ solve n (reverse bs)
    if any (== 0) ans then
        print (-1)
    else mapM_ print ans

solve 0 _ = []
solve k rs | i == 0 = [0]
           | otherwise = i : solve (k-1) (map snd (xs ++ tail ys))
    where (xs,ys) = span (\(i,b) -> i /= b) (zip [k,k-1..] rs)
          i = length ys

Measured memory_bytes: 1020
a,b,x = map(int, input().split())

import math

if x > a**2*b*0.5:
    ans = math.atan(2*b/a-2*x/a**3)
else:
    ans = math.atan(a*b**2/2/x)
    
ans *= 180/math.pi
print(ans)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassLibrary1
{
    public class ListNode
    {
        public int val;
        public ListNode next;
        public ListNode(int x) { val = x; }
    }


    public class Class1
    {
        static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long, long>, long>();


        static void Main(string[] args)
        {

            var aa = ReadLongArr();
            var a = aa[0];
            var b = aa[1];
            var k = aa[2];

            var res = 0;

            if (k < a)
            {
                a = a - k;
            }
            else
            {
                b = Math.Max(a + b - k, 0);
                a = 0;
            }

            Console.WriteLine(a + " " + b);
        }


        class BitArr
        {
            public bool[] bitArr = new bool[64];

            public BitArr(long l)
            {
                var ll = l;
                for(int i=0; i<64; i++)
                {
                    bitArr[i] = (ll % 2) == 1;
                    ll = ll / 2;
                }
            }
        }

        public static int Digit(long num)
        {
            // Mathf.Log10(0)はNegativeInfinityを返すため、別途処理する。
            return (num == 0) ? 1 : ((int)Math.Log10(num) + 1);
        }

        public static long nCm(long n, long m, long mod)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            var a = n * nCm(n - 1, m - 1, mod) / m;
            return a % mod;
            //return a % 1000000007;
        }

        private static string ReadString()
        {
            return Console.ReadLine();
        }
        private static string[] ReadStringArr()
        {
            return Console.ReadLine().Split(' ');
        }
        private static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadLongArr()
        {
            string[] s = ReadStringArr();
            long[] l = new long[s.Length];
            for(int i=0; i<l.Length; i++)
            {
                l[i] = long.Parse(s[i]);
            }

            return l;
        }
    }

}


Measured memory_bytes: 11220
import sys

a, b, x, y = [], [], [], []
oo = 168430090

def rdl():
	return map(int, raw_input().split())


def mht(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)


#sys.stdin = open("test.in", "r")
n, m = rdl()
for i in range(n):
	l, r = rdl()
	x.append(l), y.append(r)

for i in range(m):
	l, r = rdl()
	a.append(l), b.append(r)

for i in range(n):
	mn, mnid = oo, 0
	for j in range(m):
		if mht(x[i], y[i], a[j], b[j]) < mn:
			mn = mht(x[i], y[i], a[j], b[j])
			mnid = j
	
	print mnid + 1




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

bool m(double a1, double b1, double a2, double b2){
	bool key;

	if(a1==0){
		if(a2==0) key=true;
		else key=false;
	}
	else{
		if(a2==0) key=false;
		else{
			if(b1/a1==b2/a2) key=true;
			else key=false;		
		}
	}

	return key;
}

int main(){
	double x1,x2,x3,xp,y1,y2,y3,yp;
	while( scanf(" %lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3, &xp, &yp) != EOF ){
		
		//(x1,y1)が原点に来るように平行移動
		x2-=x1; y2-=y1; x3-=x1; y3-=y1; xp-=x1; yp-=y1;
		x1-=x1; y1-=y1;
		
		//printf(" %lf %lf %lf %lf %lf %lf %lf %lf\n", x1, y1, x2, y2, x3, y3, xp, yp);
		
		bool ans;
		
		//(xp,yp)が辺の延長線上にあるとき
		if(m(x2,y2,xp,yp) || m(x3,y3,xp,yp)){
			ans=false;
		}
		else{
			double p, q;
			
			if(x2!=0){
				q=(yp-xp*y2/x2)/(y3-x3*y2/x2);
				p=(xp-q*x3)/x2;
			}
			else{
				q=xp/x3;
				p=(yp-q*y3)/y2;
			}
		
			//printf("p=%lf, q=%lf\n",p ,q);
		
			if(0<p && p<1 && 0<q && q<1 && p+q<1) ans= true;
			else ans=false;
		}
		
		if(ans) printf("YES\n");
		else printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 1196
import re
S = [int(item) for item in list(input())]

# 0 start
flip0 = sum(S[0::2]) + (len(S[1::2]) - sum(S[1::2]))

# 1 start
flip1 = sum(S[1::2]) + (len(S[0::2]) - sum(S[0::2]))

print(min(flip0, flip1))


Measured memory_bytes: 4904
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int num,cnt=0;
  string N;
  cin >> N;
  num=stoi(N);

  if(N.size()==1){
    //num=num-pow(10,N.size());
    for(int i=0; i<num;i++){
      cnt++;
    }
    cout << cnt <<endl;
  }
  
  else if(N.size()==2){
    cout << "9" <<endl;
  } 
  
  else if(N.size()==3){
    num=num-pow(10,N.size()-1);
    for(int i=0;i<num+1;i++){
      cnt++;
    }
    cout << cnt+9 <<endl;
  }
  
  else if(N.size()==4){
    cout << "909" <<endl;
  }
  
  else if(N.size()==5){
    num=num-pow(10,N.size()-1);
    for(int i=0;i<num+1;i++){
      cnt++;
    }
    cout << cnt+909 <<endl;
  }
  
  else if(N.size()==6){
    cout << "90909" <<endl;
  }

}  

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Linq;
using System.Text;
using static System.Math;

class MainClass
{

    public static void Main(string[] args)
    {
        var N = LnInt();
        var Xs = LnInts();
        
        var result = int.MaxValue;
        foreach(var i in Enumerable.Range(-100,200))
        {
            var cost = 0;
            foreach(var n in Xs)
            {
                cost += (n - i) * (n - i);
            }
            result = cost < result ? cost : result;
        }
        print(result);
    }

    public static void print(object obj) { Console.WriteLine(obj); }
    public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; }
    public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); }
    public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; }
    public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); }
    public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; }
    public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; }
public static List<T[]> AllPermutation<T>(params T[] array) where T : IComparable{var a = new List<T>(array).ToArray();var res = new List<T[]>();res.Add(new List<T>(a).ToArray());var n = a.Length;var next = true;while (next){next = false;int i;for (i = n - 2; i >= 0; i--){if (a[i].CompareTo(a[i + 1]) < 0) break;}if (i < 0) break;var j = n;do{j--;} while (a[i].CompareTo(a[j]) > 0);if (a[i].CompareTo(a[j]) < 0){var tmp = a[i];a[i] = a[j];a[j] = tmp;Array.Reverse(a, i + 1, n - i - 1);res.Add(new List<T>(a).ToArray());next = true;}}return res;}}



Measured memory_bytes: 11220
S=list(input())

c=0
max=0
for i in range(len(S)) :
  if S[i]=='A' or S[i]=='C' or S[i]=='G' or S[i]=='T' :
    c+=1
    if c>max :
      max=c
  else :
    c=0
  
print(max)

Measured memory_bytes: 3060
// abca29c.cpp : Typical Stairs
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rp(i,n) for(int i=0;i<(n);i++)

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

	vector<bool> ok(n+1,true);
	rp(i,m){
		int a; cin>>a;
		ok[a] = false;
	}

	vector<int> dp(n+1);
	dp[0] = 1;
	rp(now,n)
		for(int next=now+1; next<=min(n, now+2); next++)
			if(ok[next]) dp[next] = (dp[next] + dp[now]) % MOD;

	cout<< dp[n] <<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
const long long int sMod = 998244353;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll n;
    cin >> n;
    ll ctr=0;
    bool ok=false;
    rp(i,n){
        ll a,b;
        cin >> a >> b;
        if(a==b) ctr++;
        else ctr=0;
        if(ctr==3){
            ok=true;
        }
    }
    Yes(ok);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3656
from collections import defaultdict
N, M = map(int, input().split())
flg = 1
ans = 0
a = [list(map(int, input().split())) for _ in range(M)]
while flg == 1:
    d = defaultdict(int)
    flg = 0
    for link in a:
        d[link[0]] += 1
        d[link[1]] += 1
    for node in range(1, M + 1):
        if d[node] == 1:
            ans += 1
            flg = 1
            a = [x for x in a if node not in x]
print(ans)


Measured memory_bytes: 3316
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Abhilash
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            char arr[][] = new char[n][m];
            for (int i = 0; i < n; i++) {
                String s = in.next();
                for (int j = 0; j < m; j++) {
                    arr[i][j] = s.charAt(j);
                }
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    boolean flag = false;
                    if (arr[i][j] == '#') {
                        if (i + 1 < n && arr[i + 1][j] == '#')
                            flag = true;
                        if (i - 1 > -1 && arr[i - 1][j] == '#')
                            flag = true;
                        if (j + 1 < m && arr[i][j + 1] == '#')
                            flag = true;
                        if (j - 1 > -1 && arr[i][j - 1] == '#')
                            flag = true;
                    } else {
                        flag = true;
                    }
                    if (!flag) {
                        out.println("No");
                        return;
                    }
                }
            }
            out.println("Yes");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 21972
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl


int s[123456];

signed main() {

	int N, M;
	cin >> N >> M;
	int L[123456], R[123456];

	rep(i, M) {
		cin >> L[i] >> R[i];
		L[i]--; R[i]--;
		s[L[i]] ++;
		s[R[i]+1] --;
	}
	rep(i, N + 1) {
		s[i + 1] += s[i];
	}

	int ans = 0;
	rep(i, N) {
		if (s[i] == M) ans++;
	}
	cout << ans << endl;







	return 0;
}


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

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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  int N;
  ll K;
  std::cin >> N >> K;

  std::vector<ll> A(N);
  rep(i, N) {
    std::cin >> A[i];
    --A[i];
  }

  std::vector<ll> S(N + 1);
  rep(i, N) {
    S[i + 1] = (S[i] + A[i]) % K;
  }

  ll ans = 0;
  std::map<ll, int> cnt;
  std::queue<ll> q;
  rep(j, N + 1) {
    ans += cnt[S[j]];
    ++cnt[S[j]];
    q.push(S[j]);
    if(q.size() == K) {
      --cnt[q.front()];
      q.pop();
    }
  }
  std::cout << ans << '\n';
}


Measured memory_bytes: 17536
#include <iostream>
#include <string>
#include <cctype>

using namespace std;

int main()
{
	string s;

	getline(cin, s);
	for (unsigned int i = 0; i < s.length(); ++i) {
		if (isupper(s[i]))
			s[i] = tolower(s[i]);
		else if (islower(s[i]))
			s[i] = toupper(s[i]);
	}
	cout << s << endl;

	return 0;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int n,ma,mb;
int a[50],b[50],c[50];
int dp[50][500][500];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>ma>>mb;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i]>>c[i];
	memset(dp,63,sizeof(dp));
	dp[0][0][0]=0;
	int res=1e9;
	for(int i=0;i<n;i++){
		for(int j=0;j<=400;j++){
			for(int k=0;k<=400;k++){
				dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k]);
				dp[i+1][j+a[i]][k+b[i]]=min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=400;j++){
			for(int k=1;k<=400;k++){
				if(j*mb==k*ma)
					res=min(res,dp[i][j][k]);
			}
		}
	}
	if(res==1e9)
		res=-1;
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 49660
#include <iostream>
using namespace std;
int main(){
    
    int a1,a2,a3;

    cin >> a1 >> a2 >> a3;

    if(a1 <= a3 && a3 <= a2){

        cout << "Yes" << endl;
    }else{

        cout << "No";
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef tuple<int, int, int> tp;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef pair<LL, LL> pll;
typedef pair<pii, int> piipi;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;
typedef pair<LL, pii> plpii;
typedef pair<LD, LD> pdd;
typedef pair<LD, int> pdi;
typedef pair<LD, LL> pdl;
typedef pair<int, LD> pid;
typedef pair<LL, LD> pld;
const int mod = 1e9 + 7;
const int hf = 999983;
const int N = 1e6;

int n, m;
vector<int> g[100005];
vector<LL> pref[100005], suff[100005];
map<int, int> idx[100005];
map<int, LL> dp[100005];
int par[100005];
bool up[100005];

void update(int u){
    up[u] = 1;
    int sz = g[u].size();
    for(int i=1;i<sz;i++) pref[u][i] = (pref[u][i]*pref[u][i-1])%m;
    for(int i=sz-2;i>=0;i--) suff[u][i] = (suff[u][i]*suff[u][i+1])%m;
}

void dfs_down(int u, int p){
    par[u] = p;
    pref[u].resize(g[u].size());
    suff[u].resize(g[u].size());

    dp[u][p] = 1;
    for(int i=0;i<g[u].size();i++){
        int v = g[u][i];
        idx[u][v] = i;
        if(v == p) continue;
        dfs_down(v, u);

        pref[u][i] = (dp[v][u]+1)%m;
        suff[u][i] = (dp[v][u]+1)%m;
        dp[u][p] = (dp[u][p]*(dp[v][u]+1))%m;
    }
    if(u == 1) update(1);
}

void dfs_up(int u, int p){
    if(!up[u]){
        int v = par[u];
        dfs_up(v, u);
        pref[u][idx[u][v]] = (dp[v][u]+1)%m;
        suff[u][idx[u][v]] = (dp[v][u]+1)%m;
        par[u] = 0;
        update(u);
    }

    if(p == 0) dp[u][p] = pref[u][g[u].size()-1];
    else{
        dp[u][p] = 1;
        if(idx[u][p]-1 >= 0) dp[u][p] = (dp[u][p]*pref[u][idx[u][p]-1])%m;
        if(idx[u][p]+1 < g[u].size()) dp[u][p] = (dp[u][p]*suff[u][idx[u][p]+1])%m;
    }
}

int main(){
    scanf("%d%d", &n, &m);
    for(int i=2;i<=n;i++){
        int a, b;
        scanf("%d%d", &a, &b);
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs_down(1, 0);
    for(int i=1;i<=n;i++){
        if(i != 1) dfs_up(i, 0);
        printf("%lld\n", dp[i][0]);
    }
}


Measured memory_bytes: 61824
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int A, B, M;
	cin >> A >> B >> M;
	vector<int> a(A), b(B), x(M), y(M), c(M);
	int a_min = 1000000;
	int b_min = 1000000;
	REP(i, A) {
		cin >> a[i];
		a_min = min(a_min, a[i]);
	}
	REP(i, B) {
		cin >> b[i];
		b_min = min(b_min, b[i]);
	}
	int res = a_min + b_min;
	REP(i, M) {
		cin >> x[i] >> y[i] >> c[i];
		res = min(res, a[x[i] - 1] + b[y[i] - 1] - c[i]);
	}
	
	cout << res << endl;
	
	return 0;
}

						

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  map<string, int> S;
  REP(i, N){
    string s; cin >> s;
    S[s]++;
  }
  cout << S.size() << endl;
}

Measured memory_bytes: 19216
#include<iostream>
#include<algorithm>
#include<climits>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
int n;
int a[100010];
int main(){
  scan(n);
  rep(i,n){
    scan(a[i]);
  }
  map<int,int> mp;
  rep(i,n){
    mp[a[i]]++;
    mp[a[i]-1]++;
    mp[a[i]+1]++;
  }
  int res=0;
  for(auto ite=mp.begin();ite!=mp.end();ite++){
    res=max(res,ite->second);
  }
  prin(res);
  
  
  
  return 0;
}


Measured memory_bytes: 5120
using System;
    using System.Linq;
    using System.Collections.Generic;
     
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int cake_max = N / 4;
            string output = "No";

            for(int i=0; i<=cake_max; i++){
                if((N-i*4)%7==0) output = "Yes";
            }

            Console.WriteLine(output);
        }
    }

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


using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define FOR(i,m,n) for(ll i=ll(m); i<ll(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;



int main() {



	int n;
	cin >> n;

	VLL a(n);
	REP(i, n)cin >> a[i];

	if (n <= 3) {
		sort(ALL(a));
		reverse(ALL(a));
		cout << a[0] << endl;
		return 0;
	}

	if (n % 2 == 0) {
		VVLL dp(n, VLL(2, 0));
		dp[0][0] = a[0];
		dp[1][1] = a[1];
		FOR(i, 2, n) {
			if (i % 2 == 0)dp[i][0] = dp[i - 2][0] + a[i];
			else {
				dp[i][1] = max(dp[i - 2][1], dp[i - 3][0]) + a[i];
			}
			
		}
		cout << max(dp[n - 1][1], dp[n - 2][0]) << endl;
		return 0;
	}

	VVLL dp(n, VLL(4, -INFL));
	dp[0][0] = a[0];
	dp[1][1] = a[1];
	dp[2][2] = a[2];
	dp[2][0] = dp[0][0] + a[2];
	FOR(i, 3, n) {

		if (i % 2 == 0) {
			dp[i][0] = dp[i - 2][0] + a[i];
			dp[i][2] = max({ dp[i - 2][2],dp[i - 3][1],dp[i - 4][0] }) + a[i];
		}
		else {
			dp[i][1] = max(dp[i - 2][1], dp[i - 3][0]) + a[i];
		}
	}
	ll ans = max({ dp[n - 1][2],dp[n - 2][1],dp[n - 3][0]});

	VVLL dq(n + 100, VLL(3, -INFL));
	dq[0][0] = a[0];
	FOR(i,1, n) {
		if (i % 2 == 0)dq[i][0] = dq[i - 2][0] + a[i];
	}

	dq[3][1] = a[0] + a[3];
	
	FOR(i, 5, n) {
		if (i % 2 == 1) {
			dq[i][1] = max(dq[i - 2][1], dq[i - 3][0]) + a[i];
		}
		else {
			if (i < 6)continue;
			dq[i][2] = max(dq[i - 2][2], dq[i - 3][1]) + a[i];
		}
	}

	ans = max(ans, dq[n - 1][2]);
	ans = max(ans, dq[n - 2][1]);

	cout << ans << endl;
}

Measured memory_bytes: 29920
N, X = gets.split.map(&:to_i)

LAYER = Hash.new do |h, i|
  h[i] = h[i - 1] * 2 + 3
end
LAYER[0] = 1

def calc(level, i)
  return 1 if level == 0
  full = LAYER[level]
  center = full / 2 + 1
  if i <= 1
    0
  elsif i < center
    calc(level - 1, i - 1)
  elsif i == center 
    calc(level - 1, center - 2) + 1
  elsif i < full
    calc(level - 1, center - 2) + 1 + calc(level - 1, i - center) 
  else  
    calc(level - 1, center - 2) * 2 + 1
  end
end

puts calc(N, X)

Measured memory_bytes: 3964
#include<stdio.h>

int H[500001],n;

void MaxHeapify(int pos){
	int L=pos*2, R=pos*2+1,largest,tmp;

	if(L<=n && H[L]>H[pos])largest=L;
	else largest=pos;

	if(R<=n && H[R]>H[largest])largest=R;

	if(largest!=pos){
		//swap
		tmp=H[pos];
		H[pos]=H[largest];
		H[largest]=tmp;

		MaxHeapify(largest);
	}

	return;
}

int main(){
	int i;	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&H[i]);

	for(i=n/2;i>0;i--)MaxHeapify(i);
	for(i=1;i<=n;i++){
		printf(" %d",H[i]);
	}printf("\n");


	return 0;
}



Measured memory_bytes: 3656