akhauriyash/Code-Regression huggingface dataset:
use std::io::Read;

fn dfs(p: Vec<i64>, size: Vec<i64>, n: usize, x: i64) -> i64 {
    if n == 0 {
        return if x == 0 { 0 } else { 1 };
    }
    let mut x = x;
    let mut result: i64 = 0;
    if x == 0 {
        return result;
    }
    x -= 1; // B
    if x == 0 {
        return result;
    }
    if x <= size[n - 1] {
        result += dfs(p, size, n - 1, x);
        return result;
    }
    x -= size[n - 1];
    result += p[n - 1];
    if x == 0 {
        return result;
    }
    x -= 1; // P
    result += 1;
    if x == 0 {
        return result;
    }

    if x <= size[n - 1] {
        result += dfs(p, size, n - 1, x);
        return result;
    }
    x -= size[n - 1];
    result += p[n - 1];

    return result;
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let x: i64 = iter.next().unwrap().parse().unwrap();

    let mut p: Vec<i64> = vec![0; n + 1];
    let mut size: Vec<i64> = vec![0; n + 1];

    p[0] = 1;
    size[0] = 1;
    for i in 1..n + 1 {
        p[i] = p[i - 1] * 2 + 1;
        size[i] = size[i - 1] * 2 + 3;
    }

    println!("{}", dfs(p, size, n, x));
}


Measured memory_bytes: 4352
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
#include <map>
#include <queue>
#include <string>
#define pb push_back
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define inf (int)(1e9)
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

int main(void){
  int n,x;
  cin>>n;
  int tmp=0;
  vector<int> p;
  p.pb(-1);
  for(int i=1;i<=n;i++){
    cin>>x;
    p.pb(x);
  }
  for(int i=1;i<=n;i++){
    if(i==p[i]){
      if(i+1==p[i+1]) i++;
      tmp++;
    }
  }
  cout<<tmp<<endl;
  return 0;
}


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

int main(){
    int n,  b, f, r, v;
    int count[4][3][10];

    for (int i = 0; i < 4; i++) {
        for(int j = 0; j < 3; j++) {
            for(int k = 0; k < 10; k++) {
                count[i][j][k] = 0;
            }
        }
    }

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> b >> f >> r >> v;
        count[b - 1][f - 1][r - 1] += v;
    }

    for (int i = 0; i < 4; i++) {
        for(int j = 0; j < 3; j++) {
            for(int k = 0; k < 10; k++) {
                cout << ' ' << count[i][j][k];
            }
            cout << endl;
        }
        if (i < 3) {
            cout << "####################" << endl;
        }
    }

}


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

using namespace std;

int solve(vector<uint16_t> osenbei, int n, int m) {       
  int max_count = 0;
  
  // n列の中から任意の数の行を裏返してできる組合せ（2^n）を全列挙する
  for (uint16_t mask = 0; mask < (1	<< n); mask++) {        
    int count = 0;
    
    for (uint16_t col: osenbei) {      
      uint16_t reversed = col ^ mask;
      bitset<16> b(reversed);
      
      // その時点で1、あるいは列を裏返せば1になる数の大きい方
      count += max(b.count(), n - b.count());
    }
    
    max_count = max(max_count, count); 
  }

  return max_count;
}

int main() {
  int N, M;
     
  while (true) {
    cin >> N >> M;
    if (N == 0 && M == 0) break;
    
    // 縦の並びをbit列に圧縮しながら読み込む
    vector<uint16_t> osenbei(M, 0);  

    for (int i = 0; i < N; i++) {
      for (int j = 0; j < M; j++) {
        uint16_t x;
        cin >> x;
        // 並び順が反転してしまっているが解答に影響はない
        osenbei.at(j) = osenbei.at(j) | (x << i);
      }
    }
    
    int count = solve(osenbei, N, M);
    cout << count << endl;
  } 
}



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

int main() {
    stack<int> S1;
    stack<pair<int, int> > S2;
    int total = 0;
    string S; cin >> S;

    for(int i = 0; i < S.size(); i++){
        if(S[i] == '/' && S1.size() > 0){
            int a = S1.top(); S1.pop();
            int b = i - a;
            total += b;
            int men = 0;
            while(!S2.empty() && S2.top().first > a){
                men += S2.top().second;
                S2.pop();
            }
            men += b;
            S2.push(make_pair(i, men));
        } else if(S[i] == '_'){
            continue;
        } else if(S[i] == '\\'){
            S1.push(i);
        }
    }

    cout << total << endl;

    if(S2.size() == 0){
        cout << 0 << endl;
    } else {
        cout << S2.size() << " ";
    }
    
    stack<int> ans; 
    while(!S2.empty()){
        int X = S2.top().second; S2.pop();
        ans.push(X);
    }

    while(!ans.empty()){
        cout << ans.top(); ans.pop();
        if(!ans.empty()){
            cout << " ";
        } else {
            cout << endl;
        }
    }
}


Measured memory_bytes: 3288
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int h[n];
    rep(i, n) cin >> h[i];
    vector<int> dp(n + 120, INF);
    dp[0] = 0;

    rep(i, n) {
        for (int j = 1; j <= k; ++j) {
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
        }
    }
    cout << dp[n - 1] << endl;
    return 0;
}



