akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
int max_n = 100;
#include <bits/stdc++.h>
using namespace std;
int main(){
  string w;
  cin >> w;
  vector<int>a(27,0);
  for(int i; i<w.length(); i++){
    a.at(w[i]-'a')++;
  }
  string rsl = "Yes";
  for(int i; i<27; i++){
    if(a[i] % 2 != 0) rsl = "No";
  }
  cout << rsl << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) throws Exception{
        
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println((n/500)*1000 + ((n%500)/5)*5);
      
      
      
      
    }
}

Measured memory_bytes: 22612
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

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

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////




int main() {

	struct UnionFind {
		vector< int > data;

		UnionFind(int sz) {
			data.assign(sz, -1);
		}

		bool unite(int x, int y) {
			x = find(x), y = find(y);
			if (x == y) return (false);
			if (data[x] > data[y]) swap(x, y);
			data[x] += data[y];
			data[y] = x;
			return (true);
		}

		int find(int k) {
			if (data[k] < 0) return (k);
			return (data[k] = find(data[k]));
		}

		int size(int k) {
			return (-data[find(k)]);
		}
	};

	ll N, M;
	cin >> N >> M;

	ll A[MAX];
	ll B[MAX];

	repn(i, M) cin >> A[i] >> B[i];

	UnionFind uf(N+1);

	ll ans[MAX];

	ans[M] = N * (N - 1) / 2;

	for (int i = M; i >= 1; i--) {

		ll x = uf.size(A[i]);
		ll y = uf.size(B[i]);

		if (uf.unite(A[i], B[i])) { ans[i - 1] = ans[i] - x * y; }
		else { ans[i - 1] = ans[i]; }

	}

	repn(i, M) cout << ans[i] << endl;




	system("PAUSE");
}

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

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

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

    n %= 10;
    if(n == 2 || n == 4 || n == 5 || n == 7 || n==9) {
        cout << "hon\n";

    } else if(n== 0 || n== 1 || n==6 || n==8) {
        cout << "pon\n";

    } else {
        cout << "bon\n";
    }
    return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(string a,string b){
	return a+b<b+a;
}
int main(){
	int n,l;
	cin>>n>>l;
	string a[n];
	for(int i=0;i<n;++i)
		cin>>a[i];
	sort(a,a+n,cmp);
	for(int i=0;i<n;++i)
		cout<<a[i];
	return 0;
}

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


int main(){
    int a,b,k;
    cin >> a >> b >> k;
    set<int> st;
    for (int i = 0;i < k;i++){
        if (i+a <= b) st.insert(i+a);
    }
    for (int i = 0;i < k;i++){
        if (b+i-k+1 >= a) st.insert(b+i-k+1);
    }
    for (auto q:st){
        cout << q << endl;
    }

   return 0;

}

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

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

    int ans = 0;
    string str;
    for (int i = 1; i <= n; ++i)
    {
        str = to_string(i);
        if(str.length() % 2 == 1){
            ans++;
        }
    }

    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

bool can[3][3][3][3];

int md(int x)
{
    return (x % 3 + 3) % 3;
}

void dfs(int a, int b, int x, int y)
{
    if (can[a][b][x][y])
    {
        return;
    }
    can[a][b][x][y] = true;
    dfs(a, b, md(x - 1), md(y + 2));
    dfs(a, b, md(x + 2), md(y - 1));
}

const int N = 1e5 + 7;

int A[N][2];
int B[N][2];

int gA(int l, int r, int t)
{
    return md(A[r][t] - (l ? A[l - 1][t] : 0));
}

int gB(int l, int r, int t)
{
    return md(B[r][t] - (l ? B[l - 1][t] : 0));
}

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#else
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            dfs(i, j, i, j);
        }
    }
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    vector <int> a(2), b(2);
    for (int i = 0; i < n; i++)
    {
        a[s[i] == 'A']++;
        A[i][0] = a[0];
        A[i][1] = a[1];
    }
    for (int i = 0; i < m; i++)
    {
        b[t[i] == 'A']++;
        B[i][0] = b[0];
        B[i][1] = b[1];
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--, b--, c--, d--;
        int a0 = gA(a, b, 1);
        int a1 = gA(a, b, 0);
        int b0 = gB(c, d, 1);
        int b1 = gB(c, d, 0);
        cout << (can[a0][a1][b0][b1] ? "YES" : "NO") << '\n';
    }
}


Measured memory_bytes: 2512
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl

