akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main {
    static long mod = (int)Math.pow(10,9)+7;
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt();
		long[] a = sc.nextLongArray(n+1);
		long[] max = new long[n+2];
		if(n == 0){
		    if(a[0] == 1){
		       System.out.println(1);
		       return;
		    }else{
		       System.out.println(-1);
		       return;
		    }
		}else if(a[0] != 0){
		    System.out.println(-1);
		    return;
		}
		long ans = 0;
		long now = 0;
		for(int i = n; i >= 0; i--){
		    now = now+a[i];
		    max[i] = now;
		}
		now = 1;
		for(int i = 0; i <= n; i++){
		    now = Math.min(max[i],now);
		    ans += now;
		    long b = now - a[i];
		    if(b < 0){
		        System.out.println(-1);
		        return;
		    }else{
		        now = b*2;
		    }
		}
		pw.println(ans);
		pw.close();
	}
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

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

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

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

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}



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

int main() {
  int n;
  cin>>n;
  deque<int>q;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    if(i%2==0){
      q.push_back(a);
    }else{
      q.push_front(a);
    }
  }
  if(n%2==1)reverse(q.begin(),q.end());
  for(int i=0;i<n;i++){
    if(i==n-1)cout<<q[i]<<endl;
    else cout<<q[i]<<" ";
  }
  return 0;
}

  


Measured memory_bytes: 2944
// Problem : A - Registration
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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


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

    string s, t;
    cin >> s;
    cin >> t;
    if (t.length() == s.length() + 1) {
        bool ok = true;
        for (long i = 0; i < s.length(); i++) {
            if (t[i] != s[i]) ok = false;
        }
        if (ok) cout << "Yes\n";
        else cout << "No\n";
    } else {
        cout << "No\n";
    }
    
    return 0;
}


Measured memory_bytes: 3652
a, b = map(int, input().split())
a_list = [a]*b
b_list = [b]*a
a_list = map(str, a_list)
b_list = map(str, b_list)
a_list = "".join(a_list)
b_list = "".join(b_list)
if a==b:
    print(a_list)
else:
    print(a_list) if a < b else print(b_list)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BS binary_search
#define all(c) (c).begin(),(c).end()
#define sz(x) (int)(x).size()
#define get(a,t) get<a>(t)
#define EPS 0.000000001 //1e-9
using pii=pair<int,int>;
const int INF=1e18;

void dprint(string s) { cout << endl;}
void dprint() { cout << endl;}
template <class T, class... U> void dprint(string s, T t, U... u) 
{int w=s.find(','); cout <<"["<< s.substr(0,w) << ": " << t << "] " ; dprint(s.substr(w+1, sz(s)-w), u...);} 


#define DEBUG 
#ifdef DEBUG
#define dbg(X...) dprint(#X,X)
#else
#define dbg(X...); 
#endif
const int N=100005;

int32_t main()
{
	IOS;
	int a,b,c,k; cin>>a>>b>>c>>k;
	if(k<=a)
		cout<<k;
	else
	{
		if(k<=a+b)
			cout<<a;
		else
			cout<<a-(k-(a+b));
	}
	return 0;
}

Measured memory_bytes: 3552
ls = [0]*4
n = int(input())

for i in range(n):
  s = input()
  if s == "AC":
    ls[0]+=1
  elif s=="WA":
    ls[1]+=1
  elif s == "TLE":
    ls[2]+=1
  else:
    ls[-1]+=1
    
  
  

print("AC x "+str(ls[0]))
print("WA x "+str(ls[1]))
print("TLE x "+str(ls[2]))
print("RE x "+str(ls[3]))

Measured memory_bytes: 9148
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)


