akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}


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

    map<string,int> a;


    rep(i,N){
        int k;
        cin >> k;
        rep(j,k){
            string s;
            cin >> s;
            a[s]++;
        }

    }

    int ans = 0;
    for(auto x : a){
        if(x.second == N)ans ++;
    }

    cout << ans << endl;
}



Measured memory_bytes: 3480
from collections import deque


class Dinic(object):
    __slots__ = ["inf", "v_count", "edges", "iter", "level"]

    def __init__(self, v_count: int, edges: list):
        self.inf = 10**9
        self.v_count = v_count
        self.edges = [[] for _ in [0]*v_count]
        self.iter = [0]*v_count
        self.level = None
        self._create_graph(edges)

    def _create_graph(self, _edges):
        edges = self.edges
        for origin, dest, cap in _edges:
            edges[origin].append([dest, cap, len(edges[dest])])
            edges[dest].append([origin, 0, len(edges[origin])-1])

    def solve(self, source: int, sink: int):
        max_flow = 0

        while True:
            self.bfs(source)
            if self.level[sink] < 0:
                return max_flow

            self.iter = [0]*self.v_count
            flow = self.dfs(source, sink, self.inf)

            while flow > 0:
                max_flow += flow
                flow = self.dfs(source, sink, self.inf)

    def bfs(self, source: int):
        level, edges = [-1]*self.v_count, self.edges
        level[source] = 0
        dq = deque([source])
        popleft, append = dq.popleft, dq.append

        while dq:
            v = popleft()
            for dest, cap, _rev in edges[v]:
                if cap > 0 > level[dest]:
                    level[dest] = level[v] + 1
                    append(dest)

        self.level = level

    def dfs(self, source: int, sink: int, flow: int) -> int:
        if source == sink:
            return flow
        while self.iter[source] < len(self.edges[source]):
            dest, cap, rev = edge = self.edges[source][self.iter[source]]
            if cap > 0 and self.level[source] < self.level[dest]:
                flowed = self.dfs(dest, sink, flow if flow < cap else cap)
                if flowed > 0:
                    edge[1] -= flowed
                    self.edges[dest][rev][1] += flowed
                    return flowed
            self.iter[source] += 1

        return 0


if __name__ == "__main__":
    import sys
    V, E = map(int, input().split())
    edges = []
    for a in (map(int, l.split()) for l in sys.stdin):
        edges.append(a)

    dinic = Dinic(V, edges)
    print(dinic.solve(0, V-1))


