akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env fsharpi

open System;

let ParseIntN ( str : string ) =
    str.Split(' ')
    |> Array.map System.Int32.Parse

let ParseInt1 ( str : string ) =
    ParseIntN str |> fun arr -> arr.[0]

let ParseInt2 ( str : string ) =
    ParseIntN str |> fun arr -> (arr.[0],arr.[1])

let ParseInt3 ( str : string ) =
    ParseIntN str |> fun arr -> (arr.[0],arr.[1],arr.[2])

let ReadLinesN ( n : int ) =
    fun _ -> Console.ReadLine()
    |> Seq.initInfinite
    |> Seq.take n

let ReadLines =
    fun _ -> Console.ReadLine()
    |> Seq.initInfinite
    |> Seq.takeWhile ((<>) null)

type 'a _heap =
    | Empty
    | Node of int * 'a * 'a _heap * 'a _heap

let rec _merge (comp : 'a -> 'a -> int) (h1 : 'a _heap) (h2 : 'a _heap) =
    let Height = function
        | Empty -> 0
        | Node(h, _, _, _) -> h
    let MakeTree x a b =
        let ha = Height a 
        let hb = Height b
        if ha >= hb then Node(hb + 1, x, a, b) else Node(ha + 1, x, b, a)
    match h1,h2 with
    | x, Empty -> x
    | Empty, x -> x
    | (Node(_, x, l1, r1) as n1), (Node(_, y, l2, r2) as n2) when comp x y <= 0 -> MakeTree x l1 (_merge comp r1 n2)
    | (Node(_, x, l1, r1) as n1), (Node(_, y, l2, r2) as n2) when comp x y > 0 -> MakeTree y l2 (_merge comp n1 r2)
    | _,_ -> failwith "empty"

