akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const int maxn = 3000005;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

int n,m,dp[105][105];
char a[105][105];
int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n>>m;
	memset(dp,0x3f,sizeof(dp));
	dp[0][1] = 0;
	for(int i = 1;i<=n;i++) for(int j = 1;j<=m;j++) cin>>a[i][j];
	for(int i = 1;i<=n;i++) {
		for(int j = 1;j<=m;j++) {
			if(a[i][j] == '#') {
				if(a[i-1][j] == '#') dp[i][j] = min(dp[i][j],dp[i-1][j]);
				if(a[i][j-1] == '#') dp[i][j] = min(dp[i][j],dp[i][j-1]);
				dp[i][j] = min(dp[i][j],min(dp[i-1][j],dp[i][j-1]) + 1);
			} else {
				dp[i][j] = min(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	cout<<dp[n][m]<<'\n';
	return 0;
}

Measured memory_bytes: 256
// AtCoder Regular Contest 076
// D - Built?

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pii> plii;


const int MAX_N = 100000;

class UnionFind {
    public:
        vector<int> data;
        void init(int size) {
            data = vector<int>(size, -1);
        }
        bool unite(int x, int y) {
            x = root(x); y = root(y);
            if (x == y) {
                return false;
            }
            if (data[y] < data[x]) {
                swap(x, y);
            }
            data[x] += data[y];
            data[y] = x;

            return true;
        }
        bool same(int x, int y) {
            return root(x) == root(y);
        }
        int root(int x) {
            return data[x] < 0 ? x : data[x] = root(data[x]);
        }
        int size(int x) {
            return -data[root(x)];
        }
};


int N;
pli X[MAX_N], Y[MAX_N];
priority_queue<plii, vector<plii>, greater<plii>> q;
UnionFind uf;
ll ans;

int main() {

    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> X[i].first >> Y[i].first;
        X[i].second = Y[i].second = i;
    }
    uf.init(N);
    sort(X, X + N);
    sort(Y, Y + N);

    for (int i = 1; i < N; i++) {
        q.push(make_pair(abs(X[i - 1].first - X[i].first), pii(X[i - 1].second, X[i].second)));
        q.push(make_pair(abs(Y[i - 1].first - Y[i].first), pii(Y[i - 1].second, Y[i].second)));
    }

    ans = 0;
    while (!q.empty()) {
        auto p = q.top(); q.pop();
        if (uf.same(p.second.first, p.second.second)) {
            continue;
        }
        ans += p.first;
        uf.unite(p.second.first, p.second.second);
    }

    cout << ans << endl;

    return 0;

}





Measured memory_bytes: 9968
#include <stdio.h>
#include <assert.h>

int main() {

    int n, c, total_p = 0, p;
    if ( scanf("%d %d", &n, &c) != 2 ) assert( 0 );
    ++n;
    
    for ( int i=0; i<c; ++i ) {
	if ( scanf("%d", &p) != 1 ) assert( 0 );
	total_p += p;
    }

    p = total_p/n;
    if ( total_p%n != 0 ) ++p;

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



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

int main(){
    int n;
    cin >> n;
    int w[n];
    int min=100;
    for(int i=0;i<n;i++){
        cin >> w[i];
    }
    
    for(int i=0;i<n;i++){
        int s1=0;
        int s2=0;
        int temp=0;
        for(int j=0;j<n;j++){
            if(j<=i){
                s1+=w[j];
            } else if(j>i){
                s2+=w[j];
            }
        }
        temp=s1-s2;
        if(temp<0){
            temp*=-1;
        }
        if(min>temp){
            min=temp;
        }
    }
    cout << min << endl;
    return 0;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

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

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

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

    int N, K;
    std::cin >> N >> K;
    
    int one_idx;
    for(int i=1;i<=N;++i){
        int a;
        std::cin >> a;

        if(a == 1){
            one_idx = i;
        }
    }

    int res = 200100;
    for(int i=0;i<K;++i){
        if(one_idx - i <= 0){continue;}

        int n1 = one_idx - i - 1,
            n2 = N - n1 - K;

        res = min(res, (n1 + K - 2) / (K - 1) + (n2 + K - 2) / (K - 1) + 1);
    }

    std::cout << res << std::endl;
}


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

namespace AOJ
{
    class Program
    {
        static void call(int n)
        {
            for (int i = 1; i <= n; ++i)
            {
                if (i % 3 == 0)
                {
                    Console.Write(" {0}", i);
                    continue;
                }

                for (int x = i; x != 0; x /= 10)
                {
                    if (x % 10 == 3)
                    {
                        Console.Write(" {0}", i);
                        break;
                    }
                }
            }

            Console.WriteLine();
        }

        static void Main(string[] args)
        {
            var inputLine = Console.In.ReadLine();
            var n = int.Parse(inputLine);
            call(n);
        }
    }
}


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

int main(void){
    int n;
    cin>>n;
    if(n>=100)n%=100;
    if(n>=10)n%=10;
    if(n==2 || n==4 || n==5 || n==7 || n==9){
        cout<<"hon"<<endl;
    }else if(n==0 || n==1 || n==6 || n==8){
        cout<<"pon"<<endl;
    }else if(n==3){
        cout<<"bon"<<endl;
    }
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    string ans;
    ans="Yes";
    if(n%2!=0){
        ans="No";
    }else{
        for(int i=0; i<n/2; i++){
           if(s.at(i)!=s.at(i+n/2)){
                ans="No";
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x; cin >> x;
    if (x <= 599) cout << 8 << '\n';
    else if (x <= 799) cout << 7 << '\n';
    else if (x <= 999) cout << 6 << '\n';
    else if (x <= 1199) cout << 5 << '\n';
    else if (x <= 1399) cout << 4 << '\n';
    else if (x <= 1599) cout << 3 << '\n';
    else if (x <= 1799) cout << 2 << '\n';
    else if (x <= 1999) cout << 1 << '\n';
    return 0;
}


Measured memory_bytes: 3648
[N,M]=[int(item)for item in input().split()]
items=[int(item)for item in input().split()]
items_sum=sum(items)

cnt=0
for item in items:
    if item >= items_sum /(4*M):
        cnt += 1
        if cnt==M:
            print("Yes")
            exit()
        
print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
 
const int mod = 1000000007;
//const int mod = 998244353;
 

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;}
 
 
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);
 
// M * (M-1)^(N-1-K) * N-1 C K
int main(int argc, const char * argv[]) {
    ll N,K; cin >> N >> K;
    mint dp0 = 1;
    mint dp1 = N * (N-1);
    mint ans = dp0 + dp1;
    
    
    if(N<=K){
        for(ll i=2;i<N;i++){
            ans += c(N,i) * c(N-1,i);
        }
    }
    else{
        for(ll i=2;i<=K;i++){
            ans += c(N,i) * c(N-1,i);
        }
    }
    cout << ans << endl;
    
}



Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define RI register int

using namespace std;

int const MAXN = 2e5 + 5;
struct Edges { int to, next; } e[MAXN];
int head[MAXN], tot;
int vis[MAXN], Ring[MAXN], stk[MAXN], top, a[MAXN], cnt, dfn[MAXN];
int ok[MAXN][21], b[MAXN];

inline void addedge(int from, int to) {
  e[++tot] = (Edges){to, head[from]};
  head[from] = to;
}

void Dfs(int now) {
  if (vis[now]) {
    while (stk[top] != now) a[++cnt] = stk[top--];
    a[++cnt] = stk[top--];
    return;
  }
  stk[++top] = now;
  vis[now] = 1;
  for (RI i = head[now]; i; i = e[i].next)
    if (!dfn[e[i].to]) Dfs(e[i].to);
  dfn[now] = 1;
  --top;
}

void Work(int now) {
  for (RI i = head[now]; i; i = e[i].next)
    if (!Ring[e[i].to])
      Work(e[i].to), ok[now][b[e[i].to]] = 1;
  for (RI i = 0; i < 20; ++i)
    if (!ok[now][i])
      return b[now] = i, void();
}

int main() {
 // freopen("a.in", "r", stdin);
  ios :: sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int n; cin >> n;
  for (RI i = 1, x; i <= n; ++i)
    cin >> x, addedge(x, i);
  for (RI i = 1; i <= n; ++i)
    if (!dfn[i]) Dfs(i);
  if (cnt % 2 == 0) return puts("POSSIBLE"), 0;
  for (RI i = 1; i <= cnt; ++i) Ring[a[i]] = 1;
  for (RI i = 1; i <= cnt; ++i)
    Work(a[i]);
  for (RI i = 2; i <= cnt; ++i)
    if (b[a[i]] != b[a[1]]) return puts("POSSIBLE"), 0;
  puts("IMPOSSIBLE");
  return 0;
}


Measured memory_bytes: 23552
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {

	int ans;

	int N;
	cin >> N;

	for (int i = 1; i <= 10; i++) {
		if (i * 1000 >= N) { cout << i * 1000 - N << endl; return 0; }
	}


	return 0;
}

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

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

    vector<int> ans(n);
    for(int i = 0; i < n; i++){
        if(i % 2 == 0){
            ans[i/2] = a[n-1-i];
        }else{
            ans[n-(i+1)/2] = a[n-1-i];
        }
    }

    for(int i = 0; i < n; i++){
        cout << ans[i];
        if(i != n-1) cout << " ";
        else cout << endl;
    }
} 

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

Measured memory_bytes: 3584
#!/usr/bin/env python3

def divmod2(n, d):
    a, b = divmod(n, d)
    if b == 0:
        return a-1, d
    return a,b

def base(n):
    ret = []
    while n > 0:
        n, d = divmod2(n, 26)
        ret += [chr(ord('a') + d - 1)]
    return ''.join(ret[::-1])

N = int(input())

print(base(N))

Measured memory_bytes: 61720
#include "bits/stdc++.h"
using namespace std;

int dp[100005];
bool visited[100005];
vector<int> adj[100005];

void visit(int vertex){
	visited[vertex] = 1;
	dp[vertex] = 0;
	for(int child:adj[vertex]){
		if(!visited[child]){
			visit(child);
		}
		dp[vertex] = max(dp[vertex] , 1 + dp[child]);
	}
}

int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
	}
	
  int ans = 0;
	for(int i = 1; i <= n; i++){
		if(!visited[i]){
			visit(i);
          ans = max(ans, dp[i]);
		}
	}
	
	
	

	
	cout<<ans<<endl;
	
}


Measured memory_bytes: 12188
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________


	int a, b;
	cin >> a >> b;
	if (a != 1 && b != 1)
		cout << 1 << en;
	else if (a != 2 && b != 2)
		cout << 2 << en;
	else
		cout << 3 << en;

	return 0;
}



Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
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;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