int gcd(int a,int b){
    if(a<=0||b<=0){
        return 0;
    }
    if(a<b)swap(a,b);
    int r=a%b;
    while(r){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}

signed main(){
    int N;
    int A[114514];
    cin >> N;
    REP(i,N){cin >> A[i];}
    int Ans=A[0];
    REP(i,N){
        Ans=gcd(Ans,A[i]);
    }
    cout << Ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
  string o,e;
  cin>>o>>e;
  string ans;
  if(o.length()-e.length()==0){
    rep(i,o.length()){
      ans+=o[i];
      ans+=e[i];
    }
  }
  if(o.length()-e.length()==1){
    rep(i,o.length()-1){
      ans+=o[i];
      ans+=e[i];
    }
    ans+=o[o.length()-1];
  }
  cout<<ans<<endl;
}

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

int main(void)
{
	int S;
	int h, m, s;

	cin >> S;
	h = S / 3600;
	m = S / 60 % 60;
	s = S % 60;
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}

Measured memory_bytes: 3092
#include <cstdio>

#define N 3

/* -----------------------------------------------------------------------------
	大域データ
----------------------------------------------------------------------------- */

int main () {

	int A, B;
	int cnt = 0;

	// タップ口数A，ほしい口数Bの読込み
	scanf("%d %d", &A, &B);
	// 
	if(B <= 1) printf("%d\n", 0);
	else if(B <= A) printf("%d\n", 1);
	else printf("%d\n", (B - A - 1)/(A - 1) + 2);

	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define frr(i,x,y) for(ll i=x-1;i>=y;i--)
#define inf 10000000000000000
const ll mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b)
{
    ll ans=1;
    while(b!=0)
    {
        if(b&1)
        {
            ans*=a;
            ans%=mod;
        }
        a=(a*a);
        a%=mod;
        b>>=1;
    }
    return ans%mod;
}
void solve()
{
    ll r,c,k;
    cin>>r>>c>>k;
    vector<string> arr(r);
    fr(i,0,r)
    {
        cin>>arr[i];
    }
    VL pref(r),visit(r,0);
    fr(i,0,r)
    {
        ll ct=0;
        fr(j,0,c)
        {
            if(arr[i][j]=='#')
                ct++;
        }
        pref[i]=ct;
    }
    vector<VL> ans(r,VL(c,0));
    ll fg=0;
    ll ct=0;
    fr(i,0,r)
    {
        ll pc=0;
        if(pref[i]!=0)
        {
            fg=1;
            visit[i]=1;
            ct++;
            pc++;

            fr(j,0,c)
            {
                
                ans[i][j]=ct;
                if(arr[i][j]=='#'&&pref[i]!=pc)
                {
                    ct++;pc++;
                }
            }
            //if()
        }
        else
        {
            
            if(fg==1)
            {
                visit[i]=1;
                fr(j,0,c)
                {
                    ans[i][j]=ans[i-1][j];
                }
            }
        }
    }
    frr(i,r,0)
    {
        if(visit[i]==0)
        {
            fr(j,0,c)
            {
                ans[i][j]=ans[i+1][j];
            }
        }
    }
    fr(i,0,r)
    {
        fr(j,0,c)
        {
            cout<<ans[i][j]<<" ";

        }
        cout<<"\n";
    }
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t=1;
    //cin>>t;
    while(t--)
    {
    	solve();
    }
	return 0;
}

Measured memory_bytes: 1664
N, K = map(int, input().split())
p = list(map(int,input().split()))
ans = 0
cum = [0]
     
for i in range(len(p)):
    ex = (1 + p[i])/2
    p[i] = ex
        
for i in  range(len(p)):
    cum.append(p[i] + cum[i])
        
for i in range(K, N+1):
    ans  = max(ans, cum[i] - cum[i-K])
     
print(ans)

Measured memory_bytes: 24804
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> Pr;

int n;
vector<vector<Pr> > g;
int dist[20];
bool leaf[20];

int calc(int v, int par, int dst)
{
	leaf[v] = true;
	dist[v] = dst;
	
	int res = 0;
	for (int i = 0; i < g[v].size(); i++){
		int to = g[v][i].first;
		int cost = g[v][i].second;
		if (to == par) continue;
		int t = calc(to, v, dst + cost);
		if (t != -1){
			res += t + cost * 2;
		}
		leaf[v] = false;
	}
	
	if (leaf[v]) return -1;
	return res;
}

int main()
{
	while (scanf("%d", &n), n){
		g.clear();
		g.resize(20);
		memset(leaf, 0, sizeof(leaf));
		
		for (int i = 0; i < n - 1; i++){
			int a, b, t;
			scanf("%d %d %d", &a, &b, &t);
			g[--a].push_back(Pr(--b, t));
			g[b].push_back(Pr(a, t));
		}
		
		int res = calc(0, 0, 0);
		int t = 0;
		for (int i = 0; i < n; i++){
			if (!leaf[i]) t = max(t, dist[i]);
		}
		
		printf("%d\n", res - t);
	}
	
	return 0;
}

Measured memory_bytes: 1188
from sys import exit

A = []
for i in range(3):
    for j in input().split():
        A.append(int(j))
N = int(input())
b = [int(input()) for i in range(N)]

t = [0]*9
for bt in b:
    for j,a in enumerate(A):
        if a==bt:
            t[j] = 1

for i in [[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]:
    f = True
    for j in i:
        if t[j]==0:
            f=False
    if f:
        print('Yes')
        exit()
print('No')




Measured memory_bytes: 3064
n = int(input())
txy = [list(map(int,input().split())) for _ in range(n)]
txy.insert(0,[0,0,0])
for i in range(n):
  t = txy[i+1][0] - txy[i][0]
  x = abs(txy[i+1][1] - txy[i][1])
  y = abs(txy[i+1][2] - txy[i][2])
  if t < x+y:
    print('No')
    exit()
  elif t == x+y:
    pass
  else:
    if ((t%2 == 0) and ((x+y)%2 == 0)) or ((t%2 != 0)and((x+y)%2 != 0)):
      pass
    else:
      print('No')
      exit()
print('Yes')

Measured memory_bytes: 27324
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if(A<=C){
    if(A+B-C>=0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
  else cout<<"NO"<<endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int monsters=0;
	int specialmoves=0;
	unsigned long long sum = 0;
	cin >> monsters >> specialmoves;
	int temp=monsters;
	unsigned long long h[monsters];
	for (int i = 0; i < monsters; i++){
		cin >> h[i];
		}
	sort(h, h+ monsters);
	for (int i = 0; i < monsters-specialmoves; i++){
		sum = sum + h[i];
	}
	cout << sum<<endl;;
	return 0;

}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 510;
int n;
ll a[2][N][N], f[N][N];
ll sum[2][N][N];

ll getsum(int sig, int a,int b, int x, int y) {
	//(a,x) (b,y)
	swap(x, b);
	if (a <= x && b <= y)
		return sum[sig][x][y] - sum[sig][a - 1][y] - sum[sig][x][b - 1] + sum[sig][a - 1][b - 1];
	else return 0;
}

ll ss;
int main() {
	cin>>n;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			if (i != j) {
				scanf("%lld\n", &a[i<j][i][j]), ss += a[i<j][i][j];
			}
		}
	}
	for(int o=0;o<2;o++) {
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= n; j++) {
				sum[o][i][j] = sum[o][i][j - 1] + a[o][i][j];
			}
		}

		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= n; j++) {
				sum[o][i][j] += sum[o][i - 1][j];
			}
		}
	}

	memset(f,128,sizeof f);
	ll ans = f[0][0];
	f[0][0] = 0;
	for(int l = 0; l <= n; l++) {
		for(int r = l; r <= n; r++) {
			for(int nx = r + 1; nx <= n; nx++) {
				if (r == 0 && nx == 2) {
					int kk = r;
				}
				f[r][nx] = max(f[r][nx], f[l][r] + getsum(1, 1, r, r + 1, nx) + getsum(0, r + 1, nx, l + 1, nx));

			}
		}
	}
	for(int l = 1; l <= n; l++) ans = max(ans, f[l][n]);
	cout<<ss - ans<<endl;
}