Measured memory_bytes: 6532
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll INF = 1e18 + 10 ;
int main(){
    fastio 
    ll n , k ; 
    cin >> n >> k ; 
    vector<ll> a(n) , f(n) ; 
    for(int i = 0; i < n; i++){
        cin >> a[i] ; 
    }
    sort(a.begin(), a.end()) ;
    for(int i = 0; i < n; i++){
        cin >> f[i] ; 
    }
    sort(f.rbegin(), f.rend()) ;
    ll L = 0, R = 1e18 ; 
    ll ans = -1 ; 
    while(L <= R){
        ll mid = L + (R - L) / 2 ;
        ll moves = 0 ; 
        for(int i = 0; i < n; i++){
            ll newx= mid / f[i];
            if ( a[i] - newx > 0 ) moves += a[i] - newx ; 
        }
        if ( moves <= k ){
            ans = mid ; 
            R = mid - 1;
        }
        else L = mid + 1;
    }
    cout << ans << endl;
    return 0 ;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
char s[N]; int X,Y,n,f[N][2][2];
signed main()
{
    scanf("%s%lld%lld",s+1,&X,&Y);
    n=strlen(s+1);
    X+=25000, Y+=25000;
    int qwq=1;
    int gg=0;
    while(qwq<=n&&s[qwq]=='F') qwq++, gg++;
    f[25000+gg][0][0]=f[25000][1][0]=1;
    int p,q; p=q=0;
    while(qwq<=n)
    {
        qwq++, p^=1, q^=p;
        int tt=0;
        while(qwq<=n&&s[qwq]=='F') qwq++, tt++;
        for(ri int i=25000-n;i<=25000+n;i++) f[i][p][q]=f[i+tt][p][q^1ll]|f[i-tt][p][q^1ll];
    }
    if(p==1 && f[X][0][q^1ll] && f[Y][1][q] || p==0 && f[X][0][q] && f[Y][1][q]) puts("Yes");
    else puts("No");
    return 0;
}

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

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            if(int.Parse(input[0])*int.Parse(input[1])%2 == 0)
            {
                Console.WriteLine("Even");
            }
            else
            {
                Console.WriteLine("Odd");
            }
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <cstring>
#include <array>
#include <algorithm>
using namespace std;

string words[4] = {"dream", "dreamer", "erase", "eraser"};

int main() {
  string S;

  cin >> S;
  reverse(S.begin(), S.end());
  for(int i =0; i< 4; i++)
    reverse(words[i].begin(), words[i].end());

  while(1) {
    const string current = S;
    for(const auto w: words) {
      if (S.find(w) == 0) {
        S.erase(0, w.length());
      }
    }
    if (S.empty()) {
      cout << "YES";
      return 0;
    } else if(current == S) {
      cout << "NO";
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 100005
int n,p[maxn],pos[maxn],a[maxn],b[maxn],cnt[maxn];

int main()
{
    scanf("%d",&n);
    int N=n+1;
    for (int i=1;i<=n;i++) scanf("%d",p+i);
    for (int i=1;i<=n;i++) a[i]=N*i;
    for (int i=1;i<=n;i++) b[i]=(n-i+1)*N;
    for (int i=2;i<=n;i++)
        if (!cnt[p[i-1]]) b[p[i]]=(n-p[i]+1)*N+1,cnt[p[i]]=1;
        else b[p[i]]=(n-p[i]+1)*N+cnt[p[i-1]]+1,cnt[p[i]]=cnt[p[i-1]]+1;
    for (int i=1;i<n;i++) printf("%d ",a[i]);printf("%d\n",a[n]);
    for (int i=1;i<n;i++) printf("%d ",b[i]);printf("%d\n",b[n]);
    return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
#include<math.h>
int main()
{
 int a,i;
 double sq;
 scanf("%d",&a);
 for(i=a;i>=1;i--)
 {
  sq=sqrt(i);
  if(sq==(int)sq){printf("%d",i);return 0;}
 }
 return 0;
}

Measured memory_bytes: 128
def main():
    import bisect
    x,y,a,b,c = map(int,input().split())
    p = sorted(list(map(int,input().split())))
    q = sorted(list(map(int,input().split())))
    r = list(map(int,input().split()))
    ans = 0
    if x<=a:
        p = p[a-x:a]
    if y<=b:
        q = q[b-y:b]
    ans = sorted(p+q+r,reverse=True)
    print(sum(ans[0:x+y]))
if __name__ == "__main__":
    main()

Measured memory_bytes: 23200
N, M = map(int, input().split())
a = []; b = []; c = []; d = []

for i in range(N):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)
for i in range(M):
    x, y = map(int, input().split())
    c.append(x)
    d.append(y)

for i in range(N):
    m = abs(a[i] - c[0]) + abs(b[i] - d[0])
    p = 0
    for j in range(1, M):
        if m > abs(a[i] - c[j]) + abs(b[i] - d[j]):
            m = abs(a[i] - c[j]) + abs(b[i] - d[j])
            p = j
    print(p + 1)


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

using namespace std;

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define Get(t, i) get<(i)>((t))
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

const int inf = 1 << 30;
const ll INF = 1LL << 55;

int N, M;
int D[1010], C[1010];
int dp[1010][1010];

int solve(int curr, int day)
{
  if(curr == N) return 0;
  if(day == M) return inf;
  if(~dp[curr][day]) return dp[curr][day];
  return dp[curr][day] = min(solve(curr+1, day+1) + D[curr]*C[day], solve(curr, day+1));
}

int main()
{
  cin >> N >> M;
  rep(i, N) cin >> D[i];
  rep(i, M) cin >> C[i];
  memset(dp, -1, sizeof(dp));
  cout << solve(0, 0) << endl;
  return 0;
}

Measured memory_bytes: 7128
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

signed main(void)
{
  int n;
  cin >> n;
  ll b = 1;
  REP(i, n) b *= 3;
  ll ret = 1;
  REP(i, n) {
    int a;
    cin >> a;
    if(a%2) {
      ret *= 1;
    } else {
      ret *= 2;
    }
  }
  cout << b - ret << endl;

  return 0;
}


Measured memory_bytes: 256
from math import sqrt
N,D = map(int, input().split())
L = []
for i in range(N):
    L.append([int(i) for i in input().split()])
ans = 0
for i in range(N):
    for j in range(N):
        if i >= j:
            continue
        a = L[i]
        b = L[j]
        e = sqrt(sum([abs(c-d)**2 for c, d in zip(a, b)]))
        if e == int(e):
            ans += 1
print(ans)

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

int main(){
  int n; string s = ""; cin >> n;
  vector<map<char, int>> v(n); vector<int> u(26, 1e9);
  rep(i, n){
    string t; cin >> t;
    rep(j, t.size()) v[i][t[j]]++;
    rep(j, 26) u[j] = min(u[j], v[i][(char)('a'+j)]);
  }
  rep(i, 26) rep(j, u[i]) s += (char)('a'+i);
  cout << s << "\n";
  return 0;
}

Measured memory_bytes: 256
//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    string s; cin >> s;

    REP(i, s.size()) {
        if (i + 1 < s.size()) {
            if (s[i] == s[i + 1]) {
                cout << i + 1 << " " << i + 2 << endl;
                return 0;
            }
        }

        if (i + 2 < s.size()) {
            if (s[i] == s[i + 2]) {
                cout << i + 1 << " " << i + 3 << endl;
                return 0;
            }
        }
    }

    print("-1 -1");
}


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

N, K = map(int, input().rstrip().split(' '))
h = sorted([int(input()) for x in range(N)])

min_cost = 1e10
for i in range(N - K + 1):
    cost = h[i+K-1] - h[i]
    if cost < min_cost:
        min_cost = cost
        
print(min_cost)

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  ll n;
  cin >> n;
  vector<ll> a1(n);
  vector<ll> a2(n);
  for(int i = 0; i < n; ++i) cin >> a1[i];
  for(int i = 0; i < n; ++i) cin >> a2[i];

  reverse(ALL(a2));
  for(int i = 0; i < n - 1; ++i)
  {
    a1[i + 1] += a1[i];
    a2[i + 1] += a2[i];
  }
  reverse(ALL(a2));
  ll ans = 0;

  for(int i = 0; i < n; ++i)
  {
    ans = max(ans, a1[i] + a2[i]);
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  int cnt = 0;
  for (int i = 0; i < M; i++) {
    int a;
    cin >> a;
    cnt += a;
  }
  if (cnt > N) {
    cout << -1 << endl;
  } else {
    cout << N - cnt << endl;
  }

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 3648
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("a.in","r",stdin);
#endif
    ll a,b,n;
    cin>>a>>b>>n;
    ll t=n/b;
    ll ans=0;
    t*=b;
    t--;
    if (t!=-1)
    {
        ans=max(ans,(a*t)/b-a*(t/b));
    }
    ans=max(ans,(a*n)/b-a*(n/b));
    cout<<ans;


}


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

int main() {
    int a, b;
    cin >> a >> b;
    if(a < b) {
        int tmp = a;
        a = b;
        b = tmp;
    }

    int gcd = 1;
    int a2 = a;
    int b2 = b;
    while(1) {
        int q = a2 / b2;
        int r = a2 % b2;
        if(r == 0) {
            gcd = b2;
            break;
        }
        a2 = b2;
        b2 = r;
    }
    cout << (int64_t)a * b / gcd << endl;

    return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;


#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;
    
    input!{
        n: usize,
        s: Chars,
    }

    let mut ans  = 0;
    for i in 1..n-1 {
        let a = s[..=i].iter().map(|x| *x).collect::<HashSet<char>>();
        let b = s[i+1..].iter().map(|x| *x).collect::<HashSet<char>>();
        ans = std::cmp::max(ans, a.intersection(&b).count());
   }

    println!("{}", ans);
}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


Measured memory_bytes: 2188
#include <cstdio>
#include <algorithm>
using namespace std;
#define EPS (1e-13)
double dp[100001];
int main() {
	dp[1]=1;
	for(int n=2;n<=100000;n++) {
		double p=1,win=0.5;
		int k=1;
		while(EPS<p&&k<n) {
			double Not=p*(1-win);
			dp[n]+=Not*(k+dp[max(n-k-1,0)]);
			p*=win; win/=2; k++;
		}
		dp[n]+=n*p;
	}
	int n;
	while(scanf("%d",&n),n) {
		printf("%lf\n",dp[n]);
	}
}

Measured memory_bytes: 1840
#include<stdio.h>
char s[1000001];
int main(){
	int n,m;
	int i,j;
	while(1){
	scanf("%d %d",&n,&m);
	if(n==0)return 0;
	scanf(" %s",s);
	int ans=0;
	int l=0,r=0;
	int res=0;
	while(l<m){
		if(s[l]=='O')l++;
		else{
			while(r<m-2&&s[r+1]=='O'&&s[r+2]=='I'&&res<n){
				r+=2;
				res++;
			}
			if(res==n)ans++;
			if(res>0){
				res--;
				l+=2;
			}else{
				l++;
			}
		}
		if(r<l)r=l;
	}
	printf("%d\n",ans);
	}
}

Measured memory_bytes: 2008
nq = list(map(int,input().split()))
q=nq[1]
s=list(input())
lr=[0 for i in range(q)]
for i in range(q):
    lr[i]=list(map(int,input().split()))
c=[0 for i in range(len(s))]
for i in range(len(s)):
    if i ==0:
        c[i]=0
    else:
        if s[i-1]=='A' and s[i]=='C':
            c[i] = c[i-1]+1
        else:
            c[i] = c[i-1]
for i in range(q):
    print(c[lr[i][1]-1]-c[lr[i][0]-1])


Measured memory_bytes: 31324
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <sstream>
using namespace std;

unsigned long long total_all;

unsigned long long str_to_number(string str) {
	string Text = str;//string containing the number
	unsigned long long Result;//number which will contain the result
	stringstream convert(Text); // stringstream used for the conversion initialized with the contents of Text
	if ( !(convert >> Result) )//give the value to Result using the characters in the string
	    Result = 0;//if that fails set Result to 0
	return Result;
}


void addall(string number, vector<string> aha, string temp_number, int index, int len) {
	if (index == len) {
		//calculate
		if (temp_number!="")
			aha.push_back(temp_number);

		long long tmp = 0;
		for (int i=0; i<aha.size(); i++) {
			tmp += str_to_number(aha[i]);
			// cout << aha[i] << " ";
		}
		// cout << endl;
		total_all += tmp;
	}
	else {
		//plus
		vector<string> aha_copy = aha;
		aha_copy.push_back(temp_number);
		addall(number, aha_copy, "", index+1, len);

		//no plus
		addall(number, aha, temp_number+number[index], index+1, len);
	}
}

int main() {
	string str;
	cin >> str;
	total_all = 0;
	vector<string> uhu;
	addall(str, uhu, "", 0, str.length());
	cout << total_all << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N;
int A[20], B[20];
int dp[1 << 18][18];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < N; i++) cin >> B[i];
    
    for(int i = 0; i < (1 << N); i++){
        for(int j = 0; j < 18; j++){
            dp[i][j] = inf;
        }
    }
    dp[0][0] = 0;
    
    for(int i = 0; i < (1 << N); i++){
        for(int j = 0; j < 18; j++){
            int s = 0;
            for(int k = 0; k < N; k++){
                s += (i >> k) & 1;
            }
            int mx = (abs(s - j) & 1 ? A[j] : B[j]);
            if(i == 0) mx = 0;
            int p = 0;
            for(int k = 0; k < N; k++){
                if((i >> k) & 1) continue;
                if(abs(k - s) & 1){
                    if(mx <= B[k]){
                        chmin(dp[i | (1 << k)][k], dp[i][j] + p);
                    }
                }else{
                    if(mx <= A[k]){
                        chmin(dp[i | (1 << k)][k], dp[i][j] + p);
                    }
                }
                p++;
            }
        }
    }
    int ans = inf;
    for(int i = 0; i < N; i++){
        chmin(ans, dp[(1 << N) - 1][i]);
    }
    cout << (ans == inf ? -1 : ans) << endl;
    return 0;
}

Measured memory_bytes: 18688
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

template<class T> struct UF{
    vector<T> par,sz,ed;

    UF(T n){
        par.resize(n);
        sz.resize(n,1);
        ed.resize(n,0);
        for (int i = 0; i < n; ++i) par[i]=i;
    }

    T find(T x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }

    bool unit(T x,T y){
        x=find(x);
        y=find(y);
        if(x==y){
            ++ed[x];
            return false;
        }
        if(sz[x]>sz[y]){
            par[y]=x;
            sz[x]+=sz[y];
            ed[x]+=ed[y]+1;
        }
        else{
            par[x]=y;
            sz[y]+=sz[x];
            ed[y]+=ed[x]+1;
        }
        return true;
    }
    bool same(T x,T y){return find(x)==find(y);}
    bool ok(T x,T y){
        x=find(x);y=find(y);
        return sz[x]+sz[y]>ed[x]+ed[y];
    }
};

struct ARC{
    int a,r,c;
    bool operator<(ARC x){
        return a>x.a;
    }
};

class ECardCollector {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n,h,w;
        in>>n>>h>>w;
        vector<ARC> arc(n);
        for(auto&i:arc) in>>i.r>>i.c>>i.a,--i.r,--i.c;
        sort(arc.begin(),arc.end());
        UF<int> uf(h+w);
        ll ans=0;
        fr(i,n){
            if(uf.ok(arc[i].r,h+arc[i].c)){
                ans+=arc[i].a;
                uf.unit(arc[i].r,arc[i].c+h);
            }
        }
        out<<ans<<endl;
    }
};

int main() {
    ECardCollector solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

def solve(A: int, B: int):
    ten = B * 10
    ans = int(ten)

    while True:
        if ans // 10 != B :
            print(-1)
            return
        elif math.floor(ans * 0.08) == A:
            print(ans)
            return
        ans += 1

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define fio() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define MOD 1000000007
#define nl '\n'
#define pb push_back
#define mp make_pair

using namespace std;
const int N = 3005;
ld dp[N][N];
int32_t main()
{
	fio();
	int n;
	cin>>n;
	ld p[n+1];
	for(int i=1;i<=n;i++)
		cin>>p[i];
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		dp[i][0]=dp[i-1][0]*(1-p[i]);
		dp[0][i]=0;
	}
	cout<<fixed<<setprecision(15);
	ld ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=i;j++)
		{
			dp[i][j]+=dp[i-1][j]*(1-p[i]);
			dp[i][j]+=dp[i-1][j-1]*p[i];
		}
	}
	/*for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
			cout<<dp[i][j]<<" ";
		cout<<endl;
	}*/
	for(int i=n/2+1;i<=n;i++)
		ans+=dp[n][i];
	cout<<ans<<endl;
	//cout<<dp[n][m];
}



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

