akhauriyash/Code-Regression huggingface dataset:
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n+1) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
  
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n+1);
	vector<vector<pii> > x(n+1);
	reps(i,n){
		cin >> a[i];
		x[i].resize(a[i]+1);
		reps(j,a[i]){
			cin >> x[i][j].first >> x[i][j].second;
		}
	}
	int maxv = 0;
	for(int bit = 0;bit < (1 << n);++bit){
		vector<bool> jd(n+1);
		rep(i,n){
			if(bit & (1 << i)){
				jd[i+1] = true;
			}
		}
		bool flg = false;
		reps(i,n){
			if(bit & (1 << (i-1))){
				reps(j,a[i]){
					int pos = x[i][j].first;
					bool s = x[i][j].second;
					if(jd[pos] != s){
						flg = true;
						break;
					}
					else jd[pos] = s;
				}
			}
			if(flg) break;
		}
		if(!flg){
			chmax(maxv,__builtin_popcount(bit));
		}
	}

	cout << maxv << '\n';


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

bool dfs(int &m, int &n, VI &a, VI &b, int idx, int cnt) {
    /*
    cerr << idx << ", " << cnt << endl;
    REP(i,0,n) cerr << a[i] << " ";
    cerr << endl;
    REP(i,0,n) cerr << b[i] << " ";
    cerr << endl;
    */

    if (cnt > m) return false;
    if (idx == n) {
        return true;
    }
    REP(i,idx, n) {
        RREP(j,idx,i) {
            swap(a[j], b[j+1]);
            swap(b[j], a[j+1]);
        }
        bool isok = false;
        if (idx == 0 || a[idx] >= a[idx-1]) {
            bool bo = true;
            REP(j,idx+1,n) {
                if (a[idx] > max(a[j], b[j])) {
                    bo = false;
                    break;
                }
            }
            if (bo) {
                if (dfs(m,n,a,b,idx+1, cnt + i - idx)) {
                    isok = true;
                }
            }
        }
        REP(j,idx,i) {
            swap(a[j], b[j+1]);
            swap(b[j], a[j+1]);
        }
        if (isok) return true;
    }
    return false;
}

bool solve(int &m, int &n, VI &a, VI &b) {
    return dfs(m,n,a,b,0,0);
}

int meguru_bin(int &n, VI &a, VI &b) {
    int ok = (n * n - n) / 2 +1;
    int ng = -1;

    while (abs(ok - ng) > 1) {
        int mid = ng + (ok - ng) / 2;
        if (solve(mid,n,a,b)) ok = mid;
        else ng = mid;
    }

    return ok;
}

void solve() {
    int n;
    cin >> n;
    VI a(n), b(n);
    REP(i,0,n) cin >> a[i];
    REP(i,0,n) cin >> b[i];
    int ans = meguru_bin(n,a,b);
    
    cout << (ans == (n * n - n) / 2 +1 ? -1 : ans ) << endl;
}

signed main() {
    solve();
    
    return 0;
}

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

const int MAX_N = 100005;
int A[MAX_N];

