akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
long long n, v, mx1, mx2, x1, x2;
vector<long long> cnt1(1000000), cnt2(1000000);
void solve() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> v;
        if (i % 2 == 0) {
            cnt1[v]++;
            if (cnt1[v] > mx1) {
                mx1 = cnt1[v];
                x1 = v;
            }
        } else {
            cnt2[v]++;
            if (cnt2[v] > mx2) {
                mx2 = cnt2[v];
                x2 = v;
            }
       }
    }
    sort(cnt1.begin(), cnt1.end());
    sort(cnt2.begin(), cnt2.end());
    if (x1 != x2) {
        cout << n - mx1 - mx2 << endl;
    } else {
        cout << n - max(mx1 + cnt2[cnt2.size() - 2], mx2 + cnt1[cnt1.size() -2]) << endl;
    }
    return;
}
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(int args, char* argv[]) {
    solve();
}

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

using namespace std;

using int64 = long long;
//const int mod = 1e9 + 7;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


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

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
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);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int H, W, K;
  cin >> H >> W >> K;
  auto S = make_v< string >(H);
  cin >> S;
  int ret = inf;
  for(int i = 0; i < (1 << H); i++) {
    vector< int > sum(H);
    int cnt = 0;
    for(int j = 0; j < H; j++) {
      if((i >> j) & 1) ++cnt;
    }
    for(int j = 0; j < W; j++) {
      int last = 0;
      for(int k = 0; k < H; k++) {
        if((i >> k) & 1) last = k;
        sum[last] += S[k][j] == '1';
      }
      bool flag = false;
      for(int k = 0; k < H; k++) {
        if(sum[k] > K) flag = true;
      }
      if(flag) {
        for(int k = 0; k < H; k++) {
          sum[k] = 0;
        }
        ++cnt;
        last = 0;
        for(int k = 0; k < H; k++) {
          if((i >> k) & 1) last = k;
          sum[last] += S[k][j] == '1';
        }
        flag = false;
        for(int k = 0; k < H; k++) {
          if(sum[k] > K) flag = true;
        }
        if(flag) goto foo;
      }
    }
    chmin(ret, cnt);
    foo:;
  }

  cout << ret << endl;

}

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

int H,W;

char chess (int h, int w){
    if (h==1 ||h==H ||w==1 ||w==W){
        return '#';
    }
   return '.' ;

}
        
int main(void){
    while(true){
        cin >> H >> W;
        if (H==0 && W==0){
            break;
        }

        for (int i=1;i<=H;i++){
            for(int j=1;j<=W;j++){
                cout << chess(i,j);
            }
            cout << endl;
        }
        cout << endl;
    }
    
    // Your code here!
    
}


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


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

  set<int> s;
  REP (i, n) {
    int a;
    cin >> a;

    if (s.find(a) == s.end()) s.insert(a);
  }

  cout << (s.size() - (1 - s.size() % 2)) << endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
int main() {
    string S;
    cin>>S;
    bool c=false;
    sort(S.begin(),S.end());
    int a=S.size();
    rep(i,a){
        if(S[i]==S[i+1]){
            c=true;
        }
    }
    if(c==true){
        cout<<"no"<<endl;
    }
    else
    {
        cout<<"yes"<<endl;
    }
}


Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <utility>
#include <algorithm>
#include <map>
#include <cassert>
using namespace std;
#define REPP(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,a) for(int i = 0; i < (a); ++i)
#define PER(i,a) for(int i = (a) - 1; i >= 0; --i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair

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

const int maxn = 1e5 + 5;
vector<int> g[maxn];
int dp[maxn];
bool vis[maxn];

int dfs(int u) {
    if (vis[u]) return dp[u];
    vis[u] = true;
    int depth = 0;
    for (int v : g[u]) {
        depth = max(depth, 1 + dfs(v));
    }
    dp[u] = depth;
    return depth;
}

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    int x, y;
    REP(i, m) {
        scanf("%d%d", &x, &y);
        g[x].push_back(y);
    }
    int ans = 0;
    REPP(i, 1, n + 1) ans = max(ans, dfs(i));
    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

ll n, w;
ll dp[100+9][100000+9], maksio=-1;
vector<pair<ll, ll>>a;


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>w;
    a.resize(n);
    //for(int i=0; i<=n; i++) fill(dp[i]+1, dp[i]+w+1, -1);
    for(int i=0; i<n; i++) cin>>a[i].second>>a[i].first;
    //sort(a.begin(), a.end());
    for(int i=1; i<=n; i++)
    {
        ll v=a[i-1].first, m=a[i-1].second;
        for(int j=0; j<m; j++) dp[i][j]=dp[i-1][j];
        for(int j=w; j>=m; j--)
        {
            dp[i][j]=max(dp[i-1][j], dp[i-1][j-m]+v);
            maksio=max(dp[i][j], maksio);
        }
    }
    //for(int i=0; i<=w; i++) maksio=max(maksio, dp[n][i]);
    for(int i=0; 0&&i<=n; i++)
    {
        for(int j=0; j<=w; j++) cout<<dp[i][j]<<" ";
        cout<<endl;
    }
    cout<<maksio<<endl;
    return 0;
}


