akhauriyash/Code-Regression huggingface dataset:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
A = LI()

a = A[0]
b = A[1]
c = 0
if len(A) >= 3:
    for i in range(2,N):
        c ^= A[i]

INF = 10**12

from functools import lru_cache

@lru_cache(maxsize=None)
def f(s,t,u):
    '''
    (s-x) ^ (t+x) == u たる x の最小値を返す
    '''
    if s == 0:
        if t == u:
            return 0
        else:
            return INF
    else:
        if (s & 1) ^ (t & 1) == u & 1:
            return min(2*f(s//2,t//2,u//2),2*f((s-1)//2,(t+1)//2,u//2)+1)  # 1の位が0か1か
        else:
            return INF

ans = f(a,b,c)
if ans >= a:
    print(-1)
else:
    print(ans)

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long

using namespace std;

int main(){
	string s;
	cin >> s;
	ll max_len = 0;
	ll temp_len = 0;
	REP (i, s.size()){
		if (s[i]=='A' || s[i]=='T' ||s[i]=='G' || s[i]=='C'){
			temp_len += 1;
			if (temp_len > max_len) {max_len = temp_len;}
		} else {temp_len = 0;}
	}
	cout << max_len << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
 
using namespace std;
using namespace __gnu_pbds;
using lli = long long int;
 
template<typename key> using ordered_set = tree <key, null_type, less<key>, rb_tree_tag, tree_order_statistics_node_update>;
 
int main () {
   IO;
   lli a, b, k;
   cin >> a >> b >> k ;
   if(a >= k) {
	  cout << a - k << " " << b;
	  return 0;
   }
   else 
	  cout << 0 << " ";
   k-=a;
   cout << b-min(k, b);
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,k,n) for(int i = (k); i < (n); i++)
#define rep(i,n) repr(i,0,n)
#define ALL(a) begin(a),end(a)
const int INF = 114514810;
const int MOD = 1000000007;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A,B,C,K,M;
	cin >> A >> B >> C >> K;
	M=max({A,B,C});
	rep(i,K){
		M*=2;
	}
	M+=A+B+C-max({A,B,C});
	cout << M << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  double x1, y1, x2, y2, result;
  cout << fixed << setprecision(6);
  cin >> x1 >> y1 >> x2 >> y2;
  result = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
  cout << result << endl;
}


Measured memory_bytes: 3260
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int a,b;
  cin>>a>>b;
  cout<<a*b-a-b+1<<endl;
  return 0 ;
}


Measured memory_bytes: 256
// 遅い
// package main

// import (
// 	"fmt"
// 	"sort"
// 	"strings"
// )

// func main() {
// 	var n, l int
// 	fmt.Scan(&n, &l)

// 	s := make([]string, n)
// 	for i := 0; i < n; i++ {
// 		fmt.Scan(&s[i])
// 	}
// 	// fmt.Println(s)

// 	sort.Strings(s)
// 	fmt.Println(strings.Join(s, ""))
// }

package main

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

var sc = bufio.NewScanner(os.Stdin)

func receive() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	var n, l int
	fmt.Scan(&n, &l)

	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = receive()
	}
	sort.Strings(s)
	fmt.Println(strings.Join(s, ""))
}


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

const int MOD = (int)1e9+7;

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

	int ans;
	int mi=1e9;
	for(int i=1;i<=N;i++){
		if(abs(L+i-1)<=abs(mi))	mi=L+i-1;
		ans+=L+i-1;
	}
	cout << ans-mi << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
int n;
string s;
char t[d5];
void ok(char t[d5]){
    for(int i=1;i<n;i++){
        if((s[i]=='o'&&t[i]=='S')||(s[i]=='x'&&t[i]=='W')){
            t[i+1]=t[i-1];
        }
        else{
            if(t[i-1]=='S')t[i+1]='W';
            else t[i+1]='S';
        }
    }
    if(t[0]==t[n]){
        if((s[0]=='o'&&t[0]=='S')||(s[0]=='x'&&t[0]=='W')){
            if(t[1]==t[n-1]){
                for (int i = 0;i<n;i++){
                    cout << t[i];
                }
                cout << endl;
                exit(0);
            }
        }else{
            if(t[1]!=t[n-1]){
                for (int i = 0;i<n;i++){
                    cout << t[i];
                }
                cout << endl;
                exit(0);
            }
        }
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);    
    cin>>n>>s;
    t[0]='S';
    t[1]='S';
    ok(t);
    t[0] = 'S';
    t[1] = 'W';
    ok(t);
    t[0]='W';t[1]='S';
    ok(t);
    t[0] = 'W';
    t[1] = 'W';
    ok(t);
    cout << -1 << endl;
}


Measured memory_bytes: 720
import java.util.*;
import java.lang.*;

import static java.lang.StrictMath.abs;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int list[] = new int[n];
        int list2[] = new int[n];
        for(int i=0; i< n; i++){
            list[i]= sc.nextInt();
            list2[i] = list[i];
        }
        Arrays.sort(list);
        for(int k=0; k<n; k++){
        if(list2[k] != list[n-1]){
            System.out.println(list[n-1]);
        }else if(list2[k] == list[n-1]){
                System.out.println(list[n - 2]);
            }
        }
    }
}


Measured memory_bytes: 86828
// https://atcoder.jp/contests/abc171/tasks/abc171_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    if (s[0] >= 'a' && s[0] <= 'z') {
        cout << "a\n";
    } else {
        cout << "A\n";
    }

    return 0;
}


