akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template<class T> bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

int main() {
    long long x;
    cin >> x;
    
    long long now = 100;
    
    int ans = 0;
    while (now < x) {
        now *= (1.01);
        ans++;
    }
    
    cout << ans << '\n';
    
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    long long int N,X;
    cin>>N>>X;
    long long int a=X,b=N-X,ans=N;
    while(true){
        //if(a>b)swap(a,b);
        if(a==0){
            ans-=b;
            break;
        }
        long long int m=b/a;
        ans+=2*m*a;
        long long int a_next,b_next;
        a_next=b-m*a;
        b_next=a;
        a=a_next;
        b=b_next;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <map>
using namespace std;


#define prec(i) cout << fixed << setprecision(i)

const long long int MOD = 1000000007;

long long int fact(long long int k) {
	long long int sum = 1;
	for (long long int i = 2; i <= k; i++)
		sum *= i;

	return sum;
}

int ctoi(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else
		return -1;
}

long long int pow_mod(int a, int b) {
	long long int  ans = 1;
	for (int i = 0; i < b; i++)
		ans = (ans * a) % MOD;

	return ans;
}


int main()
{
	long long int a, b, cnt = 0;

	cin >> a >> b;

	if (a == 1 || b == 1) {
		if (a == 2 || b == 2)
			cout << 3 << endl;
		else
			cout << 2 << endl;
	}
	else
		cout << 1 << endl;




	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = [0]*(N+1)
ans = []
 
for n in range(N):
  i = N-n
  BB = B[::i]
  if (sum(BB))%2 != A[i-1]:
    B[i] = 1
    ans.append(str(i))
  
print(len(ans))
print(' '.join(ans))

Measured memory_bytes: 18764
#include <bits/stdc++.h>
#define ll long long int
#define pr pair<ll, ll>
#define tp tuple<ll, ll, ll>
using namespace std;
long long int mod = 1e9 + 7;

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

    char s[20], t[20];
    cin >> s >> t;
    ll sn = strlen(s), tn = strlen(t);
    ll flag = 0;
    if (tn != sn + 1)
        flag = 1;
    for (ll i = 0; i < sn; i++)
    {
        if (s[i] != t[i])
            flag = 1;
    }
    if (flag)
        cout << "No\n";
    else
        cout << "Yes\n";
    return 0;
}

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

int main(){

  int a,b;
  cin >> a >> b;
  if(a%3==0||b%3==0||(a+b)%3==0){
    cout << "Possible" << endl;
  }else{
    cout <<"Impossible"	<< endl;
  }


}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let n: usize = read();
    let mut l: Vec<u64> = (0..n).map(|_| read()).collect();
    l.sort();

    let sum = (&l).into_iter().take(n - 1).fold(0, |a, &b| a + b);
    if l[n - 1] < sum {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#!/usr/bin/perl

my ($n,$m) = map { $_ - 0 } split(/\s+/,scalar(<STDIN>));

my @p = ();
$#p = $n - 1;

for(my $i=0;$i<$m;$i++){
  my ($s,$c) = map { $_ - 0 } split(/\s+/,scalar(<STDIN>));
  $s --;
  if( ($p[$s] . '') ne '' ){
    if( ($p[$s] . '') ne ( $c . '' ) ){
      print "-1\n"; exit(0);
    }
  } else {
    $p[$s] = $c;
  }
}

my $d = '';
for(my $i=0;$i<$n;$i++){
  if( $p[$i] . '' ne '' ){
    if( $n>1 and $i == 0 and ($p[0] . '' eq '0' ) ){
      print "-1\n";exit(0);
    }
    $d .= $p[$i];
  } else {
    if( $n>1 and $i == 0 ){
      $d .= '1';
    } else {
      $d .= '0';
    }
  }
}
print "$d\n";






Measured memory_bytes: 4772
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin >> N >> K;
  
  string S;
  
  cin >> S;
  
  int ans = 0;
  
  
  
  
  
  for(int i=1;i<N;i++){
    if(S.at(i) == 'L'){
      if(S.at(i-1) == 'L'){
        ans++;
      }
    }
    else{
      if(S.at(i-1) == 'R'){
        ans++;
      }
    }
  }
  

  
  
  if(ans+2*K < N){
    ans = ans+2*K;
  }
  else{
    ans = N-1;
  }
  
  
  
  cout << ans<< endl;
}

Measured memory_bytes: 512
import java.util.*;
 
class Main {
        public static void main(String args[]) {
                int[] ans = new int[26];
                try (Scanner sc = new Scanner(System.in)) {
                        while (sc.hasNextLine()) {
                                String S = sc.nextLine();
                                S = S.toLowerCase();
                                for (int i = 0; i < S.length(); i++) {
                                        if (0 <= S.charAt(i) - 'a' && S.charAt(i) - 'a' < 26) {
                                                ans[S.charAt(i) - 'a']++;
                                        }
                                }
                        }
                }
                for (int i = 0; i < 26; i++) {
                        System.out.printf("%c : %d\n", i + 'a', ans[i]);
                }
        }
}


Measured memory_bytes: 26372
from fractions import gcd
from functools import reduce


def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    MOD = 10 ** 9 + 7
    com = lcm_list(A) % MOD
    ans = 0
    for a in A:
        ans += com * pow(a, MOD - 2, MOD)
    ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 67432
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int n;
vector<int> v[200010];
int mod = 1e9+7;
int fac[200010];

void factorial()
{
    fac[0] = 1;
    for(int i=1; i<200001; i++)
    {
        fac[i] = (i * fac[i-1]) % mod;
    }
}

int power(int a, int b)
{
    a %= mod;
    int res = 1;
    while(b>0)
    {
        if(b&1)
            res = (res * a)%mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}

int subtree[200010], dp[200010], dp2[200010];
void solve(int node, int parent)
{
    subtree[node] = 1;
    dp[node] = 1;
    for(auto child : v[node])
    {
        if(child != parent)
        {
            solve(child, node);
            subtree[node] += subtree[child];
            dp[node] = (dp[node] * dp[child]) % mod;
            dp[node] = (dp[node] * power(fac[subtree[child]], mod-2)) % mod;
        }
    }
    dp[node] = (dp[node] * fac[subtree[node] - 1]) % mod;
}

void solve2(int node, int parent)
{
    for(auto child : v[node])
    {
        if(child != parent)
        {
            int cur = dp[node];

            // Removing contribution of child
            cur = (cur * fac[subtree[child]]) % mod;
            cur = (cur * power(dp[child], mod-2)) % mod;
            cur = (cur * power(fac[n-1], mod-2)) % mod;
            cur = (cur * fac[n - subtree[child] - 1]) % mod;

            // Update child
            dp[child] = (dp[child] * power(fac[subtree[child] - 1], mod-2)) % mod;

            // Adding contribution of node to child
            dp[child] = (dp[child] * cur) % mod;
            dp[child] = (dp[child] * power(fac[n - subtree[child]], mod-2)) % mod;
            dp[child] = (dp[child] * fac[n-1]) % mod;

            solve2(child, node);
        }
    }
}

int32_t main()
{
    cin >> n;
    for(int i=1; i<n; i++)
    {
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    factorial();

    solve(1, 0);

    solve2(1, 0);

    for(int i=1; i<=n; i++)
    {
        cout << dp[i] << endl;
    }
    return 0;
}


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

using namespace std;
mt19937_64 rng(58);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n;
    string s;
    cin >> n >> s;
    if (s.size() > n) {
        cout << s.substr(0, n) << "..." << endl;
    } else {
        cout << s << endl;
    }

}

Measured memory_bytes: 3640
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        long[] counts = Enumerable.Repeat(1L, n + 1).ToArray();
        long[] powCount = Enumerable.Repeat(0L, n + 1).ToArray();
        foreach (var prime in Primes(n))
        {
            long curPow = prime;
            for (long i = curPow; i < counts.Length; i += curPow)
                powCount[i] = 1;
            curPow *= prime;
            while (curPow < powCount.Length)
            {
                for (long i = curPow; i < counts.Length; i += curPow)
                {
                    powCount[i]++;
                }
                curPow *= prime;
            }

            for (int i = prime; i < counts.Length; i += prime)
                counts[i] *= powCount[i] + 1;
        }
        long res = 0;
        for (int i = 0; i < counts.Length; i++)
        {
            res += counts[i] * i;
        }
        Console.WriteLine(res);
    }


    public static IEnumerable<int> Primes(int n)
    {
        if (n < 2) yield break;
        yield return 2;
        ulong[] bitArray = new ulong[(n + 1) / 2 / 64 + 1];

        int[] smallPrimes = { 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61 };
        foreach (var prime in smallPrimes)
        {
            if (n < prime) yield break;
            yield return prime;

            ulong[] mask = new ulong[prime];
            for (int j = (prime - 3) >> 1; j < (prime << 6); j += prime)
                mask[j >> 6] |= 1UL << j;

            int maskInd = 0;
            for (int i = 0; i < bitArray.Length; i++)
            {
                bitArray[i] |= mask[maskInd];
                if (++maskInd >= prime) maskInd = 0;
            }
        }

        int[] deBruijnIndex = { 0, 1, 59, 2, 60, 40, 54, 3, 61, 32, 49, 41, 55, 19, 35, 4, 62, 52, 30, 33, 50, 12, 14, 42, 56, 16, 27, 20, 36, 23, 44, 5, 63, 58, 39, 53, 31, 48, 18, 34, 51, 29, 11, 13, 15, 26, 22, 43, 57, 38, 47, 17, 28, 10, 25, 21, 37, 46, 9, 24, 45, 8, 7, 6 };
        int maxInd = n / 2;
        for (int i = 0; i < bitArray.Length; i++)
        {
            for (ulong bit = ~bitArray[i]; bit != 0; bit &= bit - 1)
            {
                int index = i << 6 | deBruijnIndex[((bit & (~bit + 1)) * 0x03F566ED27179461UL) >> 58];
                int prime = (index << 1) + 3;
                if (n < prime) yield break;
                yield return prime;
                for (int ind = index; ind <= maxInd; ind += prime)
                    bitArray[ind >> 6] |= 1UL << ind;
            }
        }
    }
}

Measured memory_bytes: 185624
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int x;
    cin >> x;
    int ans = 0;
    ans += x / 500 * 1000;
    x %= 500;
    ans += (x / 5) * 5;

    cout << ans << endl;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,a[N];
unordered_map<int,int>vis;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]),vis[a[i]]++;
    sort(a+1,a+1+n);
    int ans=0;
    for(int i=n;i>=1;i--)
    {
        if(!vis[a[i]]) continue;
        vis[a[i]]--;
        for(int j=1<<30;j&&j>=a[i];j>>=1)
        {
            if(vis[j-a[i]])
            {
                vis[j-a[i]]--;
                ans++;
                break;
            }
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 29684
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        n:usize,m:usize,
        mut s:Chars,
    }
    s.reverse();
    let mut left = 0;
    let mut anss = vec![];
    let mut ng = false;
    while left < n {
        let mut right = left + m;
        let mut found = false;
        for ms in (1..=m).rev() {
            let target = left + ms;
            if target <= n && s[target] == '0' {
                left = target;
                anss.push(ms);
                found = true;
                break;
            }
        }
        if !found {
            ng = true;
            break;
        }
    }
    if ng {
        println!("{}", -1);
    } else {
        for &x in anss.iter().rev() {
            println!("{}", x);
        }
    }
}


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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using pint = pair<int, int>; 
using pll  = pair<ll, ll>;
using vint = vector<int>; 
using vll  = vector<ll>;
using vstr = vector<string>;

