akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    int result=0;
    for(int i=0;i<n;i++)
    {
        if(i==0)
        {
            result+=abs(v[i]);
        }
        else
        {
            result+=abs(v[i]-v[i-1]);
        }
        if(i==n-1)
        {
            result+=abs(v[i]);
        }
    }
    int prev=0;
    int next=v[1];
    for(int i=0;i<n;i++)
    {
        if(i==0)
            prev=0;
        else
            prev=v[i-1];
        if(i==n-1)
            next=0;
        else
            next=v[i+1];
        int temp;
        temp=abs(v[i]-prev);
        temp+=abs(v[i]-next);
        int tempresult=result;
        tempresult-=temp;
        tempresult+=abs(next-prev);
        cout<<tempresult<<endl;
    }
}

Measured memory_bytes: 3772
import math

n = int(input())
a = [0]*100001
b = math.ceil(math.sqrt(n)) + 1
for i in range(1,b):
    for j in range(1,b):
        for k in range(1,b):
            ans = ((i + j) ** 2 + (j + k) ** 2 + (k + i) ** 2) //2
            a[ans] += 1

for i in range(1,n+1):
    print(a[i])

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

using namespace std;

typedef long long ll;

ll GCD(ll a, ll b)
{if(b == 0) {return a;}
 else{return GCD(b, a%b);}
}
ll abs_diff(ll a, ll b)
{ if(a >= b){return a - b;}
 else{return b - a;}}

int main()
{ll N, S ;
 cin >> N >> S; //start
 vector<ll> T(N,0),U(N,0);// 問題文のXがSで、x列をTと置いたことに注意
 
 for(ll i = 0; i < N; i++)
 {cin >> T[i];
 U[i] = abs_diff(T[i],S);}
 //u0,u1,,,, uN-1の最大公約数を求めればいい
 
 vector<ll> gcd(N);
 gcd[0] = U[0];
 for(ll i = 0; i < N-1; i++)
 {gcd[i+1] = GCD(gcd[i],U[i+1]);}
 
 cout << gcd[N-1] << endl;
 return 0;}
 

Measured memory_bytes: 2560
#[allow(unused_macros)]
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 : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
#[allow(unused_macros)]
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 ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ 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 ) * } } ; }

fn main() {
    input! {
        s: String,
        t: String,
    }
    println!("{}{}", t, s);
}


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


// sの中にcが出現するかどうか判定する
bool check(string s, char c) {
  if(s.find(c) == string::npos)
    return false;
  else
    return true;
}     
  

int main() {
  string n;
  char k, *d;
  int pay;
  bool d_flag = false;

  // scan
  cin >> n >> k;
  d = new char[k];
  for(int i = 0; i < (int)k; i++)
    cin >> d[i];

  // 
  for(pay = stoi(n); true; pay++) {
    d_flag = false;
    for(int i = 0; i < (int)k; i++) {
      if(check(to_string(pay), d[i])) {
	d_flag = true;
	break;
      }
    }
    if(!d_flag)
      break;
  }

  cout << pay << '\n';

  delete(d);
  return 0;
}


Measured memory_bytes: 256
from sys import stdin
from collections import deque
sa = deque(list((stdin.readline().rstrip())))
sb = deque(list((stdin.readline().rstrip())))
sc = deque(list((stdin.readline().rstrip())))

next = "a"
for i in range(300):
    if len(sa) == 0 and next == "a":
        print("A")
        break
    if len(sb) == 0 and next == "b":
        print("B")
        break
    if len(sc) == 0 and next == "c":
        print("C")
        break
        
    
    if next == "a":
        next = sa.popleft()
    elif next == "b":
        next = sb.popleft()
    elif next == "c":
        next = sc.popleft()
    

Measured memory_bytes: 3316
#include <algorithm>
#include <array>
#include <complex>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int N, L;
int xx[5000];
int x[5000];
int a[5000];
const ll M = 1000000007LL;
ll sum[5001];
ll dp[5000];

