akhauriyash/Code-Regression huggingface dataset:
class RMQ:
    def __init__(self, length, ini_num = float("inf")):
        self.length = 1
        while self.length < length:
            self.length <<= 1
        self.segtree = [ini_num] * (2 * self.length - 1)

    def update(self, index, n):
        leaf_index = index + self.length - 1
        self.segtree[leaf_index] = n
        while leaf_index > 0:
            leaf_index = (leaf_index - 1) // 2
            self.segtree[leaf_index] = min(self.segtree[leaf_index * 2 + 1], self.segtree[leaf_index * 2 + 2])

    def find(self, a, b, index, l, r):
        if a <= l <= r <= b:
            return self.segtree[index]
        elif b < l or r < a:
            return float("inf")
        else:
            return min(self.find(a, b, index * 2 + 1, l, (l + r) // 2), self.find(a, b, index * 2 + 2, (l + r) // 2 + 1, r))

v_num, query = (int(n) for n in input().split(" "))
rmq = RMQ(v_num, 2147483647)
for _ in range(query):
    com, i, n = (int(n) for n in input().split(" ") )
    if com == 0:
        rmq.update(i, n)
    else:
        print(rmq.find(i, n, 0, 0, rmq.length - 1))

Measured memory_bytes: 11028
package main

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

func main() {
	sc := NewScanner()
	N, K := sc.NextInt(), sc.NextInt()
	p := sc.NextIntArray()
	a := make([]float64, N)
	for i := 0; i < N; i++ {
		a[i] = (float64((1+p[i])*p[i]) / 2.0) / float64(p[i])
	}

	c := 0.0
	cur := 0
	for ; cur < K; cur++ {
		c += a[cur]
	}
	mx := c
	for ; cur < N; cur++ {
		c -= a[cur-K]
		c += a[cur]
		if mx < c {
			mx = c
		}
	}
	fmt.Println(mx)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

int main()
{
	string s, t;
	cin >> s >> t;
	int mozisu_s = s.length(), mozisu_t = t.length();

	int flag = 0, i2 = -1;
	for (int i = 0; i < mozisu_s - mozisu_t + 1; i++) {
		int ii = i;
		flag = 0;
		for (int j = 0; j < mozisu_t; j++) {
			if (t[j] != s[ii] && s[ii] != '?') {
				flag = 1;
			}
			ii++;
		}
		if (flag == 0) {
			i2 = max(i2, i);
		}
	}

	if (i2 == -1) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	else {
		int jj = 0;
		while (mozisu_t - 1 >= jj) {
			s[i2] = t[jj];
			i2++;
			jj++;
		}
		for (int i = 0; i < mozisu_s; i++) {
			if (s[i] == '?') {
				s[i] = 'a';
			}
		}
	}

	cout << s << endl;

	return 0;
}

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

int gcd(int u, int v){
	while(v!=0){
		int r = u%v;
		u = v;
		v = r;
	}
	return u;
}

int main(){
	int p,q;
	cin >> p >> q;
	q /= gcd(p,q);
	
	int ans=1;
	int rq=q;
	for(int i=2; i*i<=q; i++){
		if(rq%i==0){
			ans*=i;
		}
		while(rq%i==0){
			rq/=i;
		}
	}
	ans *= rq;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int N,M;
    cin >> N >> M;
    string A[N];
    string B[M];
    for(int i = 0; i < N;i++)cin >> A[i];
    for(int i = 0; i < M;i++)cin >> B[i];
    
    bool flag;
    for(int i = 0; i <= N - M;i++){
        
        for(int j = 0; j <= N - M;j++){
        
            flag = true;
        
            for(int k = 0; k < M;k++){
                
                for(int l = 0; l < M;l++){
                    
                    if(A[i+k][j+l]!=B[k][l]){
                        flag = false;
                        break;
                    }
                    
                }
            if(!flag)break;
            }
            
            if(flag){
                cout << "Yes"<<endl;
                return 0;
            }    
        
        
        }
        
    }
    
    cout << "No"<<endl;
    return 0;

}


Measured memory_bytes: 256
n=int(input())
a=input()
b=input()
if a[0]!=b[0]:
  x=6
  p=2
  f=1
else:
  x=3
  p=1
  f=0
while p<n:
  if f:
    if a[p]!=b[p]:
      p+=2
      x*=3
    else:
      p+=1
      f=0
  else:
    if a[p]!=b[p]:
      p+=2
      x*=2
      f=1
    else:
      p+=1
      x*=2
print(x%(10**9+7))

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

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int res = 0;
    for(int i = 1; i <= n; ++i) {
        int temp = i;
        int cnt = 0;
        while(temp > 0) {
            ++cnt;
            temp /= 10;
        }
        res += (cnt%2);
    }
    cout << res << '\n';
}


Measured memory_bytes: 256
def bubbleSort(A, N):
    flag = True
    count = 0
    while flag:
        flag = False
        for i in range(N-1, 0, -1):
            if A[i] < A[i-1]:
                A[i], A[i-1] = A[i-1], A[i]
                count += 1
                flag = True

    return A, count

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))

    answer_list, answer_count = bubbleSort(A, N)

    print(*answer_list)
    print(answer_count)