int main() {

	ll n; cin >> n;
	map<ll, ll> mp;
	for (int i = 0; i < n; i++) {
		ll a; cin >> a;
		mp[a]++;
	}
	ll ans = 0;
	for (auto u : mp) {
		if (u.second % 2 != 0) ans++;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  int n,m,cnt=0,cnt1=0;
  cin >> n >> m;
  bool a[n]={};
  int d[n]={};
  for(int i=0;i<m;i++){
    int b;
    string c;
    cin >> b >> c;
    if(c == "WA"&&!a[b-1]) d[b-1]++;
    if(c == "AC"&&!a[b-1]){
      a[b-1] = 1;
      cnt1++;
      cnt += d[b-1];
    }
  }
  cout << cnt1 << " " << cnt << endl;
}

Measured memory_bytes: 768
/**
 *    author:  FromDihPout
 *    created: 2020-05-26
**/

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    vector<double> a(n), pref(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i] = (a[i] + 1) / 2;
    }
    for (int i = 0; i < n; i++) {
        pref[i] = pref[i-1] + a[i];
    }
    double max_sum = pref[k-1];
    for (int i = k; i < n; i++) {
        max_sum = max(max_sum, pref[i] - pref[i-k]);
    }
    printf("%.10f", max_sum);
    return 0;
}