int main() {
  cin >> N >> L;
  for(int i = 0; i < N; ++i) {
    cin >> x[i];
    xx[i] = x[i];
  }
  for(int i = 0; i < N; ++i) {
    cin >> a[i];
  }
  int pre = L;
  for(int i = N - 1; i >= 0; --i) {
    if(a[i] != 0){
      int r = (pre - 1 - x[i]) / a[i];
      x[i] += a[i] * r;
    }
    pre = x[i];
  }

  memset(dp, 0, sizeof(dp));
  for(int i = 0; x[0] - a[0] * i >= xx[0]; ++i) {
    dp[x[0] - a[0] * i] = 1;
    if(a[0] == 0) break;
  }
  for(int i = 1; i < N; ++i) {
    sum[0] = 0;
    for(int j = 1; j <= x[i]; ++j) {
      sum[j] = (sum[j - 1] + dp[j-1]) % M;
    }
    memset(dp, 0, sizeof(dp));
    for(int j = 0; x[i] - a[i] * j >= xx[i]; ++j){
      int id = x[i] - a[i] * j;
      dp[id] = sum[id];
      if(a[i] == 0) break;
    }
  }
  ll ans = 0;
  for(int i = 0; i < L; ++i) {
    ans = (ans + dp[i]) % M;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1300
k = int(input())
s = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(s[k - 1])


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

int a[100002];
int father[100002];

int findx(int a){
	if(father[a]==a) return a;
	return father[a]=findx(father[a]);
}

void conbine(int x,int y)
{
    int xi = findx(x);
    int yi = findx(y);
    if(xi!=yi)
    {
        father[yi] = xi;
    }
}
int main()
{
    int n,c,b,m;
    scanf("%d%d",&n,&m);
    for(int i = 0 ; i < n ;i++)
    {
        scanf("%d",&a[i]);
        father[i+1] = i+1;
    }
    for(int i = 0 ; i < m ;i++)
    {
        scanf("%d%d",&c,&b);
        conbine(c,b);
    }
    int sum = 0;
    for(int i = 0 ; i < n;i++)
    {
        if(a[i] == (i+1))
        {
            sum++;
            continue;
        }
        if(findx(a[i]) == findx(i+1))
        {
            sum++;
        }
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mp make_pair
map<ll,vector<ll> >m;
map<ll,bool> vi;
ll dp[(ll)10e5+1];
ll indegree[(ll)10e5+1];
ll dfs(ll n)
{
	if(vi[n])
		return dp[n];
	vi[n]=1;
	ll flag=0;
	for(auto x:m[n])
	{
		dp[n]=max(dp[n],1+dfs(x));
	}
	if(m[n].size()==0)
		return dp[n]=0;
	return dp[n];
}
int32_t main()
{
	ll n,q;
	cin>>n>>q;
	while(q--)
	{
		ll x,y;
		cin>>x>>y;
		m[x].pb(y);
		vi[x]=0;
		vi[y]=0;
		indegree[y]++;
	}
	ll mi=-1;
	for(auto x:m)
	{
		if(indegree[x.first]==0)
		mi=max(mi,dfs(x.first));
	}
	cout<<mi;
}

Measured memory_bytes: 30080
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		long s = sc.nextLong();
		long c = sc.nextLong();
		long ans = 0;

		if (s * 2 < c) {
			ans += s;
			c -= 2 * s;
			ans += Math.floor(c / 4);
		} else {
			ans += Math.floor(c / 2);
		}
		System.out.println(ans);
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

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

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

// #define NDEBUG 1
// debug用出力 https://trap.jp/post/998/
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << H << " ";
    debug_out(T...);
}
#ifdef NDEBUG
#define debug(...)
#else
#define debug(...) debug_out(__VA_ARGS__)
#endif

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

// constexpr inline ll mod = 1'000'000'007;
// constexpr int max_n = 200'000 + 5;
int n;
int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15); // 浮動小数の表示の精度

    cin >> n;
    cout << (10000 - n) % 1000 << endl;

    return 0;
}


Measured memory_bytes: 3648
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 1e-9;

long long int N, M, K, H, W, L, R;

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

	cin >> N >> M >> K >> L >> R;
	vector<int>ans;
	while (N) {
		vector<vector<int>>edge(N, vector<int>(N,MOD));
		for (int i = 0; i < N; i++) {
			edge[i][i] = 0;
		}
		K--;
		L--;
		R--;
		for (int i = 0; i < M; i++) {
			int a, b, c;
			cin >> a >> b >> c;
			a--;
			b--;
			edge[a][b] = c;
		}
		for (int k = 0; k < N; k++) {
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j]);
				}
			}
		}
		int ret = MOD;
		for (int i = 0; i < N; i++) {
			if (edge[K][i] == MOD || edge[i][L] == MOD || edge[i][R] == MOD)continue;
			ret = min(ret, edge[K][i] + edge[i][L] + edge[i][R]);
		}
		ans.push_back(ret);
		cin >> N >> M >> K >> L >> R;
	}
	for (auto i : ans)cout << i << endl;
	return 0;
}



Measured memory_bytes: 3060
def submit():
    # read input
    n = int(input())

    first = 0
    second = 0

    alist = []
    for i in range(n):
        alist.append(int(input()))

        if alist[-1] > first:
            second = first
            first = alist[-1]
        elif alist[-1] > second:
            second = alist[-1]

    for a in alist:
        if a == first:
            print(second)
        else:
            print(first)


    return


