akhauriyash/Code-Regression huggingface dataset:
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

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

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------

        string s, t;
        cin >> s >> t;
        // 塊として等しいことが必要。
        // ただし、文字のペアは一つだけ。(map[s[i]] = t[i]で管理)
        map<char, char> mp_s;
        map<char, char> mp_tt;
        for(int i=0; i<s.length(); i++){
            mp_s[s[i]] = '0';
            mp_tt[t[i]] = '0';
        }

        int flag = 0;
        for(int i=0; i<s.length()-1; i++){
            if(s[i] != s[i+1] && t[i] == t[i+1]){
                flag = 1;
            }
            else if(s[i] == s[i+1] && t[i] != t[i+1]){
                flag = 1;
            }

            // ただし、文字のペアは一つだけ。(map[s[i]] = t[i]で管理)
            if(mp_s[s[i]] == '0'){
                mp_s[s[i]] = t[i];
            }
            else if(mp_s[s[i]] != t[i]){
                flag = 1;
            }

            if(mp_tt[t[i]] == '0'){
                mp_tt[t[i]] = s[i];
            }
            else if(mp_tt[t[i]] != s[i]){
                flag = 1;
            }
        }

        if(flag == 0) cout << "Yes";
        else cout << "No";

    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 916
use proconio::input;

fn main() {
    input! {
        x: i64
    }

    let mut mon: i64 = 100;
    let mut cou: i32 = 0;

    while mon < x {
        mon = mon + mon / 100;
        cou = cou + 1;
    }
    println!("{}", cou);
}

Measured memory_bytes: 2156
use std::error::Error;
use std::io;

fn main() {
    if let Err(e) = run() {
        println!("{}", e);
    }
}

