akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	//static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	//for(int i=0;i<N;i++) {}
	
	
	
	//a 97 || //b 98 || //c 99 || 
	
	public static void main(String[] args) {
		String S=sc.next();
		
		char v[]=S.toCharArray();
		
		int g[]=new int[3];
		
		
		for(int i=0;i<S.length();i++) {
			g[v[i]-97]++;
		}
		int t=g[0]+g[1]+g[2];
		int M=Math.max(g[0], Math.max(g[1], g[2]));
		int M2=Math.min(g[0], Math.min(g[1], g[2]));
		if(M-M2<=1)p("YES");
		else p("NO");
	}
	
	
	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 27816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, P;
  cin >> N >> P;
  if ( N == 1) {
    cout << P << "\n";
    return 0;
  }
  ll m = pow(P, (double) 1 / N) + 1;
  
  ll ans = 1;
  for (ll t = 2; t <= m; t++) {
    ll k = pow(t, N);
    if (P % k == 0) {
      ans = max(ans, t);
    }
  }
  cout << ans << "\n";
  return 0;
}

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

int main(void)
{
	ios::sync_with_stdio(false);

	int N, A[100], flag, cnt;

	cin >> N;
	for (int i = 0; i < N; i++)	cin >> A[i];

	flag = 1;  cnt = 0;
	while (flag){
		flag = 0;
		for (int j = N - 1; j >= 0;j--)
			if (A[j] < A[j - 1]){
				int tmp = A[j];
				A[j] = A[j - 1];
				A[j - 1] = tmp;
				flag = 1;
				cnt++;
			}
	}
	for (int i = 0; i < N; i++){
		cout << A[i];
		if (i == N - 1)
			cout << endl;
		else
			cout << " ";
	}
	cout << cnt << endl;

	return 0;
}

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

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

  int a[200005];
  int fi=0,se,i_fi;
  for (int i=0; i<n; i++) {
    cin>>a[i];
    if (fi<a[i]) {
      se=fi;
      fi=a[i];
      i_fi=i;
    }
    else if (fi==a[i]) {
      i_fi=-1;
    }
    else if (se<a[i]) {
      se=a[i];
    }
  }
  for (int i=0; i<n; i++) {
    if (i_fi==i) {
      cout<<se<<endl;
    }
    else {
      cout<<fi<<endl;
    }
  }      
  return 0;
}



Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

// = = = Mint = = =
template<int64_t MOD> struct Mint {
    int64_t v;
    Mint() { v = 0; }
    Mint(int64_t x) { v = x % MOD; if(v < 0)  v += MOD; }

    Mint operator-() { return Mint{-v}; };
    Mint operator+(Mint x) { return Mint(v + x.v); };
    Mint operator-(Mint x) { return Mint(v - x.v); };
    Mint operator*(Mint x) { return Mint(v * x.v); };
    Mint operator/(Mint x) { return Mint(v * pow(x.v, MOD-2).v); };

    Mint& operator+=(Mint x) { return *this = (*this + x); };
    Mint& operator-=(Mint x) { return *this = (*this - x); };
    Mint& operator*=(Mint x) { return *this = (*this * x); };
    Mint& operator/=(Mint x) { return *this = (*this / x); };

    static Mint pow(Mint base, int64_t exp) {
        if(exp == 0)  return Mint(1);
        return pow(base*base, exp/2) * (exp&1 ? base : Mint(1));
    }

    friend ostream& operator<<(ostream& os, Mint x) { return os << x.v; }
};
using mint = Mint<1000000007>;
// = = = = = = = = = =

int main() {
    string s;
    cin >> s;

    lint n;
    n = s.size();

    mint eq[n+1], lt[n+1];
    eq[0] = 1;
    for(lint i = 0; i < n; i++) {
        if(s[i] == '0') {
            eq[i+1] = eq[i];
            lt[i+1] = lt[i] * 3;
        }
        if(s[i] == '1') {
            eq[i+1] = eq[i] * 2;
            lt[i+1] = eq[i] + lt[i] * 3;
        }
    }
    cout << eq[n] + lt[n] << endl;
}

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

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

	ll n,k;
	cin>>n>>k;
	vector<int> arr(n);
	for(int i=0; i<n; ++i){
		cin>>arr[i];
	}
	double max_ans = 0.0;
	double now = 0.0;
	for(int i=0; i<k; ++i){
		now += 1.0 * (arr[i]+1)/2;
	}
	for(int i=k; i<n; ++i){
		max_ans = max(max_ans, now);
		now -= 1.0 * (arr[i-k]+1)/2;
		now += 1.0 * (arr[i]+1)/2;
	}
	max_ans = max(max_ans, now);
	cout.precision(10);
	cout<<fixed<<max_ans<<'\n';

	return 0;
}


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

        int ans = 0;
        if(k <= a){
                cout << k << endl;
                return 0;
        }

        k -= a;
        ans += a;
        if(k <= b){
                cout << ans << endl;
                return 0;
        }

        k -= b;
        ans += (-1 * k);

        cout << ans << endl;
}