// 超難しい、浮動小数点の精度
// 小数点2桁までとの制約があるのでまずBをstringで受けるのがポイント
ll A;
string B;

int main(){
    cin >> A >> B;
    rep(i, B.size()){
        if(B[i]=='.'){
            B.erase(B.begin() + i);
            break;
        }
    }


    //int b = atoi(B.c_str());
    int b  = stoi(B);
    
    cout << A*b/100 <<endl;

}

Measured memory_bytes: 3636
from itertools import permutations


def main(n, p, q):
    t = []

    for i, d in enumerate(permutations([_i for _i in range(1, n + 1)])):
        if d == p:
            t.insert(0, i)
        if d == q:
            t.insert(1, i)
        if len(t) == 2:
            break

    print(abs(t[1] - t[0]))


if __name__ == "__main__":
    n = int(input())
    p = tuple(map(int, input().split(" ")))
    q = tuple(map(int, input().split(" ")))

    main(n, p, q)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iostream>
#include <functional>
#include <vector>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define rep1(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define per1(i,a,n) for (int i=a;i>n;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define pi 3.14159265358979323846264338327950288419716939937510
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res, t;res=1;t=a%c;while(b){if(b & 1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
// head
double n;
int main()
{
    //IOS;
    cin>>n;
    //printf("%.12f\n",(n/3)*(n/3)*(n/3));
    printf("%.12f",(n*n*n)/27.0);
    return 0;
}
/*

*/


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

template<class T,class F>
struct segment_tree{
  std::vector<T> data;
  int n;F f;T identity;
  segment_tree(){}
  segment_tree(int sz,T ide,F _f):f(_f),identity(ide){
    n=1;while(n<sz)n<<=1;
    data.resize(2*n,identity);
  }
  segment_tree(std::vector<T> const& v,T ide,F _f):f(_f),identity(ide){
    build(v);
  }
  void build(std::vector<T> const& v){
    int sz=v.size();
    n=1;while(n<sz)n<<=1;
    data.resize(2*n,identity);
    for(int i=0;i<sz;++i)data[i+n]=v[i];
    for(int i=n-1;i>0;--i)data[i]=f(data[i<<1|0],data[i<<1|1]);
  }
  void set(int i,T x){
    i+=n;data[i]=x;
    while(i,i>>=1)data[i]=f(data[i<<1|0],data[i<<1|1]);
  }
  T fold(int l,int r)const{
    l+=n,r+=n;
    T x=identity;
    while(l<r){
      if(l&1)x=f(x,data[l++]);
      if(r&1)x=f(x,data[--r]);
      l>>=1,r>>=1;
    }
    return x;
  }
  T operator[](int i)const{return data[i+n];}
};
template<class T,class F>
auto make_segtree(int n,T ide,F f){
  return segment_tree<T,F>(n,ide,f);
}
template<class T,class F>
auto make_segtree(std::vector<T>const& v,T ide,F f){
  return segment_tree<T,F>(v,ide,f);
}

signed main(){

  int n;
  cin>>n;
  vector<ll> a(n);
  cin>>a;

  auto seg = make_segtree<ll>(a,0,[](auto a,auto b){return a^b;});

  rep(i,n){
    cout<<(seg.fold(0,i)^seg.fold(i+1,n))<<" ";
  }
  cout<<endl;


}

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

int main(){
  long long S;
  cin >> S;
  long c, d, e, f;
  c = sqrt(S);
  f = c;
  int check = 1;
  while(c * f < S){
    if(check > 0){
      c++;
      check *= -1;
    }else{
      f++;
      check *= -1;
    }
  }
  e = c * f - S;
  cout << 0 << " " << 0 << " " << c << " " << 1 << " " << e << " " << f << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
 public static void main (String[] args){

	 	Scanner sc = new Scanner(System.in);
	 	
	 	// 整数の入力
	 	String str = sc.nextLine();
	 	String out = "NO";
	 	for (int i =0; i< 8; i++){
	 		String strTry = str.substring(0,i)+str.substring(i+str.length()-7);
	 		if (strTry.equals("keyence")){
	 			out = "YES";
	 			break;
	 		}
	 	}



	 	// 出力
	 	
	 	System.out.println(out);

	 
	 
 }
	
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    int K, X;
    cin >> K >> X;

    for(int i = X-K+1; i <= X+K-1; i++){
        cout << i << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
n=input()
N=int(n)

X=[int(_) for _ in input().split(" ")]

total=0
p=0
ans=0

for i in range(len(X)):
  total += X[i]

p=round(total/N)

for i in range(len(X)):
  ans += (X[i]-p)*(X[i]-p)


print(ans)



Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;

const int N=200005;

int n;
int dp[N],nxt[N][27],f[N],c[N];
char s[N];

void init(){
	int i,j;
	for (j=0;j<26;j++) nxt[n+1][j]=n+1;
	for (i=n;i>=1;i--){
		for (j=0;j<26;j++) nxt[i][j]=nxt[i+1][j];
		nxt[i][s[i]-'a']=i;
	} 
}

int main(){
	int i,j;
	scanf("%s",s+1); n=strlen(s+1);
	init();
	dp[n+1]=1;
	for (i=n;i>=1;i--){
		dp[i]=-1;
		for (j=0;j<26;j++)
			if (dp[i]==-1||dp[nxt[i][j]+1]+1<dp[i]){
				dp[i]=dp[nxt[i][j]+1]+1;
				f[i]=nxt[i][j]+1; c[i]=j;
			}
	}
	i=1;
	while (i<n){
		printf("%c",c[i]+'a');
		i=f[i];
	}
	return 0;
}

Measured memory_bytes: 23936
n, q = gets.split.map(&:to_i)
used = Array.new(n,false)

g = Array.new(n){[]}
(n-1).times do
  a,b = gets.split.map{ |i| i.to_i - 1 }
  g[a].push(b)
  g[b].push(a)
end

points = Array.new(n,0)
q.times do |i|
  node,x = gets.split.map(&:to_i)
  node -= 1
  points[node] += x
end

que = [0]

while que.size != 0 do
  node = que.pop
  used[node] = true
  g[node].each do |k|
    next if used[k]
    points[k] += points[node]
    que.push(k) unless used[k]
  end
end

puts points.join(' ')

Measured memory_bytes: 26236
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

ll n;
string s;
vector<ll> color;//狼:1 hituzi:0

bool cul(){
    for(int i=2;i<n;i++){
        color[i]=((ll)s[i-1]^color[i-1]^color[i-2]);
    }
    for(int i=0;i<n;i++){
        if(color[i]!=((ll)s[(i+n-1)%n]^color[(i+n-1)%n]^color[(i+n-2)%n])){return false;}
        if(color[i]!=((ll)s[(i+1)%n]^color[(i+1)%n]^color[(i+2)%n])){return false;}
    }
    return true;
}




int main(){
    cin>>n;
    cin>>s;
    color.resize(n);
    for(auto &I:s){
        if(I=='o'){I=0;}
        else{I=1;}
    }
    for(int i=0;i<2;i++){
        for(int t=0;t<2;t++){
            color[0]=i;
            color[1]=t;
            if(cul()){
                for(auto &I:color){cout<<(I?"W":"S");}
                cout<<endl;
                return 0;
            }
        }
    }
    cout<<"-1"<<endl;
    
    
    return 0;
}


Measured memory_bytes: 1408
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  [a, b, k] <- getIntList
  let a' = max 0 (a-k)
      k' = max 0 (k-a)
      b' = max 0 (b-k')
  putStrLn $ show a' ++ " " ++ show b'

Measured memory_bytes: 508
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split("\\s+");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		HashMap<String, Integer> m = new HashMap<String, Integer>();
		m.put("SUN", 7);
		m.put("MON", 6);
		m.put("TUE", 5);
		m.put("WED", 4);
		m.put("THU", 3);
		m.put("FRI", 2);
		m.put("SAT", 1);
		System.out.println(m.get(str));
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}


Measured memory_bytes: 22612
#include <iostream>

using namespace std;

int main()
{
  int t1, t2, r1, r2;

  cin >> t1 >> t2 >> r1 >> r2;

  if (r1 != -1 && r2 != -1) {
    if (r1 > r2) cout << "Alice" << endl;
    else if (r1 == r2) cout << "Draw" << endl;
    else cout << "Bob" << endl;
  } else {
    if (t1 < t2) cout << "Alice" << endl;
    else if (t1 == t2) cout << "Draw" << endl;
    else cout << "Bob" << endl;
  }
}



Measured memory_bytes: 3116
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
typedef double D;
typedef complex<D> P;
typedef pair<P,P> L;
typedef vector<P> Pol;
D eps=1e-9;
inline D cro(P a,P b){
	return imag(conj(a)*b);
}
inline int ccw(P a,P b,P c){
	if(cro(b-a,c-a)>eps) return 1;
	if(cro(b-a,c-a)<-eps) return -1;
	return 0;
}
inline bool iLSex(L l,L s){
	return cro(l.sc-l.fs,s.fs-l.fs)*cro(l.sc-l.fs,s.sc-l.fs)<-eps;
}
inline P intLL(L a,L b){
	D t=cro(a.sc-a.fs,a.sc-b.fs)/cro(a.sc-a.fs,b.sc-b.fs);
	return b.fs+t*(b.sc-b.fs);
}
inline Pol convexcut(Pol p,L l){
	Pol ret;
	rep(i,p.size()){
		if(ccw(l.fs,l.sc,p[i])!=-1) ret.pb(p[i]);
		L s=L(p[i],p[(i+1)%p.size()]);
		if(iLSex(l,s)) ret.pb(intLL(l,s));
	}
	return ret;
}
vector<Pol> makevolonoi(Pol vp,Pol pol){
	vector<Pol> ret;
	Pol polc=pol;
	rep(i,vp.size()){
		pol=polc;
		rep(j,vp.size()){
			if(i==j) continue;
			P p=(vp[i]+vp[j])/2.0,q=p+(vp[j]-vp[i])*P(0,1);
			pol=convexcut(pol,L(p,q));
		}
		ret.pb(pol);
	}
	return ret;
}
D aPol(Pol p){
	int n=p.size();
	D ret=0;
	rep(i,n) ret+=cro(p[i],p[(i+1)%n])/2;
	return ret;
}
int main(){
	while(true){
		int N,M;
		cin>>N>>M;
		if(N==0) break;
		Pol pol,vp;
		rep(i,N){
			int x,y;
			cin>>x>>y;
			pol.pb(P(x,y));
		}
		rep(i,M){
			int x,y;
			cin>>x>>y;
			vp.pb(P(x,y));
		}
		vector<Pol> vol=makevolonoi(vp,pol);
		rep(i,M) printf("%.12f\n",aPol(vol[i]));
	}
}

Measured memory_bytes: 1240
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    limit = sum(a) / (4 * m)
    count = 0
    for i in range(n):
        if a[i] >= limit:
            count += 1
    if count >= m:
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


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

int main(){
  double measure=0;
  int N;
  int under=1;
  double A[10][2]={0};
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>A[i][0]>>A[i][1];
    under*=(i+1);
  }
  for(int i=0;i<N-1;i++){
    for(int j=i;j<N;j++){
      measure+=sqrt((A[i][0]-A[j][0])*(A[i][0]-A[j][0])+(A[i][1]-A[j][1])*(A[i][1]-A[j][1]));
    }
  }
  cout<<setprecision(12)<<measure*2/N<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=LLONG_MAX;
const int inf=INT_MAX;
const int nmax=1e5+5;
const int mod=1e9+7;
using namespace std;
string s;
int i,n,ans,ans1;
int main()
{
    //freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>s;
	n=(int)s.length(),ans=ans1=n;
	for(i=0;i<n;i++)
	{
		if(s[i]=='0')ans=min(ans,max(max(i,1),max(n-i-1,1)));
		else ans1=min(ans1,max(max(i,1),max(n-i-1,1)));
	}
	cout<<max(ans,ans1)<<endl;
	return 0;
}

Measured memory_bytes: 512
#Nは人の数を表す
#Kは操作を行う回数を表す
N,K = map(int, input().split())
#SはLとRからなる文字列
S = list(input())
#点数を保管する変数
score = 0
ans = 0
#操作を行う前の点数を求めル
for i in range(N-1):
    if(S[i] == S[i+1]):
        score += 1
#操作を行うことによってスコアは＋2される(例外あり、ただし考える必要なし)        
ans = min(score+2*K,N-1)

print(ans)

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

int main(){
  int a, b;
  while(cin >> a >> b){
    int ab = a + b;
    int digit = 0;
    while(1){
      ab = ab/10; 
      digit++;
      if(ab==0)break;
    }
    cout << digit << endl;
  }
  return 0;
}



Measured memory_bytes: 2984
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-9;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int p[310000];
int u[310000];
int d[310000];
int ev[310000];
int ind[310000];
int val[310000];
int segtree[1048576];
int z[310000];
int query(int a,int b,int c,int d,int e){
	if(d<a||b<c)return 0;
	if(c<=a&&b<=d)return segtree[e];
	return max(query(a,(a+b)/2,c,d,e*2),query((a+b)/2+1,b,c,d,e*2+1));
}
void update(int a,int b){
	a+=524288;
	while(a){
		segtree[a]=max(segtree[a],b);
		a/=2;
	}
}
int calc(int a,int b){
	if(a>b)return max(calc(0,b),calc(a,524287));
	return query(0,524287,a,b,1);
}
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d",p+i);p[i]--;
	}
	int st=-1;
	int now=0;
	int sl=0;
	int len=0;
	for(int i=0;i<2*a;i++){
		if(p[i%a]==0){
			if(now==0)st=i;
			now++;
			if(len<now){
				len=now;sl=st;
			}
		}else{
			now=0;
		}
	}
	if(len==0){
		printf("0\n");return 0;
	}
	for(int i=len;i<a;i++){
		if(p[(i+sl)%a]==0){
			printf("0\n");return 0;
		}
	}
	for(int i=0;i<a;i++)d[i]=-1;

	for(int i=len;i<a;i++){
		if(p[(i+sl)%a]<p[(i+sl+1)%a]){
			d[(i+sl-len+1)%a]=p[(i+sl)%a];
		}
		if(p[(i+sl)%a]>p[(i+sl+1)%a]){
			d[(i+sl+1)%a]=p[(i+sl+1)%a];
		}
	}

	long long ret=1;
	int sz=0;
	for(int i=0;i<a;i++){

		if(i==0||p[(i+sl)%a]!=p[(i+sl+a-1)%a]){
			ind[sz]=i;
			val[sz++]=p[(i+sl)%a];
		}
	}
	//for(int i=0;i<sz;i++)printf("%d %d\n",ind[i],val[i]);
	for(int i=0;i<sz;i++){
		if((ind[(i+1)%sz]+a-ind[i])%a>len){
			ret=0;
		}
		if(val[i]>val[(i+1)%sz]&&val[i]>val[(i+sz-1)%sz]){
			d[(ind[i]+sl)%a]=val[i];
			int L=(ind[(i+1)%sz]+a-ind[i])%a;
			ret=(ret*(max(0,len-L+1)))%mod;
		}
	}
	int f=0;
	for(int i=0;i<a;i++){
		if(~d[i]){
			u[d[i]]++;
			
		}
	}
	for(int i=0;i<a;i++){
		if(u[i]>1){
			printf("0\n");return 0;
		}
		if(u[i]==0){
			z[f++]=i;
		}
	}
//	for(int i=0;i<a;i++){
//		printf("%d ",d[i]);
//	}printf("\n");
	int rem=a;
	int n=0;
	for(int i=0;i<a;i++)
		update(i,p[i]);
	
	for(int i=0;i<a;i++){
		if(~d[i]){
//			printf("%d %d %d\n",i,d[i],calc(i,(i+len-1)%a));
			if(calc(i,(i+len-1)%a)>d[i]){ret=0;break;}
			continue;
		}
		ev[n++]=lower_bound(z,z+f,calc(i,(i+len-1)%a))-z;
	}
	if(ret==0){
		printf("0\n");return 0;
	}
	std::sort(ev,ev+n);
//	for(int i=0;i<n;i++){
//		printf("%d ",ev[i]);
//	}printf("\n");
	for(int i=n-1;i>=0;i--){
		ret=ret*max(0,(f-ev[i])-(n-i-1))%mod;
	}
	printf("%lld\n",ret);
}
/*
1 1 2
1   

3 5 6 7 8
0 0 1 1 1
*/