Measured memory_bytes: 5608
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

bool kaibun(string S) {
  int L = S.size();
  for (int i = 0; i < L/2; ++i) {
    if (S[i] != S[L-1-i]) return false;
  }
  return true;
}

int main() {
  string S; cin >> S;
  int N = S.size();
  bool a =  kaibun(S);
  bool b =  kaibun(S.substr(0, (N-1)/2));
  bool c =  kaibun(S.substr((N+1)/2));
  if (a && b && c) cout << "Yes" << endl;
  else             cout << "No" << endl;
}


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

int main(){
  int n; int k; cin>>n>>k;
  int h[110000];
  int count=0;
  for(int i=0;i<n;i++){
  cin>>h[i];
  if(h[i]>=k) count++;
}
cout<<count<<endl;
}


Measured memory_bytes: 640
import heapq

xs,ys,xt,yt = map(int, input().split())
N = int(input())
L = [[int(l) for l in input().split()] for _ in range(N)]

def dist(x, y, s, t):
    return ((x-s)**2 + (y-t)**2)**0.5
    
h = []
for i in range(N):
    heapq.heappush(h, (max(0, dist(xs, ys, L[i][0], L[i][1])-L[i][2]), i))

inf = 10**10
d = [inf]*N
cnt = 0
while cnt < N:
    temp = heapq.heappop(h)
    if d[temp[1]] < inf:
        continue
    cnt += 1
    d[temp[1]] = temp[0]
    for i in range(N):
        if d[i] < inf:
            continue
        heapq.heappush(h, (temp[0]+max(0, dist(L[i][0], L[i][1], L[temp[1]][0], L[temp[1]][1])-L[i][2]-L[temp[1]][2]), i))

ans = dist(xs, ys, xt, yt)
for i in range(N):
    ans = min(ans, d[i]+max(0, dist(xt, yt, L[i][0], L[i][1])-L[i][2]))

print(ans)

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, T, A;
  cin >> N >> T >> A;
  int h;
  vector<double> diff;
  REP(i, N) {
    cin >> h;
    diff.push_back(abs(A - (T - (h * 0.006))));
  }

  auto min_diff = min_element(diff.begin(), diff.end());
  int ans = std::distance(diff.begin(), min_diff);
  cout << ans + 1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <string>

using namespace std;