Measured memory_bytes: 79360
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
ll MOD = 1000000007;
ll INF = 214748364700000000;
double EPS = 1e-12;
double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

ll cnt = 0;

int main(){
   ll N,C;cin >> N >> C;
   vector<ll> X(N),V(N),R(N+1,0),L(N+1,0),reR(N+1,0),reL(N+1,0),maxR(N+1,0),maxL(N+1,0);
   rep(i,N){
       cin >> X[i] >> V[i];
       R[i+1] = R[i] + V[i] - X[i];
       reR[i+1] = reR[i] + V[i] - 2 * X[i];
       if(i != 0){
           R[i+1] += X[i-1];
           reR[i+1] += X[i-1] * 2;
       }
       maxR[i+1] = max(maxR[i],reR[i+1]);
   }
   rrep(i,N){
       L[N-i] = L[N-i-1] + V[i] - (C-X[i]);
       reL[N-i] = reL[N-i-1] + V[i] - (C-X[i])*2;
       if(i != N-1){
           L[N-i] += (C-X[i+1]);
           reL[N-i] += (C-X[i+1])*2;
       }
       maxL[N-i] = max(maxL[N-i-1],reL[N-i]);
   }
   ll ans = 0;
   rep(i,N+1){
       //cout << i << ' ' << N-i << endl;
       ans = max(ans,R[i] + maxL[N-i]);
       ans = max(ans,L[i] + maxR[N-i]);
   }
   cout << ans << endl;
}

Measured memory_bytes: 6528
#include<stdio.h>

int main(void)
{

  int A,B,C,D;
  
  scanf("%d %d %d %d",&A,&B,&C,&D);
  
  while(C>0&&A>0)
  {
  	C = C-B;
    A = A-D;
  }
    
  if(C<=0)
  {
  printf("Yes");
  }else{
  	printf("No");
  }
  
  return 0;

}

Measured memory_bytes: 1736
#include <iostream>

typedef long long ll;

ll N, A, B, C;
ll INF = 1LL << 60;
ll trees[8];

ll rec(ll i, ll a, ll b, ll c) {
  if (i == N) {
    if (a == 0 || b == 0 || c == 0) {
      return INF;
    } else {
      return abs(A - a) + abs(B - b) + abs(C - c);
    }
  }

  long long cost = INF;

  // i番目の木を採用しない
  cost = std::min(cost,rec(i + 1, a, b, c));
  // i番目の木をAを構成する木として使う
  cost = std::min(cost, rec(i + 1, a + trees[i], b, c) + (a == 0 ? 0 : 10));
  // i番目の木をBを構成する木として使う
  cost = std::min(cost, rec(i + 1, a, b + trees[i], c) + (b == 0 ? 0 : 10));
  // i番目の木をCを構成する木として使う
  cost = std::min(cost, rec(i + 1, a, b, c + trees[i]) + (c == 0 ? 0 : 10));

  return cost;
};

int main() {
  std::cin >> N >> A >> B >> C;

  for (ll i = 0; i < N; i++) {
    std::cin >> trees[i];
  }

  ll ans = rec(0, 0, 0, 0);

  std::cout << ans << std::endl;
}

Measured memory_bytes: 256
/* CODED WITH ❤️ by Sidharth Anand aka sidanand6 */

#include "bits/stdc++.h"
#define mod 1000000007
typedef long long ll;
typedef std::vector<int> vi;
using namespace std;

int main() {
	ios::sync_with_stdio(0);	
	cin.tie(0);
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif	

    //start coding from here
    string input;
    cin>> input;
    int n = input.size();
    if (input[n-1] == 's') {
    	input += "es";
    }
    else {
    	input += 's';
    }
    cout<< input;
	return 0;
}


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

int x;
long long cont;

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>x;
    while(x>=5){
        if(x>=500){
            x-=500;
            cont+=1000;
            continue;
        }
        if(x>=5){
            x-=5;
            cont+=5;
        }
    }
    cout<<cont;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	if (nextInt()*nextInt())%2 == 0 {
		fmt.Println("Even")
	} else {
		fmt.Println("Odd")
	}
}


Measured memory_bytes: 640
# coding: utf-8
# Your code here!

N,L=map(int, input().split()) 

al_te = []
for i in range(N):
    T = L + (i+1) -1
    al_te.append(T)
#print(al_te)

ab_te = []
for i in range(N):
    T = L + (i+1) -1
    ab_te.append(abs(T))
#print(ab_te)
x = ab_te.index(min(ab_te))
#print(x)

al_te.pop(x)
print(sum(al_te))

Measured memory_bytes: 3064
N, M = map(int, input().split())
X = [int(x) for x in input().split()]

if N >= M:
    print(0)
    quit()

X.sort()

dX = list()

for i in range(M - 1):
    dX.append(X[i + 1] - X[i])

dX.sort(reverse=True)