Measured memory_bytes: 10368
use std::io;
use std::str::FromStr;
use std::collections::HashSet;

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

fn combination(n: u64, mut m: u64) -> u64 {
    if n < m {
        return 0;
    }
    if m > n - m {
        m = n - m
    }

    let mut ret = 1u64;
    for i in 0..m {
        ret *= n - i;        
    }

    let mut div = 1u64;
    for i in 1..(m+1) {
        div *= i;
    }
    ret / div
}

#[derive(Debug, PartialEq, Clone)]
struct Node {
    parent: Option<usize>, 
    size: usize,
}

#[derive(Debug, PartialEq)]
pub struct UnionFind {
    tree: Vec<Node>,
}

impl UnionFind {
    pub fn new(n: usize) -> UnionFind {
        UnionFind {tree: vec![Node {parent: None, size: 1}; n]}
    }

    pub fn unite(&mut self, i: usize, j: usize) {
        let root_i = self.find(i);
        let root_j = self.find(j);
        if root_i == root_j {
            return
        }

        if self.tree[root_i].size < self.tree[root_j].size {
            self.tree[root_i].size += self.tree[root_j].size;
            self.tree[root_j].parent = Some(root_i);
        } else {
            self.tree[root_j].size += self.tree[root_i].size;
            self.tree[root_i].parent = Some(root_j);
        }

    }

    pub fn find(&mut self, i: usize) -> usize {
        match self.tree[i].parent {
            Some(p) => {
                let root = self.find(p);
                self.tree[i].parent = Some(root);
                root
            },
            None => i
        }
    }

    pub fn equiv(&mut self, i: usize, j: usize) -> bool {
        self.find(i) == self.find(j)
    }

    pub fn size(&mut self, i: usize) -> usize {
        let root = self.find(i);
        self.tree[root].size
    }
}

fn main() {
    let (n, m) = input_tuple();

    let mut a_vec: Vec<usize> = Vec::new();
    let mut b_vec: Vec<usize> = Vec::new();
    for i in 0..m {
        let (a, b) = input_tuple();
        a_vec.push(a - 1);
        b_vec.push(b - 1);
    }
    a_vec.reverse();
    b_vec.reverse();
    let mut tree: UnionFind = UnionFind::new(n as usize);
    let mut buf = combination(n as u64, 2) as usize;
    let mut ans: Vec<usize> = Vec::new();
    for i in 0..m as usize {
        ans.push(buf);
        let a = a_vec[i];
        let b = b_vec[i];
        if tree.equiv(a, b) {
            continue;
        }    
        buf -= tree.size(a) * tree.size(b);
        tree.unite(a, b);
    }
    ans.reverse();
    for a in ans {
        println!("{}", a);
    }
}


Measured memory_bytes: 13564
#include <iostream>

int main(){
  int N, T;
  std::cin>>N>>T;
  const long long NUM = 1000000000;
  long long k_c = NUM;

  for(int i = 0;i < N;i++){
    int c, t;
    std::cin>>c>>t;
    if(t <= T && c < k_c){
      k_c = c;
    }
  }
  if(k_c == NUM){
    std::cout<<"TLE"<<std::endl;
  }else{
    std::cout<<k_c<<std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
using System;

using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        //回答
        //Console.WriteLine(Math.Ceiling((double)N / X) * T);

        //整数の入力
        //int N = int.Parse(Console.ReadLine());

        // 複数の入力
        //string[] line = Console.ReadLine().Split(' ');
        //int N = int.Parse(line[0]);
        //int X = int.Parse(line[1]);
        //int T = int.Parse(line[2]);


        String N = Console.ReadLine();

        int sum = 0;
        for(int i =0;i< N.Length; i++)
        {
            //Console.WriteLine("sum : " + sum);
            //Console.WriteLine("N[i] : " + (N[i] - '0'));
            sum += N[i] - '0';

        }

        //Console.WriteLine("sum : " + sum);

        if (sum % 9 == 0)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }



        //スペース区切りの整数の入力
        //string[] dates = Console.ReadLine().Split(' ');
        //string[] amounts = Console.ReadLine().Split(' ');

        //double date = double.Parse(input[0]);
        //double amount = double.Parse(input[1]);

        //double date = double.Parse(input[0]);
        //double amount = double.Parse(input[1]);

        //var L2 = L.Distinct().OrderBy(o => o);
        //var L2 = L.OrderBy(o => o).ToArray();

        //string input = Console.ReadLine();
        //int b = int.Parse(input[0]);
        //int c = int.Parse(input[1]);
        //文字列の入力
        //string s = Console.ReadLine();
        //出力




        //onsole.WriteLine(N);
        //Console.WriteLine(string.Join(" ", L));


        //for (int i = 1; i < N; i++)
        //{
        //    for (int j = i - 1; j > 0; j--)
        //    {
        //        if (amounts[i] >= amount)
        //        Console.WriteLine(double.Parse(amounts[i]));
        //    }
        //}

        //for (int i = 0; i < K; i++)
        //{
        //    if(D / 10  X)

        //    if(now > 0)
        //    {
        //        now -= D;
        //    }
        //    else
        //    {
        //        now += D;
        //    }

        //    //Console.WriteLine(now);
        //}

        //Console.WriteLine(Math.Abs(now));
    }
}