let _head (h : 'a _heap) =
    match h with
    | Empty -> failwith "empty"
    | Node(h, x, l, r) -> x

let _tail (comp : 'a -> 'a -> int) (h : 'a _heap) =
    match h with
    | Empty -> failwith "empty"
    | Node(_, _, l, r) -> _merge comp l r

type 'a pqueue = ('a -> 'a -> int)  * 'a _heap
let PriorityQueue (comp : 'a -> 'a -> int)  =
    ( comp , Empty )

let IsEmpty (q : 'a pqueue) : bool =
    q |> function | ( _ , h )  -> h = Empty

let Top (q : 'a pqueue) =
    q |> function | ( _ , h )  -> _head h

let Push (q : 'a pqueue) (v : 'a) =
    q |> function | ( c , h )  -> Node(1,v,Empty,Empty) |> _merge c h |> fun h' -> ( c, h' )

let Pop (q : 'a pqueue) =
    q |> function | ( c , h )  -> (_head h, ( c, _tail c h) )

let rec toSeq (q : 'a pqueue) =
    q |> Pop |> fun (h,t) -> seq{ yield h; yield! toSeq t }

let cnt pq =
    let rec doit pq h c =
        if IsEmpty pq then
            c
        else
            let (h', pq') = Pop pq
            if h' = h then
                doit pq' h (c+1)
            else
                c
    doit pq (Top pq) 0

let (n,t) = ParseInt2 <| Console.ReadLine()
Console.ReadLine()
|> ParseIntN
|> Seq.fold (fun (pq,mv) a -> (Push pq (a - mv), min mv a)) (PriorityQueue (fun a b -> -compare a b), System.Int32.MaxValue)
|> fun (pq,_) -> cnt pq
|> Console.WriteLine



Measured memory_bytes: 30392
S=input()
N=len(S)

st=0
en=N
en2=(en+1)//2
for i in range(st,en2):
#  print(i)
  if S[i]!=S[en-1-i]:
    print("No")
    exit()
st=0
en=(N-1)//2
en2=(en+1)//2
for i in range(st,en2):
#  print(i)
  if S[i]!=S[en-1-i]:
    print("No")
    exit()
st=(N+3)//2
en=N
en2=(en+1)//2
for i in range(st,en2):
#  print(i)
  if S[i]!=S[en-1-i]:
    print("No")
    exit()
print("Yes")


Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

n,m=map(int,input().split())
S=input()
step=[]
def dfs(node):
    for i in range(m,0,-1):
        if node-i<0:
            continue
        # print(S[node-i])
        if S[node-i]=="0":
            # print(12345678)
            step.append(i)
            dfs(node-i)
            return

dfs(n)
step=step[::-1]
if sum(step)!=n:
    print(-1)
else:
    print(*step)


Measured memory_bytes: 125560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K, A, B;
  int i;
  
  cin >> K >> A >> B;

  while (A<=B)
  {
      if (A%K==0)
      {
          i++;
      }

      A++;
  }

  if (i>=1)
  {
      cout << "OK";
  }

  else {
      cout << "NG";
  }
  
}

Measured memory_bytes: 3624
#include <iostream>


using namespace std;

int main(){

    int N, K;
    cin >> N >> K;
    
    int ans = 0;
    
    for (int i = 1; i <= N; i++) {
        if (i+K-1 <= N) {
            ans += 1;
        }else{
            break;
        }
    }
    
    
    
    cout << ans << endl;
    
    
    
    
    
    return 0;
    
}


Measured memory_bytes: 256
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define x real()
#define y imag()
#define fi first
#define se second
#define pii pair<int, int>

const int N = 1e5 + 100;
int cnt[N];

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int n, k, q;
	cin >> n >> k >> q;
	int a[q];
	for (int i = 0; i < q; i++) {
		cin >> a[i];
		cnt[a[i]]++;
	}
	for (int i = 1; i <= n; i++) {
		if (k - (q - cnt[i]) > 0) {
			cout << "Yes\n";
		} else {
			cout << "No\n";
		}
	}
}



Measured memory_bytes: 2176
#include<iostream>
using namespace std;
#include<iostream>
using namespace std;
int main(){
    int H,W;
    while(1){
        cin>>H>>W;
        if(H==0&&W==0)break;    
        for(int i=0;i<H;i++){       
            for(int j=0;j<W;j++){
                if(i==0||i==H-1||j==0||j==W-1){
                    cout<<"#";
                }else{cout<<".";}
                            
                }
            cout<<endl;
        } 
    cout<<endl;
    }
    return 0;
} 


Measured memory_bytes: 3120
N=int(input())
T,A=map(int,input().split())
H=list(map(int,input().split()))
ans=0;m=100000000
A=A*1000;T=T*1000
for i in range(N):
    if abs(A-(T-(H[i]*6))) < m:m=abs(A-(T-(H[i]*6)));ans=i+1
print(ans)

Measured memory_bytes: 9160
#include <iostream>
#include <vector>

using namespace std;

const int MOD = 1000000007;

int main(){
	int N;
	while(cin >> N){
		vector<int> x(N);
		for(int i=0;i<N;i++) cin >> x[i];
		long long res = 1;
		vector<int> c(N, 0);
		c[0] = 1;
		int pre = 0;
		for(int i=1;i<N;i++){
			int enable = (x[i-1]+1)/2;
			int cur = max(pre, i-enable);
			c[cur]++;
			pre = cur;
		}
		int s = 0;
		for(int i=0;i<N;i++){
			s += c[i];
			res *= s-i;
			res %= MOD;
		}
		cout << res << endl;
	}
}



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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> l(m), r(m);
  for (int i = 0; i < m; i++) {
    cin >> l[i] >> r[i];
  }
  int min_r = *min_element(r.begin(), r.end());
  int max_l = *max_element(l.begin(), l.end());
  cout << max(0, min_r - max_l + 1) << '\n';
  return 0;
}

Measured memory_bytes: 3864
#include <iostream>
#include <vector>
using namespace std;
vector<int> A,B;

void CountingSort(int k,int n){
  vector<int> C(k+1,0);
  for(int j=0;j<n;j++){
    C[A[j]]++;
  }
  for(int i=1;i<=k;i++){
    C[i]+=C[i-1];
  }
  for(int j=n-1;j>=0;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
}

int main(){
  int n;
  cin>>n;
  A.resize(n);
  B.resize(n+1);
  for(int i=0;i<n;i++){
    cin>>A[i];
  }
  CountingSort(10000,n);
  for(int i=1;i<=n;i++){
    cout<<B[i];
    if (i!=n) cout<<" ";
  }
  cout<<endl;
  return 0;
}



Measured memory_bytes: 18372
#include <iostream>
#include <vector>
#include <set>

using namespace std;

int main() {
    const unsigned long long MAXN = 1e5+5;
    int N, M;
    cin >> N >> M;

    vector<vector<int>> jobs(MAXN);
    for(int idx = 0; idx < N; idx++) {
        int A, B;
        cin >> A >> B;
        
        // add a job that takes A days to complete
        // and rewards B
        jobs[A].push_back(B);
    }

    long long int ans = 0LL;

    // multiset is sorted
    multiset<int, greater<int>, allocator<int>> available;

    // start from the M, go backwards
    // and take the best possible job
    for(int day = M - 1; day >= 0; day--) {
        // jobs that take M-day days to complete
        // ie. we can still take them
        for(int job: jobs[M - day])
            available.insert(job);

        if(!available.empty()) {
            // since multiset is sorted
            // we take the best job first
            ans += *available.begin();
            available.erase(available.begin());
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 7808
x = int(input())
if x == 2:
         print(x)
         exit()
for i in range(x,100004):
         for j in range(2,max(3,int(i**(1/2))+1)):
                  if i % j == 0:
                           break
         else:
                  print(i)
                  exit()
                  


Measured memory_bytes: 2940
#include <cstdio>

//FILE *fin = fopen("a.in", "r"), *fout = fopen("a.out", "w");
#define fin stdin
#define fout stdout

#define MAXN 200009

int n;
char s[MAXN + 10];

inline bool go(int x, int y) {
    if (x > y)
        return 0;
    while (x < y) {
        if (s[x + 2] == '.')
            x += 2;
        else if (s[x + 1] == '.')
            x++;
        else
            return 0;
    }
    return 1;
}

int main() {
    int a, b, c, d;
    fscanf(fin, "%d%d%d%d%d ", &n, &a, &b, &c, &d);
    fgets(s + 1, MAXN + 5, fin);

    if (c < d) {
        if (go(b, d) && go(a, c))
            fprintf(fout, "Yes\n");
        else
            fprintf(fout, "No\n");
    } else {
        int poz = b;
        while (poz + 1 <= n && (s[poz - 1] == '#' || s[poz] == '#' || s[poz + 1] == '#'))
            poz++;
        if (go(a, poz - 1) && go(poz + 1, c) && go(b, poz) && go(poz, d))
            fprintf(fout, "Yes\n");
        else
            fprintf(fout, "No\n");
    }

    fclose(fin);
    fclose(fout);
    return 0;
}


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

vector<int> X, Y;
vector<int> SX, TX, SY, TY;
vector<int> data;

void dfs(vector<int> vec, int k, bool xaxis){
    vector<pair<int, int>> cvec;
    if(xaxis){
        for(auto v: vec)
            cvec.push_back({X[v], v});
    }else{
        for(auto v: vec)
            cvec.push_back({Y[v], v});
    }
    sort(cvec.begin(), cvec.end());
    
    int m = cvec.size();
    data[k] = cvec[m/2].second;
    
    vector<int> lvec;
    for(int i=0; i<m/2; i++){
        lvec.push_back(cvec[i].second);
    }
    if(lvec.size() > 0){
        dfs(lvec, 2*k+1, xaxis^true);
    }
    vector<int> rvec;
    for(int i=m/2+1; i<m; i++){
        rvec.push_back(cvec[i].second);
    }
    if(rvec.size() > 0){
        dfs(rvec, 2*k+2, xaxis^true);
    }
}

void buildtree(){
    int N_ = X.size();
    int N = 1;
    while(N <= N_)
        N <<= 1;
    data.assign(2*N-1, -1);
    
    vector<int> vec;
    for(int i=0; i<N_; i++)
        vec.push_back(i);
    
    dfs(vec, 0, true);
}

void query(int k, int sx, int tx, int sy, int ty, bool xaxis, vector<int> &ans){
    if(data[k] == -1) return;
    
    if(xaxis){
        if(sx <= X[data[k]] && X[data[k]] <= tx && sy <= Y[data[k]] && Y[data[k]] <= ty)
            ans.push_back(data[k]);
            
        if(sx <= X[data[k]])
            query(2*k+1, sx, tx, sy, ty, xaxis^true, ans);
        if(X[data[k]] <= tx)
            query(2*k+2, sx, tx, sy, ty, xaxis^true, ans);
    }else{
        if(sx <= X[data[k]] && X[data[k]] <= tx && sy <= Y[data[k]] && Y[data[k]] <= ty)
            ans.push_back(data[k]);
        
        if(sy <= Y[data[k]])
            query(2*k+1, sx, tx, sy, ty, xaxis^true, ans);
        if(Y[data[k]] <= ty)
            query(2*k+2, sx, tx, sy, ty, xaxis^true, ans);
    }
}

int main(){
//    ios::sync_with_stdio(false);
//    cin.tie(0);
    
    int N;
//    cin >> N;
    scanf("%d", &N);
    for(int i=0; i<N; i++){
        int x, y;
//        cin >> x >> y;
        scanf("%d %d", &x, &y);
        X.push_back(x);
        Y.push_back(y);
    }
    
    buildtree();
    
    int Q;
//    cin >> Q;
    scanf("%d", &Q);
    for(int i=0; i<Q; i++){
        int sx, tx, sy, ty;
//        cin >> sx >> tx >> sy >> ty;
        scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
        
        vector<int> ans;
        query(0, sx, tx, sy, ty, true, ans);
        sort(ans.begin(), ans.end());
        for(auto v: ans){
//            cout << v << endl;
            printf("%d\n", v);
        }
        printf("\n");
        
//        cout << endl;
        
//        SX.push_back(sx);
//        TX.push_back(tx);
//        SY.push_back(sy);
//        TY.push_back(ty);
    }
    
    
    return 0;
}

Measured memory_bytes: 28256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define PI (3.14159265358979323846)
#define INF (2147483647)
#define INF_LL (9223372036854775807)
#define DIV_NUM (1000000007)
typedef long long ll;

// 配列初期化テンプレ
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}


int main() {

	int A, B, H, M;
	cin >> A >> B >> H >> M;

	double x1, y1, x2, y2;

	double thetaH = 2 * PI / 12.0 * ((double)(H)+(double)(M)/60.0);
	double thetaM = 2 * PI / 60.0 * (double)(M);

	x1 = A * sin(thetaH);
	y1 = A * cos(thetaH);
	x2 = B * sin(thetaM);
	y2 = B * cos(thetaM);

	double ans = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));

	cout << setprecision(20) << ans << endl;

	return 0;

}


Measured memory_bytes: 4064
S = input().strip()

MOD = 10 ** 9 + 7

N = len(S)
DP = [[0] * 13 for i in range(N+1)]
DP[0][0] = 1

for _i, s in enumerate(S):
    i = _i + 1

    if s == '?':
        candidate = range(10)
    else:
        candidate = [int(s)]

    for j in range(13):
        for c in candidate:
            m = (j * 10 + c) % 13
            DP[i][m] += DP[i-1][j]
    for j in range(13):
        DP[i][j] %= MOD

print(int(DP[-1][5]))


Measured memory_bytes: 61992
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
#define vi vector<ll>
#define pi pair<ll,ll>
#define vp vector<pi>
#define pb push_back
#define mp map<ll,ll>
#define endl '\n'
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int32_t main(){
    fast;
    ll a,b;
    cin>>a>>b;
    cout<<6-(a+b);
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val input = readLine()!!.split(" ").map { it.toInt() }
    val n = input[0]
    val k = input[1]

    val l = readLine()!!.split(" ").map { it.toInt() }

    print(l.sorted().reversed().subList(0, k).sum())

}

Measured memory_bytes: 37720
//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n,m;cin>>n>>m;
  vector<ll>a(m);
  rep(i,0,m)cin>>a[i];
  rep(i,0,m)res+=a[i];
  ans(res>n,-1,n-res);
  return 0;
}

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

int main(){
    int A[3][3];
    for (int i=0; i<3; i++){
        for (int j=0; j<3; j++){
            cin >> A[i][j];
        }
    }
    int N;
    cin >> N;
    int B[N];
    for (int i=0; i<N; i++){
        cin >> B[i];
    }

    int check[3][3];
    for (int i=0; i<3; i++){
        for (int j=0; j<3; j++){
            check[i][j] = 0;
        }
    }
    for (int i=0; i<3; i++){
        for (int j=0; j<3; j++){
            for (int n=0; n<N; n++){
                if (A[i][j] == B[n]){
                    check[i][j] = 1;
                }
            }
        }
    }
    string ans = "No";
    if (check[0][0] == 1 && check[0][1] == 1 && check[0][2] == 1) ans = "Yes";
    if (check[1][0] == 1 && check[1][1] == 1 && check[1][2] == 1) ans = "Yes";
    if (check[2][0] == 1 && check[2][1] == 1 && check[2][2] == 1) ans = "Yes";
    if (check[0][0] == 1 && check[1][0] == 1 && check[2][0] == 1) ans = "Yes";
    if (check[0][1] == 1 && check[1][1] == 1 && check[2][1] == 1) ans = "Yes";
    if (check[0][2] == 1 && check[1][2] == 1 && check[2][2] == 1) ans = "Yes";
    if (check[0][0] == 1 && check[1][1] == 1 && check[2][2] == 1) ans = "Yes";
    if (check[0][2] == 1 && check[1][1] == 1 && check[2][0] == 1) ans = "Yes";

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

n = ni()
a = list(li())

ap = [ai+1 for ai in a]
am = [ai-1 for ai in a]

cnt = Counter(am+a+ap)

print(cnt.most_common(1)[0][1])

Measured memory_bytes: 29960
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		System.out.println(solve(n));
		in.close();
	}

	private static int solve(int n) {
		if (n % 2 == 0)
			n -= 1;
		return n / 2;
	}
}

Measured memory_bytes: 21844
#include <iostream> 

using namespace std;

int main() {
	int m;
	int d;
	cin >> m >> d;
	int k = 0;
	for (int i = 10; i <= d; i++) {
		int x = i % 10;
		int y = i / 10;
		if (x >= 2 && y >= 2 && (x * y <= m) && (1 <= x * y)) {
			k++;
		}
	}
	cout << k;
}

Measured memory_bytes: 256
<?php
$n = intval(trim(fgets(STDIN)));
$a = array_map("intval", explode(" ", trim(fgets(STDIN))));
$sum = 0;
$mod = 10**9+7;
for($i = 0; $i < 60; $i++){
  $c = 0;
  foreach($a as $b){
    $c += ($b >> $i) & 1; 
  }
  $c *= $n-$c;
  $c %= $mod;
  $c *= (1<<$i) % $mod;
  $c %= $mod;
  $sum += $c;
  $sum %= $mod;
}
echo $sum;


Measured memory_bytes: 40936
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

int n,m,o,x,y,p[100100],r[100100],s[100100];
vector<int> v[100100];
vector<int> graph[100100];
bool vis[100100];

void dfs(int u){
  if(vis[u]) return;
  vis[u]=1;
  for(int i=0;i<graph[u].size();i++){
    int v = graph[u][i];
    dfs(v);
  }
}


int main() {
  scanf("%d %d",&n,&m);
  for(int i=1;i<=n;i++){
    p[i]=i;
    r[i]=1;
    s[i]=1;
    scanf("%d",&o);
    for(int j=0;j<o;j++){
      scanf("%d",&x);
      v[x].pb(i);
    }
  }
  for(int i=1;i<=m;i++){
    if(v[i].size()>1) x = v[i][0];
    for(int j=1;j<v[i].size();j++){
      y = v[i][j];
      graph[x].pb(y);
      graph[y].pb(x);
    }
  }
  dfs(1);
  bool check=true;
  for(int i=1;i<=n;i++){
    if(!vis[i]) check=false;
  }
  if(check) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 10240
import heapq

N = int(input())
a    = [ int(x) for x in input().split() ]
arev = [ -x for x in a[::-1] ]

Hl = a[:N]
heapq.heapify(Hl) #; print(Hl)
suml = sum(Hl)
sumL = [suml]

Hr = arev[:N]
heapq.heapify(Hr) #; print(Hr)
sumr = sum(Hr)
sumR = [sumr]

for i in range(N):
    x = heapq.heappushpop(Hl, a[N+i])
    #print(i, x, Hl, sum(Hl))
    suml += -x + a[N+i]
    sumL.append(suml)
    
for i in range(N):
    x = heapq.heappushpop(Hr, arev[N+i])
    #print(i, x, Hr, sum(Hr))
    sumr += -x + arev[N+i]
    sumR.append(sumr)

#print(sumL, sumR)
dif = [ i+j for i, j in zip(sumL, sumR[::-1])]  #; print(dif)
print(max(dif))

Measured memory_bytes: 43436
import java.util.Scanner;

/**
 * 
 */

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner as = new Scanner(System.in);
		
		int n=as.nextInt();
		long tr;
		int j = 0,k = 0;
		long jug[] = new long[n];
		
		
		
		
		
		for(int i=0;i<n;i++){
			
			jug[i]=as.nextInt();
	
		}
		
		
		for(int l=n-1;l>=0;l--){
			
			String str=String.valueOf(jug[l])+" ";
			if(l==0)
				str=String.valueOf(jug[l])+"\n";
			
				System.out.print(str);
				
			
		}

	}

}

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

