akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  string S;
  cin >> S;
  ll K;
  cin >> K;
  int ssize = (int)S.size();
  ll ans = 0;
  ll tmp = 0;

  if(ssize==1){cout << K/2 << endl; return 0;}
  if(ssize%2==1){
    for(int i=1;i<ssize;i++){
      if(S[i]!=S[0]) break;
      if(i+1==ssize){
        ans = (ssize*K) /2;
        cout << ans << endl;
        return 0;
      }
    }
  }

  string S2 = S+S;


  tmp = 0;
  for(int i=1;i<ssize;i++){
    if(S[i] == S[i-1]){
      S[i] = '0';
      tmp++;
    }
  }

  ll tmpp = 0;

  for(int i=1;i<S2.size();i++){
    if(S2[i-1]==S2[i]){
      S2[i] = '1';
      tmpp++;
    }
  }
  ll diff = tmpp-tmp;
  ans = tmp+diff*(K-1);
  cout << ans << endl;
  return 0;
  /*
  ans += tmp * K;
  if(S[0] == S[ssize-1]){
    ans += K-1;
  }
  cout << ans << endl;
  return 0;
  */
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 100;
const long long LLINF = 2e18 + 129;
const long long MOD = 1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    int n;
    lint a, b;
    cin >> n >> a >> b;

    vector<lint> x(n);
    rep(i, n){
        cin >> x[i];
    }

    lint ans = 0;
    REP(i, 1, n){
        ans += min((x[i] - x[i - 1]) * a, b);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
#include<stdio.h>
#include<cmath>
#include<limits>
#include<iomanip>

using namespace std;

template <class T> using V = vector<T>;

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

const long long INF = 1LL << 60;

using ll = long long;
using db = long double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
using graph = V<V<int>>;
using pq = priority_queue<ll>;



#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define pb(a) push_back(a);



ll Sum(ll n) {
ll m=0;
  while(n){
    m+=n%10;
    n/=10;
  }
  return m;
}



const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


#define comuse Comuse()

ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll perm(int n,int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] % MOD) % MOD;
}


ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}


vll div(ll n){
  vll ret;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      ret.push_back(i);
      if(i*i!=n){
        ret.push_back(n/i);
      }
    }
  }
  SORT(ret);
  return (ret);
}

ll modpow(ll a,ll n,ll mod){
  ll ans=1;
  while(n>0){
    if(n&1){
      ans=ans*a%mod;
    }

    a=a*a%mod;
    
    n>>=1;
  }

  return ans;
}

void Solve();


const int MAX_N = 131072;
//segment tree 
int NN;
int seg[MAX_N*2-1];
void seguse(){
  for(int i=0;i<2*NN-1;i++){
    seg[i]=INT_MAX;
  }
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(20)<<fixed;
  Solve();
}




/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
//segtreeの葉の先頭の添え字はn-1
void Solve(){
  //vll segtree(524287);
  //ll N=262144;
  ll a,b;
    cin>>a>>b;
  if(b<a){
    swap(a,b);
  }
  char c='0'+a;
  string s(b,c);
  cout<<s<<"\n";
}

Measured memory_bytes: 256
import numpy as np
import math
import itertools

# 距離の最大公約数を求める

def factorize(M):
    P = []
    F = []
    for m in range(2, int(math.sqrt(M))+1):
        n = 0
        while M % m == 0:
            M/= m
            n +=1
        if n != 0:
            P.append(m)
            F.append(n)
    if M != 1:
        P.append(M)
        F.append(1)
    return P,F

N,X = map(int, input().split())
xN = list(map(int, input().split()))

dN = np.abs(np.array(xN) - X)
P,F = factorize(np.min(dN))

M = []
for F_ in itertools.product(*list(map(lambda f:range(f+1), F))):
    m = 1
    for p,f in zip(P,F_):
        m *= int(pow(p,f))
    if np.all(np.mod(dN, m) == 0):
        M.append(m)

print(max(M))
    
    


Measured memory_bytes: 23072
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end())
using namespace std;

typedef long long ll;

vector<int> prime;
int isp[1010];
void era(){
    for(int i=2; i<1010; i++){
        if(isp[i]) continue;
        prime.push_back(i);
        for(int j=i+i; j<1010; j+=i) isp[j] = 1;
    }
}