int main() {
  while (true) {
    string s;
    getline(cin, s);
    if (s == ".") break;
    string ans = "yes";
    std::stack<char> st;
    for (int i = 0; i < s.size(); ++i) {
      if (s[i] == '(') {
        st.push('(');
      } else if (s[i] == '[') {
        st.push('[');
      } else if (s[i] == ')') {
        if (st.empty() || st.top() != '(') {
          ans = "no";
        }
        if (!st.empty()) st.pop();
      } else if (s[i] == ']') {
        if (st.empty() || st.top() != '[') {
          ans = "no";
        }
        if (!st.empty()) st.pop();
      }
    }
    if (st.size() != 0) ans = "no";

    cout << ans << endl;
  }
}

Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  cin >> N;
  
  int ans=0;
  
  vector<int> B(N);
  
  for ( int i=0; i<N-1; i++) {
    
    cin >> B.at(i);
  }
  
  for ( int i=0; i<N; i++) {
  
    if (i==N-1) {
      ans += B.at(i-1);
    }
    else if( i==0 ) {
      ans += B.at(i);
    }
         
    else {
     ans += min(B.at(i),B.at(i-1));
    }
    
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < int(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < int(n); ++ (i))
using ll = long long;
using namespace std;
ll powmod(ll x, ll y, ll p) { assert (0 <= x and x < p); assert (0 <= y); ll z = 1; for (ll i = 1; i <= y; i <<= 1) { if (y & i) z = z * x % p; x = x * x % p; } return z; }
ll modinv(ll x, ll p) { assert (x % p != 0); return powmod(x, p - 2, p); }

constexpr int mod = 1e9 + 7;
int main() {
    // input
    int n; cin >> n;
    string s; cin >> s;
    // solve
    vector<int> cur(n + 2);
    vector<int> prv(n + 2);
    cur[0] = 1;
    REP (i, n) {
        cur.swap(prv);
        cur[0] = (prv[0] + prv[1]) % mod;
        REP3 (j, 1, n + 1) {
            cur[j] = (2ll * prv[j - 1] + prv[j + 1]) % mod;
        }
    }
    int result = cur[s.length()] *(ll) powmod(modinv(2, mod), s.length(), mod) % mod;
    // output
    cout << result << endl;
    return 0;
}


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

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define mp make_pair

using namespace std;

using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvb = vector<vb>;

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

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()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    ld n, m, d; cin >> n >> m >> d;
    ld t = 2;
    if(d == 0) t = 1;
    cout << (m-1)*t*(n-d)/(n*n) << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main ()
{
	int a,b,n,c;
	cin>>n;
	for(a=1;a<10;a++)
	{
		for(b=1;b<10;b++)
		{
			if(a*b==n)
			{
				cout<<"Yes";
				return 0;
			}
		}
	}
	cout<<"No";
	
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
    long long N, A, B;

    cin >> N >> A >> B;

    if(N == 1){
        if(A != B){
            cout << 0 << endl;
        }
        else{
            cout << 1 << endl;
        }
    }

    else if(N == 2){
        cout << 1 << endl;
    }

    else{
        if(B < A){
            cout << 0 << endl;
        }

        else{
            cout << B*(N-2)-A*(N-2)+1 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/perl
#= CPAN mocules =====================================================#
use strict;				# strictモード
use warnings;			# 警告有効

#= Global values ====================================================#
#= Local routines ===================================================#
sub main(){
	my $in = <>;
	chomp $in;
	my ($n, $m) = split(/ /, $in);

	$in = <>;
	chomp $in;
	my (@a) = split(/ /, $in);

	my $sum = 0;
	foreach(@a){
		$sum += $_;
	}

	@a = sort {$b <=> $a} @a;
	my $min = $sum / ($m * 4);

	my $cnt = 0;
	foreach (@a){
		if ($_ < $min){
			last;
		}
		$cnt++;
		if ($cnt >= $m){
			last;
		}
	}

	print (($cnt >= $m)?"Yes":"No");

	return 0;
}

#----- 実行 -----#
exit( main() );




Measured memory_bytes: 768
#include<iostream>
#include<string.h>
using namespace std;


int main(){
  string S;
  int res =0;
  cin >> S;
  for(int i=0;i<S.length();i++){
    if(S[i]=='o') res++;
  }
  res += 15-S.length();
  if(res >= 8) cout << "YES" << endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int INFTY = (1 << 21); // 2097152
// const ll INFTY = (1LL << 60);
const ll MD = 1000000007LL;
// fprintf(stderr, "%d %lld \n", x, xll);


int N, M;
int D[200000];
int T[200000];

int main() {
	cin >> N;
	rep(i, N) cin >> D[i];
	cin >> M;
	rep(i, M) cin >> T[i];

	map<int, int> MD;
	map<int, int> MT;
	rep(i, N){
		int v = D[i];
		if(MD.find(v) == MD.end()) MD[v] = 0;
		MD[v]++;
	}
	rep(i, M){
		int v = T[i];
		if(MT.find(v) == MT.end()) MT[v] = 0;
		MT[v]++;
	}

	bool flag = true;
	for(auto it: MT){
		int v = it.first;
		int c = it.second;
		if(MD.find(v) == MD.end() || MD[v] < c) flag = false;
	}
	cout << (flag ? "YES" : "NO") << endl;
}

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

using namespace std;
using ll = long long;

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

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

  vector<vector<int>> v;
  multiset<int> s;
  map<int, int> id;
  rep(i, n) {
    auto it = s.lower_bound(a[i]);
    if (it == s.begin()) {
      id[a[i]] = v.size();
      v.push_back(vector<int>{a[i]});
      s.insert(a[i]);
    } else {
      --it;
      id[a[i]] = id[*it];
      v[id[a[i]]].push_back(a[i]);
      s.erase(s.find(*it));
      s.insert(a[i]);
    }
  }

  int ans = v.size();
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 18192
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void){
    int num;
    cin>>num;
    
    vector<vector<string>> inputData(num,vector<string>(2));

    int p=0;
    while(p<num){
        for(int i=0;i<2;i++){
            cin>>inputData[p][i];
        }
        p+=1;
    }

    int q=0;
    while(q!=num){
        int s=inputData[q][0].length();
        int t=inputData[q][1].length();
        vector<vector<int>> Table(s,vector<int>(t));

        for(int i=0;i<s;i++){
            if(inputData[q][0][0]==inputData[q][1][i]){
                Table[0][i]=1;
            }else{
                Table[0][i]=0;
            }

            if(inputData[q][0][i]==inputData[q][1][0]){
                Table[i][0]=1;
            }else{
                Table[i][0]=0;
            }
        }

        vector<int> RMax(t);
        for(int i=0;i<t;i++){
            RMax[i]=Table[0][i];
        }

        //Table作成
        for(int i=1;i<s;i++){
            int max=0;
            for(int j=1;j<t;j++){
                if(RMax[j-1]>max){
                    max=RMax[j-1];
                }
                Table[i][j]=max;
                if(inputData[q][0][i]==inputData[q][1][j]){
                    Table[i][j]+=1;
                }
            }

            for(int k=0;k<t;k++){
                if(Table[i][k]>RMax[k]){
                    RMax[k]=Table[i][k];
                }
            }
        }

        //表示
        int ans=0;
        for(int i=0;i<s;i++){
            for(int j=0;j<t;j++){
                if(Table[i][j]>ans){
                    ans=Table[i][j];
                }
            }
        }

        cout<<ans<<endl;

        // for(int i=0;i<s;i++){
        //     for(int j=0;j<t;j++){
        //         cout<<Table[i][j]<<" ";
        //     }
        //     cout<<endl;
        // }
        q+=1;
        // cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 6828
import java.util.Scanner;

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

        if (k % 2 == 0) {
            long counterA = 0;
            for (int i = 1; i <= n; i++) {
                if (i % k == 0) {
                    counterA++;
                }
            }

            long counterB = 0;
            for (int i = 1; i <= n; i++) {
                if (i % k == k / 2) {
                    counterB++;
                }
            }

            System.out.println((long) Math.pow(counterA, 3L) + (long) Math.pow(counterB, 3L));
            return;
        }

        long counter = 0;
        for (int i = 1; i <= n; i++) {
            if (i % k == 0) {
                counter++;
            }
        }

        System.out.println((long) Math.pow(counter, 3L));
    }
}


Measured memory_bytes: 21716
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        
        AtCoder problem = new AtCoder(sc);
        problem.solve(out);
        
        out.flush();
    }
    
}

class AtCoder {
    final int A, B;
    AtCoder(FastScanner sc) {
        A = sc.nextInt();
        B = sc.nextInt();
    }

    void solve(PrintWriter out) {
        out.println(Math.max(A-B*2, 0));
    }
    
}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {
    
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    
    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }
    
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }
    
    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    
    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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

int main() {
  
  int K; cin >> K;
  vector<int64_t> lunlun;
  
  int i=0;
  while(i<9){
    lunlun.push_back(i+1);
    i++;
  }
  
  int a = 0;
  while(i<K){
    int64_t b = lunlun.at(a);
    if(!(b%10 == 0)){
      lunlun.push_back(b*10+b%10-1);
      i++;
    }
    lunlun.push_back(b*10+b%10);
    i++;
    if(!(b%10 == 9)){
      lunlun.push_back(b*10+b%10+1);
      i++;
    }
    a++;
  }
  
  cout << lunlun.at(K-1) << endl;
  
}

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

int r[20000];
int main() {
	int n, s;
	while (scanf("%d%d", &n, &s), n) {
		rep(i, n)scanf("%d", &r[i]);
		int cnt = 0;
		rep(i, n)for (int j = i + 1; j < n; j++) {
			if (r[i] + r[j] > s)cnt++;
		}
		printf("%d\n", cnt);
	}
}

Measured memory_bytes: 3184
import java.util.Scanner;
class Main
{
    public static void main(String args[])
    {
	int a,b,c;
	Scanner scan=new Scanner(System.in);
	a=scan.nextInt();
	b=scan.nextInt();
	c=scan.nextInt();
	if(a<b && b<c)
	    System.out.println("Yes");
	else
	    System.out.println("No");
    }
}

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

static const int MAX_N = 100;

int bubbleSort(int A[], int N) {
    bool flag = true;
    int cnt = 0;
    for (int i = 0; flag; ++i) {
        flag = false;
        for (int j = N-1; j >= i+1; --j) {
            if (A[j] < A[j-1]) {
                swap(A[j], A[j-1]);
                flag = true;
                cnt++;
            }
        }
    }
    return cnt;
}


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

    int cnt = bubbleSort(A, N);
    for (int i = 0; i < N; ++i) {
        if (i == N-1) cout << A[i] << endl;
        else cout << A[i] << " ";
    }
    cout << cnt << endl;
}