const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE x(n), y(n), h(n); rep(i, n)cin >> x[i] >> y[i] >> h[i];
	rep(i, 101) {
		rep(j, 101) {
			int tmp = 0;
			rep(k, n) {
				if (h[k] > 0) {
					tmp = abs(x[k] - i) + abs(y[k] - j) + h[k]; break;
				}
			}
			bool ok = true;
			rep(k, n) {
				if (h[k] != max(0LL, tmp - abs(x[k] - i) - abs(y[k] - j))) {
					ok = false;
				}
			}
			if (ok) {
				cout << i << " " << j << " " << tmp << endl; break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
const int Max_N = 100005;
const int INF = 0x7fffffff;
int n;
int a[Max_N];
int dp[Max_N];

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    fill(dp, dp + n, INF);
    for (int i = 0; i < n; ++i)
        *lower_bound(dp, dp + n, a[i]) = a[i];
    cout << (find(dp, dp + n, INF) - dp) << endl;
    return 0;
}


Measured memory_bytes: 3880
import math

if __name__ == '__main__':
  input_line=input()
  first_half=input_line[:math.ceil(len(input_line)/2)]
  latter_half=input_line[-math.ceil(len(input_line)/2):]
  latter_half=latter_half[::-1]
  answer=0
  for i in range(len(first_half)):
    if(first_half[i]!=latter_half[i]):
      answer+=1
  print(str(answer))

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define MaxN 100000+100
typedef long long LL;
LL tt[MaxN];
int main()
{
    int N;
    scanf("%d",&N);
    for(int i=1;i<=N;i++)
        scanf("%lld",&tt[i]);
    LL sx=2;
    LL xx=2;
    int i;
    for(i=N;i>=1;i--)
    {
        LL a1=sx/tt[i];
        LL a2=xx/tt[i];
        if(xx%tt[i]!=0)
            a2++;
        if(a1<a2)
            break;
        xx=a2*tt[i];
        sx=a1*tt[i]+tt[i]-1;
    }
    if(i!=0)
        printf("-1");
    else
        printf("%lld %lld",xx,sx);
    return 0;
}


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

using ll = long long int;
using P = std::pair<int, int>;

constexpr ll INF = 1e5 * 2 + 10;

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

std::vector<ll> a, b;

ll cutoffr(ll c)
{

    ll lb = 0, ub = INF;

    while (ub - lb > 1)
    {

        ll mid = (lb + ub) / 2;

        ll len = 0;

        for (auto x : a)
        {
            len += std::upper_bound(std::begin(b), std::end(b), x - mid) - std::begin(b);
        }

        if (len >= c)
        {
            lb = mid;
        }
        else
        {
            ub = mid;
        }
    }

    return lb;
}

int main()
{
    int n;
    ll m;

    std::cin >> n >> m;

    a.resize(n);

    rep(i, n)
    {
        std::cin >> a[i];
    }

    std::sort(std::begin(a), std::end(a), std::greater<>());

    b = a;

    for (auto &x : b)
        x = -x;

    ll rate = cutoffr(m);

    //std::cerr << rate << std::endl;

    std::vector<int> vec;

    ll diff = 0;

    rep(i, n)
    {
        int y = std::upper_bound(std::begin(b), std::end(b), a[i] - rate) - std::begin(b);

        diff += (ll)y;

        vec.push_back(y);
    }

    diff -= m;

    std::vector<ll> c;
    c.push_back(0);
    rep(i, n)
    {
        c.push_back(a[i]);

        c[i + 1] += c[i];
    }

    /*for (auto x : c)
        std::cerr << x << ' ';
    std::cerr << std::endl;*/

    ll ans = 0;

    rep(i, n)
    {
        ans += c[vec[i]] + vec[i] * a[i];

        //std::cerr << vec[i] << ' ' << ans << std::endl;

        //std::cerr << i << ' ' << vec[i] << std::endl;
    }

    //std::cerr << rate << std::endl;

    std::cout << ans - diff * rate << std::endl;

    /*std::cerr << "DEBUG" << std::endl;

    for (auto x : a)
    {
        ll res = std::upper_bound(std::begin(b), std::end(b), x - 131) - std::begin(b);

        std::cerr << res << ' ';
    }

    std::cerr << std::endl;*/

    return 0;
}

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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;

#define INF 1e9
#define MOD 1000000007
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define each(x, v) for (auto& x: (v))
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl

void solve();
void in(){} template<class T, class... U> void in(T &t, U &...u){ cin >> t; in(u...); }
int main() { cin.tie(0); ios::sync_with_stdio(0); solve(); }

void solve() {
  int N;
  in(N);
  vi L(N);
  each(x, L) in(x);

  sort(all(L), greater<>());

  ll ans = 0;
  rep(i, 0, N)
    rep(j, i + 1, N)
      rep(k, j + 1, N)
        if (L[i] < L[j] + L[k])
          ans++;

  print(ans);
}


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

#ifndef DEBUG
#define endl '\n'
#define debug(...)
#else
#define debug(...) __VA_ARGS__
#endif
#define debugf(...) debug(printf(__VA_ARGS__);)

const int N = 1e5 + 5;

vector<int> g[N];
int dx[N], dy[N];

void dfs(int u, int* d, int p=0) {
    d[u] = d[p] + 1;
    for (int v : g[u]) if (v != p) {
        dfs(v, d, u);
    }
}

int (((((main)))))() <%
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n, x, y;
    cin >> n >> x >> y;

    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }

    dx[0] = -1;
    dy[0] = -1;

    dfs(x, dx);
    dfs(y, dy);

    int ans = 0;
    for (int u = 1; u <= n; u++) {
        debugf("u=%d, dx=%d, dy=%d\n", u, dx[u], dy[u]);
        if (dx[u] < dy[u])
            ans = max(ans, dy[u] - 1);
    }

    cout << ans << endl;

    return 0;
%>

Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main(){
    int X;
    cin >> X;
    int yenf, yens;
    yenf=X/500;
    X=X-(500*yenf);
    yens=X/5;
    cout<<yenf*1000+(yens*5)<<endl;

return 0;

}  



Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<stack>
#include<set>
#include<string.h>
#include<map>
#include<vector>
#define pb push_back
#define eb emplace_back
#define ins insert 
#define mp make_pair
#define ll long long 
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define M 10000007
using namespace std;
void solve(){
	ll n,k;
	cin>>n>>k;
	ll a[n],dp[n+1];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
		dp[i]=0;
	}
	dp[0]=0;
	dp[1]=abs(a[0]-a[1]);
	//cout<<dp[0]<<" "<<dp[1]<<" ";
	for (int i = 2; i < n; ++i)
	{
		dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
		for (int j=i-2; j>=i-k && j>=0; --j)
		{
			dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
		}
		//cout<<dp[i]<<" ";
	}
	cout<<dp[n-1];
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0 ;
}


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