Measured memory_bytes: 1024
from itertools import permutations as pe
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    n=INT()
    ns=[]
    for i in range(1,n+1):
        ns.append(str(i))
    p=LISTS()
    q=LISTS()
    ct=0
    for v in pe(ns,n):
        v=list(v)
        #print(v,p,q)
        ct+=1
        if p==v:
            a=ct
        if q==v:
            b=ct

    print(abs(a-b))
if __name__=='__main__':
    do()

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

#include<cstdio>
#include<cstring>
#include<string>

string Upper(string s){
  string t=s;
  for (int i=0; i<s.size(); i++){
    t[i]=toupper(s[i]);
  }
  return t;
}

int main(){
  string W, T;
  int count=0;

  cin >> W;
  W=Upper(W);

  while(1){
    cin >> T;
    
    if (T=="END_OF_TEXT") break;
    T=Upper(T);
    if (T==W) count++;
  }

  cout << count << "\n";
  

  return 0;
}

Measured memory_bytes: 3132
<?php
$input = trim(fgets(STDIN));
$length = strlen($input);

for($i=1; $i <= $length; $i++){
    if ($length == 3){
        $num =  substr($input, 2);
    } elseif ($length == 2){
        $num =  substr($input, 1);
    } else {
        $num =  $input;
    }
}

if($num == 3 ){
    echo "bon";
} elseif($num == 0 || $num == 1 || $num == 6 || $num == 8){
    echo "pon";
}else{
    echo "hon";
}

?>

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

using namespace std;

int a[1000];

int main(){
	int n,d,x;
	scanf("%d%d%d",&n,&d,&x);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	x+=n;
	for(int i=2;i<=d;i++)
	{
		for(int j=1;j<=n;j++)
		{
			int t=i-1;
			if(t%a[j]==0)
			{
			x++;
			}
		}
	}
	cout<<x;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define pb push_back
#define iter std::vector<int>::iterator
 
int main() {
	ios_base ::sync_with_stdio(0);
	cin.tie(0);
 
	int n, x;
	cin >> n >> x;

	vector<int> vi (n);

	int res = 1, temp = 0;

	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		temp += a;

		if (temp <= x) res++;

	}

	cout << res;
	
 
	return 0;	
}

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

void solve(long long N, std::vector<long long> d){
    ll res = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
	res+= d[i]*d[j];
    }
  }
  cout << res << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> d(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&d[i]);
    }
    solve(N, std::move(d));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;

int n, ta = 0, mu = 0;
string s;
vector<char> rin = {};

signed main(){
	cin >> n >> s;
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < i; j++) {
			for (int k = 0; k < rin.size(); k++) {
				if (rin[k] == s[j]) {
					goto oi;
				}
			}
			for (int k = i; k < n; k++) {
				if (s[j] == s[k]) {
					ta++;
					rin.push_back(s[j]);
					goto oi;
				}
			}
		oi:;
		}
		mu = max(ta,mu);
		ta = 0;
		rin.clear();
	}
	cout << mu << endl;
	return 0;
}

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

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<int> a(n+1);
    for (size_t i = 0; i < n+1; i++) cin >> a[i];
    vector<int> b(n);
    for (size_t i = 0; i < n; i++) cin >> b[i];

    long long ans = 0;
    for (int i = 0; i < n; i++) {
        int c;
        c = min(a[i], b[i]);
        a[i] -= c;
        ans += c;

        c = min(a[i+1], b[i]-c);
        a[i+1] -= c;
        ans += c;
    }

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


Measured memory_bytes: 4044
from collections import deque

n, m = map(int, input().split())
eg = [[] for _ in range(n + 1)]

al = [0] * m
bl = [0] * m

for i in range(m):
    a, b = map(int, input().split())
    eg[a].append(b)
    eg[b].append(a)
    al[i], bl[i] = a, b

ans = 0
for i in range(m):
    x, y = al[i], bl[i]
    q = deque()
    q.append(1)
    seen = {1}
    while len(q) > 0:
        v = q.pop()
        for t in eg[v]:
            if t in seen:
                continue
            elif (v == x and t == y) or (v == y and t == x):
                continue
            q.append(t)
            seen.add(t)
    if len(seen) != n:
        ans += 1
print(ans)


Measured memory_bytes: 71260
#include<stdio.h>
int main()
{
	long int n, w, i, a, x, s=0, p=100010;
	scanf("%ld%ld", &n, &w);
	i=n;
	while (i--)
	{
		scanf("%ld", &a);
		s=s+a;
		if (a<p)
		{
			p=a;
		}
	}
	x=(w-s)/p;
	printf("%ld\n", x+n);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int A[3];
    rep(i,3) cin >> A[i];
    sort(A,A+3);
    cout << A[2]-A[0] << endl;



}


Measured memory_bytes: 256
n = int(input())
A = [int(i) for i in input().split()]
count = 0
for i in range(n):
    minj = i
    for j in range(i,n):
        if A[j] < A[minj]:
            minj = j
            
    A[i],A[minj] = A[minj],A[i]
    if minj != i:
        count += 1
print(" ".join(map(str,A)))
print(count)


Measured memory_bytes: 5604
#include "bits/stdc++.h"
#include <stdint.h>
 
#pragma optimize("O3")
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long double ld;
 