Measured memory_bytes: 3112
#include <iostream>
#include <cstdio>
#include <cstring>
typedef long long ll;
#define N 100005
#define fr(i,x,y) for(int i=x;i<=y;i++)
#define ms(x,y) memset(x,y,sizeof(x))
ll dp[N][6],ans1,ans2;
int son[N][6];
int head[N],o;
struct node{
    int to,next;
}e[N<<1];
int n,kk;
int a[N];
ll an1,an2;
void doit()
{
    fr(i,1,n)scanf("%d",&a[i]);
    an1=an2=0;
    ll tmp;
    if (a[1]<=0) {an1+=-a[1]+1;tmp=1;}else tmp=a[1];
    fr(i,2,n)
    {
        tmp+=a[i];
        if (i%2==0){
            if (tmp>=0) {an1+=tmp+1;tmp=-1;}
        }else{
            if (tmp<=0) {an1+=-tmp+1;tmp=1;}
        }
    }
    if (a[1]>=0) {an2+=a[1]+1;tmp=-1;}else tmp=a[1];
    fr(i,2,n)
    {
        tmp+=a[i];
        if (i%2==0){

            if (tmp<=0) {an2+=-tmp+1;tmp=1;}
        }else{
            if (tmp>=0) {an2+=tmp+1;tmp=-1;}
        }
    }
    printf("%lld\n",an1>an2?an2:an1);
}