Measured memory_bytes: 3456
#include<stdio.h>
int main()
{
int S;
scanf("%d",&S);
int h,m,s;
h = S/3600;
m = S/60 - 60*h;
s = S - 60*m -3600*h;
printf("%d:%d:%d\n",h,m,s);
return 0;
}



Measured memory_bytes: 1976
using System;

class Program
{
    static void Main(string[] args)
    {
        int t = int.Parse(Console.ReadLine());
        int b;
        string a = t.ToString();
        if (a.Length > 3)
        {
            b = int.Parse(a.Substring(a.Length - 3, 3));
        } else
        {
            b = t;
        }

        if (b == 0)
        {
            Console.WriteLine(0);
        } else
        {
            Console.WriteLine(1000 - b);
        }
        return;
    }
}

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

int main(){
  int N,a,b;
  int d1,d2,d3,d4,d5;
  int sum = 0;
  cin >> N >> a >> b;
  for(int i=1;i<=N;i++){
    d1 = i/10000;
    d2 = (i%10000)/1000;
    d3 = (i%1000)/100;
    d4 = (i%100)/10;
    d5 = i%10;
    if(a <= d1+d2+d3+d4+d5 && d1+d2+d3+d4+d5 <= b) sum += i;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		
		int N = scan.nextInt();
		
		int[] order = new int[N];
		for (int i = 0; i < N; i++) {
			order[i] = scan.nextInt();
		}
		
		int[] satisfaction = new int[N];
		for (int i = 0; i < N; i++) {
			satisfaction[i] = scan.nextInt();
		}
		
		int[] addSatisfaction = new int[N];
		for (int i = 0; i < N - 1; i++) {
			addSatisfaction[i] = scan.nextInt();
		}
		
		int total = 0;
		for (int i = 0; i < order.length; i++) {
			total += satisfaction[order[i] - 1];

          	if (i == 0) {
              continue;
            }
          
			if (order[i - 1] + 1 == order[i]) {
				total += addSatisfaction[order[i - 1] - 1];
			}
		}

		System.out.println(total);
	}
}



Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<long long,long long>;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll gcd(ll x, ll y){
  if(x%y==0)return y;
  return gcd(y,x%y);
}
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int n;
  string s;
  cin >> n >> s;
  int pointer=0,need=0;
  rep(i,n){
    if(s[i]=='('){
      pointer++;
    }
    else{
      if(pointer==0)need++;
      else pointer--;
    }
  }
  string t="";
  rep(i,need)t+='(';
  s=t+s;
  rep(i,pointer)s+=')';
  cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;