int main(){
    string s;
    cin >> s;
    s += 'R';
    int l = 0, r = 1, k;
    vector<int> ans(s.size());
    for(int i = 1; i < s.size(); i++){
        if(s[i] == s[i-1]){
            if(s[i] == 'R') r++;
            else l++;
        }
        else{
            if(s[i] == 'R'){
                ans[k-1] += (r+1)/2 + l/2;
                ans[k] = r/2 + (l+1)/2;
                r = 1; l = 0;
            }
            else{
                l++;
                k = i;
            }
        }
    }

    rep(i,s.size()-1) cout << ans[i] << ' ';
}

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

using namespace std;

const int MAXN = 2E5;
int a[MAXN];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    long long ans = 0;
    int i = 0;
    int j = 1;
    int cur = a[i];
    while (i < n)
    {
        while (j < n && (a[j] & cur) == 0)
        {
            cur |= a[j];
            j++;
        }
        ans += j - i;
        cur = cur ^ a[i];
        i++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ITP2_2_A
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int[] n = ReadIntAr();
            List<Stack<int>> li = new List<Stack<int>>();
            for (int i = 0 ; i < n[0] ; i++) li.Add(new Stack<int>()) ;

            for (int i = 0 ; i < n[1] ; i++)
            {
                int[] line = ReadIntAr();
                switch (line[0])
                {
                    case 0: li[line[1]].Push(line[2]); break;
                    case 1: if (li[line[1]].Count > 0) Console.WriteLine(li[line[1]].Peek().ToString()); break;
                    case 2: if (li[line[1]].Count > 0)li[line[1]].Pop(); break;
                }
            }
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}



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

using ll = long long;

int main() {
	int n, w;
	cin >> n >> w;
	vector<vector<ll>> dp(n + 1, vector<ll>(w + 1, 0));
	for (int i = 1; i <= n; ++i) {
		int weight, value;
		cin >> weight >> value;
		for (int j = 1; j <= w; ++j) {
			if (j - weight < 0) {
				dp[i][j] = dp[i - 1][j];
				continue;
			}
			dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weight] + value);
		}
	}
	cout << dp[n][w] << endl;
}

Measured memory_bytes: 80256
module DLinkedList : sig
  type 'a t
  type 'a element
  val create : unit -> 'a t
  val is_empty : 'a t -> bool
  val next : 'a element -> 'a element option
  val prev : 'a element -> 'a element option
  val value : 'a element -> 'a
  val find : 'a t -> f:('a -> bool) -> 'a element option
  val iter : 'a t -> f:('a element -> unit) -> unit
  val insert_first : 'a t -> 'a -> 'a element
  val remove : 'a t -> 'a element -> unit
  val remove_first : 'a t -> unit
  val remove_last : 'a t -> unit
end = struct
  type 'a element =
    { value : 'a;
      mutable next : 'a element option;
      mutable prev : 'a element option
    }
  type 'a t = {
    mutable first : 'a element option;
    mutable last  : 'a element option
  }

  let create () = {first = None; last = None}
  let is_empty t = t.first = None && t.last = None
  let value elt = elt.value
  let next elt = elt.next
  let prev elt = elt.prev

  let insert_first t value =
    let new_elt = {prev = None; next = t.first; value} in
    begin match t.first with
      | Some old_first -> old_first.prev <- Some new_elt
      | None -> ()
    end;
    t.first <- Some new_elt;
    begin match t.last with
      | Some _ -> ()
      | None -> t.last <- Some new_elt
    end;
    new_elt

  let remove t elt =
    let {prev; next; _} = elt in
    begin match prev with
      | Some prev -> prev.next <- next
      | None -> t.first <- next
    end;
    begin match next with
      | Some next -> next.prev <- prev
      | None -> t.last <- prev
    end;
    elt.prev <- None;
    elt.next <- None

  let remove_first t =
    begin match t.first with
      | Some e -> remove t e
      | None -> ()
    end

  let remove_last t =
    begin match t.last with
      | Some last ->
        begin match last.prev with
          | Some e -> e.next <- None; t.last <- last.prev
          | None -> t.first <- None; t.last <- None
        end
      | None -> ()
    end

  let find t ~f =
    let rec loop = function
      | None -> None
      | Some elt ->
        if f (value elt) then Some elt
        else loop (next elt)
    in
    loop t.first

  let iter t ~f =
    let rec loop = function
      | None -> ()
      | Some elt -> f elt; loop (next elt)
    in loop t.first
end