int main() {
    while (scanf("%d",&n)!=EOF)
    {
        doit();
    }
    return 0;
}

Measured memory_bytes: 640
a,z,x,i,j;
main(t)
{
  for(scanf("%d",&t);t--;printf("%d %d\n",-z,a))
    for(a=z=0,scanf("%d%d",&x,&i);--x;i=j)
      scanf("%d",&j),i-=j,a=i>a?i:a,z=i<z?i:z;
  //  a=0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
constexpr ll mod = 1e9 + 7;
#define endl '\n'
 
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
 
  string s;
  cin >> s;
  int n = s.length();
  for (char& c : s) if (c == '?') c = 'D';
  cout << s << endl;

}


Measured memory_bytes: 3716
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstdio> 
using namespace std;
int main(){
   int a;
   cin>>a;
   if(a%2==0)   cout<<a;
   else     cout<<2*a;
   system("pause");
   return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
main(){
  string s;
  cin>>s;
  for(int i=0;i<s.size();++i){
    if(s[i]!='U'&&s[i]!='D'){
      if((i%2==1&&s[i]!='L')||(i%2==0&&s[i]!='R'))return cout<<"No",0;
    }
  }
  cout<<"Yes";
}

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

using namespace std;
typedef long long ll;
#define debug(x) cerr << x << "\n"
#define all(x) (x).begin(),(x).end()
#define exist(s, e)((s).find(e) != (s).end())

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string o,e;
    cin >> o >> e;
    if (o.size() == e.size()) {
        for (int i = 0;i < e.size();i++) {
            cout << o[i] << e[i];
        }
        cout << '\n';
    }
    else if (e.size() == o.size() - 1) {
        for (int i = 0;i < e.size();i++) {
            cout << o[i] << e[i];
        }
        cout << o.back() << '\n';
    }
    

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()) {
            double a = scanner.nextDouble();
            double b = scanner.nextDouble();
            double c = scanner.nextDouble();
            double d = scanner.nextDouble();
            double e = scanner.nextDouble();
            double f = scanner.nextDouble();

            Equation[] equation = new Equation[2];
            equation[0] = new Equation(a, b, c);
            equation[1] = new Equation(d, e, f);

            double[] solution = solve(equation[0], equation[1]);

            final int SIZE = solution.length;
            for (int i = 0; i < SIZE; i++) {
                if (solution[i] == -0) {
                    solution[i] = 0;
                }
            }
            System.out.printf("%.3f %.3f\n", solution[0], solution[1]);
        }
    }

    static double[] solve(Equation left, Equation right) {
        double determinant = left.a * right.b - right.a * left.b;
        double x = (right.b * left.c - left.b * right.c) / determinant;
        double y = (-right.a * left.c + left.a * right.c) / determinant;

        double[] result = { x, y };
        return result;
    }

}

// ax + by = c
class Equation {

    Equation(double a, double b, double c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    public double a;
    public double b;
    public double c;

}

Measured memory_bytes: 28596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll i = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll i = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll i = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

int main(void){
	string s;
	cin >> s;
	ll n = s.size();

	ll l = 0, r = n;
	while(r - l > 1){
		ll m = (l + r) / 2;
		bool flg = false;
		rep(t, 4){
			ll mi = t % 2, ma = m - t / 2;
			bool ok = true;
			rep(i, n){
				if(s[i] == '0'){
					--ma;
					--mi;
				}else if(s[i] == '1'){
					++ma;
					++mi;
				}else{
					++ma;
					--mi;
				}

				if (ma > m) ma -= 2;
				if (mi < 0) mi += 2;
				// if(m == 21 && ma - mi < 2) co({i, mi, ma});
				if (ma < mi){
					ok = false;
					break;
				}
			}
			flg |= ok;
		}

		if (flg) r = m;
		else
			l = m;
	}
	co(r);

	return 0;
}


Measured memory_bytes: 5304
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	string str;
	cin >> str;
	cout << str.find_last_of('Z') - str.find_first_of('A') + 1 << endl;
	return 0;
}

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