Measured memory_bytes: 3624
n = int(input())
a = sorted(list(map(int, input().split())))

ans = -0.1

for j in range(n):
    for i in range(j):
        C = a[j]
        D = a[i]

        k = n - 1
        while k == j or k == i:
            k -= 1
        A = a[k]

        k -= 1
        while k == j or k == i:
            k -= 1
        B = a[k]

        ans = max(ans, (A + B) / (C - D))

print(ans)


Measured memory_bytes: 5632
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	string s; cin >> s;
	ll ans = 0;
	int n = s.size() - 1;
	rep(i, 0, pow(2, n) - 1)
	{
		vector<int> pos;
		int left = 0;
		rep(j, 0, n - 1)
		{
			if (i >> j & 1)
			{
				pos.push_back(j + 1);
			}
		}
		for (int x : pos)
		{
			ans += stol(s.substr(left, x - left));
			left = x;
		}
		ans += stoll(s.substr(left));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//  A
//
//  Created by 曾憲揚 on 2020/8/21.
//  Copyright © 2020 曾憲揚. All rights reserved.
//

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

int main(int argc, const char * argv[]) {
    int n; cin>>n;
    for(int i=0; i<3; i++){
        if(n%10 == 7){
            cout<<"Yes\n"; return 0;
        }
        
        else n/=10;
    }
    cout<<"No\n";
    return 0;
}


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

int main() {
    string s;
    cin >> s;

    int ascii = 'a' + 'b' + 'c';
    int input = s[0] + s[1] + s[2];
    cout << (input == ascii ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
int n, k;
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	double p = 0.0;
 	cin >> n >> k;
 	for(int i=1; i<=n; i++)
 	{
 		double x = 1.0;
 		int j = i;
 		while(j<k)
 		{
 			j *= 2;
 			x *= 0.5;
 		}
 		p += x;
 	}
 	p /= n;
 	cout << fixed << setprecision(12) << p;
	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val inputList = readLine()!!.split(' ').map(String::toInt)
    val (a, b, c, d) = inputList.subList(0, 4)
    val (e, f) = inputList.subList(4, 6)

    var concentration = 0.0
    var all = 0
    var sugar = 0
    for (ia in 0..(f / (100 * a))) {
        for (ib in 0..(f / (100 * b))) {
            for (ic in 0..(f / c)) {
                for (id in 0..(f / d)) {
                    if (ia == 0 && ib == 0) break
                    val tempWater = a * ia * 100 + b * ib * 100
                    val tempSugar = c * ic + d * id
                    val tempAll = tempWater + tempSugar
                    if (tempAll > f) break
                    val tempConcentration = 100.0 * tempSugar.toDouble() / tempWater.toDouble()
                    if (tempConcentration > e.toDouble()) break
                    if (tempConcentration > concentration) {
                        concentration = tempConcentration
                        all = tempAll
                        sugar = tempSugar
                    }
                }
            }
        }
    }
    if (all == 0) all = 100 * a
    println("$all $sugar")
}

Measured memory_bytes: 38240
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  string s;
  cin >> s;

  ll n = sz(s);
  
  ll ans = 0;
  for(ll bit = 0; bit < (1<<n-1); bit++)
  {
    ll tmp = atoi(s.substr(0,1).c_str());
    ll sum = 0;
    for(ll i = 0;i < n-1; i++)
    {
      if(bit & (1<<i))
      {
        sum += tmp;
        tmp = atoi(s.substr(i+1,1).c_str());
      }
      else
      {
        tmp = tmp * 10 + atoi(s.substr(i+1,1).c_str());      
      }
    }
    sum += tmp;
    ans += sum;
  }

  cout << ans << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
  int N;
  int i;
  int s[200];
  int count1 = 0;
  int count2 = 0;
  
  scanf("%d", &N);
  for(i = 0; i < N; i++) {
    scanf("%d ", &s[i]);
  }
  
  while(1) {
    for(i = 0; i < N; i++) {
    	if(s[i] % 2 == 0)	count1++;
        s[i] /= 2;
    }
    if(count1 == N)	{
      count2++;
      count1 = 0;
    }
    else	break;
  }
  
  printf("%d", count2);
  
  return 0; 
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;

int main(){

    int n, k; cin >> n >> k;

    long long cnt1, cnt2;
    long long ans;

    cnt1 = n / k;

    ans = cnt1*cnt1*cnt1;
    
    if(k % 2 == 0){
        cnt2 = n / (k/2) - cnt1;
        ans += cnt2*cnt2*cnt2;
    }

    cout << ans;

    

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <cmath>
using namespace std;
int main() {
  int n, count = 1;
  vector<int> array;
  cin >> n;
  if (n==0) {
    cout << 0 << endl;
    return 0;
  }
  while (n!=0) {
    if (n%2==0) {
      array.push_back(0);
    } else {
      array.push_back(1);
      if (count%2==0) {
        n++;
      } else {
        n--;
      }
    }
    // cout << array[count] << ' ' << count << ' ' << n << endl;
    count++;
    n/=2;
  }
  for (int i = array.size()-1; i >= 0; i--) {
    if (array[i]==0) cout << 0;
    else cout << 1;
  }
  cout << endl;
}

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

int main(){
    int N;
    cin>>N;
    char S[N];
    bool four=false;
    for(int i=0;i<N;i++){
        cin>>S[i];
        if(S[i]=='Y')four=true;
    }
    if(four)cout<<"Four"<<endl;
    else cout<<"Three"<<endl;

}

Measured memory_bytes: 256
def main():
    import sys
    import numpy as np
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    N, K = [int(x) for x in input().strip().split()]
    NN = np.array([n for n in range(N+1)], dtype=int)
    Ncumsum = NN.cumsum()
    Nrev_cumsum = NN[::-1].cumsum()
    ans = 0
    MOD = 10 ** 9 + 7
    for k in range(K-1, N+1):
        ans += Nrev_cumsum[k] - Ncumsum[k] + 1
        ans %= MOD

    print(ans)

if __name__ == '__main__':
    main()

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

long solve(string s){
  int index=0;
  for (int i=0; i<s.size(); i++) {
    if (s.at(i) == '+') {
      string fs = s.substr(0,i);
      return stol(fs) + solve(s.substr(i+1));
    }
  }
  return stol(s);
}

vector<string> makeStrState(string s){
  if(s.size() == 1)
    return {s};
  vector<string> states(0);
  string ss = s.substr(1, s.size()-1);
  string fs = s.substr(0,1);
  for(string str:makeStrState(ss)){
    states.push_back(string(fs) + "+" + str);
    states.push_back(string(fs) + str);
  }
  return states;
}
  
int main() {
  string s;
  cin >> s;
  vector<string> v = makeStrState(s);
  long total = 0;
  for (string val: v)
  	total += solve(val);
  cout << total << endl;
  
  return 0;
}
         
  
      

Measured memory_bytes: 256
n, k = map(int, input().split())
s = input()
s = list(map(int, s))

v = []
cnt = 1
for i in range(n - 1):
	if s[i] == s[i + 1]:
		cnt = cnt + 1
	else:
		v.append(cnt)
		cnt = 1
v.append(cnt)
m = len(v)

sum = [0] * (m + 1)
for i in range(1, m + 1):
	sum[i] = sum[i - 1] + v[i - 1]

ans = 0
for i in range(m + 1):
	if s[0] == 0:
		if i % 2 == 0:
			ans = max(ans, sum[i] - sum[max(i - k * 2 - 1, 0)])
		else:
			ans = max(ans, sum[i] - sum[max(i - k * 2, 0)])
	else:
		if i % 2 == 0:
			ans = max(ans, sum[i] - sum[max(i - k * 2, 0)])
		else:
			ans = max(ans, sum[i] - sum[max(i - k * 2 - 1, 0)])

print(ans)


Measured memory_bytes: 8616
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\n'
int main(){
    ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
    double r;
    double pi=3.1415926;
    cin>>r;
    double ans=2*r;
    ans*=pi;
    cout<<fixed<<setprecision(6)<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3808
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.AGC_Challenge
{
    class _024_A
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            long[] abck = ReadLongs();
            long res = abck[0] - abck[1];
            if (abck[3] % 2 == 1) res *= -1;
            if (Math.Abs(res) > Math.Pow(10, 18))
            {
                Console.WriteLine("Unfair");
            }
            else
            {
                Console.WriteLine(res);
            }
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11220
import Control.Applicative
import Control.Monad
import Data.List
import Data.Set

main = do
    [a, b, k] <- Data.List.map read . words <$> getLine
    mapM putStrLn $ Data.List.map show $ ans a b k

ans a b k = toAscList concat
    where
        left = fromList $ Data.List.take k [a..b]
        right = fromList $ reverse $ Data.List.take k [b, b-1..a]
        concat = Data.Set.union left right


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


int main()
{
    //cout<<sin(30*pi/180);

//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
//    cout.tie(NULL);
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll ans=0;
    if(a>=k)
    {
        cout<<k<<endl;
        return 0;
    }
    else
    {
        ans+=a;
        k-=a;
        
    }
    
    if(b>=k)
    {
        cout<<ans<<endl;
        return 0;
    }
    else
    {
        k-=b;
    }
    if(k>0)
        ans+=(k*-1);
    cout<<ans<<endl;
}


Measured memory_bytes: 3644
def f(field, n, m, level=0)
  field[0][0] = "#"
  que = [[0,0]]
  until que.empty?
    y, x = que.shift
    [[-1,0],[1,0],[0,-1],[0,1]].each{|dy,dx|
      ny, nx = y+dy, x+dx
      if ny>=0 && ny<=m+1 && nx>=0 && nx<=n+1
        return level if field[ny][nx]=="&"
        if field[ny][nx]=="."
          field[ny][nx] = "#"
          que << [ny,nx]
        end
      end
    }
  end
  field[0][0] = "."
  que = [[0,0]]
  until que.empty?
    y, x = que.shift
    [[-1,0],[1,0],[0,-1],[0,1]].each{|dy,dx|
      ny, nx = y+dy, x+dx
      if ny>=0 && ny<=m+1 && nx>=0 && nx<=n+1
        if field[ny][nx]=="#"
          field[ny][nx] = "."
          que << [ny,nx]
        end
      end
    }
  end
  f(field, n, m, level+1)
end

require "pp"

loop{
  n, m = gets.split.map(&:to_i)
  break if n==0 and m==0
  field = ["."*(n+2)] + m.times.map{"." + gets.chomp + "."} + ["."*(n+2)]
  puts f(field, n, m)
}


Measured memory_bytes: 7040
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e9;
int main(){
	int n;
	cin>>n;
	bool h=true;
	int co=0;
	rep(i,n){
		string s;
		cin>>s;
		if(s=="A")co++;
		else co--;
		if(co<0)h=false;
	}
	if(co)h=false;
	if(h)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

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

int main()
{
  long a;
  string b;
  cin >> a >> b;
  const char* bc = b.c_str();
  long bl = (long)((bc[0]-'0')*100+(bc[2]-'0')*10+(bc[3]-'0'));
  long c = (a*bl)/100;
  cout << c << endl;
}


Measured memory_bytes: 3628
#include <stdio.h>

int main()
{
	long long i, j;
	long long num;
	scanf("%lld %lld", &i, &j);

	if ((i == 0) && (j < 4)) {
		num = 0;
	}else if (j < 2) {
		num = 0;
	}else if (j > (2 * i)) {
		num = i + ((j - 2 * i) / 4);
	}else {
		num = j / 2;
	}

	printf("%lld", num);
	return 0;
}

Measured memory_bytes: 128
n = int(input())
A = [[0]*10 for _ in range(10)]
for i in range(1, n+1):
  t = str(i)
  a, b = int(t[0]), int(t[-1])
  A[a][b] += 1
ans = 0
for i in range(1, 10):
  for j in range(1, 10):
    ans += A[i][j] * A[j][i]
print(ans)

Measured memory_bytes: 40428
import sys;

def putQueen(i, row, col, dpos, dneq):
    global finding
    if(finding == 0):
        return
        
    if(i == 8):
        finding = 0
        printBoard(row[0:])
        return
    

    for j in range(8):
        if i in myset:
            putQueen(i+1,row[0:], col[0:], dpos[0:], dneq[0:])
            continue
        if(col[j] == 1 or dpos[i+j] == 1 or dneq[i-j+7] == 1):
            continue
        row[i] = j
        col[j] = dpos[i+j] = dneq[i-j+7] = 1
        putQueen(i+1,row[0:], col[0:], dpos[0:], dneq[0:])
        col[j] = dpos[i+j] = dneq[i-j+7] = 0

def printBoard(row):
    for k in range(8):
        if(row[k] == 0):
            print("Q.......")
        elif(row[k] == 1):
            print(".Q......")
        elif(row[k] == 2):
            print("..Q.....")
        elif(row[k] == 3):
            print("...Q....")
        elif(row[k] == 4):
            print("....Q...")
        elif(row[k] == 5):
            print(".....Q..")
        elif(row[k] == 6):
            print("......Q.")
        else:
            print(".......Q")

n = (int)(input());
row = [0 for i in range(8)]
col = [0 for i in range(8)]
dpos = [0 for i in range(15)]
dneq = [0 for i in range(15)]

myset = set()

for i in range(n):
    r,c = map(int, input().split());
    myset.add(r)
    row[r] = c
    col[c] = 1
    dpos[r+c] = 1
    dneq[r-c+7] = 1

finding = 1

putQueen(0,row, col, dpos, dneq)



Measured memory_bytes: 5624
#include<iostream>
#include<set>

using namespace std;

set<int> st;

int main(){
   int n;
   cin>>n;
   int res;
   for(int i=1;i<=n;i++){
   	cin>>res;
   	st.insert(res);
   }
   if(st.size() == n) cout<<"YES";
   else cout<<"NO"<<endl;
	return 0;
} 

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define endl        '\n'
#define pi          2*acos(0.0)
#define pb(a)       push_back(a)
#define db          double
#define ld          long double
#define ll          long long
#define ull         unsigned long long
#define mod         1000000007
#define inf         1000000000000000001
#define sqr(x)      (x) * (x)
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)   ((a/gcd(a,b)) * b)
#define debug(x) 	cerr << #x << " = " << (x) <<endl
#define all(x)      (x).begin(), (x).end()
#define unsyncIO    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


using namespace std;

int main()
{
    //freopen("/home/taalpatar_shepai/Documents/my_codes/out.txt", "w", stdout);
    unsyncIO;
    ll n, ans = 0;
    cin >> n;
    for (ll j = 1; j <= n; j++) {
        ll t = n / j;
        ans += t * (t + 1) / 2 * j;

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

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define maxn 2005
using namespace std;
typedef long long ll;
ll inv[maxn],F[maxn],Finv[maxn];
ll mod=1e9+7;
void init(){
    inv[1]=1;
    for(int i=2;i<maxn;i++){
        inv[i]=(mod-mod/i)*inv[mod%i]%mod;
    }
    F[0]=1;
    Finv[0]=1;
    for(int i=1;i<=maxn;i++){
        F[i]=F[i-1]*i%mod;
        Finv[i]=Finv[i-1]*inv[i]%mod;
    }
}
ll C(ll n,ll m){
    if(n<0||m<0||m>n) return 0;
    return F[n]*Finv[m]%mod*Finv[n-m]%mod;
}
int main()
{
    int n,k;
    init();
    scanf("%d%d",&n,&k);
    for(int i=1;i<=k;i++){
        ll a=C(n-k+1,i);
        ll b=C(k-1,i-1);
        printf("%lld\n",a*b%mod);
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{
	static PrintWriter pw;
	static MScanner  sc;
	
	public static void main(String[] args) throws Exception{
		pw=new PrintWriter(System.out);
		sc = new MScanner(System.in);
		int k=sc.nextInt(),a=sc.nextInt(),b=sc.nextInt();
		
		int m=((a+k-1)/k)*k;
		if(m<=b) {
			pw.println("OK");
		}
		else {
			pw.println("NG");
		}
		
		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}

Measured memory_bytes: 32676
#include<bits/stdc++.h>
using namespace std;
int n,a[103],b[103],h[103],x=-1;
int main(){
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i]>>h[i];
		if(h[i]!=0)x=i;
	}
	if(x==-1){
		cout<<"37 15 1";
		return 0;
	}
	for(int i=0;i<=100;i++)
		for(int j=0;j<=100;j++)
		{
			bool can=1;
			for(int k=0;k<n;k++)
				if(k!=x)
					if(fabs(a[k]-i)+fabs(b[k]-j)+h[k]!=fabs(a[x]-i)+fabs(b[x]-j)+h[x]&&(h[k]!=0||fabs(a[x]-i)+fabs(b[x]-j)+h[x]>=fabs(a[k]-i)+fabs(b[k]-j)))
						can=0;
			if(can){
				cout<<i<<' '<<j<<' '<<int(h[x]+fabs(a[x]-i)+fabs(b[x]-j))<<endl;
				return 0;
			}
		}
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<set>
#include<algorithm>
#define ll long long
#define rep(i,a,n) for(ll i=a;i<=n;i++)
#define per(i,a,n) for(ll i=n;i>=a;i--)

using namespace std;
ll arr[200500];
ll n,k;

int main()
{
    scanf("%lld %lld",&n,&k);
    rep(i,1,n)  scanf("%lld",&arr[i]);
    ll cnt=0;
    sort(arr+1,arr+n+1);
    rep(i,1,n-k)    cnt+=arr[i];
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
#include<map>
#include<deque>
#include<string>
#include<algorithm>

#define all(x) (x).begin(),(x).end()
#define puts(x) cout<< x << endl;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fore(i,a) for(auto i:a)
#define ll long long
using namespace std;
ll n,k;
ll h[1000005];
int main(){
    cin>>n>>k;
    rep(i,0,n){
        cin>>h[i];
    }
    sort(h,h+n);//昇順
    ll ans=0;
    rep(i,0,n-k){
        ans+=h[i];
    }
    puts(ans);
}

Measured memory_bytes: 1792
require 'pp'

n = gets.chomp!.to_i
s_n = []
n.times do |i|
    s_n << gets.chomp!.chars.group_by {|ch| ch }.map{|k, v| [k, v.length] }.to_h
end

ans = {}
('a'..'z').each do |ch|
    ans[ch] = 100000
end

n.times do |i|
    ('a'..'z').each do |ch|
        ans[ch] = [ans[ch], s_n[i][ch] || 0 ].min
    end
end

ans.select {|k, v| v > 0 }.each do |x, y|
    print x * y
end

puts ""



Measured memory_bytes: 2556
S = input()
a = [0] * (len(S) + 1)
 
for i in range(len(S)):
    if S[i] == '<':
        a[i + 1] = max(a[i + 1], a[i] + 1)
 
for i in range(len(S) - 1, -1, -1):
    if S[i] == '>':
        a[i] = max(a[i], a[i + 1] + 1)
 
print(sum(a))

Measured memory_bytes: 29148
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int n;
double a;
double ans;

int main(){
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a;
		ans += 1 / a;
	}
	ans = 1 / ans;

	printf("%5lf\n", ans);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 2147483647
const int Max=1e4+20;
const int mod=1e9+7;
const ll M=1e9;
using namespace std;
inline int read()
{
    int f=1,x=0;char ch;
    do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
    do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');return x*f;
}

int main()
{
    string s;
    cin>>s;
    int n=s.size()-1;
    if(s[n]=='s') cout<<s<<"es"<<endl;
    else cout<<s<<"s"<<endl;
    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

int main() {
	string s;
	int index[8][3] = {
		{0, 1, 2},
		{3, 4, 5},
		{6, 7, 8},
		{0, 3, 6},
		{1, 4, 7},
		{2, 5, 8},
		{0, 4, 8},
		{2, 4, 6},
	};
	while (cin >> s) {
		string result = "d";
		for (int i = 0; i < 8; i++) {
			int a = index[i][0];
			int b = index[i][1];
			int c = index[i][2];
			if (s[a] == s[b] && s[b] == s[c] && s[a] != 's') {
				result = s[a];
				break;
			}
		}
		cout << result << endl;
	}
	return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;



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

	sort(a.begin(), a.end());
	if (a[n - 1] == 0) {
		cout << "Yes";
	}
	else if (n % 3 == 0) {
		if (a[0] == 0 && a[n / 3 - 1] == 0 && a[n / 3] == a[n - 1]) {
			cout << "Yes";
		}
		else if(a[0] == a[n/3-1] && a[n/3] == a[2*n/3-1] && a[2*n/3] == a[n-1] && ((a[0] ^ a[n/3])^a[2*n/3]) == 0 ){
			cout << "Yes";
		}
		else {
			cout << "No";
		}
	}
	else {
		cout << "No";
	}

}



Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
#include <string>
#include <set>

using namespace std;

int main() {
  int m;
  scanf("%d", &m);
  for (int i=0;i<m;i++) {
    char buf[100];
    scanf("%s", buf);
    string s = buf;
    set<string> ss;
    for (int j=1;j<s.size();j++) {
      const string s1 = s.substr(0, j);
      string rs1 = s1;
      reverse(rs1.begin(), rs1.end());
      const string s2 = s.substr(j, s.size()-j);
      string rs2 = s2;
      reverse(rs2.begin(), rs2.end());
      ss.insert(s1+rs2);
      ss.insert(s2+s1);
      ss.insert(s2+rs1);
      ss.insert(rs1+s2);
      ss.insert(rs1+rs2);
      ss.insert(rs2+s1);
    }
    printf("%lu\n", ss.size());
  }
  return 0;
}

Measured memory_bytes: 2952
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

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

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

    map<int, int> minIdx, cnt;
    rep(i, n){
        if(minIdx.find(a[i]) == minIdx.end()){
            minIdx[a[i]] = i;
            cnt[a[i]] = 0;
        }
        cnt[a[i]]++;
    }

    vector<int> ans(n);
    int sum = 0;
    auto now = minIdx.rbegin();
    auto nxt = now;
    nxt++;
    int idx = now->second;
    for(; nxt != minIdx.rend(); nxt++){
        sum += cnt[now->first];
        ans[idx] += sum * (now->first - nxt->first);
        idx = min(idx, nxt->second);
        now++;
    }
    ans[0] += n * now->first;

    rep(i, n){
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 15104
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

MOD = 1000000007

def smax(a,b):
    if a>b:
        return a
    else:
        return b

def smin(a,b):
    if a<b:
        return a
    else:
        return b

def main():
    S = int(readline())
    if S!=10**18:
        a = S%1000000000
        b = S//1000000000
        x1 = 1000000000
        y2 = b
        x2 = a
        y1 = -1
        print(0,1,x1,1+y1,x2,1+y2)
    else:
        print(0,0,1000000000,0,0,1000000000)


if __name__ == '__main__':
    main()

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

ll f(ll x) {
    return to_string(x).size();
}
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll n; cin >> n;
    ll ans = linf;
    for (ll i = 1; i*i <= n; ++i) {
        if (n % i == 0) {
            ans = min(ans, max(f(i), f(n/i)));
        }
    }
    cout << ans << endl;
}


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

int main(){
  int k,s;
  cin >> k >> s;
  int ans = 0;
  for(int i = 0; i <= k; i++){
    for(int j = 0; j <= k; j++){
      int z = s - i - j;
      if( 0 <= z && z <= k){
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
 
 
int main(){
  
  int n;
  cin >> n;
 int count=1;
  
  while(n!=4&&n!=2&&n!=1){
  
    if(n%2==0){
      n/=2; count++;
    }
    else{
      n=3*n+1; count++;
    }
  }
  
  cout << count+3 << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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


    int cnt=0;
    for (int i = 1; i < n-1; ++i) {
        if(a[i-1]+a[i+1]==max({a[i+1],a[i],a[i-1]})+min({a[i+1],a[i],a[i-1]}))
        {
            cnt++;
        }
    }
    cout<<cnt;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input!(a: [[usize1; 4]]);
    let mut pf = [[true; 8]; 8];
    for i in 0..4 {
        for j in 0..4 {
            pf[2 * i][2 * j + 1] = false;
        }
    }
    for a in a {
        let mut count = 0;
        for i in a[0]..a[2] + 1 {
            for j in a[1]..a[3] + 1 {
                if pf[i][j] {
                    count += 1;
                }
            }
        }
        puts!("{}\n", count);
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}



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

int main()
{
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    if(n<=k)cout << n*x;
    else{
        int sum = k*x;
        n-=k;
        sum+=n*y;
        cout << sum;
    }
}



Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll n,t;
cin>>n>>t;

ll a[n][2];
for(int i=0;i<n;i++){cin>>a[i][0]>>a[i][1];}
ll ans=1000000007;
for(int i=0;i<n;i++){if(a[i][1]<=t) ans=min(ans,a[i][0]);}
if(ans==1000000007) cout<<"TLE\n";
else cout<<ans<<"\n";
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#define REP(i, a, b) for (auto i = (a); i < (b); ++i)
using namespace std;

using ll = long long;

const int N = 1e5;
vector<int> g[N];
int p[N], h[N], d[N];

void dfs(int u) {
	if (p[u] != -1) d[u] = d[p[u]] + 1;
	else d[u] = 0;

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

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int n, A, T; cin >> n >> T >> A; --T, --A;
	REP(i, 1 , n) {
		int u, v; cin >> u >> v; --u, --v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	p[A] = -1; dfs(A);
	int ans = 0;
	int steps = 0;
	int cur = T;
	while (steps < d[cur]) {
		ans = max(ans, d[cur] + h[cur] - 1);
		cur = p[cur];
		++steps;
	}
	cout << ans;
}

Measured memory_bytes: 10752
#include<iostream>
#include<stack>
#include<algorithm>

using namespace std;

typedef pair<int, int> P;

int W, H;
int vx[4] = { 0,-1,0,1 }, vy[4] = { 1,0,-1,0 };
int filed[50][50];
bool usedB[50][50], usedW[50][50];

void dfs(P start, int flg) {
	stack<P> s;
	s.push(start);
	
	while (s.size()) {
		auto now = s.top(); s.pop();
		for (int i = 0; i < 4; i++) {
			int nx = now.first + vx[i], ny = now.second + vy[i];
			if (nx < 0 || ny < 0 || nx >= H || ny >= W)continue;
			if (!flg) {
				if (usedW[nx][ny])continue;
				if (filed[nx][ny] != 0)continue;
				usedW[nx][ny] = true;
				s.push(P(nx, ny));
			}else {
				if (usedB[nx][ny])continue;
				if (filed[nx][ny] != 0)continue;
				usedB[nx][ny] = true;
				s.push(P(nx, ny));
			}
		}
	}
}

int main() {
	
	while (1) {
		cin >> W >> H;
		if (W + H == 0)break;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				char c;
				cin >> c;
				if (c == 'W')filed[i][j] = 1;
				else if (c == 'B')filed[i][j] = 2;
				else filed[i][j] = 0;
				usedB[i][j] = false;
				usedW[i][j] = false;
			}
		}

		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (filed[i][j] == 1) {
					dfs(P(i, j), 0);
				}
				else if (filed[i][j] == 2) {
					dfs(P(i, j), 1);
				}
			}
		}

		int ansB = 0, ansW = 0;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (usedW[i][j] && !usedB[i][j])ansW++;
				if (usedB[i][j] && !usedW[i][j])ansB++;
			}
		}
		cout << ansB << " " << ansW << endl;

	}
	return 0;
}


Measured memory_bytes: 2992
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
#include<deque>
#include<queue>
#include<set>

//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)

#define All(a) (a).begin(),(a).end()

//定数
#define INF 1e9
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
template<class T>bool chmax(T &a, const T &b) {
	if (a < b) { a = b; return 1; }
	return 0;
}
template<class T>bool chmin(T &a, const T &b) {
	if (a > b) { a = b; return 1; }
	return 0;
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int d[50];
	REP(i, n) {
		cin >> d[i];
	}
	int ans = 0;
	REP(i, n-1) {
		FOR(j, i + 1, n) {
			ans += d[i] * d[j];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=100010;

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

    ll n,m;
    cin>>n>>m;
    string s[n];
    for(ll i=0;i<n;++i){cin>>s[i];}
    ll dp[n][m];

    for(ll i=0;i<n;++i){
        for(ll j=0;j<m;++j){
            if(i==0&&j==0){dp[i][j]=1;}
            else if(i==0){
                if(s[i][j]=='#'){dp[i][j]=0;}
                else{dp[i][j]=dp[i][j-1];}
            }
            else if(j==0){
                if(s[i][j]=='#'){dp[i][j]=0;}
                else{dp[i][j]=dp[i-1][j];}
            }
            else{
                if(s[i][j]=='#'){dp[i][j]=0;}
                else{dp[i][j]=(dp[i-1][j]+dp[i][j-1])%M;}
            }
        }
    }
    cout<<dp[n-1][m-1];

    return (0);
}


Measured memory_bytes: 9088
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <cstring>
#include <cmath>

using namespace std;
const long double eps = 1e-12;

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

#define sz(a) ((int) a.size() )
#define LL(x) (x << 1)
#define RR(x) ((x << 1) | 1)
#define For(i , a , b) for (int i = a ; i <= b ; i++)
#define Ford(i , a , b) for (int i = a ; i >= b ; i--)
#define Rep(i , n) for (int i = 0 ; i < n ; i++)

const int maxn = 2005;
int n , k;

vector<int> cost[15];
int dp[15][2004];

void ReadData() {
    cin >> n >> k;
    For(i , 1 , n) {
        int type , x; cin >> x >> type;
        cost[type].push_back(x);
    }
    For(i , 1 , 10) sort(cost[i].begin() , cost[i].end());
    For(i , 1 , 10) reverse(cost[i].begin() , cost[i].end());
    For(i , 1 , 10) For(j , 0 , k) {
        dp[i][j] = dp[i - 1][j];
        int sum = 0;
        Rep(l , sz(cost[i])) {
            sum += cost[i][l];
            if (j >= l + 1) dp[i][j] = max(dp[i][j] , dp[i - 1][j - l - 1] + sum + (l + 1) * l);
        }
    }
    int res = 0;
    For(j , 0 , k) res = max(res , dp[10][j]);
    cout << res << endl;
}

void Process() {

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  //  freopen("/users/youaremysky/documents/workspace/input.inp" , "r" , stdin);
    ReadData();
    Process();
}

Measured memory_bytes: 1324
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl

using ld = long double;
using P = complex<ld>;
using G = vector<P>;
const ld pi = acos(-1);

namespace std {
    bool operator < (const P& a, const P& b) {
        return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
    }
}

template<class iter>
tuple<ld, P, P> closest_pair(iter left, iter right) {
    int n = distance(left, right);
    if(n <= 1) return make_tuple(numeric_limits<ld>::max(), *left, *left);
    iter middle = next(left, n/2);
    ld x = middle->real();
    auto d = min(closest_pair(left, middle), closest_pair(middle, right));
    inplace_merge(left, middle, right, [](const P &a, const P &b){
            return a.imag() < b.imag();
        });
    vector<iter> around;
    for(iter i = left; i != right; ++i){
        ld dx = fabs(i->real() - x);
        ld &opt = get<0>(d);
        if(dx*dx >= opt) continue;
        for(auto j = around.rbegin(); j != around.rend(); ++j){
            ld dx = i->real() - (**j).real();
            ld dy = i->imag() - (**j).imag();
            if(dy*dy >= opt) break;
            ld norm = dx*dx + dy*dy;
            if(get<0>(d) > norm){
                d = make_tuple(norm, *i, **j);
            }
        }
        around.push_back(i);
    }
    return d;
};

// http://www.spoj.com/problems/CLOPPAIR/
// 18124516

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(6) << endl;
    int n;
    cin >> n;
    vector<P> a;
    rep(i,n){
        ld x,y;
        cin >> x >> y;
        a.emplace_back(x,y);
    }
    ld z;
    P x, y;
    sort(all(a));
    tie(z, x, y) = closest_pair(all(a));
    cout << sqrt(z) << endl;
}

Measured memory_bytes: 10840