Measured memory_bytes: 3628
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    s, t = input().split()
    a, b = MI()
    u = input()

    if s == u:
        a -= 1
    else:
        b -= 1
    print(a, b)


main()


Measured memory_bytes: 64928
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long a,at,b,k;
  cin>>a>>b>>k;
  at = a;
  a = max(0L, a-k);
  if(a==0)
  {
    b = max(0L, b - (k-at));
  }
  
  cout<<a<<" "<<b;
  
}


Measured memory_bytes: 256
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// #include<deque>
// #include<multiset>
// #include<bitset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int n, m;
int x[112345];
int ch[112345];
int lost[112345];

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> m;
  vector<int> v;
  int now = n - m;
  for(int i = 0; i < m; i++) cin >> x[i], ch[x[i]] = 1, v.emplace_back(x[i]);

  lost[1] = now;
  for(int i = 2; i <= n; i++) {
    vector<int> nv;
    for(auto e : v) {
      if(e == n || ch[e+1]) {
      } else {
        ch[e+1] = 1;
        now--;
        nv.emplace_back(e + 1);
      }
    }
    v = nv;
    lost[i] = now;
  }

  int q;
  cin >> q;
  vector<int> ans(int(1e5) + 1, -1);
  int head = n;
  for(int i = 0; i <= int(1e5); i++) {
    while(head >= 1 && lost[head] <= i) head--;
    ans[i] = head == n ? -1 : head + 1;
  }

  for(int i = 0; i < q; i++) {
    int x;
    cin >> x;
    cout << ans[x] << "\n";
  }
  
  return 0;
}



Measured memory_bytes: 4912
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <set>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

using namespace std;

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

	if (isupper(s))
	{
		cout << "A" << endl;
	}
	else
	{
		cout << "a" << endl;
	}

	return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main() {
  string s; cin >> s;
  int size = s.size();
  int64_t sint = stoll(s);
  int64_t tenpros = 10;
  for(int i = 0; i < size - 4; i++) {
    tenpros *= 10;
  }
  vector<int> spartint(size - 2);
  for(int i = 0; i < size-2; i++) {
    spartint.at(i) = sint / tenpros;
    sint -= sint / (tenpros * 100) * (tenpros * 100);
    tenpros /= 10;
  }
  vector<int> differencebetween753(size - 2);
  for(int i = 0; i < size -2; i++) {
    if(spartint.at(i) <= 753) {
      differencebetween753.at(i) = 753 - spartint.at(i);
    }
    else {
      differencebetween753.at(i) = spartint.at(i) - 753;
    }
  }
  sort(differencebetween753.begin(), differencebetween753.end());
  cout << differencebetween753.at(0) << endl;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
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; }
const double INF = 1e9;

//input
ll t1,t2;
ll a1,a2;
ll b1,b2;

ll move_forward,move_back;


void input(){
    cin >> t1 >> t2;
    cin >> a1 >> a2;
    cin >> b1 >> b2;
}

void initial(){
    if(a1<b1){
        swap(a1,b1);
        swap(a2,b2);
    }
    move_forward = (a1-b1)*t1;
    move_back = (a2-b2)*t2;
}

bool inf_check(){
    if(move_forward+move_back==0)return true;
    return false;
}

bool non_check(){
    if(move_forward+move_back>0)return true;
    return false;
}

ll solve(){
    ll x = move_forward;
    ll dif = abs(move_forward+move_back);
    ll res = 0;
    res += x/dif*2+1;
    if(x%dif==0)res--;
    return res;
}

int main(){
    input();
    initial();
    if(inf_check()){
        cout << "infinity" << endl;
        return 0;
    }
    if(non_check()){
        cout << 0 << endl;
        return 0;
    }
    cout << solve() << endl;
    return 0;
}



Measured memory_bytes: 3580
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;

const int maxm=105;

int n,m,cntj,cur;
int a[maxm],b[maxm];

int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1; i<=m; i++)
	{
		scanf("%d",&a[i]);
		if (a[i]%2==1) cntj++;
	}
	if (m==1)
	{
		if (a[1]==1) 
		{
			printf("%d\n",a[1]);
			printf("1\n");
			printf("%d\n",a[1]);
		}
		else {
			printf("%d\n",a[1]);
			printf("2\n");
			printf("%d %d\n",a[1]-1,1);
		}
		return 0;
	}
	if (cntj>2) {
		printf("Impossible\n");
		return 0;
	}
	for (int i=2; i<=m; i++)
	{
		if (a[i]%2==1)
		{
			if (a[1]%2==1) swap(a[i],a[m]);
			else swap(a[1],a[i]);
		}
	}
	cur=0;
	if (a[1]>1) b[++cur]=a[1]-1;
	for (int i=2; i<m; i++)
		b[++cur]=a[i];
	b[++cur]=a[m]+1;
	printf("%d",a[1]);
	for (int i=2; i<=m; i++) printf(" %d",a[i]);
	printf("\n");
	printf("%d\n",cur);
	printf("%d",b[1]);
	for (int i=2; i<=cur; i++) printf(" %d",b[i]);
	printf("\n");
	
	return 0;
}

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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

int main(){
    map<int,int> ac;
    map<int,int> wa;
    int n,m;
    cin >> n >> m;

    rep(i,m){
        int p;
        string s;
        cin >> p >> s;

        if(s=="AC"){
            ac[p]++;
        }else{
            if(!ac.count(p))
                wa[p]++;
        }
    }

    int ans_wa(0);
    for(auto a : wa){
        if(ac.count(a.first))
            ans_wa += a.second;
    }

    cout << ac.size() << " " << ans_wa << endl;
 
    return 0;
}