#define sync                    \
ios_base::sync_with_stdio(0); \
cin.tie(0);                   \
cout.tie(0)
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout)
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, b, a) for(ll i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define REPR(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll, ll>
#define MP make_pair
const ll MOD = 1e9+7;
const ll INF = 1e9 + 7;
const int base = 2e5+1;
const int MAX =1e5+2;
const double EPS = 1e-9;
const double PI = acos(-1.);
const int MAXN = 32000+5;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
ull k;
map<int, int> start_index;
int t[800000 + 47];
void build(vector<pair<int, int>> a, int v, int l, int r){
    if(l == r){
        t[v] = a[l].second;
    }else{
        int mid = (l+r)/2;
        build(a, v*2, l, mid);
        build(a, v*2 + 1, mid + 1, r);
        t[v] = max(t[v*2], t[v*2 + 1]);
    }
}
int get_max(int v, int tl, int tr, int l, int r){
        if(l > r){
            return -1;
        }
        if(l == tl && r == tr){
            return t[v];
        }
        int mid = (tl + tr)/2;
        return max(get_max(v*2, tl, mid, l, min(r, mid)), get_max(v*2+1, mid+1, tr, max(l, mid + 1 ), tr));
}

int main()
{   
    int n;
    cin >> n;
    int cnt = 0;
    for(int i = 0;i<n;i++){
        int a;
        cin >> a;
        if(a != i+1){
            cnt++;
        }
    }
    if(cnt > 2){
        cout<<"NO";
    }else{
        cout<<"YES";
    }
 
}

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

int main(){
	//入力機構
	std::string s,t;
	std::cin>>s>>t;

	//処理機構
	//回転して得られる文字列はsの文字列数だけしか存在しない。|s|<=100なので全探索でよい。これより早くするにはどうすればいいんだろう？
	bool ans=false;//一致を見つければtrueになる。
	const size_t size=s.size();
	if(size==t.size()){
		//この前提が成り立っていないとプログラムが落ちるのでやっておく。
		for(size_t i=0;i<size;i++){
			//回転した結果、文字列がs[i]から始まりs[i-1]で終わる。
			bool flag=true;//ひとまずtrueとする。不一致を認識すればfalseになる。
			for(size_t j=0;j<size;j++){
				const size_t index=(i+j)%size;
				if(s[index]!=t[j]){
					flag=false;
					break;
				}
			}
			if(flag){
				//flagがtrue、すなわち文字列が一致していればansはtrueとなり探索は打ち切れる
				ans=true;
				break;
			}
		}
	}

	//出力機構
	std::cout<<(ans?"Yes":"No")<<std::endl;
	
	return 0;
}

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

using namespace std;

int main()
{
  int n , k ,s;
  cin >> n >> k >> s;
  for(int i = 1; i<=k; i++)cout << s << " ";
  for(int i = k+1; i<=n; i++) if(s<=100)cout << (s+1) << " ";
  else cout << (s-1) << " ";
  return 0;
}


Measured memory_bytes: 1280
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = sum(b)
for i in range(n-1):
    if a[i+1] - a[i] == 1:
        ans += c[a[i]-1]
print(ans)

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

int main(){
    int k, ans; cin >> k;
    if(k%2==0 || k%5==0) ans = -1;
    else{
        ans = 1;
        int num = 7, col = 1;
        while(num%k != 0) {
            col *= 10; col %= k;
            num += 7*col; num %= k;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
#include<stdio.h>
#include<math.h>
long int GCD(long int a,long int b)
 {
    if(b>a)
        return GCD(b,a);
    if(b==0)
        return a;
    else
        return GCD(b,a%b);
 }
int main()
 {
     long int num1,num2;
     scanf("%ld %ld",&num1,&num2);
     printf("%ld\n",GCD(num1,num2));
     return 0;
 }




Measured memory_bytes: 2084
#include<stdio.h>
#include<stdlib.h>

void int_display(int *A,int n)
{
  int i;
  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i<n-1) printf(" ");
  }
  printf("\n");
}

void swap(int *A,int i,int j)
{
  int x;
  x=A[i];
  A[i]=A[j];
  A[j]=x;
}

int selection_sort(int *A,int n)
{
  int i,j,minj,s;
  s=0;
  for(i=0;i<n;i++){
    minj=i;
    for(j=i;j<n;j++){
      if(A[j]<A[minj]) minj=j;
    }
    swap(A,i,minj);
    if(i!=minj) s++;
  }
  return s;
}

int *int_read()
{
  int i,n;
  int *A;
  scanf("%d",&n);
  printf("%d\n",n);
  A=malloc(n*sizeof(int));
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  return A;
}

int main()
{
  int *A;
  int i,n,swap;
  scanf("%d",&n);
  A=malloc(n*sizeof(int));
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  swap=selection_sort(A,n);
  int_display(A,n);
  printf("%d\n",swap);
  return 0;
}

Measured memory_bytes: 1812
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    public static bool f = false, t = true;
    static void Main(string[] args)
    {
        int[] a = Read.ints();
        Console.WriteLine(a[0]+a[1]>=a[2]?"Yes":"No");
    }
    public static long gcd(long a, long b)
    {
        while (true)
        {
            if (a == 0) { return b; }
            if (b == 0) { return a; }
            if (a > b) { a -= b; }
            else { b -= a; }
        }
    }
    public static long lcm(long a, long b) { return a / gcd(a, b) * b; }
    public static bool IsPrime(int num)
    {
        if (num < 2) return false;
        else if (num == 2) return true;
        else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2)
        {
            if (num % i == 0)
            {
                // 素数ではない
                return false;
            }
        }

        // 素数である
        return true;
    }
}
public static class Read
{
    public static void outl(string n = "") { Console.WriteLine(n); return; }
    public static long Long() { return long.Parse(Console.ReadLine()); }
    public static long[] longs() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); }
    public static int Int() { return int.Parse(Console.ReadLine()); }
    public static int[] ints() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    public static string Str() { return Console.ReadLine(); }
    public static string[] Strs() { return Console.ReadLine().Split(); }
}