int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//ios_base& scientific (ios_base& str);
string s;
cin >> s;
ll flag = 0;
for(int i=0; i<s.length(); i++){
	if((i+1)%2){
		if(s[i]=='R' || s[i] == 'U' || s[i] == 'D'){
			continue;
		}
		else{
			flag = 1;
			break;
		}
	}

	else{
		if(s[i] == 'L' || s[i] == 'U' || s[i] == 'D'){
			continue;
		}
		else{
			flag =1 ;
			break;
		}
	}
}
if(flag == 0){
	cout << "Yes" << endl;
}
else
	cout << "No" << endl;
return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <utility>
#include <functional>
#define INF 0x3f3f3f3f3f3f3f3f
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

int a[40][40];
ll dp[1600][40][40];
int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };

int main() {
	int h, w; cin >> h >> w;
	rep(i, h)rep(j, w)cin >> a[i][j];
	memset(dp, 0x3f, sizeof(dp));
	dp[0][0][0] = 0;
	rep(i, h*w)rep(j, h)rep(k, w) {
		rep(t, 4) {
			int nx = j + dx[t], ny = k + dy[t];
			if (0 <= nx&&nx < h && 0 <= ny&&ny < w) {
				dp[i + 1][nx][ny] = min(
					dp[i + 1][nx][ny],
					dp[i][j][k] + i*a[nx][ny] * 2 + a[nx][ny]
				);
			}
		}
	}
	ll Min = INF;
	rep(i, h*w + 1)Min = min(Min, dp[i][h - 1][w - 1]);
	cout << Min << endl;
}


