akhauriyash/Code-Regression huggingface dataset:
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;

public class Main 
{
	static HashMap<String, String> groupdef;
	static String firstgroup;
	static TreeSet<String> members;
	static TreeSet<String> checked;
	
	static void get(String g)
	{
		String con = groupdef.get(g);
		int start = 0;
		int mem = 0;
		for(int i = 0; i < con.length(); i++)
		{
			if(con.charAt(i) == ',' || con.charAt(i) == '.')
			{
				String word = con.substring(start, i);
				start = i+1;
				
				if(groupdef.containsKey(word))
				{
					if(!checked.contains(word))
						get(word);
				}
				else
				{
					members.add(word);
				}
			}
		}
		checked.add(g);
	}

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		
		while(true)
		{
			int n = sc.nextInt();
			if(n == 0)break;
			groupdef = new HashMap<String, String>();
			members = new TreeSet<String>();
			checked = new TreeSet<String>();
			
			for(int i = 0; i < n; i++)
			{
				String s = sc.next();
				int lim = s.indexOf(':');
				String groupname = s.substring(0, lim);
				String groupcon = s.substring(lim+1);
				if(i == 0)firstgroup = groupname;
				groupdef.put(groupname, groupcon);
			}
			
			get(firstgroup);
			System.out.println(members.size());
		}
	}
}



Measured memory_bytes: 37948
x,n = map(int,input().split())

if n == 0:
  print(x)
else:
  p = set(map(int,input().split()))
  i = 0
  while True:
    x_p,x_n = x+i,x-i
    if not x_n in p:
      print(x_n)
      break
    if not x_p in p:
      print(x_p)
      break
    i += 1

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

typedef pair<int, int> P;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int w, h;
bool visited[64][64];
vector<string> maze;

bool check(int x, int y){
	return x >= 0 && x < w && y >= 0 && y < h;	
}