Measured memory_bytes: 13268
let k = Int(readLine()!)!
let ab = readLine()!.split(separator: " ").map { Int($0)! }
for i in ab[0]...ab[1] {
  if i.isMultiple(of: k) {
    print("OK")
    break
  } else if i == ab[1] {
    print("NG")
  }
}

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

int main() {
	string s, ans;
	cin >> s;
	if (s[0] == s[s.length() - 1]) {
		if ((s.length() - 2) % 2 == 0) {
			ans = "First";
		}
		else {
			ans = "Second";
		}
	}
	else {
		if ((s.length() - 2) % 2 == 1) {
			ans = "First";
		}
		else {
			ans = "Second";
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 512
use std::io::Read;
use std::str::SplitWhitespace;
use std::str::FromStr;

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

pub trait Parse<T> {
    fn parse(&mut self) -> T;
}

impl<'a, T> Parse<T> for SplitWhitespace<'a>
where
    T: FromStr,
{
    fn parse(&mut self) -> T {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let n = iter.parse();
    let k = iter.parse();
    let v: Vec<i64> = (0..n).map(|_| iter.parse()).collect();
    let min = std::cmp::min(n, k);
    let mut m = Vec::new();
    for take_count in 0..(min + 1) {
        for i in 0..(take_count + 1) {
            let a = i;
            let b = take_count - i;
            let mut vv = v.iter()
                .take(a)
                .chain(v.iter().rev().take(b))
                .collect::<Vec<_>>();
            vv.sort();
            m.push((vv.iter().fold(0, |st, &x| st + x), vv, k - take_count));
        }
    }
    for i in 0..m.len() {
        for _ in 0..m[i].2 {
            if let Some(&f) = m[i].1.first() {
                if *f < 0 {
                    m[i].0 -= *f;
                    m[i].1.remove(0);
                }
            }
        }
    }
    let max: i64 = m.into_iter().map(|(sum, _, _)| sum).max().unwrap();

    println!("{}", max);
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int X = sc.nextInt();

        int min = X - K + 1;
        for(int i = 0; i < 2 * K - 1; i++)
            System.out.println(min + i);
    }
}

Measured memory_bytes: 21844
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*

 */
int n,m;

int main(){
  cin>>n>>m;
  cout<<(n-1)*(m-1)<<endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt() - 1;
        }

        sc.close();

        int ans = -1;
        int count = 0;
        int pos = 0;
        for (int i = 0; i < 100000; i++) {
            pos = a[pos];
            count++;
            if (pos == 1) {
                ans = count;
                break;
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 50640
N,M = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(M)]

s1 = set()
sn = set()
for a,b in AB:
    if a==1:
        s1.add(b)
    if b==N:
        sn.add(a)

print('POSSIBLE' if s1&sn else 'IMPOSSIBLE')

Measured memory_bytes: 42872
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	cout << min(a*b,c) << endl;

	return 0;
}

Measured memory_bytes: 256
//#include "pch.h"
//#include "stdafx.h"
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <cstring>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define INF				2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define MIN(a, b)		((a) < (b) ? a : b)
#define MAX(a, b)		((a) > (b) ? a : b)
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)		/* 奇数 */
#define IsEven(x)		(!IsOdd((x)))					/* 偶数 */
#define ArrayLength(x)	(sizeof(x) / sizeof(x[0]))
#define DWORD_MAX		(0xFFFFFFFF)

typedef short SWORD;
typedef unsigned short WORD;
typedef long SDWORD;
typedef unsigned long DWORD;
typedef long long int QWORD;
#define N_MAX	(1000 * 100 + 1)
#define M_MAX	(1000 * 100 + 1)

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int N;
int dist[2][100000], id;
vector<int> g[100000];

void dfs(int nowTo, int nowFrom = -1)
{
	if (0 <= nowFrom) {
		dist[id][nowTo] = dist[id][nowFrom] + 1;
	}

	for (auto &nextTo : g[nowTo]) {
		// 来た道は省く
		if (nextTo != nowFrom) {
			dfs(nextTo, nowTo);
		}
	}
}

int main()
{
	cin >> N;

	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}

	id = 0;
	dfs(0);
	id = 1;
	dfs(N - 1);

	int ret = 0;
	for (int i = 0; i < N; i++) {
		if (dist[0][i] <= dist[1][i]) {
			++ret;
		}
	}
	
	if (ret >= (N + 2) / 2) {
		cout << "Fennec" << endl;
	} else {
		cout << "Snuke" << endl;
	}
}


Measured memory_bytes: 11136
#include <stdio.h>

int main()
{
	int n, Y, M, D;
	
	int year = 20*5 + 19*5, year3 = 20*10;
	int yearsum = 999*year + (int)(1000/3)*5;
	
	scanf("%d", &n);
	for( int i=0; i<n; i++ ){
		scanf("%d %d %d", &Y, &M, &D);
		Y--;M--;D--;
		printf( "%d\n", yearsum - ( Y*year + (int)(Y/3)*5 + M*19 + D + (((Y+1)%3)?(int)((M+1)/2):M) ) );
	}
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    int a,b,c,x,y; cin >> a >> b >> c >> x >> y;

    int ans = inf;
    for(int i = 0; i <= max(x,y); ++i) {
        chmin(ans, 2*c*i + a*max(0,x-i) + b*max(0,y-i));
    }

    cout << ans << '\n';

    // printf("ExcutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}

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

int main()
{
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  if(k<=a)cout << k << endl;
  else if(k>a && k<=a+b)cout << a << endl;
  else if(k>a+b && k<=a+b+c)cout << a-(k-a-b) << endl;
}

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

  const int MOD = 1000000007;
  const double PI = acos(-1); 

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

  //for
  #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }
int n;
ll k;
vector<int>a;
vector<int>f;


  //二分探索(最小値を出す問題は疑う)

bool C(ll x){
    ll res = 0;
    for(int i = 0; i < n; ++i){
		res += max(0ll, a[i]-x/f[i]);
    }
    return res <= k;
}

  ll binary_search(ll ok, ll ng){
    while(abs(ok - ng) > 1){
      ll mid = (ok + ng) / 2;
      if(C(mid)) ok = mid;
      else ng = mid;
    }
    return ok;
  }






int main() {
  
  cin >> n >> k;
  a = vector<int>(n);
  f = vector<int>(n);
  REP(i,n) cin >> a[i];
  REP(i,n) cin >> f[i];
  sort(a.begin(), a.end());
  sort(f.rbegin(), f.rend());
  ll l = -1, r = 1e12;
  cout << binary_search(r, l) << endl;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int yen = sc.nextInt();
        boolean flg = true;
        int i = 1;
        while(flg){
            
            int cg = 1000 * i - yen ;
            if(cg >=0){
                flg = false;
                System.out.println(cg);
            }
            i++;
        }
    }
}

Measured memory_bytes: 35784
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <sstream>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
 
using namespace std;
 
#define ll long long
#define pi pair<int,int>
#define pll pair<ll,ll>
#define pii pair<int,pi>
#define X first
#define Y second
#define pb push_back
#define ab(x) ((x)<0?(-(x)):(x))
#define xx(x) ((x)*(x))
#define mp make_pair
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vpi vector<pi>
#define vpll vector<pll>
#define ALL(x) (x).begin(),(x).end()
#define Max (1<<30)
#define LLMax (1ll<<60)
template<class T>string ToString(T t){stringstream s;s<<t;return s.str();}
template<class T>void ToOther(T&t,string a){stringstream s(a);s>>t;}
 

 
int a[3333][3333];

int xx[]={1,0,-1,0};
int yy[]={0,-1,0,1};

int wh1[1000005];
int wh2[1000005];
int d[3333][3333];
int ck[3333][3333];

bool pr[1000005];

int main(){
//	freopen("output.txt","w",stdout);

	pr[1]=1;
	for(int i=2;i<=1000000;i++)if(pr[i]==0){
		pr[i]=0;
		for(int j=i+i;j<=1000000;j+=i)pr[j]=1;
	}

	int x=1500;
	int y=1500;
	int di=0,now=1;

	a[y][x]=now;
	wh1[now]=y;
	wh2[now]=x;

	for(int L=1;;L++){
		
		for(int i=0;i<2;i++){
			for(int c=0;c<L;c++){
				now++;
				if(now>1000000)goto END;
				x+=xx[di];
				y+=yy[di];

				a[y][x]=now;
				wh1[now]=y;
				wh2[now]=x;

			}
			di=(di+1)%4;
		}
	} 
	END:;

	int n,st;
	int CC=0;
	while(cin>>n>>st,n){
		CC++;
		int mx=Max;
		int MX=-Max;
		int my=Max;
		int MY=-Max;

		for(int i=1;i<=n;i++){
			mx=min(mx,wh2[i]);
			MX=max(MX,wh2[i]);

			my=min(my,wh1[i]);
			MY=max(MY,wh1[i]);
		}

		int x=wh2[st];
		int y=wh1[st];

		ck[y][x]=CC;
		d[y][x]=!pr[st];

		int r1=0;
		int r2=0;

		if(!pr[st])r1=1,r2=st;

		for(int i=y+1;i<=MY;i++){
			for(int j=mx;j<=MX;j++)if(a[i][j]>=1 && a[i][j]<=n){
				for(int k=-1;k<=1;k++){
					int nx=j+k;

					if(ck[i-1][nx]!=CC)continue;
					if(a[i-1][nx]<=0 || a[i-1][nx]>n)continue;

					if(ck[i][j]==CC){
						d[i][j]=max(d[i][j],d[i-1][nx]+ !pr[ a[i][j] ]);
					}else d[i][j]=d[i-1][nx]+ !pr[ a[i][j] ];
					ck[i][j]=CC;

					if(!pr[ a[i][j] ]){
						if(r1<d[i][j]){
							r1=d[i][j];
							r2=a[i][j];
						}else if(r1==d[i][j])r2=max(r2,a[i][j]);
					}
				}
			}
		}

		cout<<r1<<" "<<r2<<endl;
	}
}

Measured memory_bytes: 57432
using System;
using static System.Console;
using System.Linq;

namespace AtCoder
{
  public class sora
  {
    static void Main(string[] args)
    {
      int N = int.Parse(ReadLine());
      long[] A = ReadLine().Split(' ').Select(long.Parse).ToArray();
      long check = 1;
      long ans = 1;
      for(int i = 0; i < N; i++){
        if(A[i] == 0){
          ans = 0;
          break;
        }
      }
      if(ans != 0){
        for(int i = 0; i < N; i++){
          ans *= A[i];
          if(ans / A[i] != check || 1000000000000000000 < ans){
            ans = -1;
            break;
          }
          check *= A[i];
        }
      }
      WriteLine(ans);
    }
  }
}

Measured memory_bytes: 41632
#include <iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>
using namespace std;

int main() {
	string s;
	cin >> s;
	if (s == "ABC")cout << "ARC" << endl;
	else cout << "ABC" << endl;
}


Measured memory_bytes: 3628
/*
 * 0306.cc: Symmetric Ternary Number
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_E = 11 + 1; // 3^11 = 177147 > 100000

/* typedef */

/* global variables */

int ds[MAX_E];

/* subroutines */

/* main */

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

  int n = 0;
  while (w > 0) {
    ds[n++] = w % 3;
    w /= 3;
  }
  //for (int i = 0; i < n; i++) printf("%d", ds[i]); putchar('\n');

  for (int i = 0; i < n; i++)
    if (ds[i] >= 2) {
      ds[i] -= 3;
      ds[i + 1]++;
    }
  while (ds[n]) n++;
  //for (int i = 0; i < n; i++) printf("%d", ds[i]); putchar('\n');

  for (int i = n - 1; i >= 0; i--)
    switch (ds[i]) {
    case -1: putchar('-'); break;
    case 0: putchar('0'); break;
    case 1: putchar('+'); break;
    }
  putchar('\n');
  
  return 0;
}