Measured memory_bytes: 26664
#include <iostream>
using namespace std;
int T, ans = 0;
long long em[] = {3, 5, 7};
struct node
{
    bool exist[4];
    long long num;
};

void dfs(node n)
{
    if (n.num > T)
        return;
    if (!n.exist[0])
    {
        if (n.exist[1] && n.exist[2] && n.exist[3])
            n.exist[0] = 1;
    }
    if (n.exist[0])
        ans++;
    for (int i = 0; i < 3; i++)
    {
        node nt = n;
        nt.num = nt.num * 10 + em[i];
        nt.exist[i + 1] = 1;
        dfs(nt);
    }
}

int main()
{
    cin >> T;
    node n;
    n.num = 0;
    fill(n.exist, n.exist + 4, 0);
    dfs(n);
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static final long MX = 1000000000000000000L;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        long a[] = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextLong();
        }

        long sum = 1;
        boolean zero = false;
        boolean over = false;
        for (int i = 0; i < n; i++) {
            if (a[i] == 0) {
                zero = true;
                break;
            }

            try {
                Math.multiplyExact(sum, a[i]);
            } catch (ArithmeticException e) {
                over = true;
            }

            if (!over) {
                sum *= a[i];
            }

            if (sum > MX) {
                over = true;
            }
        }

        if (zero) {
            System.out.println(0);
        } else if (over) {
            System.out.println(-1);
        } else {
            System.out.println(sum);
        }
    }
}


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

