akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
// #include <numeric> // gcdとかlcmとか C++17から
#include <time.h> // time_t timer; time(&timer); でtimerに現在時刻が代入される．
#include <unistd.h> // sleep関数．引数は秒単位．
using namespace std;

typedef long long ll;


// sortの仕方
// 	■ string s の場合
// 	昇順: sort(s.begin(), s.end())
// 	降順: sort(s.rbegin(), s.rend())
//
// 	■ ll a[N] の場合
// 	昇順: sort(a, a+N)
// 	降順: 不明

// vector の使い方
// 宣言：
// vector<int> v;
// vector<int> v(N);
// 初期化:
// vector<int> v(10, 5); 要素数10，全ての要素の値5．
// vector<int> v = {1, 2, 3};
// 代入：
// v[0] = 3;
// sort:
// sort(v.begin(), v.end());
//

// int alph2int(char character) {
//     int x = character - 'a';
//     return x;
// }

ll my_gcd(ll a, ll b){
	return (b==0) ? a : my_gcd(b, a%b);
}

ll my_lcm(ll a, ll b){
	return a*b / my_gcd(a,b);
}

ll factorial(ll a){
	ll ans = 1;
	for(ll i=a; i>0; i--){
		ans *= i;
	}
	return ans;
}

ll pow(ll a, ll b) {
	ll a_powered = 1;
	for (int i=0; i<b; i++) {
		a_powered *= a;
	}
	return a_powered;
}

int f(int n){
    if (n%2 == 0){
        return n/2;
    } else {
        return 3*n + 1;
    }

}

int main(int argc, char *argv[]){
    int s;
    cin >> s;

    int a_mem[1000000] = {};
    int a = s;
    a_mem[s] = 1;

    for(int i=2; i<1000001; i++) {
        a = f(a);
        if (a_mem[a] == 1) {
            cout << i << endl;
            return 0;
        } else {
            a_mem[a] = 1;
        }
    }

    return 1;
}


Measured memory_bytes: 4096
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n=in.nextInt();
            for (int i = 1; i <=9 ; i++) {
                if ((n%i)==0 && (n/i)>0 && (n/i)< 10){
                    out.println("Yes");
                    return;
                }
            }
            out.println("No");
        }
    }


    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }

}