fn run() -> Result<(), Box<Error>> {
    let mut n = String::new();
    io::stdin().read_line(&mut n)?;
    let n = n.trim().as_bytes();
    if n[0] == n[2] {
        println!("Yes");
    } else {
        println!("No");
    }
    Ok(())
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A;
  cin >> N >> A;
  int B;
  B = N % 500;
  if (B <= A){
	cout << "Yes" << endl;
  }
  else{
	cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    string s; cin >> s;
    ll r=0,g=0,b=0;
    REP(i,n) {
        if (s[i] == 'R') r++;
        else if (s[i] == 'G') g++;
        else b++;
    }

    ll ans = r * g * b;

    REP(i,n) FOR(j,i+1,n) {
        if (s[i] == s[j]) continue;
        int k = 2 * j - i;
        if (k >= n) continue;
        if (s[j] == s[k] || s[k] == s[i]) continue;
        ans--;
    } 

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 3652
import math

N = int(input())
N_max = math.floor(pow(N, 0.5))

ans = math.floor(math.log10(N)) + 1

for i in range(1, N_max+1):
    if N % i == 0:
        M = N / i
        digI = math.floor(math.log10(i)) + 1
        digM = math.floor(math.log10(M)) + 1
        if digI >= digM:
            score = digI
        else:
            score = digM

        if score <= ans:
            ans = score

print(ans)

Measured memory_bytes: 3188
L, R = map(int, input().split())
mod = 2019

if R - L >= 2018:
    print(0)
elif R - L == 1:
    print(((L % mod) * (R % mod)) % mod)
else:
    m = 2019
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            m = min(m, ((i % mod) * (j % mod)) % mod)
    print(m)

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

using namespace std;

typedef int weight;

class Edge {
    public:
        int s_,t_;
        weight w_;
        Edge(int s, int t, weight w):s_(s), t_(t), w_(w) {}
};

class Graph {
    public:
        vector<vector<Edge>> edge_;
        Graph(int N) {
            edge_.resize(N);
        }
        void addEdge(int s, int t, weight w) {
            edge_[s].push_back(Edge(s, t, w));
        }
};

void dfs(int now, int prev, int color, vector<int> &colorbox, Graph &g) {
    colorbox[now] = color;
    vector<Edge> &es = g.edge_[now];
    for (int i=0;i<(int)es.size();i++) {
        if (es[i].t_ == prev) continue;
        int w = es[i].w_;
        if (w%2) {
            dfs(es[i].t_, now, color^1, colorbox, g);
        } else {
            dfs(es[i].t_, now, color, colorbox, g);
        }
    }
    return;
}

int main(){
    int N;cin>>N;
    vector<int> ans(N);
    Graph g(N);
    for (int i=1;i<N;i++) {
        int u, v, w;
        cin>>u>>v>>w;
        u--,v--;
        g.addEdge(u,v,w);
        g.addEdge(v,u,w);
    }
    dfs(0,-1,0,ans,g);
    for (int i=0;i<N;i++) {
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 10496
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
  int a,b;string s;
  cin >> a >> b >> s;
  int n = s.size();
  for(int i = 0; i < a; ++i){
    if(s[i]=='-'){
      cout << "No" << endl;
      return 0;
    }
  }
  if(s[a]!='-'){
    cout << "No" << endl;
    return 0;
  }
  for(int i = 0; i < b; ++i){
    int j = a+i+1;
    if(s[j]=='-'){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main
{
    public static void main(String[] args) {
      Scanner s = new Scanner(System.in);
     int h = s.nextInt();
     int n = s.nextInt();
      int a[] = new int[n];
      int sum=0;
      for(int i = 0; i < n; i++)
        {
            a[i] = s.nextInt();
            sum = sum + a[i];
        }
      if(sum>=h){
      System.out.println ("Yes");
      }
    else
    {
    System.out.println ("No");
    }
    
    }
}

Measured memory_bytes: 50468
//
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <array>
#include <numeric>
#include <functional>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <complex>

using namespace std;

#define REP(i,m,n) for(int i=m;i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define ALL(x) (x).begin(),(x).end()

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

int main(){

	int n,k;
	string s;
	cin >> n >> k >> s;
	char t = s[k-1];
	s[k-1] = tolower(t);
	cout << s << endl;

	return 0;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

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

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

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

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

use std::io::{stdout, Write, BufWriter};
// use std::cmp::{max};

fn main() {
    input! {
        n: usize,
        k: u32,
        q: usize,
        a: [usize; q],
    }

    let out = stdout();
    let mut out = BufWriter::new(out.lock());

    let mut t: Vec<u32> = vec![0; n];
    for a_ in a { t[a_ - 1] += 1 }
    for i in t {
        if i + k > q as u32 { writeln!(out, "Yes").unwrap(); }
        else { writeln!(out,"No").unwrap(); }
    }
}


Measured memory_bytes: 6780
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}

ll mod_combi(ll n, ll m){
    ll tmp = mod_mul(fac[n],invfac[n-m]);
    return mod_mul(tmp,invfac[m]);
}

int main(void){

	ll n,a,b;
  cin>>n>>a>>b;
  
  cout << min(b,n*a) << endl;

  return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;

int main(){

  ll n;
  cin >> n ;

  std::vector<ll> x(n);
  std::vector<ll> y(n);

  ll z=0;

  for(ll i=0;i<n;i++){
    cin >> x.at(i) >> y.at(i);
    if(x.at(i)==y.at(i)){
      z++;
      if(z==3){
        cout << "Yes" << endl;
        return 0;
      }
    }
    else{
      z=0;
    }
  }

  cout << "No" << endl;


}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int n,x,ans;
string s;
int main()
{
	cin>>n>>s;
	for(int i=0;i<n;i++){
		if(s[i]=='I')x++;
		else x--;
		ans=max(ans,x);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <set>
#include <algorithm>
using namespace std;
#define LL long long
#define MX 200005

int a[55][55];

void init(){
    for (int i=1; i<=50; ++i) a[50][i]=50;
    for (int i=49; i>=0; --i){
        int ma=0, p;
        for (int j=1; j<=50; ++j) if (ma<a[i+1][j]) ma=a[i+1][j], p=j;
        for (int j=1; j<=50; ++j) {
            if (j==p) a[i][j]=a[i+1][j]-50;
            else a[i][j]=a[i+1][j]+1;
        }
    }
}
int main()
{
    LL k;
    scanf("%lld",&k);
    init();
    LL x=k%50, y=k/50;
    puts("50");
    for (int i=1; i<=50; ++i) printf(i==1?"%lld":" %lld",a[x][i]+y);
    putchar('\n');
    return 0;
}


Measured memory_bytes: 256
# encoding:utf-8
import copy
import numpy as np
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import math

N = int(input())
S = str(input())

ans = 10**6
blacks = [0 for i in range(N)]
black = 0
white = 0
for i in range(N):
    if S[i] == "#":
        black += 1

    else:
        white += 1
    blacks[i] = black

ans = min(black,white,ans)

# print(blacks)
for i in range(1,N):
    cnt = 0
    cnt += (N-(i+1))-(blacks[N-1]-blacks[i])#white
    # print("white",cnt)
    cnt += blacks[i-1]#black
    # print(cnt)
    ans = min(ans,cnt)

print(ans)


Measured memory_bytes: 28456
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

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

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

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

fn main() {
    input!{
        h: usize,
        w: usize,
        s: [String; h]
    };
    for i in s {
        println!("{}", i);
        println!("{}", i);
    }

    //println!("{}", if ret {"vowel"} else {"consonant"});

}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll GCD(ll a, ll b)
{
    if (b == 0) return a;
    else return (GCD(b, a % b));
}

ll LCM(ll a, ll b)
{
    return a = a / GCD(a, b) * b;
}

int main()
{
    ll a, b, c, d; cin >> a >> b >> c >> d;
    b = b - (b / c + b / d - b / LCM(c, d));
    a = a - 1;
    a = a - (a / c + a / d - a / LCM(c, d));
    //COUT(b);COUT(a);
    cout << b - a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()
 
 int main(){
     char s;
     cin>>s;
     if(s=='A') cout<<'T'<<endl;
     if(s=='T') cout<<'A'<<endl;
     if(s=='C') cout<<'G'<<endl;
     if(s=='G') cout<<'C'<<endl;
     return 0;
 }

Measured memory_bytes: 256
n = int(input())
AB = []
for _ in range(n):
    a,b = map(int,input().split())
    AB.append([a,b])

AB.sort(key=lambda x: x[1])

ans = "Yes"
day = 0
for i in range(n):
    day += AB[i][0]
    if day > AB[i][1]:
        ans = "No"

print(ans)

Measured memory_bytes: 38036
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int p[30];
    for(int i=1;i<=n;i++)
    {
        cin>>p[i];
    }
    int ans=0;
    for(int i=2;i<n;i++)
    {
        if((p[i]-p[i-1])*(p[i]-p[i+1])<0)
        ans++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string jia(string a,string b)
{
  int aa,bb;
  int alen=a.length();
  int blen=b.length();
  if(alen<blen)
  {
    swap(a,b);
    swap(alen,blen);
  }
  int bblen=blen;
  blen--;
  for(int i=alen-1; i>=1; i--)
  {
    if(blen>=0)
    {
      if(a[i]+b[blen]<106)
      {
        a[i]=a[i]+b[blen]-48;
      }
      else
      {
        a[i-1]++;
        a[i]=a[i]+b[blen]-58;
      }
      blen--;
    }
    else
    {
      if(a[i]>'9')
        a[i]=a[i]-10,a[i-1]++;
    }
  }
  if(bblen==alen)
  {
    aa=(int)(a[0])-48,bb=(int)(b[0])-48;
    if(aa+bb<10)
    {
      a[0]=(char)(aa+bb+48);
    }
    else
    {
      cout<<1;
      a[0]=(char)(aa+bb+38);
    }
  }
  else
  {
    if(a[0]>'9')
    {
      a[0]=a[0]-10;
      cout<<1;
    }
  }
  cout<<a<<endl;
}

int a[5001],b[5001],ans[5001];
int main()
{
  string s;
  cin>>s;
  int  ans=0;
  for(int i=1; i<s.length(); i++)
    if(s[i]!=s[i-1])ans++;
  cout<<ans;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<62);

int main() {
    cin>>K>>N;
    set<ll> have;
    rep(i,102) have.insert(i);
    ll last = INF;
    rep(i,N){
        cin>>A;
        have.erase(A);
    }
    for(ll v : have){
        if(abs(K - v) < abs(K - last)){
            last = v;
        }else if(abs(K - v) == abs(K - last) && v < last){
            last = v;
        }
    }
    cout<<last<<endl;
}

Measured memory_bytes: 3640
using System;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            int w = 0,r=0;
            for (int i = 0; i < n; i++)
            {
                if (s[i] == 'W') w++;
                else r ++;
            }
            int cnt = 0;
            for(int i = r; i < n; i++)
            {
                if (s[i] == 'R') cnt++;
            }
            Console.WriteLine(cnt);
        }
    }
}


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

bool B[531442];

int main(){
    int N;
    cin>>N;
    for(int i=0;i<N;i++){
        string s;
        cin>>s;
        for(int j=0;j<s.size();j++){
            int d=0;
            for(int k=0;k<4&&j+k<s.size();k++){
                d=d*27+(s[j+k]-'a'+1);
                B[d]=true;
            }
        }
    }
    for(int c1=1;c1<=26;c1++){
        int d1=c1;
        if(!B[d1]){
            cout<<char('a'+c1-1);
            cout<<endl;
            return 0;
        }
    }
    for(int c1=1;c1<=26;c1++){
        int d1=c1;
        for(int c2=1;c2<=26;c2++){
            int d2=d1*27+c2;
            if(!B[d2]){
                cout<<char('a'+c1-1);
                cout<<char('a'+c2-1);
                cout<<endl;
                return 0;
            }
        }
    }
    for(int c1=1;c1<=26;c1++){
        int d1=c1;
        for(int c2=1;c2<=26;c2++){
            int d2=d1*27+c2;
            for(int c3=1;c3<=26;c3++){
                int d3=d2*27+c3;
                if(!B[d3]){
                    cout<<char('a'+c1-1);
                    cout<<char('a'+c2-1);
                    cout<<char('a'+c3-1);
                    cout<<endl;
                    return 0;
                }
            }
        }
    }    
    for(int c1=1;c1<=26;c1++){
        int d1=c1;
        for(int c2=1;c2<=26;c2++){
            int d2=d1*27+c2;
            for(int c3=1;c3<=26;c3++){
                int d3=d2*27+c3;
                for(int c4=1;c4<=26;c4++){
                    int d4=d3*27+c4;
                    if(!B[d4]){
                        cout<<char('a'+c1-1);
                        cout<<char('a'+c2-1);
                        cout<<char('a'+c3-1);
                        cout<<char('a'+c4-1);
                        cout<<endl;
                        return 0;
                    }
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3896
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> (a);)
#define all(v) (v).begin(),(v).end()
#define trav(x,v) for(auto &x : v)
#define sz(v) int(v.size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;

int main(){
	cin.sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;

	vector<vi> gr(n);

	rep(_,1,n){
		int a, b;
		cin >> a >> b;
		--a, -- b;
		gr[a].push_back(b);
		gr[b].push_back(a);
	}

	vi par(n, -1), ls;

	function<void(int)> dfs = [&](int v){
		ls.push_back(v);
		trav(u, gr[v]) if(u != par[v]){
			par[u] = v;
			dfs(u);
		}
	};
	dfs(0);

	vector<pii> mxs(n);

	trav(i, ls){
		if(!i) continue;
		pii pa = mxs[par[i]];

		int A = pa.first, B = pa.second;
		if(i > A) mxs[i] = pii(i, A);
		else if(i > B) mxs[i] = pii(A, i);
		else mxs[i] = pii(A, B);
	}

	vector<bool> big(n,false), cool(n,false);
	rep(i,0,n) if(mxs[i].first==i) big[i] = true;
	rep(i,1,n) if(big[par[i]]) cool[i] = true;

	vi cop(n,-1);
	trav(i, ls){
		if(!i) continue;
		if(cool[i]) cop[i] = i;
		else cop[i] = cop[par[i]];
	}

	map<pii,int> cnt;
	map<pair<pii,int>, int> rak;

	rep(i,1,n) ++cnt[mxs[i]];
	rep(i,1,n) ++rak[make_pair(mxs[i], cop[i])];

	vi ans(n);
	rep(i,1,n) if(!big[cop[i]] && !big[i] && mxs[i] != mxs[par[cop[i]]])
		++ans[cop[i]];
	rep(i,1,n) if(big[i]){
		ans[i] += cnt[mxs[i]];
	}

	trav(i,ls) if(i) ans[i] += ans[par[i]];

	rep(i,1,n) cout << ans[i] << ' ';
	cout << endl;
}

Measured memory_bytes: 43364
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	void solve() throws IOException {
		String s = nextToken();
		int ans = 0;
		for (int i = 0; i < s.length() - 1; i++) {
			if (s.charAt(i) != s.charAt(i + 1)) {
				ans++;
			}
		}
		out.println(ans);
	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 10964
a,b,c = input().split()
A = int(a)
B = int(b)
C = int(c)
K = int(input())

for i in range(K):
	if(max(A,B,C)==A):
		A = A*2
	elif(max(A,B,C)==B):
		B = B*2
	elif(max(A,B,C)==C):
		C = C*2

sum_abc = A + B + C
print(sum_abc)

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

int n,W,ans;
int f[150][150][450],w[150],c[150];

int main()
{
	int n,W;
	cin>>n>>W;
	for (int i=0;i<n;i++) cin>>w[i]>>c[i];
	for (int i=0;i<n;i++) for (int j=0;j<=i;j++) for (int k=0;k<=3*j;k++)
	  {
		f[i+1][j][k]=max(f[i+1][j][k],f[i][j][k]);
		f[i+1][j+1][k+w[i]-w[0]]=max(f[i+1][j+1][k+w[i]-w[0]],f[i][j][k]+c[i]);
	  }
	for(int i=0; i<=n; i++) for(int j=0; j<=3*i; j++)
	  {
		long long nowW=(long long)w[0]*i+j;
		if(nowW<=W) ans=max(ans,f[n][i][j]);
	  }
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 24960
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			string s = cin.Next();
			int n = s.Length;
			int ans = 0;
			for (int i = 0; i < n / 2; i++) {
				if (s[i] != s[n - 1 - i]) {
					++ans;
				}
			}

			Console.WriteLine(ans);
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private string[] buf_;
		private int index_;
		Func<string> reader_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

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

double a, b, x;
double pi = 3.1415926535;
double rightangle = 90.0000000000;

int main() {
    cin >> a >> b >> x;

    if(x / a == a * b / 2.0) printf("%.7f", atan(1)*180.0/pi);
    else {
        if(x / a < a * b / 2.0) {
            double h = (2.0 * x) / (a * b);
            printf("%.7f", rightangle - atan(h/b)*180.0/pi);
        }

        else {
            double h = (2.0 / a) * ((a * b) - (x / a));

            printf("%.7f", atan(h/a)*180.0/pi);
        }
    }

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_lim=(n); i<i##_lim; ++i)
#define FOR(i, a, b) for (int i=(a), i##_lim=(b); i<i##_lim; ++i)
#define mp make_pair
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<int, int>;

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

    double ret = 0.0;
    FOR(i, 1, N+1)
    {
        int n = ceil(log2(ceil(K/(double)i)));
        ret += 1.0/N * pow(0.5, n);
    }

    cout << fixed;
    cout << setprecision(10) << ret << endl;
    return 0;
}

Measured memory_bytes: 384
from collections import Counter

n,k=map(int,input().split())
a=list(map(int,input().split()))

city=[0]*n
city[0]+=1
dict={}
for x in range(n-1):
  b=city[x]-1
  c=a[b]
  city[x+1]+=c
  
for y in range(n):
  d=city[y]
  e=str(d)
  if e in dict:
    check=d
    end=y
    break
  if  e not in dict:
    dict[e]=y

start=city.index(d)
w=end-start
if k<start:
  print(city[k])
  
else:
  kk=k-start
  rest=kk%w
  q=start+rest
  print(city[q])

Measured memory_bytes: 57956
#include<bits/stdc++.h>
using namespace std;
main()
{
	int n;
	cin>>n;
	vector<float> v(n);
	for(int i=0;i<n;i++)cin>>v[i];
	sort(v.begin(),v.end());
    for(int i=1;i<n;i++)
    {
    	v[i]=(v[i-1]+v[i])/2.0;

    }

    cout<<v[n-1]<<"\n";

     
                                                                                     
}

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

int N;
int routedCount = 0;
int a, b;
vector<int> P;
vector<int> Q;

void calc(vector<bool> passed, vector<int> route, int passedCount) {
    if (passedCount == N) {
        routedCount++;
        bool isA = true, isB = true;
        for (int i = 0; i < N; i++) {
            if (!isA && !isB) return;
            if (route[i] != P[i]) isA = false;
            if (route[i] != Q[i]) isB = false;
        }
        if (isA) a = routedCount;
        if (isB) b = routedCount;
        return;
    }

    for (int i = 0; i < N; i++) {
        if (passed[i]) continue;
        passed[i] = true;
        route[passedCount] = i + 1;
        calc(passed, route, passedCount + 1);
        passed[i] = false;
    }
}

int main() {
    cin >> N;
    int p, q;
    for (int i = 0; i < N; i++) {
        cin >> p;
        P.push_back(p);
    }
    for (int i = 0; i < N; i++) {
        cin >> q;
        Q.push_back(q);
    }

    for (int i = 0; i < N; i++) {
        vector<bool> passed(N, false);
        passed[i] = true;
        vector<int> route(N);
        route[0] = i + 1;
        calc(passed, route, 1);
    }
    cout << abs(a - b);
}


Measured memory_bytes: 3644
import math

n=int(input())
alist = [int(i) for i in input().split()]
alist=sorted(alist)

keta=math.floor(math.log(max(alist[-1],1), 2))+1
zeros=[0]*keta
ones=[0]*keta

for al in alist:
    kaz2=bin(al)[2:]
    kaz2=(keta-len(kaz2))*'0'+kaz2
    for i in range(keta):
        if kaz2[i]=='1':
            ones[i]+=1
        else:
            zeros[i]+=1

answer=0
for i in range(keta):
    tas=ones[-i-1]*zeros[-i-1]
    tas*=((2**i)%(10**9+7))
    answer+=tas%(10**9+7)

print(answer%(10**9+7))

Measured memory_bytes: 123056
import java.io.*;
import java.util.*;
 
class Main {
    public static void main(String args[]){
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    try {
        String s = r.readLine();
        int num = Integer.valueOf(s);
        while(num != 0){
        int result = 0;
        for(int i = 1;i< num; i++){
            int tmp = i;
            int next = i+1;
            while(tmp < num){
            tmp = tmp + next;
            next++;
            }
            if(tmp == num) result++;
        }
        System.out.println(result);
        s = r.readLine();
                num = Integer.valueOf(s);
        }
    }catch(Exception e){}
 
    }
}

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

int main() {
	int n,k;
	cin>>n>>k;
	cout<<fixed<<setprecision(10);
	double ans = 0.0;
	int cnt = 0,tmp;
	for(int i=1; i<=min(n,k-1); i++){
	    tmp = i;
	    cnt = 0;
	    while(tmp<k){
	        cnt++;
	        tmp*=2;
	    }
	   // cout<<cnt<<" ";
	    ans+=pow(0.5,cnt);
	}
	
	if(n<k){
	    ans/=n;
	}else {
	    ans = ans/n;
	    ans+=((double)(n-k+1))/n;
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <iostream> 
#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

#define For(i , a , b) for (int i = a , _b = b ; i <= _b ; ++i)
#define Ford(i , a  ,b) for (int i = a , _b = b : i >= _b ; --i)
#define Rep(i , n) for (int i = 0 , _n = n ; i < _n ; ++i)
#define sz(A) ((int)A.size())
#define LL(x) (x << 1)
#define RR(x) ((x << 1) | 1)

typedef pair<int , int> pt;
const int maxn = 300 + 3;
int n, m;
pt q[maxn];
int x[maxn];
#define fi first
#define se second
vector<int> con[maxn];

void ReadData() {
	cin >> n >> m;
	For(i,1,m) cin >> q[i].fi >> q[i].se >> x[i];
	For(i,1,m) con[q[i].se].push_back(i);
}

const int md = 1e9 + 7;
int dp[2][3][maxn][maxn];
void add(int &a, int b) {
	a += b;
	if (a >= md) a -= md;
}

void Process() {
	memset(dp,0,sizeof(dp));
	dp[0][0][0][0] = 1;
	int cur = 0, nex;
	For(i,0,n - 1) {
		nex = cur ^ 1;
		For(c,0,2) For(u,0,i + 1) For(v,0,i + 1) dp[nex][c][u][v] = 0;
		For(c,0,2) For(u,0,i) For(v,0,i) {
			if (!dp[cur][c][u][v]) continue;
			int first0 = (c == 0 ? i : u);
			int first1 = (c == 1 ? i : (c == 0 ? u : v));
			int first2 = (c == 2 ? i : v);
			For(p,0,2) { /// try to put color p at i + 1
				int newFirst0 = first0;
				int newFirst1 = first1;
				int newFirst2 = first2;
				if (p == 0) newFirst0 = i + 1;
				if (p == 1) newFirst1 = i + 1;
				if (p == 2) newFirst2 = i + 1;
				bool ok = true;
				for (int id : con[i + 1]) {
					int lseg = q[id].fi, rseg = i + 1;
					int cnt = 0;
					if (newFirst0 >= lseg) ++cnt;
					if (newFirst1 >= lseg) ++cnt;
					if (newFirst2 >= lseg) ++cnt;
					if (cnt != x[id]) {
						ok = false;
						break;
					}
				}
				if (!ok) continue;
				if (p == 0) {
					add(dp[nex][0][newFirst1][newFirst2], dp[cur][c][u][v]);
				}
				if (p == 1) {
					add(dp[nex][1][newFirst0][newFirst2], dp[cur][c][u][v]);
				}
				if (p == 2) {
					add(dp[nex][2][newFirst0][newFirst1], dp[cur][c][u][v]);
				}
			}
		}
		cur = nex;
	}

	int res = 0;
	Rep(c,3) For(u,0,n) For(v,0,n)  add(res, dp[cur][c][u][v]);

	cout << res << endl;
}

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

//	freopen("input.inp" , "r" , stdin);
	ReadData();
	Process();

	return 0;

}			

Measured memory_bytes: 2560
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]

S = sum(A)
D = Counter(A)

for b, c in BC:
    s = c - b
    nb = D[b]
    S += nb * s
    print(S)
    D[b] = 0
    D[c] += nb


Measured memory_bytes: 40404
from collections import Counter

n, k = map(int, input().split())
s = list(map(int, input().split()))

num = Counter(s)


if len(num) <= k:
    print(0)

else:
    cnt = len(num) - k
    ans = 0
    i = 0
    for v in sorted(num.values()):
        if cnt == i:
            break
        ans += v
        i += 1

    print(ans)

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

int main() {
	// your code goes here
	string s,t;
	cin>>s>>t;
	int n,m,i,j;
	n=s.length();
	m=t.length();
	string ans="";
	int dp[n+1][m+1];
	for(i=0;i<=n;i++)
		dp[i][0]=0;
	for(j=0;j<=m;j++)
		dp[0][j]=0;
	bool add[m];
	memset(add,false,sizeof(add));
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			if(s[i-1]==t[j-1])
			{
				dp[i][j]=dp[i-1][j-1]+1;
				
			}
			else
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
	i=n;j=m;
	//cout<<dp[n][m]<<endl;
	while(i>0 && j>0)
	{
		if(s[i-1]==t[j-1])
		{
			ans+=s[i-1];
			i--;
			j--;
			
		}
		else if(dp[i-1][j]>dp[i][j-1])
			i--;
		else
			j--;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> data(n);
  for(int i = 0; i < n; i++){
    cin >> data.at(i);
  }
  int m = 0;
  for(int i = 0; i < n; i++){
    if(m == 1){
      cout << i << endl;
      return 0;
    }
    m = data.at(m) - 1;      
  }
  cout << -1 << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>

int main(){
    char ch;
    
    do {
      scanf("%c", &ch);
      
      if(ch >= 'A' && ch <= 'Z')
      {
        ch = ch + 32; 
      }
      else if (ch >= 'a' && ch <= 'z')
      {
          ch = ch - 32;
      }
      
      printf("%c", ch);
    } while (ch != '\n');
    
    return 0;
}


Measured memory_bytes: 2100
def main():
    X, Y, A, B, C = list(map(int, input().split(' ')))
    P = list(map(int, input().split(' ')))
    Q = list(map(int, input().split(' ')))
    R = list(map(int, input().split(' ')))
    P.sort(reverse=True)
    Q.sort(reverse=True)
    R = R + P[:X] + Q[:Y]
    R.sort(reverse=True)
    print(sum(R[:(X+Y)]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 23328
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second
template <typename A, typename B> inline bool chmax(A &a, B b) {if (a < b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline bool chmin(A &a, B b) {if (a > b) {a = b; return 1;} return 0;}
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const bool debug = 0;
/****************************/

struct SyntaxAnalysis {
	string s;
	int i;
	int val;
	
	int init(string _s) {
		s = _s;
		i = 0;
		
		val = expr(i);
		return val;
	}
	
	int expr(int &i) {
		int res = 0;
		if (s[i] >= '0' && s[i] <= '9') {
			res = s[i] - '0';
		}
		else {
			res = term(++i);
			++i;
		}
		return res;
	}
	
	int term(int &i) {
		int ope;
		if (s[i] == '+') ope = 0;
		else if (s[i] == '*') ope = 1;
		else ope = 2;
		
		int val1 = expr(++i);
		int val2 = expr(++i);
		
		int res;
		if (ope == 0) res = val1 | val2;
		else if (ope == 1) res = val1 & val2;
		else res = val1 ^ val2;
		return res;
	}
};

string make(int i) {
	string num = to_string(i);
	reverse(ALL(num));
	while (num.size() < 4) num += '0';
	reverse(ALL(num));
	return num;
}

string arrange(string str, string num) {
	REP(i, str.size()) {
		if (str[i] >= 'a' && str[i] <= 'd') {
			str[i] = num[str[i]-'a'];
		}
	}
	return str;
}

int main() {
	string s;
	while (cin >> s, s != ".") {
		string num;
		cin >> num;
		
		string tmp = arrange(s, num);
		
		SyntaxAnalysis sa;
		int hsorg = sa.init(tmp);
		
		int ans = 0;
		REP(i, 10000) {
			string cur = make(i);
			if (hsorg == sa.init(arrange(s, cur))) {
				ans++;
			}
		}
		
		if (debug) printf("@ ");
		cout << hsorg << " " << ans << endl;
	}
	return 0;
}

// C


Measured memory_bytes: 3140
#include <vector>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <string>
#include <queue>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define RANGE(i,min,max) for(int i=(min), i##_len=((max)+1); i<i##_len; ++i)

constexpr int INF = 1e6;
int H, W;

vector<string> svv;
vector<vector< int>> dist;

inline bool is_in(const int x, const int y){
    return (0 <= x) && (x < W) && (0 <= y) && (y < H);
}

inline bool is_white(const int x, const int y){
    return svv[y][x] == '.';
}


inline bool check(const int x, const int y){
    if(is_in(x, y)) return is_white(x,y);
    else return false;
}

void movePos(const int x, const int y, const int dx, const int dy, queue<pair<int,int>>& que){
    int nx=x+dx, ny=y+dy;
    if(check(nx, ny)){
        svv[ny][nx] = '#';
        dist[ny][nx] = dist[y][x] + 1;
        que.push({nx, ny});
    }
}


int main(){
    cin >> H >> W;
    svv.resize(H);
    dist.resize(H, vector<int>(W));
    for(vector<int>& dis: dist) for(int& di: dis) di = INF;
    dist[0][0] = 0;
    
    int initBs =0;
    for(string& sv: svv) cin >> sv;
    for(string& sv:svv)for(char& s: sv) if(s=='#') ++initBs;

    svv[0][0] = '#';
    pair<int, int> init {0,0}, cp;

    queue<pair<int, int>> que;
    que.push(init);
    int cx, cy;

    while(!que.empty()){
        cp = que.front(), que.pop();
        cx = cp.first, cy = cp.second;
        movePos(cx, cy, 1, 0, que);
        movePos(cx, cy, -1, 0, que);
        movePos(cx, cy, 0, 1, que);
        movePos(cx, cy, 0, -1, que);
    }
    cout << ((svv[H-1][W-1] == '#') ? H*W - dist[H-1][W-1] - initBs -1 : -1) << endl;
    
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    priority_queue<ll> MinusPQ;
    priority_queue<pair<ll,ll > > PlusPQ;
    set<int> S;
    int n,k,t,d;
    vector<pair<ll, ll> > sushi;
    cin >> n >> k;
    ll sum = 0;
    
    for (int i=0;i<n;i++){
        cin >> t >>d;
        sushi.push_back(make_pair(d,t));
    }
    sort(sushi.rbegin(), sushi.rend());
    for (int i = 0; i < n; i++) {
        if (i<k){
            if (S.count(sushi[i].second)){
                MinusPQ.push(-sushi[i].first);
            }else{
                S.insert(sushi[i].second);
                
            }
            sum += sushi[i].first;
        }else{
            PlusPQ.push(sushi[i]);
        }
    }
 
    sum+=pow(S.size(),2);
    ll mx = sum;
  
    while(MinusPQ.size()>0 && PlusPQ.size()>0){

        if(S.count(PlusPQ.top().second)==0){
            long long diff = pow(S.size()+1,2)-pow(S.size(),2)+PlusPQ.top().first+MinusPQ.top();
            S.insert(PlusPQ.top().second);
            sum += diff;
            mx = max(sum,mx);
            MinusPQ.pop();
        }
        PlusPQ.pop();
    }
    cout << mx << endl;
}

Measured memory_bytes: 6256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int abs(int a,int b){
    if(a-b>=0){
        return a-b;
    }else{
        return (a-b)*(-1);
    }
}
int main(void){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(abs(a,c)<=d){
        cout<<"Yes"<<endl;
        return 0;
    }else if(abs(a,b)<=d&&abs(b,c)<=d){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <vector>
using namespace std;
static const int max_n = 200000;
static const int INF = 1e8;
static long long x,a,b,m,n,h,D=0,amax=1;
typedef pair<long long, long long> p;
static long long s[max_n],d[max_n];
static const int mod =1e9 + 7;
static int dist[111];//出発地からの最短距離
static long long cnt[111];//cnt[i] : 出発地からiまでの最短距離の回数
static vector<vector<int> > G;
static long long dp[max_n];
long long k = 0;
void solve(){
    for(int i=2 ; i<=n ; i++){
        if(dp[i] != -1){
            dp[i] = (max(dp[i-1], k) + max(dp[i-2], k))%mod;
        }
    }
    cout << dp[n] << endl;
}
int main(){
    cin >> n >> m;
    for(int i=0 ; i<m ; i++){
        cin >> s[i];
    }
    dp[0] = dp[1] = 1;
    for(int i=0 ; i<m ; i++){
        dp[s[i]] = -1;
    }
    solve();
    return 0;
}


Measured memory_bytes: 1792
package main

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

func intSlice(str string) []int {
	splitted := strings.Split(str, " ")
	ret := make([]int, len(splitted))

	for i, str := range splitted {
		if strings.TrimSpace(str) != "" {
			n, _ := strconv.Atoi(str)
			ret[i] = n
		}
	}

	return ret
}

func main() {

	stdin := bufio.NewScanner(os.Stdin)

	// 一行目
	stdin.Scan()
	line1 := stdin.Text()
	ints1 := intSlice(line1)
	r := ints1[0]
	d := ints1[1]
	x := ints1[2]
	x0 := x

	for i := 0; i < 10; i++ {
		x1 := r*x0 - d
		fmt.Println(x1)
		x0 = x1
	}
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

ll X, Y, Z, K;
vi A, B, C;
ll nxt[3030];

void solve() {
    vi ab;
    FORE (a, A) FORE (b, B) ab.PB(a+b);
    sort(rALL(ab));
    sort(rALL(C));
    priority_queue<ii> q;
    q.push(MP(ab[0]+C[0], 0));
    nxt[0] = 1;
    while (K) {
        ii r = q.top(); q.pop();
        int idx = r.second;
        if (nxt[idx] < Z) {
            q.push(MP(ab[idx]+C[nxt[idx]], idx));
            nxt[idx]++;
        }
        if (idx+1 < X*Y && nxt[idx+1] < Z) {
            q.push(MP(ab[idx+1]+C[nxt[idx+1]], idx+1));
            nxt[idx+1]++;
        }

        cout << r.first << endl;
        K--;
    }
}

int main() {
    cin >> X >> Y >> Z >> K;
    A = vi(X), B = vi(Y), C = vi(Z);
    REP (i, X) cin >> A[i];
    REP (i, Y) cin >> B[i];
    REP (i, Z) cin >> C[i];
    solve();
}

Measured memory_bytes: 10480
#include <iostream>

using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) {
    if (b == 0)
        return a;
    else 
        return gcd(b, a%b);
}

int main() {
    int N, K;  cin >> N >> K;
    ll *A = new ll[N];
    ll M = 0;
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
        M = max(M, A[i]);
    }

    ll g = A[0];
    for (ll i = 1; i < N; i++)
        g = gcd(g, A[i]);

     if (M >= K && (M-K)%g == 0)
        cout << "POSSIBLE" << endl;
    else
        cout << "IMPOSSIBLE" << endl;
    return 0;
}

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

using namespace std;
int main()
{
    string s;
    cin>>s;


    for(int i=0;i<(s.length())/2;i++)
    {
        if(s[i]!=s[s.length()-i-1])
        {
           cout<<"No";
           return 0;
        }
    }
         for(int i=0;i<(s.length())/4;i++)
           {
            if(s[i]!=s[(s.length())/2-i-1])
            {
                cout<<"No";
                return 0;
            }
           }
            for(int i=((s.length())/2+2);i<3*(s.length())/4;i++)
            {
                if(s[i]!=s[s.length()-i-1])
                {
                    cout<<"No";
                    return 0;
                }
            }



    cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256