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

using namespace std;

typedef long long ll;

int n, k;
int d[100002];
int edgeX[200002], edgeY[200002];
vector<pair<int, int> > link[100002];
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq;

bool visited[100002];
bool color[100002]; /// 0: B, 1: W
int weight[200002];

int main(){
    scanf("%d %d", &n, &k);
    for(int i=1; i<=n; i++){
        scanf("%d", &d[i]);
        pq.push(make_pair(d[i], i));
    }
    for(int i=1; i<=k; i++){
        scanf("%d %d", &edgeX[i], &edgeY[i]);
        link[edgeX[i]].push_back(make_pair(edgeY[i], i));
        link[edgeY[i]].push_back(make_pair(edgeX[i], i));
    }

    while(!pq.empty()){
        int x = pq.top().second;
        pq.pop();
        if(visited[x]) continue;
        visited[x] = 1;

        vector<pair<int, int> > bv, wv;

        for(auto &y: link[x]){
            if(visited[y.first]){
                if(color[y.first] == 0) bv.push_back(y);
                else wv.push_back(y);
            }
        }

        if(bv.empty() && wv.empty()){
            bool done = 0;
            for(auto &y: link[x]){
                if(d[x] == d[y.first]){
                    weight[y.second] = d[x];
                    color[x] = 0, color[y.first] = 1;
                    visited[y.first] = 1;
                    done = 1;
                    break;
                }
            }
            if(!done){
                printf("-1");
                return 0;
            }
            else continue;
        }

        bool done = 0;
        for(auto &y: bv){
            if(d[y.first] <= d[x]){
                weight[y.second] = d[x];
                color[x] = 1;
                done = 1;
                break;
            }
        }
        if(done) continue;
        for(auto &y: wv){
            if(d[y.first] <= d[x]){
                weight[y.second] = d[x];
                color[x] = 0;
                done = 1;
                break;
            }
        }
        if(done) continue;
        printf("-1");
        return 0;
    }
    for(int i=1; i<=n; i++) printf("%c", color[i] ? 'W' : 'B');
    puts("");
    for(int i=1; i<=k; i++) printf("%d\n", weight[i] ? weight[i] : (int)1e9);
}


Measured memory_bytes: 14068
N = int(input())
Weight = input().split()
Wall = []
for i in range(N):
    Wall.append(int(Weight[i]))
mT = 0
gT = 0
diff = []
ans = []
for k in range(N):
    for i in range(0,k):
        mT += Wall[i]
    for j in range(k,N):
        gT += Wall[j]
    if mT > gT:
        diff.append(mT - gT)
    else:
        diff.append(gT - mT)
    mT = 0
    gT = 0
print(min(diff))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		sb.append("");
		int r, c;
		r = scan.nextInt();
		c = scan.nextInt();
		int[][] ar = new int[r+1][c+1];
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				ar[i][j] = scan.nextInt();
			}
		}
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				ar[i][c] += ar[i][j];
				ar[r][j] += ar[i][j];
			}
		}
		for (int i : ar[r]) {
			ar[r][c] += i;
		}
		ar[r][c] /= 2;
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != c) {
					System.out.print(ar[i][j] + " ");
				}else {
					System.out.println(ar[i][j]);
				}
			}
		}
	}
}

Measured memory_bytes: 42480
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

class UnionFindTree
{
private:
    int n;
    int groupNum;       // グループの数
    vector<int> parent; // 親ノード
    vector<int> rank;   // 木の高さの上限
    vector<int> num;    // グループの要素数
    vector<pair<long long, int> > val;
    int find(int i){
        if(parent[i] == i)
            return i;
        else
            return parent[i] = find(parent[i]);
    }
public:
    UnionFindTree(int n){ // コンストラクタ
        this->n = n;
        groupNum = n;
        parent.resize(n);
        for(int i=0; i<n; ++i)
            parent[i] = i;
        rank.assign(n, 0);
        num.assign(n, 1);
        val.assign(n, make_pair(0, 0));
    }
    void unite(int a, int b){ // aとbのグループを併合
        if((a = find(a)) != (b = find(b))){
            if(rank[a] < rank[b]){
                parent[a] = b;
                num[b] += num[a];
                val[b].first += val[a].first;
                val[b].second += val[a].second;
            }
            else{
                parent[b] = a;
                if(rank[a] == rank[b])
                    ++ rank[a];
                num[a] += num[b];
                val[a].first += val[b].first;
                val[a].second += val[b].second;
            }
            -- groupNum;
        }
    }
    bool same(int a, int b){ // aとbのグループが同じかを調べる
        return find(a) == find(b);
    }
    int getNum(){ // グループの数を返す
        return groupNum;
    }
    int getNum(int a){ // aのグループの要素数を返す
        return num[find(a)];
    }
    pair<long long, int>& getVal(int a){
        return val[find(a)];
    }
};