Measured memory_bytes: 8292
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

red = P[:X]
green = Q[:Y]
ans = sum(red + green)
rg = sorted(red + green)

for i in range(min(C, X+Y)):
    if rg[i] < R[i]:
        ans += R[i] - rg[i]

print(ans)


Measured memory_bytes: 22560
package main

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

func f(k int) int {
	if k < 3 {
		return math.MaxInt32
	} else if k%3 == 0 {
		return 0
	}
	return 1
}

func main() {
	H := nextInt()
	W := nextInt()
	ans := min(f(H)*W, f(W)*H)
	for i := 1; i < W; i++ {
		a, b, c := H*i, (H/2)*(W-i), (H-H/2)*(W-i)
		ans = min(ans, max(a, max(b, c))-min(a, min(b, c)))
	}
	for i := 1; i < H; i++ {
		a, b, c := W*i, (W/2)*(H-i), (W-W/2)*(H-i)
		ans = min(ans, max(a, max(b, c))-min(a, min(b, c)))
	}
	fmt.Println(ans)
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


Measured memory_bytes: 640
import { readFileSync } from 'fs'
function main() {
  const input: string = readFileSync('/dev/stdin', 'utf8').trim()
  let state = 1
  let count = 0
  const [a, b] = input.split(' ').map(v => parseInt(v))
  while(state < b) {
    state += a - 1
    count++
  }

  console.log(count)
}
main()


Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <chrono>
#include <random>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

const int ms = 100100;

int to[ms][26];

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	std::string s, t;
	std::cin >> s >> t;
	int n = (int) s.size();
	for(int i = 0; i < 26; i++) {
		to[n][i] = n;
	}
	for(int i = n-1; i >= 0; i--) {
		for(int j = 0; j < 26; j++) {
			to[i][j] = to[i+1][j];
		}
		to[i][s[i]-'a'] = i;
	}
	int ans = 0;
	int st = 0;
	for(auto c : t) {
		if(to[0][c-'a'] == n) {
			ans = 0;
			st = -1;
			break;
		}
		if(to[st][c-'a'] == n) {
			st = 0;
			ans++;
		}
		st = to[st][c-'a'] + 1;
	}
	std::cout << (long long) ans * n + st << '\n';
}

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

int main() {
  long long n, x, tmp, ans = 0;
  cin >> n >> x;

  vector<long long> v(n + 1, 0);
  rep(i, 0, n) { cin >> v[i]; }

  rep(i, 0, n) {
    tmp = 0;
    if (v[i] + v[i + 1] >= x) {
      tmp = v[i] + v[i + 1] - x;
      v[i + 1] = v[i + 1] - tmp;
      ans += tmp;
    }
  }

  cout << ans << endl;
  getchar();
}


Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
int main(){
    vector<vector <int>> A(3,vector<int>(3));
    for (int i=0;i<3;i++){
        for (int j=0;j<3;j++){
            cin >> A[i][j];
        }
    }
    int n;
    cin >> n;
    int a;
    for (int i=0;i<n;i++){
        cin >> a;
        for (int j=0;j<3;j++){
            for (int k=0;k<3;k++){
                if (A[j][k] == a){
                    A[j][k] = 0;
                }
            }
        }
    }
    string ans = "No";
    for (int i = 0; i<3; i++){
        if (A[i][0] == 0 && A[i][1] == 0 && A[i][2] == 0){
            ans = "Yes";
        }
        if (A[0][i] == 0 && A[1][i] == 0 && A[2][i] == 0){
            ans = "Yes";
        }
    }

    if (A[0][0] == 0 && A[1][1] == 0 && A[2][2] == 0){
        ans = "Yes";
    }
    if (A[0][2] == 0 && A[1][1] == 0 && A[2][0] == 0){
        ans = "Yes";
    }
    
    cout << ans << endl;
    return 0;
}

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

int N, T, c[110];