int dfs(int x, int y){
	if(maze[y][x] == 'B')
		return 1;
	else if(maze[y][x] == 'W')
		return 2;
	
	int res = 0;
	for(int i = 0; i < 4; ++i){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if(!check(nx, ny) || visited[ny][nx])
			continue;
		visited[ny][nx] = true;
		res |= dfs(nx, ny);
	}
	return res;
}
int main() {
	while(cin >> w >> h && (w || h)){
		string a;
		maze.clear();
		int cntB = 0, cntW = 0;
		for(int i = 0; i < h; ++i){
			cin >> a;
			maze.push_back(a);
		}
		for(int y = 0; y < h; ++y){
			for(int x = 0; x < w; ++x){
				if(maze[y][x] != '.')
					continue;
				memset(visited, 0, sizeof(visited));
				visited[y][x] = true;
				int res = dfs(x, y);
				if(res == 1)
					cntB++;
				else if(res == 2)
					cntW++;
			}
		}
		cout << cntB << " " << cntW << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 1e8;
const int INF = 1e9;
const int MOD = 998244353;


int main() {
    int n;
    cin >> n;
    vector<double> v (n);
    for (int i = 0; i < n; i++)
        cin >> v[i];
    sort(v.rbegin(), v.rend());
    while (v.size() > 1) {
        double val1 = v.back();
        v.pop_back();
        double val2 = v.back();
        v.pop_back();
        v.push_back((val1 + val2) / 2);
        sort(v.rbegin(), v.rend());
    }
    cout << setprecision(10) << v[0];
}

Measured memory_bytes: 256
H, W = map(int, input().split())
A = [[i for i in input()]for j in range(H)]
B = [["." for i in range(W)]for i in range(H)]
B[0][0] = "#"
x = 0; y = 0
while(True):
    if x == H-1 and y<W-1:
        if A[x][y+1] == "#":
            y += 1
        else:
            break
    elif x<H-1 and y == W-1:
        if A[x+1][y] == "#":
            x += 1
        else:
            break
    elif x==H-1 and y==W-1:
        B[x][y] = "#"
        break
    else:
        if A[x][y+1] == "#":
            y += 1
        elif A[x+1][y] == "#":
            x += 1
        else:
            break
    B[x][y] = "#"
for i in range(H):
    for j in range(W):
        if A[i][j]!=B[i][j]:
            print("Impossible")
            exit()
print("Possible")


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if ((A + B) > (C + D)) {
  cout << "Left" << endl;
  }
  else if ((A + B) == (C + D)) {
  cout << "Balanced" << endl;
  }
  else {
  cout << "Right" << endl;
  }
  
}


Measured memory_bytes: 256
//============================================================================
// Name        : hoba.cpp :)
// Author      : (O_O Diab) (Why_not) (el 3AQ)
// Version     :
// Copyright   : please, Don't touch me :(
// Description : problem G in C++
/* IDEA        : interesting problem the main idea
 * to gain the longest K we need to find seq which start and end with the same
 * number so for each number let us store the start and end pos we can do it easily
 * using set
 * depend on OVERLAP
 */
//============================================================================
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define rw freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define EPS 1e-6
// to convert string to number use int a = stoi(string);
// to convert number to string use string s = to_string(int);
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace __gnu_pbds;
using namespace std;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int N = 1e5 + 5, mod = (int) 1e9 + 7, INF = 0x3f3f3f3f;
inline ll compute(ll x) {
	ll fact = 1;
	for (ll i = 1; i <= x; ++i) {
		fact *= i;
		fact %= mod;
	}
	return fact;
}
int main() {
	FAST;
	ll a,
	b;
	cin >> a >> b;
	if (abs(a - b) > 1)
		f(0);
	ll fact1 = compute(a);
	ll fact2 = compute(b);
	ll ans = fact1 * fact2;
	ans %= mod;
	if (a == b)
		ans *= 2;
	ans %= mod;
	f(ans);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <atcoder/all>

using namespace std;
using namespace atcoder;

#define all(v) (v).begin(),(v).end()
using ll = long long;
constexpr ll INF = 1e18;

vector<ll> solver(ll N, ll Q, vector<ll> a, vector<ll> t, vector<ll> u, vector<ll> v) {
    fenwick_tree<ll> fw(N);
    vector<ll> ans;
    for (int i = 0; i < N; i++) {
        fw.add(i, a[i]);
    }
    for (int i = 0; i < Q; i++) {
        if (t[i] == 0) {
            fw.add(u[i], v[i]);
        } else {
            ans.push_back(fw.sum(u[i], v[i]));
        }
    }
    return ans;
}

int main(void) {
    ll N, Q;
    cin >> N >> Q;
    vector<ll> a(N);
    vector<ll> t(Q), u(Q), v(Q);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < Q; i++) {
        cin >> t[i] >> u[i] >> v[i];
    }
    for (auto&& x : solver(N, Q, a, t, u, v)) {
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 40032
import math

K = int(input())
arr = []
a = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    arr.append(math.gcd(i, j))      
for j in range(len(arr)):
  for k in range(1,K+1):
    a += math.gcd(arr[j],k)
print(int(a))

Measured memory_bytes: 9356
n=int(input())
alst=list(map(int,input().split()))

csum=[0]*(n+1)
xor=[0]*(n+1)

for i in range(n):
    csum[i+1]=csum[i]+alst[i]
    xor[i+1]=xor[i]^alst[i]

ans=0

for i in range(n):
    left=0
    right=i

    while abs(right-left)>0:
        center=(right+left)//2

        s=csum[i+1]-csum[center]
        x=xor[i+1]^xor[center]

        if s==x:
            right=center
        else:
            left=center+1
    
    ans+=i-right+1

print(ans)

Measured memory_bytes: 101652
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String readline = br.readLine();

		String[] set = readline.split(" ");

		int a = Integer.parseInt(set[0]);
		int b = Integer.parseInt(set[1]);
		int c = Integer.parseInt(set[2]);

		if (a < b && b < c ) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}

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

namespace ABC130C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            long W = long.Parse(input[0]);
            long H = long.Parse(input[1]);
            long x = long.Parse(input[2]);
            long y = long.Parse(input[3]);

            double ans;//面積が実数になる場合がある
            int plural;//答えが複数あるか　ある=1　ない=0
            if (W % 2 == 0 && H % 2 == 0 && W / 2 == x && H / 2 == y)
            {
                //与えられた点が中央にあるとき
                ans = W * H / 2;
                plural = 1;
            }
            else
            {
                //与えられた点が中央にないとき
                ans = (double)W * (double)H / 2;
                plural = 0;
            }
            Console.WriteLine(ans + " " + plural);

        }
    }
}


Measured memory_bytes: 11220
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	k := getNextInt(scanner)
	if k%7 == 0 {
		k /= 7
	}
	m := 1
	if k%2 == 0 {
		fmt.Fprintln(writer, -1)
		return
	}
	if k%5 == 0 {
		fmt.Fprintln(writer, -1)
		return
	}
	var ans int = 1
	x := 1 % k
	for x > 0 {
		x = (x + m*10) % k
		m *= 10
		m %= k
		ans++
	}
	fmt.Fprintln(writer, ans)
}


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

int main (){
    long long N = 0;
    cin >> N;
    long long K = 0;
    cin >> K;
    vector<long long> A(N,0);
    vector<long long> times(N,1);
    for(long long i = 0; i < N; i++) {
    cin >> A.at(i);
    }
    for (size_t i = 0; i < N - K; i++)
    {
        if(A.at(K+i) > A.at(i)) {
        cout << "Yes" << endl;
        } else {
        cout << "No" << endl;
        }
    }
    
    

    
}

Measured memory_bytes: 6412
import java.util.Scanner;

class Point {
	private double x;
	private double y;

	public Point(double x, double y) {
		super();
		this.x = x;
		this.y = y;
	}

	public double getX() {
		return x;
	}

	public void setX(double x) {
		this.x = x;
	}

	public double getY() {
		return y;
	}

	public void setY(double y) {
		this.y = y;
	}

	@Override
	public String toString() {
		return String.format("%.8f %.8f", x, y);
	}

}

public class Main {