Measured memory_bytes: 23140
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
    public static void main(String[] args){
        FastScanner sc = new FastScanner();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        String result = "No";
        int max = 0;
        max = Math.max(a, b);
        max = Math.max(max, c);

        if(max == a){
            if(b + c == max) result = "Yes";
        }else if(max == b){
            if(a + c ==max) result ="Yes";
        }else{
            if(a + b ==max) result = "Yes";
        }
        System.out.println(result);


    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
    }
}


Measured memory_bytes: 22740
#include <cstdio>
#include <iostream>

using namespace std;
const int L = 5010;
int a;
char str[L];
int main(){
	scanf("%d",&a);
	scanf("%s",str);
	if(a>=3200){
		printf("%s\n",str);
	}
	else{
		puts("red");
	}
	return 0;
}


Measured memory_bytes: 760
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

string s, t;

int Find(const vector<int>& p, int pos) {
  if (p.empty()) return -1;
  auto it = upper_bound(p.begin(), p.end(), pos);
  if (it == p.end()) {
    return *p.begin();
  }
  return *it;
}

int main() {
  while (cin >> s >> t) {
    vector<int> p[26];
    for (int i = 0; i < (int)s.size(); ++i) {
      p[s[i] - 'a'].push_back(i);
    }
    long long cnt = 0;
    int pos = -1;
    for (int i = 0; i < (int)t.size(); ++i) {
      int next = Find(p[t[i] - 'a'], pos);
      if (next < 0) {
	pos = -1;
	break;
      }
      if (next <= pos) ++cnt;
      pos = next;
    }
    if (pos < 0) {
      cout << -1 << endl;
    } else {
      cout << cnt * s.size() + pos + 1 << endl;
    }
  }
}


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

const int MAX = 100;
int main() {
	int N, t[MAX + 2], v[MAX + 2]; // 始点と終点も走行時間0で制限速度0の区間と置いておく
	cin >> N;
	for (int i = 1;i <= N;i ++) cin >> t[i];
	for (int i = 1;i <= N;i ++) cin >> v[i];
	
	t[0] = 0;
	t[N + 1] = 0;
	v[0] = 0;
	v[N + 1] = 0;
	
	int m[MAX + 2]; // 更新された制限速度
	m[N + 1] = 0;
	for (int i = N;i >= 0;i --) {
		m[i] = min(m[i + 1] + t[i], v[i]); // i～i+1の地点における出していい限界速度
		// ここで、ある地点で次の地点の制限速度まで出しても常に大丈夫ということを成立させておく
		// これにより遠くの地点の制限速度を気にしなくてよくなるので問題が分割できる
		// 分割統治法が使えることは動的計画法の必要条件
	}
	int d = 0;
	
	int acc[MAX], con[MAX], dec[MAX], nowspd = 0;
	for (int i = 0;i < N;i ++) { // 最初の地点から順に動的計画法で求めていく
		acc[i] = min(min(2 * (m[i + 1] - nowspd), t[i + 1] + m[i + 2] - nowspd), t[i + 1] * 2); // i～i+1地点における加速時間の2倍
		dec[i] = max(nowspd * 2 + acc[i] - m[i + 2] * 2, 0); // i～i+1地点における減速時間の2倍
		con[i] = t[i + 1] * 2 - acc[i] - dec[i]; // i～i+1地点における等速時間の2倍
		d += (nowspd * 2 + nowspd * 2 + acc[i]) * acc[i]
			+ (nowspd * 2 + acc[i]) * con[i] * 2
			+ (nowspd * 2 + acc[i] + nowspd * 2 + acc[i] - dec[i]) * dec[i]; // i～i+1地点における移動距離の8倍
		nowspd += (acc[i] - dec[i]) / 2; // 現在の速度
	}
	cout << d / 8;
	if (d % 8) {
		cout << '.' << 125 * (d % 8);
	}
	return 0;
}
/* 
まず、最初にNから0に向かって制限速度の調整をして、制限速度一杯まで出してもセーフにしておく
そうすると、ある地点において初速sで入ったならなるべく次の区間の制限速度v[i+1]に近い値まで出せば良いということになる

次に、各区間について考える。
当然だが各区間では加速、等速、減速をこの順番で行うので、どれくらいの時間だけ加速/等速/減速するか求める。
これは各区間について初速s、制限速度v[i]、終速min(s+t[i],v[i+1])が分かっていれば求められる。
後は台形の公式で移動距離も分かるので、O(N)で求められるね！
*/

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