class Edge
{
public:
    int a, b, weight;
    Edge(){
    }
    bool operator<(const Edge& other) const{
        return weight < other.weight;
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> x(n);
    for(int i=0; i<n; ++i)
        cin >> x[i];
    vector<Edge> edges(m);
    for(int i=0; i<m; ++i){
        cin >> edges[i].a >> edges[i].b >> edges[i].weight;
        -- edges[i].a;
        -- edges[i].b;
    }
    sort(edges.begin(), edges.end());

    UnionFindTree uft(n);
    for(int i=0; i<n; ++i)
        uft.getVal(i) = make_pair(x[i], 0);

    int ans = m;
    for(int i=0; i<m; ++i){
        int a = edges[i].a;
        int b = edges[i].b;
        uft.unite(a, b);
        if(edges[i].weight <= uft.getVal(a).first){
            ans -= uft.getVal(a).second + 1;
            uft.getVal(a).second = 0;
        }
        else{
            ++ uft.getVal(a).second;
        }
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;
#define ll long long int
const int MAXN = 2e5 + 10;

vector<pair<int, int>> g[MAXN];
ll dp[MAXN];

void solve(){
    int n, m;
    cin >> n >> m;
    for(int i = 0, x,y,z; i < m; ++i){
        cin >> x >> y >> z; x--; y--;
        g[x].push_back({y, z});
        g[y].push_back({x, -z});
    }

    for(int i = 0; i < n; ++i) dp[i] = INT_MAX;
    for(int i = 0; i < n; ++i){
        if(dp[i] == INT_MAX){
            queue<int> q;
            q.push(i);
            dp[i] = 0;
            while(!q.empty()){
                int u = q.front(); q.pop();
                for(auto & x: g[u]){
                    int to = x.first;
                    int c = x.second;
                    if(dp[to] == INT_MAX){
                        dp[to] = dp[u] + (ll)c;
                        q.push(to);
                    } else if( dp[to] != dp[u] + (ll)c){
                        cout << "No\n";
                        return;
                    }
                }
            }
        }
    }
    cout << "Yes\n";
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
	//int t; cin >> t;
	//while(t--)
		solve();
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;

const ll mod = 1e9+7;
const ll inf = 1e16;

#define loop(i,m,n) for(ll i=m;i<n;i++)
#define vloop(it,x) for(auto it=x.begin(); it!=x.begin(); it++)
#define all(x) x.begin(),x.end()
#define debug(x) cout << #x <<":"<< x <<endl	
#define showll(x) printf("%lld\n",x)
#define test(t) ll t;cin >> t;while(t--)
#define showc(x) printf("%c\n",x)
#define read(x) cin >> x
#define yes printf("YES\n")
#define no printf("NO\n")
#define pb push_back

void fast()
{
ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
}

//////////////////////////////// - _ - \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

ll n;

int main()
{
	fast();
	// debug(n);
	// showll(a);
	ll i,j,w,n,tmp;
	read(n);read(w);
//	debug(n);debug(w);
	
	ll val[n];
	ll wt[n];
	ll maxi = n*1000 + 10;
	ll dp[maxi];
	loop(i,0,n)
	{
		cin >> wt[i] >> val[i]; 
	}
	loop(i,0,maxi)
	{
		dp[i] = inf;
	}
	dp[0] = 0;
	loop(i,0,n)
	{
		for(j=maxi-1;j>=0;j--)
		{
			if(dp[j]==inf)
			{
				continue;
			}
			if((val[i]+j)<maxi)
			{
				dp[val[i]+j] = min(dp[val[i]+j],wt[i]+dp[j]);
			//	debug(wt[i]+j);
			//	debug(dp[wt[i]+j]);
			}
		}
	}
	ll ans= 0;
	loop(i,0,maxi)
	{
		if(dp[i]<=w)
		ans = max(ans,i);
	}
	showll(ans);
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <deque>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2 vector<vec>
#define vecll2 vector<vecll>
#define vec3 vector<vec2d>
#define vecll3 vector<vecll2d>
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
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;}
template<class T> inline void print(vector<T> v){for(T e:v)cout<<e<<" ";cout<<endl;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
void print(vector<vec> v){for(auto e:v){for(auto ee:e)cout<<ee<<" ";cout<<endl;}}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}
template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};
#define BIT BinaryIndexedTree

main(){
    int n=in();
    vector<BIT<ll>> bit(n*3+1,BIT<ll>(n*3+1));
    vec b(n),w(n);
    rep(i,n*2){
        char c;cin>>c;
        if(c=='B')b[in()-1]=i;
        else w[in()-1]=i;
    }
    vector<vecll> dp(n*3+1,vecll(n*3+1));
    dp[0][0]=0;
    rep(i,n*2){
        rep(j,i+1){
            if(i-j<n)
            chmax(dp[i+1][j],dp[i][j]+bit[j].sum(w[i-j]));
            if(j<n)
            chmax(dp[i+1][j+1],dp[i][j]+bit[j].sum(b[j]));
        }
        rep(j,i+1){
            if(i-j<n)
            bit[j].add(w[i-j],1);
        }
        if(i<n+1)
        rep(j,i+1){
            if(j<n)
            bit[i+1].add(b[j],1);
        }
    }
    ll ans=n*(n*2-1);
    cout<<ans-dp[n*2][n]<<endl;
}

Measured memory_bytes: 565504
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < (int)n;i++)
#define repb(i, n) for(int i = (int)n;i >= 0;i--)
#define reps(i, m, n) for(int i = (int)m;i < (int)n;i++)
#define repsb(i, m, n) for(int i = (int)m;i >= (int)n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
using namespace std;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[]) {
    string n;
    cin>>n;
    rep(i,3){
      if(n[i]=='1') n[i]='9';
      else if(n[i]=='9') n[i]='1';
    }
    cout<<n<<endl;
    return 0;
}


Measured memory_bytes: 256
from heapq import heappush,heappop,heapify
INF=10**30

def dijkstra(G,s,n):
    que=[(0,s)]
    dist=[INF]*n
    dist[s]=0
    while que:
        mincost,u=heappop(que)
        if(mincost>dist[u]):
            continue
        for c,v in G[u]:
            if(dist[u]+c<dist[v]):
                dist[v]=dist[u]+c
                heappush(que,(dist[v],v))
    return dist

sx,sy,gx,gy=map(int,input().split())
N=int(input())
X,Y,R=[sx,gx],[sy,gy],[0,0]
for i in range(N):
    t,m,p=map(int,input().split())
    X.append(t);Y.append(m);R.append(p)
G=[[] for i in range(N+2)]
for i in range(N+2):
    for j in range(i):
        d=max(0,((X[i]-X[j])**2+(Y[i]-Y[j])**2)**0.5-R[i]-R[j])
        G[i].append((d,j))
        G[j].append((d,i))
dist=dijkstra(G,0,N+2)
print(dist[1])

Measured memory_bytes: 121820
N=int(input())
tree=[[] for i in range(N)]
for i in range(N-1):
  u,v,w=map(int,input().split())
  tree[u-1].append((v-1,w))
  tree[v-1].append((u-1,w))
h=[]
h.append(0)
distance=[-1 for i in range(N)]
distance[0]=0
while h:
  k=h.pop(0)
  for v in tree[k]:
    x=v[0]
    y=v[1]
    if distance[x]==-1:
      distance[x]=distance[k]+y
      h.append(x)
for i in range(N):
  if distance[i]%2==0:
    print(0)
  else:
    print(1)

Measured memory_bytes: 47248
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>N;
    vec a(N), sum(N,0);
    rep(i,N) {
        cin>>a[i];
        sum[i] = a[i];
        if(i > 0) sum[i] += sum[i-1];
    }
    ll ans = 1e+15;
    rep(i,N-1){
        ans = min(ans, abs(sum[N-1] - sum[i] * 2));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
struct Card {
	char c;
	int v;
	Card() {}
	Card(char c, int v) :c(c), v(v) {}
	bool operator<=(const Card &p)const {
		return v <= p.v;
	}
	bool operator==(const Card &p)const {
		return c == p.c&&v == p.v;
	}
};
istream &operator >> (istream &is, Card &p) {
	is >> p.c >> p.v;
	return is;
}
ostream &operator<<(ostream &os, Card &p) {
	os << p.c << ' ' << p.v;
	return os;
}
template<typename T>
int partition(vector<T>&a, int l, int r) {
	T pivot = a[r];
	int i(l - 1);
	rep(j, l, r)if (a[j] <= pivot)swap(a[++i], a[j]);
	swap(a[++i], a[r]);
	return i;
}
template<typename T>
void quicksort(vector<T>&a, int l, int r) {
	if (!(l < r))return;
	int x = partition(a, l, r);
	quicksort(a, l, x - 1);
	quicksort(a, x + 1, r);
}
template<typename T>
void merge(vector<T>&a, int l, int r) {
	int mid = (l + r) / 2;
	int n1 = mid - l, n2 = r - mid;
	vector<T>L(n1 + 1), R(n2 + 1);
	rep(i, 0, n1)L[i] = a[l + i];
	L[n1] = T(0, INF);
	rep(i, 0, n2)R[i] = a[mid + i];
	R[n2] = T(0, INF);
	int i(0), j(0);
	rep(k, l, r) {
		if (L[i] <= R[j])a[k] = L[i++];
		else a[k] = R[j++];
	}
}
template<typename T>
void mergesort(vector<T>&a, int l, int r) {
	if (r - l > 1) {
		mergesort(a, l, (l + r) / 2);
		mergesort(a, (l + r) / 2, r);
		merge(a, l, r);
	}
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<Card> v(N); rep(i, 0, N) { cin >> v[i]; }
	vector<Card>w(v);
	mergesort(w, 0, N);
	quicksort(v, 0, N - 1);
	if (w == v)cout << "Stable" << endl;
	else cout << "Not stable" << endl;
	rep(i, 0, N)cout << v[i] << endl;
	return 0;
}

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

string s;

void solve()
{
	const int n = s.length();
	int ans = 0;
	int g = 0, p = 0;
	for(int i=0;i<n;++i){
		if(s[i] == 'g'){
			if(g > p) p++, ans++;
			else g++;
		}else{
			if(g > p) p++;
			else g++,ans--;
		}
	}
	cout << ans << '\n';
}

int main()
{	
	cin >> s;
	solve();
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const int MAX_N = 1e5 + 10;
ld dp[MAX_N];

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n, k;
    cin >> n >> k;
    ld now = 0;
    for(int i = max(n, k); i > 0; i --) {
        if(i >= k) {
            dp[i] = 1;
        } else if(i * 2 >= k) {
            dp[i] = 0.5;
        } else {
            dp[i] = 0.5 * dp[i * 2];
        }
        if(i <= n) {
            now += dp[i];
        }
    }
    cout << fixed << setprecision(10);
    cout << now / (ld)n << endl;
    return 0;
}




Measured memory_bytes: 5312
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <tuple>
#include <algorithm>

constexpr int MAX = 1010;

using ll = long long int;
using T = std::tuple<ll, int, int, int>;

ll a[MAX], b[MAX], c[MAX];

std::set<T> used;
std::priority_queue<T> que;

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

int main()
{

    int x, y, z, k;

    std::cin >> x >> y >> z >> k;

    for (int i = 0; i < x; ++i)
        std::cin >> a[i];
    for (int i = 0; i < y; ++i)
        std::cin >> b[i];
    for (int i = 0; i < z; ++i)
        std::cin >> c[i];

    std::sort(a, a + x, std::greater<>());
    std::sort(b, b + y, std::greater<>());
    std::sort(c, c + z, std::greater<>());

    que.emplace(a[0] + b[0] + c[0], 0, 0, 0);

    for (int i = 0; i < k; ++i)
    {
        int X, Y, Z;
        ll t;
        std::tie(t, X, Y, Z) = que.top();
        que.pop();
        std::cout << t << std::endl;

        for (int j = 0; j < 3; ++j)
        {
            int xx = X + dx[j], yy = Y + dy[j], zz = Z + dz[j];
            if (xx == x || yy == y || zz == z)
                continue;
            ll tt = a[xx] + b[yy] + c[zz];
            if (used.count(T(tt, xx, yy, zz)))
                continue;
            que.emplace(tt, xx, yy, zz);
            used.emplace(tt, xx, yy, zz);
        }
    }

    return 0;
}

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

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() {
    int n, k;
    int pla;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
        if (a[i] == 1)
            pla = i;
    }
    int ans = 0;

    ans = (n - 1) / (k - 1);
    if ((n - 1) % (k - 1) != 0)
        ans++;
    cout << ans << endl;
    return 0;
}

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

using namespace std;
using ll = long long;


int main()
{
    int n, t;
    cin >> n >> t;
    vector<int> x(n), y(n);
    for(int i = 0; i < n; i++)cin >> x[i] >> y[i];
    ll ans = 4e18 + 10000;

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            for(int k = 0; k < n; k++) {
                for(int l = 0; l < n; l++) {

                    int x1 = x[i], y1 = y[j], x2 = x[k], y2 = y[l];
                    if(x1 == x2 || y1 == y2)continue;
                    if(x1 > x2)swap(x1, x2);
                    if(y1 > y2)swap(y1, y2);

                    int cnt = 0;
                    for(int m = 0; m < n; m++){
                        if(x1 <= x[m] && x[m] <= x2 && y1 <= y[m] && y[m] <= y2)cnt++;
                    }
                    if(cnt >= t)ans = min(ans, (ll)(x2 - x1) * (y2 - y1));
                }
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
int main()
{
   int n,i,r,p=0,result;

   cin>>n>>r;
    while(n>0)
    {
        n=n/r;
        p++;
    }
    cout<<p<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
#define spln(i,n) (i==n?'\n':' ')
using namespace std;
inline void read(int &x)
{
	char c;int f=1;
	while(!isdigit(c=getchar()))if(c=='-')f=-1;
	x=(c&15);while(isdigit(c=getchar()))x=(x<<1)+(x<<3)+(c&15);
	x*=f;
}
int n,m,i,j,ans,lst=-2147483600;
struct ii
{
	int l,r;
}a[100005];
bool cmp(ii x,ii y)
{
	return x.r<y.r;
}
int main()
{
	read(n);
	fz1(i,n){
		int x,y;
		read(x);read(y);
		a[i].l=x-y;a[i].r=x+y;
	}
	sort(a+1,a+n+1,cmp);
	fz1(i,n){
		if(a[i].l>=lst){
			lst=a[i].r;
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

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

using namespace std;
typedef pair<int, int> pii;

int n,w,x[2][110]={0};
int dp[110][100010]={0};

signed main() {
	cin>>n>>w;
    rep(i,n){
        cin>>x[0][i]>>x[1][i];
    }

    rep(i,n+1){
        rep(j,100000+1){
            dp[i][j]=1e+9+1;
            if(j==0){
                dp[i][j]=0;
            }
        }
    }
    dp[0][0]=0;

    rep(i,n){
        rep(j,100000){
            dp[i+1][j+1]=dp[i][j+1];
            if(j+1-x[1][i]>=0){
                dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j+1-x[1][i]]+x[0][i]);
            }
        }
    }
	
    int ans;
    rep(i,100000+1){
        if(dp[n][i]<=w)ans=i;
    }
	
    cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 80128
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    long a =sc.nextLong();
    long b =sc.nextLong();
    long c =sc.nextLong();
    long d =sc.nextLong();
    long e =a*c;
    long f =b*d;
    long g =a*d;
    long h =b*c;
    long ans =Math.max(e,f);
    ans =Math.max(ans,g);
    ans =Math.max(ans,h);
    System.out.println(ans);
  }
}

Measured memory_bytes: 35772
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 2e3;
int h, w, u[N][N], d[N][N], r[N][N], l[N][N];
string s[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> w;
  FOR(i, 0, h) cin >> s[i];
  FOR(i, 0, h){
    int p = 0;
    FOR(j, 0, w){
      if(s[i][j]=='.') l[i][j] = ++p;
      else p = 0;
    }
  }
  FOR(i, 0, h){
    int p = 0;
    FORR(j, w-1, 0){
      if(s[i][j]=='.') r[i][j] = ++p;
      else p = 0;
    }
  }
  FOR(j, 0, w){
    int p = 0;
    FOR(i, 0, h){
      if(s[i][j]=='.') u[i][j] = ++p;
      else p = 0;
    }
  }
  FOR(j, 0, w){
    int p = 0;
    FORR(i, h-1, 0){
      if(s[i][j]=='.') d[i][j] = ++p;
      else p = 0;
    }
  }
  int ans = 0;
  FOR(i, 0, h)FOR(j, 0, w) if(s[i][j]=='.') maxs(ans, l[i][j]+r[i][j]+u[i][j]+d[i][j]);
  cout << ans-3 << endl;
}

Measured memory_bytes: 67072
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

import math

def func(i, j, d):
    if i <= 1:
        return 1
    e = j
    b = int(math.log2(d)/math.log2(i))
    ret = 1
    while e > b:
        ret = ret*(i**b%d)
        e = e - b
    else:
        if e > 0:
            ret = ret*(i**e%d)
    return ret


def main():
    N = int(input())
    Ds = [int(d) for d in input().split()]

    if Ds[0] != 0:
        print(0)
        return

    Ds.sort()
    if Ds[1] == 0:
        print(0)
        return

    i = 1
    l = 1
    r = 1
    ans = 1
    divider = 998244353

    while i < N:
        cnt = 0
        while i < N and Ds[i] == l:
            cnt = cnt + 1
            i = i + 1
        if cnt == 0:
            print(0)
            return

        ans = ans*func(r, cnt, divider)%divider
        r = cnt
        l = l + 1
    
    print(ans)

# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("nikkei2019-2-qual","b",main)


Measured memory_bytes: 14396
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,0,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;
const int MAX=3000;

signed main(){
    int N;cin>>N;
    int count=0;
  	int xcou=0;
    REP(i,N){
        int a;cin>>a;
        if(a%4==0)count++;
      	else if(a%2==0)xcou++;
    }
  	if(xcou>1)N-=xcou-1;
    cout<<(N/2<=count?"Yes":"No")<<endl;
}


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

int check(int a,int b,int r) {
	if (0 <= b - r && b + r <= a) {
		return 1;
	}
	else return 0;
}

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


Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ulli;
typedef long long int lli;
int main()
{
   
  int n;
   cin>>n;
   for(int i=n;i>=1;i--)
   {
     int j=0,k=0;
     for(int j=2;j<i;j++)
        if(i%j==0){
        for(k=1;pow(j,k)<=i;k++)
            if(i==pow(j,k))
            {
                cout<<i<<endl;
                return 0;
            }}
if(i==1)
cout<<1;
   }     

    return 0;
}  

Measured memory_bytes: 256
use proconio::input;
use std::cmp;

fn main() {
    input! {
        n: usize,
    }
    let mut dp = vec![0; n + 1];

    for i in 1..n + 1 {
        let mut min = dp[i - 1] + 1;
        for j in 1..7 {
            if i >= 6usize.pow(j) {
                min = cmp::min(min, dp[i - 6usize.pow(j)]+1);
            }
        }
        for j in 1..6 {
            if i >= 9usize.pow(j) {
                min = cmp::min(min, dp[i - 9usize.pow(j)]+1);
            }
        }
        dp[i] = min;
    }

    println!("{}", dp[n]);
}


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

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

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

    int a, b, n;
    cin >> a >> b >> n;
    a = max(a, b);
    cout << (n + a - 1) / a << endl;
}

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

using namespace std;

const int MOD = 1000000007;
const int MAX32 = 2147483647;
const double PI = 3.14159265358979323846;

int main() {
  int x;
  cin >> x;
  if (x >= 30){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int N, K; cin >> N >> K;
    vector<int> v;
    rep(i, N) { int t; cin >> t; v.pb(t); }
    sort(all(v));
    ll ans = 0;
    rep(i, N-K) ans += v[i];
    cout << ans << endl;
}

Measured memory_bytes: 1400
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n, a, b;
int main() {
  cin >> n >> a >> b;
  cout << max(0ll, (n-2)*(b-a)+1) << endl;
  return 0;
}



Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author varunvats32
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CRally solver = new CRally();
        solver.solve(1, in, out);
        out.close();
    }

    static class CRally {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] arr = new int[n];

            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
            }

            int stamina = Integer.MAX_VALUE;

            for (int i = 1; i <= 100; i++) {
                int st = 0;
                for (int j = 0; j < n; j++) {
                    st += Math.pow(i - arr[j], 2);
                }
                stamina = Math.min(st, stamina);
            }

            out.println(stamina);
        }

    }
}



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

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> v(n);
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    v[i] = make_pair(a, b);
  }
  sort(all(v));
  ll ans = 0;
  rep(i, n) {
    ll a, b;
    tie(a, b) = v[i];
    if(b <= m) {
      m -= b;
      ans += a * b;
    } else {
      ans += a * m;
      break;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 1792
N = int(input())
A = list(map(int,input().split( )))
Nodes = [1 for _ in range(N+1)]
for i in range(1,N+1):
  Nodes[i] = (Nodes[i-1]-A[i-1])*2
before = 0
ans = 0
for a,n in zip(A[::-1],Nodes[::-1]):
    if (n - a) >= before:
        before = before + a
    elif (n - a)*2 >= before :
        before = n
    else:
        ans = -1
        break
    ans += before
print(ans)

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

int isPrime(int x) {
    int i = 3;
    while (i <= x / i) {
        if (x % i == 0)
            return 0;
        i += 2;
    }
    return 1;
}

int main() {
    int x;
    cin >> x;
    if (x == 2 || x == 3) {
        cout << x << endl;
        return 0;
    };
    if (x % 2 == 0) x++;
    while (!isPrime(x)) {
        x += 2;
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

N,Q=map(int,input().split())
l=[ tuple( map(int,input().split()) ) for i in range(N-1) ]
p_l=[ tuple( map(int,input().split()) ) for i in range(Q) ]
d=defaultdict(list)

for f,g in l:
    d[f].append(g)

d_2=defaultdict(int)
for h in range(1,N+1):
    d_2[h]=0
  
for p,x in p_l:
    d_2[p]+=x

for n in range(1,N+1):
    for m in d[n]:
        d_2[m]+=d_2[n]

print(*d_2.values())


Measured memory_bytes: 150292
#include <cstdio>

int main()
{
	int a,b,c;
	scanf("%d %d %d", &a, &b, &c);
	if(a+b<=a+c and a+b<=b+c)
	{
		printf("%d", a+b);
	}
	else if(a+c<=a+b and a+c<=b+c)
	{
		printf("%d", a+c);
	}
	else if(b+c<=a+c and b+c<=a+b)
	{
		printf("%d", b+c);
	}
}

Measured memory_bytes: 1708
#include <iostream>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define out(v) cout<<v<<"\n"

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

  int d[N];
  rep(i, N) {
    cin >> d[i];
  }
  int ans = 0;
  rep(i, N) rep(j, i+1, N) {
    ans += d[i] * d[j];
  }
  out(ans);

  return 0;
}


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

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> x(n);
    for (int i = 0; i < n; i++) cin >> x[i];
    int res = INT_MAX;
    for (int p = 1; p <= 100; p++) {
        int s = 0;
        for (int xx : x) {
            s += (xx - p) * (xx - p);
        }
        res = min(res, s);
    }
    cout << res;

    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String str1 = in.next();
            String str2 = in.next();

            str2 = new StringBuilder(str2).reverse().toString();

            if (str1.equals(str2)) {
                out.print("YES");
            } else {
                out.print("NO");
            }
        }

    }
}



