akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main()
{
  int W,H,x,y,r;
  cin >> W >> H >> x >> y>> r;
   
  if (x - r >= 0 && x + r <= W){
     if (y -r >= 0 && y + r <= H)
        cout << "Yes" << endl;
     else 
     cout << "No" << endl;
  } else 
  cout << "No" << endl;
}

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

int main()
{
  int n, m, ans = -1;
  cin >> n >> m;
  vector<pair<int, char>> sc;
  for (int i = 0; i < m; ++i)
  {
    int s;
    char c;
    cin >> s >> c;
    sc.push_back(make_pair(s, c));
  }
  for (int i = pow(10, n - 1) - 1, ma = pow(10, n); i < ma; ++i)
  {
    bool flag = 1;
    string str = to_string(i);
    if ((int)str.size() != n) continue;
    for (int j = 0; j < m; ++j)
    {
      if (str[sc[j].first - 1] != sc[j].second)
      {
        flag = 0;
        break;
      }
    }
    if (flag)
    {
      ans = i;
      break;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007
#define MAX 2000005

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;
//vector<vector<int>> data(3, vector<int>(4, -1));
//left + 1 < top

using namespace std;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.141592653589793;
long long fact[MAX], inv[MAX];
int dx[] = { -1,0,1,0 };
int dy[] = { 0,-1,0,1 };

//////////////////////////////////

vector<vector<int>> tree(100005);
int color[100005];
map<P, int>colorMap;
int m = 0;

struct BridgeInfo {
	int town1;
	int town2;
	int year;
	BridgeInfo(int t1, int t2, int y) {
		town1 = t1;
		town2 = t2;
		year = y;
	}
};

struct People {
	int index;
	int town;
	int year;
	People(int i, int t, int y) {
		index = i;
		town = t;
		year = y;
	}
};

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

struct UnionFind {
	vector<int>uf;
	
	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

ll CalcPow(ll num, ll power) {
	if (power == 0)return 1;
	if (power % 2 == 0) {
		ll half = CalcPow(num, power / 2);
		return (half * half) % MOD;
	}
	else return (num * CalcPow(num, power - 1)) % MOD;
}

ll combination(ll all, ll select) {
	if (all < select) return 0;
	if (all < 0 || select < 0) return 0;
	return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}

void initCombination(int max) {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= max; ++i) {
		fact[i] = fact[i-1] * i % MOD;
	}

	inv[max] = CalcPow(fact[max], MOD - 2);
	for (int i = max - 1; 0 <= i; --i) {
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
	}
}

void dfs(int from) {
	int c = 1;
	for (auto t : tree[from]) {
		c = c != color[from] ? c : c + 1;
		color[t] = c;
		colorMap[make_pair(from, t)] = c;
		m = max(c, m);
		dfs(t);
		c++;
	}
}

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

	int m = N;
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		int p;
		cin >> p;
		if (p <= m) ans++;
		m = min(m, p);
	}
	cout << ans << endl;
}

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

#define FILE_IN "post.in"
#define FILE_OUT "post.out"
#define ofile freopen(FILE_IN,"r",stdin);freopen(FILE_OUT,"w",stdout)
#define fio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define nfio cin.tie(0);cout.tie(0)
#define max(x,y) (((x)>(y))?(x):(y))
#define min(x,y) (((x)<(y))?(x):(y))
#define ord(a,b,c) ((a>=b)and(b>=c))
#define MOD (ll(998244353))
#define MAX 300001
#define mag 320
#define p1 first
#define p2 second.first
#define p3 second.second
#define pow2(x) (ll(1)<<x)
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;
typedef pair<ll,pii> piii;
#define endl "\n"
#define finish(s) {cout<<s;return 0;}


ll n,m,a[310][310];
ll od[310],ev[310],bit[310],xxj[310];
int main()
{
	fio;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>a[i][j],a[i][j]&=1;
	if(n<m)
	{
		for(int i=1;i<=n;i++)
			for(int j=i+1;j<=m;j++)
				swap(a[i][j],a[j][i]);
		swap(n,m);
	}
 
	int u=max(n,m);
	od[1]=1;ev[1]=3;
	for(int i=2;i<=u;i++)
	{
		od[i]=(ev[i-1]+3ll*od[i-1]%MOD)%MOD;
		ev[i]=(od[i-1]+3ll*ev[i-1]%MOD)%MOD;
	}
	ll cnt=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			if(a[i][j])
			{
				if(xxj[j])
					for(int k=j;k<=m;k++)
						a[i][k]^=a[xxj[j]][k];
				else {xxj[j]=i;cnt++;break;}
			}
	}
	bit[0]=1;
	for(int i=1;i<=u;i++) bit[i]=2ll*bit[i-1]%MOD;
	int bs=1ll*bit[n-cnt]*bit[m-cnt]%MOD;
	cout<<1ll*od[cnt]*bs%MOD;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>

using namespace std;
long long N;
int main()
{
	scanf("%lld",&N);
	printf("50\n");
	for(int i = 0; i < 50; i++)
	{
		if(i)
		{
			printf(" ");
		}
		printf("%lld",49-i+(N+49-i)/50);
	}
	return 0;
}


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

def main():
    N = int(input())
    for i in range(1, 10):
        if N%i == 0:
            t=N//i
            if 0 < t and t < 10:
                print("Yes")
                return
    print("No")
    return

if __name__ == "__main__":
    main()


Measured memory_bytes: 9100
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll x=a[0],y=a[1];
    vector<ll> vx,vy;
    for(int i=1;i*i<=x;i++){
        if(x%i==0){
            vx.pb(i);
            vx.pb(x/i);
        }
    }
    for(int i=1;i*i<=y;i++){
        if(y%i==0){
            vy.pb(i);
            vy.pb(y/i);
        }
    }
    ll ans=0;
    bool maki;
    for(int i=0;i<vx.size();i++){
        if(vx[i]>ans){
            maki=false;
            for(int j=0;j<n;j++){
                if(a[j]%vx[i]){
                    if(maki){
                        break;
                    }
                    else{
                        maki=true;
                    }
                }
                if(j==n-1){
                    ans=max(ans,vx[i]);
                }
            }
        }
    }
    for(int i=0;i<vy.size();i++){
        if(vy[i]>ans){
            maki=false;
            for(int j=0;j<n;j++){
                if(a[j]%vy[i]){
                    if(maki){
                        j=n;
                    }
                    else{
                        maki=true;
                    }
                }
                if(j==n-1){
                    ans=max(ans,vy[i]);
                }
            }
        }
    }
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
def score(s):
    return sum(map(int, s))


def main():
    s = input()
    best = score(s)
    for i in range(1, len(s)):
        ss = int(s) // 10**i * 10**i - 1
        best = max(best, score(str(ss)))
    print(best)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <unordered_set>

using namespace std;

int main() {
  int w, a, b;
  cin >> w >> a >> b;

  if (abs(a - b) <= w) {
    cout << 0 << endl;
  } else {
    cout << abs(a - b) - w << endl;
  }
}


Measured memory_bytes: 256
/*
 * 2501.cc: Grid Mori
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int INF = 1 << 30;

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;

  n--, a--, b--, c--, d--;
  int minhd = INF;

  for (int w = 1; w <= n; w++) {
    int xa = a % w, ya = a / w;
    int xb = b % w, yb = b / w;
    int xc = c % w, yc = c / w;
    int xd = d % w, yd = d / w;

    int hd = abs(xa - xb) + abs(ya - yb) + abs(xc - xd) + abs(yc - yd);
    if (minhd > hd) minhd = hd;
  }

  printf("%d\n", minhd);
  return 0;
}

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

int main(){
  int n,m;
  while(cin>>n>>m,n){
    int table[11]={0};
    int d,p;
    int max = 0;
    for(int i=0;i<n;i++){
      cin>>d>>p;
      table[p]+=d;
      if(max < p) max = p;
    }
    for(int i=max;i>=0;i--){
      if(table[i] <= m){
	m-=table[i];
	table[i]=0;
      }else{
	table[i]-=m;
	m=0;
	break;
      }
    }
    long long int sum=0;
    for(int i=0;i<=max;i++){
      sum+=i*table[i];
    }
    cout<<sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> H(N);
    rep(i, N) cin >> H.at(i);

    sort_g(H);
    ll cnt = 0;
    repi(i, K, H.size()) {
        cnt += H.at(i);
    }

    cout << cnt << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int a; 
	int sum;
	char b;
	cin>>sum;
	while(1){
		cin>>b;
		if(b=='=')	break;
		cin>>a;
		if(b=='+')	sum+=a;
		else if(b=='-')  sum-=a;
		else if(b=='*')  sum*=a;
		else	sum/=a;
	}
	cout<<sum<<endl;
	return 0;
}
		
		
		


Measured memory_bytes: 3116
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=200000000000000;
double pi=3.141592653589793;

const int MOD = 1000000007;

long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	return gcd(a%b,b);
}

long long lcm(long long a,long long b){
	return a/gcd(a,b)*b;
}
long myPow(long long x, long long n, long long m=MOD){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

ll N,M;
vector<ll>A(106);

void batten(ll i,ll k){
	if(i==N)return;
	if((A[i]%k)>(A[i+1]%k)){
		swap(A[i],A[i+1]);
		batten(i+1,k);
		return;
	}else{
		batten(i+1,k);
		return;
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll N;
	//cin>>N;
	ll A,B;
	cin>>A>>B;
	ll ans=0;
	if(A==1)ans+=300000;
	if(A==2)ans+=200000;
	if(A==3)ans+=100000;
	if(B==1)ans+=300000;
	if(B==2)ans+=200000;
	if(B==3)ans+=100000;
	if(A==1&&B==1)ans+=400000;
	cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
typedef map<int, vector<int>> Graph;
typedef map<int, map<int, int>> WGraph;
typedef pair<int, int> Edge;

map<Edge, bool> mp;
map<int, int> back;
vector<int> dijkstra(int v, WGraph &g, int r)
{
    vector<int> cost(v, 1 << 30);
    cost[r] = 0;
    priority_queue<pair<int, int>> pq;

    pq.push({0, r});

    while (!pq.empty())
    {
        //cerr << "-------------------------------" << endl;
        auto t = pq.top();
        pq.pop();
        //cerr << t.second << "," << t.first << endl;
        if (cost[t.second] < -t.first)
        {
            continue;
        }
        for (auto x : g[t.second])
        {
            if (cost[x.first] > cost[t.second] + g[t.second][x.first])
            {
                cost[x.first] = cost[t.second] + g[t.second][x.first];
                //cerr << "update cost[" << x.first << "] with " << cost[x.first] << endl;
                back[x.first] = t.second;
                pq.push({-cost[x.first], x.first});
            }
        }
    }
    return cost;
}

int main(int argc, char const *argv[])
{
    int n, m;
    cin >> n >> m;
    WGraph g;
    vector<Edge> e;
    rep(i, m)
    {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        g[a][b] = c;
        g[b][a] = c;

        e.push_back({a, b});
    }
    rep(i, n)
    {
        rep(i, n)
        {
            back[i] = -1;
        }
        dijkstra(n, g, i);
        // cerr << "d " << i << endl;
        rep(i, n)
        {
            //   cerr << back[i] << "," << i << endl;
            mp[{back[i], i}] = true;
        }
    }
    int ans = 0;
    for (auto x : e)
    {
        if (mp[x] == false)
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
($N,$A)=glob<>;@x=(map$_-$A,0,glob<>);for$i(0..$N){$d[$i]{$_}=$i?$d[$i-1]{$_}+$d[$i-1]{$_-$x[$i]}:!$_ for-2450..2500}print$d[$N]{0}-1,$/

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    int n, q;
    cin >> n >> q;

    string s;
    cin >> s;

    vi L(n, 0);
    int cnt = 0;
    rep(i, 0, n - 1) {
        if (s[i] == 'A' && s[i + 1] == 'C') {
            L[i + 1] = ++cnt;
        } else {
            L[i + 1] = cnt;
        }
    }

    rep(_, 0, q) {
        int l, r;
        cin >> l >> r;
        cout << L[r - 1] - L[l - 1] << endl;
    }

    return 0;
}

Measured memory_bytes: 1488
#include <cstdio>
#include <iostream>
#include <iomanip>
#include<cmath>
using namespace std;
int main() {
	double a, b, c, d;
	cin >> a >> b >> c >> d;
	double e = abs(c - a);
	double f = abs(d - b);
	double g = e * e + f * f;
	cout << fixed << setprecision(10) << sqrt(g) << endl;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
const long long INF = 10000000000;
int main() {
	int H, W; cin >> H >> W;
	char A[H][W];
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> A[i][j];
		}
	}
	int cnt = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (A[i][j] == '#') cnt++;
		}
	}
	if (cnt == H + W - 1) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define ABS(a) ((a)>(0)? a :-(a))

int asc(const void *a, const void *b) {
   return *(int *)a - *(int *)b;
}


int main(void) {
   int N, M;
   int L[100000+1];
   int L2[100000];
   scanf("%d%d", &N, &M);
   for (int i = 0; i < M; i++) {
      scanf("%d", &L[i]);
   }
   qsort(L, M,sizeof (L[0]), asc);
   for (int i = 0; i < M - 1; i++) {
      L2[i] = abs(L[i] - L[i+1]);
   }
   int ans = 0;
   qsort(L2,M - 1,sizeof (L2[0]), asc);
   for (int i = 0; i < M - 1 - (N - 1); i++) {
      ans += L2[i];
   }
   printf("%d\n", ans);
   return 0;
}


Measured memory_bytes: 1396
N = input()


def f(d, used, cur):
    num = len(used | set(cur))
    if d == 0:
        if num == 3:
            return 1
        else:
            return 0
    elif num == 1:
        return 3 ** d - 2 * (2 ** d) + 1
    elif num == 2:
        return 3 ** d - 2 ** d
    else:
        return 3 ** d


def high(N, used, ret):
    if N:
        if N[0] > "3":
            ret += f(len(N) - 1, used, "3")
        if N[0] > "5":
            ret += f(len(N) - 1, used, "5")
        if N[0] > "7":
            ret += f(len(N) - 1, used, "7")
    else:
        if len(used) == 3:
            ret += 1
        return ret
    if N[0] in "357":
        ret = high(N[1:], used | set(N[0]), ret)
    return ret


def low():
    ret = 0
    for d in range(len(N) - 1):
        ret += 3 * (3 ** d - 2 ** (d + 1) + 1)
    return ret


def main():
    print(high(N, set(), low()))
    return


main()


Measured memory_bytes: 3064
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a,b;
    scanf("%x%x",&a,&b);
		if(a<b) printf("<\n");
		if(a>b) printf(">\n");
		if(a==b) printf("=\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n, s, t;
    cin >> n >> s >> t;
    s--, t--;
    vector<vector<ll>> g(n);
    REP(i, n-1) {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    ll type;
    vector<vector<ll>> dist(2, vector<ll>(n));
    function<void(ll,ll,ll)> dfs = [&](ll v, ll p, ll d) {
        dist[type][v] = d;
        for(auto to: g[v]) {
            if(to == p) continue;
            dfs(to, v, d+1);
        }
    };
    type = 0;
    dfs(s, -1, 0);
    type = 1;
    dfs(t, -1, 0);

    ll ret = 0;
    REP(i, n) {
        if(dist[0][i] <= dist[1][i]) {
            chmax(ret, dist[1][i]-1);
        }
    }
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 15216
# -*- coding: utf-8 -*-
import sys 
from itertools import permutations
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10**31

N, M, R = map(int, readline().split())
r = list(map(int,readline().split()))
len_r = len(r)
cost = [[INF]*(N+1) for i in range(N+1)]

for i in range(M):
    s, t, d = map(int,readline().split())
    cost[s][t] = d
    cost[t][s] = d
  
for i in range(N+1):
    cost[i][i] = 0

for k in range(N+1):
    for i in range(N+1):
        for j in range(N+1):
            if cost[i][k] != INF and cost[k][j] != INF: #costがINFのときその道はつながっていないから
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])

ans = INF
for A in permutations(r,len_r):
    total = 0
    for i in range(len_r-1):
        s = A[i]
        t = A[i+1]        
        total += cost[s][t]
    ans = min(total,ans)
print(ans)

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int a, b; cin >> a >> b;
    if((a*b)%2 == 1){
        cout << "Odd" << endl;
    }else{
        cout << "Even" << endl;
    }
}

Measured memory_bytes: 256
from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

A,B,M = mi()
a = li()
b = li()
xyc = [li() for i in range(M)]

ans = min(a)+min(b)
for i in range(M):
    ans = min(ans,a[xyc[i][0]-1]+b[xyc[i][1]-1] - xyc[i][2])
print(ans)

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

LL A, B, C, D;
map<LL, LL> memo;
LL solve(LL N) {
    if (N == 0) return 0;
    if (N == 1) return D;
    if (memo.count(N)) return memo[N];
    LL l2 = (N/2)*2;
    LL r2 = ((N+1)/2)*2;
    LL l3 = (N/3)*3;
    LL r3 = ((N+2)/3)*3;
    LL l5 = (N/5)*5;
    LL r5 = ((N+4)/5)*5;

    LL res = 1e18;
    if (N < res/D) res = N*D;
    res = min(res, llabs(l2-N)*D + A + solve(l2/2));
    res = min(res, llabs(r2-N)*D + A + solve(r2/2));

    res = min(res, llabs(l3-N)*D + B + solve(l3/3));
    res = min(res, llabs(r3-N)*D + B + solve(r3/3));

    res = min(res, llabs(l5-N)*D + C + solve(l5/5));
    res = min(res, llabs(r5-N)*D + C + solve(r5/5));

    memo[N] = res;

    return res;
}

int main() {
    int T;
    cin >> T;
    for (int t = 0; t < T; t++) {
        memo.clear();
        LL N;
        cin >> N;
        cin >> A >> B >> C >> D;
        cout << solve(N) << "\n";
    }
}

Measured memory_bytes: 4380
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define rv(s) reverse(s.begin(),s.end());
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n;
  cin>>n;
  vi a(n);
  rep(i,n)cin>>a[i];
  
  vsort(a);
  int ans=a[0];
  irep(i,1,n){
    ans=GCD(ans,a[i]);
  }
  printf("%d\n",ans);
}

Measured memory_bytes: 640
//created by Whiplash99
import java.io.*;
import java.util.*;
public class Main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        long X=Long.parseLong(br.readLine().trim());
        long ans=(X/500)*1000;
        X%=500;
        ans+=5*(X/5);

        System.out.println(ans);
    }
}

Measured memory_bytes: 24916
#include <bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

int A[100000],n;

int binarysearch(int key){
  int left=0;
  int right=n;
  int mid;
  while(left<right){
    mid=(left+right)/2;
    if(key==A[mid]) return 1;
    if(key>A[mid]) left=mid+1;
    else if(key<A[mid]) right=mid;
  }
  return 0;
}

int main(){
  int i,q,k,sum=0;
  cin>>n;
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  cin>>q;
  for(i=0;i<q;i++){
    scanf("%d",&k);
    if (binarysearch(k)) sum++;
  }
  cout<<sum<<endl;
  return 0;
}



Measured memory_bytes: 3536
<?php
//最大公約数
function gcd($m, $n){
    if($n > $m) list($m, $n) = array($n, $m);

    while($n !== 0){
        $tmp_n = $n;
        $n = $m % $n;
        $m = $tmp_n;
    }
    return $m;
}

//最小公倍数
function lcm($m, $n){
    return $m * $n / gcd($m, $n);
}

echo lcm(2, trim(fgets(STDIN)))."\n";


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

int main(){
    ios_base::sync_with_stdio(false);
    int n,k,l;
    cin >> n >> k;
    vector<int> a;
    for(int i=0;i<n;i++){
        cin >> l;
        a.push_back(l);
    }
    int ans = 0;
    sort(a.begin(),a.end(),greater<int>());
    for(int i=0;i<k;i++){
        ans = ans+a[i];
    }
    cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include<string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int r, g, b, answer;
    cin >> r >> g >> b;
    string r_, g_ , b_, sum;
    r_ = to_string(r);
    g_ = to_string(g);
    b_ = to_string(b);
    sum = r_ + g_ + b_;
    answer = stoi(sum);
    if (answer % 4 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

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

#define ll long long

ll power2(ll a) {
  ll res = 0;
  while (a % 2 == 0) {
    res++;
    a /= 2;
  }
  
  return res;
}

int main() {
  int N;
  cin >> N;
  
  ll ans = 0;
  
  for (int i = 0; i < N; i++) {
    ll x;
    cin >> x;
    
    ans += power2(x);
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3644
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

void solve() {
	int a, b, t; cin >> a >> b >> t;
	int ans = 0;
	rep1(i, t) {
		if (i%a == 0)ans += b;
	}
	cout << ans << endl;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	long long P[N];
	for (int i = 0; i < N; i++) {
		cin >> P[i];
	}
	sort(P, P + N);
	P[N - 1] = P[N - 1] / 2;
	long long sum = 0;
	for (int i = 0; i < N; i++) {
		sum += P[i];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

constexpr int MOD = 1000000007;

// + - * / ^
int mod(int a)
{
    int res = a % MOD;
    if(res < 0) {
        return res + MOD;
    }
    return res;
}
int mul_mod(int a, int b)
{
    ll res = ((ll)a * (ll)b) % MOD;
    return mod((int)res);
}
int pow_mod(int a, int b)
{
    ll res = 1;
    while (b > 0) {
        if(b & 1) {
            res = res * (ll)a % (ll)MOD;
        }
        a = mul_mod(a, a);
        b >>= 1;
    }
    return (int)res;
}
int inv_mod(int a)
{
    return pow_mod(a, MOD - 2);
}
int div_mod(int a, int b)
{
    return mul_mod(a, inv_mod(b));
}

// ! C
constexpr int FAC_MAX = 3000000;
ll fac[FAC_MAX], finv[FAC_MAX], inv[FAC_MAX];
void com_init()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < FAC_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;
    }
}
ll com_mod(int a, int b){
    if (a < b) return 0;
    if (a < 0 || b < 0) return 0;
    return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD;
}


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    com_init();
    int r1, r2, c1, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    int ans = 0;
    repp (i, c1, c2 + 1) {
        ans = mod(ans + com_mod(r2 + i + 1, i + 1));
        ans = mod(ans - com_mod(r1 + i, i + 1));
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 70528
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define EPS 1e-14

#define all(v) v.begin(),v.end()
#define INF 1<<30
#define mp make_pair
#define pb push_back

#define fi first
#define se second

#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

typedef long long ll;

void solve(){
	int N;
	int A[100100] = {0};
	int B[100100] = {0};
	int C[100100] = {0};
	stack<int> s;
	cin >> N;
	rep(i,N) cin >> A[i];
	rep(i,N) cin >> B[i];
	rep(i,N) cin >> C[i];
	sort(A,A+N);
	sort(B,B+N);
	sort(C,C+N);
	long long ans = 0;
	int ta = 0;
	int tb = N-1;
	for(int i = 0; i < N ; ++i){
		while(ta < N && A[ta] < B[i]){
			ta++;
		}
		s.push(ta);
	}
	for (int i = N-1; i >= 0; --i)
	{
		while(tb >= 0 && C[tb] > B[i]){
			tb--;
		}
		ans += (long long)s.top()*(N-1-tb);
		s.pop();
	}

	cout << ans << endl;
	return ;
}

int main(){
	// while(1){
		solve();
	// }
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve() {
  ll n,m;
  cin>>n>>m;
  if(m==0){
    cout<<0<<" "<<0<<endl;
    return;
  }
  vi p(m);
  vector<string> s_(m);
  rep(i,m) cin>>p[i]>>s_[i];
  vi s(m,0);
  rep(i,m) if(s_[i]=="AC") s[i]=1;
  vector<P> v;
  rep(i,m) v.eb(make_pair(p[i],s[i]));
  //outvp(v);
  vector<pair<bool,ll>> foo(n+1,make_pair(false,0));
  rep(i,m){
    if(foo[v[i].fi].fi) continue;
    if(v[i].se==0) foo[v[i].fi].se++;
    else foo[v[i].fi].fi=true;
  }
  //outvp(foo);
  ll ac=0,wa=0;
  rep(i,n){
    if(foo[i+1].fi){
      ac++; wa+=foo[i+1].se;
    }
  }
  cout<<ac<<" "<<wa<<endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 10612
k = int(input())
ai = [int(i) for i in input().split()]

low = 2
high = 2*10**15
ans = []

while low+1 < high:
    tmp = 0
    mid = (low + high) //2
    #print(mid)
    tmp = mid
    
    for i in range(k):
        tmp = tmp // ai[i]
        tmp = tmp*ai[i]
    #print(tmp,mid,low)
    
    if tmp > 2:
        high = mid
    else:
        low = mid

tmp = low

for i in range(k):
    tmp = tmp // ai[i]
    tmp = tmp*ai[i]

if tmp != 2:
    print(-1)
    exit()
        
ans.append(low)

low = 2
high = 2*10**15

flag = True

while low+1 < high:
    tmp = 0
    mid = (low + high) //2
    if flag == True:
        flag = False
        mid = 2
    #print(mid)
    tmp = mid
    
    for i in range(k):
        tmp = tmp // ai[i]
        tmp = tmp*ai[i]
    #print(tmp)
    
    if tmp > 1:
        high = mid
    else:
        low = mid
    #print(mid)
ans.append(high)
tmp = high
for i in range(k):
    tmp = tmp // ai[i]
    tmp = tmp*ai[i]

if tmp != 2:
    print(-1)
    exit()
print(ans[1],ans[0])

Measured memory_bytes: 63984
#include <iostream>
#include <math.h>
static const int INF=1<<21;
using namespace std;
int p[105];
int X,N;
int main(void){
    
    cin>>X>>N;
    
    for(int i=0;i<N;i++){
        cin>>p[i];
    }
    int minv=INF;
    int Min;
    bool flag=true;
    for(int i=-1;i<=101;i++){
        for(int j=0;j<N;j++){
            if(p[j]==i) flag=false;
        }
        if(flag && minv>abs(X-i)){
            minv=abs(X-i);
            Min=i;
        } 
        flag=true;
    }
    printf("%d",Min);
}


Measured memory_bytes: 3764
import sys
sys.setrecursionlimit(10**9)

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

color = [-1] * N


def dfs(x, y):
    for i, w in G[x]:
        if color[i] == -1:
            color[i] = (y+w) % 2
            dfs(i, y+w)


dfs(0, 0)
for i in color:
    print(i)

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

int main()
{
	int n, m;

	int syu[1000 + 10] = { 0 };
	int sin;
	pair<int, int>runk[1000+10];
	int i,j;

	cin >> n>> m;

	for (i = 0; i < n; i++)
	{
		cin >> syu[i];
		runk[i].first = i;
		runk[i].second = 0;
	}
	for (i = 0; i < m; i++)
	{
		cin >> sin;
		for (j = 0; j < n; j++)
		{
			if (syu[j] <= sin)
			{
				runk[j].second++;
				break;
			}
		}
	}
	for (i = 0; i < n - 1; i++)
	{
		for (j = i + 1; j < n; j++)
		{
			if (runk[i].second < runk[j].second)
			{
				runk[1001] = runk[i];
				runk[i] = runk[j];
				runk[j] = runk[1001];
			}
		}
	}
	cout << runk[0].first + 1 << endl;
	return 0;
}

Measured memory_bytes: 3088
#include <stdio.h>

int main()
{
  int i, j;
  int le, ri;
  int lem, rim;
  scanf("%d%d", &le, &ri);
  lem=le%2019;
  rim=ri%2019;
  if(rim<lem || ri-le>=2019){
    printf("%d\n", 0);
    return 0;
  }
  int minrem=9999;
  for(i=lem;i<rim; i++){
    for(j=lem+1; j<=rim; j++){
      if((i*j)%2019<minrem) minrem=(i*j)%2019;
    }
  }
  printf("%d\n", minrem);
  return 0;
}

Measured memory_bytes: 128
import java.math.*

val map = mapOf(1 to 2, 2 to 5, 3 to 5, 4 to 4, 5 to 5, 6 to 6, 7 to 3, 8 to 7, 9 to 6)

fun main(args: Array<String>) {
    val (n, m) = readInputLine().split(" ").map{it.toInt()}
    val aList = readInputLine().split(" ").map{it.toInt()}.sortedDescending()
    
    val dp = IntArray(n + 1, {Int.MIN_VALUE})
    dp[0] = 0
    
    for (i in 1..n) {
        for (a in aList) {
            val oldIndex = i - map.get(a)!!
            if (oldIndex < 0) {
                continue
            }
            dp[i] = Math.max(dp[i], dp[oldIndex] + 1)
        }
    }
    
    var remain = n
    
    while (remain != 0) {
        for (a in aList) {
            val match = map.get(a)!!
            if (remain - match < 0) {
                continue
            }
            if (dp[remain - match] == dp[remain] - 1) {
                print(a)
                remain -= match
                break
            }
        }
    }
    
    println()
}

fun readInputLine(): String {
    return readLine()!!
}



Measured memory_bytes: 40996
import java.io.*;

class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String str;
		str = br.readLine();
		String[] str1 = (br.readLine()).split(" ");
		int n = Integer.parseInt(str);
		int[] arr = new int[n];
		int sum = 0;
		for(int i=0;i<n;i++){
			arr[i] = Integer.parseInt(str1[i]);
		}
		for(int i=0;i<n;i++){
			if(i<arr[i] && arr[arr[i]-1]==(i+1)){
				sum++;
			}
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 24340
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
const long long int m=pow(10,9)+7;

bool cmp(pair<int, int>& a, pair<int, int>& b) 
{ 
    return a.second < b.second; 
} 

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    set<ll>s;
    unordered_map<ll,ll>m;
    for(int i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        s.insert(x);
        m[x]++;
    }
    if(s.size()<=k)
        {cout<<"0"<<endl;return 0;}
    if(s.size()>k)
    {
        vector<pair<int,int>>v;
        for(auto x:m)
        v.push_back(x);
        sort(v.begin(), v.end(), cmp); 
        ll ans=0;
        for(int i=0;i<s.size()-k;i++)
        {
            ans+=v[i].second;
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 23764
n = parse(Int, readline())
a = parse.([Int64], split(readline()))

ans = 10^18
s = [0]
for ai in a
    push!(s, s[end] + ai)
end
for i in 2 : n
    ans = min(ans, abs(s[i] - (s[end] - s[i])))
end
println(ans)

Measured memory_bytes: 173520
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

h, w = map(int, input().split())
graph = []
for _ in range(h):
    r = input().strip()
    if set(r) == {'.'}:
        continue
    graph.append(r)

transpose_graph = [[0] * len(graph) for _ in range(w)]
for i in range(len(graph)):
    for j in range(w):
        transpose_graph[j][i] = graph[i][j]

graph = []
for i in range(w):
    if set(transpose_graph[i]) == {'.'}:
        continue
    graph.append(transpose_graph[i])

transpose_graph = [[0] * len(graph) for _ in range(len(graph[0]))]
for i in range(len(graph)):
    for j in range(len(graph[0])):
        transpose_graph[j][i] = graph[i][j]

for r in transpose_graph:
    print(''.join(r))


Measured memory_bytes: 67680
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define MXN 200005
int main(){
    int n,c,k;
    scanf("%d %d %d",&n,&c,&k);
    int t[100005];
    priority_queue<int,vector<int>,greater<int> > pq;
    for(int i = 0;i<n;i++){
        scanf("%d",&t[i]);
        pq.push(t[i]);
    }
    //sort(t,t+n);
    int ans=0;
    while(!pq.empty()){
        int x=pq.top();
        int cnt=1;
        pq.pop();
        while(!pq.empty()){
            if(cnt==c)break;
            int a=pq.top();
            if(a>x+k)break;
            cnt++;
            pq.pop();
            
        }
        ans++;
    }
    printf("%d\n",ans);
}


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

int main(){
  string S;
  cin >> S;
  int count=0;
  for(int i=0;i<S.size()-1;i++){
    if(S.at(i)!=S.at(i+1)){
      count++;
    }
  }
  cout << count << endl;
} 

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

int n;
long long x;
long long tab[2007];

long long dp[2007][2007];

long long inf=(long long)1000000000*1000000000;

long long wyn=inf;

long long s;

int main()
{
    scanf("%d%lld", &n, &x);
    for (int i=0; i<n; i++)
    {
        scanf("%lld", &tab[i]);
        s+=tab[i];
    }
    wyn=s;
    for (int i=0; i<n; i++)
        dp[0][i]=tab[i];
    for (int i=1; i<n; i++)
    {
        for (int j=1; j<n; j++)
            dp[i][j]=min(dp[i-1][j-1], tab[j]);
        dp[i][0]=min(dp[i-1][n-1], tab[0]);
        s=0;
        for (int j=0; j<n; j++)
            s+=dp[i][j];
        wyn=min(wyn, s+i*x);
    }
    printf("%lld\n", wyn);
    return 0;
}


Measured memory_bytes: 31616
#sys.stdout=open("output.txt", 'w')
#sys.stdout.write("Yes" + '\n')
#from  sys import stdin
#input=stdin.readline
#a = sorted([(n, i) for i, n in enumerate(map(int, input().split()))])
# from collections import Counter
# import sys
#s="abcdefghijklmnopqrstuvwxyz"
#n=int(input())
#n,k=map(int,input().split())
#arr=list(map(int,input().split()))
#arr=list(map(int,input().split
n=int(input())
abc=[]
for i in range(n):
    abc.append(list(map(int,input().split())))
dp=[[-1,-1,-1] for i in range(n)]


for i in range(n):
    if i==0:
        for j in range(3):
            dp[i][j]=abc[i][j]
    else:
        dp[i][0]=max(dp[i-1][1]+abc[i][0],dp[i-1][2]+abc[i][0])
        dp[i][1]=max(dp[i-1][2]+abc[i][1],dp[i-1][0]+abc[i][1])
        dp[i][2]=max(dp[i-1][0]+abc[i][2],dp[i-1][1]+abc[i][2])
print(max(dp[n-1]))

Measured memory_bytes: 47344
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

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;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string s, t; cin >> s >> t;
    string ans = "";
    rep(i, n) {
        ans += s[i];
        ans += t[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
S = input()

if S[K-1] == 'A':
  print(S[:K-1] + 'a' + S[K:])
elif S[K-1] == 'B':
  print(S[:K-1] + 'b' + S[K:])
elif S[K-1] == 'C':
  print(S[:K-1] + 'c' + S[K:])  

Measured memory_bytes: 3060
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

int main(void)
{
    std::vector<int64_t> X(5);

    for (auto& x : X) {
        std::cin >> x;
    }

    int64_t ans = 1;

    for (auto x : X) {
        if (x == 0) break;
        ans++;
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;

int gcd(int x, int y);

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    string s;
    cin >> s;

    int even = 0;
    int odd = 0;
    rep(i, s.size()) {
        if (i % 2 == 0) {
            if (s[i] == '1')
                even++;
        }
        else if (s[i] == '1')
            odd++;
    }
    int e_num = s.size() / 2;
    int o_num = s.size() / 2;
    if (s.size() % 2 == 1)
        e_num++;

    cout << min(e_num - even + odd, even + o_num - odd) << endl;
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map> 
#include<set> 
using namespace std;
#define mid 1000000007
typedef long long  ll;
map<ll,ll>k;
int main(){
	ll a,sum=0,i,b;
	cin>>a;
	for(i=1;i<=a;i++){
		cin>>b;
		sum+=k[i-b]; 
		k[i+b]++;
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 26152