Measured memory_bytes: 12416
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		int n, a, b;
		String cmd;
		Scanner scan = new Scanner(System.in);
		char[] str = scan.next().toCharArray();
		n=scan.nextInt();
		for(int i=0;i<n;i++){
			cmd=scan.next();
			switch(cmd){
				case "print":
					a=scan.nextInt();
					b=scan.nextInt();
					for(int j=a;j<=b;j++)
						System.out.print(str[j]);
					System.out.println();
					break;					
				case "reverse":
					a=scan.nextInt();
					b=scan.nextInt();
					char[] temp = new char[b-a+1];
					for(int j=a;j<=b;j++)
						temp[j-a]=str[j];
					for(int j=a;j<=b;j++)
						str[j]=temp[b-j];
					break;
				case "replace":
					a=scan.nextInt();
					b=scan.nextInt();
					char[] p = scan.next().toCharArray();
					for(int j=a;j<=b;j++)
						str[j]=p[j-a];
					break;
			}
		}
		scan.close();
	}
}


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

int main(){
    ll N;
    cin>>N;
    vector<ll>A(N);
    rep(i,N)scanf("%lld",&A[i]);
    ll g=A[0];
    rep(i,N)g=__gcd(g,A[i]);
    cout<<g<<endl;
}

Measured memory_bytes: 1024
import collections
count = 0
N = int(input())
a = list(map(int,input().split(" ")))
c = collections.Counter(a)
C = c.most_common()
for i in C:
    A = i[0]
    B = i[1]
    if A < B:
        count += B-A
    elif A == B:
        continue
    else:
        count += B