int main()
{
	int N,K,Q;
	cin >> N >> K >> Q;
	int a;

	rep(i,MAX_N) A[i] = 0;

	rep(i,Q)
	{
		cin >> a;
		a--;
		A[a]++;
	}

	rep(i,N)
	{
		if (K - Q + A[i] > 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
import sys


class Paper(object):
    def __init__(self, x=None, y=None):
        if x == None:
            self.x = 10
        else:
            self.x = x
        if y == None:
            self.y = 10
        else:
            self.y = y
        t = [0] * self.x
        self.sheet = [t[:] for _ in range(self.y)]

    def drop_ink(self, ink):
        x, y, s = ink
        if s == 1:
            self.process_ink(x, y)
            self.process_ink(x+1, y)
            self.process_ink(x-1, y)
            self.process_ink(x, y+1)
            self.process_ink(x, y-1)
        elif s == 2:
            self.process_ink(x-1, y-1)
            self.process_ink(x, y-1)
            self.process_ink(x+1, y-1)
            self.process_ink(x-1, y)
            self.process_ink(x, y)
            self.process_ink(x+1, y)
            self.process_ink(x-1, y+1)
            self.process_ink(x, y+1)
            self.process_ink(x+1, y+1)
        elif s == 3:
            self.process_ink(x, y-2)
            self.process_ink(x-1, y-1)
            self.process_ink(x, y-1)
            self.process_ink(x+1, y-1)
            self.process_ink(x-2, y)
            self.process_ink(x-1, y)
            self.process_ink(x, y)
            self.process_ink(x+1, y)
            self.process_ink(x+2, y)
            self.process_ink(x-1, y+1)
            self.process_ink(x, y+1)
            self.process_ink(x+1, y+1)
            self.process_ink(x, y+2)

    def process_ink(self, x, y):
        if 0 <= x < self.x and 0 <= y < self.y:
            self.sheet[y][x] += 1

    def print_sheet(self):
        for row in self.sheet:
            print(row)


if __name__ == '__main__':
    ink_drops = []
    for line in sys.stdin:
        ink_drops.append([int(x) for x in line.strip().split(',')])

#    for line in sys.stdin:
#        try:
#            ink_drops.append([int(x) for x in line.strip().split(',')])
#        except ValueError:
#            break

    p = Paper(10, 10)
    for ink in ink_drops:
        p.drop_ink(ink)
        #p.print_sheet()
        #print('=' * 64)

    white_cell = 0
    max_ink = 0
    for r in p.sheet:
        white_cell += r.count(0)
        max_ink = max(max(r), max_ink)
    print(white_cell)
    print(max_ink)

Measured memory_bytes: 7732
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s;
	cin >> s;
	s.pop_back();
	while (1) {
		if (s.size() % 2) {
			s.pop_back();
		} else {
			if (s.substr(0, s.size() / 2) == s.substr(s.size() / 2, s.size() / 2)) {
				cout << s.size() << endl;
				return 0;
			} else {
				s.pop_back();
			}
		}
	}
	return 0;
}

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

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b&&b!=c)cout<<"Yes"<<endl;
  else if(a==c&&c!=b)cout<<"Yes"<<endl;
  else if(b==c&&c!=a)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main{

public static int bunkai(int n){
    int r = 0;
    int x = (int)Math.sqrt(n);
    for(int i=2; i<=x; i++){
        if(n % i == 0){
            r = i;
            break;
        }
    }

    if(r == 0){
        r = n;
    }

    return r;
}    

public static void main(String args[]){

    Scanner sc = new Scanner(System.in);
    String line = sc.nextLine();
    int n = Integer.parseInt(line);
    ArrayList<Integer> kotae = new ArrayList<>();

    int m = n;

    while(n != 1){
        kotae.add(bunkai(n));
        n = n / bunkai(n);
    }




    System.out.print(m + ": ");
    for(int i=0; i<kotae.size()-1; i++){
        System.out.print(kotae.get(i) + " ");

    }

    System.out.print(kotae.get(kotae.size()-1));
   System.out.println();
}

}

Measured memory_bytes: 26148
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n; cin>>n;
    vl as(n); cin>>as;

    priority_queue<LP> q;
    rep(i, n) q.push(LP(as[i], i));

    ll h = q.top().fi;
    ll cur = q.top().se;
    ll cnt = 0;
    map<ll, ll> mp;
    while (!q.empty()) {
        LP p = q.top(); q.pop();
        mp[cur] += cnt * (h - p.fi);
        cnt++;
        chmin(cur, p.se);
        h = p.fi;
    }
    mp[cur] += cnt * h;
    rep(i, n) cout<<mp[i]<<endl;
}

Measured memory_bytes: 11900
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, m, x;
  cin >> n >> m >> x;

  vector<int> cost(n);
  vector<vector<int>> a(n, vector<int>(m));
  rep(i, 0, n) {
    cin >> cost[i];
    rep(j, 0, m) { cin >> a[i][j]; }
  }

  ll ans = 1e18;
  rep(i, 0, 1 << n) {
    vector<ll> tmp(m, 0);
    ll sumcost = 0;
    rep(j, 0, n) {
      if (i >> j & 1) {
        sumcost += cost[j];
        rep(k, 0, m) { tmp[k] += a[j][k]; }
      }
    }

    bool flg = true;
    rep(j, 0, m) {
      if (tmp[j] < x) {
        flg = false;
        break;
      }
    }
    if (flg)
      chmin(ans, sumcost);
  }

  if (ans == 1e18)
    cout << -1 << endl;
  else
    cout << ans << endl;
}


Measured memory_bytes: 3592
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
    int H, A;
    
    cin >> H >> A;
    
    int answer = H / A;
    if ( H % A == 0)
        cout << answer << endl;
    else
        cout << answer + 1 << endl;
    return 0;
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

const int limit = 50;

int N, M;
vector<int> a(limit), b(limit);

vector<vector<bool>> graph(limit, vector<bool>(limit));
vector<bool> visited(limit);