Measured memory_bytes: 1108
#include <fstream>
#include <iostream>

#include <cassert>
#include <climits>

#include <string>

#include <vector>
#include <map>
#include <deque>
#include <stack>

#include <algorithm>

#include <utility>

int main()
{
    int n, w;
    std::cin >> n >> w;
    assert(n >= 1 && n <= 100);
    assert(w >= 1 && w <= 10000);

    std::vector< std::pair<int, int> > items;
    items.push_back(std::make_pair(0, 0));
    for (int i = 1; i <= n; ++i)
    {
        int vi, wi;
        std::cin >> vi >> wi;
        assert(vi >= 1 && vi <= 1000);
        assert(wi >= 1 && wi <= 1000);

        items.push_back(std::make_pair(vi, wi));
    }

    std::vector< std::vector<int> > dp = std::vector< std::vector<int> >(n + 1, std::vector<int>(w + 1, 0));
    for (int i = 1; i < items.size(); ++i)
    {
        int value  = items[i].first;
        int weight = items[i].second;
        for (int j = 1; j <= w; ++j)
        {
            if ((j - weight) >= 0)
            {
                dp[i][j] = std::max(dp[i - 1][j], dp[i - 1][j - weight] + value);
            }
            else
            {
                dp[i][j] = dp[i - 1][j];
            }
            
        }
    }

    std::cout << dp[n][w] << std::endl;
}