#define P(s) cout << s << endl

int main() {
    int64_t p = 1;
    int32_t n;
    cin >> n;
    
    for (int64_t i = 0; i < n; ++i) {
        p *= i + 1;
        p %= 1000000007;
    }
    
    P(p);
}

Measured memory_bytes: 256
def dfs(i, f, sum):
  if i == 3:
    if sum == 7:
      print(f + '=7')
      exit()
  else:
    dfs(i + 1, f + '-' + s[i + 1], sum - int(s[i + 1]))
    dfs(i + 1, f + '+' + s[i + 1], sum + int(s[i + 1]))
    
s = input()
dfs(0, s[0], int(s[0]))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
using namespace std;
#define N 1005
int n,m,a,b,i,j;char mp[N][N];
int main(){
	scanf("%d%d%d%d",&n,&m,&a,&b);
	for (i=1;i<=n;i++) for (j=1;j<=m;j++) mp[i][j]='.';
	if (n&1){
		i=n,j=1;
		while (a&&j+1<=m) mp[i][j]='<',mp[i][j+1]='>',j+=2,a--;
	}
	if (m&1){
		i=n,j=m;
		while (b&&i>1) mp[i][j]='v',mp[i-1][j]='^',i-=2,b--;
	}
	for (i=n/2;i>=1;i--)
		for (j=1;j<=m/2;j++){//分成(n/2)*(m/2)个2*2的矩形 
			int x=i*2-1,y=j*2-1;
			if ((n&1)&&(m&1)&&a==1&&b==1&&i==1&&j==m/2){
				mp[x][y]='^';mp[x+1][y]='v';b--;
				mp[x][y+1]='<';mp[x][y+2]='>';a--;
			}
			if (a&&b<2){
				mp[x][y]='<';mp[x][y+1]='>';a--;
				if (a){
					x++;
					mp[x][y]='<';mp[x][y+1]='>';a--;
				}
			} else if (b){
				mp[x][y]='^';mp[x+1][y]='v';b--;
				if (b){
					y++;
					mp[x][y]='^';mp[x+1][y]='v';b--;
				}
			}
		}
	if (a||b) puts("NO");
	else{
		puts("YES");
		rep (i,1,n){rep (j,1,m) printf("%c",mp[i][j]);puts("");}
	}
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<ll> h(n), v(n);
  for (int i = 0; i < n; i++) cin >> h[i];
  for (int i = 0; i < n; i++) cin >> v[i];

  vector<ll> bit(n + 1, 0);  // 列の右端がiのときの、総和の最大値
  for (int i = 0; i < n; i++) {
    ll res = 0;
    for (int x = h[i]; x > 0; x -= x & -x) res = max(res, bit[x]);
    for (int x = h[i]; x < bit.size(); x += x & -x) bit[x] = max(bit[x], res + v[i]);
  }

  ll ans = 0;
  for (int x = n; x > 0; x -= x & -x) ans = max(ans, bit[x]);
  cout << ans << endl;
}