int main(void){
    int a, b, c; cin >> a >> b >> c;
    if(c <= a * 7 + b && c >= a * 7) cout << 7 << endl;
    else if(c < a * 7) {
        cout << (c + a - 1)/a << endl;
    } else {
        long long ans = 0;
        ans += c/(7*a+b) * 7;
        c %= 7*a+b;
        if(c >=7 * a) ans+= 7;
        else ans += (c+a-1)/a;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3112
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let x: i64 = read();
    let a: i64 = read();
    let b: i64 = read();
    println!(
        "{}",
        if b <= a {
            "delicious"
        } else if b <= a + x {
            "safe"
        } else {
            "dangerous"
        }
    );
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
a,b=map(int,input().split())
lx=[]
cnt=0
for i in range(a,b+1):
    t=i
    kai=0
    for j in range(5):        
        t2=t%10
        kai=kai+t2*10**(4-j)
        t=t//10
    #print(kai,i)
    if(kai==i):
        cnt=cnt+1
print(cnt)
        


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define int long long
#define rep(i, l, r) for(register int i = l;i <= r; ++ i)
int MAXN = 100010;
inline int read()
{
	register char cc = getchar(); register int cn(0), flus(1);
	while(cc > '9' || cc < '0') {if(cc == '-') flus = -flus; cc = getchar();}
	while(cc >= '0' && cc <= '9') {cn = cn * 10 + cc - 48; cc = getchar();}
	return cn * flus;
}
signed main()
{
	int x = read();
	for(register int i = -1000; ; ++ i)
	{
		for(register int j = -1000; j <= 1000; ++ j)
		{
			//printf("i = %d j = %d \n",i,j);
			if(i * i * i * i * i - j * j * j * j * j == x)
			{
				printf("%lld %lld \n",i,j);
				return 0;
			}
		}
	}
	return 0;
}

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

const int N = (int)1e6 + 5;

ll n, k, f[N], a[N];
vector<pll> v;

bool ok(ll g) {
  ll cost = 0;
  for(int i = 0 ; i < n ; ++i) {
    if(a[i] * f[i] > g) {
      ll need = (a[i] - g / f[i]);
      cost += need;
      if(cost > k) return false;
    }
  }
  return true;
}

void init() {
  cin >> n >> k;
  for(int i = 0 ; i < n ; ++i) cin >> a[i];
  for(int i = 0 ; i < n ; ++i) cin >> f[i];
  sort(a, a + n);
  sort(f, f + n);
  reverse(f, f + n);
}
void solve() {
  ll L = 0, R = 1e12, mid;
  while(L < R) {
    mid = L + (R - L) / 2;
    if(ok(mid)) R = mid;
    else L = mid + 1;
  }
  cout << L << '\n';
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  init();
  solve();
}


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

const int MAX = 200005; //適当に変更する
const long long MOD = 1000000007;

vector<int> G_bi[MAX];
vector<int> G[200005];
int pr[200005]={};

int c[MAX]={};
//queue<int> que_dfs;
int dfs(int x){
    for(int y : G[x]) dfs(y);
    int ret = 1;
    for(int y : G[x]) ret += c[y];
    c[x] = ret;
    return ret;
}
/* int f(int x){
    if (memo[x] != 0) return memo[x];
    int ret = 1;
    for(int y : G[x]) ret += f(y);
    return ret;
}
 */

long long pow2[200005]={};
long long inv2[200005]={};

int main(){
    long long n;
    cin >> n;
    pow2[0] = 1;
    inv2[0] = 1;
    for(int i=1; i<MAX; i++){
        pow2[i] = 2*pow2[i-1]%MOD;
        inv2[i] = (MOD+1)/2*inv2[i-1]%MOD;
    }

    for(int i=1; i<n; i++){
        int x,y;
        cin >> x >> y;
        G_bi[x].push_back(y);
        G_bi[y].push_back(x);
    }

    pr[1] = 1;
    queue<int> que;
    que.push(1);
    while(!que.empty()){
        int x = que.front();
        que.pop();
        for(int y : G_bi[x]){
            if(pr[y]==0){
                pr[y] = x;
                G[x].push_back(y);
                que.push(y);
            }
        }
    }
    
    //return 0;
    dfs(1);

    long long ans=(1+(MOD-inv2[n])+(MOD-(n*inv2[1])%MOD))%MOD;
    for(int x=1; x<=n; x++){
        //cout << c[x] << endl;
        long long z = (pow2[c[x]]-1)*(pow2[n-c[x]]-1)%MOD;
        z *= inv2[n];
        z %= MOD;
        ans += z;
        ans %= MOD;
    }
    cout << ans << endl;



}

Measured memory_bytes: 36224
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()
#define chmax(x,y) x=max(x,y)

const int inf=2e9+5;


int main(){
    int n; cin>>n;
    vector<vector<int>> f(n, vector<int>(10,0));
    rep(i,n){
        rep(j,10){
            cin>>f[i][j];
        }
    }
    vector<vector<int>> p(n, vector<int>(11,0));
    rep(i,n) rep(j,11) cin>>p[i][j];
    int ans=-inf;
    rep(i, 1<<10){
        if(i==0) continue;
        int karians=0;
        rep(j,n){
            int kari=0;
            rep(kk,10){
                if(f[j][kk]==1 && i>>kk&1){
                    kari++;
                }
            }
            karians+=p[j][kari];
        }
        ans=max(ans, karians);
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

int main(){
	int N; cin>>N;
  int ans=100000000;
  for(int a=1;a<N;a++){
  	int b=N-a;
    int ta=a;
    int tmp=0;
    for(int i=4;i>=0;i--){
    	tmp+=ta/(int)pow(10,i);
      tmp+=b/(int)pow(10,i);
      ta=ta%(int)pow(10,i);
      b=b%(int)pow(10,i);
    }
    if(tmp<ans) ans=tmp;
  }
	printf("%d",ans);
}

Measured memory_bytes: 256
a = input()
b = input()
ans = ''
f = 1
a = a[::-1]
b = b[::-1]
for ii in range(len(a)-len(b)+1):
    s =0
    for i,j in zip(a[ii:ii+len(b)+1],b):
        if i==j or i =='?':s+=1
    if s == len(b):
        rec = ii
        f = 2
        break
if f != 2:
    print('UNRESTORABLE')
else:
    for i in range(len(a)):
        if i == rec:ans+=b
        elif i < rec+len(b):continue
        elif a[i] == '?':ans+='a'
        else:ans +=a[i] 
    t=(a[:rec]+b+a[len(b)+rec:]).replace('?','a')
    #print(ans[::-1])
    print(t[::-1])

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>

int main(void) {
	
	int i, j, z;
	int k, s;
	int cases = 0;

	scanf("%d%d", &k, &s);

	for (i = 0; i <= k; i++) {
		for (j = 0; j <= k; j++) {
			z = s - i - j;
			if (0 <= z && z <= k) {
				cases++;
			}
		}
	}

	printf("%d", cases);

	

	return 0;
}

Measured memory_bytes: 128
N, Y = map(int, input().split())
Y //= 1000

for x in reversed(range(Y//10+1)):
    for y in reversed(range((Y-x*10)//5+1)):
        z = Y-(x*10+y*5)
        if N == sum((x,y,z)):
            print(x, y, z)
            exit()
else:
    print(-1, -1, -1)

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

int X[20][20];

int main()
{
  int N,D;cin>>N>>D;
  for (int i=1;i<=N;i++)
  {
    for (int j=1;j<=D;j++)
    {
      cin>>X[i][j]; 
    }
  }
  
  int count=0;
  for (int i=1;i<=N-1;i++)
  {
    for (int j=i+1;j<=N;j++)
    {
      double d = 0;
      for (int k=1;k<=D;k++)
      {
         d += pow(X[i][k]-X[j][k],2);
      }
      d=sqrt(d);
      //cout<<d<<endl;
      int i=0;
      while (i<=d)
      {
        i++; 
      }
      //cout<<d-(i-1)<<endl;
      if (d-(i-1)==0) count++;
    }
  }
  cout<<count<<endl;
}

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


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

    vector<int> dp(100010),h(100010);
    int n;
    cin >> n;
    rep(i, n) cin >> h[i + 1];

    dp[1] =0;
    dp[2] = abs(h[1]-h[2]);
    forx(i, 3, n+1)
    {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[n] << endl;

    return 0;
    }


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <string>

int main() {
  std::string q, s;
  std::cin >> q;

  int count = 0;
  while (std::cin >> s) {
    std::transform(s.begin(), s.end(), s.begin(), tolower);
    if (s == "END_OF_TEXT") break;
    if (s == q) count++;
  }
  std::cout << count << std::endl;
}



Measured memory_bytes: 3196
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] $) {
        int n = sc.nextInt(), q = sc.nextInt();
        String s = sc.next();
        int[] AC = new int[n + 1];
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                AC[i] = 1;
            }
        }
        for (int i = 1; i < n + 1; i++) {
            AC[i] += AC[i - 1];
        }
        for (int i = 0; i < q; i++) {
            int l = sc.nextInt(), r = sc.nextInt();
            int k = 0;
            if (r < n && s.charAt(r - 1) == 'A' && s.charAt(r) == 'C') k++;

            out.println(max(0, AC[r] - AC[l - 1] - k));
        }
        out.close();
    }
  static class sc {
        static Scanner s = new Scanner(System.in);

        static String next() {
            return s.next();
        }

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

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

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

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

#define vl vector<ll>
#define vi vector<int>

#define ff first
#define ss second

#define pb push_back
#define MOD 1e9+7 
const int nax = 1e6+5;
#define display(v) for(int i =0;i<v.size();++i)cout << v[i] << " "

inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }


int main()
 {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    map<pair<int,int>,int> mp;
    for(int i =1;i<=n;++i){
        string str = to_string(i);
        int f = str.front() - '0';
        int b = str.back() - '0';
        mp[{f,b}]++;
    }
    ll ans = 0;
    for(int i =0;i<=9;++i){
        for(int j = 0;j<=9;++j){
            ans = ans + mp[{i,j}]*mp[{j,i}];
        }
    }
    cout << ans;

    return 0;
 }

Measured memory_bytes: 256
from collections import deque
k = int(input())
lun = deque([i for i in range(1, 10)])
for i in range(1, k+1):
    num = lun.popleft()
    if num % 10 != 0:
        lun.append(num * 10 + ((num % 10) - 1))
    lun.append(num * 10 + (num % 10))
    if num % 10 != 9:
        lun.append(num * 10 + (num % 10) + 1)
print(num)

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

int h[100003], n;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    h[n] = 2e9;
    for(int i=0;i<n;i++)
    {
        cin >> h[i];
    }
    int ans = 0, tmp = 0;
    for(int i=0;i<n;i++)
    {
        if(h[i] >= h[i+1]) tmp++;
        else tmp = 0;
        ans = max(ans, tmp);
    }
    cout << ans;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,A,B; cin>>N>>A>>B;
    if((B-A)%2==0) cout<<"Alice"<<endl;
    else cout<<"Borys"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long long ll;

template <typename T> void max_self(T& a, T b){
  a = max(a,b);
}

template <typename T> void min_self(T& a, T b){
  a = min(a,b);
}

void solve(){	
  string a,b;
  cin>>a>>b;
  for(int i=0;i<a.size();i++){
    if(a[i] != b[i]){
      cout<<"No\n";
      return;
    }
  }
  cout<<"Yes\n";
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //int t; cin >> t;
  //while(t--) solve();
  //
  solve();
  return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#define int long long
using namespace std;

int n;
int q[100000];
bool isPrime[1000001];

void setPrime(int n) {
	int i, j;
	for (i = 2; i <= n; i++) isPrime[i] = true; isPrime[0] = isPrime[1] = false;
	for (i = 2; i <= n; i++) {
		if (isPrime[i]) {
			for (j = i * 2; j <= n; j += i)
				isPrime[j] = false;
		}
	}
}

int dp[100001];
int mod = 1000000007;

signed main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> q[i];
	setPrime(1000000);
	
	if (!isPrime[q[0]]) { cout << 0 << endl; return 0; }
	
	dp[0] = 1;
	for (i = 0; i < n; i++) {
		if (i + 1 == n || (isPrime[q[i + 1]] && q[i] < q[i + 1])) {
			dp[i + 1] += dp[i];
			dp[i + 1] %= mod;
		}
		if (i == n - 1) continue;
		if (i + 2 == n || (isPrime[q[i + 2]] && q[i] < q[i + 2])) {
			dp[i + 2] += dp[i];
			dp[i + 2] %= mod;
		}
	}
	cout << dp[n] << endl;
	return 0;
}


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

using namespace std;

signed main() {
    int k, x;
    cin >> k >> x;
    int yen = 500 * k;
    if (yen >= x && yen - 100 <= x) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }  
    return false;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
int n, m, p, MOD;
lint pow2[2505], ans;
inline int ask(int x1, int y1, int x2, int y2) {
	cout << "? " << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << endl;
	int ret = 0; cin >> ret; return ret;
}
inline int siz(int x1, int y1, int x2, int y2) {
	return (x2 - x1 + 1) * (y2 - y1 + 1);
}
inline void search(int x1, int y1, int x2, int y2, int las) {
	if (x1 == x2 && y1 == y2) {
		ans = (ans + pow2[x1 * m + y1]) % MOD;
	} else if (x2 - x1 < y2 - y1) {
		int mid = (y1 + y2) >> 1;
		int a1 = ask(x1, y1, x2, mid);
		int a2 = las - a1;
		if (a1) {
			if (a1 == siz(x1, y1, x2, mid)) {
				rep (i, x1, x2) {
					rep (j, y1, mid) {
						search(i, j, i, j, 1);
					}
				}
			} else {
				search(x1, y1, x2, mid, a1);
			}
		}
		if (a2) {
			if (a2 == siz(x1, mid + 1, x2, y2)) {
				rep (i, x1, x2) {
					rep (j, mid + 1, y2) {
						search(i, j, i, j, 1);
					}
				}
			} else {
				search(x1, mid + 1, x2, y2, a2);
			}
		}
	} else {
		int mid = (x1 + x2) >> 1;
		int a1 = ask(x1, y1, mid, y2);
		int a2 = las - a1;
		if (a1) {
			if (a1 == siz(x1, y1, mid, y2)) {
				rep (i, x1, mid) {
					rep (j, y1, y2) {
						search(i, j, i, j, 1);
					}
				}
			} else {
				search(x1, y1, mid, y2, a1);
			}
		}
		if (a2) {
			if (a2 == siz(mid + 1, y1, x2, y2)) {
				rep (i, mid + 1, x2) {
					rep (j, y1, y2) {
						search(i, j, i, j, 1);
					}
				}
			} else {
				search(mid + 1, y1, x2, y2, a2);
			}
		}
	}
}
int main() {
	cin >> n >> m >> p >> MOD;
	pow2[0] = 1;
	rep (i, 1, 2500) {
		pow2[i] = pow2[i - 1] * 2ll % MOD;
	}
	//search(0, 0, n - 1, m - 1, p);
	lint poww = 1;
	rep (i, 0, n - 1) {
		rep (j, 0, m - 1) {
			(ans += ask(i, j, i, j) * poww) %= MOD;
			poww = poww * 2 % MOD;
		}
	}
	cout << "! " <<  ans << endl;
	return 0;
}

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

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

  string S;
  map<int, int> mp;
  int total_acs = 0;
  rep(i,0,N-1) {
    char c;
    cin >> c;
    if (S.back() == 'A' && c == 'C') {
      total_acs++;
    }
    mp[i] = total_acs;
    S.push_back(c);
  }

  vector<int> answers;
  rep(i,0,Q-1) {
    int l, r;
    cin >> l >> r;
    int answer = mp[r-1] - mp[l-1];
    answers.push_back(answer);
  }

  for (int answer: answers)
    cout << answer << endl;

  return 0;
}


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

int main() {
  int S;
  cin >> S;
  int a = S/100;
  int b = S%100;
  if (1 <= a && a <= 12 && 1 <= b && b <= 12) {
    cout << "AMBIGUOUS" << endl;
  }
  else if (1 <= a && a <= 12) {
    cout << "MMYY" << endl;
  }
  else if (1 <= b && b <= 12) {
    cout << "YYMM" << endl;
  }
  else {
    cout << "NA" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 30);
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	cin >> S;
	ll ans = 0;
	REP(i, (1 << (SZ(S)-1))) {
		ll sum = 0;
		ll now = S[0] - '0';
		FOR(j, 1, SZ(S)) {
			if ((i>>(SZ(S)-1-j)) & 1) {
				sum += now;
				now = S[j] - '0';
			}
			else {
				now *= 10;
				now += S[j] - '0';
			}
		}
		sum += now;
		ans += sum;
	}
	cout << ans << endl;
	PAU;
	return 0;
}


Measured memory_bytes: 512
require("fs").readFileSync("/dev/stdin","utf8").trim().split('\n').some(function(i){j=i.split(' ');if(j[1])a=j[0],b=j[1],c=j[2],d=j[3],e=j[4],f=j[5],g=a*a,h=b*b,k=c*c,l=d*d,m=e*e,n=f*f,o=a-c,r=b-d,s=b-f,t=a-e,p=(s*(h-l+g-k)-r*(h-n+g-m))/(2*s*o-2*r*t),q=(t*(g-k+h-l)-o*(g-m+h-n))/(2*t*r-2*o*s),console.log(p.toFixed(3),q.toFixed(3),Math.sqrt((a-p)*(a-p)+(b-q)*(b-q)).toFixed(3))})

Measured memory_bytes: 7904
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

int main(){
  string s; int k; cin >> s >> k;
  int n = s.size();
  vector<string> list;

  for (int j = 1; j <= k; j++){// j;文字列の長さ
    // s[i]から始まる長さjの文字列はs[i]s[i+1]...s[i+j-1].
    for (int i = 0; i+j-1 < n; i++){
      string t;
      rep(k, j) t += s[i+k];
      list.pb(t);
    }
  }

  sort(all(list));
  //for(auto p : list) std::cout << p << '\n';
  list.erase(unique(all(list)), list.end());

  std::cout << list[k-1] << '\n';
}


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

#define rp(i, k, n) for (ll i = k; i < n; i++)
#define ll  long long

ll mod = 1e9 + 7;


int main() {
    string s;
    cin >> s;
    rp(i,0,3) {
        if (s.at(i) == s.at(i+1)) {
            printf("Bad");
            return 0;
        }
    }
    printf("Good");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(int argc, char** argv) {
  int A, B;
  std::cin >> A >> B;
  if ( 0 < A && A < 10 && 0 < B && B < 10) {
    std::cout << A*B << '\n';
  } else {
    std::cout << "-1\n";
  }
}


Measured memory_bytes: 256
N = int(raw_input())
r=[]
for i in range(N):
    r.append(map(int, raw_input().split()))

ave = 0.0
for i in range(N):
    xi = r[i][0]
    yi = r[i][1]
    for j in range(i, N):
        xj = r[j][0]
        yj = r[j][1]
        rij = ((xi-xj)**2 + (yi-yj)**2)**0.5
        ave = ave + rij

ave = ave*2/N

print ave

Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  in x;
  in a,b;
  cin>>x;
  int d;
  d=sqrt(sqrt(x)+1)+1;
  
  //cout<<d<<endl;
  for(in i=-d+1;i<d+1;i++){
    for(in j=-d+1;j<d+1;j++){
      if((i-j)*(pow(i,4)+pow(i,3)*j+pow(i,2)*pow(j,2)+i*pow(j,3)+pow(j,4))==x){
        a=i;
        b=j;
        break;
      }
    }
  }
  cout<<a<<" "<<b<<endl;
}

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

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

    int mx = 0, s = 0;
    queue<int> q;
    for(int i = 0; i < n; i++) {
        s += a[i];
        q.push(a[i]);
        if(q.size() > k){
            s -= q.front();
            q.pop();
        }
        if(q.size() == k){
            mx = max(mx, s);
        }
    }
    double ans = mx;
    ans /= 2;
    printf("%.10f\n", ans);

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];

int main(){
  string s;
  cin >> s;
  bool cnt[26] ;
  rep(i,26)
    cnt[i] = true ;
  rep(i,s.size())
    cnt[s[i] - 'a'] = false ;
  rep(i,26){
    if(cnt[i]){
      cout << (char)(i +'a') << endl;
      return 0 ;
    }
  }
  cout << "None" << endl;
  return 0 ;
}
    
    

Measured memory_bytes: 512
N=int(input())
A1=list(map(int,input().split()))
A2=list(map(int,input().split()))
l=[]

for i in range(N):
    ans=0
    for j in range(i+1):
        ans+=A1[j]
    for k in range(j,N):
        ans+=A2[k]
    l.append(ans)
print(max(l))
    
        

Measured memory_bytes: 3060
/*g++ main.cpp -o main.out*/
/*./main.out*/
/*std::ios::sync_with_stdio(false);cin.tie(0);*/

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

#define LL long long
#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

#define ree(n,a) memset(n,a,sizeof(n));

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))