Measured memory_bytes: 6864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 1001001001;
//stoi(s) : string→int stoll(s) :string→longlong
const double PI=3.14159265358979323846;

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

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    for(int i=0;i<100010;i++){
        dp[i] = INT_INF;
    }
    dp[0] = 0;

    for(int i=1;i<n;i++){
        chmin(dp[i],dp[i-1] + abs(h[i] - h[i-1]));
        if(i>1) chmin(dp[i],dp[i-2] + abs(h[i] - h[i-2]));
    }

    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main () {
	int N;
	cin >> N;
	int r[N];
	int l[N];
	int sum = 0;
	for (int i = 0; i < N; ++i)
	{
		cin >> r[i] >> l[i];
		sum += l[i] - r[i] + 1;
	}
	cout << sum << endl;
}

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

int main() {
  string C;
  int N , Y , i;
  cin >> N;
  for(i=0;i<N;i++){
    cin >> C;
    if(C == "Y"){
      Y = 1;
      break;
    }else{
      Y = 0;
    }
  }
  if(Y == 0){
    cout << "Three" << endl;
  }else{
    cout << "Four" << endl;
  }
  
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;

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

int x[10], y[10];
int a[] = {0, 1, 2, 3, 4, 5, 6, 7};
int main() {
    int n;
    cin >> n;
    rep(i, n) {
        cin >> x[i] >> y[i];
    }
    
    double ave = 0;
    do{
        double tmp = 0;
        rep(i, n-1) {
            int j = a[i];
            int k = a[i+1];
            tmp += sqrt((x[j] - x[k])*(x[j] - x[k]) + (y[j] - y[k]) * (y[j] - y[k]));
        }

        ave += tmp;
    } while(next_permutation(a, a+n));

    int d = 1;
    for(int i=1; i<=n; i++) {
        d *= i;
    }
   
    cout << setprecision(18);
    cout << ave/d << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

ll get_interval(vector<pair<ll, ll>> &v){
    int n = v.size();
    vector<ll> z(2*n);
    for (int i = 0; i < n; ++i) {
        z[2*i] = v[i].first; z[2*i+1] = v[i].second;
    }
    sort(z.begin(), z.end());
    z.erase(unique(z.begin(), z.end()), z.end());
    vector<ll> s(z.size()+1);
    auto f = [&](ll x){ return lower_bound(z.begin(),z.end(), x) - z.begin(); };
    for (int i = 0; i < n; ++i) {
        s[f(v[i].first)]++; s[f(v[i].second)]--;
    }
    ll ret = 0;
    for (int i = 0; i+1 < z.size(); ++i) {
        s[i+1] += s[i];
        if(s[i] > 0){
            ret += z[i+1]-z[i];
        }
    }
    return ret;
}

ll s(ll l, ll r){ // lからrまでの和
    if(l > r) return 0;
    return (r-l+1)*(2*l+(r-l))/2;
}

int main() {
    ll n, x, d;
    cin >> n >> x >> d;
    if(d == 0){
        if(x == 0) puts("1");
        else cout << n+1 << "\n";
        return 0;
    }
    if(d < 0) d *= -1, x *= -1;
    vector<tuple<int, ll, ll>> u;
    for (int i = 0; i <= n; ++i) {
        ll X = (n-2*(n-i))*x+s(1, n-1)*d;
        ll l = 0, r = 0;
        l = s(0, i-1), r = s(n-i, n-1);
        l += X/(2*d), r += X/(2*d); X %= (2*d);
        if(X < 0){
            X += 2*d; l--; r--;
        }
        u.emplace_back(X, l, r+1);
    }
    sort(u.begin(),u.end());
    ll ans = 0, cur = 0;
    int m = u.size();
    vector<pair<ll, ll>> p;
    while(cur < m){
        ll curr = cur;
        while(curr < m && get<0>(u[cur]) == get<0>(u[curr])) {
            int a; ll b, c;
            tie(a, b, c) = u[curr];
            curr++;
            p.emplace_back(b, c);
        }
        ans += get_interval(p);
        p.clear();
        cur = curr;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 16876
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut l_s = buf.split_whitespace()
        .map(|x| x.parse::<usize>().unwrap())
        .collect::<Vec<_>>();

    l_s.sort();

    let mut ans = 0usize;

    for a in 0..l_s.len() {
        for b in (a+1)..l_s.len() {
            let c_over = l_s[a] + l_s[b];

            let mut l = b;
            let mut r = l_s.len();
            let mut mid = (l + r) / 2;

            while r - l > 1 {
                if l_s[mid] < c_over {
                    l = mid;
                } else {
                    r = mid;
                }
                mid = (l + r) / 2;
            }

            ans += mid - b;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
N,K = map(int,input().split())
S,P,R = map(int,input().split())
point = {'s':S,'p':P,'r':R}
T = str(input())
max_point = 0
for i in range(K):
  while i < N:
    if i+K < N and T[i] == T[i+K]:
      max_point += point[T[i]]
      i = i+2*K
    else:
      max_point += point[T[i]]
      i = i+K
print(max_point)

Measured memory_bytes: 9332
#include<bits/stdc++.h>
using namespace std;
struct Dice{
    int lab[6];
    int sumple[6];
    void in(){
        for(int i=0;i<6;i++){
            cin >> lab[i];
        }
    }
    void sumplein(){
        for(int i=0;i<6;i++){
            cin >> sumple[i];
        }
    }
    void roll(char a){
        if(a=='S'){
            int stock;
            stock=lab[0];
            lab[0]=lab[4];
            lab[4]=lab[5];
            lab[5]=lab[1];
            lab[1]=stock;
        }
        if(a=='N'){
            int stock;
            stock=lab[0];
            lab[0]=lab[1];
            lab[1]=lab[5];
            lab[5]=lab[4];
            lab[4]=stock;
        }
        if(a=='W'){
            int stock;
            stock=lab[0];
            lab[0]=lab[2];
            lab[2]=lab[5];
            lab[5]=lab[3];
            lab[3]=stock;
        }
        if(a=='E'){
            int stock;
            stock=lab[0];
            lab[0]=lab[3];
            lab[3]=lab[5];
            lab[5]=lab[2];
            lab[2]=stock;
        }
        if(a=='R'){
            roll('N');roll('E');roll('S');
        }
        if(a=='L'){
            roll('N');roll('W');roll('S');
        }
    }
    
    int top(){
        return lab[0];
    }
    void right(int a,int b){
        int i;
        for(i=0;i<6;i++){
            if(lab[i]==a){
                break;
            }
        }
            
        if(i==1){
            roll('N');
        }
        if(i==2){
            roll('W');
        }
        if(i==3){
            roll('E');
        }
        if(i==4){
            roll('S');
        }
        if(i==5){
            roll('N');roll('N');
        }
            
        for(int j=1;j<5;j++){
            roll('L');
            
            if(lab[1]==b){
                break;
            }
        }
        return;
    }
    bool judge(){
        for(int i=0;i<2;i++){
            for(int j=0;j<4;j++){
                for(int k=0;k<4;k++){
                    if(lab[0]==sumple[0]&&lab[1]==sumple[1]&&lab[2]==sumple[2]&&lab[3]==sumple[3]&&lab[4]==sumple[4]&&lab[5]==sumple[5]){
                        return true;
                    }
                    roll('W');
                }
                roll('N');
            }
            roll('L');
        }
        return false;
    }
};

int main() {
    int n;
    cin >> n;
    Dice d[n];
    for(int i=0;i<n;i++){
        d[i].in();
    }
    bool q=true;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=0;k<2;k++){
                for(int l=0;l<4;l++){
                    for(int m=0;m<4;m++){
                        if(d[i].lab[0]==d[j].lab[0]&&d[i].lab[1]==d[j].lab[1]&&d[i].lab[2]==d[j].lab[2]&&d[i].lab[3]==d[j].lab[3]&&d[i].lab[4]==d[j].lab[4]&&d[i].lab[5]==d[j].lab[5]){
                            q=false;
                            break;
                        }
                        d[j].roll('W');
                    }
                d[j].roll('N');
                }
            d[j].roll('L');
            }
        }
    }
    if(q){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3104
<?php
define("MOD", 10**9+7);
fscanf(STDIN, "%d%d", $N, $M);

$rootM = $M**0.5;
for($j = 2; $j <= $rootM; $j++){
    if($M%$j == 0){
        @$map[$j]++;
        $M/=$j;
        $rootM = $M**0.5;
        $j--;
    }
}
if($M>1){
    @$map[$M]++;
}
$product = 1;
foreach($map as $prime => $count){
    $product *= nCm($count + $N - 1, $count);
    $product %= MOD;
}
printf("%d", $product);
 
//足し算
function addm($a, $b){
    return ($a + $b) % MOD;
}
//引き算
function subm($a, $b){
    return ($a + MOD - $b) % MOD;
}
//掛け算
function mulm($a, $b){
    return ($a * $b) % MOD;
}
//割り算
function divm($a, $b){
    return mulm($a, powerm($b, MOD - 2));
}
//累乗
function powerm($a, $b){
    if($b == 0)return 1;
    if($b & 1)return (powerm($a, $b>>1)**2 % MOD) * $a % MOD;
    return powerm($a, $b>>1)**2 % MOD;
}
//階乗
function factorialm($a){
    if($a == 0)return 1;
    return factorialm($a - 1) * $a % MOD;
}
//順列
function nPm($n, $m){
    if($m == 0)return 1;
    return nPm($n, $m - 1) * ($n - $m + 1) % MOD;
}
//組み合わせ
function nCm($n, $m){
    $m = min($m, $n-$m);
    return divm(nPm($n, $m), factorialm($m));
}

Measured memory_bytes: 4604
#include <stdio.h>
#include <string.h>
int main(void){
  char str[21];
  int n;
  scanf("%s\n",str);
  n=strlen(str); n--;
  while(n>=0){
    printf("%c",str[n]);
    n--;
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 524
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<algorithm>

struct P{ double x, y; };
typedef std::pair<P, double> Cir;
typedef std::pair<P, P> Ret;

Ret cross(Cir a, Cir b){
	Ret ret;
	ret.first.x = -100000;

	double x = a.first.x - b.first.x;
	double y = a.first.y - b.first.y;
	double l = std::sqrt(x*x + y*y);

	if (l > a.second + b.second)return ret;

	double c = std::atan2(b.first.y - a.first.y, b.first.x - a.first.x);
	//double alpha = std::acos((l*l + a.second*a.second - b.second*b.second) / (2 * l*a.second));
	double alpha = std::acos(l / 2);

	P r1, r2;
	r1.x = a.first.x + std::cos(c + alpha), r1.y = a.first.y + std::sin(c + alpha);
	r2.x = a.first.x + std::cos(c - alpha), r2.y = a.first.y + std::sin(c - alpha);

	ret.first = r1;
	ret.second = r2;

	return ret;
}

const double EPS = 1e-15;

bool check(Cir cir, P p){
	double l = (cir.first.x - p.x)*(cir.first.x - p.x) + (cir.first.y - p.y)*(cir.first.y - p.y);
	l = std::sqrt(l);

	return (l <= cir.second + EPS);
}

int main(){
	int n;

	while (std::cin >> n, n){
		int res = 1;
		Cir data[1001];

		std::vector<P>search;
		for (int i = 0; i < n; i++){
			double x, y, r;
			scanf("%lf,%lf", &data[i].first.x, &data[i].first.y);
			data[i].second = 1.0;
		}

		for (int i = 0; i < n; i++){
			for (int j = i + 1; j < n; j++){
				Ret ret = cross(data[i], data[j]);
				if (ret.first.x != -100000)search.push_back(ret.first), search.push_back(ret.second);
			}
		}

		for (int i = 0; i < search.size(); i++){
			int cnt = 0;
			for (int j = 0; j < n; j++){
				cnt += check(data[j], search[i]);
			}
			res = std::max(res, cnt);
		}

		std::cout << res << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1448
use std::collections::BinaryHeap;
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let m: u64 = read();
    let mut heap = BinaryHeap::new();

    for _ in 0..n {
        heap.push(read::<u64>());
    }

    for _ in 0..m {
        let peak = heap.pop().unwrap();
        heap.push(peak / 2);
    }

    let sum: u64 = heap.iter().fold(0, |acc, &x| acc + x);
    println!("{}", sum);
}


Measured memory_bytes: 2920