print(count)


Measured memory_bytes: 21224
s = input()
t = input()
dp = [[0 for _ in range(len(t) + 1)] for _ in range(len(s) + 1)]
for i in range(len(s) + 1):
    for j in range(len(t) + 1):
        if i < len(s):
            dp[i+1][j] = max(dp[i+1][j], dp[i][j])
        if j < len(t):
            dp[i][j+1] = max(dp[i][j+1], dp[i][j])
        if i < len(s) and j < len(t) and s[i] == t[j]:
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1)
i, j = len(s), len(t)
now = dp[len(s)][len(t)]
ans = []
while now:
    if dp[i-1][j] == now:
        i -= 1
    elif dp[i][j-1] == now:
        j -= 1
    else:
        i -= 1
        j -= 1
        ans.append(s[i])
        now -= 1
print(''.join(reversed(ans)))

Measured memory_bytes: 153404
val MOD = 1000000007L

fun main(args : Array<String>) {
    val (x, y) = readLine()!!.split(" ").map { it.toInt() }

    if ((x + y) % 3 != 0) {
        println(0)
        return
    }

    var numX = -1
    var numX2 = -1

    for (i in 0..x) {
        if ((x - i) % 2 != 0) continue
        val x2 = (x - i) / 2
        val posY = 2 * i + x2
        if (posY == y) {
            numX = i
            numX2 = x2
        }
    }

    if (numX == -1 && numX2 == -1) {
        println(0)
        return
    }

    println(modComb((numX+numX2).toLong(), numX.toLong(), MOD))
}