int main()
{
    LL a,b;
    cin>>a>>b;
    if(abs(a-b)==0||abs(a-b)==1)cout<<"Brown"<<endl;
    else cout<<"Alice"<<endl;
    return 0;
}


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

int main() {
    int N, W;
    cin >> N >> W;
    long long w[110];
    long long v[110];

    for (int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
    }
    long long INF = 10000000000;
    long long dp[110][100010];

    //dpテーブルをINFで初期化
    for (int i = 0; i < N + 1;i++) {
        for (int j = 0; j < 100010; j++) {
            dp[i][j] = INF;
        }
    }
  
    dp[0][0] = 0;

    //dpループ
    for (int i = 0; i < N; i++) {
        for (int sum_v = 0; sum_v < 100009; sum_v++) {
            if (sum_v - v[i] >= 0) {
                dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v - v[i]] + w[i]);
            }
            dp[i + 1][sum_v] = min(dp[i][sum_v], dp[i+1][sum_v]);
        }
    }

    long long ans = 0;
    for (long long sum_v = 0; sum_v < 100010; sum_v++) {
          if (dp[N][sum_v] <= W){
          ans = sum_v;
          //cout<<ans<<"###"<<sum_v<<endl;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 82544
class UnionFind
  def initialize(n)
    @size = Array.new(n, 1)
    @rank = Array.new(n, 0)
    @parent = []

    (0..n).each do |i|
      @parent[i] = i
    end
  end

  def find(x)
    if @parent[x] == x
      x
    else
      @parent[x] = find(@parent[x])
    end
  end

  def unite(x, y)
    x = find(x)
    y = find(y)
    return if x == y

    if @rank[x] < @rank[y]
      @parent[x] = y
      @size[y] += @size[x]
    else
      @parent[y] = x
      @size[x] += @size[y]

      @rank[x] += 1 if @rank[x] == @rank[y]
    end
  end

  def same?(x, y)
    find(x) == find(y)
  end

  def size(x)
    @size[find(x)]
  end
end

N, Q = gets.split.map(&:to_i)
uf = UnionFind.new(N + 1)

Q.times do
  t, u, v = gets.split.map(&:to_i)

  if t == 0
    uf.unite(u, v)
  else
    if uf.same?(u, v)
      puts 1
    else
      puts 0
    end
  end
end


Measured memory_bytes: 18992
using System;
using System.Linq;
namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            Console.WriteLine(string.Join(" ",(from q in Console.ReadLine().Split(" .,".ToArray()) where q.Length >= 3 && q.Length <= 6 select q).ToArray()));
        }
    }
}

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