let () =
  let open DLinkedList in
  let n = read_int () in
  let dll = create () in
  let rec loop = function
      0 -> ()
    | i ->
      begin match read_line () with
        | "deleteFirst" -> remove_first dll
        | "deleteLast" -> remove_last dll
        | s ->
          begin match String.sub s 0 6,
                      (String.sub s 7 (String.length s - 7) |> int_of_string) with
          | "insert", n -> let _ = insert_first dll n in ()
          | "delete", n -> (match find dll ~f:((=) n) with
              | Some e -> remove dll e
              | None -> ())
          | _,_ -> ()
          end
      end;
      loop (i-1)
  in
  loop n;
  iter dll
    ~f:(fun e -> match next e with
          Some _ -> Printf.printf "%d " (value e)
        | None -> Printf.printf "%d\n" (value e))

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

using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class T> ostream& operator<<(ostream &os, set<T> S){os << "{ "; for(auto s:S) os<<s<<" "; return os<<"}";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {os << "{ "; for(auto m:M) os<<"("<<m.first<<":"<<m.second<<") "; return os<<"}";}
#ifdef np
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>void __f(const char *name, Arg1 &&arg1) { cout<<name<<" : "<<arg1<<endl;}
template<typename Arg1, typename ... Args>void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma=strchr(names+1,','); cout.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif


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

	int a, b;
	cin>>a>>b;
	if(a<10 and b<10) cout<<a*b;
	else cout<<-1;

#ifdef np
    cerr <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif  
 return 0; 
 }


Measured memory_bytes: 256
use std::io;
use std::str::FromStr;

fn input_int_tuple() -> (i32, i32) {
  let mut line: String = String::new();
  io::stdin().read_line(&mut line);
  let vec: Vec<i32> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
  (vec[0], vec[1])
}

fn input_i32_vec() -> Vec<i32> {
  let mut line: String = String::new();
  io::stdin().read_line(&mut line);
  line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn main() {
  let (n, k) = input_int_tuple();
  let h_vec = input_i32_vec();
  let mut sum = 0;
  for h in h_vec {
    if h >= k {
      sum += 1;
    }
  }
  println!("{}", sum);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a, b;
  cin >> a >> b;

  if (a == 1) a += 13;
  if (b == 1) b += 13;

  if (a == b) cout << "Draw" << endl;
  else if (a > b) cout << "Alice" << endl;
  else cout << "Bob" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
using namespace std;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int a;
	cin >> a;
	int ans = a + (a * a) + (a * a * a);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
#define maxn 100005
#define Mod 1000000007
using namespace std;
int read(){
	int x=0,c;while(!isdigit(c=getchar()));
	while(x=x*10+c-'0',isdigit(c=getchar()));
	return x;
}
int main(){
	int n=read();
	if(n>999)printf("ABD");else printf("ABC");
	return 0;
}

Measured memory_bytes: 256
package main

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

func sum(a []int) int {
	total := 0
	for _, x := range a {
		total = (total + x) % CYCLE
	}
	return total
}

func parseInt(s string) int {
	return int(parseInt64(s))
}

func parseInt64(s string) int64 {
	x, _ := strconv.ParseInt(s, 10, 64)
	return x
}

var reader *bufio.Reader

func readLine() string {
	s, _ := reader.ReadString('\n')
	return strings.TrimSuffix(s, "\n")
}

var CYCLE = 1000000007

func main() {
	reader = bufio.NewReader(os.Stdin)
	N := parseInt(readLine())
	s := readLine()

	k := make([]int, 1)
	k[0] = 1

	for i := 0; i < N-1; i++ {
		// fmt.Println(k)
		kk := make([]int, i+2)
		if s[i] == '<' {
			for j := 0; j < i+2-1; j++ {
				kk[j+1] = (kk[j] + k[j]) % CYCLE
			}
		} else if s[i] == '>' {
			for j := i + 2 - 2; j >= 0; j-- {
				kk[j] = (kk[j+1] + k[j]) % CYCLE
			}
		} else {
			panic("string must contain only '<' and '>'")
		}
		k = kk
	}
	fmt.Println(sum(k))
}


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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var input1 = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            var input2 = Console.ReadLine().Split(' ').Select(int.Parse);
            var N = input1[0];
            var M = input1[1];

            var logDic = new SortedDictionary<long, IList<Product>>();
            foreach (var i in input2)
            {
                var log = (long)Math.Log(i, 2) + 1;
                Add(logDic, new Product() { Price = i, Log = log, Ticket = 0 });
            }

            SetTicket(logDic, M);

            Console.WriteLine(logDic.Values.SelectMany(s => s).Sum(s => s.DiscountPrice()));
        }

        private static void Add(SortedDictionary<long, IList<Product>> dic, Product product)
        {
            if (dic.ContainsKey(product.Log))
            {
                dic[product.Log].Add(product);
                return;
            }
            dic.Add(product.Log, new List<Product> { product });
        }

        private static void SetTicket(SortedDictionary<long, IList<Product>> dic, int tickets)
        {
            if (tickets == 0) return;

            var max = dic.Last().Key;
            if (max == 0) return;

            var count = dic[max].Count;

            if (count > tickets)
            {
                PlusTicket(dic[max].OrderByDescending(x => x.DiscountPrice()).Take(tickets));
                return;
            }

            PlusTicket(dic[max]);
            Shift(dic, max);
            SetTicket(dic, tickets - count);
        }

        private static void PlusTicket(IEnumerable<Product> products)
        {
            foreach (var p in products)
            {
                p.Ticket += 1;
                p.Log -= 1;
            }
        }

        private static void Shift(SortedDictionary<long, IList<Product>> dic, long max)
        {
            if (dic.Keys.Contains(max - 1))
            {
                dic[max - 1] = dic[max - 1].Concat(dic[max]).ToList();
            }
            else
            {
                dic[max - 1] = dic[max];
            }
            dic.Remove(max);
        }
    }

    class Product
    {
        public long Price { get; set; }
        public long Log { get; set; }
        public long Ticket { get; set; }

        public long DiscountPrice()
        {
            return (long)(Price / Math.Pow(2, Ticket));
        }
    }
}