print(sum(dX) - sum([dX[i] for i in range(N - 1)]))


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

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

	long long int h, n, w = 0, wn, wd;
	long long int hs = (4 - 2 * N <= 0) ? N : (N / (4 - 2 * N));
	long long int he = N / 4;
	for (h = he + 1; h <= hs; ++h)
	{
		long long int ns = (4 * h - N - N * h <= 0) ? N * h : (N * h / (4 * h - N - N * h));
		long long int ne = (4 * h - N <= 0) ? N * h : (N * h / (4 * h - N));
		for (n = ne + 1; n <= ns; ++n)
		{
			wn = N * h * n;
			wd = 4 * h * n - N * n - N * h;

			if (wn % wd == 0)
			{
				w = wn / wd;
				break;
			}
		}
		if (0 != w) break;
	}

	cout << h << " " << n << " " << w << endl;
	return 0;
}

Measured memory_bytes: 256
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    unused_imports,
    dead_code
)]
//use permutohedron::LexicalPermutation as _;
use proconio::{fastout, input, marker::*};
//use std::collections::HashSet;
use std::collections::*;
//use std::collections::BTreeMap;
//use std::cmp::*;
//use std::num;
//use petgraph::unionfind::UnionFind;

#[fastout()]
fn main() {
    input! {
        N:usize, mut S:[String;N]
    }
    S.sort();
    //println!("{:?}", S);
    let mut m = HashMap::new();
    //let S: Vec<String> = S.iter().map(|s| s.iter().collect::<String>()).collect();
    let mut max = 0;
    for i in 0..N {
        *m.entry(S[i].clone()).or_insert(0) += 1;
        max = std::cmp::max(max, *m.get(&S[i]).unwrap());
    }

    let mut before = "".to_string();
    for s in S {
        if before != s && *m.get(&s).unwrap() == max {
            println!("{}", s);
        }
        before = s;
    }
}


Measured memory_bytes: 31660
#include <stdio.h>
#include <string.h>
#define N 20

int aa[N], xx[N][N - 1], yy[N][N - 1];
char honest[N];
int n, i, j, b, ans;