int n;
int chk[1010101];

int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    era(); cin >> n;
    
    int g;
    
    int flag = 1;
    for(int i=1; i<=n; i++){
        int t; cin >> t;
        if(i == 1) g = t;
        else g = __gcd(g, t);
        for(auto j : prime){
            if(t < j*j) break;
            if(t % j == 0){
                if(chk[j]) flag = 0;
                chk[j] = 1;
                while(t % j == 0) t /= j;
            }
        }
        if(t != 1){
            if(chk[t]) flag = 0;
            chk[t] = 1;
        }
    }
    
    if(flag){ cout << "pairwise coprime"; }
    else if(g == 1){ cout << "setwise coprime"; }
    else cout << "not coprime";
}

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

#define int long long
#define fi first
#define se second
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) ct(v[i])
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int n,a[100000],b[100000],ans;

main() {
    cin >> n;
    rep(i,n) cin >> a[i] >> b[i];
    repm(i,n) a[i]+=ans,ans+=(a[i]+b[i]-1)/b[i]*b[i]-a[i];
    ct(ans)
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

#define MOD LLONG_MAX

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

ll binary_square(ll x, ll n);

int main()
{
    int n;
    cin >> n;
    ll limit = binary_square(10, 18);
    //cout << limit << endl;
    ll ans=1;
    vector<ll> a;
    rep(i, n){
        ll x;
        cin >> x;
        if(x==0){
            cout << x << endl;
            return 0;
        }
        a.push_back(x);
    }

    rep(i, n){
        ll nowlimit = limit / ans;
        if(a[i]>nowlimit){
            ans = -1;
            break;
        }
        ll tmp = ans * a[i];
        ans = tmp;
    }
    cout << ans << endl;
    return 0;
}

ll binary_square(ll x, ll n)
{
    ll m = MOD;
    ll ans = 1;
    while (n)
    {
        if (n % 2 == 1)
        {
            ans = ans * x % m;
        }
        x = x * x % m;
        n >>= 1;
    }
    return ans % m;
}

Measured memory_bytes: 4256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, *X = map(int, read().split())

    if N >= M:
        print(0)
        return

    X.sort()
    dist = [0] * (M - 1)
    for i in range(M - 1):
        dist[i] = X[i + 1] - X[i]

    dist.sort()
    ans = sum(dist[: M - N])

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 20408
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void) {
	int a, b;
	double c, d;
	cin >> a >> b;
	c = a;
	d = b;
	cout << a / b << " " << a % b << " ";
	printf("%.8f\n", c / d);
		return 0;
}


Measured memory_bytes: 3224
ans = 0
s = input()
l = len(s)

N = [0 for i in range(l)]

for i in range(l):
    N[i] = int(s[-i-1])
N.append(0)

for i in range(l+1):
    if N[i]<5:
        ans += N[i]
    elif N[i]>5:
        ans += 10-N[i]
        N[i+1] += 1
    elif N[i+1]>4:
        ans += 10-N[i]
        N[i+1] += 1
    else:
        ans += N[i]

print(ans)


Measured memory_bytes: 118764
#include <iostream>
#include <vector>
#include <algorithm>


#define int long long
using namespace std;