fun modPow(base: Long, p: Long, m: Long): Long {
    return when {
        p == 0L -> 1L
        p == 1L -> base
        p % 2L == 0L -> modPow(base, p / 2L, m).let { it*it%m }
        else -> base * modPow(base, p - 1L, m) % m
    }
}

fun modComb(n: Long, k: Long, m: Long): Long {
    if (n < k) return 0L
    val kk = Math.min(k, n-k)

    var n1 = 1L
    var n2 = 1L

    for (i in 1..kk) {
        n1 *= (n-i+1)
        n1 %= m
        n2 *= i
        n2 %= m
    }

    return n1 * modInv(n2, m) % m
}

fun modInv(n: Long, m: Long): Long {
    return modPow(n, m-2, m)
}

Measured memory_bytes: 37868
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long W = sc.nextLong();
    long[] w = new long[N];
    long[] v = new long[N];

    ArrayList<Long> a = new ArrayList<Long>();
    ArrayList<Long> b = new ArrayList<Long>();
    ArrayList<Long> c = new ArrayList<Long>();
    ArrayList<Long> d = new ArrayList<Long>();

    for(int i = 0; i < N; i++) {
      w[i] = sc.nextLong();
      v[i] = sc.nextLong();
      if(w[i] == w[0]) a.add(v[i]);
      if(w[i] == w[0] + 1) b.add(v[i]);
      if(w[i] == w[0] + 2) c.add(v[i]);
      if(w[i] == w[0] + 3) d.add(v[i]);
    }

    Collections.sort(a);
    Collections.sort(b);
    Collections.sort(c);
    Collections.sort(d);

    Collections.reverse(a);
    Collections.reverse(b);
    Collections.reverse(c);
    Collections.reverse(d);

    long ans = 0;

    long[] asum = new long[a.size() + 1];
    long[] bsum = new long[b.size() + 1];
    long[] csum = new long[c.size() + 1];
    long[] dsum = new long[d.size() + 1];

    for(int i = 1; i < a.size() + 1; i++) {
      asum[i] += (asum[i - 1] + a.get(i - 1));
    }

    for(int i = 1; i < b.size() + 1; i++) {
      bsum[i] += (bsum[i - 1] + b.get(i - 1));
    }

    for(int i = 1; i < c.size() + 1; i++) {
      csum[i] += (csum[i - 1] + c.get(i - 1));
    }

    for(int i = 1; i < d.size() + 1; i++) {
      dsum[i] += (dsum[i - 1] + d.get(i - 1));
    }

    for(int x = 0; x <= a.size(); x++) {
      for(int y = 0; y <= b.size(); y++) {
        for(int z = 0; z <= c.size(); z++) {
          for(int u = 0; u <= d.size(); u++) {
            if((long)x * w[0] + (long)y * (w[0] + 1) + (long)z * (w[0] + 2) + (long)u * (w[0] + 3) <= W) {
              ans = Math.max(ans, asum[x] + bsum[y] + csum[z] + dsum[u]);
            }
          }
        }
      }
    }

    System.out.println(ans);
  }
}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
#define long long LL
const int N=1000005;
const int M=1e9+7;
int n,m,k,ans,f[N],v[N],sum;
int fp(int x,int y){int s=1;
for(;y;y>>=1){if(y&1)s=1ll*s*x%M;
x=1ll*x*x%M;}return s;}
int C(int x,int y){
return 1ll*f[x]*v[y]%M*v[x-y]%M;}
signed main(){scanf("%d%d%d",&n,&m,&k);
f[0]=v[0]=1;sum=n+m+k;
for(int i=1;i<=sum;i++)f[i]=1ll*f[i-1]*i%M;
v[sum]=fp(f[sum],M-2);for(int i=sum-1;i;i--)
v[i]=1ll*v[i+1]*(i+1)%M;if(m<k)swap(m,k);int q=1;
for(int i=n;i<=sum;i++){if(k+n>=i){
(ans+=1ll*C(i-1,n-1)*fp(3,sum-i)%M*q%M)%=M;
if(k+n!=i)q=q*2%M;}
else if(n+m>=i){q=q*2-C(i-n-1,k);q=(q%M+M)%M;
(ans+=1ll*q*C(i-1,n-1)%M*fp(3,sum-i)%M)%=M;}
else{q=q*2-C(i-n-1,k);q=(q%M+M)%M;
q=(q-C(i-n-1,i-n-m-1)+M)%M;
(ans+=1ll*q*C(i-1,n-1)%M*fp(3,sum-i)%M)%=M;}
}printf("%d\n",(ans+M)%M);return 0;}