Measured memory_bytes: 4992
#include<stdio.h>
#include<stdlib.h>
#define MAX 20000  // スタックの最大値

typedef struct{
  int top;         // スタックポインタ(一番上の位置)
  int S[MAX];
}Stack;


// スタック st の初期化
void initialize(Stack *st)
{
  st->top = 0;
  st->S[st->top] = 0;
}

// スタック st が空かどうかを確認
int isEmpty(Stack *st)
{
  return st->top == 0;
}

// スタック st が一杯かどうかを確認
int isFull(Stack *st)
{  
  return st->top >= MAX - 1;
}

// スタック st に要素 x をプッシュ(一番上に要素を追加)
void push(int x, Stack *st)
{
  if (isFull(st)) 
    exit(1);

  st->top++;
  st->S[st->top] = x;
}

// スタック st から要素をポップ(一番上の要素を取り出す)
int pop(Stack *st) {
  if (isEmpty(st)) 
    exit(1);

  st->top--;
  return st->S[st->top+1];
}


int main(void)
{
  Stack st1;     // '\' の開始位置を格納するスタック
  Stack st2_j;   // 各水たまりの最も左の'\' の位置を格納するスタック
  Stack st2_a;   // 各水たまりの水量を格納するスタック

  // スタック初期化
  initialize(&st1);
  initialize(&st2_j);
  initialize(&st2_a);

  char c;
  int sum = 0;  // 水たまりの総水量

  // 地形を読み込み，各水たまりの水量を計算
  for (int i = 0; (c = getchar()) != EOF; i++) {
    if (c == '\\') {                                 // '\' が出た時の処理
      // 位置 i を st1 にプッシュ(write your code)
    	push(i,&st1);
    }else if (!isEmpty(&st1) && c == '/') {          // '/' が出た時の処理
      // 水たまりの総水量 sum を更新(write your code)
    	int j = pop(&st1);
    	sum+=i - j;
      // st2_j と st2_a を用いて水たまりの水量を更新 
      int a = i - j;   // 更新する水たまりの水量を a に格納していく
      while (!isEmpty(&st2_j) && st2_j.S[st2_j.top] > j) {  // 最も左の '\' の位置が j よりも大きい場合，以下を繰り返す
        // 水たまりの水量を求めていく (write your code)
      	a += pop(&st2_a);
      	pop(&st2_j);
      }
      // 更新した水たまりの「最も左の'\' の位置」および「水量」を更新 (write your code)
    	push(j,&st2_j);
    	push(a,&st2_a);
    }
  }

  printf("%d\n", sum);       // 水たまりの総水量を出力
  printf("%d", st2_a.top);   // 水たまりの個数を出力

  // 各水たまりの水量を断面図の左から出力(スタックの底から出力)
  for (int i = 1; i <= st2_a.top; i++) 
    printf(" %d", st2_a.S[i]);  
  printf("\n");

  return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m,x; cin >> n >> m >> x;
    int res=1e9;
    vector<int> c(n);
    vector<vector<int>> a(n,vector<int>(m));
    for(int i=0;i<n;i++){
        cin >> c[i];
        for(int j=0;j<m;j++){
            cin >> a[i][j];
        }
    }
    for(int i=1;i<(1<<n);i++){
        vector<int> r(m,0);
        int sum=0;
        bool ok=1;
        for(int j=0;j<n;j++){
            if((1<<j)&i){
                for(int k=0;k<m;k++){
                    r[k]+=a[j][k];
                }
                sum+=c[j];
            }
        }
        for(int j=0;j<m;j++){
            if(r[j]<x)ok=0;
        }
        if(ok){
            res=min(res,sum);
        }
    }
    if(res==1e9){
        printf("-1\n");
    }else{
        printf("%d\n",res);
    }
}