// まずdp[n][m]が答えの文字列の長さ
// dp[i-1][m]+1 == dp[i][m] ならsのi文字目を答えに追加
// これを後ろから繰り返せば答えが復元できる

int n, m, dp[3030][3030];
string s, t, res;

signed main() {
	cin >> s >> t;
	n = s.size(), m = t.size();
	rep(i,n) rep(j,m) {
		if (s[i]==t[j]) chmax(dp[i+1][j+1], dp[i][j] + 1);
		else chmax(dp[i+1][j+1], max(dp[i+1][j], dp[i][j+1]));
	}
	int i = s.size(), j = t.size();
	while (i && j) {
		if (dp[i][j]==dp[i-1][j]) i--;
		else if (dp[i][j]==dp[i][j-1]) j--;
		else res.push_back(s[i-1]), i--, j--;
	}
	reverse(all(res));
	cout << res << endl;
}

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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
#define VL vector<lol>
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define PI 3.1415926535897932385 //pi
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main()
{
    //lol result{0};
    lol n, m; cin >> n >> m;
    //lol k; cin >> k;
    /*
    VL a(n);
    REP(i, n)
    {
        cin >> a[i];
    }
    */
    if(n > m)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
    //cout << result << endl;
    return 0;
}

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

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

    int n;
    cin >> n;

    string s;
    cin >> s;

    int x = 0, y = 0;

    for(auto c : s){
        if(c == '(') x++;
        else if(x > 0) x--;
        else y++;
    }
    while(y) {
        cout << '(';
        y--;
    }
    cout << s;
    while(x){
        cout << ')';
        x--;
    }
    cout << endl;
}

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