Measured memory_bytes: 33752
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
//---------------------------------------------------------------------------------------------------
typedef pair<int,int> P;

int main(void){
    // Your code here!
    int n; cin >> n;
    FOR(i,1,9) FOR(j,1,9) {
        if (i * j == n) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define inv(x) Power(x, mod - 2)
#define N 1000005

using namespace std;
typedef long long ll;

template <class T> inline void read(T &x) {
	char ch; bool flag = false;
	while (!isdigit(ch = getchar())) flag |= ch == '-';
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	if (flag) x = -x;
}

inline int input() {
	int x; char ch; bool flag = false;
	while (!isdigit(ch = getchar())) flag |= ch == '-';
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	return flag ? -x : x;
}

const int mod = 998244353;
inline int add(int x, int y) { x += y; return x >= mod ? x - mod : x; }
inline void inc(int &x, int y) { x += y; x -= x >= mod ? mod : 0; }

inline int Power(int x, int y) {
	int res = 1;
	while (y) {
		if (y & 1) res = (ll) res * x % mod;
		x = (ll) x * x % mod, y >>= 1;
	} return res;
}

template <class T> void chkmax(T &x, T y) { x = x > y ? x : y; }
template <class T> void chkmin(T &x, T y) { x = x < y ? x : y; }
template <class T> T gcd(T x, T y) { return !y ? x : gcd(x % y, y); }

int fac[N], ifac[N];
void init() {
	fac[0] = ifac[0] = 1;
	for (int i = 1; i < N; ++i) fac[i] = (ll) fac[i - 1] * i % mod;
	ifac[N - 1] = inv(fac[N - 1]);
	for (int i = N - 2; i; --i) ifac[i] = (ll) ifac[i + 1] * (i + 1) % mod;
}

int n, k, ans;
int C(int x, int y) {
	if (x < y || y < 0) return 0;
	return (ll) fac[x] * ifac[x - y] % mod * ifac[y] % mod;
}

int main() {
	cin >> n >> k, init();
	for (int i = n; i <= k; ++i)
		inc(ans, C(k - 1, i - 1));
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 8064
n = int(input())

x = []
sum = 0

for i in range(n):
    x.append(list(input().split()))

for i in range(n):
    if x[i][1] == 'JPY':
        sum += int(x[i][0])
    else:
        sum += float(x[i][0]) * 380000

print(sum)

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

int main(){
    int n;
    cin >> n;
    if(n%10==3) cout << "bon" << endl;
    else if(n%10==0 || n%10==1 || n%10==6 || n%10==8) cout << "pon" << endl;
    else cout << "hon" << endl;
    return 0;
}

Measured memory_bytes: 3624
while True:
    M,F,R = map(int,input().split())
    if M == -1 and F == -1 and R == -1:
        break
    if M == -1 or F == -1:
        print("F")
    elif M+F >= 80:
        print("A")
    elif M+F >= 65:
        print("B")
    elif M+F >= 50:
        print("C")
    elif M+F >= 30:
        if R >= 50:
            print("C")
        else:
            print("D")
    else:
        print("F")


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

int main(){
	int N, T, i, j;
	scanf("%d%d", &N, &T);
	vector<int> A(N + 2), B(N + 2);
	for(i = 1; i <= N; i++){
		scanf("%d%d", &A[i], &B[i]);
	}
	vector<vector<int>> dp(N + 2, vector<int>(T + 1, 0));
	vector<vector<int>> pd(N + 2, vector<int>(T + 1, 0));
	for(i = 1; i <= N; i++){
		for(j = 1; j <= T; j++){
			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			if(j >= A[i]){
				dp[i][j] = max(dp[i][j], dp[i - 1][j - A[i]] + B[i]);
			}
		}
	}
/*	for(i = 0; i <= N; i++){
		printf("dp[%d]: ", i);
		for(j = 0; j <= T; j++){
			printf("%d ", dp[i][j]);
		}
		printf("\n");
	}
	printf("\n");
*/	for(i = N; i > 0; i--){
		for(j = 1; j <= T; j++){
			pd[i][j] = max(pd[i + 1][j], pd[i][j - 1]);
			if(j >= A[i]){
				pd[i][j] = max(pd[i][j], pd[i + 1][j - A[i]] + B[i]);
			}
		}
	}
	int ans = 0;
	for(i = 1; i <= N; i++){
		for(j = 0; j < T; j++){
			ans = max(ans, B[i] + dp[i - 1][j] + pd[i + 1][T - 1 - j]);
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

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

const long long MOD = 1000000007;

int main(){
  int n,x;
  cin >> n;
  vector<int> a(n,0);
  rep(i,n-1){
  	cin >> x;
    x--;
  	a.at(x) +=1;
  }
  
  rep(i,n){
  	cout << a.at(i) << endl;
  }
}


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

struct st { int p, h; ll c; };
bool operator<(st a, st b) { return a.c > b.c; }

int h[100000], y;
ll d[100000];
vector<P>E[100000];
int main() {
	int n, m, x; scanf("%d%d%d", &n, &m, &x);
	rep(i, n)scanf("%d", &h[i]);
	rep(i, m) {
		int a, b, t; scanf("%d%d%d", &a, &b, &t);
		a--; b--;
		if (t <= h[a])E[a].push_back(P(t, b));
		if (t <= h[b])E[b].push_back(P(t, a));
	}
	fill(d, d + n, LLONG_MAX);
	priority_queue<st>que;
	d[0] = 0;
	que.push({ 0,x,0 });
	while (!que.empty()) {
		st s = que.top(); que.pop();
		if (d[s.p] != s.c)continue;
		for (P u : E[s.p]) {
			int t = 0, k = s.h - u.first;
			if (k < 0)t = 0 - k, k = 0;
			if (k > h[u.second])t = k - h[u.second], k = h[u.second];
			if (d[u.second] > s.c + u.first + t) {
				if (u.second == n - 1)y = k;
				d[u.second] = s.c + u.first + t;
				que.push({ u.second,k,d[u.second] });
			}
		}
	}
	if (d[n - 1] == LLONG_MAX)puts("-1");
	else printf("%lld\n", d[n - 1] + h[n - 1] - y);
}

Measured memory_bytes: 15064
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100000;
int N;
ll a[MAX_N];

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

  cin >> N;
  rep(i, N) cin >> a[i];
  sort(a, a+N);

  ll n = a[N-1];
  ll r = 0;
  if (n%2 == 0) {
      ll mid = n/2;
      ll midist = INFLL;
      for (int i = 0; i < N-1; ++i) {
          ll dist = abs(a[i]-mid);
          if (midist > dist) {
              r = a[i];
              midist = dist;
          }
      }
      cerr << "mid: " << mid << endl;
      cerr << "midist: " << midist << endl;
  } else {
      ll mid = (n-1)/2;
      ll midist = INFLL;
      for (int i = 0; i < N-1; ++i) {
          ll dist;
          if (a[i] > mid) {
              dist = abs(a[i]-(mid+1));
          } else {
              dist = abs(a[i]-mid);
          }
          if (midist > dist) {
              r = a[i];
              midist = dist;
          }
      }
      cerr << "mid: " << mid << endl;
      cerr << "midist: " << midist << endl;
  }

  


  cout << n << ' ' << r << endl;
  return 0;
}


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

int main(){
    int r,D,x;
    scanf("%d%d%d",&r,&D,&x);
    int weight = x;
    for(int i=0; i<10; i++){
        weight = r*weight-D;
        printf("%d\n",weight);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 1e9+7;

int main(){
    ll a; cin >> a;
    cout << a + a*a + a*a*a << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
 
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
 
string S;
int N;
int cnt[256];
 
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	N=S.size();
	ll ret=1;
	FOR(i,N) {
		FOR(j,256) if(S[i]!=j) ret+=cnt[j];
		cnt[S[i]]++;
	}
	cout<<ret<<endl;
	
	
}
 
 
int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

Measured memory_bytes: 720
def gcd(x,y):
  if x>y: x,y = y,x
  while x:
    x,y = y%x, x
  return y

def lcm(a,b):
    return a*b //gcd(a,b)

n=int(input())
t=[]
for i in range(n):
    t.append(int(input()))
t.sort()
if(n==1):
    print(t[0])
    exit()
ans=lcm(t[0],t[1])
if(n==2):
    print(ans)
    exit()
for i in range(2,n):
    ans=lcm(ans,t[i])
print(ans)



Measured memory_bytes: 3064
using System;

namespace ABC048
{
    class B
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            long a = long.Parse(input[0]);
            long b = long.Parse(input[1]);
            long x = long.Parse(input[2]);

            long start = 0;
            if (a % x == 0) start = (a / x) - 1;
            else start = a / x;

            long end = b / x;
            Console.WriteLine(end - start);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

int n, k;
int64_t h[100001];
int64_t dp[100001];

const int64_t INF = 1000000000LL * 100000000LL;

int64_t f(int i) {
  if (i >= n) return INF;
  if (i == n - 1) return 0;
  if (dp[i] != -1) return dp[i];
  int64_t cost = INF;
  for (int j = 1; j <= k; ++j) {
    if (i + j < n) {
      cost = std::min(cost, std::abs(h[i] - h[i + j]) + f(i + j));
    } else break;
  }
  return dp[i] = cost;
}

int main() {
  std::memset(dp, -1, sizeof(dp));
  std::cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    std::cin >> h[i];
  }
  std::cout << f(0) << '\n';
}


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

int main()
{
	int min = 1000000, max = -1000000, n, i, temp;
	long sum = 0;
	
	cin >> n;
	
	for (i = 0; i < n; i++)
	{
		cin >> temp;
		
		if (temp < min)
		{
			min = temp;
		}
		if (temp > max)
		{
			max = temp;
		}
 			sum += temp;
	}
		cout << min << " " << max << " " << sum << endl;	
		
return 0;
}

Measured memory_bytes: 3104
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> div;
    for(int i = 1; i <= sqrt(2*N); ++i) {
            if((2*N)%i==0) {
                div.push_back(i);
                div.push_back((2*N)/i);
            }
    }
    int ret = -1;
    for(auto d : div) {
        if ((2*N)/d == d-1 && d-1 <= N) {
            ret = d;
            break;
        }
    }
    if (ret == -1){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
        cout << ret << endl;
        vector<vector<int> > a(ret);
        int x = 0;
        int y = 1;
        int x_num = 0;
        for(int i = 1; i <= N; ++i) {
            a[x].push_back(i);
            a[y].push_back(i);
            y++;
            x_num++;
            if(x_num == ret-1) {
                x++;
                x_num=a[x].size();
                y=x+1;
            }
        }
        for(auto aa : a) {
            cout << aa.size();
            for(auto aaa : aa) {
                cout << " " << aaa;
            }
            cout << endl;
        }
    }
    return 0;
}

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

#define MOD 1000000007

int main(){
	int n;	cin>>n;
	vector<int> count(n,0);
	for(int i=0;i<n;i++){
		int a;	cin>>a;
		count[a]++;
	}
	long long ans=1;

	if(count[0]<=1){
		for(int i=1;i<n;i++){
			if(count[i]==0)continue;
			else if(count[i]!=2){
				ans=0;
				break;
			}

			ans*=count[i];
			ans%=MOD;
		}
	}else{
		ans=0;
	}

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


Measured memory_bytes: 640
#include <stdio.h>

#define N 100

int queue[N] = {0};
int b = 0, e = 0;
void enq( int v ) {
    queue[b++] = v;
}
int deq() {
    return queue[e++];
}
int is_empty() {
    return b == e;
}

int step[N] = {0};

void clear()
{
    int i;
    for( i=0; i<N; ++i ) {
        queue[i] = 0;
        step[i] = -1;
    }
    b = 0;
    e = 0;
}

void bfs( int table[], int s, int n )
{
    int u, v;

    enq( s - 1 );
    while( !is_empty() ) {
        u = deq();
        if ( step[u] == -1 )
            step[u] = 0;
                    
        for( v=0; v<n; ++v ) {
            if ( table[u*N+v] == 1 && step[v] == -1 ) {
                step[v] = step[u] + 1;
                enq( v );
            }
        }
    }
}


int main( void )
{
    int n, i, j, u, k, v;
    int cnt = 0;
    int table[N*N] = {0};
    scanf( "%d", &n );

    clear();

    for( i=0; i<n; ++i ) {
        scanf( "%d %d", &u, &k );
        for( j=0; j<k; ++j ) {
            scanf("%d", &v);
            table[((u-1)*N)+(v-1)] = 1;
        }
    }

    bfs( table, 1, n );

    for( i=0; i<n; ++i )
        printf("%d %d\n", i+1, step[i]);

    return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
	int x,n;
	cin >> x >> n;
	vector<int> p(n);
	rep(i,n) cin >> p[i];
	vector<int> cand;
	if (n > 0) {
		for (int i=0;i<102;i++) {
			bool found = false;
			rep(j, n) {
				if (i == p[j]) {
					found = true;
					break;
				}
			}
			if (!found)
				cand.push_back(i);
		}
		int dmax=102;
		int index = 0;
		for (int i=0;i<cand.size();i++) {
			if (abs(cand[i] - x) < dmax) {
				index = i;
				dmax = abs(cand[i] - x);
			}
		}
		cout << cand[index] <<endl;
	} else if (n == 0) {
		cout << x <<endl;
	}
	return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] line = sc.nextLine().split(" ");

		int L = Integer.parseInt(line[0]);
		int R = Integer.parseInt(line[1]);

		long minVal = Integer.MAX_VALUE;
		for (long i = L; i <= R; i++) {
			for (long j = i + 1; j <= R; j++) {
				minVal = Math.min(minVal, (i * j) % 2019);
				if (minVal == 0) {
					System.out.println(minVal);
					return;
				}
			}
		}
		System.out.println(minVal);
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 0x3fffffff;

const int vx[4]={1,0,-1,0}, vy[4]={0,1,0,-1};

int H, W, K, ans=0;
vector<string> mp(805);
bool visited[805][805]={};
int solve(int x, int y, int K){
	int ret = INF;
	queue< pair<pii, int> > que;
	que.emplace(pii(x,y), K);
	while( !que.empty() ){
		int x = que.front().X.X;
		int y = que.front().X.Y;
		int limit = que.front().Y;
		que.pop();
		//cout << x << "," << y << " " << limit << endl;
		chmin(ret, x);
		chmin(ret, W-1-x);
		chmin(ret, y);
		chmin(ret, H-1-y);
		if( limit == 0 ){
			continue;
		}
		if( x == 0 || y == 0 || x == H-1 || y == W-1 ) continue;
		rep(k,4){
			int nx = x + vx[k];
			int ny = y + vy[k];
			//cout << "nex: " << nx << "," << ny << endl;
			if( nx < 0 && ny < 0 && nx >= H && ny >= W ) continue;
			if( mp[ny][nx] == '.' && !visited[ny][nx] ){
				que.emplace(pii(nx,ny), limit-1);
				visited[ny][nx] = true;
			}
		}
	}
	return ret;
}

int main(){
	//ios_base::sync_with_stdio(0);

	cin >> H >> W >> K;
	rep(i,H) cin >> mp[i];

	rep(y,H) rep(x,W){
		if( mp[y][x] == 'S' ){
			ans = solve(x, y, K);
		}
	}

	cout << (ans == 0 ? 1 : (ans-1)/K + 2) << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
#define MAXN (int)(2*1e5 + 1)
#define F first
#define S second
#define endl "\n"
#define MOD (int)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
#define DEBUG if(0) cout << "aqui" << endl;
#define PI 2 * acos(0.0)
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1};

int r;

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

  cin >> r;

  cout << r*r << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int a,b;
    scanf("%d%d",&a,&b);
    if(a * b > a + b && a * b > a - b){
        printf("%d",a * b);
    } else if(a + b > a - b){
        printf("%d",a + b);
    } else {
        printf("%d",a - b);
    }
}

Measured memory_bytes: 128
N = int(input())
A = [[] for i in range(N)]
for n in range(N-1):
    a,b = map(int, input().split())
    A[a-1].append(b-1)
    A[b-1].append(a-1)
#print(A)


from collections import deque
def dfs(node):
    st = deque()
    push, pop = st.append, st.popleft
    push(node)
    cnt = [0]*N
    cnt[node] = 1
    while st:
        now = pop()
        for n in A[now]:
            if cnt[n] == 0:
                push(n)
            cnt[n] = 1
    return now

def dfs_L(node):
    st = deque()
    push, pop = st.append, st.popleft
    push([node,0])
    cnt = [0]*N
    cnt[node] = 1
    L_list = []
    while st:
        [now,L] = pop()
        L_list.append(L)
        for n in A[now]:
            if cnt[n] == 0:
                push([n,L+1])
            cnt[n] = 1
    return max(L_list)
            

step1 = dfs(0)
length = dfs_L(step1)
if length%3 == 1:
    print('Second')
else:
    print('First')

Measured memory_bytes: 63376
#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<=(int)k;i++)
#define per(i,j,k) for(int i=(int)j;i>=(int)k;i--)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long LL;
const int N=310000;
vector<int>dj[N];
int ans[N];
int l[N],r[N],n,m;
vector<int>lk[N];
int cnt[N];
inline void add(int x){
	for(;x<=m;x+=(x&(-x)))cnt[x]++;
}
inline int ask(int x){
	int ans=0;
	for(;x;x-=(x&(-x)))ans+=cnt[x];
	return ans;
}
int main(){
	scanf("%d%d",&n,&m);
	rep(i,1,n)scanf("%d%d",&l[i],&r[i]);
	rep(d,1,m){
		for(int i=d;i<=m;i+=d)dj[i].push_back(d);
	}
	rep(i,1,n)lk[r[i]].push_back(l[i]);
	per(i,m,1){
		rep(j,0,lk[i].size()-1){
			add(lk[i][j]);
		}
		rep(j,0,dj[i].size()-1){
			ans[dj[i][j]]+=ask(i);
			ans[dj[i][j]]-=ask(max(i-dj[i][j],0));
		}
	}
	rep(i,1,m)printf("%d\n",ans[i]);
	return 0;
}





Measured memory_bytes: 29952
// B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<string>
using namespace std;


int main()
{
    int n;
    string s,s2;
    int ans = 0;
    cin >> n;
    cin >> s;

    for (int i = 0; i <= n-3; i++) {
        s2 = s.substr(i, 3);
        if (s2 == "ABC") {
            ans++;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 256