Measured memory_bytes: 3756
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <utility>
#define FR first
#define SE second
#define lowbit(x) (x&-x)
#define inf 0x3f3f3f3f3f3f3f3fLL

using namespace std;

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

inline void add(pr &x,pr y) {
  x.FR+=y.FR;x.SE+=y.SE;
}

pr sumv[100005];

void add(int x,pr num) {
  for(;x;x-=lowbit(x)) add(sumv[x],num);
}

pr sum(int x,int n) {
  pr s(0,0);
  for(;x<=n;x+=lowbit(x)) add(s,sumv[x]);
  return s;
}

void add(int l,int r,pr num) {
  add(l-1,pr(-num.FR,-num.SE));
  add(r,num);
}

int num[100005];

int main() {
  int n,m;
  scanf("%d%d",&n,&m);
  for(int i=1;i<=n;i++) scanf("%d",&num[i]);
  ll s=0;
  for(int i=1;i<n;i++)
    if (num[i]<num[i+1]) {
    	add(num[i]+1,num[i+1],pr(1,-num[i]-1));
    	s+=num[i+1]-num[i];
	}
	else {
		if (num[i]<m) add(num[i]+1,m,pr(1,-num[i]-1));
		add(1,num[i+1],pr(1,m-num[i]-1));
		s+=m-num[i]+num[i+1];
	}
  ll ans=inf;
  for(int i=1;i<=m;i++) {
  	pr t=sum(i,m);
  	ans=min(ans,s-(ll)t.FR*i-t.SE);
  }
  printf("%lld\n",ans);
  return 0;
}

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