Measured memory_bytes: 22100
#include<iostream>
using namespace std;
int main(){
  int a[3],ma=0,mi=100,i;
  for(i=0;i<3;i++){
cin>>a[i];
    if(a[i]>ma)ma=a[i];
    if(a[i]<mi)mi=a[i];
  }
  cout<<ma-mi<<endl;
  return 0;

}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,a[100000],i;
    scanf("%d",&n);
    for(i=0; i<n; i++)
        scanf("%d",&a[i]);
    for(i=0; i<n-1; i++)
        if(a[i]<=a[i+1])
        {
            if(a[i]<a[i+1])
                a[i+1]--;
        }
        else if(a[i]>a[i+1])
        {
            printf("No\n");
            return 0;
        }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;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 all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vint = vector<int>;

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

	string s;
	cin >> s;
	sort(all(s));
	if (s == "abc"){
		cout << "Yes" << "\n";
	}else{
		cout << "No" << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let n = read_int () in
  let tbl = Hashtbl.create ~random:true n in
  for _ = 0 to n - 1 do
    match split_on_char ' ' (read_line ()) with
    | ["find"; s] -> print_endline (if Hashtbl.mem tbl s then "yes" else "no")
    | [_; s] -> Hashtbl.add tbl s 0
    | _ -> assert false
  done

Measured memory_bytes: 43928
import sys
import numpy as np
import math
from collections import deque 
from functools import reduce

# input = sys.stdin.readline
x, y = map(int, input().split())
if y == 0:
    print(x)
    exit()
p = [list(map(int, input().split()))]
p_n = np.array(p)
p_n = p_n.reshape(-1)
pp = np.arange(0, 102)
for i in p_n:
    pp[i] += 10000
sa = min(abs(pp-x))
if sa <= 101:
    if pp[x-sa] >= 10000:
        print(x+sa)
    else:
        print(x-sa)
else:
    print("0")



Measured memory_bytes: 27160
#include <iostream>

int main()
{
    char a, b;
    std::cin >> a >> b;

    if (a > b) {
        std::cout << ">" << std::endl;
    } else if (a < b) {
        std::cout << "<" << std::endl;
    } else {
        std::cout << "=" << std::endl;
    }
}


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

int main() {
  int n; cin >> n;
  int t = n, s = 0;
  while (t) {
    s += t % 10;
    t /= 10;
  }
  cout << (n % s == 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk
#define prev fhsgfhjf
#define plus fsghsf
#define minus ytryr
  
using namespace std;
  
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
  
const int N = 10;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
//const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD = 998244353;
const ld eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;
 
string a[N];
 
int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 10.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n, m, k;
    cin >> n >> m >> k;
    rep(i, 0, n) {
        cin >> a[i];
    }
    int ans = inf;
    rep(mask, 0, (1 << (n - 1))) {
        int cnt = __builtin_popcount(mask);
        int tot = cnt;
        vector<int> cur(cnt + 1, 0);
        rep(j, 0, m) {
            int p = 0;
            rep(i, 0, n) {
                cur[p] += (a[i][j] == '1');
                if ((mask >> i) & 1) {
                    p++;
                }
            }
            bool bad = false;
            rep(i, 0, sz(cur)) {
                if (cur[i] > k) {
                    bad = true;
                }
            }
            if (bad) {
                tot++;
                fill(cur.begin(), cur.end(), 0);
                int p = 0;
                rep(i, 0, n) {
                    cur[p] += (a[i][j] == '1');
                    if ((mask >> i) & 1) {
                        p++;
                    }
                }
                bool bad = false;
                rep(i, 0, sz(cur)) {
                    if (cur[i] > k) {
                        bad = true;
                    }
                }
                if (bad) {
                    tot = inf;
                }
            }
        }
        setmin(ans, tot);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    string s;
    cin >> s;
    int ans = 0;
    rep(i, s.length())
    {
        if (i % 2 == 0)
        {
            if (s[i] == 'p')
                ans--;
        }
        else
        {
            if (s[i] == 'g')
                ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  long long a;
  double b;

  cin >> a >> b;

  long long ib = b*100 + 0.5;

  a *= ib;
  a /= 100;

  printf("%lld\n", a);

  return 0;
}


Measured memory_bytes: 3792
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
	int n; cin >> n;
	long long ans = 1;
	bool bad = false;
	while (n--) {
		long long a; cin >> a;
		if (a == 0) {
			cout << "0\n";
			return 0;
		}
		if (ans > 1000000000000000000LL / a)
			bad = true;
		if (!bad)
			ans *= a;
	}
	cout << (!bad ? ans : -1) << '\n';
	return 0;
}


Measured memory_bytes: 3640
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll INF = 1e+18;
const ld EPS = 1e-12L;
const ld PI = acos(-1.L);
inline ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
inline ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

const int MAX = 2001;
bitset<MAX*MAX> dp[2];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll n;
  cin >> n;
  vll a(n);
  rep(i, n){
    cin >> a[i];
  }
  //sort(ALL(a));
  dp[1][0] = 1;
  rep(i, n){
    int ne = i&1;
    int ol = !ne;
    dp[ne].reset();
    rep(j, a[i]+1){
      dp[ne][a[i]-j] = dp[ol][j];
    }
    dp[ne] |= dp[ol] << a[i];
    dp[ne] |= dp[ol] >> a[i];
  }
  ll ans = 0;
  while(!dp[(n-1)&1][ans]) ans++;
  print((accumulate(ALL(a), 0ll)+ans)/2);
}


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

int main()
{
    string s,t;cin>>s>>t;
    int n=s.length();
    int m=t.length();
    string ans="";
    int dp[n+1][m+1];
    for(int i=0;i<=n;i++)
        dp[i][0]=0;
    for(int i=0;i<=m;i++)
        dp[0][i]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(s[i-1]==t[j-1])
                dp[i][j]=1+dp[i-1][j-1];
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    int i=n,j=m;
    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<<"\n";
    return 0;
}


Measured memory_bytes: 35456
#include <iostream>

using namespace std;

int a[10000];
int b[10000];
int h;
int cb[10001];

int main()
{
    int h, n;
    cin >> h >> n;
    int maxa = 0;

    for (int i = 0; i < n; ++i)
    {
        cin >> a[i] >> b[i];
        if (a[i] > maxa)
        {
            maxa = a[i];
        }
    }

    for (int gap = n/2; gap > 0; gap /= 2)
    {
        for (int i = gap; i < n; ++i)
        {
            for (int j = i - gap; j >= 0 && b[j] > b[j+gap]; j -= gap)
            {
                swap(b[j], b[j+gap]);
                swap(a[j], a[j+gap]);
            }
        }
    }

    cb[0] = 0;
    cb[1] = b[0];
    int cix = 0;
    int cur;
    int i = 2;
    for (i = 2; i <= h && i <= maxa; ++i)
    {
       while (a[cix] < i)
       {
           cix++;
       }
       cb[i] = b[cix];
       //cout << "cb[" << i << "]=" << b[cix] << "\n";
       for (int j = 1; i-j >= 0; ++j)
       {
           cur = cb[i-j] + cb[j];
           if (cur < cb[i])
           {
               cb[i] = cur;
               //cout << "cb[" << i << "]=" << b[cix] << "\n";
           }
       }
    }

    for (; i <= h; ++i)
    {
        cb[i] = cb[i-1] + cb[1];
       for (int j = 2; i-j >= 0; ++j)
       {
           cur = cb[i-j] + cb[j];
           if (cur < cb[i])
           {
               cb[i] = cur;
               //cout << "cb[" << i << "]=" << b[cix] << "\n";
           }
       }
    }
    cout << cb[h] << "\n";
    return 0;
}


Measured memory_bytes: 256
def comp(gen)
    ht0=Hash.new
    gen[0].each{|key,value|
       str=""
       value.each{|v|
          str+=v.to_s
       }
       ht0.store(key,str+str)
    }
    ht=Hash.new
    gen[1].each_key{|key|
       if gen[0].has_key?(key)==false then
          return false
       end
       arr=gen[1][key]
       str=""
       arr.each do |v|
           str+=v.to_s
       end
       ht.store(key,str)
    }
    ht.each{|key,value|
       if ht0[key].include?(value)==false then
          return false
       end
    }
    return true
end

def generate(src,lbl)
     gen=Hash.new
     src.each{|key,arr|
       r=Array.new
       arr.each{|v|
         r.push(lbl[v])
       }
       gen.store(lbl[key],r)
     }
     return gen
end

src={1=>[2,3,5,4],
     2=>[1,4,6,3],
     3=>[1,2,6,5],
     4=>[2,1,5,6],
     5=>[3,6,4,1],
     6=>[2,4,5,3]}

gen=Hash.new
2.times do |p|
    lbl=Hash.new
    mp=gets.split(' ').map(&:to_i)
    mp.each_with_index {|x,i|
       lbl.store(i+1,x)
    }
    gen.store(p,generate(src,lbl))
end
if comp(gen) == true then
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 8660
import javax.print.DocFlavor;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

    //グローバル変数を定義
    List<char[]> list = new ArrayList<>();

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

    void run() {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int goal = sc.nextInt();
        int[] pArray = new int[num];
        int[] cArray = new int[num];

        for(int i=0; i<num; i++){
            pArray[i] = sc.nextInt();
            cArray[i] = sc.nextInt();
        }

        int min = 1000;

        int sum = 0;
        int count = 0;

        for(int bit=0; bit<Math.pow(2, num); bit++){
            sum = 0;
            count = 0;
//            List<Integer> alreadyList = new ArrayList<>();

            for(int i=0; i<num; i++){
                if((1&bit>>i) == 1){
                    sum += pArray[i] * 100 * (i+1) + cArray[i];
                    count += pArray[i];
//                    alreadyList.add(i);
                }
            }

            if(sum >= goal){
                min = Math.min(min, count);
            } else {
                for(int i=0; i<num; i++){
                    int count2 = count;
                    int sum2 = sum;
                    if((1&bit>>i) != 1){
                        for(int j=0; j<pArray[i]; j++){
                            sum2 += (i+1) * 100;
                            count2++;

                            if(sum2 >= goal){
                                min = Math.min(min, count2);
                                sum2 =sum;
                                count2 = count;
                            }
                        }
                    }
                }
            }
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>

using namespace std;

const int MAX_N = 5000;

int as[MAX_N+1];

int main ( void )
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	while (cin >> n, n) {
		as[0] = 0;
		for (int i = 0; i < n; ++i) {
			int x;
			cin >> x;
			as[i+1] = as[i] + x;
		}

		int ans = -(1 << 29);
		for (int i = 0; i < n; ++i) {
			for (int j = i+1; j <= n; ++j) {
				ans = max(ans, as[j] - as[i]);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	int a, b, c; cin >> a >> b >> c;
	map<int, int> freq;
	freq[a]++;
	freq[b]++;
	freq[c]++;

	cout << ((freq.size() == 2) ? "Yes" : "No");

	return 0;
}

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

static const int MAX = 500000;
static const int INFTY = 2000000000;

int L[MAX / 2 + 2], R[MAX / 2 + 2];
int total;


void merge(int S[], int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	for (int i = 0; i < n1; i++) {
		L[i] = S[left + i];
	}
	for (int i = 0; i < n2; i++) {
		R[i] = S[mid + i];
	}
	L[n1] = INFTY;
	R[n2] = INFTY;
	int i = 0, j = 0;
	for (int k = left; k < right; k++) {
		total += 1;
		if (L[i] <= R[j]) {
			S[k] = L[i];
			i++;
		}
		else {
			S[k] = R[j];
			j++;
		}
	}
}

void mergeSort(int S[], int left, int right) {
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		mergeSort(S, left, mid);
		mergeSort(S, mid, right);
		merge(S, left, mid, right);
	}
}

int main() {
	total = 0;
	int S[MAX];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> S[i];
	}
	mergeSort(S, 0, n);
	for (int i = 0; i < n; i++) {
		if (i > 0) {
			cout << " ";
		}
		cout << S[i];
	}
	cout << endl;
	cout << total << endl;
	return 0;
}


Measured memory_bytes: 6968
import java.util.*

fun main(args:Array<String>){
    val (n,d,a) = readLine()!!.split(" ").map{it.toInt()}
    val x = Array(n){IntArray(2)}
    for(i in 0 until n){
        val (b,c) = readLine()!!.split(" ").map{it.toInt()}
        x[i][0] = b
        x[i][1] = c
    }
    x.sortBy{it -> it[0]}
    var ans = 0L
    var sum = 0L
    val pq = PriorityQueue<Pair<Int,Int>>(n){i1 : Pair<Int,Int>, i2 : Pair<Int,Int> -> return@PriorityQueue i1.first - i2.first}
    for(i in 0 until n){
        while(pq.isNotEmpty() && pq.first().first < x[i][0]){
            sum -= a.toLong() * pq.first().second.toLong()
            pq.remove()
        }
        if(sum < x[i][1]){
            val k = (x[i][1] - sum + a - 1).toLong() / a.toLong()
            sum += k * a.toLong()
            pq.add(Pair(Math.min(x[i][0] + 2 * d, 1000000010).toInt(), k.toInt()))
            ans += k
        }
    }
    println(ans)
}


Measured memory_bytes: 118188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll a,b;
	cin>>a>>b;
	for(ll i=1;i<=3;i++)
	{
		if((a*b*i)&1)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
using namespace std;
int main(){
  char s[1001];
  scanf("%s",s);
  for(int i=0;i<strlen(s);i++){
    char c = s[i];
    if(c == '2') putchar('k');
    else if(c == '3') putchar('s');
    else if(c == '4') putchar('t');
    else if(c == '5') putchar('n');
    else if(c == '6') putchar('h');
    else if(c == '7') putchar('m');
    else if(c == '8') putchar('y');
    else if(c == '9') putchar('r');
    else if(c == '0' && s[i+1] == 'U'){
      printf("nn");
      i++;
    }
    else if(c == '0') putchar('w');
    else if(c == 'T') putchar('a');
    else if(c == 'L') putchar('i');
    else if(c == 'U') putchar('u');
    else if(c == 'R') putchar('e');
    else if(c == 'D') putchar('o');
  }
  putchar('\n');
  return (0);
}

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

int main() {
  long long A, B, N; 
  cin >> A >> B >> N;
  if (N < B) {
    cout << (long long)floor(A * N / B) << endl;
    return 0;
  } 
  long long x = N;
  x = x - (x % (B - 1));
  cout << (long long)floor(A * (B - 1) / B) - A * (long long)floor((B - 1) / B) << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front

using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;

typedef pair<int, int> P;

bool ps1(const P &forall_a_in_P, const P &forall_b_in_P)
{ //first昇順
	return forall_a_in_P.first < forall_b_in_P.first;
}
bool ps2(const P &forall_a_in_P, const P &forall_b_in_P)
{ //first降順
	return forall_a_in_P.first > forall_b_in_P.first;
}
bool ps3(const P &forall_a_in_P, const P &forall_b_in_P)
{ //second昇順
	return forall_a_in_P.second < forall_b_in_P.second;
}
bool ps4(const P &forall_a_in_P, const P &forall_b_in_P)
{ //second降順
	return forall_a_in_P.second > forall_b_in_P.second;
}
int main()
{
    int n;
    cin>>n;
    vector<int>x(n),y(n);
    
    rep(i,n){
        cin>>x[i]>>y[i];
    }
    vector<int>turn(n);
    rep(i,n){
        turn[i]=i;
    }
    double sum=0;
    int cnt=0;
    do{
        cnt++;
        FOR(i,1,n){
            sum+=sqrt(pow(x[turn[i]]-x[turn[i-1]],2)
            +pow(y[turn[i]]-y[turn[i-1]],2));
        }
    }while(next_permutation(all(turn)));
    double ans=(double)sum/cnt;
    cout<<setprecision(15)<<ans<<endl;
 }

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

int main(){
    int N;  cin >> N;
    vector<vector<int>> A(2, vector<int>(N));
    for(int i=0; i<2; i++) for(int j=0; j<N; j++){
        cin >> A[i][j];
    }

    vector<int> S0(N+1, 0), S1(N+1, 0);
    S0[1] = A[0][0];  S1[1] = A[1][0];
    for(int j=1; j<N; j++){
        S0[j+1] = S0[j] + A[0][j];
        S1[j+1] = S1[j] + A[1][j];
    }

    int ans = 0;
    for(int j=1; j<=N; j++){
        // cout << j << " " << S0[j] << " " << S1[j-1] << endl;
        ans = max(ans, S0[j] + S1[N] - S1[j-1]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	Main(){
		int a = sc.nextInt();
		int b = sc.nextInt();
		System.out.println( (a*b) + " " + (a*2 + b*2));
	}
	public static void main(String[] arg) {
		new Main();
	}
}


Measured memory_bytes: 26348
from sys import stdin
import fractions

a,b = [int(x) for x in stdin.readline().rstrip().split()]

dp = [0]*999
dp[0] = 1

for i in range(1,999):
    dp[i] = dp[i-1] + i+1
    if b-a == dp[i]-dp[i-1]:
        print(dp[i]-b)
        exit()

Measured memory_bytes: 64620
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TypeFamilies #-}
import           Data.Maybe
import           Data.Int
import           Data.List
import           Data.Char
-- import qualified Data.Vector.Unboxing as VU
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import           Data.List (scanl')
import           Data.IORef
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Control.Monad.Primitive
import           Control.Applicative
import           Debug.Trace
import           Text.Printf

main = do
  [a,b] <- words <$> getLine
  let a' = read a :: Integer
      b' = read b :: Double
  -- print $ floor $ a' * b'
  -- print 1
  print $ solve a' b'


solve a b = ans
  where
    a' = a `div` 1000
    a'' = a `mod` 1000
    b' = floor $ (fromIntegral a'' :: Double) * b
    ans = a' * (floor $ 1000 * b) + b'


readInt = BS.readInt . BS.dropWhile isSpace
getVector f = VU.unfoldr f <$> BS.getLine
getIntVector = getVector readInt
getBSVector = getVector BS.uncons
getInt = readLn :: IO Int
getInt2Tuple = (\vec -> (vec VU.! 0, vec VU.! 1)) <$> getIntVector
getInt3Tuple = (\vec -> (vec VU.! 0, vec VU.! 1, vec VU.! 2)) <$> getIntVector


Measured memory_bytes: 4076
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = b - 1;i >= a;--i)
#define p(s) cout << (s) << endl
#define p2(s,t) cout << (s) << " " << (t) << endl 
#define ALL(v) (v).begin(), (v).end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;
using namespace std;

static const ll MOD  = 1e9 + 7;
static const ll INF  = 1e18;
static const double EPS = 1e-10;

int main(){
    vector<int> V(10);
    int A, B, C, K, ans = 0;
    string S,T;

    cin >> S >> T;
    rep(i,3){
        if(S[i] == T[i]) ans++;
    }
    p(ans);

}

Measured memory_bytes: 892
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    n = int(input())
    C = input()
    C_cunt = Counter(C)
    cunt_r = C_cunt['R']
    ans = 0
    for i in range(cunt_r):
        if C[i] == 'W':
            ans += 1
    print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 9776
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector< double > a(n);
    double ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        ans += 1 / a[i];
    }
    cout << setprecision(20) << 1 / ans << endl;
    return 0;
}

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

int main() {
  int N; cin >> N;
  int ans{};
  for (int i{1}; i <= N; ++i) {
    int num = static_cast<int>(log10(i)+1);
    if (num % 2)
      ++ans;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long sum = 1;
		long waru = (long)(Math.pow(10, 9)+7.0);		
		for(long i = 1;i <= n; i++)
		{
			sum = sum * i;
			sum = sum % waru;	
		}
		System.out.println((long)(sum%waru));
	}
}	
	

Measured memory_bytes: 20692
S = input()
T = input()

n_s = len(S)
n_t = len(T)

flg = 0

for i in range(n_s):
    if S[i] == T[i]:
        continue
    else:
        flg = 1
        
if (flg == 0) and (n_t == n_s + 1):
    print('Yes')
else:
    print('No')

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

int main(){

    int N, M, temp, sum;

    cin >> N;

    int T[N] = {0};

    for(int i = 0; i < N; i++){
        cin >> T[i];
    }

    cin >> M;

    int P[M] = {0};
    int X[M] = {0};

    for(int i = 0; i < M; i++){
        cin >> P[i] >> X[i];

        sum = 0;
        temp = T[P[i] - 1];

        T[P[i] - 1] = X[i];

        for(int j = 0; j < N; j++){
            sum += T[j];

        }

        cout << sum << endl;
        T[P[i] - 1] = temp;
    }



    return 0;

}




Measured memory_bytes: 3592
# include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL a[2003];
int main()
{
    int n;
    LL z, w;
    scanf("%d%lld%lld",&n,&z,&w);
    for(int i=1; i<=n; ++i) scanf("%d",&a[i]);
    if(n == 1) printf("%lld\n",llabs(a[1]-w));
    else
        printf("%lld\n",max(llabs(a[n-1]-a[n]), llabs(a[n]-w)));
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;

struct UnionFind{
	vector<int> par,rank;
	UnionFind(int N){
		par.assign(N,0);
		rank.assign(N,0);
		rep(i,N) par[i]=i;
	}
	int find(int x){
		if(par[x]==x) return x;
		return par[x]=find(par[x]);
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	void unite(int x,int y){
		x=find(x),y=find(y);
		if(x==y) return;
		if(rank[x]<rank[y]) swap(x,y);

		//x becomes root
		par[y]=x;
		if(rank[x]==rank[y]) rank[x]++;
	}
};

int main(){
	int N,M;
	cin>>N>>M;
	vector<int> p(N);
	rep(i,N) cin>>p[i],p[i]--;
	UnionFind UF(N);
	rep(i,M){
		int x,y;
		cin>>x>>y;
		x--,y--;
		UF.unite(x,y);
	}
	int ans = 0;
	rep(i,N) if(UF.find(i) == UF.find(p[i])) ans++;
	cout<<ans<<endl;
}

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

int main(){
  int n,t0=0,x0=0,y0=0,t1,x1,y1,dif=0,dif_t=0;cin>>n;

  for(int i=0;i<n;++i){
    cin>>t1>>x1>>y1;
    dif=abs(x0-x1)+abs(y0-y1);
    dif_t=t1-t0;
    if((dif%2!=dif_t%2)||dif>dif_t){
      printf("No\n");
      return 0;
    }
    t1=t0;
    x1=x0;
    y1=y0;
  }printf("Yes\n");
}

Measured memory_bytes: 256
#include <stdio.h>
#include<math.h>
using namespace std;
 
int main(){
    double v,N;
 
    while(scanf("%lf",&v)!=EOF){
        for(int N=0;;N+=1){
            if(N >= (v*v+98)/98){
                printf("%d\n",(int)N);
                break;
            }
        }
    }
 
    return 0;
}


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

int main(){

    int N, M;
    cin >> N >> M;
    vector<pair<long long, long long>> drink(N);
    for(int i = 0; i < N; i++) cin >> drink[i].first >> drink[i].second;

    sort(drink.begin(), drink.end());

    long long ans = 0;
    for(int i = 0; i < N; i++){
        if(drink[i].second >= M){
            ans += drink[i].first * M;
            M = 0;
        }else{
            M -= drink[i].second;
            ans += drink[i].first * drink[i].second;
        }
        if(M == 0) break;;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#define MAX 100000
using namespace std;

typedef long long llong; 

int n,k;
llong T[MAX];

int check (llong p)
{
	int i=0;
	for (int j=0;j<k;j++)
	{
		llong s=0;
		while (s+T[i]<=p)
		{
			s+=T[i];
			i++;
			if (i==n) return n; 
			//这样可以试T[i]能不能装下，若不能，则I=4，说明最后一个货物 
			//没有被装下，若可以，则I=5，说明试过了最后一个且能装下。就是
			//检测i值，若i值等于5，则说明能装下T[4]，  
		}
	}
	return i;
}

int solve ()
{
	llong left=0;
	llong right = 100000*10000;
	llong mid=0;
	while (right-left>1)
	{
		mid=(left+right)/2;
		int v=check(mid);
		if (v>=n) right=mid;
		else left=mid; 
	}
	return right;
}

int main()
{
	cin>>n>>k;
	for (int i=0;i<n;i++) cin>>T[i];
	llong ans =solve();
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3860
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
	string s;
	 cin >> s;
	 cout << (s <= "2019/04/30" ? "Heisei" : "TBD") << endl;
}

Measured memory_bytes: 256
# O(N)

N = int(input())
# abc[k]: (k+1)日目の行動
abc = [[int(i) for i in input().split()] for j in range(N)]

# dp[i][j]: i日目の行動jで得られる幸福度の総和の最大値
# (j= 0:a, 1:b, 2:c)
dp = [[0]*3 for i in range(N+1)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i+1][k] = max(dp[i+1][k], dp[i][j]+abc[i][k])

answer = 0
for i in range(3):
    answer = max(answer, dp[-1][i])
print(answer)


Measured memory_bytes: 45068
N = gets.chomp.to_i
numArr = gets.chomp.split(" ").map(&:to_i)


key = 1
arr = numArr.select{ |num|
    if(num == key)
        key += 1
    end
}

if(arr.size.zero?)
    puts -1
else
    puts numArr.size - arr.size
end


Measured memory_bytes: 18052
#include <bits/stdc++.h>
using namespace std;
int main(){
int A,B,C,K,D,E,F,G,H;
  cin>>A>>B>>C>>K;
 if(A<K){
  D=K-A;
   if(B<D){
   E=D-B;
     if(C<E){
     cout<<A-C;
     }
     else{
     cout<<A-(K-A-B);
     }
    }
   else{
   cout<<A;
   }
 }
  else{
  cout<<K;
  }
}

Measured memory_bytes: 3636
package main

import "fmt"

type dice struct {
	sur [6]int8
}

func (d *dice) Scan() {
	for i := 0; i < 6; i++ {
		fmt.Scan(&d.sur[i])
	}
	return
}

func (d *dice) Move(dir rune) {
	nd := *d
	switch dir {
	case 'E':
		d.sur[0] = nd.sur[3]
		d.sur[2] = nd.sur[0]
		d.sur[3] = nd.sur[5]
		d.sur[5] = nd.sur[2]
	case 'N':
		d.sur[0] = nd.sur[1]
		d.sur[1] = nd.sur[5]
		d.sur[4] = nd.sur[0]
		d.sur[5] = nd.sur[4]
	case 'S':
		d.sur[0] = nd.sur[4]
		d.sur[1] = nd.sur[0]
		d.sur[4] = nd.sur[5]
		d.sur[5] = nd.sur[1]
	case 'W':
		d.sur[0] = nd.sur[2]
		d.sur[2] = nd.sur[5]
		d.sur[3] = nd.sur[0]
		d.sur[5] = nd.sur[3]
	}
	return
}

func (d *dice) Judge(target *dice) bool {
	for i := 0; i < 6; i++ {
		if d.sur[i] != target.sur[i] {
			return false
		}
	}
	return true
}

func (d *dice) Roll(target *dice, depth int) bool {
	if depth >= 4 {
		return false
	}
	for i := 0; i < 4; i++ {
		nd := *d
		switch i {
		case 0:
			nd.Move('E')
		case 1:
			nd.Move('N')
		case 2:
			nd.Move('W')
		case 3:
			nd.Move('S')
		}
		if nd.Judge(target) || nd.Roll(target, depth+1) {
			return true
		}
	}
	return false
}

func main() {
	d1, d2 := &dice{}, &dice{}
	d1.Scan()
	d2.Scan()
	if d1.Roll(d2, 0) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

	return
}



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


#define mx 200005
#define ll long long 
#define mod 998244353

void IO()
{
  #ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin);
  freopen("out.txt","w",stdout);
  #endif
}


int ar[mx];
char ch[mx];
int m,n,k,ii;
int mark[mx];
ll dp[mx],csum[mx];
vector<int>v;
vector<pair<int,int>>ace;

ll add(ll a,ll b)
{
    a+=b;
    if(a>=mod)a%=mod;
    return a;
}

ll func(int val)
{
    if(val==n)return 1;
    if(dp[val]!=-1)return dp[val];
    ll re=0;
    for(int u:v)
    {
        if(val+u>n)break;
        re=add(re,func(val+u));
    }
    return dp[val]=re;
}

void solve()
{
   scanf("%d%d",&n,&k);
   for(int i=1;i<=k;i++)
   {
      int x,y;
      scanf("%d%d",&x,&y);
      for(int j=x;j<=y;j++)mark[j]=1;
   }
   int shuru=1;
   int sesh=0;
   for(int i=1;i<=n+1;i++)
   {
      if(mark[i])
      {
         sesh++;
      }
      else
      {
        if(shuru<=sesh)
        {
            ace.push_back({shuru,sesh});

        }
        shuru=i+1;
        sesh=i;
      }
   }
   dp[n]=1;
   csum[n]=1;
   for(int i=n-1;i>=1;i--)
   {
       int need=n-i;
       for(auto it:ace)
       {
          if(it.first>need)break;
          int st=it.first;
          int en=min(need,it.second);
          ll va=(csum[i+st]-csum[i+en+1])%mod;
          if(va<0)va=(va+mod)%mod;
          dp[i]=(dp[i]+va)%mod;
          if(it.second==need)break;
       }
       csum[i]+=csum[i+1];
       csum[i]=add(csum[i],dp[i]);

   }
   printf("%lld\n",dp[1]);
}

int main()
{
   IO();
  int t=1;
  //scanf("%d",&t);
  while(t--)
  {
    solve();
  }
  return 0;
}

Measured memory_bytes: 7624
import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import Data.List
import Data.Ord

listToTuple2 [a,b] = (a,b)

main = do
  (n,m) <- listToTuple2 . map read . words <$> getLine :: IO (Int,Int)
  query <- sortBy (comparing snd) . map (listToTuple2 . map (fst . fromJust . BS.readInt) . BS.words) . BS.lines <$> BS.getContents :: IO [(Int,Int)]

  print $ length $ solve query Nothing

  where
    solve [] _ = []
    solve ((a,b):qs) Nothing = (b-1) : (solve qs (Just $ b-1))
    solve ((a,b):qs) (Just x)
      | a <= x = solve qs (Just x)
      | a > x = (b-1) : (solve qs (Just $ b-1))


Measured memory_bytes: 40188
#include <iostream>
#include <array>
#include <algorithm>

int main()
{
	std::array<int, 10> high;
	for (int i = 0; i < 10; ++i)
		std::cin >> high[i];

	std::sort(high.begin(), high.end());

	for (int i = 9; i > 6;--i)
		std::cout << high[i] << std::endl;
	
	return 0;
}

Measured memory_bytes: 1172
#include <queue>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define set0(x) memset(x,0,sizeof(x))
#define id(x,lev) x*52+lev
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();int f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}

int n,dp[200020][2] = {0};
char s[200020];
int main() {
	cin>>n>>s;
	for(int i=n-1;i>=0;i--){
		dp[i][0] = min(dp[i+1][0],dp[i+1][1]);
		dp[i][1] = dp[i+1][1];
		
		if(s[i] == '#')dp[i][0]+=1;
		else dp[i][1]+=1;
		//cout<<dp[i][0]<<' '<<dp[i][1]<<endl;
	}
	cout<<min(dp[0][0],dp[0][1])<<endl;
	return 0;
}


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



int main(){
    ll n,k;
    cin>>n>>k;
    vector<pll> a(n);
    for(auto &i:a){cin>>i.S>>i.F;}
    sort(a.begin(),a.end(),greater<pll>());
    ll ans=0;
    ll sum=0;
    ll kind=0;
    priority_queue<ll,vector<ll>,greater<ll>> Q;
    set<ll> S;
    for(int i=0;i<k;i++){
        sum+=a[i].F;
        if(S.count(a[i].S)==0){
            kind++;
            S.insert(a[i].S);
        }
        else{
            Q.push(a[i].F);
        }
    }
    ans=sum+kind*kind;
    for(ll i=k;i<n;i++){
        if(Q.empty()){break;}
        if(S.count(a[i].S)==0){
            kind++;
            sum-=Q.top(); Q.pop();
            sum+=a[i].F;
            S.insert(a[i].S);
            ans=max(ans,sum+kind*kind);
        }
    }
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 5244
#include<iostream>
#include<algorithm>
#include<assert.h>
#include<algorithm>
using I = long long int;
using namespace std;
int H[300001]; 
int main() {
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    I n, k; cin >> n >> k;
    for(int i = 0; i < n; ++ i) cin >> H[i];
    sort(H, H+n);
    // for(int i = 0; i < n; ++ i) cout << H[i] << " ";

    I tot = 0;
    const int start = n-(k+1); // cout << "start: " << start << "\n";
    for(int i = start; i >= 0; i--) { tot += H[i]; }
    cout << tot;
    return 0;
}


Measured memory_bytes: 1024
import java.io.*;
import java.io.ObjectInputStream.*;
import java.util.*;
import java.util.regex.*;


public class Main {

	final static long MOD = 1000000007;
	//final static long MOD = 998244353;

	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		slove(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void slove(String[] args) throws Exception{

		int N = nextInt();
		int[] A = nextInts();

		HashMap<Long,Integer> map = new HashMap<Long, Integer>();
		long rui=0;
		map.put(rui,map.getOrDefault(rui, 0)+1);
		for(int i=0;i<N;i++) {
			rui+=A[i];
			map.put(rui,map.getOrDefault(rui, 0)+1);
		}
		long ans = 0;
		for(long key:map.keySet()) {
			long val=map.get(key);
			ans+=val*(val-1)/2;
		}
		pw.println(ans);
	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}



Measured memory_bytes: 62104
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
typedef long long ll;

const int INF = 1001001001;
const int MOD = 1e9+7;


int main() {
    ll n;
    cin >> n;
    ll ans = 1001001001001;
    for (ll i = 1; i*i <= n; i++) {
        if (n%i == 0) {
            ans = min(ans, i+n/i-2);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	s := scanString()
	n, _ := strconv.Atoi(strings.Replace(s, "/", "", -1))
	if n <= 20190430 {
		fmt.Fprintln(wr, "Heisei")
	} else {
		fmt.Fprintln(wr, "TBD")
	}

}


Measured memory_bytes: 1776
if __name__ == '__main__':
    s = input()
    for i in range(1,len(s)):
        s2 = s[:len(s)-i]
        count =0
        if len(s2) % 2 ==0:
            for j in range(len(s2)// 2):
                if s2[j] == s2[len(s2)// 2 + j]:
                    count+=1


            if count == len(s2)//2:
                print(len(s2))
                break


Measured memory_bytes: 3060
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

s = ns()
if 'B' not in s or 'A' not in s:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 10768
def is_prime(N):
    if N == 1:
        return False
    for k in range(2, int(N**0.5) + 1):
        if N % k == 0:
            return False
    return True


N, M = map(int, input().split())
k = 0
if N != 1:
    if is_prime(M):
        print(1)
        exit()
while True:
    if M % (N + k) == 0:
        ans = M // (N+k)
        break
    k += 1
print(ans)

Measured memory_bytes: 3060
mod = 10 ** 9 + 7

N = int(input())

s, n, z, e = 1, 0, 0, 0
for _ in range(N):
    s, n, z, e = 8 * s, s + n * 9, s + z * 9, n + z + e * 10
    s %= mod
    n %= mod
    z %= mod
    e %= mod

print(e)

Measured memory_bytes: 63844