public class Main {

	public static void main(String[] args) {
		// テキスト入力
		Scanner sc = new Scanner(System.in);
		ArrayList<StringBuilder> list = new ArrayList<StringBuilder>();

		while (true) {

			StringBuilder out = new StringBuilder();
			int height = sc.nextInt();
			int width = sc.nextInt();

			if (height == 0 && width == 0) {
				break;
			}
			// #を出す処理
			// 行の数
			for (int h = 0; h < height; h++) {

				// ########の列
				if (h == 0 || h == height - 1) {
					for (int w = 0; w < width; w++) {
						out = out.append("#");
					}
					// #....#の列
				} else {
					for (int w = 0; w < width; w++) {
						if (w == 0 || w == width - 1) {
							out = out.append("#");
						} else {
							out = out.append(".");
						}
					}

				}
				out = out.append("\n");
			}
			list.add(out);
		}
		for (int index = 0; index < list.size(); index++)
			System.out.println(list.get(index));
	}
}

Measured memory_bytes: 20756
#include <iostream>
#include <math.h>
#include <list>
#include <algorithm>
#include <string.h>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define endl '\n'
#define int long long
#define mod 1000000007

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

const int INF = 1e9+7;
const int maxVal = 1e5 + 1;

int dp[101][maxVal];

int findMinWt(int value, vector<int>& w, vector<int>& val, int index) {
	if(index>=w.size()) {
		if(value==0) return 0;
		return INF;
	}

	if(dp[index][value]!=-1) return dp[index][value];

	int weight = findMinWt(value, w, val, index+1);
	if(val[index]<=value) weight = min(weight, w[index] + findMinWt(value-val[index], w, val, index+1));

	dp[index][value] = weight;

	return weight;
}

int32_t main() {
    
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n,W; cin>>n>>W;

	vector<int> w(n);
	vector<int> val(n);

	memset(dp, -1, sizeof dp);

	forn(i,n) {
		cin>>w[i]>>val[i];
	}	

	int fl=0;

	for(int i=maxVal-1;i>0;i--) {
		if(findMinWt(i, w, val, 0)<=W) {
			fl=1;
			cout<<i<<endl;
			break;
		}
	}

	if(!fl) cout<<-1<<endl;

	return 0;
}

Measured memory_bytes: 82520
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
#include <stdio.h>
using namespace std;
string s;
int  n, a, b, c, d;
int ans;
void dfs(int x, int y)
{
    if(x == y)
    {
        ans += 1;
        return;
    }
    if(x+1 < n && s[x+1] == '.')
    {
        dfs(x+1,y);
    }
    else if(x+2 < n && s[x+2] == '.')
    {
        dfs(x+2,y);
    }
}

int main()
{
    scanf("%d %d %d %d %d", &n, &a, &b, &c, &d);
    cin >> s;
    if(d > c)
    {
        dfs(a-1, c-1);
        dfs(b-1, d-1);
    }
    else
    {
        bool over = false;
        for (int i = b-1; i <= d-1; i++) {
            if (s[i-1] == '.' && s[i] == '.' && s[i+1] == '.') 
            {
                over = true;
            }
        }
        if(over)
        {
            dfs(a-1, c-1);
            dfs(b-1, d-1);
        }
    }
    
    if(ans == 2)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    return 0;
}



    



Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;

public class program{
    public static void Main(){
        Console.ReadLine();
        var S = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        Console.ReadLine();
        var T = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        var C = T.Count(t => linearSearch(S, t) != -1);
        Console.WriteLine(C);
    }

    public static int linearSearch(int[] array, int key){
        var Array = array.Concat(new[]{key}).ToArray();
        int i = 0;
        int n = array.Length;
        while(Array[i] != key){
            i++;
        }
        return i == n ? -1 : i;
    }
}



Measured memory_bytes: 31948
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