public class Main{
	public static void main(String[]args) {
		
		Scanner sc=new Scanner(System.in);
		
		int N=sc.nextInt();
		int[] p=new int[N];
		int[] copy=new int[N];
		
		for(int i=0;i<N;i++) {
			p[i]=sc.nextInt();
			copy[i]=p[i];
		}
		
		Arrays.sort(copy);
		
		int count=0;
		
		for(int i=0;i<N;i++) {
			if(p[i]==copy[i]) {
				
			}else {
				count++;
			}
		}
		
		if(count==0||count==2) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
		
		sc.close();
	}
}

Measured memory_bytes: 23508
import math
from functools import reduce
import itertools
k = int(input())
a = [i for i in range(1,k+1)]
s =0
#同じ数字３つの時
s = int(k*(k+1)/2)
#同じ数字２つと違う数字一つ
for q in itertools.combinations(a,2):
  s += reduce(math.gcd,q)*3*2
for t in itertools.combinations(a,3):
  s += reduce(math.gcd,t)*6
print(s)

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

int main(){
int n;
  cin >> n;
  int ans=0;
  int a,b;
  rep(i, n){
    cin >> a >> b;
    ans += b-a+1;
  }
  cout << ans << endl;

	return 0;
}


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

#define MAX 500
 
int main()
{
    int H, W;
 
    while (cin >> H >> W, H | W) {
	string s[MAX];
	int field[MAX][MAX];
 
	for (int i = 0; i < H; i++) {
	    cin >> s[i];
	    for (int j = 0; j < W; j++) { 
		if(s[i][j] == '*') {
                    field[i][j] = 0;
		} else {
		    if (j > 0) {
                        field[i][j] = field[i][j-1] + 1;
		    } else {
                        field[i][j] = 1;
                    }
                }
	    }
	}
 
	int res = 0;
	for (int i = 0; i < W; i++) {
	    for (int j = 0; j < H; j++) {
		int width = 1e9;
		for (int k = j; k < H; k++) {
		    width = min(width, field[k][i]);
		    res = max(res, (k - j + 1) * width);
		}
	    }
	}
	cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 4276
n = int(input())
v = list(map(int,input().split()))
b = []
c = []

for i, vv in enumerate(v):
    if i%2 == 0:
        b.append(vv)
    else:
        c.append(vv)

b_set = {}
c_set = {}

for bb in b:
    if not bb in b_set.keys():
        b_set[bb] = 1
    else:
        b_set[bb] += 1

for cc in c:
    if not cc in c_set.keys():
        c_set[cc] = 1
    else:
        c_set[cc] += 1

b_sorted = []
c_sorted = []

for key, value in b_set.items():
    b_sorted.append([value,key])
for key, value in c_set.items():
    c_sorted.append([value,key])

b_sorted = sorted(b_sorted, reverse=True)
b_sorted += [[0,0]]
c_sorted = sorted(c_sorted, reverse=True)
c_sorted += [[0,0]]


if b_sorted[0][1] != c_sorted[0][1]:
    ans = n - b_sorted[0][0] - c_sorted[0][0]
else:
    try1 = n - b_sorted[1][0] - c_sorted[0][0]
    try2 = n - b_sorted[0][0] - c_sorted[1][0]
    ans = min(try1,try2)

print(ans)

Measured memory_bytes: 25152
import itertools
n = int(input())
x = tuple(map(int, input().split()))
y = tuple(map(int, input().split()))
result = [i for i,j in enumerate(itertools.permutations(range(1, n+1), n)) if j in {x, y}]
#print(result)
print(abs(result[0] - result[1])) if x != y else print(0)

Measured memory_bytes: 40940
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265
 
const ll N = 100005;

void solve(){
    ll n;
    cin>>n;
    set<string> s;
    rep(i,0,n){
        string t;
        cin>>t;
        s.insert(t);
    }
    cout<<s.size()<<endl;
    return;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll no;
    // cin>>no;
    no = 1;
    while(no--){
        solve();
    }
    return 0;
}

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

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

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

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

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int k = lower_bound(l.begin(), l.end(), l[i] + l[j]) - l.begin();
      ans += max(0, k - j - 1);
    }
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define Size(x) ((int)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    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;
    }

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo,gyakugen
//mint,dijkstra

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        string s;
        cin>>s;
        if(Size(s)<=3){
            cout<<"No"<<endl;
            return 0;
        }
        if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I'){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }

Measured memory_bytes: 256
import java.util.Scanner;

class Main{


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int[] A = new int[n+2];
		A[0] = 0;				//始点
		A[n+1] = 0;				//終点
		for(int i = 1;i <= n;i++){
			A[i] = sc.nextInt();
		}
		long sum = 0;
		for(int i = 0;i <= n;i++){
			sum +=Math.abs(A[i+1]-A[i]);
		}
		
	//	System.out.println(sum);
		for(int i = 1;i <= n;i++){
			long dis = 0;
			if((A[i] >= A[i-1] && A[i] <= A[i+1]) ||(A[i] <= A[i-1] && A[i] >= A[i+1])){
				dis = 0;
			}else{
				long near = Math.min(Math.abs(A[i]-A[i-1]),Math.abs(A[i]-A[i+1]));
				dis = 2*near;
			}
			System.out.println(sum - dis);
		}
		
		
		

	}



}