int check(int h, int w, vector<vector<int>> &A){
    if (h>=0 && h < A.size() && w>=0 && w < A[0].size()){
       if (A[h][w] == 0){
           A[h][w] = 1;
           return true;
       } else{
           return false;
       }
    }else
    {
        return false;
    }
    
}


void solve(long long H, long long W, vector<vector<int>> A, set<pair<int,int>> blacks){
    int count = 0;
    while(1){
        set<pair<int,int>> next_blacks;
        for (const auto &b:blacks){
            if (check(b.first,b.second-1,A)) next_blacks.insert(make_pair(b.first,b.second-1));
            if (check(b.first,b.second+1,A)) next_blacks.insert(make_pair(b.first,b.second+1));
            if (check(b.first-1,b.second,A)) next_blacks.insert(make_pair(b.first-1,b.second));
            if (check(b.first+1,b.second,A)) next_blacks.insert(make_pair(b.first+1,b.second));

        }
        blacks = std::move(next_blacks);
        if (blacks.size() == 0) break;
        count++;

    }
    printf("%d\n",count);


}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    vector<vector<int>> A(H,vector<int>(W,0));
    set<pair<int,int>> blacks;
    for(int i = 0 ; i < H; i++){
        for (int j=0;j<W;j++){
            char c;
            cin >> c;
            if (c=='#'){
                A[i][j] = 1;
                blacks.insert(make_pair(i,j));
            } 
        }
    }
    solve(H, W, std::move(A),std::move(blacks));
    return 0;
}


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