if __name__ == '__main__':
    submit()


Measured memory_bytes: 68696
#include <stdio.h>

int r[100][100], d[100], f[100];

int dijkstra(int s, int g){
  int min, p, i, j;
  for(i=0;i<100;i++){
    d[i]=100000;
    f[i]=0;
  }
  d[s]=0;
  while(1){
    min=100000;
    for(i=0;i<100;i++){
      if(d[i]<min && f[i]==0){
	min=d[i];
	p=i;
      }
    }
    
    if(min==100000) break;
    f[p]=1;
    for(j=0;j<100;j++){
      if(r[p][j]==1){
	if(d[p]+r[p][j]<d[j])
	  d[j]=r[p][j]+d[p];
      }
    }
  }
 
  return d[g]+1;
}

main(){
  int s, g, n, o, k, t, i, j, a, p, TTL;

  for(i=0;i<100;i++){
    for(j=0;j<100;j++){
      r[i][j]=0;
    }
  }

  scanf("%d", &n);

  for(j=0;j<n;j++){
    scanf("%d %d", &o, &k);
    for(i=0;i<k;i++){
      scanf("%d", &t);
      r[o-1][t-1]=1;
    }
  }

  scanf("%d", &p);

  for(j=0;j<p;j++){
    scanf("%d %d %d", &s, &g, &TTL);
    a = dijkstra(s-1, g-1);

    if(a <= TTL){
      printf("%d\n", a);
    }
    else printf("NA\n");
  }
  return 0;
}

Measured memory_bytes: 456
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var nrl=arr.shift().split(" ").map(Number);
var n=nrl[0];
var L=nrl[2];
var t=[];
var max=[0,0];
var time=0;
for(var i=0;i<n;i++)t[i]=[0,0,i];
arr.push([1,L,0].join(" "));
for(var i=0;i<arr.length;i++){
   var v=arr[i].split(" ").map(Number);
   var d=v[0]-1;
   var T=v[1];
   var x=v[2];
   t[max[0]][1]+=T-time;
   time=T;
   t[d][0]+=x;
   if(x>0){
      if(t[d][0]>max[1])max=[d,t[d][0]];
      else if(t[d][0]==max[1] && d<=max[0])max=[d,t[d][0]];
   }
   else if(x<0 && max[0]==d){
      var MAX=0;
      var m=0;
      for(var j=0;j<t.length;j++){
         if(MAX<t[j][0]){m=j;MAX=t[j][0];}
      }
      max=[m,t[m][0]];
   }
}
var MAX=0;
var m=0;
for(var i=0;i<t.length;i++){
   if(MAX<t[i][1]){m=i;MAX=t[i][1];}
}
console.log(m+1);

Measured memory_bytes: 126460
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;

int sum(int x){
  int ans=0;
  while(x>0){
    ans+=x%10;
    x/=10;
  }
  return ans;
}