void dfs(int v)
{
  visited[v] = true;
  for (int v2 = 0; v2 < N; v2++)
  {
    if (graph[v][v2] == false)
      continue;
    if (visited[v2] == true)
      continue;
    dfs(v2);
  }
}

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

  cin >> N >> M;

  for (int i = 0; i < M; i++)
  {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }

  int ans = 0;

  for (int i = 0; i < M; i++)
  {
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;

    for (int j = 0; j < N; j++)
      visited[j] = false;

    dfs(0);

    bool bridge = false;
    for (int j = 0; j < N; j++)
      if (visited[j] == false)
        bridge = true;
    if (bridge)
      ans++;

    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }

  cout << ans << endl;
  return 0;
}

// グラフ　橋検出アルゴリズム
// dfsによる連結判定
// 連結判定はdfsを用いて行う．連結判定をする際には全ての頂点を未訪問にしてから任意の1つの頂点からDFSを呼びます．そのあとに全ての頂点が訪問済みなら連結であり，そうでなければ非連結です．各辺をグラフから取り除いてグラフが連結であるか判定して非連結である場合を数え上げます．


Measured memory_bytes: 256
import java.util.Scanner;

 class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        String t = in.next();
        int count=0;
        for(int i=0;i<3;i++){
            if(s.charAt(i)==t.charAt(i))
                count++;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
//typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};

int main(){
  int N,M;  cin>>N>>M;
  vector<ll> h(N);
  vector<int> a(M), b(M);
  vector<vector<int> > v(N);
  rep(i,0,N) cin>>h[i];
  rep(i,0,M)cin>>a[i]>>b[i];
  rep(i,0,M){
    --a[i]; --b[i];
    v[a[i]].pb(b[i]);
    v[b[i]].pb(a[i]);
  }
  ll cnt=0;
  for(int i=0 ; i<N ; i++){
    bool ok=true;
    for(int j=0 ; j<v[i].size() ; j++){
      if(h[i]<=h[v[i][j]]) ok=false;
    }
    if(ok) cnt++;
  }
  
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 9804
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
using namespace std;
string S;
int main() {
	cin >> S;
	cout << S.substr(0, S.size() - 8) << endl;
	return 0;
}

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

int main(){
	string s;
	cin>>s;
	int n = s.size();
	for (int i = 0; i<s.size(); i++){
		if (s[i]!=s[s.size()-1-i]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	int fe = ((n-1)/2);
	for (int i = 0; i<fe; i++){
		if (s[i]!=s[fe-1-i]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	int se = ((n+3)/2)-1;
	for (int i = se; i<n; i++){
		if (s[i]!=s[n-i+se-1]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int n, m;
  scanf("%d%d", &n, &m);
  printf("%d\n", (n - 1) * (m - 1));

  return 0;
}


Measured memory_bytes: 128
import java.util.HashMap;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        long x=scan.nextLong();
        HashMap<Long,Long> results=new HashMap<>();
        for (long i = -120; i <=120 ; i++) {
            results.put(i*i*i*i*i,i);
        }

        for(Long num:results.keySet()){
            if (results.containsKey(x+num)){
                System.out.println(results.get(x+num)+" "+results.get(num));
                break;
            }
        }


    }
}

Measured memory_bytes: 38924
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//-------------------
constexpr int MX = 22;
int a[MX][MX];
vector<ll> dp(1<<21, -1);
int n;

ll dfs(ll state, int cur) {
    if(dp[state]!=-1) return dp[state];
    ll sm = 0;
    rep(i,n) {
        if(state & (1<<i) and a[cur][i]) {
            sm += dfs(state^(1<<i), cur+1);
            sm %= mod;
        }
    }
    return dp[state] = sm;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(15);
    cin >> n;
    rep(i,n) {
        rep(j,n) {
            cin >> a[i][j];
        }
    }
    dp[0] = 1;
    cout << dfs((1<<n)-1, 0) << endl;
    return 0;
}


Measured memory_bytes: 19484
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16000000")
using namespace std;

typedef long long ll;

const int Maxl = 26;
const int Maxn = 1000005;

struct trie {
    trie *ch[Maxl];
    int cnt[Maxl];
    trie() {
        for (int i = 0; i < Maxl; i++) {
            ch[i] = nullptr;
            cnt[i] = 0;
        }
    }
};

char tmp[Maxn];
trie *tr;
int n;
string S[Maxn];
int my[Maxn];
ll res;

void Read(string &s)
{
    scanf("%s", tmp);
    s = tmp;
}

void Add(trie *tr, int lvl, string &S, int my[])
{
    for (int i = 0; i < Maxl; i++)
        if (my[lvl] & 1 << i) tr->cnt[i]++;
    if (lvl == 0) return;
    int ind = S[lvl] - 'a';
    if (!tr->ch[ind]) tr->ch[ind] = new trie();
    Add(tr->ch[ind], lvl - 1, S, my);
}

int Get(trie *tr, int lvl, string &S)
{
    if (lvl == 0) return tr->cnt[S[0] - 'a'] - 1;
    else return Get(tr->ch[S[lvl] - 'a'], lvl - 1, S);
}

int main()
{
    scanf("%d", &n);
    tr = new trie();
    for (int i = 0; i < n; i++) {
        Read(S[i]);
        my[0] = 1 << (S[i][0] - 'a');
        for (int j = 1; j < S[i].length(); j++)
            my[j] = my[j - 1] | 1 << (S[i][j] - 'a');
        Add(tr, int(S[i].length()) - 1, S[i], my);
    }
    for (int i = 0; i < n; i++)
        res += Get(tr, int(S[i].length()) - 1, S[i]);
    cout << res << endl;
    return 0;
}


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

using namespace std;

typedef long long ll; // ll  is 64bit same as double

int main() {
	
	// make input and output more efficient
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	double a, b;
	int h, m;
	
	cin >> a >> b >> h >> m;
	
	cout << fixed << setprecision(20);
	
	double ha = (double)(90.0 - h * 30 - m/2.0) * M_PI / 180.0;
		
	double ma = (double)(90.0 - m * 6) * M_PI / 180.0;
		
	double dist = sqrt(pow(a*cos(ha) - b*cos(ma),2) + pow(a*sin(ha) - b*sin(ma),2));
		
	cout << dist << "\n";
	
	return 0;
}

Measured memory_bytes: 4088
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
# from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

x,n = MI()
p = RI()

m = INF
ans = INF
for i in range(-102,102):
    if i in p:
        pass
    else:
        sa = abs( x - i )
        if sa<m:
            ans = i
            m = sa
        elif sa==m:
            ans = min(i,ans)
        else:
            pass
print(ans)

Measured memory_bytes: 74388
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int N, M;
	cin >> N >> M;
	string S;
	cin >> S;

	int dp[100002] = {};
	int mae = 0;
	int kazu = 0;
	while (mae <= N) {
		int tugi = mae + M;
		chmin(tugi, N);
		kazu++;
		int saigo = mae;
		for (int i = mae + 1; i <= tugi; i++) {
			if (S[i] == '0') {
				dp[i] = kazu;
				saigo = i;
			}
		}
		if (mae == saigo) break;
		mae = saigo;
	}

	if (dp[N] == 0) {
		co(-1);
		return 0;
	}
	vector<int> kotae;
	for (int i = N; i > 0;) {
		int k = dp[i];
		for (int j = max(0, i - M); j <= i; j++) {
			if (dp[j] == k - 1) {
				kotae.pb(i - j);
				i = j;
				break;
			}
		}
	}

	for (auto itr = kotae.rbegin(); itr != kotae.rend(); itr++) {
		cosp(*itr);
	}

	Would you please return 0;
}

Measured memory_bytes: 1528
import sys
A, B = map(int, input().split())

count = 0

for i in range(A, B+1):
    num = []
    while i != 0:
        num.append(i%10)
        i = int(i/10)
    
    if num[0] == num[4] and num[1] == num[3]:
        count += 1


print(count)

Measured memory_bytes: 3060
/******************************************
* NICK : nikhilsinghh59 *
******************************************/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"

#define PB push_back
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
const int M = 1e9+7;

int main()
{   
    //#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    //freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    //freopen("output.txt", "w", stdout);
    //#endif

    ll n , base;
    cin >> n >> base;

    ll dig = (ll)(floor( log(n) /log(base)) + 1);
    cout << dig ;  
}

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

public class Main {
    public static void main(String[] args ) {
        Scanner scanner = new Scanner(System.in);
        HashSet<String> hash = new HashSet<String>();
        int n = scanner.nextInt();
        for(int i = 0; i < n; i++){
            String op = scanner.next();
            String word = scanner.next();
            if(op.equals("insert"))
                hash.add(word);
            else if(op.equals("find")){
                if(hash.contains(word))
                    System.out.println("yes");
                else
                    System.out.println("no");
            }
        }
    }
}



Measured memory_bytes: 252956
n = int(input())
a = list(map(int,input().split()))
cou = 1
ans = 0

for i in range(n):
    if a[i] == cou:
        cou += 1
    elif a[i] != cou:
        ans += 1

if ans == n:
    print("-1")
else:
    print(ans)

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

typedef long long ll;
const int maxn=600+10;
int n,d1,d2,cnt[3][3];
int x[maxn][maxn],y[maxn][maxn];
vector<pair<int,int> > g[maxn][maxn];

void dfs(int a,int b){
	for(int i=0;i<g[a][b].size();++i)
		if(!x[g[a][b][i].first][g[a][b][i].second]){
			x[g[a][b][i].first][g[a][b][i].second]=3-x[a][b];
			dfs(g[a][b][i].first,g[a][b][i].second);
		}
}
void dfss(int a,int b){
	for(int i=0;i<g[a][b].size();++i)
		if(!y[g[a][b][i].first][g[a][b][i].second]){
			y[g[a][b][i].first][g[a][b][i].second]=3-y[a][b];
			dfss(g[a][b][i].first,g[a][b][i].second);
		}
}

int main(){
	cin>>n>>d1>>d2;
	for(int x=0;x*x<=d1;++x){
		int y=round(sqrt(d1-x*x));
		if(y*y+x*x==d1)
			for(int i=1;i<=2*n;++i)
				for(int j=1;j<=2*n;++j){
					if(0<i-x&&i-x<=2*n&&j-y>0&&j-y<=2*n)
						g[i][j].push_back(make_pair(i-x,j-y));
					if(0<i+x&&i+x<=2*n&&j-y>0&&j-y<=2*n)
						g[i][j].push_back(make_pair(i+x,j-y));
					if(0<i-x&&i-x<=2*n&&j+y>0&&j+y<=2*n)
						g[i][j].push_back(make_pair(i-x,j+y));
					if(0<i+x&&i+x<=2*n&&j+y>0&&j+y<=2*n)
						g[i][j].push_back(make_pair(i+x,j+y));
				}
	}
	for(int i=1;i<=2*n;++i)for(int j=1;j<=2*n;++j)
		if(!x[i][j])
			x[i][j]=1,dfs(i,j);
	for(int i=1;i<=2*n;++i)
		for(int j=1;j<=2*n;++j)
			g[i][j].clear();
	for(int x=0;x*x<=d2;++x){
		int y=round(sqrt(d2-x*x));
		if(y*y+x*x==d2)
			for(int i=1;i<=2*n;++i)
				for(int j=1;j<=2*n;++j){
					if(0<i-x&&i-x<=2*n&&j-y>0&&j-y<=2*n)
						g[i][j].push_back(make_pair(i-x,j-y));
					if(0<i+x&&i+x<=2*n&&j-y>0&&j-y<=2*n)
						g[i][j].push_back(make_pair(i+x,j-y));
					if(0<i-x&&i-x<=2*n&&j+y>0&&j+y<=2*n)
						g[i][j].push_back(make_pair(i-x,j+y));
					if(0<i+x&&i+x<=2*n&&j+y>0&&j+y<=2*n)
						g[i][j].push_back(make_pair(i+x,j+y));
				}
	}
	for(int i=1;i<=2*n;++i)for(int j=1;j<=2*n;++j)
		if(!y[i][j])
			y[i][j]=1,dfss(i,j);
	for(int i=1;i<=2*n;++i)
		for(int j=1;j<=2*n;++j)
			++cnt[x[i][j]][y[i][j]];
	for(int a=1;a<=2;++a)for(int b=1;b<=2;++b)
		if(cnt[a][b]>=n*n){
			int xxx=n*n;
			for(int i=1;i<=2*n;++i)
				for(int j=1;j<=2*n;++j)
					if(x[i][j]==a&&y[i][j]==b&&xxx){
						printf("%d %d\n",i-1,j-1);
						--xxx;
					}
			return 0;
		}
	return 0;
}


Measured memory_bytes: 122496
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define show(x) cout<<x<<'\n'
#define showh(x) cout<<x<<' '
#define go(i,a,n) for(ll i=a;i<n;i++)
#define gor(i,a,n) for(ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
bool prime[1000001];
bool isperfectsquare(ld x)
{
    return (ceil(sqrt(x))==floor(sqrt(x)));
}
bool ispoweroftwo(ll x)
{
    return x && !(x & (x-1));
}
ll xorcal(ll n)
{
    if(n%4==0)
        return n;
    if(n%4==1)
        return 1;
    if(n%4==2)
        return n+1;
    if(n%4==3)
        return 0;
}
void sieve(ll n)
{
    memset(prime,true,sizeof(prime));
    prime[0]=false;
    prime[1]=false;
    for(ll i=2;i*i<=n;i++)
    {
        if(prime[i]==true)
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                prime[j]=false;
            }
        }
    }
}
bool isprime(ll n)
{
    if (n<=1) return false;
    if (n<=3) return true;

    if(n%2==0 or n%3==0) return false;

    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0 or n%(i+2)==0) return false;
    }
    return true;
}

ll modinverse(ll a,ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m; a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
       x += m0;

    return x;
}

ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    return gcd(b%a,a);
}
ll power(ll A, ll B)
{
    if (A == 0)
        return 0;
    if (B == 0)
        return 1;

    ll y;
    if (B % 2 == 0) {
        y = power(A, B / 2);
        y = (y * y) % mod;
    }

    else {
        y = A % mod;
        y = (y * power(A, B - 1) % mod) % mod;
    }

    return (ll)((y + mod) % mod);
}
bool cmp(pair<ll,ll>&a,pair<ll,ll>b)
{
    return a.second < b.second;
}
int main()
{
    ios_base::sync_with_stdio(false);
    ll a,b,n,sum=0;
    vector<pair<ll,ll>>v;
    cin>>n;
    ll flag=0;
    go(i,0,n)
    {
        cin>>a>>b;
        if(a>b)
        {
            flag=1;
        }
        v.pb(mp(a,b));
        sum+=a;
    }
    if(flag)
    {
        show("No");
        exit(0);
    }
    sort(v.begin(),v.end(),cmp);
    ll t=0;
    go(i,0,n)
    {
        t+=v[i].first;
        if(t>v[i].second)
        {
            flag=1;
            break;
        }
    }
    if(flag)
    {
        show("No");
    }
    else
    {
        show("Yes");
    }
    return 0;
}