Measured memory_bytes: 7808
#include <bits/stdc++.h>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18 


int main () {
    int h , w ;
    cin >> h >> w; 
    vector<vector<int>> c(10, vector<int> (10)) ;
    rep(i, 10){
        rep(j, 10){
            cin >> c[i][j] ;
        }
    }
    vector<vector<int>> tab (h, vector<int> (w)) ;
    rep(i, h){
        rep(j, w){
            cin >> tab[i][j] ;
        }
    }
    rep(k, 10){
        rep(i, 10){
            rep(j, 10){
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]) ;
            }
        }
    }
    ll ans = 0 ;
    rep(i, h){
        rep(j, w){
            if(tab[i][j] != -1){
                int p = tab[i][j] ;
                ans += c[p][1] ;
            }
        }
    }
    cout << ans << endl ;
} 

Measured memory_bytes: 3748
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
//#include"matrix.h"
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define REP(i,x,y) for(ll (i)=(x);(i)<(y);(i)++)
#define RREP(i,x,y) for(ll (i)=(x);(i)>=(y);(i)--)
#define sqr(x) ((x)*(x))
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);
#define fst first
#define snd second
#define itm1 fst
#define itm2 snd.fst
#define itm3 snd.snd
#define sz(v) ((ll)v.size())
#define oo 200000000000
//#define EPS 1e-9

