akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

#define clr(a,i) memset((a), (i) ,sizeof(a))

long long BubbleSort(vector<long long> a){
  long long ans=0;
  // rep(i,a.size()-2){
  //   rep(j,a.size()-i-2){
  //     if(a[j]>a[j+2]) swap(a[j],a[j+2]);
  //   }
  // }
  rep(i,a.size()-1){
    rep(j,a.size()-i-1){
      if(a[j]>a[j+1]){
        swap(a[j],a[j+1]);
        ans++;
      }
    }
  }
  return ans;
}

int main(){
  long long n;
  std::cin >> n;
  std::vector<long long> a(n/2+(n%2)),b(n/2+(n%2)),c(n),v;
  rep(i,n) cin >> c[i];
  rep(i,n){
    if(i%2==0){
      a[i/2]=c[i];
    }
  }
  sort(all(c));
  rep(i,n){
    if(i%2==0){
      b[i/2]=c[i];
    }
  }
  sort(all(a));
  set_difference(all(a),all(b),back_inserter(v));

  std::cout << v.size() << std::endl;
}


Measured memory_bytes: 2428
import sys
input = sys.stdin.readline

N = int(input())
S = list(input())

# 最長共通接頭辞問題(Z-Algorithm)
# 文字列SとS[i:]の最長共通接頭辞を各iについて求める
# 参考：https://codeforces.com/blog/entry/3107
# 図がわかりやすい:https://snuke.hatenablog.com/entry/2014/12/03/214243


def Z_Algorithm(S):
    N = len(S)
    R = 0 # Rはi文字目まで読んだ時、接頭辞の右端のうち一番右側にくるようなもの
    L = 0 # Lはその範囲の左端
    Z = [0 for _ in range(N)] # 答えとなる最長接頭辞の長さ
    Z[0] = N

    for i in range(1, N):
        if i > R:
            # iが前のRより右側ならS[i:]とSのみで考える
            L = i
            R = i
            while (R < N and S[R-L] == S[R]):
                R += 1
            Z[i] = R - L
            R -= 1
        else:
            k = i - L
            if Z[k] < R - i + 1:
                # はみ出さないなら前のがそのまま使える。R,Lはそのまま
                Z[i] = Z[k]
            else:
                # はみ出したら伸ばしてく
                L = i
                while (R < N and S[R-L] == S[R]):
                    R += 1
                Z[i] = R - L
                R -= 1
    return Z