Measured memory_bytes: 6512
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(){
    int i;
    int cnt=0;
    char t1[1510];
    char t2[1510];
    
    scanf("%s",t1);
    for(i=0;i<strlen(t1);i++){
        t1[i]=tolower(t1[i]);
    }
    while(scanf("%s",t2)){
        if(strcmp(t2,"END_OF_TEXT")==0) break;
        for(i=0;i<strlen(t2);i++){
            t2[i]=tolower(t2[i]);
        }
        if(strcmp(t1,t2)==0) cnt++;
    }
    
    printf("%d\n",cnt);
    
    return 0;
}


Measured memory_bytes: 2044
#include <algorithm>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <numeric>

using namespace std;

int main(void)
{
	int n;
	cin >> n;
	int sum = 0;
	int sum_of_squares = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		sum += a;
		sum_of_squares += a*a;
	}
	int x = round((double)sum/n);
	cout << n * x*x -2*sum*x + sum_of_squares << endl;
	return 0;
}


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

int main(){
    int L,R,d;
    cin>>L>>R>>d;
    int ans=0;
    for(int i=L; i<R+1; i++){
        if(i%d==0)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef vector<int> vi;

int n;
vi eratosthenes_sieve(int n){
	vi res(n+1);
	if(n<2) return res;
	res[2]=1;
	for(int i=3;i<=n;i+=2){
		if(i*i<=n && !res[i]) for(int j=i+i+i;j<=n;j+=i+i) res[j]=1;
		res[i]=!res[i];
	}
	return res;
}
vi prime_list(const vi& isprime){
	vi res;if(isprime.size()<=2)return res;
	res.push_back(2);
	for(unsigned int i=3;i<isprime.size();i+=2)
		if(isprime[i])res.push_back(i);
	return res;
}
vi prime_list(int n){
	return prime_list(eratosthenes_sieve(n));
}

main(){
	vi pl = prime_list(1000000);
	while(cin >> n) cout << (upper_bound(pl.begin(), pl.end(), n) - pl.begin()) << endl;
	return 0;
}

Measured memory_bytes: 5500
import java.util.*;
public class Main{
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    int e = sc.nextInt();
    int mindex = 0;
    int sum = 0;
    int[] alist = {a,b,c,d,e};
	int slist[] = new int[5];
    
    for(int i = 0;i < 5;i++){
            if(alist[mindex] % 10 > alist[i] % 10 && alist[i] % 10 != 0 || alist[mindex] % 10 == 0){
              mindex = i;
            }
    }
    
    for(int i = 0;i < 5;i++){
      if(i == mindex || alist[i] % 10 == 0){
        sum+= alist[i];
      }else{
       	sum+= alist[i] / 10 * 10 +10; 
      }
    }
    
    System.out.println(sum);
  }
}

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

int main()
{
    int N, R;
    cin >> N >> R;

    int rate;
    if (N < 10)
    {
        rate = R + 100 * (10 - N);
    }
    else
    {
        rate = R;
    }
    cout << rate << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
int main() {
  string S;
  cin>>S;
  int a,b,i,N;
  N=S.length();
  a=0;
  b=0;
  for(i=0;i<N;i++){
  if(S[i]=='0'){
  a++;
  }else{
  b++;
  }
   
  }
  a=min(a,b);
  cout<<a*2<<endl;
    
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int main(){
	int n;
	cin>>n;
	vector<vector<int>> adj(n);
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--,b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	vector<int> c(n);
	rep(i,n) cin>>c[i];
	sort(all(c), greater<int>());

	const int root=0;
	int max_sum=0,idx=0;
	vector<int> max_w(n,-1);
	queue<int> que;
	que.push(root);
	max_w[root]=c[idx++];

	while(!que.empty()){
		int cur=que.front();que.pop();
		for(auto u : adj[cur]){
			if(max_w[u]!=-1) continue;
			max_w[u]=c[idx++];
			max_sum+=min(max_w[cur],max_w[u]);
			que.push(u);
		}
	}
	cout<<max_sum<<endl;
	rep(i,n) cout<<max_w[i]<<" ";

}

Measured memory_bytes: 1024
using System;
using System.Linq;

namespace _2100
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                int a = int.Parse(Console.ReadLine());
                int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                int min = 0;
                int max = 0;
                for (int j = 1; j < a; j++)
                {
                    int now = x[j] - x[j - 1];
                    max = Math.Max(max, now);
                    min = Math.Min(min, now);
                }
                Console.WriteLine(max + " " + min * -1);
            }
        }
    }
}

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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  int n,K;
  cin >> n >> K;
  VI h(n);
  rep(i,n){
    cin >> h[i];
  }
  VLL dp(n+1,1e12);

  dp[0] = 0;
  rep(i,n){
    FOR(j,1,K+1){
      if(i+j < n) dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]));
    }
  }
  cout << dp[n-1] << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=LLONG_MAX;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl



int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N,K;
	cin >> N >> K;
	vector<ll> x(N),y(N);
	FOR(i,0,N){
		cin >> x[i] >> y[i];
	}
	ll ans = INF;
	FOR(i,0,N){
		FOR(j,0,N){
			FOR(k,0,N){
				FOR(l,0,N){
					ll yu,yd,xr,xl;
					yu = max( {y[i],y[j],y[k],y[l]} );
					yd = min( {y[i],y[j],y[k],y[l]} );
					xr = max( {x[i],x[j],x[k],x[l]} );
					xl = min( {x[i],x[j],x[k],x[l]} );
					if((xr-xl)*(yu-yd)==0)continue;
					ll n = 0;
					FOR(m,0,N){
						if(xl<=x[m] && x[m]<=xr)
							if(yd<=y[m] && y[m]<=yu)
								n++;
						if(n>=K)
							ans = min(ans,(xr-xl)*(yu-yd));
					}
				}
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll l, r;
    int ans;
    cin >> l >> r;
    if (r - l + 1 >= 2019) {
      ans = 0;
    } else {
      ans = 2020;
      FOR(i, l, r + 1) {
        FOR(j, i + 1, r + 1) {
          int tmp = (i % 2019) * (j % 2019);
          ans = min(ans, tmp % 2019);
        }
      }
    }

    cout << ans << '\n';

    return 0;
}


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

using namespace std;

#define rep(i, s, n) for(int i = s;i<n;i++)
#define repe(i, s, n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<int> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
static const ll maxLL = (ll) 1 << 62;
const ll MOD = 1000000007, INF = 1e18;
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, 1, 0, -1};

template<typename T1, typename T2>
bool pairCompare(const pair<T1, T2> &firstElof, const pair<T1, T2> &secondElof) {
    return firstElof.second > secondElof.second;
}

int mapMaxValue(std::map<ll, int> m) {
    int max = 0;
    for (std::map<ll, int>::iterator it = m.begin(); it != m.end(); it++) {
        if (max < it->second) max = it->second;
    }
    return max;
}

int main(void) {
    string s, t;
    cin >> s >> t;
    vector<string> keys;
    vector<string> replaced_keys;
    int s_length = s.length();
    int t_length = t.length();
    for (int i = 0; i < s_length; ++i) {
        string s_copy = s;
        bool is_match = true;
        for (int j = 0; j < t_length; ++j) {
            if (i + j < s_length) {
                if ((s_copy[i + j] != t[j]) && (s_copy[i + j] != '?')) {
                    is_match = false;
                }

                if (is_match && j == t_length - 1) {
                    s_copy.replace(i, t_length, t);
                    keys.push_back(s_copy);
                    break;
                }
            }
        }
    }

    for (auto k : keys) {
        replace(k.begin(), k.end(), '?', 'a');
        replaced_keys.push_back(k);
    }

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

    if (replaced_keys.size()) {
        cout << replaced_keys[0] << endl;
    } else {
        cout << "UNRESTORABLE" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include<math.h>
#include<algorithm>

using namespace std;

int main(void)
{
	int A, B;
	cin >> A >> B;
	if (A == B){
		cout << A + B << endl;
	}
	else{
		cout << max(A, B) + max(A - 1, B - 1) << endl;
	}
}

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

typedef long long LL;
typedef unsigned long long ULL;

#define debug printf("fuck %d\n", __LINE__);

inline LL read() {
	LL res = 0, bo = 1; char ch = getchar();
	while(ch < '0' || ch > '9') { if (ch == '-') bo = -1; ch = getchar(); }
	while(ch >= '0' && ch <= '9') { res = (res << 1) + (res << 3) + ch - '0'; ch = getchar(); }
	return bo * res;
}

template<typename T> void read(T &x) { x = read(); }
template<typename T, typename ...Argv> void read(T &a, Argv &...argv) { read(a); read(argv...); }

const int N = 3e5 + 100;
int a[N], sum[N], n, s[2];

bool check(int mid) { // 删掉几个偶数点，使得剩下极长连续子序列的收益 >= mid
	int Min = 0;
	for (int i = 2; i <= n; ++ i) {
		if (sum[i - 1] - Min >= mid) { // i - 1 为右端点 Min 所对应的点位 l - 1;
			Min = std::min(Min, sum[i]); // 由于是验证可行性所以保留前缀和最小的点即可
		}
	}
	return sum[n] - Min >= mid;
}

int main() {
	read(n);
	for (int i = 1; i <= n; ++ i) s[i & 1] += (a[i] = read()), sum[i] = sum[i - 1] + (i & 1 ? a[i] : -a[i]); 
	if (!(n & 1)) {
		std::cout << std::max(s[0], s[1]) << ' ' << std::min(s[0], s[1]) << std::endl;
		return 0;
	}
	int l = 0, r = s[0] + s[1], ans = 0;
	while (l <= r) {
		int mid = (l + r) >> 1;
		if (check(mid)) l = mid + 1, ans = mid;
		else r = mid - 1;
	}
	ans += s[0];
	std::cout << ans << ' ' << s[0] + s[1] - ans << std::endl;
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
static const int MAX = 1001;
int L[MAX][MAX];

int LCS(string s1, string s2)
{
    int m = s1.size();
    int n = s2.size();
    for (int i = 0; i <= m; ++i)
    {
        L[i][0] = 0;
    }
    for (int i = 0; i <= n; ++i)
    {
        L[0][i] = 0;
    }
    for (int i = 1; i <= m; ++i)
    {
        for (int j = 1; j <= n; ++j)
        {
            if (s1[i-1] == s2[j-1])
            {
                L[i][j] = L[i-1][j-1] + 1;
            }
            else
            {
                L[i][j] = max(L[i-1][j], L[i][j-1]);
            }
        }
    }
    return L[m][n];
}

int main()
{
    string s1, s2;
    int n;
    cin >> n;
    for (int i = 0; i != n; ++i)
    {
        cin >> s1 >> s2;
        cout << LCS(s1, s2) << endl;
    }
    return 0;
}


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

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

int main() {
    int answer_w = 0;
    int answer_b = 0;
    string S;
    cin >> S;
    REP(i,S.size()) {
        if (i%2 == 1) {
            if (S[i] == '0') {
                answer_w++;
            } else {
                answer_b++;
            }
        } else {
            if (S[i] == '0') {
                answer_b++;
            } else {
                answer_w++;
            }
        }

    }

    cout << min(answer_b, answer_w) << endl;

}





Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(long long i=(long long)(a);i<(long long)(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 all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
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<Pll> vPll;
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;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int n, k, ans=0;

	cin>>n>>k;

	repr(i, 1, n+1){
		if(i+k-1<=n) ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int k=1e18;
int main()
{
int n;
  cin>>n;
  
  long long arr[n];
  long long ans=1;
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  int count=0;
  for(int i=0;i<n;i++)
  {
      if(arr[i]==0)
      count++;
  }
  if(count>0)
  {
      cout<<0;
      return 0;
  }
  for(int i=0;i<n;i++)
  {
 
    if(arr[i]<= ((long long)1e18)/ans)
    {
      ans*=arr[i];
    }
    else
    {
        
        cout<<-1;
        return 0;
    }
  }
 cout<<ans;
  
}


Measured memory_bytes: 4400