Measured memory_bytes: 21716
#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 A, B;
    string S;
    cin >> A >>B >> S;

    bool flg = true;
    rep(i, S.size()) {
        if(i == A) {
            if(S.at(i) != '-') flg = false;
        } else {
            if(!('0' <= S.at(i) && S.at(i) <= '9')) flg = false;
        }
    }

    cout << (flg ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	int n; cin >> n;
	string s, t; cin >> s >> t;
	for (int i = 0; i < n; i++) {
		cout << s[i] << t[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
char cheese[1002][1002];
bool done[1002][1002];
struct P{
	int x,y,depth;
};

int dx[] = {1,-1,0,0} , dy[] = {0,0,-1,1};
int bfs(int a,int b,int c,int d){
	rep(i,1002)rep(j,1002)done[i][j] = false;
	queue<P> Q;
	P t;
	t.x = a , t.y = b , t.depth = 0;
	Q.push(t);
	while(Q.size()){
		P q = Q.front(); Q.pop();
		if(q.x == c && q.y == d){
			return q.depth;
		}
		if(done[q.y][q.x])continue;
		done[q.y][q.x] = true;
		rep(i,4){
			P t;
			t.x = q.x + dx[i];
			t.y = q.y + dy[i];
			t.depth = q.depth + 1;
			if(cheese[t.y][t.x] == 'X')continue;
			Q.push(t);
		}
	}
	return -1;
}
int main(){
	int h,w,n;cin >> h >> w >> n;
	rep(i,1002)rep(j,1002)cheese[i][j] = 'X';
	rep(i,h)rep(j,w)cin >> cheese[i+1][j+1];
	
	int px[10],py[10];
	rep(i,h+1)rep(j,w+1){
		if(cheese[i][j] >= '1' && cheese[i][j] <= '9'){
			px[cheese[i][j]-'0'] = j;
			py[cheese[i][j]-'0'] = i;
		}
		if(cheese[i][j] == 'S')px[0] = j, py[0] = i;
	}
	int ret = 0;
	rep(i,n){
		ret += bfs(px[i],py[i],px[i+1],py[i+1]);
	}
	cout << ret << endl;
}

Measured memory_bytes: 2836
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

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

  int alimit = f / (100 * a);
  int blimit = f / (100 * b);
  int climit = f / c;
  int dlimit = f / d;

  double max = 0;
  int answ = a*100;
  int anss = 0;
  rep (i, alimit + 1){
    rep (j, blimit + 1){
      rep (k, climit + 1){
        rep (l, dlimit + 1){
          int w = 100*a*i + 100*b*j;
          int s = c*k + d*l;
          if (w+s <= f){
            if ((w != 0) || (s != 0)){
              if (e*w >= (s*100)){
                double dens = (1.0*s) / (w+s);
                if (max < dens){
                  max = dens;
                  answ = w;
                  anss= s;
                }
              }
            }
          }
        }
      }
    }
  }
  cout << answ + anss << " " << anss << endl;
  return 0;
}

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

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

  string a, b;
  long long e=0;
  cin >> a >>b;
  for (int i=0; i<3;i++){
    char c=a[i], d=b[i];
    if (c==d){
      e++;}}
  cout << e;}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main(){
  int N,M; cin>>N>>M;
  priority_queue<int,vector<int>,greater<int>>A;
  for(int i=0;i<N;i++){
    int a; cin>>a;
    A.push(a);
  }
  vector<P>ope(M);
  for(int i=0;i<M;i++) cin>>ope.at(i).second>>ope.at(i).first;
  sort(ope.rbegin(),ope.rend());
  
  for(int i=0;i<M;i++){
    while(A.top()<ope.at(i).first && ope.at(i).second>0){
      A.pop();
      A.push(ope.at(i).first);
      ope.at(i).second--;
    }
  }
  
  long long ans=0;
  
  while(A.size()>0){
    ans+=A.top();
    A.pop();
  }
  
  cout<<ans;
}

Measured memory_bytes: 1528
#include <iostream>
#include <cmath>
using namespace std;
int n, cx, cy, en, x[105], y[105], h[105];
int main() {
	int i, t;
	cin>>n;
	for(i=0; i<n; i++) {
		cin>>x[i]>>y[i]>>h[i];
		if(h[i]>0) en = i;
	}
	for(cx=0; cx<=100; cx++) for(cy=0; cy<=100; cy++) {
		t = h[en] + abs(x[en] - cx) + abs(y[en] - cy);
		for(i=0; i<n; i++) {
			if(max(t - (int)abs(x[i]-cx) - (int)abs(y[i]-cy), 0) != h[i]) break;
		}
		if(i==n) {cout<<cx<<' '<<cy<<' '<<t; return 0;}
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
const int maxn = 100010;
using namespace std;
bool vis[maxn]; int col[maxn]; ll h[3], ans;
int n, m, e, ter[maxn << 1], nxt[maxn << 1], lnk[maxn], opt[maxn];
void add(int x, int y) {
	ter[++ e] = y, nxt[e] = lnk[x], lnk[x] = e;
	ter[++ e] = x, nxt[e] = lnk[y], lnk[y] = e;
}
void bfs(int st) {
	int he = 0, ta = 1, ed = 0; opt[1] = st, vis[st] = false;
	col[st] = 0; bool flg = true;
	while (he != ta) {
		++ he; int u = opt[he];
		for (int i = lnk[u]; i; i = nxt[i]) {
			if (i & 1) ++ ed;
			if (vis[ter[i]]) {
				vis[ter[i]] = false;
				if (i & 1) col[ter[i]] = (col[u] + 1) % 3;
					else col[ter[i]] = (col[u] + 2) % 3;
				opt[++ ta] = ter[i];
			} else {
				if (i & 1) flg &= (col[ter[i]] == (col[u] + 1) % 3);
					else flg &= (col[ter[i]] == (col[u] + 2) % 3);
			}
		}
	}
	if (flg) {
		h[0] = h[1] = h[2] = 0;
		rep(i, 1, ta) ++ h[col[opt[i]]];
		if (!h[0] || !h[1] || !h[2]) { ans += ed; return ; }
		ans += h[0] * h[1] + h[1] * h[2] + h[2] * h[0];
	} else ans += (ll) ta * ta;
}
int main() {
	scanf("%d%d", &n, &m); int x, y;
	rep(i, 1, m) scanf("%d%d", &x, &y), add(x, y);
	memset(vis, true, sizeof(vis));
	ans = 0;
	rep(i, 1, n) if (vis[i]) bfs(i);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
//typedef long double ld;
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; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};

int main(){
  ll a,b,c,k; cin>>a>>b>>c>>k;
  ll sum=0;
  sum += min(a, k);
  k -= min(a, k);
  if(k>0){
    k -= min(b, k);
  }
  if(k>0){
    sum -= min(c, k);
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 3636
#include<cstdio>

using namespace std;

int main()
{
	static bool era[50000];
	era[0]=era[1]=true;
	for(int i=2;i<300;i++){
		if(!era[i])for(int j=i*i;j<50000;j+=i)era[j]=true;
	}
	int sz=0;
	static int p[5133];
	for(int i=2;i<50000;i++){
		if(!era[i])p[sz++]=i;
	}

	int n;
	for(;scanf("%d",&n),n;){
		int cnt=0;
		for(int i=0;n-p[i]>=0&&p[i]<=n/2;i++){
			if(!era[n-p[i]])cnt++;
		}
		printf("%d\n",cnt);
	}

	return 0;
}

Measured memory_bytes: 0