def main():
    ans = 0
    for i in range(N):
        Z = Z_Algorithm(S[i:])
        for j, z in enumerate(Z):
            ans = max(ans, min(z, j))
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 59228
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define int long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define each(i, x) for (auto &i : x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using priority_queuel = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-9;
ll mod = static_cast<ll>(1e9 + 7);
template <class T>
constexpr int sz(const T &a) { return (int)a.size(); }
template <class T>
constexpr T pow2(const T a) { return a * a; }
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class A, int N, class T>
void fillArray(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

int n;
ll a[200005];
vector<int> g[200005];
int ans[200005];
ll dp[200005];
void dfs(int v, int p) {
    auto ptr = lower_bound(dp, dp + n, a[v]);
    auto tmp = *ptr;
    *ptr = a[v];
    ans[v] = lower_bound(dp, dp + n, inf) - dp;
    each(nv, g[v]) {
        if (nv == p) continue;
        dfs(nv, v);
    }
    *ptr = tmp;
}
void solve() {
    cin >> n;
    rep(i, n) cin >> a[i];
    rep(i, n - 1) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }

    fillArray(dp, inf);
    dfs(0, -1);
    rep(i, n) cout << ans[i] << '\n';
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout.flush();
    return 0;
}


Measured memory_bytes: 30716
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 
ll Abs(ll x,ll y){
    if(x>=y)return x-y;
    else return y-x;
}
 
 
int main(void){
    string s,t;
    cin>>s>>t;
    ll ssize = s.length();
    ll tsize = t.length();
    vector<ll>pos[26];
    for(ll i=0;i<ssize;i++){
        pos[s[i]-'a'].push_back(i);
    }
    for(ll i=0;i<tsize;i++){
        ll x = t[i]-'a';
        auto itr = lower_bound(pos[x].begin(),pos[x].end(),-1);
        if(itr==pos[x].end()){
            cout<<-1<<endl;
            return 0;
        }
    }
    ll now = -1;
    ll cnt = 0;
    for(ll i=0;i<tsize;i++){
        ll x = t[i]-'a';
        auto itr = upper_bound(pos[x].begin(),pos[x].end(),now);
        if(itr!=pos[x].end()){
            now = (*itr);
        }
        else{
            cnt++;
            now = pos[x][0];
        }
    }
    cout<<(ll)ssize*cnt+now+1<<endl;
    return 0;
}

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

#define MAX_N 200

int main(){
    int N,L;
    int temp = 1000000, index, sum=0;
    int *apple,*abs_apple;
    cin >> N >> L ;
    apple = new int[N];
    for (int i=0; i<N; i++) apple[i] = L + i;
    for (int i=0; i<N; i++){
        if (temp > abs(apple[i])){
            temp = abs(apple[i]);
            index = i;
        }
    }
    for (int i=0;i<N;i++){
        if (i == index) continue;
        else{
            sum += apple[i];
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    int d[11];
    for (int i = 0; i < 11; i++) {
        d[i] = int(pow(2.0, double(i)));
    }
    int n, k;
    scanf("%d %d", &n, &k);
    int ans = 1;
    for (int i = 0; i < n; i++) {
        if (d[i + 1] - d[i] < k) ans *= 2;
        else ans += k;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
use std::io::{BufRead, Write};
use std::io;

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut buf = String::new();
    input.read_line(&mut buf).unwrap();
    let (n,m):(usize,usize) = {
      let mut split = buf.split_whitespace();
        (split.next().unwrap().parse().unwrap(),split.next().unwrap().parse().unwrap())
    };
    let rate = 1 << m;
    let time = 100*n+1800*m;
    writeln!(output, "{}", rate*time).unwrap();
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v: Vec<u8> = Vec::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }

    #[test]
    fn case1() {
        test(
            "1 1
        ",
            "3800\n",
        );
    }

    #[test]
    fn case2() {
        test(
            "10 2
",
            "18400\n",
        );
    }

    #[test]
    fn case3() {
        test(
            "100 5
",
            "608000\n",
        );
    }
}


Measured memory_bytes: 4352
### constant

CH_A = "a".ord
MAX_N = 10

### subroutines

def store(str)
  $count += 1
  $strs << str.clone
  $strs.sort!
  if $strs.length > MAX_N
    $strs.delete_at(MAX_N / 2)
  end
end

def rep_rec(k, str)
  if k < 0
    store(str)
    return
  end

  cur = (CH_A + k).chr
  nxt = (CH_A + k + 1).chr
  found = false

  for i in (0...str.length)
    case str[i]
    when nxt
      found = true
      break
    when cur
      str[i] = nxt
      rep_rec(k - 1, str)
      str[i] = cur
    end
  end

  if ! found
    rep_rec(k - 1, str)
  end
end

### main

loop do
  line = gets.strip
  break if line == '#'

  $count = 0
  $strs = []

  rep_rec(24, line)

  puts $count
  $strs.each{|str| puts str}
end

Measured memory_bytes: 6124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n,k;
ll a[200005];
ll b[200005];
ll aaa=0;
bool x;
int main(void){
    cin>>n>>k;
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    for(ll i=0;i<k;i++){
        for(int j=0;j<n;j++){
            b[max(aaa,j-a[j])]++;
            b[min(n,j+a[j]+1)]--;
        }
        for(ll j=1;j<n;j++){
            b[j]=b[j]+b[j-1];
        }
        x=true;
        for(ll j=0;j<n;j++){
            a[j]=b[j];
            b[j]=0;
            if(a[j]!=n){
                x=false;
            }
        }
        if(x){
            for(ll j=0;j<n;j++){
                cout<<n;
                if(j==n-1){
                    cout<<endl;
                }else{
                    cout<<" ";
                }
            }
            return 0;
        }
    }
    for(ll i=0;i<n;i++){
        cout<<a[i];
        if(i==n-1){
            cout<<endl;
        }else{
            cout<<" ";
        }
    }

}



Measured memory_bytes: 6744
MOD = 10**9 + 7
MAX = int(2e5)


def div(a, b):
    return a * pow(b, MOD-2, MOD) % MOD


FACT = [1] * (MAX+1)
for i in range(1, MAX+1):
    FACT[i] = (i * FACT[i-1]) % MOD
INV = [1] * (MAX+1)
INV[MAX] = div(1, FACT[MAX])
for i in range(MAX, 0, -1):
    INV[i-1] = (INV[i] * i) % MOD


def combi(n, x):
    ret = 1
    for i in range(x):
        ret = ret * (n-i) % MOD
    ret = ret * INV[x] % MOD
    return ret


def main():
    n, a, b = map(int, input().split())
    ans = pow(2, n, MOD) - 1
    ans = (ans - combi(n, a) - combi(n, b)) % MOD
    print(ans)


if __name__ == "__main__":
    main()


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

int main(){
    string O,E;
    cin >>O>>E;
    if(O.size()==E.size()){
        for(int i=0;i<O.size();i++){
            cout << O.at(i)<<E.at(i);
        }
        cout <<endl;
    }
    else{
            for(int i=0;i<E.size();i++){
            cout << O.at(i)<<E.at(i);
        }
        cout <<O.at(E.size())<<endl;
    }
}

Measured memory_bytes: 3564
package main

import (
	"fmt"
)

// go run ./main.go < in

type NibunData struct {
	target int
	left   int
	mid    int
	right  int
}

var nubunData NibunData

var a, b int

func main() {
	fmt.Scan(&a, &b)

	num8 := 0
	var stack []int
	for i := 0; i < 1265; i++ {
		num8 = about8(i)
		if num8 != 0 {
			stack = append(stack, num8)
		}
	}

	num10 := 0
	for _, v := range stack {
		num10 = about10(v)
		if num10 != 0 {
			break
		}
	}

	if num10 == 0 {
		fmt.Println("-1")
	} else {
		fmt.Println(num10)
	}
}

func about8(price int) int {
	if price*8 >= a*100 && price*8 < (a+1)*100 {
		return price
	}
	return 0
}

func about10(price int) int {
	if price*10 >= b*100 && price*10 < (b+1)*100 {
		return price
	}
	return 0
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair




int main() {
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vi cnt(n);
  rep (i, n - 1) {
    if (s.substr(i, 2) == "AC") {
      cnt[i + 1] = 1;
    }
  }
  vi sum(n + 1);
  rep (i, n) {
    sum[i + 1] = sum[i] + cnt[i];
  }

  while (q--) {
    int l, r;
    cin >> l >> r;
    l--;
    int ans = sum[r] - sum[l];
    ans -= cnt[l];
    cout << ans << endl;
  }
}


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

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

  string ans = "";
  switch (N) {
  case 22:
    ans = "Christmas Eve Eve Eve";
    break;
  case 23:
    ans = "Christmas Eve Eve";
    break;
  case 24:
    ans = "Christmas Eve";
    break;
  case 25:
    ans = "Christmas";
    break;
  }

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

Measured memory_bytes: 256
S = list(input())
N = len(S)
if S == S[::-1] and S[:(N - 1) // 2] == S[:(N - 1) // 2][::-1] and S[(N - 1) // 2 + 1:] == S[(N - 1) // 2 + 1:][::-1]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 61804
N = int(input())
L_A=list(map(int,input().split()))
m = 1000
L = []
for i in range(N-1):
    if L_A[i] < L_A[i+1]:
        L.append(1)
    elif  L_A[i] > L_A[i+1]:
        L.append(-1)
    else:
        L.append(0)
k = 0
a = 0
while k < N-1:
    if L[k] == 1 and a == 0:
        a = L_A[k]
    elif  L[k] == -1 and a != 0:
        m += (m//a)*(L_A[k]-a)
        a = 0
    k += 1
if a != 0:
    m += (m//a)*(L_A[-1]-a)
print(m)

Measured memory_bytes: 9224
#include<bits/stdc++.h>
using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	int n,sum=0,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		char s;
		cin>>s;
		if(s=='I') sum++;
		else sum--;
		ans=max(ans,sum);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
(defun solve (s)
  (let ((n (length s))
	(cnt 0)
	(ans 0))
    (dotimes (i n ans)
      (when (equal (aref s i) #\W)
	(setq ans (+ ans (- i cnt)))
	(incf cnt)))))


(defun main()
  (let ((s (concatenate 'vector (read-line))))
    (princ (solve s))
    (fresh-line)))


(main)


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

int main() {
  int ans = 0;
  string S;
  cin >> S;
  for (int i = 0; i < 4; i++) {
    if (S[i] == '+') {
    	ans++;
    } else {
      ans--;
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define ll long long
#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  REP(i, N) {
    cin >> a[i];
  }
  double avg = 0;
  REP(i, N) {
    avg += a[i];
  }
  avg /= N;
  int ans;
  double res = 1e9;
  REP(i, N) {
    if(abs(a[i] - avg) < res) {
      ans = i;
      res = abs(a[i] - avg);
    }
  }
  REP(i, N) {
    if(abs(a[i] - avg) == res) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <string>
using namespace std;
char s[99];
main(){
	vector<pair<string,int> >v;
	int n,t,t1,t2,x,y;
	scanf("%d%d",&n,&t);
	scanf("%d:%d %s",&x,&y,s);
	for(n--;n--;){
		scanf("%d:%d %s",&x,&y,s);t1=x*60+y;
		scanf("%d:%d %s",&x,&y,s);t2=x*60+y;
		if(t2-t1>=t)v.push_back(make_pair(s,t2-t1));
	}
	printf("%d\n",v.size());
	for(n=0;n<v.size();n++)printf("%s %d\n",v[n].first.c_str(),v[n].second);
}

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


int main()
{
    int n,m,j,k=0;
    cin>>n;
    int arr[n-1];
    int a[n];
    for(int i=0;i<n;i++)
    {
        a[i]=0;
    }

    for(int i=0;i<n-1;i++)
    {
        cin>>arr[i];
        j=arr[i]-1;
        a[j]++;

    }

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




    return 0;
}


Measured memory_bytes: 5196
def main():
    N = int(input())
    comb_count = [[0 for i in range(10)] for j in range(10)]
    res = 0

    for i in range(1, N + 1):
        s = str(i)
        max, min = int(s[0]), int(s[-1])
        comb_count[max][min] += 1

    for l in range(1, 10):
        for r in range(1, 10):
            res += comb_count[l][r] * comb_count[r][l]
        
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9152
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int A = 0;
    int[] xx = new int[n];
    for (int i = 0; i < n; i++) {
      int x = sc.nextInt();
      xx[i] = x;
      A += x;
    }
    int p = A/n;
    int p1 = p+1;
    int B = 0;
    int B1 = 0;
    for (int i = 0; i < n; i++){
      B += Math.pow((xx[i]-p), 2);
      B1 += Math.pow((xx[i]-p1), 2);
    }
    System.out.println(Math.min(B, B1));
  }
}

Measured memory_bytes: 35856
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N,K;
    cin >> N >> K;
    string S;
    cin >> S;
    if(S[K-1] == 'A'){
        S[K-1] = 'a';
    }else if(S[K-1] == 'B'){
        S[K-1] = 'b';
    }else{
        S[K-1] = 'c';
    }
    
    cout << S << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <queue>

using namespace std;

int n;
int vertex[101];
int graph[101][101];
int dis[101];

queue<int> Q;

int main() {
	cin >> n;
	int k,d;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			graph[i][j] = -1;
		}
		dis[i] = -1;
	}


	for (int i = 1; i <= n; ++i) {
		cin >> vertex[i] >> k;
		for (int j = 0; j < k; ++j) {
			cin >> d;
			graph[i][d] = 1;
		}
	}

	Q.push(1);
	dis[1] = 0;

	while (!Q.empty()) {
		k = Q.front();
		Q.pop();
		for (int i = 1; i <= n; ++i) {
			if (graph[k][i] == 1 && dis[i] == -1) {
				Q.push(i);
				dis[i] = dis[k]+1;
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		cout << i << ' ' << dis[i] << endl;
	}
	return 0;
}


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

int main(){
    int a;
    string s;
    cin >> a >> s;
    if(a >= 3200){
        cout << s << endl;
    } else {
        cout << "red" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
void trace(int A[],int N){
 int i;
 for(i=0;i<N;i++){
  if(i>0)printf(" ");
  printf("%d",A[i]);
  }
 printf("\n");
}

void insertionSort(int A[], int N){
 int j,i,v;
 for(i=1;i<N;i++){
  v=A[i];
  j=i-1;
  while(j>=0 && A[j]>v){
   A[j+1]=A[j];
   j--;
   }
  A[j+1]=v;
  trace(A,N);
 }
}

int main(){
 int N,i,j;
 int A[100];

 scanf("%d",&N);
 for(i=0;i<N;i++)scanf("%d",&A[i]);

 trace(A,N);
 insertionSort(A,N);
 
 return 0;
}

Measured memory_bytes: 2672
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int dx[] = {1,1,0,0,0,0,1,2,3,0,-1,-1,1,1,2,0,1,1,1,0,-1};
	int dy[] = {0,1,1,1,2,3,0,0,0,1,1,2,0,1,1,1,1,2,0,1,1};
	string abc = " ABCDEFG";
	string map[8];
	while (cin >> map[0]){
		
		for (int i = 1; i < 8; i++){
			cin >> map[i];
		}
		int cnt = 0;
		int flag = 0;
		for (int i = 0; i < 8; i++){
			for (int i2 = 0; i2 < 8; i2++){
				if (map[i][i2] == '1'){
					for (int i3 = 1; i3 <= 21; i3++){
						int x = i2 + dx[i3 - 1];
						int y = i + dy[i3 - 1];
						if (x >= 0 && x < 8 && y >= 0 && y < 8 && map[y][x] == '1'){
							cnt++;
						}
						if (i3 % 3 == 0){
							if (cnt == 3){
								flag = i3 - 1; cout << abc[(i3) / 3] << endl;
								cnt = 0;
							}
							cnt = 0;
						}
					}
				}
			}
		}
	}
}

Measured memory_bytes: 1188
#import time
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p



n, k = map(int, input().split())
#start = time.time()
p = 10 ** 9 + 7
N = n
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

#elapsed_time = time.time() - start
#print("elapsed_time:{0}".format(elapsed_time) + "[sec]")

aki = [0] * n
aki[0] = 1
for i in range(1, min(k+1, n)):
    # aki ni suru heya
    aki[i] = cmb(n, i, p)
    # ireru heya
    tmp = fact[n-1]*pow(fact[i], p-2, p)*pow(fact[n - i - 1], p-2, p)
    aki[i] = (aki[i] * tmp) % p
#print(aki)
ans = 0
for a in aki[:k+1]:
    ans = (ans + a) % p
print(ans)
##print(aki)
#for i in range(len(aki)-1):
#    print(aki[i+1]/sum(aki[:i+1]))



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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n;
	cin >> n;
	cout << (n + 1) / 2 << endl;
    
    return 0;
}



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

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

int main()
{
  int x,y;
  cin >>x >>y;

  for(int i=0;i<=x;i++)
  {
    for(int k=0;k<=x;k++)
    {
      if((i*2+k*4)==y&&(i+k)==x)
      {
      printf("Yes\n");
      return 0;
    }
    }
  }
  printf("No\n");
  return 0;

}


Measured memory_bytes: 3620
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

n = int(input())
aaa = get_nums_l()

counts = [0] * (n+1)
patterns = [0] * (n+1)

for a in aaa:
    counts[a] += 1

for i in range(n+1):
    m = counts[i]
    patterns[i] = m * (m-1) // 2

all_patterns = sum(patterns)

for a in aaa:
    ans = all_patterns - patterns[a]
    ans += (counts[a]-1) * (counts[a]-2) // 2
    print(ans)


Measured memory_bytes: 84444
#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>
using namespace std;
int main(){
  int x,y,z,i,j,k;
  cin >> x >> y >> z >> k;
  vector<long int>a(x);
  vector<long int>b(y);
  vector<long int>c(z);
  vector<long int>f(x*y);
  vector<long int>s(k*z);
  for(i=0;i<x;i++) cin >> a.at(i);
  for(i=0;i<y;i++) cin >> b.at(i);
  for(i=0;i<z;i++) cin >> c.at(i);
  for(i=0;i<x;i++) for(j=0;j<y;j++) f.at(y*i+j)=a.at(i)+b.at(j);
  sort(f.begin(),f.end());
  for(i=0;i<min(x*y,k);i++) for(j=0;j<z;j++) s.at(z*i+j)=f.at(x*y-i-1)+c.at(j);
  sort(s.begin(),s.end());
  for(i=0;i<k;i++) cout << s.at(k*z-i-1) << endl;
}

Measured memory_bytes: 31616
#include <bits/stdc++.h>
    
#define int long long

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
    
using namespace std;

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

int32_t main(){
    int n, m, t;
    cin >> n >> m;
    t=n-m;

    cout << (1900*m+100*t)*pow(2, m) << endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

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

  if (N % 2 == 0) {
    cout << (N * (N - 1) / 2) - (N / 2) << endl;
    FOR(i, 1, N + 1) FOR(j, 1, i) {
      if (i + j != N + 1)
        cout << j << " " << i << endl;
    }
  } else {
    cout << (N * (N - 1) / 2) - (N / 2) << endl;
    FOR(i, 1, N + 1) FOR(j, 1, i) {
      if (i + j != N)
        cout << j << " " << i << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 888
package main

import "fmt"

func main() {
  var X int
  fmt.Scanf("%d\n", &X)
  
  for b := 0; ; b++ {
    b5 := b * b * b * b * b
    aX := X + b5
    for i := 1; ; i++ {
      i5 := i * i * i * i * i
      if i5 > aX {
        break
      }
      if i5 == aX {
        fmt.Println(i, b)
        return
      }
    }
    
    neg := 0
    sX := X - b5
    if sX < 0 {
      neg = 1
      sX *= -1
    }
    for i := 1; ; i++ {
      i5 := i * i * i * i * i
      if i5 > sX {
        break
      }
      if i5 == sX {
        if neg == 0 {
        	fmt.Println(i, -b)
        }else{
          fmt.Println(-i, -b)
        }
        return
      }
    }
  }
}

Measured memory_bytes: 1816
import sys
input = sys.stdin.readline
n = int(input())
iptls = [list(map(int,input().split())) for i in range(n)]
a,b = zip(*iptls)
if a == b:
  print(0)
  exit()
ans = 10**18
for i in range(n):
  if a[i]>b[i]:
    ans = min(ans,b[i])
print(sum(b)-ans)

Measured memory_bytes: 9588
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
 
int main(){
  int c[3][3];
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
      cin >> c[i][j];
  bool flag=false;
  int a[3];
  int b[3];
  for(a[0]=0;a[0]<=c[0][0];a[0]++){
    b[0]=c[0][0]-a[0];
    b[1]=c[0][1]-a[0];
    b[2]=c[0][2]-a[0];
    a[1]=c[1][0]-b[0];
    a[2]=c[2][0]-b[0];
    bool flag2=true;
    for(int i=1;i<3;i++){
      for(int j=1;j<3;j++){
        if(c[i][j]!=a[i]+b[j])flag2=false;
      }
  }
    if(flag2){
      flag=true;
      break;
    }
  }
  if(flag){
    cout<<"Yes" <<endl;
  }else{
    cout << "No" <<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

int main() {
  string key = "MARCH";
  vector<ll> c(5, 0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < 5; j++) {
      if (s[0] == key[j]) c[j]++;
    }
  }
  ll ans = 0;
  for (int i = 0; i < 5; i++) {
    for (int j = i + 1; j < 5; j++) {
      for (int k = j + 1; k < 5; k++) {
        ans += c[i] * c[j] * c[k];
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define LENGTH 256

int main(void) {
    int MONEY;
    scanf("%d", &MONEY);

  if(MONEY>=1,MONEY<=10000){
    int AMARI;
    int OTURI;
    if(MONEY<1000){
      AMARI=MONEY;
      OTURI=1000-AMARI;
      if(OTURI==1000){
        printf("0");
      }else{
      printf("%d\n", OTURI);
    }
    }else{
      AMARI=MONEY%1000;
      OTURI=1000-AMARI;
      if(OTURI==1000){
        printf("0");
      }else{
      printf("%d\n", OTURI);
    }
    }

  }else{
  }
}


Measured memory_bytes: 1708
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
    #include <filesystem>
    namespace fs = std::filesystem;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

string s;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path __p = __FILE__;
        fs::path __input, __output;
        __input = __output = __p.parent_path();
        __input += string("/input/") + string(__p.stem()) + string(".txt");
        __output += string("/output/") + string(__p.stem()) + string(".txt");
        freopen(__input.c_str(), "r", stdin);
        freopen(__output.c_str(), "w", stdout);
    #endif
    cin >> s;
}

int solve(){
    string ans;
    for (int i = 0; i < s.length(); i++)
    {
        if(s[i]!='B') ans+=s[i];
        else ans = ans.substr(0,ans.length()-1);
    }
    cout << ans << endl;
    
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
  int m;
  cin >> m;
  for(int i=0; i<m;i++){
    int money,year,n,input;
    cin >> money;
    cin >> year;
    cin >> n;
    double s[n][3];
    int t[n];
    for(int j=0;j<n;j++){
      cin >> s[j][0] >> s[j][1] >> s[j][2];
      input = money;
      t[j] = 0;
      if(s[j][0] == 0){
        for(int l=0;l<year;l++){
          t[j] += (int)floor(input * s[j][1]);
          input -= (int)s[j][2];
        }
      }else if(s[j][0] == 1){
        for(int l=0;l<year;l++){
          input = input + (int)floor(input * s[j][1]) - (int)s[j][2];
        }
      }
      t[j] += input;
    }
    int max=0;
    for(int j=0;j<n;j++){
      if(max < t[j]){
        max = t[j];
      }
    }
    cout << max <<endl;
  }
}

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr int INF = 1001001001;
//constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;


int main() {
  int n,k; cin >> n >> k;
  vi h(n);
  rep(i,n) cin >> h[i];
  sort(all(h));
  int ans = INF;
  for(int i = 0; i+k-1 < n; i++){
    chmin(ans,h[i+k-1]-h[i]);
  }
  
  cout << ans << endl;

}



Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>
#define mod  1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;

using ll = long long;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  string s, ss;
  cin >> s, ss = s;
  if(s == "zyxwvutsrqponmlkjihgfedcba"){cout << -1 << endl; return 0;}
  if(s.size() == 26){
    next_permutation(all(s));
    for(int i = 0; i < s.size(); i++){
      if(s[i] != ss[i]){
	s = s.substr(0, i + 1);
      }
    }
  }else{
    for(int i = 0; i < 26; i++){
      if(s.find('a' + i) == string::npos) {
	s += 'a' + i;
	break;
      }
    }
  }
  if(s == ss) cout << -1 << endl;
  else cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
# E
from collections import deque
import numpy as np

N, M = map(int, input().split())
G = dict()
for i in range(1, N+1):
    G[i] = dict()
    for j in range(1, N+1):
        if i != j:
            G[i][j] = 1
            
for _ in range(M):
    a, b = map(int, input().split())
    _ = G[a].pop(b)
    _ = G[b].pop(a)
    
res_con = []

done_list = [1] + [0]*N



core = 1

while core != 0:
    
    # BFS
    queue = deque([core])    
    res_flag = True
    
    size_a = 1
    size_b = 0

    done_list[core] = 1
    while len(queue) > 0:
        a = queue.popleft()
        for b in G[a].keys():
            if done_list[b] == done_list[a]:
                res_flag = False
                break
            elif done_list[b] == 0:
                done_list[b] = -1*done_list[a]
                if done_list[a] == 1:
                    size_b += 1
                else:
                    size_a += 1
                queue.append(b)
    
    res_con.append([size_a, size_b])
    
        
    if res_flag == False:
        break
        
    
    core = 0
    for i in range(1, N+1):
        if done_list[i] == 0:
            core = i
            break
            
# summarize
if res_flag == False:
    res = 0
else:
    res_can_s = np.array([0])
    for rr in res_con:
        a = rr[0]
        b = rr[1]
        res_can_s = np.unique(np.concatenate([res_can_s + a, res_can_s + b]))
    res = ((res_can_s*(res_can_s - 1) // 2) + ((N - res_can_s)*(N - res_can_s - 1) // 2)).min()

if res_flag == False:
    print(-1)
else:
    print(res)

Measured memory_bytes: 55652
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <queue>
#include <cmath>
#include <iomanip>
#include <cstdlib>
// #include <fstream>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long mod = 1e9 + 7;
const int INF32 = INT32_MAX;

const int MAX_N = 100010;
long long int dp[MAX_N] = {0};

int main()
{
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    
    int N, M; std::cin >> N >> M;
    
    std::vector<bool> str(N+1, true);
    
    for(int i=0; i<M; i++)
    {
        int a;
        std::cin >> a;
        str[a] = false;
    }
    dp[0] = 1;
    for(int now=0; now<N; now++)
    {
        for(int next=now+1; next<=std::min(N, now+2); next++)
        if(str[next])
        {
            dp[next] += dp[now];
            dp[next] %= mod;
        }
    }

    std::cout << dp[N] << std::endl;

    return 0;
}


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

pair<int, int> dp[109][50009]; int n, x[109], g[109];

int main() {
	while (true) {
		cin >> n; if (n == 0) break;
		for (int i = 1; i <= n; i++) { cin >> x[i]; g[i] = x[i]; x[i] %= 1000; }

		for (int i = 1; i <= n + 1; i++) { for (int j = 0; j <= n * 500; j++) dp[i][j] = make_pair(-1, -1); }

		dp[1][0] = make_pair(0, 0);

		for (int i = 1; i <= n; i++) {
			for (int j = 0; j <= n * 500; j++) {
				if (dp[i][j] == make_pair(-1, -1)) continue;

				dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);

				if (x[i] == 0) {
					// 何もできない
					if (j >= 500) dp[i + 1][j - 500] = max(dp[i + 1][j - 500], make_pair(dp[i][j].first + 1, dp[i][j].second - g[i]));
				}
				else if (x[i] >= 1 && x[i] <= 500) {
					// 1000 円支払う
					dp[i + 1][j + (1000 - x[i]) % 500] = max(dp[i + 1][j + (1000 - x[i]) % 500], make_pair(dp[i][j].first + 1, dp[i][j].second - g[i]));
				}
				else {
					// 1000 円支払う
					if (j - (x[i] - 500) >= 0) {
						dp[i + 1][j - (x[i] - 500)] = max(dp[i + 1][j - (x[i] - 500)], make_pair(dp[i][j].first + 1, dp[i][j].second - g[i]));
					}
					else {
						dp[i + 1][j + (1000 - x[i]) % 500] = max(dp[i + 1][j + (1000 - x[i]) % 500], make_pair(dp[i][j].first, dp[i][j].second - g[i]));
					}
				}
			}
		}
		pair<int, int>maxn = make_pair(-1, -1);
		for (int i = 0; i <= 50000; i++) maxn = max(maxn, dp[n + 1][i]);
		cout << maxn.first << " " << -maxn.second << endl;
	}
	return 0;
}


Measured memory_bytes: 42528
/*input
1000000
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=1e6+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=3.14159265358979323846;
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define MP make_pair
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
int cnt[maxn];
int lp[maxn];
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n;
    cin>>n;
    REP1(i,maxn){
        lp[i]=i;
    }
    for(int i=2;i<maxn;i++){
        if(lp[i]==i){
            for(int j=i*2;j<maxn;j+=i){
                if(lp[j]==j) lp[j]=i;
            }
        }
    }
    ll ans=0;
    REP1(i,n-1){
        int z=i;
        map<int,int> mp;
        while(z>1){
            mp[lp[z]]++;
            z/=lp[z];
        } 
        ll cnt=1;
        for(auto x:mp){
            //cout<<x.s<<'\n';
            cnt*=(x.s+1);
        }
        ans+=cnt;
    }
    cout<<ans;
}  


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

using namespace std;

const int N = 1e5+20,M=1e5+20;;

typedef long long ll;
ll v[N],w[N],f[M];

int main()
{
	ll n,W;
	cin>>n>>W;
	for(int i=1;i<=n;i++)
	cin>>w[i]>>v[i];
	memset(f,0x3f,sizeof(f));
	f[0]=0;
	
	
	for(int i=1;i<=n;i++)
	{
		for(int j=1e5;j>=v[i];j--)
		{
			f[j]=min(f[j],f[j-v[i]]+w[i]);
		}
	}
	ll ans=0;
	for(int i = 1;i<=1e5;++i) if(f[i]<=W) ans = max(ans,1ll*i);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

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

	int x = 0, cnt = 0;
	for (int i = 0; i < N; i++) {
		int n;
		cin >> n;
		if (n >= x) cnt++;
		x = max(n, x);
	}

	cout << cnt << endl;
}

Measured memory_bytes: 3620
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int[] d = new int[a];
        int ans = 0;
        for(int i=0;i<b;i++){
            int c = scan.nextInt();
            for(int l=0;l<c;l++){
                int e = scan.nextInt();
                d[e-1] +=1;
            }
        }
        for(int l=0;l<a;l++){
            if(d[l]==0){
                ans++;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 46416
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int c = sc.nextInt();
		
		int[] b = new int[m];
		
		for (int i = 0; i < m; i++) {
			b[i] = sc.nextInt();
		}
		
		int count = 0;
		
		for (int i = 0; i < n; i++) {
			long sum = c;
			for (int j = 0; j < m; j++) {
				sum += b[j] * sc.nextInt();
			}
			if(sum > 0) {
				++count;
			}
		}
		
		System.out.println(count);
	}
}


Measured memory_bytes: 23380
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
      // 整数の入力
      int a = sc.nextInt();
      // b
      int b = sc.nextInt();
      // c
      int c = sc.nextInt();
      if (a < b) {
         int temp = a;
         a = b;
         b = temp;
      }
      if (a < c) {
         int temp = a;
         a = c;
         c = temp;
      }
    System.out.println(a * 10 + b + c);
  }
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

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

using i64=int64_t;

void solve(){
    int N;
    i64 K;
    cin >> N >> K;
    vector<pair<int,i64>> ps;
    rep(i,0,N){
        int a;
        i64 b;
        cin >> a >> b;
        ps.push_back(make_pair(a,b));
    }
    i64 s=0;
    sort(ps.begin(),ps.end());
    rep(i,0,N){
        s+=ps[i].second;
        if(s>=K){
            cout << ps[i].first << endl;
            return;
        }
    }
}

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


Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

str s,t;
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>s>>t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    str temp ="";
    for(int i=t.size()-1;i>=0;i--){temp += t[i];}
    t = temp;
    if(s<t)cout<<"Yes\n";
    else{cout<<"No\n";}
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <climits>
#include <random>
#include <algorithm>

#define int_max 2147483647;

void Problem_A(void)
{
    std::string str;
    std::cin>>str;

    int a = int(str[5])-48;
    int b = int(str[6])-48;

    int month =10*a+b;
    // std::cout<<month;
    if(month >= 5)
    {
        std::cout<<"TBD";
    }
    else
    {
        std::cout<<"Heisei";
    }
    return;
}

void Problem_B(void)
{
    int N;
    std::cin>>N;
    std::vector<double> money(N);
    std::vector<std::string> kind(N);

    for(int i = 0; i < N ; i ++)
    {
        std::cin>>money[i];
        std::cin>>kind[i];
    }

    double sum = 0;

    for(int i = 0; i < N ; i ++)
    {
        if(kind[i] == "JPY")
        {
            sum += money[i];
        }
        else
        {
            sum += money[i] *380000.0;
        }
    }
    std::cout<<sum;
    return;
}
int main(int argc, char const *argv[])
{
    Problem_B();
    return 0;
}

Measured memory_bytes: 256