signed main(){
	int n, k;
	cin >> n >> k;
	vector <int> a(n);
	for (int i = 0; i < n; ++i){
		cin >> a[i];
	}

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

	int ans = 0;
	for (int i = 0; i < k; ++i){
		ans += a[n - 1 - i];
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<P> vp;
typedef vector<T> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll dp[10005][105][2];// dp[i][sum%D][less]: 0~i-1番目まで決めたときの総数

int main () {
  string s;
  int D;
  cin >> s >> D;
  int n = s.size();

  dp[0][0][0] = 1;
  rep(i,n)rep(j,D)rep(k,2) {
    int nd = s[i]-'0';
    rep(d,10) {
      int ni = i+1, nj = (j+d)%D, nk = k;
      if (k == 0) {
        if (d > nd) continue;
        if (d < nd) nk = 1;
      }
      (dp[ni][nj][nk] += dp[i][j][k]) %= mod;
    }
  }

  ll ans = (dp[n][0][0] + dp[n][0][1] - 1 + mod)%mod;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 16640
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    void solve(Scanner sc, PrintWriter pw) {
        int N = sc.nextInt();
        long D = sc.nextLong();
        int result = 0;
        for (int i = 0; i < N; i++) {
            long x = sc.nextLong();
            long y = sc.nextLong();
            if (x * x + y * y <= D * D) {
                result++;
            }
        }
        pw.println(result);
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        new Main().solve(sc, pw);
        pw.flush();
        pw.close();
        sc.close();
    }
}


Measured memory_bytes: 59300
//Optimise
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// #define MULTI_TEST
#ifdef LOCAL
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
#define pc(...) PC(#__VA_ARGS__, __VA_ARGS__);
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
    out << '[' << p.first << ", " << p.second << ']';
    return out;
}
template <typename Arg>
void PC(const char *name, Arg &&arg)
{
    while (*name == ',' || *name == ' ')
        name++;
    std::cerr << name << " { ";
    for (const auto &v : arg)
        cerr << v << ' ';
    cerr << " }\n";
}
template <typename Arg1, typename... Args>
void PC(const char *names, Arg1 &&arg1, Args &&... args)
{
    while (*names == ',' || *names == ' ')
        names++;
    const char *comma = strchr(names, ',');
    std::cerr.write(names, comma - names) << " { ";
    for (const auto &v : arg1)
        cerr << v << ' ';
    cerr << " }\n";
    PC(comma, args...);
}
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
    std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
    const char *comma = strchr(names + 1, ',');
    std::cerr.write(names, comma - names) << " = " << arg1;
    ZZ(comma, args...);
}
#else
#define db(...)
#define pc(...)
#endif

using ll = long long;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define f first
#define s second
#define pb push_back
auto TimeStart = chrono::steady_clock::now();

const int NAX = 2e5 + 10, MOD = 1000000007;
int n;
string s;

void solveCase(int caseNo)
{
    cin >> n >> s;
    vector<vector<bool>> existLater(n + 2, vector<bool>(10));
    vector<vector<bool>> existBefore(n + 2, vector<bool>(10));
    s = '$' + s;
    set<pair<int, pair<int, int>>> S;
    for (int i = n; i > 0; --i)
    {
        existLater[i] = existLater[i + 1];
        if (i != n)
            existLater[i][s[i + 1] - '0'] = true;
    }
    for (int i = 1; i <= n; ++i)
    {
        existBefore[i] = existBefore[i - 1];
        if (i != 1)
            existBefore[i][s[i - 1] - '0'] = true;
    }
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 0; j < 10; ++j)
            for (int z = 0; z < 10; ++z)
                if (existLater[i][z] && existBefore[i][j])
                    S.insert({j, {s[i] - '0', z}});
    }
    cout << S.size() << '\n';
}

int main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
#ifdef MULTI_TEST
    cin >> t;
#endif
    for (int i = 1; i <= t; ++i)
    {
        solveCase(i);
#ifdef TIME
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

int main(){ string s; cin >> s; ll  K; cin >> K;
           ll first_iterator = -1;
           for(int i = 0; i < s.size(); i++){ 
             if(s[i] != '1'){ first_iterator = i ; break;}}
           
    if( first_iterator == -1){ cout << 1 << endl;}
           else{
             if( first_iterator + 1 <= K){cout << s[first_iterator] - '0' << endl;}
             else{cout << 1 << endl; }}
           
           return 0;}

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

int main() {
  int N;
  cin >> N;
  vector<int> cnt(pow(10, 5) + 1, 0);
  int max_v = 0;
  for (int i = 0; i < N; ++i) {
    int ai;
    cin >> ai;
    ++cnt[ai];
    max_v = max(max_v, ai);
  }
  cnt.resize(max_v + 1);
  int result = 0;
  for (int i = 0; i < pow(10, 5) - 1; ++i) {
    int sum = accumulate(cnt.begin() + i, cnt.begin() + i + 3, 0);
    result = max(result, sum);
  }
  cout << result << endl;
}

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

void CountingSort(int A[], int B[], int n, int k)
{
	int* C = new int[k + 1];
	for (int i = 0; i < k + 1; ++i)
	{
		C[i] = 0;
	}
	for (int i = 0; i < n; ++i)
	{
		C[A[i]]++;
	}
	for (int i = 1; i < k+1; ++i)
	{
		C[i] = C[i - 1] + C[i];
	}
	for (int i = n - 1; i >= 0; --i)
	{
		C[A[i]]--;
		B[C[A[i]]] = A[i];
	}
}

int main()
{
	int n = 0;
	cin >> n;
	int* A = new int[n];
	int* B = new int[n];
	int max = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> A[i];
		if (A[i] > max)
		{
			max = A[i];
		}
		B[i] = A[i];
	}
	CountingSort(A, B, n, max);
	for (int i = 0; i < n; ++i)
	{
		if (i != 0)
		{
			cout << ' ';
		}
		cout << B[i];
	}
cout<<endl;
	return 0;
}