int main() {
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &aa[i]);
		for (j = 0; j < aa[i]; j++)
			scanf("%d%d", &xx[i][j], &yy[i][j]), xx[i][j]--;
	}
	ans = -1;
	for (b = 0; b < 1 << n; b++) {
		int k;
 
		memset(honest, 0, n * sizeof *honest);
		for (i = 0; i < n; i++)
			if (b & 1 << i)
				honest[i] = 1;
		k = 0;
		for (i = 0; i < n; i++)
			if (honest[i]) {
				k++;
				for (j = 0; j < aa[i]; j++)
					if (honest[xx[i][j]] != yy[i][j])
						goto bad;
			}
		if (ans < k)
			ans = k;
bad:
		;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	bool prime[100001];
	rep(i,100001)prime[i]=true;
	prime[0]=prime[1]=false;
	loop(i,2,1000){
		for(int j=i*2;j<100001;j+=i){
			prime[j]=false;
		}
	}
	int n;
	while(cin>>n){
		int cnt=0;
		loop(i,1,n+1){
			if(prime[i] && prime[n-i+1])cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 1256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    string s; cin >> s;
    vector<bool> used(26, false);
    REP(i, s.length()){
        if(used[s[i] - 'a']){
            cout << "no\n";
            return 0;
        }
        used[s[i] - 'a'] = true;
    }
    cout << "yes\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int n,k,i,A[1005],j;
bool F[100005];
int main()
{
    cin >> n >> k;
    for (i = 1; i <= n; i ++)
    {
        cin >> A[i];
    }
    for (i = 1; i <= k; i++)
    {
        if (F[i]) continue;
        for (j = 1; j <= n; j++)
        {
            if (i-A[j] >= 0)
            {
                if (!F[i-A[j]]) F[i]=true;
            }
        }
    }
    if (F[k]) cout << "First"; else cout << "Second";
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
#define PI 3.14159265358979

//const int64_t INF = 1LL << 60;
const int INF = 1 << 29;
//const int64_t MOD = 1000000007;
//const int64_t INF = 998244353;
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; }
using namespace std;
//#define P pair<int, int>
typedef pair<int, int> P;

int main(){
    int N;
    cin >> N;
    vector<double> x(N), y(N);
    rep(i, 0, N) cin >> x.at(i) >> y.at(i);
    double sum = 0;
    rep(i, 0, N){
        rep(j, 0, N){
            sum += pow(pow(x.at(i) - x.at(j), 2) + pow(y.at(i) - y.at(j), 2), 0.5);
        }
    }
    sum /= (double)N;
    cout << fixed << setprecision(10) << sum << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
const int maxn=2005;
int a[maxn*3];
int n;
int dp[maxn][maxn],g[maxn][maxn];
int f[maxn];
vector<pair<int,int> > mem;
inline void upd(int i,int j,int x){
	g[i][j]=max(g[i][j],x);
	mem.push_back(make_pair(i,j));
	//f[i]=max(f[i],x);
	//f[j]=max(f[j],x);
}
int curmax=0;
inline void clermem(){
	for(int i=0;i<mem.size();i++){
		int u=mem[i].first,v=mem[i].second;
		dp[u][v]=max(g[u][v],dp[u][v]);
		curmax=max(curmax,dp[u][v]);
		f[u]=max(f[u],dp[u][v]);
		f[v]=max(f[v],dp[u][v]);
	}
	mem.clear();
}
int main(){
	//freopen("data.txt","r",stdin);
	cin>>n;
	for (int i=1;i<=n*3;i++){
		scanf("%d",&a[i]);
	}
	memset(dp,0xf3,sizeof(dp));
	memset(g,0xf3,sizeof(g));
	memset(f,0xf3,sizeof(f));
	dp[a[1]][a[2]]=dp[a[2]][a[1]]=0;
	g[a[1]][a[2]]=g[a[2]][a[1]]=0;
	f[a[1]]=f[a[2]]=0;
	int tag=0;
	for (int i=3;i+2<=n*3;i+=3){
		vector<int> cur;
		cur.push_back(a[i]);
		cur.push_back(a[i+1]);
		cur.push_back(a[i+2]);
		sort(cur.begin(),cur.end());
		if (a[i]==a[i+1]&&a[i+1]==a[i+2]){
			tag++;
			continue;
		}
		int a1,a2,a3;
		if (cur[0]==cur[1]){
			a1=cur[0],a2=cur[1];
			a3=cur[2];
		}
		else if (cur[1]==cur[2]){
			a1=cur[1],a2=cur[2];
			a3=cur[0];
		}
		else{
			a1=cur[0],a2=cur[1];
			a3=cur[2];
		}
		if (a1==a2){
			// case 1: 2
			for (int i=1;i<=n;i++){
				upd(i,a3,dp[a1][i]+1);
				upd(a3,i,dp[a1][i]+1);
			}
			// case 
		}
		for (int i=1;i<=n;i++){
			upd(i,a3,f[i]);
			upd(a3,i,f[i]);
		}
		for (int i=1;i<=n;i++){
			upd(i,a2,f[i]);
			upd(a2,i,f[i]);
		}
		for (int i=1;i<=n;i++){
			upd(i,a1,f[i]);
			upd(a1,i,f[i]);
		}
		upd(a1,a2,curmax);
		upd(a2,a1,curmax);
		upd(a1,a2,dp[a3][a3]+1);
		upd(a2,a1,dp[a3][a3]+1);
		upd(a2,a3,curmax);
		upd(a3,a2,curmax);
		upd(a2,a3,dp[a1][a1]+1);
		upd(a3,a2,dp[a1][a1]+1);
		upd(a1,a3,curmax);
		upd(a3,a1,curmax);
		upd(a1,a3,dp[a2][a2]+1);
		upd(a3,a1,dp[a2][a2]+1);
		clermem();
	}
	int ans=0;
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			if (i==j&&i==a[n*3]){
				ans=max(ans,dp[i][j]+tag+1);
			}
			else{
				ans=max(ans,dp[i][j]+tag);
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 35208
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int MAXN = 100010;
int x[MAXN], y[MAXN];
pair<int, int> xsorted[MAXN];
pair<int, int> ysorted[MAXN];
int par[MAXN];
int rnk[MAXN];
void makeset(int x){
    par[x] = x;
    rnk[x] = 1;
}
int get(int x){
    if(par[x] == x) return x;
    return (par[x] = get(par[x]));
}
void unite(int x, int y){
    int xr = get(x);
    int yr = get(y);
    if(xr == yr) return;
    if(rnk[xr] > rnk[yr]){
        par[yr] = xr;
        rnk[xr] += rnk[yr];
    } else {
        par[xr] = yr;
        rnk[yr] += rnk[xr];
    }
}
struct edge{
    int val, u, v;
    edge(){

    }
    edge(int _val, int _u, int _v){
        val = _val;
        u = _u;
        v = _v;
    }
    bool operator <(const edge &a) const{
        return val < a.val;
    }
};
int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> x[i]  >> y[i];
        xsorted[i] = {x[i], i};
        ysorted[i] = {y[i], i};
    }
    sort(xsorted + 1, xsorted + n + 1);
    sort(ysorted + 1, ysorted + n + 1);
    vector<edge> edges;
    for(int i = 1; i <= n - 1; i++){
        edge e;
        e.val = xsorted[i + 1].first - xsorted[i].first;
        e.u = xsorted[i + 1].second;
        e.v = xsorted[i].second;
        edges.push_back(e);
        e.val = ysorted[i + 1].first - ysorted[i].first;
        e.u = ysorted[i + 1].second;
        e.v = ysorted[i].second;
        edges.push_back(e);
    }
    sort(edges.begin(), edges.end());
    for(int i = 1; i <= n; i++) makeset(i);
    long long ans = 0;
    for(auto ed : edges){
        int ur = get(ed.u);
        int vr = get(ed.v);
        if(ur == vr) continue;
        ans += ed.val;
        unite(ur, vr);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7284
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in=new Scanner(System.in);
		while(in.hasNext())
		{
			char ch[]=in.nextLine().toCharArray();
			String str="";
			int j=0;
			for(int i=0;i<ch.length;i++)
			{
				if(ch[i]==' '||ch[i]==','||ch[i]=='.')
				{

					if(str.length()>=3&&str.length()<=6)
					{
						if(j==1)
							System.out.print(" ");
						System.out.print(str);
						j=1;
					}
					str="";
				}
				else
					str+=ch[i];
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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


int main(void) {
	string s;

	cin >> s;

	if (s <= "2019/04/30") {
		cout << "Heisei" << endl;
	}
	else {
		cout << "TBD" << endl;
	}
	




	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    cin.setf(std::ios::hex, std::ios::basefield);
    int X, Y;
    cin >> X >> Y;
    if (X < Y) {
        cout << "<";
    } else if (X == Y) {
        cout << "=";
    } else {
        cout << ">";
    }
}


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

using namespace std;
#define INFS (1LL<<28)
#define INF (1LL<<60)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long
#define double long double
#define all(n) n.begin(),n.end()
typedef complex<double> P;

vector<pair<double,pair<double,double>>> ans;

double max(double a,double b){
	if(a>b)return a;
	else return b;
}

double rot(double x,double y){
	double angle=acos(x/(sqrt(x*x+y*y)));
	angle=angle*180.0/acos(-1);
	if(y<0)angle=360.0-angle;
	return angle;
}

signed main(){
	cout << fixed << setprecision(15);
	int n;
	cin>>n;

	lp(i,n){
		int x,y;
		cin>>x>>y;
		ans.push_back({arg(P(x,y)),{x,y}});
	}
	sort(ans.begin(),ans.end());
	lp(i,n){
		ans.push_back(ans[i]);
	}
	double r=0;
	lp(i,n){
		double sum[2]={0,0};
		for(int j=i;j<n+i;j++){
			sum[0]+=ans[j].second.first;
			sum[1]+=ans[j].second.second;
			r=max(r,(double)sqrt(sum[0]*sum[0]+sum[1]*sum[1]));
		}
	}
	cout<<r<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    ll dist = abs(a - b);
    if (v <= w)
        putout("NO");
    else
    {
        ll vv = v - w;
        if (vv * t >= dist)
            putout("YES");
        else
            putout("NO");
    }
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
int main(void) {
	int n, k, a;
	cin >> n >> k;
	set<int> st;
	vector<int> A(200001, 0);
	for (int i = 0; i < n; ++i) {
		cin >> a;
		st.insert(a);
		++A[a];
	}
	sort(A.begin(), A.end());
	k = st.size() - k;
	int i = 0;
	long long ans = 0;
	while (k > 0 && i < 200000) {
		if (A[i] != 0) ans += A[i], --k;
		++i;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn = 1e5 + 100;
const ll inf = 1e18;

ll x[maxn], dp[maxn];

class node {
	public:
		ll mnm;
		ll lzy;
		node () {
			mnm = inf;
		}
};

node seg[4 * maxn];

void propagate (int, int, int);

ll get (int id, int L, int R, int l, int r) {
	if (L == l and R == r)
		return seg[id].mnm;
	propagate (id, L, R);
	int mid = (L + R) >> 1;
	ll ret = inf;
	if (mid > l)
		ret = min(ret, get(2 * id + 0, L, mid, l, min(mid, r)));
	if (mid < r)
		ret = min(ret, get(2 * id + 1, mid, R, max(l, mid), r));
	return ret;
}

void update(int id, int L, int R, int l, int r, ll val) {
	if (L == l and R == r) {
		seg[id].mnm += val;
		seg[id].lzy += val;
		return;
	}
	propagate (id, L, R);
	int mid = (L + R) >> 1;
	if (mid > l)
		update(2 * id + 0, L, mid, l, min (mid, r), val);
	if (mid < r)
		update(2 * id + 1, mid, R, max (l, mid), r, val);
	seg[id].mnm = min (seg[2 * id + 0].mnm, seg[2 * id + 1].mnm);
}

void propagate (int id, int L, int R) {
	if (seg[id].lzy == 0)
		return;
	int mid = (L + R) >> 1;
	update(2 * id + 0, L, mid, L, mid, seg[id].lzy);
	update(2 * id + 1, mid, R, mid, R, seg[id].lzy);
	seg[id].lzy = 0;
}

ll dis (int fi, int se) { return abs (x[fi] - x[se]); }

int main () {
	ios_base::sync_with_stdio (false);
	int n, e, t;
	cin >> n >> e >> t;
	for (int i = 1; i <= n; i++)
		cin >> x[i];
	int ptr = 1;
	for (int i = 1; i <= n; i++) {
		update (1, 1, n + 1, i, i + 1, -inf + dp[i - 1] + dis(i - 1, i) + t);
		if (i != 1)
			update (1, 1, n + 1, 1, i, 3*dis (i - 1, i));
		if (ptr != i)
			update (1, 1, n + 1, ptr, i, -2 * dis (i - 1, i)); 
		while (2 * (x[i] - x[ptr]) > t) {
			update (1, 1, n + 1, ptr, ptr + 1, 2 * dis(ptr, i) - t);
			ptr ++;
		}
		dp[i] = get (1, 1, n + 1, 1, i + 1);
//		cout << dp[i] << endl;
//		dp[i] = min (dp[i], dp[j-1] + dis(j-1, j) + 3*dis(j, i) + max(0ll,t-2*dis(j, i)));
	}
	cout << dp[n] + e - x[n] << endl;
}


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

int main(){
  ll N;
  cin >> N;
  vector<ll> A(N+1);
  vector<ll> Counts(N+1);
  ll num=0;
  
  for(ll i=1;i<=N;i++){
    cin >> A.at(i);
  }
  
  for(ll i=1;i<=N;i++){
    Counts.at(A.at(i))++;
  }
  
  /*
  for(int i=1;i<=N;i++){
    cout << Counts.at(i) << endl;
  }
  */

  for(ll i=1;i<=N;i++){
    ll x = Counts.at(i);
    num += x*(x-1)/2;
  }
  
  //cout << num << endl;
  
  for(ll i=1;i<=N;i++){
    cout << num - (Counts.at(A.at(i)) - 1) << endl;
  }
  
  return(0);
}


Measured memory_bytes: 5760
def g(r, c):
    ret = 0
    for i in range(1, r + 2):
        ret += fact[i + c] * fact_inv[i] * fact_inv[c]
        ret %= mod

    return ret


r1, c1, r2, c2 = map(int, input().split())

mod = 10 ** 9 + 7
MAX = 2 * 10 ** 6 + 10

fact = [1] * (MAX + 1)
for i in range(1, MAX + 1):
    fact[i] = (fact[i-1] * i) % mod

inv = [1] * (MAX + 1)
for i in range(2, MAX + 1):
    inv[i] = inv[mod % i] * (mod - mod // i) % mod

fact_inv = [1] * (MAX + 1)
for i in range(1, MAX + 1):
    fact_inv[i] = fact_inv[i-1] * inv[i] % mod

ans = g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1)
ans %= mod
print(ans)


Measured memory_bytes: 87388
#include <bits/stdc++.h>
#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int r, d, x;
    cin >> r >>d >>x;
    int ans = x;
    REP(i, 10)
    {
        ans = ans * r - d;
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n,m;
	std::cin >> n >> m;
	int max = (1<<n)-1;
	const int INF = 1e9+7;
	std::vector<int> minc(max+1,INF);
	rep(i,m) {
		int a,b;
		std::cin >> a >> b;
		int opens = 0;
		rep(j,b) {
			int c;
			std::cin >> c;
			opens |= (1<<(c-1));
		}
		minc[opens] = std::min(minc[opens],a);
	}

	std::vector<int> dp(max+1,INF);
	dp[0]=0;
	rep(i,max+1) {
		if(minc[i]==INF) continue;
		rep(j,max+1) {
			dp[i|j] = std::min(dp[j]+minc[i],dp[i|j]);
		}
	}
	if(dp[max]==INF) {
		print(-1);
		return 0;
	}
	std::cout << dp[max] << ENDL;

	return 0;
}


Measured memory_bytes: 256
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rep3(var, min, max) for (ll (var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll (var) = (max) - 1; (var) + 1 > (min); --(var))
#define Mp(a,b) make_pair((a),(b))
#define F first
#define S second
#define Icin(s) ll (s);cin>>(s);
#define Scin(s) ll (s);cin>>(s);
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; }
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD=1e9+7;
//ここから
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main() {
    int n;
    cin>>n;
    V A(n);
    V B(n);
    rep(i,n)cin>>A[i];
    rep(i,n)cin>>B[i];
    VP A2(n);
    VP B2(n);
    rep(i,n)A2[i]={A[i],i};
    rep(i,n)B2[i]={B[i],i};
    sort(all(A));
    sort(all(B));
    sort(all(A2));
    sort(all(B2));
    rep(i,n){
        if(B[i]<A[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    UnionFind tree(n);
    rep(i,n)tree.unite(A2[i].second,B2[i].second);
    int c=0;
    rep(i,n){
        if(tree.root(i)==i)c++;
    }
    if(c>1){
        cout<<"Yes"<<endl;
        return 0;
    }
    rep3(i,1,n){
        if(A2[i].first<=B2[i-1].first){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

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

using namespace std;

int main()
{
    long long int n , m , i , sum=0;
     cin>>n>>m;
    long long int a[n];
    for( i = 0 ; i < m ; i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    if(sum>n)cout<<"-1"<<endl;
    else cout<<n-sum<<endl;
}

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

typedef long long LL;
const int maxn = 2e5 + 5;
LL a[maxn], k;
int n;

bool check(LL limit)
{
    LL res = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] > 0) {
            int left = 1, right = n, mid, ans = 0;
            while (left <= right) {
                mid = (left + right) >> 1;
                if (a[mid] * a[i] <= limit) {
                    ans = mid;
                    left = mid + 1;
                } else
                    right = mid - 1;
            }
            res += ans;
            if (a[i] * a[i] <= limit)
                res--;
        } else if (a[i] < 0) {
            int left = 1, right = n, mid, ans = n + 1;
            while (left <= right) {
                mid = (left + right) >> 1;
                if (a[mid] * a[i] <= limit) {
                    ans = mid;
                    right = mid - 1;
                } else
                    left = mid + 1;
            }
            res += n + 1 - ans;
            if (a[i] * a[i] <= limit)
                res--;
        } else {
            if (limit >= 0)
                res += n - 1;
        }
    }
    //cout << "res " << res / 2 << '\n';
    return res / 2 >= k;
}

int main()
{

    scanf("%d%lld", &n, &k);
    for (int i = 1; i <= n; i++)
        scanf("%lld", &a[i]);
    sort(a + 1, a + n + 1);

    // for (int i = 1; i <= n; i++)
    //     printf("%lld ", a[i]);
    // printf("\n");

    LL left = -1e18, right = 1e18, mid, ans;
    while (left <= right) {
        mid = (left + right) >> 1;
        //  cout << "check " << mid << '\n';
        if (check(mid)) {
            ans = mid;
            right = mid - 1;
        } else
            left = mid + 1;
    }

    printf("%lld\n", ans);
    return 0;
}

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

int main() {
  int n, m, i, j, k, count = 0, check = 0;
  string s, t;
  cin >> s >> t;
  n = s.length();
  m = t.length();
  if (n >= m) {
    for (i = n - m; i >= 0; i--) {
      count = 0;
      for (j = 0; j < m; j++) {
        if (s[i + j] == t[j] || s[i + j] == '?') {
          count++;
        }
      }
      if (count != m) {
        continue;
      } else {
        k = i;
        check = 1;
        break;
      }
    }
  }
  if (check) {
    for (i = 0; i < m; i++) {
      s[k + i] = t[i];
    }
    for (i = 0; i < n; i++) {
      if (s[i] == '?') {
        s[i] = 'a';
      }
    }
  } else {
    s = "UNRESTORABLE";
  }
  cout << s << "\n";
  return 0;
}

Measured memory_bytes: 256
//    _____ _     _                _           _     _ _     _     
//    \_   \ |_  (_)___  __      _| |__   __ _| |_  (_) |_  (_)___ 
//     / /\/ __| | / __| \ \ /\ / / '_ \ / _` | __| | | __| | / __|
//  /\/ /_ | |_  | \__ \  \ V  V /| | | | (_| | |_  | | |_  | \__ \
//  \____/  \__| |_|___/   \_/\_/ |_| |_|\__,_|\__| |_|\__| |_|___/
//                                                                 
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int sz=2e3+9;
int n,x,y;
vector<int> v[sz];
bool visited[sz];
int d[sz];
int ans[sz];

void bfs(int idx){
	visited[idx]=1;
	d[idx]=0;
	queue<int> q;
	q.push(idx);
	while(!q.empty()){
		int s=q.front();
		q.pop();
		for(auto u:v[s]){
			if(visited[u]) continue;
			visited[u]=1;
			d[u]=d[s]+1;
			if(idx<u){
				ans[d[u]]++;
				// cout<<idx<< " "<<u<< " "<<d[u]<<'\n';
			}
			q.push(u);
		}
	}
}

int main(){
	cin>>n>>x>>y;
	for(int i=1;i<n;i++){
		v[i].pb(i+1);
		v[i+1].pb(i);
	}	
	v[x].pb(y);
	v[y].pb(x);
	for(int i=1;i<n;i++){
		memset(visited,0,sizeof(visited));
		bfs(i);
	}
	for(int i=1;i<n;i++) cout<<ans[i]<< "\n";
	return 0;
}

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


int main()
{


     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
    
 

 int index=0;
 for(int i=0;i<5;i++)
 {
      int first;
      cin>>first;
      if(first==0)
        index=i+1;
 }

 cout<<index<<endl;

  return 0;

}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string s;
    cin >> s;
    bool flag=true;
    for (int i=0;i<3;i++) {
        if (s[i]==s[i+1]) flag=false;
    }
    if (flag) cout << "Good" << endl;
    else cout << "Bad" << endl;
}

Measured memory_bytes: 256
private fun readInt() = readLine()!!.toInt()

private fun readInts() = readLine()!!.split(' ').map { it.toLong() }

fun main() {
    val v = readInts()
    val a = v.take(2)
    val b = v.takeLast(2)
    val x = listOf(a[0]*b[0], a[0]*b[1], a[1]*b[0], a[1]*b[1])
    println(x.max()!!)
}

Measured memory_bytes: 39012
#include <bits/stdc++.h>
#define x first
#define y second
#define int int long long // 2e9 & 9e18
using namespace std; const int inf = numeric_limits<int>::max();
struct __io{__io(){ios_base::Init i; ios_base::sync_with_stdio(0); cin.tie(0);}} __io; // fast I/O
#ifdef LOCAL // setting up print debugging (yes lol)
template<class K, class V>ostream& operator<<(ostream&s,const pair<K,V>&p){s<<'<'<<p.x<<", "<<p.y<<'>';return s;}
template<class T, class=typename T::value_type, class=typename enable_if<!is_same<T,string>::value>::type>
ostream& operator<<(ostream&s,const T&v){s<<'[';for(auto&x:v){s<<x<<", ";}if(!v.empty()){s<<"\b\b";}s<<']';return s;}
void __prnt(){cerr<<endl;} template<class T, class...Ts>void __prnt(T&&a,Ts&&...etc){cerr<<a<<' ';__prnt(etc...);}
#define print(...) __prnt(__VA_ARGS__)
#else
#define print(...)
#endif

signed main() {
    string s;
    cin >> s;
    int n = s.length();
    vector<vector<int>> a(2, vector<int>(2019));
    a[0][(s[0]-'0')%2019] = 1;
    int count = a[0][0];
    for (int i = 1; i < n; ++i) {
        a[i%2].assign(2019, 0);
        a[i%2][(s[i]-'0')%2019] = 1;
        for (int k = 0; k < 2019; ++k) {
            int r = ((k * 10) + (s[i]-'0')) % 2019;
            a[i%2][r] += a[(i+1)%2][k];
        }
        count += a[i%2][0];
    }
    cout << count << endl;
}


Measured memory_bytes: 3776
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d %d", &a, &b);
	if(a<b){
		printf("a < b\n");
	}else if(a>b){
		printf("a > b\n");
	}else{
		printf("a == b\n");
	}
	return 0;
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    cin >> skipws;

    for (;;) {
        int n, a, b, c, x;
        cin >> n >> a >> b >> c >> x;

        if (!n) break;

        vector<int> v(n);
        rep(i, 0, n) cin >> v[i];

        int cur = 0;
        int it = 1;
        if (x == v[cur])
            cur++;
        for (; it <= 10000 && cur < n; ++it) {
            x = (a * x + b) % c;
            if (x == v[cur])
                cur++;
        }
        if (cur == n) cout << it - 1 << endl;
        else cout << -1 << endl;
    }
}


Measured memory_bytes: 3144
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()

int main() {
    int n; cin >> n;
    vector<ll> a(n);
    rep(i, n) {
        cin >> a[i];
    }

    ll ans = 0;
    for(int i = 0; i < n; i++) {
        if(i == 0) {
            ans += 0;
        } else {
            if(a[i] < a[i-1]) {
                ans += a[i-1] -a[i];
                a[i] = a[i-1];
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 4840
import sys

if __name__ == "__main__":
    MAX_V = 100 ** 2  # N <= 100, v <= 100
    N, W = map(lambda x: int(x), input().split())
    dp = [sys.maxsize] * (MAX_V + 1)
    dp[0] = 0
    for i in range(N):
        value, weight = map(lambda x: int(x), input().split())
        for v in range(MAX_V, 0, -1):
            if (v - value < 0):
                break
            dp[v] = min(dp[v], dp[v - value] + weight)

    ans = 0
    for v in range(MAX_V, 0, -1):
        if dp[v] <= W:
            ans = v
            break

    print(ans)



Measured memory_bytes: 5724
#include "bits/stdc++.h"
using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pll = pair<ll, ll>;

int main() {
	int N;
	cin >> N;
	vector<int> x(N), y(N);
	for (int i = 0; i < N; i++)
		cin >> x[i] >> y[i];

	map<pii, int> mp;
	for (int i = 0; i < N; i++)
		for (int j = i + 1; j < N; j++)
		{
			int dx = x[i] - x[j], dy = y[i] - y[j];
			if (dx < 0) {
				dx *= -1;
				dy *= -1;
			}
			else if (dx == 0 and dy < 0) {
				dy *= -1;
			}
			mp[pii(dx, dy)]++;
		}
	int npq_max = 0;
	for (const auto& e : mp)
		npq_max = max(npq_max, e.second);
	cout << N - npq_max << endl;
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

typedef long long ll;

int main(){
ll A,B,K; cin >> K >> A >> B;
if( ( B - A ) <= 2 ){ cout << K + 1 << endl; return 0;}
else{
  if( K <= ( A - 1)){ cout << K + 1 << endl; return 0;}
  else{
    ll U = K - ( A - 1 ) ; ll biscket = A;
      for(ll i = 0; i < U / 2; i++){
        biscket += (B - A);} 
    if( U % 2 == 0){ cout<< biscket << endl; return 0;}
    else{ cout << biscket + 1 << endl;  return 0;}
  }}
  return 0;}


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

long long LCM (long long a, long long b) {
  long long a2 = a, b2 = b;
  long long r;
  while(max(a,b)%min(a,b) != 0) {
    r = max(a,b)%min(a,b);
    (a > b ? a : b) = r;
  }
  return a2/min(a,b)*b2;
}

int main() {
  int N;
  cin >> N;
  vector<long long> T(N);
  for (int i = 0; i < N; i++) cin >> T.at(i);
  long long share = T.at(0);
  for (int i = 1; i < N; i++) {
    share = LCM(share, T.at(i));
  }
  cout << share << endl;
}

Measured memory_bytes: 3580
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<time.h>
#include<ctime>
#include<functional>
#define int long long
#define INT INT_MAX
#define LONG LLONG_MAX
#define f(i,n) for(int i=0;i<(n);i++)
#define P pair<int,int>
typedef long long ll;
using namespace std;

signed main() {
	int a, b, c = 0;
	cin >> a;
	f(i, a) {
		cin >> b;
		if (b % 2) c++;
	}
	if (c % 2) puts("NO");
	else puts("YES");
	return 0;
}

Measured memory_bytes: 256