LL ans;
vector<LL> p;
vector<LL> cnt;

LL find_root(LL x) {
  if (p[x] != x) p[x] = find_root(p[x]);
  return p[x];
}

void unite(LL x, LL y) {
  LL nx = find_root(x);
  LL ny = find_root(y);
  ans = 0;
  if (nx == ny) return;
  else {
    p[ny] = nx;
    ans = cnt[nx] * cnt[ny];
    cnt[nx] += cnt[ny];
  }
}

int main() {
  LL n, m;
  cin >> n >> m;
  p = vector<LL>(n);
  cnt = vector<LL>(n, 1);
  for (int i = 0; i < n; i ++) p[i] = i;

  vector<LL> a(m), b(m);
  for (int i = 0; i < m; i ++) {
    int s, t; cin >> s >> t;
    s --, t --;
    a[i] = s, b[i] = t;
  }

  vector<LL> res(m);
  res[m - 1] = n * (n - 1) / 2;
  for (int i = m - 1; i >= 1; i --) {
    unite(a[i], b[i]);
    res[i - 1] = res[i] - ans;
  }

  for (int i = 0; i < m; i ++) {
    cout << res[i] << endl;
  }
}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

const int MOD = 2019;

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

	string s;
	cin>>s;

	int n = s.length();

	int suf = 0; 
	int power_of_ten = 1;

	vector<int>cnt_suf(MOD);

	ll ans = 0;
	cnt_suf[suf]++; //emopty suffixes

	for(int i = n - 1;i>=0;i--)
	{
		int digit = s[i] - '0';

		suf = (suf + digit * power_of_ten) % MOD;

		power_of_ten = 10 * power_of_ten % MOD;

		ans += cnt_suf[suf];
		cnt_suf[suf]++;
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3684