Measured memory_bytes: 18744
#include "bits/stdc++.h"

using namespace std;

void Main() {
    int N;
    cin >> N;
    vector<int> A(N, 0);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    int ans = 0;
    for (int i = 1; i < N; ++i) {
        ans += A[i] - A[i - 1];
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

int main(){
  int n,m;
  cin>>n>>m;
  int a[100][100];
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cin>>a[i][j];
    }
  }
  int b[100];
  for(int i=0;i<m;i++){
    cin>>b[i];}
  int c[100]={};
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      c[i] +=a[i][j]*b[j];
    }
  }
  for(int i=0;i<n;i++) cout<<c[i]<<endl;
  return 0;
}


Measured memory_bytes: 3104
#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 equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) cin >> p[i];

  sort(p.begin(), p.end());
  int ans = 0;
  rep(i, k) ans += p[i];
  cout << ans << '\n';

  




  
  return 0;
}

Measured memory_bytes: 3672
n=gets.to_i
a=gets.split.map(&:to_i)
h=a.group_by{|e|e}.select{|k,v|v.size>1}.map{|k,v|[k,v.size]}.sort{|x,y|x[0]<=>y[0]}
puts n-(h.inject(0){|s,x|s+x[1]-1}*1.0/2).ceil*2


Measured memory_bytes: 18820
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

N, M = map(int,input().split())
UFT = UnionFind(N)
for _ in range(M):
    A, B = map(int,input().split())
    UFT.union(A-1, B-1)

print(UFT.group_count() - 1)

Measured memory_bytes: 12928
//---------- begin union_find ----------
mod union_find {
    pub struct UF {
        p: Vec<i32>,
    }
    #[allow(dead_code)]
    impl UF {
        pub fn new(n: usize) -> UF {
            UF {p: vec![-1; n] }
        }
        pub fn init(&mut self) {
            for p in self.p.iter_mut() {
                *p = -1;
            }
        }
        pub fn root(&mut self, mut x: usize) -> usize {
            while self.p[x] >= 0 {
                x = self.p[x] as usize;
            }
            x
        }
        pub fn same(&mut self, x: usize, y: usize) -> bool {
            self.root(x) == self.root(y)
        }
        pub fn unite(&mut self, mut x: usize, mut y: usize) {
            x = self.root(x);
            y = self.root(y);
            if x == y {
                return;
            }
            if self.p[x] > self.p[y] {
                let s = x;
                x = y;
                y = s;
            }
            self.p[x] += self.p[y];
            self.p[y] = x as i32;
        }
        pub fn get_size(&mut self, x: usize) -> usize {
            let r = self.root(x);
            (-self.p[r]) as usize
        }
    }
}
//---------- end union_find ----------
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let 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 $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")
    };
}

// ここまで