//#define pi acos(-1)
#define MOD 1000000007
#define MAXN 999409605
#define cot 20
//#define N 300005
//#define min -9042414321442
#define INF 1065435634
#define N1 90
//typedef long double ld;
typedef  long long ll;
//typedef short int ll;
//typedef ll ll;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef pair<ll,ii> tri;
typedef vector<ll> vi;

#define N 243555   
#define M 31
//#define cap 1000000000
#define bas 31

inline ll ma(ll a, ll b){ return ((a-b>0)? a:b);}
inline ll mi(ll a, ll b){return ((a-b>0)? b:a);}
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << 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

inline ll go(ll a){
  ll ans=0;
  while(a) ans+=a%10, a/=10;
  return ans;
}
ll dp[N], ar[N], p[N];
vi b;
inline ll chek(ll &n){
  ll flag=1;
  REP(i,0,n-1) if(ar[i+1]-ar[i]>1) flag=0;
  if(ar[0]!=0) flag=0;
  return flag;
}
inline void solve(ll &n){
  ll ans=0;
  REP(i,0,n) ans+=dp[i];
  cout<<ans<<endl; 
}
inline ll lis(vi &v){
  ll sz=0;
  REP(i,0,v.size()){
    auto id=lower_bound(all(b),v[i])-b.begin();
    if(id==sz) {sz++, b.pb(v[i]);}
  }
  return sz;
}
int main(){
  fastio;
  ll n,froz=1; cin>>n;
  vi v;
  REP(i,0,n) {cin>>ar[i], p[ar[i]]=i+1;}
  REP(i,1,n+1) v.pb(p[i]);
  //REP(i,1,n+1) cout<<i<<" "<<p[i]<<endl;
  REP(i,1,n+1) dp[i]=i==1? 1: (p[i]>p[i-1]? dp[i-1]+1:1); 
  REP(i,1,n+1) froz=ma(dp[i],froz);
  //REP(i,0,n) cout<<i<<" | "<<b[i]<<endl;
  cout<<n-froz<<endl;
  return 0;
}