int main() {
  int m1, d1, m2, d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if (m1 == m2) {
    cout << 0 << endl;
  } else {
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
vector<char> Alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
vector<char> alphabet = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
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; }


int main()
{
  cout << fixed << setprecision(10);
  ll N;
  cin >> N;
  vector<ll> A(N);
  set<ll> s;
  rep(i,N) 
  {
    cin >> A[i];
    if(s.count(A[i]))
    {
      s.erase(A[i]);
    }
    else
    {
      s.insert(A[i]);
    }
  }
  cout << s.size() << endl;
  return 0;
}

Measured memory_bytes: 8728
//JSD
#include<iostream>
#include<vector>
#include<cmath>
#define ll long long 
using namespace std;
int main(){
	int n,d;
	cin>>n>>d;
	vector<int > v[n];
	for(int i=0;i<n;i++){
		for(int j=0;j<d;j++){
			int x;
			cin>>x;
			v[i].push_back(x);
		}
	}
	int count=(n*(n-1))/2;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			ll ans = 0;
			for(int k=0;k<d;k++){
				ans += pow(v[i][k]-v[j][k],2);
			}
			//cout<<ans<<"\n";
			long double dd = sqrt(1.0*ans);
			if(dd-floor(dd) > 0) count--;
		}
	}
	cout<<count;
	return 0;
}

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

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

    int x, n, temp, b = 0;
    set<int> nums;
    cin >> x >> n;
    if(n==0){
        cout << x;
        return 0;
    }else{
        for(int i=0; i<n; i++){
            cin >> temp;
            nums.insert(temp);
        }
    }

    while(1){
        if(nums.find(x-b) == nums.end()){
            cout << x-b;
            break;
        }else if(nums.find(x+b) == nums.end()){
            cout << x+b;
            break;
        }
        b++;
    }
    
    return 0;
}

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

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long T = sc.nextLong();
        long[] t = new long[N];
        int G = 0;
        t[0] = sc.nextLong();
        for (int i = 1; i < N; i++) {
            t[i] = sc.nextLong();
            if (t[i] - t[i - 1] > T) {
                G += t[i] - t[i - 1] - T;
            }
        }
        System.out.println(t[N - 1] + T - G);
    }
}

Measured memory_bytes: 66096
#pragma GCC optimize("trapv")
//#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
const int maxn = 2e5 + 55;
const int mod = 1e9 + 7;
ll n, k, r, s, p;
string t;
map<char, char> c;
map<char, int> sc;
bitset<maxn> ww;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> k >> r >> s >> p >> t;
	c['s'] = 'r';
	c['p'] = 's';
	c['r'] = 'p';
	sc['s'] = s;
	sc['p'] = p;
	sc['r'] = r;
	ll ans = 0;
	for(int i = 0; i < n; i++) {
		char w = c[t[i]];
		if(i-k<0||!ww.test(i-k)||w!=t[i-k]) {
			ww.set(i);
			ans += sc[w];
			t[i] = w;
		}
	}
	cout << ans;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<=int(b);++i)
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {

int main(void) {
  string s;cin>>s;
  if(s=="ARC")  {
    pr("ABC");
  } else {
    pr("ARC");
  }
  return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b=0;
  for(int i=0;i<3;i++){
    cin>>a;
    b+=a;
  }
  if(b>=22){
    cout<<"bust"<<"\n";
    return(0);
  }
  cout<<"win"<<"\n";
  return(0);
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
auto makeNdVector(int n, const T& v) {
  return vector<T>(n, v);
}

template<typename T, typename N, typename... Tail>
auto makeNdVector(const N& n, const Tail&... tail) {
  auto vec = makeNdVector<T>(tail...);
  vector<decltype(vec)> vecs(n, vec);
  return vecs;
}

int main() {
  int N, T; cin >> N >> T;
  auto dp = makeNdVector<LL>(N + 1, T + 5000, 0LL);
  vector<pair<LL, LL>> ps(N);
  for (int i = 0; i < N; ++i) {
    LL A, B; cin >> A >> B;  // time, score
    ps[i] = {A, B};
  }
  sort(ps.begin(), ps.end());

  for (int i = 1; i <= N; ++i) {
    auto [A, B] = ps[i-1];
    for (int j = 0; j < T + 5000; ++j) dp[i][j] = dp[i-1][j];
    for (int j = 0; j < T; ++j) {
      dp[i][j + A] = max(dp[i][j + A], dp[i-1][j] + B);
    }
  }

  LL vmax = 0;
  for (LL x : dp[N]) vmax = max(vmax, x);
  cout << vmax << endl;
}


Measured memory_bytes: 190820
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m=map(int,input().split())
uf=UnionFind(n)
for i in range(m):
  a,b=map(int,input().split())
  uf.union(a-1,b-1)
print(uf.group_count()-1)

Measured memory_bytes: 12952