fn run() {
    input! {
        n: usize,
        h: usize,
        w: usize,
        e: [(usize1, usize1, u64); n],
    }
    let mut e = e;
    e.sort_by_key(|e| e.2);
    let mut u = union_find::UF::new(h + w);
    let mut cnt = vec![0; h + w];
    let mut ans = 0;
    println!("");
    for &(a, b, c) in e.iter().rev() {
        let b = b + h;
        if !u.same(a, b) {
            let a = u.root(a);
            let b = u.root(b);
            u.unite(a, b);
            let z = u.root(a);
            cnt[z] += cnt[a ^ b ^ z];
        }
        let r = u.root(a);
        if cnt[r] < u.get_size(r) {
            cnt[r] += 1;
            ans += c;
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 13560
import sys
N, M = map(int, raw_input().split())
A = [raw_input() for i in range(N)]
B = [raw_input() for i in range(M)]
for i in range(N):
    if i + M - 1 >= N:
        break
    for j in range(N):
        if j + M - 1 >= N:
            break
        match = True
        for k in range(M):
            for l in range(M):
                if A[i + k][j + l] != B[k][l]:
                    match = False
                    break
            if not match:
                break
        if match:
            print "Yes"
            sys.exit(0)
print "No"


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

int main(){
    int n, result, i;
    scanf("%d", &n);
    for (i = 1; i < 10; i++){
        result = n / i;
        if (result > 0 && result < 10 && n % i == 0){
            printf("Yes");
            return 0;
        }
    }
    printf("No");
}


Measured memory_bytes: 128
cards = {
        'S':[0 for _ in range(13)],
        'H':[0 for _ in range(13)],
        'C':[0 for _ in range(13)],
        'D':[0 for _ in range(13)],
        }

n = int(input())
for _ in range(n):
    (s, r) = input().split()
    cards[s][int(r) - 1] = 1

for s in ['S','H','C','D']:
    for r in range(13):
        if cards[s][r] == 0:
            print(s, r+1)

Measured memory_bytes: 6724
n = int(input())
a = input()
b = input()
c = input()


def fix_str(s1, s2, s3):
    if s1 == s2 == s3:
        return 0
    if s1 == s2 or s1 == s3 or s2 == s3:
        return 1
    else:
        return 2

res = 0
for i in range(n):
    res += fix_str(a[i], b[i], c[i])

print(res)

Measured memory_bytes: 3060
/******************************************
*    AUTHOR:         Atharva Sarage       *
*    INSTITUITION:   IIT HYDERABAD        *
******************************************/
#include<bits/stdc++.h>
#warning Check Max_Limit,Overflows
using namespace std;
# define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define ff first
# define ss second
# define pb push_back
# define mod 1000000007
# define ll long long 
# define db double
# define pii pair<ll,ll>
# define inf (ll)1e18
# define mx2 1000005
# define mx (1<<19)
# define endl "\n"
ll a[mx];
pii F[mx];
int main()
{
	ll n;
	cin>>n;
	for(ll i=0;i<(1<<n);i++){ll x;cin>>x;F[i]={x,0};}
	for(ll i = 0;i < n; ++i) 
	{
		for(ll mask = 0; mask < (1<<n); ++mask)
		{
			if(mask & (1<<i))
			{
				vector <ll> vec={F[mask].ff,F[mask].ss,F[mask^(1<<i)].ff,F[mask^(1<<i)].ss};
				sort(vec.begin(),vec.end(),greater<ll>());
				F[mask]={vec[0],vec[1]};
			}
		}
	}	
	ll temp=0;
	for(ll i=1;i<(1<<n);i++)
	{
		temp=max(temp,(F[i].ff+F[i].ss));
		cout<<temp<<endl;
	}
}


Measured memory_bytes: 9216
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define MP make_pair
typedef long long ll;
typedef std::pair<int,int> pii;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;


int main(){
    int n;
    while(cin>>n){
        if(n==-1)break;
        string s;
        if(n==0){
            cout<<0<<endl;
            continue;   
        }
        while(n>0){
            s.insert(s.begin(),'0'+n%4);
            n/=4;
        }
        cout<<s<<endl;
    }

    
    return 0;
}


Measured memory_bytes: 3024
from string import ascii_lowercase
from collections import Counter

def main():
    S = input()
    N = len(S)
    ans = 100
    c = Counter(list(S))

    if any(val == N for  val in c.values()):
        print(0)
        exit()


    for letter in ascii_lowercase:
        count = 0
        T = S
        while True:
            count += 1
            flag = True
            n = len(T)
            next_T = ""

            for i in range(n-1):
                if letter in T[i:i+2]:
                    next_T += letter
                else:
                    next_T += "#"
                    flag = False

            if flag:
                break
            T = next_T
        ans = min(ans, count)

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9796
#include<bits/stdc++.h>
using namespace std;
const int maxn = 100;
int n,m,k,ans;
int h[maxn];

int main(){
    //freopen("in.txt","r",stdin);
    scanf("%d",&n);
    int tmpMax = -1;
    ans = 0;
    for(int i = 0;i < n;i++){
        scanf("%d",h + i);
        if(tmpMax <= h[i]){
            ans++;
            tmpMax = h[i];
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    //static void Main_o(string[] args)
    //{
    //    // 整数の入力
    //    int a = int.Parse(Console.ReadLine());
    //    // スペース区切りの整数の入力
    //    while (a-- > 0)
    //    {
    //        Console.WriteLine("a");
    //    }
    //    string[] input = Console.ReadLine().Split(' ');
    //    int b = int.Parse(input[0]);
    //    int c = int.Parse(input[1]);
    //    // 文字列の入力
    //    string s = Console.ReadLine();
    //    //出力
    //    Console.WriteLine((a + b + c) + " " + s);

    //}

    //static void Main1(string[] args)
    //{
    //    // 整数の入力
    //    string[] input = Console.ReadLine().Split(' ');
    //    int b = int.Parse(input[0]);
    //    int c = int.Parse(input[1]);
    //    int a = int.Parse(input[2]);
    //    //出力
    //    Console.WriteLine( (b+c < a ? "No" : "yes" ) );
    //    Console.ReadLine();
    //}

    static void Main(string[] args)
    {
        Dictionary<string,int> dct = new Dictionary<string, int>();
        // 整数の入力
        int n = int.Parse(Console.ReadLine());

        while (n-- > 0)
        {
            string s = Console.ReadLine();
            if (dct.ContainsKey(s))
            {
                dct[s] += 1;
            }
            else
            {
                dct[s] = 1;
            }
        }

        int m = int.Parse(Console.ReadLine());
        while(m-- > 0)
        {
            string s = Console.ReadLine();
            if (dct.ContainsKey(s))
            {
                dct[s] -= 1;
            }
        }

        int iMax = dct.Values.Max();
        Console.WriteLine ( (iMax > 0) ? iMax : 0 );
    }
}

Measured memory_bytes: 13152
#include <bits/stdc++.h> 
#define lowbit(x) x&(-x)
using namespace std;
typedef unsigned long long ll;
const int N = 1e4+5;

void dfs(int now,int n,string ans,int k){
	if(now == n){
		cout << ans << "\n";
		return ;
	}
	
	for(int i = 0;i <= k;++i) dfs(now+1,n,ans+(char)('a'+i),max(k,i+1));
	return ;
}

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    
    int n;
	cin >> n;
	dfs(0,n,"",0);
    return 0;
}

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

long long a,b,c,k;

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


Measured memory_bytes: 3636
package main

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

func main() {
	scanner := makeWordScanner()
	n := eGetInt(scanner)
	m := eGetInt(scanner)
	sumA, sumB := 0, 0
	for i := 0; i < n; i++ {
		sumA += n - i - 1
	}
	for i := 0; i < m; i++ {
		sumB += m - i - 1
	}
	fmt.Println(sumA + sumB)
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
const (
	TooLarge = math.MaxInt64
	TooSmall = math.MinInt64
)

func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeCharScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanRunes)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func pow(a, n int) int {
	if n == 0 {
		return 1
	}
	if n == 1 {
		return a
	}
	if n%2 == 1 {
		return pow((a*a), n/2) * a
	}
	return pow((a * a), n/2)
}
func powMod(a, n, mod int) int {
	if n == 0 {
		return 1 % mod
	}
	if n == 1 {
		return a % mod
	}
	if n%2 == 1 {
		return powMod((a*a)%mod, n/2, mod) * a % mod
	}
	return powMod((a*a)%mod, n/2, mod)
}

func factoricalMod(n, count, mod int) int {
	if count == 1 {
		return n % mod
	}
	return (n % mod) * (factoricalMod(n-1, count-1, mod)) % mod
}

func combinationMod(n, a, mod int) int {
	x := factoricalMod(n, a, mod)
	y := factoricalMod(a, a, mod)
	y = powMod(y, mod-2, mod)
	return ((x % mod) * (y % mod)) % mod
}
func countBitOfOn(i, numbits int) int {
	count := 0
	var bit uint64
	for bit = 0; bit < uint64(numbits); bit++ {
		t := 1 << bit
		if i&t > 0 {
			count++
		}
	}
	return count
}

type ints []int

func ToString(slice []int) string {
	format := fmt.Sprint(slice)
	return fmt.Sprint(format[1 : len(format)-1])
}


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

int main(){
    int n,x;
    cin >> n >> x;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a.at(i);
    }
    ll cnt=0;
    if(a.at(0)>x){
        cnt+=a.at(0)-x;
        a.at(0)=x;
    }
    for(int i=1; i<n; i++){
        ll k=a.at(i)+a.at(i-1);
        if(k>x){
            cnt+=k-x;
            a.at(i) -= k-x;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=0,b=1, c,k=0, i, j,l=1e9+7;
  string s, r, y;
  cin>>n>>s;
  if(n%2) {cout<<"No";return;}
  sort(s.begin(),s. end());
  rep(i,0,s.length())
  {
    if(s[i]==s[i+1] && i+1<n){i++;continue ;}
    else if(i+1<n)
    {
      cout<<"No";return;
    }
  }
  cout<<"Yes";
  
// cout<<n*n;
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
 //  cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 
  
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = (int)1e9 + 7;
const int MX = (int)1e5 + 10;

void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}
void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}
void mul(int &x, int y){x = x * 1LL * y % mod;}


int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);

	int n;
	cin >> n;

	for(int i = 0; i <= n; ++i){
		int res = i * 1.08;
		if(res == n){
			cout << i << endl;
			return 0;
		}
	}

	cout << ":(";

	return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
pair<int, int> a[N];
int ans[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i].first;
		a[i].second = i;
	}
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; i++)
	{
		if (i <= n / 2) ans[a[i].second] = a[n / 2 + 1].first;
		else ans[a[i].second] = a[n / 2].first;
	}
	for (int i = 1; i <= n; i++)
		printf("%d\n", ans[i]);
	return 0;
}


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