int main() {
	int cnt = 0;
	int tempc, tempt;
	cin >> N >> T;
	for (int i = 0; i < N; i++) {
		cin >> tempc >> tempt;
		if (tempt <= T) {
			c[cnt] = tempc;
			cnt++;
		}
	}
	if (cnt == 0) {
		cout << "TLE" << endl;
		return 0;
	}
	sort(c, c + cnt);
	cout << c[0] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,x=0,count=0; cin >> n;
  vector<int> h(n);
  for(int i=0;i<n;i++) {
    cin >> h[i];
    x=max(x,h[i]);
    if(x==h[i]) {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>

using namespace std;

#define MAX 30
#define INF 10000000.0
struct S{
	int e,s,b;
};

struct S2{
	int d,c,to;
};

int main(){

	int n,m;
	int s,g;
	int x,y,d,c;
	int min;
	int size;
	double cost[MAX+1][MAX+1][MAX+1];
	S point,tmp;
	int pe,ps,pb,psj;
	S2 nod;
	vector<S2> ed[MAX+1];
	int edd,edc,edt;
	queue<S> no;

	while(1){

		cin>>n>>m;
		if(n==0&&m==0) break;

		for(int i=1;i<=n;i++){
			if(!ed[i].empty()) ed[i].clear();
		}

		for(int i=0;i<=30;i++){
			for(int j=0;j<=30;j++){
				for(int k=0;k<=30;k++){
					cost[i][j][k]=INF;
				}
			}
		}

		cin>>s>>g;
		point.e=s,point.s=0,point.b=0;
		cost[0][s][0]=0;

		for(int i=0;i<m;i++){
			cin>>x>>y>>d>>c;
			nod.c=c,nod.d=d,nod.to=y;;
			ed[x].push_back(nod);
			nod.to=x;
			ed[y].push_back(nod);
		}

		no.push(point);
		while(!no.empty()){
			point=no.front();
			no.pop();
			ps=point.s,pb=point.b,pe=point.e;
			size=ed[pe].size();
			for(int i=0;i<size;i++){
				edd=ed[pe][i].d,edc=ed[pe][i].c,edt=ed[pe][i].to;
				if(pb!=edt){
					for(int j=-1;j<=1;j++){
						psj=ps+j;
						if(psj>0&&psj<=edc){
							if(cost[psj][edt][pe]>cost[ps][pe][pb]+(double)edd/psj){
								cost[psj][edt][pe]=cost[ps][pe][pb]+(double)edd/psj;
								tmp.e=edt;
								tmp.s=psj;
								tmp.b=pe;
								no.push(tmp);
							}
						}
					}
				}
			}
		}
		min=0;
		for(int i=1;i<=30;i++){
			if(cost[1][g][i]<cost[1][g][min]) min=i;
		}
		if(min==0) printf("unreachable\n");
		else printf("%.5f\n",cost[1][g][min]);
	}

}

Measured memory_bytes: 1728
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
//const long long MOD = 1000000007LL;
const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
///////////////////////////////////////////////////////////////////////////////////////////////////

ll gcd(ll x, ll y) {
    if (x==0) return y;
    return gcd(y%x,x);
}

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

using mint = modint<MOD>;

struct ModCombination {
    vector<mint> Fac;
    vector<mint> Facinv;

    ModCombination(int x) {
        Fac.resize(x+1);
        Facinv.resize(x+1);
        Fac[0] = 1;
        for (long long i = 1; i <= x; i++) Fac[i] = Fac[i-1]*i;
        Facinv[x] = Fac[0]/Fac[x];
        for (long long i = x; i > 0; i--) Facinv[i-1] = Facinv[i]*i;
    }

    mint get(int n, int k) {
        if (k < 0 || k > n) return 0;
        return Fac[n]*Facinv[k]*Facinv[n-k];
    }
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll N,A,B,K; cin >> N >> A >> B >> K;
    ll c = gcd(A,B);
    if (K%c) {
        cout << 0 << endl;
        return 0;
    }
    A /= c; B /= c; K /= c;

    ModCombination MC(N);
    mint ans = 0;
    for (ll i = 0; i <= N; i++) {
        ll p = K - A*i;
        if (p < 0 || p%B != 0) continue;
        ll j = p/B;
        ans += MC.get(N,i)*MC.get(N,j);
    }

    cout << ans.a << endl;
}

Measured memory_bytes: 4992
function Main(input) {
  // start 0
  const values = input.split(' ').map(value => {
    return Number(value);
  });
  const v1 = values[0];
  const v2 = values[1];
  const MINUS_AMOUNT = 1;
  console.log(
    v1 === v2 ? v1 * 2 : v1 > v2 ? v1 * 2 - MINUS_AMOUNT : v2 * 2 - MINUS_AMOUNT
  );
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  if (s == "SUN") cout << 7 << endl;
  if (s == "MON") cout << 6 << endl;
  if (s == "TUE") cout << 5 << endl;
  if (s == "WED") cout << 4 << endl;
  if (s == "THU") cout << 3 << endl;
  if (s == "FRI") cout << 2 << endl;
  if (s == "SAT") cout << 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int n,d;
    cin>>n>>d;
    d*=2;
    d+=1;
    int ans=n/d;
    if(n%d!=0)ans+=1;
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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)*}
    };
}

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)*}
    };

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

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

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input!{
        n: i64,
        a: [i64; n],
    }
    let mut res = 10000000000000000;
    for i in -100..100+1 {
        let mut acc = 0;
        for &a_ in a.iter() {
            acc += (&a_ - i).pow(2)
        }
        if acc < res {
            res = acc
        }
    }
    println!("{}", res);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <fstream>
#include <iomanip>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  ll i = 0;
  for (auto x : v){os << " [" << i++ << "]" << x; if (i % 5 == 0) os << std::endl;}
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 5 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N, A, B;
  std::cin >> N >> A >> B;

  ll ans = std::min(A * N, B);
  print(ans);
  return 0;
}


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

int main() {
    string s;
    cin >> s;
  	int counter = 0;
  	if (s[0] == '1') ++counter;
  	if (s[1] == '1') ++counter;
  	if (s[2] == '1') ++counter;
    cout << counter << endl;
}

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