int main()
{
  int n, m;
  int data[1001];

  while( cin >> n >> m, n+m ) {
    for(int i=0; i<n; i++) {
      cin >> data[i];
    }

    sort(data, data+n);
    int ans = 0;
    int cnt = 0;

    while( n > 0 ) {
      cnt++;
      n--;
      if( cnt == m ) {
	cnt = 0; 
	continue;
      } 
      ans += data[n];
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 1180
big = 10**5 + 1

N = int(input())
A = list(map(int, input().split()))
Q = int(input())

B, C = [0]*Q, [0]*Q
for i in range(Q):
    B[i], C[i] = map(int, input().split())

counts = [0]*big
total = 0
for Ai in A:
    counts[Ai] += 1
    total += Ai

for i in range(Q):
    Bi, Ci = B[i], C[i]
    total += (Ci - Bi)*counts[Bi]

    counts[Ci] += counts[Bi]
    counts[Bi] = 0
    print(total)



Measured memory_bytes: 84784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
const int nax = 1e5;
vector< int > G[nax];
vector< int > dp(nax);
vector< int > visited(nax);
void dfs(int u , int p){
	visited[u] = 1;
	for(auto v : G[u]){
		if(!visited[v])
			dfs(v , u);
		dp[u] = max(dp[u] , 1 + dp[v]);
	}
}
int main(int argc,char ** argv){
	int n , k;
	cin >> n >> k;
	for(int i = 0 ; i < k ; i++)
	{
			int x, y;
			cin >> x >>y;
			G[x].push_back(y);
	}
	for(int i = 1 ; i <= n ; i++){
		if(!visited[i])
			dfs(i , 0);
	}
	int ans = 0; 
	for(int i = 1; i <= n ; i++){
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8576
n = gets.to_i
a = Array.new(n).map{Array.new(2, 0)}
for i in 0..(n-1)
  a[i] = gets.split.map(&:to_i)
end
a.sort!{|s, t| s[1] <=> t[1]}
time = 0
flag = 1
for i in 0..(n-1)
  time += a[i][0]
  if time > a[i][1]
    flag = 0
    break
  end
end
if flag == 1
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 29540
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    string s;
    cin>>s;
    int n=s.size();
    int ans=n;
    rep(i,n){
        if(s[i]==s[i+1]){
            ans--;
            i+=2;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
package main

import "fmt"

func gcd(x, y int64) int64 {
        if y == 0 {
                return x
        } else {
                return gcd(y, x%y)
        }
}

func prime_factor(n int64) map[int64]int {
        ret := map[int64]int{}

        for i := int64(2); i*i <= n; i++ {
                for n%i == 0 {
                        ret[i]++
                        n /= i
                }
        }
        if n != 1 {
                ret[n]++
        }
        return ret
}

func main() {
        var a, b int64

        fmt.Scan(&a, &b)
        g := gcd(a, b)

        fmt.Println(len(prime_factor(g)) + 1)
}

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

int main() {
  int n ;
  cin >> n;
  vector <int> v(n) ;
  vector <double> a(n) ;
  a.at(0)  = 0.5;
   cin >> v.at(0) ;
  for (int i=1 ; i<n-1 ; i++){
    cin >> v.at(i) ;
    a.at(i) = a.at(i-1)*0.5 ;
  }
  cin >> v.at(n-1) ;
  a.at(n-1)=a.at(n-2) ;
  sort( v.begin() , v.end() );
  sort ( a.begin() , a.end() );
  double V = 0 ;
  for (int i=0 ; i<n ; i++){
    V += a.at(i)*v.at(i) ;
  }
  cout << V << endl;
}

Measured memory_bytes: 3808
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

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

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

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

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

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

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

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

fn main() {
  input! {
    x: i32,
    a: i32,
  }

  println!("{}", if x < a { 0 } else { 10 });
}


Measured memory_bytes: 4352
import numpy as np

def solve(inp):
    def bit_add(arr, n, i, x):
        while i <= n:
            arr[i] += x
            i += i & -i

    def bit_sum(arr, i):
        result = 0
        while i > 0:
            result += arr[i]
            i ^= i & -i
        return result

    N, Q = inp[:2]
    C = inp[2: 2+N]
    L, R = inp[2+N::2] - 1, inp[3+N::2] - 1

    just_left = {}
    segments = []
    for i in range(N):
        c = C[i]
        if c in just_left:
            segments.append((i, 0, just_left[c], 0))
        just_left[c] = i

    for i in range(Q):
        segments.append((R[i], 1, L[i], i))

    segments.sort()
    bit = np.zeros(N + 2, dtype=np.int64)
    ans = np.zeros(Q, dtype=np.int64)

    for r, tp, l, i in segments:
        if tp == 0:
            bit_add(bit, N + 2, l + 2, 1)
        else:
            base = r - l + 1
            ans[i] = base - (bit_sum(bit, r + 2) - bit_sum(bit, l + 1))

    return ans

def main():
    inp = np.fromstring(open(0).read(), dtype=np.int64, sep=' ')
    ans = solve(inp)
    print("\n".join(map(str,ans)))
    

def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()

if __name__ == '__main__':
    import sys
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    from my_module import solve
    main()

Measured memory_bytes: 98480
#include<bits/stdc++.h>
#define MOD 1000000007
#define MOD2 1000000006
#define TEMPMOD1 998244353
#define TEMPMOD2 998244352
#define INF 1000000000000000007
#define NEGINF -1000000000000000007
#define vll vector<ll> 
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define plll pair<ll,pll>
#define vpll vector<pll>
using namespace std;
typedef long long int ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    ll n;
    cin>>n;
    ll amount[n+1];
    ll actual[n+1];
    ll sum=0;
    for(ll i=1;i<=n;i++)
    {
        cin>>amount[i];
        sum+=amount[i];
    }
    sum=sum/2;
    for(ll i=1;i<n;i+=2)
    {
        sum-=amount[i];
    }
    actual[n]=sum;
    for(ll i=n-1;i>=0;i--)
    {
        actual[i]=amount[i]-actual[i+1];
    }
    for(ll i=1;i<=n;i++)
    {
        actual[i]=actual[i]*2;
        cout<<actual[i]<<" ";
    }
    return 0;
}
    

Measured memory_bytes: 2944
import qualified Data.ByteString.Char8 as BS
import Data.Maybe (fromJust)
import Control.Monad
import Data.List
import Debug.Trace

solve :: Int -> Int -> String
solve a b
    | a + b < 10 = show (a + b)
    | otherwise = "error"

main :: IO ()
main = do
    [a, b] <- map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
    putStrLn $ solve a b


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

#include <cstdio>
#include <cstdlib>
#include <cmath>

#include <iostream>

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

const ll mod = 1000000007;

class mint{
public:
  ll x;
  mint(ll x=0) : x(x%mod){}
  mint& operator+=(const mint rhs){
    x += rhs.x;
    while(x >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint rhs){
    x -= rhs.x;
    while(x < 0) x += mod;
    return *this;
  }
  mint & operator*=(const mint rhs){
    (x *= rhs.x) %= mod;
    return *this;
  }
  mint operator+(const mint rhs) const {
    mint res(*this);
    return res += rhs;
  }
  mint operator-(const mint rhs) const {
    mint res(*this);
    return res -= rhs;
  }
  mint operator*(const mint rhs) const {
    mint res(*this);
    return res *= rhs;
  }
  friend ostream& operator<<(ostream& os,const mint rhs){
    os << rhs.x;
    return os;
  }
};

#define rep(index,num) for(int index=0;index<num;++index)


int main(){
  int n;
  std::cin >> n;
  int p[n];
  rep(i,n) cin >> p[i];
  int ans = 0;
  for(int i=1;i<n-1;i++){
    int t[3];
    t[0] = p[i-1];
    t[1] = p[i];
    t[2] = p[i+1];
    if(t[0]>t[2]) swap(t[0],t[2]);
    if(t[0]<=t[1] && t[1]<t[2]){
      ans++;
      //cout << i << " " << t[0] << t[1] << t[2] << endl;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/* C - Forbidden List */

#include <bits/stdc++.h>
using namespace std;

int main(){
  int X, N;
  vector<int> p(100);
  cin >> X >> N;
  int ans = X;
  for(int i = 0; i < N; i++){
    cin >> p.at(i);
  }
  if(N > 0){
    for(int i = 0; i <= 100; i++){
      if(ans == X - i || ans == X + i){
        int cnt = 0;
        for(int j = 0; j < N; j++){
          if(p.at(j) == X - i){
            ans = X + i;
            cnt++;
          }
          if(p.at(j) == X + i){
            ans = X - i;
            cnt++;
          }
          if(cnt == 2){
            ans = X - i - 1;
            break;
          }
        }
      }else{
        break;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	1000000007

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

struct p
{
	ll a;
	int b;
	int c;
};

int main()
{
	ll l;
	cin >> l;
	double p = l / 3.0f;
	printf("%lf", p * p * p);

	return 0;
}


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

#define ll long long int

const int MAX = 100006;

int a[MAX],b[MAX];

vector<pair<int,int>> ar(MAX);
int main()
{

    int n,m;
    cin >> n >> m;
    for(int i=0;i<n;++i)
    cin >> ar[i].first >> ar[i].second;
    sort(ar.begin(),ar.begin()+n);
    ll ans = 0;
    bool yo = true;
    for(int i=0;i<n;++i)
    {
        
        while(ar[i].second-->0)
        {
            m--;
            ans+=ar[i].first;
            if(m==0)
            {
                yo = false;
                break;
            }
            
        }
        if(!yo)break;
    }
    
    cout << ans;
}

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

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)
#define INF 1000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

int main()
{
	int n;cin >> n;
	vector<ll> v;
	ll ans = 0;
	bool flag = false;
	REP(i,n){
		ll a,b;
		cin >> a >> b;
		if(a < b){
			flag = true;
			ans += b;
		}else if(a == b){
			ans += b;
		}else{
			v.PB(b);
		}
	}
	
	if(!flag){
		cout << 0 << endl;
		return 0;
	}
	sort(ALL(v),greater<ll>());
	REP(i,v.size()-1){
		ans += v[i];
	}
	
	cout << ans << endl;
			
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int N,M;
  while(cin>>N>>M,N){
    int num[M+10][730]={};
    int r;cin>>r;
    for(int i=0;i<r;i++){
      int t,n,m,s;cin>>t>>n>>m>>s;
      if(s)num[m][t-535]++;
      else num[m][t-535+1]--;
    }
    int q;cin>>q;
    for(int i=0;i<q;i++){
      int ans=0;
      int ts,te,mm;cin>>ts>>te>>mm;
      ts-=535;
      te-=535;
      int now=0;
      for(int i=0;i<730;i++){
	int mae=now;
	now+=num[mm][i];
	//	cout<<now<<" "<<i<<":"<<" ";
	if(ts<i&&i<=te&&now>0){
	  // cout<<now<<" "<<i<<endl;
	  if(mae==0)ans--;
	  ans++;
	}
      }
      cout<<ans<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 30624
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	int n,m;
	List<List<Integer>> graph;
	static int[] memo;//graph.get(i)の有向パスの最大を記録
	static boolean f[];//memo[i]に記録されているならばtrue;

	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}

	private void solve() {
		n = nextInt();
		m = nextInt();
		graph = new ArrayList<List<Integer>>();
		for(int i=0;i<=n;i++)graph.add(new ArrayList<Integer>());
		for(int i=0;i<m;i++)graph.get(nextInt()).add(nextInt());

		f = new boolean [n+1];
		memo = new int [n+1];
		Arrays.fill(memo, -1);
		for(int i=1;i<=n;i++)if(!f[i])memo[i] = SearchVerticesPass(i);

		Arrays.sort(memo);
		System.out.println(memo[n]);
	}

	private int SearchVerticesPass(int vi) {
		if(f[vi])return memo[vi];
		List<Integer>V = graph.get(vi);
		int cntmax=0,t;
		for(int i=0;i<V.size();i++)if((t=SearchVerticesPass(V.get(i))+1)>cntmax)cntmax=t;
		f[vi]=true;
		return memo[vi] = cntmax;
	}

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

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

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 998244353;

const int MAXN = 100005;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	ll a,b,c; cin>>a>>b;
	cout<<max(max(a+b,a-b),a*b)<<'\n';
	
	return 0;
}


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

class Main {
    static Scanner scanner = new Scanner();
    static long mod = 1000000007;

    public static void main(String[]$) {
        int n = scanner.nextInt();
        Map<Integer, Integer> map = new TreeMap<>();
        for (int i = 0; i < n; i++) {
            map.put(scanner.nextInt(), i);
        }
        for (Integer value : map.values()) {
            System.out.println(value + 1);
        }
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

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

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

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


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

int main(){
  string s;
  cin >> s;
  int ccount = 0;
  int scount = 0;
  for(int i=1; i<s.size(); i++){
    if(s[i] >= 'a' && s[i] <= 'z') scount++;
    if(i>1 && i<s.size()-1){
      if(s[i] == 'C'){
        ccount += 1;
      }
    }
  } 
  if(s[0] == 'A' && ccount == 1 && scount == s.size()-2) cout << "AC" << endl;
  else cout << "WA" << endl;
}
    

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int s[102],a[12];
int i,n,t=0,c=0,g,h,r=0,e=0;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&s[i]);
t+=s[i];
}
g=t/n;
h=(t)/n+1;
//printf("%d %d.\n",g,h);
for(i=0;i<n;i++){
r+=(s[i]-g)*(s[i]-g);
e+=(s[i]-h)*(s[i]-h);
}
if(r>e)printf("%d\n",e);
else printf("%d\n",r);
return 0;
}

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

int main() {
	int n;
	cin >> n;
	long sum = 0;
	int i;
	for (i = 1; i <= n; i++) {
		if (!(i % 3 == 0 || i % 5 == 0)) {
			sum += i;
		}
	}
	cout << sum;
	return 0;

}

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const ll LLINF = 1LL<<60;
/* -- template -- */

void nearestNtoM(const int N, const int M, ll arrayN[], ll arrayM[], ll array[]){
    rep(i, N){
        int l = 0, r = M;
        while(l + 1 < r){
            int mid = (l + r) / 2;
            if(arrayM[mid] < arrayN[i]){
                l = mid;
            }else{
                r = mid;
            }
        }
        array[i] = min(abs(arrayN[i] - arrayM[l]), abs(arrayN[i] - arrayM[r]));
    }
}

int main(){
    int shrineCount, templeCount, Q;cin >> shrineCount >> templeCount >> Q;
    ll temple[templeCount + 1], shrine[shrineCount + 1];
    temple[templeCount] = LLINF, shrine[shrineCount] = LLINF;
    rep(i, shrineCount){
        cin >> shrine[i];
    }
    rep(i, templeCount){
        cin >> temple[i];
    }
    ll nearestStoT[shrineCount];
    nearestNtoM(shrineCount, templeCount, shrine, temple, nearestStoT);
    ll nearestTtoS[templeCount];
    nearestNtoM(templeCount, shrineCount, temple, shrine, nearestTtoS);
    ll q[Q];
    rep(i, Q){
        cin >> q[i];
    }
    rep(i, Q){
        int l = 0, r = templeCount;
        while(l + 1 < r){
            int mid = (l + r) / 2;
            if(temple[mid] < q[i]){
                l = mid;
            }else{
                r = mid;
            }
        }
        int tl = l, tr = r;
        l = 0, r = shrineCount;
        while(l + 1 < r){
            int mid = (l + r) / 2;
            if(shrine[mid] < q[i]){
                l = mid;
            }else{
                r = mid;
            }
        }
        int sl = l, sr = r;
        cout << min<ll>(min<ll>(nearestStoT[sl] + abs(shrine[sl] - q[i]), nearestStoT[sr] + abs(shrine[sr] - q[i])), min<ll>(nearestTtoS[tl] + abs(temple[tl] - q[i]), nearestTtoS[tr] + abs(temple[tr] - q[i]))) << endl;
    }
}


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

int main()
{
   char a[110000];
   scanf("%s",&a);
   int w=strlen(a);
   w=w/2;
   int k=0;
   int kk=0;
   for(int i=0;a[i];i++)
   {
       if(a[i]=='p')
       {
           k++;
       }
       else if(a[i]=='g')
       {
           kk++;
       }
   }
if(k>=w)
{
    printf("%d\n",w-k);
}
else
{
   printf("%d\n",w-k);
}
    return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {

    public static List<List<Integer>> switchList;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int L = sc.nextInt();
        sc.close();

        int baseVal = L - 1;
        int[] apples = new int[N];
        for (int i = 0; i < N; i++) {
            apples[i] = (i + 1) + baseVal;
        }

        int sum = 0;
        boolean isEat = false;
        for (int i = 0; i < N; i++) {
            int taste = apples[i];
            if (!isEat) {
                if (taste >= 0) {
                    isEat = true;
                    continue;
                }
            }
            sum += taste;
        }
        if (!isEat) {
            sum -= apples[N - 1];
        }
        System.out.println(sum);
    }

}

Measured memory_bytes: 21972
N = int(input())
H = list(map(int, input().split()))

INF = 10 ** 12
dp = [INF] * N
dp[0] = 0

for n in range(1, N):
	dp[n] = dp[n - 1] + abs(H[n] - H[n - 1])
	if 2 <= n:
		dp[n] = min(dp[n], dp[n - 2] + abs(H[n] - H[n - 2]))
print(dp[-1])


Measured memory_bytes: 13924
#include<bits/stdc++.h>
using namespace std;int N,a,b,i,V[1<<20],f[1<<20];pair<int,int>R[1<<20];main(){for(cin>>N;i<N;cin>>a>>b,R[i++]={a,a+b});for(sort(R,R+N),b=V[N]=1;a=i--;b=V[i]=(b+V[f[i]=a])%998244353)for(;a<N&R[a].first<R[i].second;a=f[a]);cout<<*V;}

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

using namespace std;

typedef long long ll;

#ifdef RED
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const int N = (int)1e6 + 5;
const int inf = (int)1e9 + 7;

int n, k;
int h[N], dp[N];

int main() {
#ifdef RED
  freopen("a.in", "r", stdin);
#endif
  ios_base :: sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> h[i];
    dp[i] = inf;
  }
  dp[1] = 0;
  for (int i = 2; i <= n; ++i) {
    for (int j = 1; j <= k; ++j)
      dp[i] = min(dp[i], dp[max(1, i - j)] + abs(h[i] - h[max(1, i - j)]));
  }
  cout << dp[n] << "\n";
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> l(n*2);
    for (int i = 0; i < n*2; i++) cin >> l[i];

    sort (l.begin(), l.end());
    int ans = 0;
    for (int i = 0; i < n*2; i += 2) ans += l[i];
    cout << ans << endl;
}

Measured memory_bytes: 3616
def factoring(n)
  res = Hash.new(0)
  i = 2
  while i*i <= n
    while n % i == 0
      res[i] += 1
      n /= i
    end
    i += 1
  end
  res[n] = 1 if n != 1
  res
end

A, B = gets.split.map(&:to_i)
a_f = factoring(A).keys
b_f = factoring(B).keys

cd = (a_f + b_f).group_by{ |e| e }.select { |k, v| v.size > 1 }.map(&:first)

puts cd.count + 1

Measured memory_bytes: 3836
#!/usr/bin/env python3
#AGC14 A

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a,b,c = LI()
ans = 0
while a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
    if a == b and b == c:
        print(-1)
        quit()
    a,b,c = (b + c)/2 , (a + c)/2 , (b + c)/2
    ans += 1
print(ans)


Measured memory_bytes: 38384
#!/usr/bin/env python3
#ABC128 C

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m = LI()
lst = [LI() for _ in range(m)]
p = LI()
ans = 0
for i in range(2**n):
    b = [0]*n
    for j in range(n):
        if (i >> j) & 1:
            b[j] = 1
    for j in range(m):
        tmp = 0
        k = lst[j][0]
        for l in range(1,k+1):
            if b[lst[j][l]-1] == 1:
                tmp += 1
        if tmp % 2 != p[j]:
            break
    else:
        ans += 1
print(ans)

Measured memory_bytes: 40944
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[n];
        int v = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            v += a[i];
        }
        int res = 0;
        int t = (int)Math.ceil((v * 1.0) / (4 * m));
        for (int i = 0; i < n; i++) {
            if (a[i] >= t) res++;
        }
        if (res < m) System.out.println("No");
        else System.out.println("Yes");
    }
}

// x * 3 <= 16

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

int main(){
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    if(a + b < 2 * c) {
        cout << a * x + b * y << endl;
        return 0;
    }

    int min_ans = min(x, y) * 2 * c + (x - min(x, y)) * a + (y - min(x, y)) * b;
    int max_ans = max(x, y) * 2 * c + max(x - max(x, y), 0) * a + max(y - max(x, y), 0) * b;
    cout << min(min_ans, max_ans) << endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    int ans = 1, sgn = 0;
    for(int i=0; i<n; i++){
        cin >> v.at(i);
        if(i == 0){
            continue;
        }
        if(v.at(i) > v.at(i-1)){
            if(sgn == -1){
                ans++;
                sgn = 0;
            }else{
                sgn = 1;
            }
        }else if(v.at(i) < v.at(i-1)){
            if(sgn == 1){
                ans++;
                sgn = 0;
            }else{
                sgn = -1;
            }
        }
    }

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 640
N, M, K = map(int, input().split())
mod = 998244353

fact = [1 for i in range(N+1)]
fact_inv = [1 for i in range(N+1)]
for i in range(1, N+1):
    fact[i] = fact[i-1] * i %mod
    fact_inv[i] = pow(fact[i], mod-2, mod)

ans = 0
for k in range(K+1):
    x = M *pow(M-1, N-1-k, mod) *fact[N-1] *fact_inv[k] *fact_inv[N-1-k]
    ans += x %mod
    ans = ans %mod
print(ans)

Measured memory_bytes: 94476