int main() {
	int a,b;
	cin >> a >> b;
	if(a%3==0 || b%3==0 || (a+b)%3==0)
	cout << "Possible" << endl;
	else
	cout << "Impossible" << endl;
	// your code goes here
	return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC179
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            string d = string.Empty;
            for (int i = 0; i < N; i++)
            {
                var D = Console.ReadLine().Split(' ');
                if (int.Parse(D[0]) == int.Parse(D[1]))
                    d += "y";
                else
                    d += "n";
            }

            if (d.Contains("yyy"))
                System.Console.WriteLine("Yes");
            else
                System.Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 27572
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

template<class T>
bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//--------------------------- Solve ---------------------------//

int maze[3005][3005];
long long dp[3005][3005][5];

void solve() {
    int R, C, K; cin >> R >> C >> K;
    for (int i = 0; i < K; i++) {
        int r, c, v; cin >> r >> c >> v;
        maze[r][c] = v;
    }

    for (int i = 1; i <= R; i++) {
        for (int j = 1; j <= C; j++) {
            for (int k = 0; k < 4; k++) {
                // 上から
                // 拾わない
                chmax(dp[i][j][0], dp[i-1][j][k]);
                // 拾う
                chmax(dp[i][j][1], dp[i-1][j][k] + maze[i][j]);

                // 左から
                // 拾わない
                chmax(dp[i][j][k], dp[i][j-1][k]);
                // 拾う
                if (k < 3) chmax(dp[i][j][k+1], dp[i][j-1][k] + maze[i][j]);
            }

        }
    }

    long long ans = 0;
    for (int i = 0; i < 4; i++) {
        ans = max(ans, dp[R][C][i]);
    }

    cout << ans << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 390840
#include <iostream>
#include <cmath>

using namespace std;
typedef long long ll;

int main(void){
  ll a,b,c;

  cin >> a >> b >> c;

  ll d = c - a - b;
  if(d > 0 && d * d > 4 * a * b){
  cout << "Yes" << endl;
  } else {
  cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putbd cout << "---------------------------------------------" << endl;
#define putln(x) cout << x << endl;
#define debug(x) cerr << #x << "=" << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const int MOD = 1000000007;

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

//********************************template END****************************************//

ll gcd(ll x, ll y) {return (y == 0 ? x : gcd(y, x%y));}

void solve(void){
	ll N, ans = 0;
	cin >> N;
	rep(N, i)
	{
		ll a;
		cin >> a;
		ans += a - 1;
	}

	cout << ans << endl;
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << 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);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();

    int sameCount = 0 ;

    if( a == b ){
      sameCount ++ ;
    }
    if( b == c ){
      sameCount ++ ;
    }
    if( c == a ){
      sameCount ++ ;
    }

    switch(sameCount){
      case 0:
        System.out.println(3);
      break;
      case 1:
        System.out.println(2);
      break;
      case 3:
        System.out.println(1);
      break;
    }
  }
}


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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll X,N;
	cin >> X>>N;
	int arr[102] = {0};
	int ans = 0;
	for(int i = 0; i<N;i++)
	{
		int temp;
		cin >>temp;
		arr[temp]++;
	}
	for(int i = 0; i<=101;i++)
	{
		if(arr[i] != 1)
		{
			if(abs(X-i) < abs(X-ans))
			{
				ans = i;
			}
		}
	}
	cout <<ans<<endl;

}


Measured memory_bytes: 3636
#include<stdio.h>
int main(void){
  int i,p=0;
  char s[3];
  
  for(i=0;i<3;i++)scanf("%s",s);
  
  
    if(s[0]=='a'){
    if((s[1]=='b'&&s[2]=='c')||(s[1]=='c'&&s[2]=='b'))
      p+=1;
    }
    
  if(s[0]=='b'){
    if((s[1]=='a'&&s[2]=='c')||(s[1]=='c'&&s[2]=='a'))
    p+=1;
  }
  
  if(s[0]=='c'){
       if((s[1]=='a'&&s[2]=='b')||(s[1]=='b'&&s[2]=='a'))
    p+=1;
  }
  
  if(p)printf("Yes");
    else printf("No");
  

return 0;
}

Measured memory_bytes: 128
/*
 * main.c
 *
 *  Created on: 2020/07/27
 *      Author: 113896
 */
#include <stdio.h>

int main() {

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

	for (int i = n-1; i >= 0; i--) {
		printf("%d", arr[i]);
		if (i == 0) printf("\n");
		else printf(" ");
	}

	return 0;
}




Measured memory_bytes: 2068
a=[str(i) for i in input().split()]
if a[0]<=a[1]:
    b=[a[0] for i in range(int(a[1]))]
    b=''.join(b)
    print(b)
else:
    b=[a[1] for i in range(int(a[0]))]
    b=''.join(b)
    print(b)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
const ll INF = LLONG_MAX;
const ll MOD = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    vector<ll> a(N);
    vector<ll> color(9);
    rep(i, N)
    {
        cin >> a[i];
        if (a[i] < 3200)
            color[a[i] / 400]++;
        else
            color[8]++;
    }
    ll minA = 0, maxA = 0;
    rep(i, 8)
    {
        minA += min(color[i], 1ll);
        maxA += min(color[i], 1ll);
    }
    if (color[8] > 0) {
        maxA += color[8];
        if (color[7] == 0) {
            minA++;
        }
    }
    cout << minA << " " << maxA << endl;
    return 0;
}

Measured memory_bytes: 384
#include<cstdio>
int a,b;
int main()
{
  scanf(" %d %d",&a,&b);
  int c,d,e;
  c=a+b;d=a-b;e=a*b;
  if(c>d)d=c;
  if(d>e)e=d;
  printf("%d\n",e);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int vs[1001];

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> vs[i];
	}
	double sum = 0;
	for (int i = 0; i < n; i++) {
		sum += (1.0) / vs[i];
	}
	cout << (1 / sum);
	return 0;
}


Measured memory_bytes: 256