int main() {
    long x, k, d;
    cin >> x >> k >> d;
    long ans;
    x = abs(x);
    if (x == 0) {
        if (k % 2 == 0) ans = 0;
        if (k % 2 == 1) ans = d;
    } else if (x > 0) {
        // if (x - k * d >= 0) {
        if ((x - x % d) / d >= k) {
            x = x % d + ((x - x % d) / d - k) * d;
            ans = x;
        } else {
            k -= x / d;
            x %= d;
            if (k % 2 == 0) ans = x;
            if (k % 2 == 1) ans = abs(x-d);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxN = 1e5+7;
const int maxV = 90010;
//const int INF = 1e9+9;
//const ll INF = (1ll)<<60;
const int INF = 2e9+9;
const ull MOD = 16769023;
const ull MOD1 = 1125899839733759;
double w,h,x,y;
int main()
{
	scanf("%lf%lf%lf%lf",&w,&h,&x,&y);
	double a1 = w*h/2;
	int ans = 0;
	if(abs(x - w/2)<1e-10 && abs(y - h/2)<1e-10)
		ans = 1;
	printf("%f %d\n",a1,ans);
	return 0;
}


Measured memory_bytes: 256
/* ex9_1
   moka223711 */

#include <stdio.h>
#include <stdlib.h>
#define SIZE 15

typedef struct stack{ // 文字列を格納するスタック
    int size;
    int count; // スタックに格納されたデータ数を表す変数
    char data[SIZE]; // スタックにデータを格納するための配列
    char *top; // スタックの先頭アドレスを表すポインタ
}stack;

void initialize_stack(stack *stk); // スタックを初期化するための関数
void print_stack(stack *stk); // スタックに格納されているデータを出力するための関数
void push(stack *stk, char input); // スタックの先頭にデータを格納するための関数
char pop(stack *stk); // スタックの先頭からデータを取り出すための関数

int main(void){
    stack stk;
    char input; // 入力を受け取るための変数
    initialize_stack(&stk); // スタックを初期化
    while((input = getchar()) != EOF){ // 入力ファイルの終端に達するまで文字を受け取る
        if(input != 'B')push(&stk, input); // 入力された文字が'0'か'1'だったときはスタックの先頭に文字を格納する
        else if(stk.count > 0)pop(&stk); // 入力された文字が'B'でありスタックの要素が空でなければ先頭から文字を削除する
    }
    print_stack(&stk); // スタックに格納されているデータを出力
    return 0;
}

// スタックを初期化するための関数
void initialize_stack(stack *stk){
    stk->count = 0; // スタックに格納されているデータの総数は0
    stk->size = SIZE;
    stk->top = &(stk->data[SIZE]); // スタックの先頭アドレスをstk->topに格納する
}

void print_stack(stack *stk){
    int i;
    for(i = 1; i <= stk->count; i++) // 格納されているデータをすべて出力していく
        printf("%c", stk->data[stk->size-i]); // 古い要素から順番に出力していく
    printf("\n");// 最後に改行を出力して終了
}

// スタックの先頭にデータを格納するための関数
void push(stack *stk, char input){
    if(stk->count >= stk->size)
        exit(1);
    else{
        stk->top--; // スタックの先頭のアドレスを一つずらす
        *(stk->top) = input; // スタックの先頭に文字を格納する
        stk->count++; // スタックのデータの総数のカウントを一つ増やす
    }
}

char pop(stack *stk){
    char ch;
    if(stk->count <= 0)
        exit(1);
    else{
        ch = *(stk->top);
        stk->top++; // スタックの先頭アドレスを一つずらす
        stk->count--; // スタックのデータの総数のカウントを一つ減らす
        return ch;
    }
}


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

#define debug(s) cout << #s << " = " << s << endl
#define all(v) (v).begin(), (v).end()
#define KeepUnique(v) (v).erase( unique(all(v)), v.end() )
#define MEMSET(a, val) memset(a, val, sizeof (a))
#define PB push_back
#define endl '\n'
typedef long long ll;

inline int myrand(int l, int r) {
	int ret = rand(); ret <<= 15; ret ^= rand();
	if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
	return ret;
}

template <typename F, typename S>
ostream& operator << (ostream& os, const pair< F, S>& p) {
    return os<<"(" <<p.first<<", "<<p.second<<")"; }

typedef pair<int, int> ii;

template<typename T> using min_pq =
	std::priority_queue<T, vector<T>, greater<T> >;

//int dx[] = {-1, +0, +1, +0};
//int dy[] = {+0, +1, +0, -1};

const ll mod_s[] = {1000000000000000177LL, 1000000000000000523LL};
const ll base_s[] = {137, 153, 163};
ll base, mod, e[50];

int n;
string s, Left, Right;

ll mul(ll x, ll y) {
	// if(y == 0) return 0;
	// if(y & 1LL) return (2LL * mul(x, y >> 1) + x) % mod;
	// return (2LL * mul(x, y >> 1)) % mod;
	return ((__int128) x * y) % mod;
}

void genLeft(int pos, int r, int b, string R, string B, vector<ll> &vec) {
	if(pos == n) {
		ll X = 0, Y = 0;
		for(int i = 0; i < R.size(); i++) {
			X = (X + mul(R[i], e[i])) % mod;
		}
		for(int i = B.size() - 1, j = r; i >= 0; i--, j++) {
			Y = (Y + mul(B[i], e[j])) % mod;
		} ll res = (X - Y + mod) % mod;
		vec.push_back(res);
		return;
	}
	genLeft(pos + 1, r + 1, b, R + Left[pos], B, vec);
	genLeft(pos + 1, r, b + 1, R, B + Left[pos], vec);
}

void genRight(int pos, int r, int b, string R, string BB, vector<ll> &vec) {
	if(pos == n) {
		ll A = 0, B = 0;
		for(int i = 0, j = b; i < R.size(); i++, j++) {
			A = (A + mul(R[i], e[j])) % mod;
		}
		for(int i = BB.size() - 1, j = 0; i >= 0; i--, j++) {
			B = (B + mul(BB[i], e[j])) % mod;
		} ll res = (B - A + mod) % mod;
		vec.push_back(res);
		return;
	}
	genRight(pos + 1, r + 1, b, R + Right[pos], BB, vec);
	genRight(pos + 1, r, b + 1, R, BB + Right[pos], vec);
}


int32_t main () {
	// freopen("in", "r", stdin);
	srand(time(0));
	base = base_s[rand() % 3];
	mod = mod_s[rand() % 2];
	e[0] = 1; for(int i = 1; i < 50; i++) e[i] = mul(e[i - 1], base) % mod;

	cin >> n >> s;
	Left = s.substr(0, n);
	Right = s.substr(n, n);
	vector<ll> L, R;
	string SSS;
	genLeft(0, 0, 0, SSS, SSS, L);
	genRight(0, 0, 0, SSS, SSS, R);
	sort(all(R));
	ll ret = 0;
	for(ll b : L) {
		ret += upper_bound(all(R), b) - lower_bound(all(R), b);
	} cout << ret << endl;
}

Measured memory_bytes: 6516
use proconio::input;

fn main() {
  input! {
    a: i32, v: i32,
    b: i32, w: i32,
    t: i32
  }
  if v <= w {
    println!("NO");
    return;
  }
  let d: i32 = (a - b).abs();
  let x: i32 = v - w;
  if x.saturating_mul(t) >= d {
    println!("YES");
  } else {
    println!("NO");
  }
}


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

int main() {
  string S;
  cin >> S;
  int x = 0;
  int y = S.size() / 2;
  
  for(int i = 0; i < y; i++){
    if(S.at(i) == S.at(S.size() - 1 - i)){
      x++;
    }
  }
  if(S.size() % 4 == 3){
    for(int i = 0; i < y / 2; i++){
      if(S.at(i) == S.at(y - 1 - i)){
        x++;
      }
    }
    for(int i = 0; i < y / 2; i++){
      if(S.at(y + 1 + i) == S.at(S.size() - 1 - i)){
        x++;
      }
    }
    if(x == 2 * y - 1){
      cout << "Yes" << endl;
    }
    
    else{
      cout << "No" << endl;
    }
  }
  
  else if(S.size() % 4 == 1){
    for(int i = 0; i < y / 2; i++){
      if(S.at(i) == S.at(y - 1 - i)){
        x++;
      }
    }
    for(int i = 0; i < y / 2; i++){
      if(S.at(y + 1 + i) == S.at(S.size() - 1 - i)){
        x++;
      }
    }
    if(x == 2 * y){
      cout << "Yes" << endl;
    }
    
    else{
      cout << "No" << endl;
    }
    
    

  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    string N;cin>>N;
    if(N.at(0)==N.at(1) && N.at(1)==N.at(2) || N.at(2)==N.at(3) && N.at(1)==N.at(2)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


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

#define F first 
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 100010, M = 2 * N;

int n, h;
int a[N], b[N];

int main()
{
	scanf("%d%d", &n, &h);
	
	int maxa = 0, res = 0;
	for (int i = 1; i <= n; i ++ )
	{
		scanf("%d%d", &a[i], &b[i]);
		maxa = max(maxa, a[i]);
	}
	
	sort(b + 1, b + 1 + n);
	reverse(b + 1, b + 1 + n);
	
	for (int i = 1; i <= n; i ++ )
		if (b[i] > maxa)
		{
			h -= b[i];
			res ++ ;
			
			if (h <= 0)
			{
				printf("%d\n", res);
				return 0;
			}
		}
	
	if (h > 0) res += (h + maxa - 1) / maxa;
	
	printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int sum = 0;
        boolean isOdd = N % 2 == 0;
        for (int i = 1; i <= N / 2; i++) {
            if (isOdd && i == N / 2) {
            } else {
                sum++;
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 21716
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])

    ret = 'No'
    for i in range(1, 10):
        if n % i == 0 and n/i < 10:
            ret = 'Yes'

    return str(ret)


if __name__ == "__main__":
    print(solve(*[input() for _ in range(1)]))


Measured memory_bytes: 39856
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		
		long Max = A>B?A:B;
		long Min = A<B?A:B;
		
		for(long i=1; i<=Max; i++) {
			if(Min*i%Max==0) {
				System.out.println(Min*i);
				break;
			}
		}
	}
}

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

int main() {
    int N;
    string S;
    cin >> S;
    N = S.size();
    int ans = 0;
  	
    bool ok = 1;
    if(N==1){
        ok = 0;
    }

    if(N%2==0 && ok == 1){
    for(int i = 0;i<N/2;i++){
        if(S.at(i) != S.at(N-i-1)){
            ans++;
        }
    }
    }

    if(N%2==1 && ok == 1){
        for(int j=0;j<N/2;j++){
            if(S.at(j) != S.at(N-j-1)){
                ans++;
            }
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long int ll;
int main(){
	int N;
	int X[200000], forsort[200000];
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> X[i];
		forsort[i] = X[i];
	}
	sort(forsort, forsort + N);
	int m1 = forsort[N / 2 - 1], m2 = forsort[N / 2];
	for(int i = 0; i < N; i++){
		if(X[i] == m1) cout << m2 << endl;
		else if(X[i] == m2) cout << m1 << endl;
		else if(X[i] > m2) cout << m1 << endl;
		else cout << m2 << endl;
	}
	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int beki(int x, int n){
  int res = 1;
  while(n > 0){
    if(n & 1) res *= x;
    x = x * x;
    n >>= 1;
  }
  return res;
}

int main(){
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  int n = max(max(A, B), C);
  int result = A + B + C - n;
  result += n * beki(2, K);
  cout << result << endl;
}


Measured memory_bytes: 256
n, m = gets.split(' ').map(&:to_i)
cities = m.times.map {|i| gets.split(' ').map(&:to_i) }
grouped = cities.group_by {|city| city[0] }
grouped.each do |pref, cs|
  cs.sort! {|a, b| a[1] <=> b[1] }.each.with_index do |c, i|
    c << i + 1
  end
end

cities.each do |c|
  puts "%06d%06d" % [c[0], c[2]]
end


Measured memory_bytes: 37628
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int r = sc.nextInt();
        int s = sc.nextInt();
        int p = sc.nextInt();
        String t = sc.next();
        char[] c = t.toCharArray();
        int now = 0;
        long ans = 0;
        while(true){
            int tmp = t.indexOf("r",now);
            if(tmp == -1){
                break;
            }else if(tmp-k >= 0 && c[tmp-k] == 'r'){
                c[tmp] = 'd';
            }else{
                ans += p;
            }
            now = tmp+1;
        }
        now = 0;
        while(true){
            int tmp = t.indexOf("p",now);
            if(tmp == -1){
                break;
            }else if(tmp-k >= 0 && c[tmp-k] == 'p'){
                c[tmp] = 'd';
            }else{
                ans += s;
            }
            now = tmp+1;
        }
        now = 0;
        while(true){
            int tmp = t.indexOf("s",now);
            if(tmp == -1){
                break;
            }else if(tmp-k >= 0 && c[tmp-k] == 's'){
                c[tmp] = 'd';
            }else{
                ans += r;
            }
            now = tmp+1;
        }
        System.out.println(ans);
    }
}



Measured memory_bytes: 28912
def main():
    a, b = map(int, input().split())
    power_list = [0, 13, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

    if power_list[a] > power_list[b]:
        print("Alice")
    elif power_list[a] < power_list[b]:
        print("Bob")
    else:
        print("Draw")


if __name__ == "__main__":
    main()


Measured memory_bytes: 61924
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
char s[N];
set<int> st[30];

int main()
{
	int n, q;
	scanf("%d%s%d", &n, s, &q);	
	for (int i = 0; i < n; i++) {
		st[s[i] - 'a'].insert(i + 1);
	}
	while (q--) {
		int op;
		scanf("%d", &op);
		if (op == 1) {
			int pos; char ch;
			scanf("%d %c", &pos, &ch);
			for (int i = 0; i < 26; i++) {
				if (st[i].size() == 0) continue;
				if (st[i].find(pos) != st[i].end()) {
					st[i].erase(pos);
					break;
				}
			}
			st[ch - 'a'].insert(pos);
		} else {
			int l, r, ans = 0;
			scanf("%d%d", &l, &r);
			for (int i = 0; i < 26; i++) {
				if (st[i].size() == 0) continue;
				auto it = st[i].lower_bound(l);
				if (it != st[i].end() && *it <= r) ans++;
			}
			printf("%d\n", ans);
		}
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int next = 1;
  int count = 1;
  int check = 0;
  vector<int> vec(N);
  for (int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  for (int i = 0; i < N; i++){
    if (vec.at(next - 1) == 2){
      check = 1;
      break;
    }else{
      count++;
      next = vec.at(next - 1);
    }
  }
  if (check == 1){
    cout << count << endl; 
  }else{
   cout << -1 << endl; 
  }
}

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

int main(){
  int a,b;
  int apb,asb,acb;
  int max;
  cin >> a >> b;
  apb=a+b;
  asb=a-b;
  acb=a*b;

  max=apb;
  if(max<asb){
    max=asb;
  }
  if(max<acb){
    max=acb;
  }
  cout << max << endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    import sys 
    input = sys.stdin.readline
    from heapq import heappop,heappush
    from operator import itemgetter
    
    def prim():
        used = [True]*n
        edgelist = []
        for e in edge[0]:
            heappush(edgelist,e)
        used[0] = False
        res = 0
        while len(edgelist) != 0:
            short_edge = heappop(edgelist)
            if not used[short_edge[1]]:
                continue
            v = short_edge[1]
            used[v] = False
            for e in edge[v]:
                if used[e[1]]:
                    heappush(edgelist,e)
            res += short_edge[0]
        return res

    n = int(input())
    A = [list(map(int,input().split()))+[i] for i in range(n)]
    A.append([-10**12,-10**12,-1])
    A.append([10**12,10**12,-1])
    X = sorted(A)
    Y = sorted(A,key = itemgetter(1))
    edge = [[] for i in range(n)]
    for i in range(1,n+1):
        sx = X[i-1][0]
        sy = Y[i-1][1]
        mx = X[i][0]
        my = Y[i][1]
        lx = X[i+1][0]
        ly = Y[i+1][1]
        nsx = X[i-1][2]
        nsy = Y[i-1][2]
        nmx = X[i][2]
        nmy = Y[i][2]
        nlx = X[i+1][2]
        nly = Y[i+1][2]
        edge[nsx].append((mx-sx,nmx))
        edge[nmx].append((mx-sx,nsx))
        edge[nlx].append((lx-mx,nmx))
        edge[nmx].append((lx-mx,nlx))
        edge[nsy].append((my-sy,nmy))
        edge[nmy].append((my-sy,nsy))
        edge[nly].append((ly-my,nmy))
        edge[nmy].append((ly-my,nly))

    print(prim()) 

if __name__ == '__main__':
    main()

Measured memory_bytes: 121052
N = int(input())
C = input()
l = 0
r = N-1
ans = 0
while l < r:
    while l < r and C[l] == 'R':
        l += 1
    while l < r and C[r] == 'W':
        r -= 1
    if l >= r:
        break
    ans += 1
    l += 1
    r -= 1
print(ans)

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

long long dfs(vector< vector<int> > &G, vector<long long> &C, int v, int p, int M){
  long long ret = 1;
  for(size_t i = 0; i < G[v].size(); ++i){
    int v_ = G[v][i];
    if(v_ == p) continue;
    ret *= dfs(G,C,v_,v,M) + 1;
    ret %= M;
  }
  C[v] = ret;
  return ret;
}

void dfs2(vector< vector<int> > &G, vector<long long> &A, vector<long long> &C, int v, int p, long long t, int M){
  A[v] = ((t+1)*C[v])%M;
  int c = G[v].size();
  vector<long long> F(c+1), B(c+1);
  F[0] = 1;
  B[c] = 1;
  for(int i = 0; i < c; ++i){
    if(G[v][i] == p) F[i+1] = F[i];
    else F[i+1] = (F[i]*(C[G[v][i]]+1))%M;
    if(G[v][c-1-i] == p) B[c-1-i] = B[c-i];
    else B[c-1-i] = (B[c-i]*(C[G[v][c-1-i]]+1))%M;
  }
  for(size_t i = 0; i < G[v].size(); ++i){
    int v_ = G[v][i];
    if(v_ == p) continue;
    long long t_ = (((t+1)*F[i])%M*B[i+1])%M;
    dfs2(G,A,C,v_,v,t_,M);
  }
}

int main(){
  int N, M;
  cin >> N >> M;
  vector< vector<int> > G(N);
  for(int i = 0; i < N-1; ++i){
    int u, v;
    cin >> u >> v;
    --u,--v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  vector<long long> C(N,0), A(N,0);
  dfs(G,C,0,-1,M);
  dfs2(G,A,C,0,-1,0,M);
  for(int i = 0; i < N; ++i){
    cout << A[i] << endl;
  }
}


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

ll N;
string name(ll n){
    if (n==0) return "";
    n--;
    return name(n/26) + string(1,'a'+n%26);
}

int main(){
    cin >> N;
    cout << name(N) << endl;
}

Measured memory_bytes: 3612
N=int(input())
k=N//2
D=list(map(int,input().split()))
DD=D[:]+D[:]
DS=[0]*(2*N+1)
for i in range(0,2*N-2,2):
  DS[i+2]=DS[i]+DD[i]
  DS[i+3]=DS[i+1]+DD[i+1]
T=sum(D)
ret=[0]*N
for i in range(N):
  ret[i]=T-2*(DS[i+1+2*k]-DS[i+1])
print(*ret)


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

int main()
{
    int n;
    cin >> n;
    int a[n][11] = {};
    int p[n][11] = {};
    for(int i=0; i<n; i++){
        for(int j=0; j<10; j++){
            cin >> a[i][j];
        }
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<11; j++){
            cin >> p[i][j];
        }
    }
    
    int ans = -2e9;
    for(int bit=1; bit<1024; bit++){
        int sum = 0;
        for(int i=0; i<n; i++){
            int cnt = 0;
            for(int j=0; j<10; j++){
                if(bit >> j &1 && a[i][j]) cnt++;
            }
            sum += p[i][cnt];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
    int K;
    char str[32]={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};
    
  scanf("%d",&K);
    
    printf("%d\n",str[K-1]);
    
    return 0;
}


Measured memory_bytes: 128
d=int(input())
c=list(map(int,input().split()))
c_days=[0]*26
c_days_2=[0]*26
fir_ans=0
sec_ans=0
ans=[]
for i in range(d):
    s=list(map(int,input().split()))
    #最大満足度を選択
    c_low=[c[x]*(i+1-c_days[x]) for x in range(26)]
    c_max=[s[x]-c_low[x] for x in range(26)]
    n=c_max.index(max(c_max))
    c_days[n]=i+1
    los_1=[c[x]*(i+1-c_days[x]) for x in range(26)]
    fir_ans+=s[n]-sum(los_1)
    ans.append(n+1)


for i in ans:
    print(i)
#print(fir_ans)

Measured memory_bytes: 9252
let rec make_rev n l =
	match n with
	|0 -> l
	|_ -> Scanf.scanf " %d" (fun x -> make_rev (n-1) (x::l));;

let rec print_list l =
	match l with
	|[] -> print_string "\n"
	|x::xs -> print_int x;if xs <> [] then print_string " ";print_list xs;;

let n = Scanf.sscanf(read_line()) "%d" (fun x -> x)
in
print_list (make_rev n []);;



Measured memory_bytes: 2368
n=int(input())
s=[[]for i in range(2*10**5+1)]
d=[1]
s[int(input())].append(0)
for i in range(1,n):
    j=int(input())
    t=0
    s[j].append(i)
    if len(s[j])>1:
        if s[j][-2]!=s[j][-1]-1:
            t+=d[i-1]+d[s[j][-2]]
        else:
            t+=d[i-1]
    else: 
        t+=d[i-1]
    d.append(t)
print(d[-1]%(10**9+7))   

Measured memory_bytes: 944272