int main(){
  int num,a;
  cin>>num;
  a=sum(num);
  if(num%a==0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
K = int(input())

ans = 1
x = 7
useds = [0] * (10**6+5)
useds[x] = 1
while True:
    if x%K == 0:
        print(ans)
        break
    x = (x*10 + 7) % K
    ans += 1
    if useds[x]:
        print(-1)
        break
    useds[x] = 1


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

int main() {
  long long A,B,N,M,Ma=0;
  cin >> A >> B >> N;
  if (B-1>=N)
  cout << floor(A*N/B)-A*floor(N/B) << endl;
  else
  cout << floor((A*(B-1))/B)-A*floor((B-1)/B) << endl;
}


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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

// ポテンシャルUF
// 2点間のポテンシャルを指定した併合・ポテンシャル差異の算出を行う
// UFより計算量的には若干重い(各操作: O(log N))
struct PotentialUnionFind {

    vector<int> p;
    vector<ll> w;
    PotentialUnionFind(int n) : p(n, -1), w(n, 0) {
    }

    // uに対するvのポテンシャルの高さをweightとして併合
    // w[v] - w[u] = weight
    // ret: true: 矛盾なし false: 矛盾あり
    // O(log N)
    bool UnionSet(int u, int v, ll weight) {
        int ru = root(u);
        int rv = root(v);
        if (ru == rv) return w[u] - w[v] == weight;
        w[ru] = weight - w[u] + w[v];
        p[rv] += p[ru];
        p[ru] = rv;
        return true;
    }

    // ポテンシャル差異を求める
    // ret: {diff (uからみたvのポテンシャルの高さ), isOK}
    // O(log N)
    pair<ll, bool> find(int u, int v) {
        int ru = root(u);
        int rv = root(v);
        if (ru != rv) return {0, false};
        return {w[u] - w[v], true};
    }

    bool isSame(int u, int v) {
        return root(u) == root(v);
    }

    int size(int x) {
        return -p[root(x)];
    }

    int root(int x) {
        if (p[x] < 0) {
            return x;
        } else {
            int r = root(p[x]);
            w[x] += w[p[x]];
            p[x] = r;
            return r;
        }
    }
};

void solve() {
    int N, M;
    cin >> N >> M;
    PotentialUnionFind uf(N);
    for (int i = 0; i < M; i++) {
        int l, r; ll d;
        cin >> l >> r >> d;
        l--, r--;
        if (!uf.UnionSet(l, r, d)) {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <functional>
#include <vector>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
typedef  long long ll;
const int maxn=1e6+50;
const int inf=0x3f3f3f3f;
const int MOD=1e9+7;
const int HASH=131;

int main()
{
    int  n;
    cin>>n;
    cout<<n+n*n+n*n*n<<endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

ll getSum(int v){
	return (1+v)*v/2;
}

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
	int x;
	cin >> x;
	int ans = 1;
	for(int i=x;i>=1;i--){
		int t = i;
		if(getSum(t)>=x){
			ans = i;
		}
	}
	cout << ans << "\n";
    
	return 0;
}

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


int main() {
	int r, d, x;
	cin >> r >> d >> x;

	vector<int> data(11);
	data.at(0) = x;
	for(int i=0; i<10; i++){
		data.at(i+1) = r*data.at(i) - d;
	}
	for(int i=0; i<10; i++){
		cout << data.at(i+1) << endl;
	}
}


Measured memory_bytes: 256
/*   _ _ _                     
    | | | | ___  ___           
    | | | || . ||  _|          
    |_____||_  ||_|  _____     
             |_|    |_____|  */
// Time : 19/10/16
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
int main(){
#ifdef Wqr_
    freopen("in.txt","r",stdin);
#endif
    std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int n, k;
    cin >> n;
    cin >> k;
    int tmp;
    int ans = 0;
    for(int i = 0; i < n; i++){
        cin >> tmp;
        if(tmp >= k) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def get_direction(y,x,block):
    direction = []
    lr = block[y*2]
    if len(lr) > x and lr[x] == 0:
        direction.append((0,1))
    if 0 < x and lr[x-1] == 0:
        direction.append((0,-1))
    # 下に移動可能か
    if y < H-1 and block[y*2+1][x] == 0:
        direction.append((1,0))
    # 上に移動可能か
    if 0 < y and block[(y-1)*2+1][x] == 0:
        direction.append((-1,0))
    return direction

def bfs(block):
    field = [[0] * W for _ in range(H)]
    next_list = set()
    now_list = [(0,0)]
    cnt = 1
    while len(now_list) > 0:
        for _ in range(len(now_list)):
            y, x = now_list.pop()
            field[y][x] = 1
            # directionを編集
            direction = get_direction(y,x,block)
            for ny, nx in direction:
                ny += y
                nx += x
                if not (0 <= ny < H and 0 <= nx < W): continue
                if ny == H-1 and nx == W-1: return cnt+1
                if field[ny][nx] != 0: continue
                next_list.add((ny,nx))
        now_list = list(next_list)
        next_list = set()
        cnt += 1
    return 0

W, H = 0, 0
while True:
    W, H = map(int, input().split())
    if W+H == 0: break
    block = []
    for _ in range(H*2-1):
        block.append(list(map(int, input().split())))
    print(bfs(block))




Measured memory_bytes: 5628
from itertools import combinations

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

num = [i for i in range(n)]
ans = []
for i in combinations(num,k):
    comb = list(i)
    comb.reverse()

    s = 0
    for j in comb:
        s += 2**j
    ans.append([s,list(i)])

ans.sort()
for i,j in ans:
    print(str(i)+":",*j)


Measured memory_bytes: 21412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){
    string s;cin>>s;
    ll n=s.size()+1;
    ll a[n];rep(i,0,n-1)a[i]=0;
    rep(i,0,s.size()-1){
        if(s[i]=='<'){
            a[i+1]=max(a[i+1],a[i]+1);
        }
    }
    for(ll i=s.size()-1;i>=0;i--){
        if(s[i]=='>'){
            a[i]=max(a[i],a[i+1]+1);
        }
    }
    ll sum=0;
    rep(i,0,n-1){
        sum+=a[i];
    }
    cout<<sum<<endl;
    
    
    return 0;
}






Measured memory_bytes: 4740
package main

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

var si = bufio.NewScanner(os.Stdin)

type Node struct {
        Id     int
        Parent int
        Count  int
        Child  []int
}

func readInt() int {
        si.Scan()
        ret, _ := strconv.Atoi(si.Text())
        return ret
}
func main() {
        si.Split(bufio.ScanWords)
        N, Q := readInt(), readInt()
        Parent := make([]int, N+1, N+1)
        Count := make([]int, N+1, N+1)
        Child := make([][]int, N+1, N+1)
        for i := 0; i < N-1; i++ {
                a, b := readInt(), readInt()
                Child[a] = append(Child[a], b)
                Child[b] = append(Child[b], a)

        }
        for i := 0; i < Q; i++ {
                p, x := readInt(), readInt()
                Count[p] += x
        }
        ret := make([]int, N+1, N+1)
        stack := []int{1}
        for len(stack) > 0 {
                t := stack[len(stack)-1]
                for i := range Child[t] {
                        if Parent[Child[t][i]] == 0 {
                                Parent[Child[t][i]] = t
                        }
                }
                stack = stack[:len(stack)-1]
                ret[t] = Count[t] + ret[Parent[t]]
                for _, v := range Child[t] {
                        if v != Parent[t] {
                                stack = append(stack, v)
                        }
                }
        }
        fmt.Println(strings.Trim(fmt.Sprint(ret[1:]), "[]"))

}

Measured memory_bytes: 31232
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include <random>
#define ll long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const int INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    string s;
    cin>>s;
    ll n=s.size(),cnt=0,cnt0=0;
    vll v;
    rep(i,n-1){
        if(i!=n-2-i&&s[i]!=s[n-2-i]){
            cout<<-1<<endl;
            return 0;
        }
        if(s[i]=='1') cnt++;
        else{
            v.pb(i+1);
            cnt0++;
        }
    }
    if(cnt0==n-1||s[0]=='0'||s[n-1]=='1'){
        cout<<-1<<endl;
        return 0;
    }
    rep(i,cnt){
        cout<<i+1<<" "<<i+2<<endl;
    }
    ll now=cnt+2,l=cnt+1;
    ll now1=2;
    rep2(i,1,n-2){
        if(s[i]=='1') now1++;
        else{
            cout<<now1<<" "<<now<<endl;
            now++;
        }
    }
    return 0;
}


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




using namespace std;

const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;


#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
#else
#define PRINT(A)
#endif

typedef pair<int, int> P;
typedef pair<ll, ll> PL;

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


class UnionFind{
    public:
    vector<int> par;
    vector<int> val;
    int root(int input){
        if(par[input]==input) return input;
        return par[input] = root(par[input]);
    }
    void unite(int val1, int val2){
        par[val1] = root(par[val2]);
    }
    bool same(int val1, int val2){
        return root(par[val1]) == root(par[val2]);
    }
    UnionFind(){
        return;
    }
};

ll X,M;

int main() {
    
    cin >> X;
    ll a = 0, b = 0;
    ll a_max;


    bool fin = false;
    rep(i,200){
        rep(j,200){
            a = i;
            b = j;
            a = a*a*a*a*a;
            b = b*b*b*b*b;
            if(X == a - b){
                a = i;
                b = j;
                PRINT(a)
                PRINT(b)
                fin = true;
                break;
            }
            if(X == a + b){
                a = i;
                b = -j;
                PRINT(a)
                PRINT(b)
                fin = true;
                break;
            }
            
            if(X == a - b){
                a = i;
                b = j;
                PRINT(a)
                PRINT(b)
                fin = true;
                break;
            }
            if(X == -a - b){
                a = - i;
                b =  j;
                PRINT(a)
                PRINT(b)
                fin = true;
                break;
            }
            if(X == -a + b){
                a = - i;
                b = - j;
                PRINT(a)
                PRINT(b)
                fin = true;
                break;
            }
        }
        if(fin){break;}
    }
    PRINT(a_max);

    cout << a << endl;
    cout << b << endl;
    return 0;
}


Measured memory_bytes: 3552
#include<bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (int)(n); i++)
#define sum(a) accumulate(a.begin(),a.end(),0LL)
#define put(i) cout<<fixed<<i<<endl
using namespace std;
using ll = long long;

int main(){
    ll n, m; cin >> n >> m;
    vector<ll> a(m), b(m);
    rep(i,m) cin >> a[i] >> b[i];;

    vector<vector<ll>> g(n+1);
    for(long long i = 0; i < m; i++){
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }

    ll maxl = 0;
    vector<ll> flag(n+1,0);
    vector<ll> c = a;
    c.insert(c.end(),b.begin(),b.end());
    

    for(auto y : c){
        
        if(flag[y]) continue;
        //BFS
        vector<ll> check(n+1,-1);
        queue<ll> q;
        q.push(y);
        check[y] = 1;
        //flag[y]++;
        ll cun = 0;
        while(!q.empty()){
            ll top = q.front(); q.pop();
            cun++;
            maxl = max(maxl, cun);
            flag[top]++;
            for(auto x:g[top]){
                if(check[x] < 0 and x != y){
                    
                    q.push(x);
                    check[x] = check[top] + 1;
                }
            }
        }
        //for(auto x : flag) cout << x << ' '; cout << endl;
    }
    //for(auto x : a) cout << x << " "; cout << endl;
    //for(auto x : b) cout << x << " "; cout << endl;

    if(m > 0) put(maxl);
    else put(1);
}

Measured memory_bytes: 26136
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919810364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int h, w, x, y;
int cnt;

signed main() {
	cin >> h >> w >> x >> y;
	if (x == 1 && y == 1) {
		cout << "No" << endl;
		return 0;
	}
	for (int i = x; i <= h; i += x) {
		for (int j = y; j <= w; j += y) {
			cnt++;
		}
	}
	int s = (1000000000 * cnt + 1 + (h*w - cnt - 1)) / (h*w - cnt);
	if (s*(x*y - 1) >= 1000000000)cout << "No" << endl;
	else {
		cout << "Yes" << endl;
		for (int i = 1; i <= h; i++) {
			for (int j = 1; j <= w; j++) {
				if (i%x == 0 && j%y == 0)cout << -1000000000 << " ";
				else cout << s << " ";
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 2944
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<long long> A(1<<N);
  for(int i = 0; i < (1<<N); ++i) cin >> A[i];
  vector<long long> dp(1<<N,0), M(1<<N,0);
  for(int i = 1; i < (1<<N); ++i){
    // vector<long long> tmp;
    set<int> s;
    for(int j = 0; j < N; ++j){
      if(!(i>>j&1)) continue;
      int i_ = i^(1<<j);
      dp[i] = max(dp[i],dp[i_]);
      // tmp.push_back(A[i_]);
      // tmp.push_back(M[i_]);
      s.insert(M[i_]);
    }
    M[i] = i;
    vector<long long> tmp;
    for(auto e : s){
      if(A[e] > A[M[i]])
        M[i] = e;
      tmp.push_back(A[e]);
    }
    tmp.push_back(A[i]);
    sort(tmp.rbegin(), tmp.rend());
    if(tmp.size() < 2) continue;
    dp[i] = max(dp[i],tmp[0]+tmp[1]);
    dp[i] = max(dp[i],dp[i-1]);
  }
  for(int i = 1; i < (1<<N); ++i)
    cout << dp[i] << endl;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

struct UnionFind {
  vector<int> par;  // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

  UnionFind(int N) : par(N) {  //最初は全てが根であるとして初期化
    for (int i = 0; i < N; i++) par[i] = i;
  }

  int root(int x) {  // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {  // xとyの木を併合
    int rx = root(x);         // xの根をrx
    int ry = root(y);         // yの根をry
    if (rx == ry) return;  // xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] =
        ry;  // xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

  bool same(int x, int y) {  // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

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

  UnionFind tree(n);
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    tree.unite(a, b);
  }
  map<int, int> check;
  int ans = -1;
  rep(i, 0, n) {
    int c = tree.root(i);
    if (check.find(c) == check.end()) {
      ans++;
      check[c] = 0;
    }
  }
  cout << ans << endl;
  return 0;
}

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

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

int main(void)
{
    int N, K;
    cin >> N >> K;
    vector<int> A(N, 0);
    vector<int> hist(N, 0);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        hist[A[i]-1]++;
    }

    sort(hist.begin(), hist.end(), greater<int>());

    int sel = 0;
    for(int i = 0; i < N; i++){
        if(hist[i] == 0){
            break;
        }
        sel = i;
    }
    int specs = sel+1;
    int numWritten = 0;
    while(specs > K){
        numWritten += hist[sel];
        specs--;
        sel--;
    }

    cout << numWritten << endl;

    return 0;
}


Measured memory_bytes: 4744
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

int main(){
    int N, x;
    cin >> N >> x;
    vector<int> a(N);
    for(int i=0; i<N; i++) cin >> a[i];
    sort(a.begin(), a.end());
    int cnt = 0;
    for(int i=0; i<N-1; i++){
        if(x >= a[i]){
            x -= a[i];
            cnt++;
        }else{
            break;
        }
    }
    if(x == a[N-1]) cnt++;

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
// ABC046 B - AtCoDeerくんとボール色塗り
#include <stdio.h>

int main(void) {
    int N, K;
    long long result;
    // input
    scanf("%d %d", &N, &K);

    result = K;

    if (N == 1) {
        printf("%lld\n", result);
        return 0;
    }
    int i;
    for (i = 0; i < (N - 1); i++) {
        result *= (K - 1);
    }
    printf("%lld\n", result);
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cassert>
#include <cstring>
#include <algorithm>
#define meow(args...) fprintf(stderr, args)
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
template<class Type> Type read() {
	Type a;
	bool b;
	unsigned char c;
	while(c=getchar()-'0', (c>9)&(c!=253));
	for(a=(b=c==253)?0:c; (c=getchar()-'0')<=9; a=a*10+c);
	return b?-a:a;
}
int (*rd)()=read<int>;
int n;
char a[40][41];
long long f[40][40][40];
int main() {
	assert(scanf("%d", &n)==1);
	for(int i=0; i<2*n; ++i) assert(scanf("%s", a[i])==1);
	for(int i=1; i<2*n; ++i) f[i][i][i]=1;
	for(int len=3; len<2*n; len+=2)
		for(int i=1, k=len; k<2*n; ++i, ++k)
			for(int j=i+1; j<k; ++j)
				for(int p=i; p<j; ++p)
					for(int r=j; r<k; ++r) {
						long long s=0;
						for(int l=p+1; l<=j; ++l) s+=f[i][p][l-1]*f[l][j][r];
						for(int q=r; q<=k; ++q) if(a[p][q]=='1') f[i][j][k]+=s*f[r+1][q][k];
					}
	long long ans=0;
	for(int i=1; i<2*n; ++i) if(a[0][i]=='1') ans+=f[1][i][2*n-1];
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 512
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
constexpr bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
constexpr bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

void Pr(bool f){
  cout << (f ? "Yes" : "No") << "\n";
  exit(0);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n, m;
  cin >> n >> m;
  
  vvll g(n);
  
  vll h(n);
  rep(i, n){
    cin >> h[i];
  }
  rep(i, m){
    ll a, b;
    cin >> a >> b;
    a--; b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  ll ans = 0;
  rep(i, n){
    ll f = 1;
    for(auto&& e: g[i]){
      if(h[e] >= h[i]){
        f = 0;
        break;
      }
    }
    ans += f;
  }
  print(ans);
}


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

int main () {
    int n;
    string s;
    map <string, int> m;
    cin >> n;
    while (n--) {
        cin >> s;
        m[s]++;
    }
    cout << m.size() << "\n";
    return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{
  gearup;
  ll n,k; cin >> n >> k;
  vl t(n),d(n); //tがネタ種類, dが美味しさ
  vpii p;
  rep(i,n){
    cin>>t[i]>>d[i];
    p.push_back({d[i],t[i]});
  }
  sort(rall(p)); //昇順ソート
  ll res = 0;
  map<int,int> mp;
  vector<int> b(n+1); //最大値をいれる
  priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > que;//降順ソート
  rep(i,k){
    res += p[i].first;
    mp[p[i].second]++;
    b[p[i].second] = max(p[i].first,b[p[i].second]);
  }
  rep(i,k){ //同じ種類が2つ以上のもので最大ではない値をqueにいれる
    if(mp[p[i].second] >= 2) if(b[p[i].second] != p[i].first)que.push({p[i].first,p[i].second});
  }
  ll type = mp.size();
  res += type*type;
  ll ans = res;
  
  int idx = k;
  while(1){ //終了条件queが空か,n種類になったか,nまで選んだか
    if(que.empty() || idx >= n)break;
    int num = que.top().first;
    que.pop();
    bool is_res = false;
    int num1;
    while(idx < n){
      num1 = p[idx].first;
      int type1 = p[idx++].second;
      if(mp[type1] == 0){
        mp[type1] = 1;
        is_res = true;
        type++;
        break;
      }
    }
    if(is_res){
      res -= num + (type-1)*(type-1);
      res += type*type + num1;
      ans = max(res,ans);
    }
    else break;
  }
  out(ans);
}

Measured memory_bytes: 6644
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
const long long MOD = 1e9+7, INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}



signed main(){
	int H,W;
	cin>>H>>W;
	string s[H];
	REP(i,H)cin>>s[i];
	int ma = 0;
	REP(i,H)REP(j,W)REP(k,H)REP(l,W){
		if(s[i][j]=='.'||s[k][l]=='.')continue;
		CHMAX(ma,abs(i-k)+abs(j-l));
	}
	cout<<ma<<endl;
}


Measured memory_bytes: 3244
from collections import deque
def slidemax(X, k):
    q = deque([])
    ret = []
    for i in range(len(X)):
        while q and q[-1][1] <= X[i]:
            q.pop()
        deque.append(q, (i+k, X[i]))
        if q[0][0] == i:
            deque.popleft(q)
        if i >= k-1:
            ret.append(q[0][1])
    return ret

def slidemin(X, k):
    q = deque([])
    ret = []
    for i in range(len(X)):
        while q and q[-1][1] >= X[i]:
            q.pop()
        deque.append(q, (i+k, X[i]))
        if q[0][0] == i:
            deque.popleft(q)
        if i >= k-1:
            ret.append(q[0][1])
    return ret

N, K = map(int, input().split())
A = [int(a) for a in input().split()]

a = 0
l = -1
cnt = 0
for i in range(1, N):
    if A[i-1] > A[i]: a = i
    if i >= K-1 and a <= i - K + 1:
        if i - l > 1: cnt += 1
        l = i

MA = slidemax(A, K)
MI = slidemin(A, K)
ans = 1 - max(cnt-1, 0)
l = -1
for i in range(K, N):
    if MI[i-K] != A[i-K] or MA[i-K+1] != A[i]:
        ans += 1

print(ans)

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

int main() {
	long long int n,i;
	cin>>n;
	long long int a[n],b[n],c[n];
	for(i=0;i<n;i++)
	  cin>>a[i];
	for(i=0;i<n;i++)
	  cin>>b[i];
	for(i=0;i<n;i++)
	  cin>>c[i];
	sort (a,a+n);
	sort(c,c+n);
	sort(b,b+n);
	long long int count1=0;
	for(i=0;i<n;i++)
	  {	//cout<<n-1-(upper_bound(c,c+n,b[i])-c-1)<<(lower_bound(a,a+n,b[i])-a);
	  	 long long int x,y;
	  	 x=n-1-(upper_bound(c,c+n,b[i])-c-1);
	  	 y=(lower_bound(a,a+n,b[i])-a);
	  	 count1+=x*y;
	  }
	cout<<count1<<'\n';  
	return 0;
}

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

namespace AtCoder.Abc
{
    class A_165_WeLoveGolf
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            long n = long.Parse(Console.ReadLine());

            // 整数配列の入力
            var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            long A = inputLongArray[0];
            long B = inputLongArray[1];

            // 回答
            bool flg = false;
            for (long i = A; i <= B; i++)
            {
                if (i % n == 0)
                {
                    Console.WriteLine("OK");
                    flg = true;
                    break;
                }
            }
            if (flg == false)
            {
                Console.WriteLine("NG");
            }

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 28208
#define TST 0
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>
#include <bits/stdc++.h>

using namespace std;
// for loop
#define F(i, L, R) for(long i = L; i < R; i++)
#define FE(i, L, R) for(long i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(long i = L; i > R; i--)
#define FRE(i, L, R) for(long i = L; i >= R; i--)

// data types
#define Int long
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back
#define InputV(a, n) F(i,0,n){long l; cin >> l; a.pb(l);}

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)
#define printM(a, n, m) F(i, 0, n){ FE(j, 0, m) cout << a[i][j] << (i==m?'\n':' ');}

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

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

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

#define printMatrix(mat,n,m){ \
    F(i, 0, n){               \
        F(j, 0, m){           \
            cout << mat[i][j] << space;\
        }\
        cout << endl;\
    }\
}

int main() {
#if TST==1
    ifstream in ("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int n;
    cin >> n;
    bool ans = false;
    FE(i, 1, 9){
        FE(j, 1, 9){
            if(i * j == n){
                ans = true;
            }
        }
    }
#if TST==1
    printMatrix(dp, n+2, 5+2);
#endif
    string out = ans? "Yes": "No";
    cout << out << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <cstring>
#define N 52
using namespace std;
int n, k;
char s[N];
int main() {
    cin >> n >> k;
    cin >> s;
    s[k - 1] = s[k - 1] + 'a' - 'A';
    cout << s;
    return 0;
}

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

int a[30];

int main() {
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  #endif
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  int ans = 0;
  for (int i = 1; i < n - 1; ++i) 
    if ((a[i] > a[i - 1] && a[i] < a[i + 1]) || (a[i] < a[i - 1] && a[i] > a[i + 1])) ++ans;
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

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

int main(){
	ll n;
	cin >> n;
	vector<ll> a(n);
	REP(i,n) cin >> a[i];
	
	//sort(a.begin(), a.end());
	
	ll monster=a[0];
	for(int i=1; i<n; ++i){
		/*
		if(a[i]%monster>0){
			monster -= a[i]%monster;
		}*/
		monster = gcd(monster,a[i]);
	}
	cout << monster << endl;
	
	return 0;
}

Measured memory_bytes: 4068