class UnionFind{
	int[] parent;
	public UnionFind(int N){
		this.parent = new int[N];
		for(int i = 0; i < N;i++){
			parent[i] = i;
		}
	}
	public int root(int x){			//根要素を取得
		if(parent[x] == x){			//初期状態
			return x;
		}else{
			return parent[x] = root(parent[x]);    	//再帰によって根を取得
		}
	}
	public void unite(int x,int y){ 	//統合メソッド
		if(same(x,y)){					//同じ根なら終了
			return;
		}
		int xroot = root(x);
		int yroot = root(y);
		parent[xroot] = yroot;			//統合
		return;

	}

	public boolean same(int x,int y){			//根が同じか（同じグループに属しているか）を判定
		return(root(x) == root(y));
	}
}



class Pair implements Comparable{
	long from;		//p
	long end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return num - otherpair.num;
	}
}



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

int main(){
  int N;
  cin >> N;
  int waru,x,tmp = 100000;
  for(int i = 0;i < N;i++){
    cin >> x;
    waru = 0;
    while(!(x % 2)){
      waru++;
      x /= 2;
    }
    if(tmp > waru)tmp = waru;
  }
  
  cout << tmp << endl;
}

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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}

lint P(lint n, lint k) {
  if(k == 1) { return n; }
  return (n*(P(n-1,k-1)%1000000007)%1000000007);
}


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

  map<lint,lint> mp;
  for(lint i=n;i>=2;i--) {
    lint cur=i;

    for(int j=2;j<=cur;j++) {
      while(cur%j == 0) {
        cur /= j;
        mp[j]++;
      }
    }

  }

  lint ans=1;
  for(auto itr: mp) { ans = (ans*(itr.second+1))%1000000007; }

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


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
void Main()
{
  int x1, x2, x3, x4, x5;
  
  cin >> x1 >> x2 >> x3 >> x4 >> x5;
  
  if(x1 == 0)
    printf("%d", 1);
  if(x2 == 0)
    printf("%d", 2);
  if(x3 == 0)
    printf("%d", 3);
  if(x4 == 0)
    printf("%d", 4);
  if(x5 == 0)
    printf("%d", 5);
  
  
}
 
int main()
{
  std::cout << std::fixed << std::setprecision(15);
  Main();
}

Measured memory_bytes: 3748
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    int n, x;
    cin >> n >> x;
    long cnt = 0, prev = 0;
    for (int i=0; i<n; i++) {
        long a;
        cin >> a;
        long dif = max(0l, prev + a - x);
        cnt += dif;
        prev = a - dif;
    }
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 764
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
static const ll INF = 1e18;


int main() {

    vector<ll> s, t;
    ll A, B, Q;
    scanf("%lld %lld %lld", &A, &B, &Q);

    s.push_back(-INF);
    t.push_back(-INF);
    ll s_, t_;
    for(int i = 0; i < A; i++) {
        scanf("%lld", &s_);
        s.push_back(s_);
    }
    for(int i = 0; i < B; i++) {
        scanf("%lld", &t_);
        t.push_back(t_);
    }
    s.push_back(INF);
    t.push_back(INF);

    ll x;
    vector<ll>::iterator it_s, it_t;
    vector<ll> ans;
    ll s_near2[2];
    ll t_near2[2];
    for (int i = 0; i < Q; i++) {
        scanf("%lld", &x);
        it_s = lower_bound(s.begin(), s.end(), x);
        it_t = lower_bound(t.begin(), t.end(), x);
        s_near2[0] = *it_s; it_s--;
        s_near2[1] = *it_s; 
        t_near2[0] = *it_t; it_t--;
        t_near2[1] = *it_t; 
        vector<ll> dist;
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 2; j++) {
                dist.push_back(abs(x - s_near2[i]) + abs(s_near2[i] - t_near2[j]));
                dist.push_back(abs(x - t_near2[i]) + abs(t_near2[i] - s_near2[j]));
            }
        }
        ans.push_back(*min_element(dist.begin(), dist.end()));
    }
    
    for (int i = 0; i < Q; i++) {
        printf("%lld\n", ans[i]);
    }

}


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
int main() {
    double W,H,x,y;
    cin >> W >> H >> x >> y;
    if(W == x*2 && H == y*2) {
        cout << W*H/2 << " " << 1 << endl;
    }
    else {
        cout << W*H/2 << " " << 0 << endl;
    }
}

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