Measured memory_bytes: 7024
#include<stdio.h>
int sum(int, int,int *,int);
int main(){

  int i,n,q;

  scanf("%d",&n);

  int A[n];
  
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&q);

  int B[q];

   for(i=0; i<q; i++){
    scanf("%d",&B[i]);
   }
    
    for(i=0; i<q; i++){
      if(sum(0,B[i],A,n))
	 printf("yes\n");
      else printf("no\n");
   }
     return 0;
}
   	   
int sum(int i,int m,int *A,int n)
{
  int s=0;
  if(m==0)return 1;
  if(i>=n)return 0;
  else{
    s+=sum(i+1,m,A,n);
    s+=sum(i+1,m-A[i],A,n);
  }
  return s;
}



Measured memory_bytes: 2104
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

n = input()
seq = sorted((int(x) for x in input().split()))
if seq[0] == 0:
    ans = 0
else:
    ans = 1
    for val in seq:
        ans *= val
        if ans > 10**18:
            ans = -1
            break
print(ans)


Measured memory_bytes: 92824
N,W = map(int,input().split())

w0,v0 = map(int,input().split())
vlist = [[v0],[],[],[]]

for i in range(N-1):
    w,v = map(int,input().split())
    vlist[w-w0].append(v)

for i in range(4):
    vlist[i].sort(reverse = True)

m = 0
S = [[0],[0],[0],[0]]
for i in range(4):
    for j in range(len(vlist[i])):
        S[i].append(S[i][-1]+vlist[i][j])

m = 0
for i in range(len(S[0])):
    for j in range(len(S[1])):
        for k in range(len(S[2])):
            for l in range(len(S[3])):
                if w0*(i+j+k+l)+j+2*k+3*l <= W:
                    m = max(m,S[0][i]+S[1][j]+S[2][k]+S[3][l])

#print(vlist)
#print(S)
print(m)

Measured memory_bytes: 40560
#include <cstring>
#include <iostream>
#include <math.h>
#include <stdio.h>

#define arrayLength(array) (size_t)((sizeof array) / (sizeof array[0]))

int main() {
  int n, m, x, y, z;

  char s[3][255];
  char p[255];

  //   scanf(" %d %d %d %d", &n, &m, &x, &y);
  for (int i = 0; i < 3; i++) {
    scanf(" %s", &s[i]);
    printf("%c", s[i][0] + ('A' - 'a'));
  }

  //   for (int i = 0; i < 3; i++) {
  //     printf("%c", s[i][i]);
  //   }

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
void read(int &a){
	a=0;
	char c=getchar();
	while(c<'0'||c>'9'){
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		a=(a<<1)+(a<<3)+(c^48);
		c=getchar();
	}
}
const int Maxn=200000;
const int Mod=1000000007;
int n;
int a[Maxn+5];
int sum[Maxn+5];
int main(){
	read(n);
	int ans=0;
	for(int i=1;i<=n;i++){
		read(a[i]);
		sum[i]=(sum[i-1]+a[i])%Mod;
		ans=(ans+1ll*a[i]*sum[i-1])%Mod;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 4656
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

}
ll min(ll a, ll b) {
	if (a < b)
		return a;
	else
		return b;

}



int main() {
	ll N;
	cin >> N;
	vector<ll> A(N + 1), B(N);

	rep(i, N+1) {
		cin >> A[i];
	}
	rep(i, N)
		cin >> B[i];

	ll sum = 0;
	rep(i, N) {
		ll temp = A[i];
		sum += min(temp, B[i]);
		A[i] = max(A[i] - B[i], 0);
		B[i] = max(B[i] - temp, 0);
		temp = A[i + 1];
		sum += min(A[i + 1], B[i]);
		A[i + 1] = max(A[i + 1] - B[i], 0);		
		B[i] = max(B[i]- temp, 0);
		
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define INF 1e18L + 5
#define ll long long

int main(){
	int n, w;
	cin >> n >> w;
	vector<int> weight(n);
	vector<int> value(n);
	ll sum_value = 0;
	for(int i = 0; i < n; i++){
		cin >> weight[i] >> value[i];
		sum_value += value[i];	
	}
	vector<ll> dp(sum_value+1, INF);
	dp[0] = 0;
	for(int i = 0; i < n; i++){
		for(int value_already = sum_value - value[i]; value_already >= 0; value_already--){
			dp[value_already + value[i]] = min(dp[value_already] + weight[i], dp[value_already + value[i]]);		
		}
	}
	int ans = 0;
	for(int i = 0; i <= sum_value; i++){
		cerr << "dp[" << i << "] = " << dp[i] << endl;
		if(dp[i] <= w)
			ans = max(ans, i);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val ds = readLine()!!.split(' ').map { it.toInt() }
    var ans = 0
    for (i in 0 until n) {
        for (j in i + 1 until n) {
            ans += ds[i] * ds[j]
        }
    }
    println(ans)
}


Measured memory_bytes: 38304
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

string s, t;

int main() {
    cin >> s;

    while (t.length() < s.length()) t += "hi";

    if (s == t) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	if a <= 5 {
		fmt.Println(0)
		return
	}
	if a <= 12 {
		fmt.Println(b / 2)
		return
	}
	fmt.Println(b)
}


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

int main(){
    string s;
    cin>>s;
    int n=s.length();
    int cnt=0;
    vector<int> ans(n);
    for(int i=0;i<n;i++){
        if(s[i]=='R') cnt++;
        else{
            ans[i]+=cnt/2;
            ans[i-1]+=(cnt+1)/2;
            cnt=0;
        }
    }
    for(int i=n-1;i>=0;i--){
        if(s[i]=='L') cnt++;
        else{
            ans[i]+=cnt/2;
            ans[i+1]+=(cnt+1)/2;
            cnt=0;
        }
    }
    for(int a : ans) cout<<a<<endl;
}

Measured memory_bytes: 3832