	public static void main(String[] args) {

		Point p1 = new Point(0.0, 0.0);
		Point p2 = new Point(100.0, 0.0);

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();

		System.out.println(p1);
		koch(n, p1, p2);
		System.out.println(p2);

	}

	private static void koch(int n, Point a, Point b) {
		if (n == 0) return;

		Point s, t, u;
		double th = 60.0/180.0 * Math.PI;	// radian60'C

		s = new Point(
				(2.0 * a.getX() + 1.0 * b.getX()) / 3.0,
				(2.0 * a.getY() + 1.0 * b.getY()) / 3.0 );
		t = new Point(
				(1.0 * a.getX() + 2.0 * b.getX()) / 3.0,
				(1.0 * a.getY() + 2.0 * b.getY()) / 3.0 );
		u = new Point(
				(t.getX() - s.getX())*Math.cos(th) - (t.getY() - s.getY())*Math.sin(th) + s.getX(),
				(t.getX() - s.getX())*Math.sin(th) + (t.getY() - s.getY())*Math.cos(th) + s.getY() );

		koch(n-1, a, s);
		System.out.println(s);
		koch(n-1, s, u);
		System.out.println(u);
		koch(n-1, u, t);
		System.out.println(t);
		koch(n-1, t, b);

	}
}

Measured memory_bytes: 40924
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647 >> 1); // 10^9 + 5000
static const ll LLINF = (9223372036854775807 >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Kunitaka{
    template<
        typename TYPE,
        std::size_t SIZE
    >
    std::size_t array_length(const TYPE (&array)[SIZE])
    {
        return SIZE;
    }
}
using namespace Kunitaka;
namespace Printer{
    void br(){
        cout << endl;
    }

    void loop_cnt(int i){
        cout << "i = " << i << endl;
    }

    void loop_cnt(int i, int j){
        cout << "i = " << i << ", " << "j = " << j << endl;
    }

    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T, class S>
    void print(T x, S y){
        cout << x << "," << y << endl;
    }

    template<class T, class S, class U>
    void print(T x, S y, U z){
        cout << x << "," << y << "," << z << endl;
    }

    template<class T, class S>
    void print(pair<T, S> p){
        cout << p.first << ", " << p.second << endl;
    }

    template<
        typename TYPE,
        std::size_t SIZE
    >
    void print(const TYPE (&array)[SIZE]){
        int lim = array_length(array);
        for(int i=0; i<lim; i++){
            if(i) cout << " ";
            cout << array[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<S> v){
        for(int i=0; i<v.size(); i++){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<vector<S> > vv){
        for(int i=0; i<vv.size(); i++){
            for(int j=0; j<vv[i].size(); j++){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void yesno(bool x){
        if(x) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
};
using namespace Printer;

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//


    // input
    cout << fixed << setprecision(10);
    ll A, B, M;cin >> A >> B >> M;
    ll miA = LLINF;
    ll miB = LLINF;
    vector<ll> va(A), vb(B);
    rep(i, A){
        cin >> va[i];
        miA = min(va[i], miA);
    }
    rep(i, B){
        cin >> vb[i];
        miB = min(vb[i], miB);
    }
    ll ans = LLINF;
    ans = min(ans, miA + miB);

    rep(i, M){
        ll x, y, c;
        cin >> x>> y >> c;
        x--; y--;
        ans = min(ans, va[x] + vb[y] - c);
    }
    print(ans);
    
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>

int n;
int house[5][4][11];
//       [b][f][ r]

int main() {
    std::cin >> n;
    for (int i=0; i<n; ++i) {
        int b, f, r, v;
        std::cin >> b >> f >> r >> v;
        house[b][f][r] += v;
    }
    for (int i=1; i<5; ++i) {
        for (int j=1; j<4; ++j) {
            for (int k=1; k<11; ++k) {
                std::cout << ' ' << house[i][j][k];
            }
            std::cout << '\n';
        }
        if (i != 4) std::cout << "####################\n";
    }
    return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <string>
using namespace std;
 
int main(void){
   string s,a;
   cin >> s;
   int sum = 0;
   while(cin >> a){
       for (int i=0; i<a.size(); i++){
            if (a[i]<97){
                a[i]=a[i]+32;
            }
        }
        if (a == s){
            sum++;
       }
   }
   cout << sum << endl;
}


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

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  vector<int> box(4);
  box[1] = w, box[3] = h;

  for(int i = 0; i < n; i++){
    int x, y, a;
    cin >> x >> y >> a;
    if(a == 1 && box[0] < x)  box[0] = x;
    if(a == 2 && box[1] > x)  box[1] = x;
    if(a == 3 && box[2] < y)  box[2] = y;
    if(a == 4 && box[3] > y)  box[3] = y;
  }

  int X = max(box[1] - box[0], 0);
  int Y = max(box[3] - box[2], 0);

  cout << X * Y << endl;
}

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

int main() {
    string s, t;
    cin >> s >> t;
    int count = 0;
    
    if (s[0] == t[0])
    {
        count++;
    }
    if (s[1] == t[1])
    {
        count++;
    }
    if (s[2] == t[2])
    {
        count++;
    }

    


    cout << count << endl;
}

Measured memory_bytes: 256
inp = input()
n = int(inp)
inp_dictionary = {}
total_count = 0
for _ in range(n):
    inp = input()
    inp = sorted(inp)
    inp_str = ""
    for i in inp:
        inp_str += i
    if inp_str in inp_dictionary:
        total_count += inp_dictionary[inp_str]
        inp_dictionary[inp_str] = inp_dictionary[inp_str] + 1

    else:
        inp_dictionary[inp_str] = 1

print(total_count)


Measured memory_bytes: 17860
#include<bits/stdc++.h>
using namespace std;
int n;
long long res;
map<int,int>m;
int main(){
	scanf("%d",&n);
	for(int i=1,x;i<=n;i++)scanf("%d",&x),res+=m[i-x],m[i+x]++;
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 20776
#include <stdio.h>
int main(void){
    int w,h,x,y,r;
    scanf("%d%d%d%d%d",&w,&h,&x,&y,&r);
    printf("%s\n",x-r<0||x+r>w||y-r<0||y+r>h?"No":"Yes");
    return 0;
}



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

using namespace std;

int main() {
    long long n;
    long long a;
    long long b;
    cin >> n >> a >> b;
    if(a == 0){
        cout << 0 << endl;
        return 0;
    }
    long long time = n/(a + b);
    long long ans = time * a + min((n % (a + b)),a);
    cout << ans << endl;
}

Measured memory_bytes: 3676
"""
4
1 2 2 1

2


5
3 1 2 3 1

5


8
4 23 75 0 23 96 50 100

221
"""

_ = int(input())
first = list(map(int, input().split()))
count = 0


def water(base_list):
    global count
    count += 1
    separated = []
    each = []
    for i in base_list:
        hoge = i - 1
        if hoge == 0:
            separated.append(each)
            each = []
        else:
            each.append(hoge)
    if each:
        separated.append(each)

    new_separated = []
    for i in separated:
        if i:
            new_separated.append(i)

    if new_separated:
        for i in new_separated:
            water(i)
    else:
        return


def plus_one(i):
    return i + 1


first = list(map(plus_one, first))


water(first)

print(count - 1)


Measured memory_bytes: 3064
fn main() {
    let (w,h,x,y)={
        let mut inputline = String::new();
        std::io::stdin().read_line(&mut inputline).ok();
        let mut inputline = inputline.split_whitespace();
        (inputline.next().unwrap().parse::<usize>().ok().unwrap(),
        inputline.next().unwrap().parse::<usize>().ok().unwrap(),
        inputline.next().unwrap().parse::<usize>().ok().unwrap(),
        inputline.next().unwrap().parse::<usize>().ok().unwrap())
    };
    let s = (w*h) as f64 / 2.0;
    let fukusuu = if x*2 == w && y*2 == h{
        1
    }else{
        0
    };
    println!("{} {}",s,fukusuu);
}


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

int main(){
	int n,a[100],i,j,m,t,c;
	
	for(cin>>n,i=0;i<n;cin>>a[i],++i);
	
	for(c=0,i=0;i<n;++i){
		m=i;
		for(j=i;j<n;++j){
			if(a[j]<a[m]){
				m=j;
			}
		}
		t=a[i];
		a[i]=a[m];
		a[m]=t;
		if(i-m)++c;
	}
	
	for(i=0;i<n;cout<<(i?" ":"")<<a[i],++i);
	cout<<endl<<c<<endl;
  return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<stdio.h>
#include<string.h>

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int makeint(char ch) {
	if (ch == 'A')return 1;
	else if (ch == 'C')return 2;
	else if (ch == 'G')return 3;
	else if (ch == 'T')return 4;
	else return 0;
}

long long makekey(char str[]) {
	long long sum = 0, p = 1, i;
	for (i = 0; i < strlen(str); i++) {
		sum += p*(makeint(str[i]));
		p *= 5;
	}
	return sum;
}

int h1(int key) { return key%M; }
int h2(int key) { return 1 + (key % (M - 1)); }

int find(char str[]) {
	long long key, i, h;
	key = makekey(str);
	for (i = 0; ; i++) {
		h = (h1(key) + i*h2(key)) % M;
		if (strcmp(H[h], str) == 0) return 1;
		else if (strlen(H[h]) == 0) return 0;
	}
	return 0;
}

int insert(char str[]) {
	long long key, i, h;
	key = makekey(str);
	for (i = 0; ; i++) {
		h = (h1(key) + i*h2(key)) % M;
		if (strcmp(H[h], str) == 0) return 1;
		else if (strlen(H[h]) == 0) {
			strcpy(H[h], str);
			return 0;
		}
	}
	return 0;
}

int main()
{
	int i, n, h;
	char str[L], c[9];
	for (i = 0; i < M; i++) H[i][0] = '\0';
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%s %s", c,str);
		if (c[0] == 'i') {
			insert(str);
		}
		else if (c[0] == 'f') {
			if (find(str)) {
				printf("yes\n");
			}
			else {
				printf("no\n");
			}
		}
	}
    return 0;
}

Measured memory_bytes: 17448
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
int fa[N],pre[N];
ll c0[N],c1[N];
ll ans;
int n;
struct pi{
	int x;
};
set<pi> p;
pi make(int x){
	return (pi){x};
}
bool operator < (pi a,pi b){
	int x=a.x,y=b.x;
	if (c0[x]*c1[y]==c0[y]*c1[x])return x<y;
	return c0[x]*c1[y]<c0[y]*c1[x];
}
int gf(int x){
	return fa[x]==x?x:fa[x]=gf(fa[x]);
}
int main(){
	cin>>n;
	for (int i=2;i<=n;i++)
		scanf("%d",&pre[i]),fa[i]=i;
	fa[1]=1;
	for (int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		x?c1[i]++:c0[i]++;
		if (i>1)p.insert(make(i));
	}
	for (int i=1;i<n;i++){
		int x=p.rbegin()->x;
		p.erase(make(x));
		if (gf(pre[x])>1)p.erase(make(gf(pre[x])));
		fa[x]=gf(pre[x]);
		ans+=c1[fa[x]]*c0[x];
		c0[fa[x]]+=c0[x];
		c1[fa[x]]+=c1[x];
		if (fa[x]>1)p.insert(make(fa[x]));
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    vec<ll> a(n); rep(i,n)cin >> a[i];
    sort(a.begin() , a.end());
    ll ans = 1;
    rep(i,n){
       if(log10l(ans)+log10l(a[i]) > 18){
           cout << -1 << endl;
           return 0;
       }
        ans *= a[i]; 
        if(ans > 1000000000000000000){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}

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

int main(){
    int N;
    double ks, ans;
    cin >> N;

    if(N%2==0){
        ans = 0.5;
    }
    else {
        ks=N/2+1;
        ans =ks/N;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys

ri = lambda: int(sys.stdin.readline())
rl = lambda: list(map(int, sys.stdin.readline().split()))

a = ri()
li = sorted(rl(), reverse=True)
cnt = 0
for i in range(a-2):
    for j in range(i+1, a-1):
        left = j+1
        right = a
        lii = li[i]
        lij = li[j]
        if lii >= lij + li[j+1]:
            continue
        while right-left > 1:
            t = (left + right)//2
            lit = li[t]
            if lii < lij + lit:
                left = t
            else:
                right = t
        cnt += left-j
print(cnt)



















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

int main()
{
    int n,x;
    while(cin>>n>>x)
    {
        vector <int> s;
        for(int i=0;i<n;i++)
        {
            int num;
            cin>>num;
            s.push_back(num);
        }
        long long cnt=0;
        for(int i=0;i<n;i++)
        {
            if(i==0)
            {
                if(s[i]>x)
                {
                    cnt+=s[i]-x;
                    s[i]=x;
                }
                continue;
            }
            if(i==n-1)
            {
                if(s[i]+s[i-1]>x)
                {
                    cnt+=(s[i]+s[i-1])-x;
                }
                continue;
            }
            if(s[i]+s[i-1]>x)
            {
                cnt+=(s[i]+s[i-1])-x;
                s[i]-=(s[i]+s[i-1])-x;
            }
            /*if(s[i]+s[i+1]>x)
            {
                cnt+=(s[i]+s[i+1])-x;
                s[i]-=(s[i]+s[i+1])-x;
            }*/
        }
        cout<<cnt<<endl;
    }
    return 0;
}


Measured memory_bytes: 892
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

a,b,c = get_nums_l()

print("bust" if a+b+c >= 22 else "win")

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

int main(){
	int c[3][3];
    int a[3], b[3];
    int count = 0;
    bool correct_information = true;

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

    for( int a1 = 0; a1 <= c[0][0]; a1++){
        b[0] = c[0][0] - a1;
        b[1] = c[0][1] - a1;
        b[2] = c[0][2] - a1;

        a[0] = a1;
        a[1] = c[1][0] - b[0];
        a[2] = c[2][0] - b[0];

        count = 0;
        for( int i = 0; i < 3; i++){
            for( int j = 0; j < 3; j++){
                if( a[i] + b[j] == c[i][j]) count++;
                else break;
            }
        }
        
        if(count == 9){
          cout << "Yes" << endl;
          return 0;
        }

    }

    cout << "No" << endl;

}



Measured memory_bytes: 256
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

s = rr()
if s[0] != 'A':
  print('WA')
  exit()
if 'C' in s[2:-1] and s.count('C') == 1:
  for i in s.replace('A', '').replace('C', ''):
    if 97 <= ord(i) <= 122:
      continue
    else:
      print('WA')
      exit()
  else:
    print('AC')
else:
  print('WA')
















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

#define ll long long
#define ull unsigned long long
#define mii make_pair<int, int>
#define mll make_pair<ll, ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define all(v) (v).begin(), (v).end()

//ofstream out("debug.txt");

const int MxN = 1e5, md = 1e9 + 7;

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

    int n;
    cin >> n;
    int f = 0, m = 0;
    for (int i = 0; i < n; ++i)
    {
        int a, b;
        cin >> a >> b;
        if (a == b)
            f++;
        else
            f = 0;
        m = max(f, m);
    }
    cout << (m >= 3 ? "Yes" : "No");
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;

int main() {
    fast_io
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int count = 0;
    rep(i,n-1) if (s[i] != s[i+1]) count++;
    int ans = n - count - 1;
    ans += 2*k;
    ans = min(n-1, ans);
    cout << ans << endl;
    return 0;
}

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

string s;
int x, y;
int main()
{
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> s >> x >> y;
  bitset< 2 * 8000 > dpx, dpy;
  int cnt = 0, first = 0, N = s.size();
  while (s[first++] == 'F');
  dpx[8000 + --first] = dpy[8000] = 1;

  bool isX = true;
  for (int i = first; i < N; ++i) {
    if (s[i] == 'F') cnt++;
    if (s[i] == 'T' || i == N - 1) {
      bitset< 2 * 8000 > pd;
      if (isX) {
	pd = (dpx << cnt) | (dpx >> cnt);
	swap(dpx, pd);
      } else {
	pd = (dpy >> cnt) | (dpy << cnt);
	swap(dpy, pd);
      }
      isX = !isX;
      cnt = 0;
    }
  }

  cout << (dpx[x + 8000] && dpy[y + 8000] ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<map>
#include<bitset>
#include<assert.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<set>
#include<queue>
#define long long long
using namespace std;
const int N=1e6,mod=1e9+7;
int aa[N+2],dp[N+2];
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  int n;cin>>n;
  for(int i=1;i<=n;i++)cin>>aa[i];
  int mx=0;
  for(int i=n;i>=1;i--)
  {
    dp[aa[i]]=dp[aa[i]+1]+1;
    mx=max(mx,dp[aa[i]]);
  }
  cout<<n-mx<<endl;
  return 0; 
}

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

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

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

        if x == y:
            return

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

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

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

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

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

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

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

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

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

n, m, k = map(int, input().split())

uf = UnionFind(n)
n_friend = [0 for i in range(n)]

for i in range(m):
    ai, bi = map(int, input().split())
    uf.union(ai-1, bi-1)
    n_friend[ai-1] += 1
    n_friend[bi-1] += 1
for i in range(n):
    uf.find(i)

block = [[] for i in range(n)]
for i in range(k):
    ci, di = map(int, input().split())
    block[ci-1].append(di-1)
    block[di-1].append(ci-1)

lst = []
for i in range(n):
    num = uf.size(i) - n_friend[i] - 1
    for j in block[i]:
        if uf.find(i) == uf.find(j):
            num -= 1
    lst.append(num)

print(' '.join(map(str, lst)))

Measured memory_bytes: 113504
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[26],dp[500][500];

int main(){
  string k,l;
  cin >> s >> t;
  clr(d,0);
  rep(i,0,s.sz)d[s[i]-'a']++;
  rep(i,0,26){
    rep(j,0,d[i]){
      k += i+'a';
    }
  }
  clr(d,0);
  rep(i,0,t.sz)d[t[i]-'a']++;
  pel(i,25,0){
    rep(j,0,d[i]){
      l += 'a'+i;
    }
  }
  bool f = true;
  rep(i,0,k.sz){
    if(k[i] < l[i])break;
    if(i >= l.sz-1 || k[i]-'a' > l[i]-'a'){
      f = false;
      break;
    }
  }
  // print(k);
  // print(l);
  if(f)print("Yes");
  else print("No");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(x) x.begin(), x.end()

int main() {
  ll n, cou = 0;
  cin >> n;
  vector<ll> l(n);
  for (ll i = 0; i < n; i++) {
    cin >> l.at(i);
  }
  sort(all(l));
  for (ll i = 0; i < n - 2; i++) {
    for (ll j = i + 1; j < n - 1; j++) {
      for (ll k = j + 1; k < n; k++) {
        if (l.at(k) >= l.at(i) + l.at(j)) {
          break;
        }
        cou++;
      }
    }
  }
  cout << cou << endl;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    a = sorted(list(map(int,input().split())))
    t = a[-1]
    s = t/2
    z = a[0]
    for i in range(1,n-1):
        if abs(a[i]-s)<abs(z-s):
            z = a[i]
    print(t,z)

if __name__ == "__main__":
    main()


Measured memory_bytes: 20084
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;

typedef pair<int, int> P;

int main(){
    int N, L;
    while(cin >> N >> L && N){
        vector<int> d(N);
        vector<int> p(N);
        REP(i, N) {
            char c;
            cin >> c >> p[i];
            d[i] = (c == 'L' ? -1 : 1);
        }
        vector<P> vp(N, P(-1, -1));
        for(int t = 0; ; t++){
            bool update = false;
            REP(i, N){
                if(p[i] > 0 && p[i] < L){
                    p[i] += d[i];
                    update = true;
                }else if(vp[i].first == -1){
                    vp[i] = P(t, -p[i]);
                }
            }
            //REP(i, N) cout << p[i] << " "; cout << endl;
            if(!update) break;
            REP(i, N) REP(j, i){
                if(p[i] == p[j]){
                    d[i] *= -1;
                    d[j] *= -1;
                }
            }
        }
        P max_vp(-1, -1);
        REP(i, N) max_vp = max(max_vp, vp[i]);
        P ans;
        REP(i, N) if(max_vp == vp[i]) ans = P(vp[i].first, i + 1);
        printf("%d %d\n", ans.first, ans.second);
    }
    return 0;
}

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

int main()
{
  int N; cin >> N;
  int d[N]; rep(i,N) cin >> d[i];
  int map[110] = {0};
  //集計
  rep(i,N) map[d[i]]++;
  //数字が入ってるところをカウント
  int ans = 0;
  rep(i,110)
  {
    if(map[i] != 0) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// ----------------------R00TDADA------------------------------
#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define int long long
#define M 1000000007

signed main()
{
    rootdada;
    // #ifndef ONLINE_JUDGE
    //     // for getting input from input.txt
    //     freopen("input.txt", "r", stdin);
    //     // for writing output to output.txt
    //     freopen("output.txt", "w", stdout);
    // #endif
    int n;
    cin >> n;
    vi a(n);
    vi v;
    map<int, int> m;
    rep(i, 0, n)
    {
        cin >>
            a[i];
        if (!m[a[i]])
        {
            v.pb(a[i]);
        }
        m[a[i]]++;
    }
    int l = v.size();
    int ans = 0;
    rep(i, 0, l)
        ans += (m[v[i]] * (m[v[i]] - 1)) / 2;

    rep(i, 0, n)
    {
        cout << ans - m[a[i]] + 1 << endl;
    }
}

Measured memory_bytes: 12020
#include <iostream>
#include <algorithm>

typedef long long ll;

const ll inf = (ll)1e+17 + 7;

int n, m;
ll k;
ll a[20001];
ll dp[20001];

int main(){
	std::cin >> n >> m >> k;
	for(int i = 0; i < n; ++i)std::cin >> a[i];
	
	for(int i = 0; i < 20001; ++i){
		dp[i] = inf;
	}
	
	dp[0] = 0;
	for(int i = 0; i < n; ++i){
		ll small = inf, large = -inf;
		for(int j = 0; j < m; ++j){
			if(i + j + 1 > n)continue;
			
			small = std::min(small, a[i + j]);
			large = std::max(large, a[i + j]);
			
			dp[i + j + 1] = std::min(dp[i + j + 1], dp[i] + k + (j + 1) * (large - small));
		}
	}
	
	std::cout << dp[n] << std::endl;
	
	return 0;
}

Measured memory_bytes: 1476
import sys
sys.setrecursionlimit(10**6)
n, u, v = map(int, input().split())
adj = [[] for _ in range(n)]
for _ in range(n-1):
	a, b = map(int, input().split())
	adj[a-1].append(b-1)
	adj[b-1].append(a-1)

tkhs = [-1 for _ in range(n)]
aoki = [-1 for _ in range(n)]
tkhs[u-1], aoki[v-1] = 0, 0

def dfs(x, player):
	for y in adj[x]:
		if player[y] < 0:
			player[y] = player[x] + 1
			dfs(y, player)
	return

dfs(u-1, tkhs)
dfs(v-1, aoki)

ans = 0
for i in range(n):
	if tkhs[i] <= aoki[i] and len(adj[i]) > 1:
		ans = max(ans, aoki[i])

print(ans)

Measured memory_bytes: 101712
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>

#include <cstdio>

using namespace std;

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

	string S;
	cin >> S;

	int price = 700;

	for (int i = 0; i < 3; i++) {
		if (S[i] == 'o') {
			price = price + 100;
		}
	}

	cout << price << '\n';
	

	return 0;
}

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();
            var n = Int32.Parse(str);

            var l = new int[2*n];
            var strs = Console.ReadLine().Split();
            for (int i = 0; i < 2*n; i++)
            {
                l[i] = Int32.Parse(strs[i]);
            }

            Console.WriteLine(Solver.Solve(l));
        }
    }

    public class Solver
    {
        public static int Solve(int[] l)
        {
            var ret = 0;
            l = l.OrderByDescending(v => v).ToArray();
            for (int i = 0; i < l.Length - 1; i+=2)
                ret += Math.Min(l[i], l[i + 1]);
            return ret;
        }
    }

}


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

int main() {
	int len;
	char s[110];
	bool valid = true;
	scanf("%s", s);
	len = strlen(s);
	for (int i = 0; i < len; i++) {
		if (i & 1) {
			if (s[i] == 'R')
				valid = false;
		}
		else if (s[i] == 'L')
			valid = false;
	}
	if (valid)
		puts("Yes");
	else
		puts("No");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    ll h, w;
    cin >> h >> w;
    vector<string> g(h);
    rep(i, h) cin >> g[i];
    vvi l(h, vi(w,0)), r(h, vi(w,0)), u(h, vi(w,0)), d(h, vi(w,0));

    // 左方向
    for(ll i=0; i<h; i++){
        ll cur = 0;
        for(ll j=0; j<w; j++){
            (g[i].at(j) == '#') ? cur = 0 : cur++;
            l[i][j] = cur;
        }
    }
    // 右方向
    for(ll i=0; i<h; i++){
        ll cur = 0;
        for(ll j=w-1; j>=0; j--){
            (g[i].at(j) == '#') ? cur = 0 : cur++;
            r[i][j] = cur;
        }
    }
    // 下方向
    for(ll i=0; i<w; i++){
        ll cur = 0;
        for(ll j=h-1; j>=0; j--){
            (g[j].at(i) == '#') ? cur = 0 : cur++;
            d[j][i] = cur;
        }
    }
    // 上方向
    for(ll i=0; i<w; i++){
        ll cur = 0;
        for(ll j=0; j<h; j++){
            (g[j].at(i) == '#') ? cur = 0 : cur++;
            u[j][i] = cur;
        }
    }
    ll ans = 0;
    for(ll i=0; i<h; i++){
        for(ll j=0; j<w; j++){
            if(g[i].at(j) != '#') chmax(ans, l[i][j]+r[i][j]+d[i][j]+u[i][j]-3);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 129792
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll X;
    cin >> X;
    ll ma = 1;
    for(int i = 2; i <= X; i++) {
        ll tmp = i*i;
        while(tmp <= X) {
            ma = max(ma, tmp);
            tmp *= i;
        }
    }
    print(ma);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <iostream>
#include <set>
#include <vector>
#include <string>

class Solver {
  using set = std::set<int>;
  public:
    std::string line;
    int solve() {
      i_ = 0;
      return expr().size();
    }
  private:
    std::size_t i_;
    set expr() {
      std::vector<set> nums = {chunk()};
      std::vector<char> ops;
      while (i_ < line.length() and is_operator(line[i_])) {
        ops.push_back(line[i_++]);
        nums.push_back(chunk());
      }
      std::vector<std::vector<set>> t(nums.size(), std::vector<set>(nums.size() + 1));
      for (std::size_t i = 0; i < nums.size(); ++i) t[i][i + 1] = nums[i];
      for (std::size_t w = 2; w <= nums.size(); ++w) {
        for (std::size_t begin = 0; begin + w <= nums.size(); ++begin) {
          std::size_t end = begin + w;
          for (std::size_t sep = begin + 1; sep < end; ++sep) {
            char op = ops[sep - 1];
            for (auto left : t[begin][sep]) {
              for (auto right : t[sep][end]) {
                auto &s = t[begin][end];
                if (op == '+') s.insert(left + right);
                if (op == '-') s.insert(left - right);
                if (op == '*') s.insert(left * right);
                if (op == '/' and right != 0) s.insert(left / right);
              }
            }
          }
        }
      }
      return t[0][nums.size()];
    }
    bool is_operator(char c) {
      return c == '+' or c == '-' or c == '*' or c == '/';
    }
    set chunk() {
      if (line[i_] == '(') {
        ++i_;
        set s = expr();
        ++i_;
        return s;
      }
      int x = 0;
      while (i_ < line.length() and std::isdigit(line[i_])) x = 10 * x + (line[i_++] - '0');
      return {x};
    }
};

int main() {
  Solver s;
  while (true) {
    std::cin >> s.line;
    if (s.line == "#") return 0;
    std::cout << s.solve() << std::endl;
  }
}

Measured memory_bytes: 3284
// https://atcoder.jp/contests/abc110/tasks/abc110_c
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main() {
    string s, t;
    map<char, char> mp1, mp2;
    bool ret = true;
    cin >> s >> t;

    // 文字列の長さが同じ
    int len1 = s.length(), len2 = t.length();
    if (len1 == len2) {
        REP(i, len1) {
            // 文字の対応を確認
            if (mp1.count(s[i])) {
                if (mp1[s[i]] != t[i]) {
                    ret = false;
                    break;
                }
            }
            if (mp2.count(t[i])) {
                if (mp2[t[i]] != s[i]) {
                    ret = false;
                    break;
                }
            }
            mp1[s[i]] = t[i];
            mp2[t[i]] = s[i];
        }
    } else {
        ret = false;
    }

    if (ret) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 776
#include <stdio.h>
int fibo(int);
 int main() {
 int n, fibonacci;
 scanf("%d", &n);
 fibonacci = fibo(n);
 printf("%d\n",fibonacci);
 return 0; } int fibo(int n) {
 int i, s[45]; // return fibo(n-1) + fibo(n-2);
 s[0] = 1; s[1] = 1;
 for(i=2;i<=n;i++){ s[i] = s[i-1] + s[i-2]; }
 return s[n]; } 


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 1000000007
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
using namespace std;
const long long N=200005, INF=2000000000000000000;
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int k,n;
    cin>>k>>n;
    int ar[n];
    for(int i=0;i<n;i++)
    cin>>ar[i];
    sort(ar, ar+n);
    int d=k-ar[n-1]+ar[0];
    for(int i=1;i<n;i++)
    {
        if(ar[i]-ar[i-1]>d)
        d=ar[i]-ar[i-1];
    }
    cout<<k-d;
}

Measured memory_bytes: 1792