def odd(x):
    if ( (x + 1) // 2 ) % 2 == 0:
        return 0
    else:
        return 1

def solve(m):
    if m % 2 == 1:
        return odd(m)
    else:
        return odd(m + 1) ^ (m + 1)

print(solve(b) ^ solve(a - 1))

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

using namespace std;
typedef long long ll;

int main()
{
  ll a, b, c;
  cin >> a >> b >> c;
  if (a + b + c >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }
  return 0;
}


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

using namespace std;
using ll = long long;

constexpr ll MOD = 1e9 + 7;
int mx[] = {-1, 1, 0, 0}, my[] = {0, 0, -1, 1};

string s;
int dp[2000001][2];
bool visited[2000000][2];

int dfs(int n, bool m)
{
	if (n == (int)s.length())
		return 0;
	if (visited[n][m])
		return dp[n][m];
	visited[n][m] = 1;
	int t = s[n] - '0';
	if (m == 0)
	{
		return dp[n][m] = min(dfs(n + 1, 0) + t, dfs(n + 1, 1) + t + 1);
	}
	else
	{
		if (n == (int)s.length() - 1)
			t = 10 - t;
		else
			t = 9 - t;
		return dp[n][m] = min(dfs(n + 1, 0) + t + 1, dfs(n + 1, 1) + t);
	}
}

int main()
{
	cin >> s;
	s = "0" + s;
	cout << dfs(0, 0);
}

Measured memory_bytes: 60464
#include <iostream>

using namespace std;

    int hap[100100][3];
    long long int dp[100100][3];

int main()
{
    int N;

    cin >> N;
    for(int i=0; i<N; i++){
        for(int j=0; j<3; j++){
                cin >> hap[i][j];
        }
    }

    for(int i=0; i<N; i++){
        dp[i+1][0] = max(dp[i][1] + hap[i][0],dp[i][2] + hap[i][0]);
        dp[i+1][1] = max(dp[i][0] + hap[i][1],dp[i][2] + hap[i][1]);
        dp[i+1][2] = max(dp[i][0] + hap[i][2],dp[i][1] + hap[i][2]);

    }

    long long ans;
    ans = max(dp[N][0], dp[N][1]);
    ans = max(ans, dp[N][2]);

    cout << ans;
}

Measured memory_bytes: 3712
/// sultanov

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
     
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
 
using namespace std;
using namespace __gnu_pbds;
                                                          
template<typename T> 
using ordered_set = tree<T, null_type,   
less<T>, rb_tree_tag,
tree_order_statistics_node_update>;

using ll = long long;
using pii = pair<int, int>;                                   

const int INF32 = 1e9;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);          
    int n, k;
    cin >> n >> k;
    vector<int> h(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> h[i];
    vector<int> dp(n + 4, INF32);
    dp[1] = 0;
    for (int i = 2; i <= n; i++) 
        for (int j = 1; j <= k; j++) 
            if (i - j > 0)
                dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
    cout << dp[n];
    return false;                                                       
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
int main() {
  string str;
  getline(cin, str);
  string t;
  getline(cin, t);
  int ans=0;
  for (int i=0;i< str.length();i++){
    if (str.at(i)==t.at(i)){
      ans++;
    }
  }
  //cout << str . at(str.length()) << "\n";
  if (ans == str.length() &&t.length()==str.length()+1){
    cout << "Yes";
  }else {
    cout << "No";
  }
}


Measured memory_bytes: 3604
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int N;
int a[100];

int main(int argc, char **argv) {
	cin >> N;
	REP(i, N) cin >> a[i];
	int res = 4000000;
	FOR(i, -100, 101) {
		int c = 0;
		REP(j, N) c += (a[j] - i) * (a[j] - i);
		if (c < res) res = c;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if(a==b)
    {
        if(a!=c&&b!=c)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
        else if(b==c)
    {
        if(b!=a&&c!=a)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
       else if(a==c)
    {
        if(a!=b&&c!=b)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    else if(a!=b&&b!=c&&a!=c)
                    cout << "No" << endl;



    return 0;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

ll even(ll m){
   ll count = 0;
   while(m % 2 == 0 && m > 0){
      m /= 2;
      count++;
   }
   return count;
}

int main(){
  ll n; cin >> n;
  ll sum = 0;
  rep(i,n){
    ll b; cin >> b;
    sum += even(b);
   }
   print(sum);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
double dp[210][210];
int sz[210];
int S[210][210];
int H[210][210];
double h[210][210];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		scanf("%d",sz+i);
		for(int j=0;j<sz[i];j++){
			scanf("%d%d",&S[i][j],&H[i][j]);
		}
	}
	for(int i=0;i<a;i++){
		for(int j=0;j<=b;j++){
			int now=j;
			for(int k=0;k<sz[i];k++){
				if(now<S[i][k]*H[i][k]){
					h[i][j]+=(double)now/S[i][k];
					now=0;
					break;
				}else{
					now-=S[i][k]*H[i][k];
					h[i][j]+=H[i][k];
				}
			}
			if(now){
				h[i][j]=-1;
			}
		}
	}
	for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-mod;
	dp[0][0]=0;
	for(int i=0;i<a;i++){
		for(int j=0;j<=b;j++){
			for(int k=0;j+k<=b;k++){
				if(h[i][k]<-0.5)continue;
				dp[i+1][j+k]=max(dp[i+1][j+k],dp[i][j]+h[i][k]);
			}
		}
	}
	double ret=0;
	for(int i=0;i<=b;i++)ret=max(ret,dp[a][i]);
	printf("%.12f\n",ret);
}

Measured memory_bytes: 3724
#include<iostream>
#include<vector>
using namespace std;
typedef long long int ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a,   b) * b;}

int main(){
  int n;
  cin >> n;
  vector<ll> t(n);
  int i=0;
  ll ans=0;
  for(i=0;i<n;++i){
    cin >> t[i];
  }
  for(i=0;i<n;++i){
    if(i==0){
      ans=t[i];
      continue;
    }
    ans=lcm(ans,t[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int int64_t
#define pb push_back
#define pii pair<int, int>
#define F first
#define S second
#define vecsort(x) sort(x.begin(), x.end())
#define vecrsort(x) sort(x.rbegin(), x.rend())
#define massort(x, n) sort(x, x + n)
#define FOR(i, n) for(int i = 0; i < n; i ++)
using namespace std;
void input();
int max(int32_t a, int b){
   return max((int)a, b);
}

int32_t main(){
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   int a;
   cin >> a;
   cout << a * a * 3;
}



Measured memory_bytes: 256