using namespace std;

long gcd(long a, long b){
  if(a==0||b==0) return 0;
  long temp;
  while((temp = a%b)!=0){
    a = b;
    b = temp;
  }
  return b;
}

long lcm(long a, long b){
  if(a==0||b==0) return 0;
  return (a / gcd(a,b))*b;
}

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

  vector<long> t;

  for(int i=0;i<n;i++){
    long temp;
    cin >> temp;
    t.push_back(temp);
  }

  long ans = 1;

  for(int i=0;i<n;i++){
    ans = lcm(t[i],ans);
  }
  cout << ans << endl;
        return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
int gcd(int x,int y){
	if(!y)return x;
	return gcd(y,x%y);
}
int main(){
	n=read();m=read();
	printf("%lld\n",1ll*n*m/gcd(n,m));
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

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

    int N;
    read(N);
    vector<string> s(N);
    vector<int> t(N);

    rep(i, N) {
        read(s[i], t[i]);
    }

    string k;
    read(k);

    int ans = 0;
    int start = find(all(s), k) - begin(s);
    reps(i, start+1, N-1) {
        ans += t[i];
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod=1000000007;
#define pb  push_back
#define FOR(i,n) for(int i=0;i<(n);i++)
#define FORA(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define count_1(n)  __builtin_popcountll(n)
#define parity(n)   __builtin_parityll(n)   //Even parity 0 as output
void show    (int a[], int arraysize) { for (int i = 0; i < arraysize; ++i)  {cout << a[i] << " ";}	cout<<endl;}
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
void sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}
int main()
{FAST

string s;
cin>>s;
if(s[2]==s[3]&&s[4]==s[5])
{
	cout<<"Yes";
}
else
	cout<<"No";
return  0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;
 

int main() {
    ios_base::sync_with_stdio(false);
    
    int n;
    string s; 
    cin >> n;
    cin >> s;
    vector<vector<int>> r(3);
    ll ans=0;
    rep(i,n) {
        if (s[i]=='R') r[0].push_back(i);
        else if (s[i]=='G') r[1].push_back(i);
        else r[2].push_back(i);
    }
    string t="RGB";
    vector<int> a= {0,1,2};

    sort(a.begin(), a.end());
    do
    {
        rep(i,n-2) {
            if (s[i]==t[a[0]]) {
                repr(j,i+1,n-1) {
                    if (s[j]==t[a[1]]) {
                        ans+=r[a[2]].end()-lower_bound(r[a[2]].begin(),r[a[2]].end(),j);
                        int k=lower_bound(r[a[2]].begin(),r[a[2]].end(),j+(j-i))-r[a[2]].begin();
                        if (k>=r[a[2]].size()) continue;
                        if (r[a[2]][k]==j+(j-i)) --ans;
                    }
                }
            }
        }
    } while (next_permutation(a.begin(), a.end()));
    cout << ans << endl;
    
}

Measured memory_bytes: 3656
N = int(input())

x = [0] * N
y = [0] * N
h = [0] * N

for i in range(N):
    xyh = list(map(int, input().split()))
    x[i] = xyh[0]
    y[i] = xyh[1]
    h[i] = xyh[2]
    if xyh[2] != 0:
        Cx = xyh[0]
        Cy = xyh[1]
        CH = xyh[2]

for i in range(101):
    for j in range(101):
        flag = True
        H = CH + abs(i - Cx) + abs(j - Cy)
        for k in range(N):
            if h[k] != max(H - abs(i - x[k]) - abs(j - y[k]), 0):
                flag = False
                break
        if flag:
            print(i, j, H)


Measured memory_bytes: 3064
#include <cstdio>
#include <deque>
#include <vector>

// スライド最小値を用いて, 固定した サイズ k と 配列 A に対し
// 各 i = 0, 1, ..., n に対し A[i, i + k) の最小値を O(N) で求める関数
template <typename element_t>
std::vector<element_t> slideMinimum(const std::vector<element_t>& A, unsigned int k){
    const unsigned int n = A.size();
    if(n == 0) return std::vector<element_t>(0); 
    if(n < k) k = n;

    std::vector<element_t> res(n); // 返り値
    // インデックス列 : インデックスは単調増加であり, A[インデックス] も単調増加になる
    std::deque<unsigned int> deq;
    unsigned int i, j;
    for(i = 0; i < k; ++i){
        while((not deq.empty()) and A[i] <= A[deq.back()]) deq.pop_back(); 
        deq.push_back(i);
    }
    for(j = 0; i < n; ++i, ++j){
        res[j] = A[deq.front()]; if(j == deq.front()) deq.pop_front();
        while((not deq.empty()) and A[i] <= A[deq.back()]) deq.pop_back();
        deq.push_back(i);
    }
    for(; j < n; ++j){ res[j] = A[deq.front()]; if(j == deq.front()) deq.pop_front();}
    return res;
}


int main(void){
    unsigned int n, L; scanf("%u%u", &n, &L);
    std::vector<unsigned int> A(n);
    for(unsigned int i = 0; i < n; ++i) scanf("%u", &A[i]);
    std::vector<unsigned int> Min = slideMinimum(A, L);
    for(unsigned int i = 0; i + L <= n; ++i){
        printf("%u", Min[i]); putchar(i + L == n ? '\n' : ' ');
    }
    return 0;
}


Measured memory_bytes: 10452
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, m;
    vector<double> l(20), a(20), b(20);
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> l[i] >> a[i] >> b[i];
    }
    double ans;
    for (int i = 0; i < (1 << n); i++)
    {
        int t = i;
        int cnt = 0;
        while (t > 0)
        {
            if (t & true)
                cnt++;
            t >>= 1;
        }
        if (cnt != m)
            continue;
        double tmp_ans = 0;
        for (int j = 0; j < n; j++)
        {
            for (int k = j + 1; k < n; k++)
            {
                if ((i >> j) & 1 && (i >> k) & 1)
                {
                    tmp_ans += pow(l[j] - l[k], 2);
                    tmp_ans += pow(a[j] - a[k], 2);
                    tmp_ans += pow(b[j] - b[k], 2);
                }
            }
        }
        if (tmp_ans > ans)
            ans = tmp_ans;
    }
    cout << fixed << setprecision(6) << ans << endl;
    return 0;
}


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

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

    int cnt[10][10] = {0};
    for (int i = 1; i <= n; ++i) {
        string s = to_string(i);
        cnt[s[0] - '0'][s[s.size() - 1] - '0']++;
    }

    ll ans = 0;
    rep(i, 10) {
        rep(j, 10) {
            ans += cnt[i][j] * cnt[j][i];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N, M=map(int, input().split())
import numpy as np

pena=np.array([0]*N)
status=np.array([0]*N)


for i in range(M):
  p,s=tuple(input().split())
  p=int(p)
  if s=="WA":
    if status[p-1]!=1:
      pena[p-1]+=1
  if s=="AC":
    if status[p-1]!=1:
      status[p-1]=1
nac=sum(status)
npena=sum(pena*status)
print(nac, npena)

Measured memory_bytes: 14804
n = int(input())
a = list(input().split())

if n%2 == 0:
    x = a[::2]
    y = a[-1::-2]
    ans = y+x
else:
    x = a[::-2]
    y = a[1::2]
    ans = x+y

ans = " ".join(ans)
print(ans)

Measured memory_bytes: 27204
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  vector<vector<ll> > a(n, vector<ll>(n));
  rep(i,n) rep(j,n) cin >> a[i][j];
  vector<ll> cost(1<<n, 0);
  for (int bit = 1; bit < (1<<n); ++bit) {
    rep(i,n) {
      if (!(bit & (1<<i))) continue;
      for (int j = i+1; j < n; ++j) {
        if (bit & (1<<j)) cost[bit] += a[i][j];
      }
    }
  }

  vector<ll> dp(1<<n, 0);
  for (int s = 1; s < (1<<n); ++s) {
    for (int t = s; t > 0; t = (t-1)&s) {
      chmax(dp[s], dp[s-t] + cost[t]);
    }
  }
  cout << dp[(1<<n)-1] << endl;
  return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

double average(int a,int b,int c){
	return ((double)a+(double)b+(double)c)/3.0;
}
int main(){
	int n;
	while(cin>>n,n){
		int pe,pm,pj;
		char cls[n];
		rep(i,n){
			cin>>pm>>pe>>pj;
			if(pm==100 || pe==100 || pj==100)cls[i]='A';
			else if(average(pm,pe,pj)>=80 ||((double)pm+(double)pe)/2>=90)cls[i]='A';
			else if(average(pm,pe,pj)>=70 || (average(pm,pe,pj)>=50 && (pm>=80 || pe>=80)))cls[i]='B';
			else cls[i]='C';
		}
		rep(i,n)cout<<cls[i]<<endl;
	}
	return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  int vertex[N];
  for (int i{}; i < N; ++i)
    vertex[i] = i+1;
  bool edge[N+1][N+1];
  fill(edge[0], edge[0]+(N+1)*(N+1), false);
  for (int i{}; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    edge[a][b] = edge[b][a] = true;
  }

  int ans{};
  sort(vertex, vertex + N); // 昇順にソートしておく必要あり
  do {
    bool path{true};
    for (int i{}; i < N-1; ++i) {
      if (!edge[vertex[i]][vertex[i+1]]) {
        path = false;
        break;
      }
    }
    if (path)
      ++ans;
  } while (next_permutation(vertex + 1, vertex + N));

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


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

int main() {
	cin.tie(0)->sync_with_stdio(false);

	string s; cin >> s;
	int cnt = 0;
	while (s.size() > 1) {
		int n = s.size();
		if (s[0] == s[n - 1]) {
			s.erase(s.begin());
			s.pop_back();
		} else if (s[0] == 'x') {
			s.push_back('x');
			cnt++;
		} else if (s[n - 1] == 'x') {
			s.insert(s.begin(), 'x');
			cnt++;
		} else {
			cnt = -1;
			break ;
		}
	}
	cout << cnt << '\n';
	return 0;
}

Measured memory_bytes: 3748
import numpy as np

H, W = map(int, input().split())
A = [[] for _ in range(H)]
inf = 10 ** 7
for i in range(H):
    A[i] = list(input())
    for j in range(W):
        if A[i][j] == '.':
            A[i][j] = inf
        elif A[i][j] == '#':
            A[i][j] = 0

A = np.array(A)

#print(A)

for j in range(1, W):
    A[:,j] = np.minimum(A[:,j-1]+1, A[:,j])

#print(A)
for j in range(W-2, -1, -1):
    A[:,j] = np.minimum(A[:,j+1]+1, A[:,j])

#print(A)

for i in range(1, H):
    A[i,:] = np.minimum(A[i-1,:]+1, A[i,:])

#print(A)

for i in range(H-2, -1, -1):
     A[i,:] = np.minimum(A[i+1,:]+1, A[i,:])

#print(A)


ans = np.max(A)

#for i in range(H):
#    ans_list.append(max(A[i]))

print(ans)

Measured memory_bytes: 29076
n=int(input())
it=list(map(int,input().split()))
mod=1000000007
#dp=[[0,0,0] for i in range(n+1)]
#dp[-1]=[1,1,1]
#col=[0 for i in range(n)]
#fe=[]
cu=0
tot=1
ss=[0 for i in range(n+1)]
ss[-1]=3

for i in range(n):
    tot*=(ss[it[i]-1]-ss[it[i]])
    tot%=mod
    ss[it[i]]+=1
    
    
        
        
                
print(tot)
#print(tot%mod)
    


Measured memory_bytes: 56300
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

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

    int N = (int)S.size()+1;
    vector<int> T(N);
    for (int i=0; i<N; i++)
        if (i==0 || i==N-1 || S[i-1]=='>' && S[i]=='<')
        {
            for (int j=i-1; j>=0 && S[j]=='>'; j--)
                T[j] = max(T[j], i-j);
            for (int j=i+1; j<N && S[j-1]=='<'; j++)
                T[j] = max(T[j], j-i);
        }
    //for (int t: T)
    //    cout<<" "<<t;
    //cout<<endl;

    long long ans = 0;
    for (int t: T)
        ans += t;
    cout<<ans<<endl;
}


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

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout.precision(10);
	string s;
	cin >> s;
	int n = s.length();
	if (s[n - 1] == 's')
		cout << s + "es" << endl;
	else
		cout << s + "s" << endl;

	return 0;
}

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

int main(){
  
  int N;
  double T, A, H[1000];
  
  cin >> N;
  cin >> T >> A;
  for(int i = 0; i < N; i++){
    cin >> H[i];
  }
  
  int k,i;
  double m = 10000; 
  k = 0;
  
  
  for(i = 0; i < N; i++){
    if(abs(T - H[i]*0.006 - A) < m){
      m = abs(T - H[i]*0.006 - A);
      k = i;
    }
  }
  
  cout << k+1 << endl;
  return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
lst = [0] + list(map(int, input().split()))
dic = {1:0}
loc = 1
for i in range(1, k + 1):
  loc = lst[loc]
  if loc not in dic:
    dic[loc] = i
  else:
    span = i - dic[loc]
    initial = dic[loc]
    z = (k - initial) % span
    for j in range(z):
      loc = lst[loc]
    print(loc)
    exit()
print(loc)

Measured memory_bytes: 32376