akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <string>
#include <memory.h>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <time.h>
#include <assert.h>
#include <cmath>
#include <stack>
#include <string.h>
#include <sstream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 100000;
const int M = 1000000007;
int n, m, s, t;
vector<vector<pair<int, int> > > g;
vector<int> p[N];
vector<vector<int> > lg, rg;
ll cost[N];
ll len;
bool vis[N];
int dp[2][N];
void Dijkstra() {
	priority_queue<pair<ll, int> > q;
	q.push({ 0,s });
	for (int i = 0; i < n; ++i)
		cost[i] = 1e18;
	cost[s] = 0;
	while (!q.empty()) {
		int u = q.top().second;
		q.pop();
		if (vis[u])
			continue;
		vis[u] = true;
		for (int i = 0; i < g[u].size(); ++i) {
			int v = g[u][i].first;
			if (vis[v])
				continue;
			ll cst = cost[u] + g[u][i].second;
			if (cost[v] == cst)
				p[v].push_back(u);
			else if (cost[v] > cst) {
				p[v].clear();
				p[v].push_back(u);
				cost[v] = cst;
				q.push({ -cst,v });
			}
		}
	}
}
void buildGraphs(int u) {
	if (u == s)
		return;
	if (vis[u])
		return;
	vis[u] = true;
	for (int i = 0; i < p[u].size(); ++i) {
		int a = p[u][i];
		int b = u;
		lg[a].push_back(b);
		rg[b].push_back(a);
		buildGraphs(a);
	}
}
int calc(int u, bool f) {
	if (!f && u == t)
		return 1;
	if (f && u == s)
		return 1;
	int &ret = dp[f][u];
	if (ret != -1)
		return ret;
	ret = 0;
	if (!f) {
		for (int i = 0; i < lg[u].size(); ++i) {
			ret += calc(lg[u][i], f);
			if (ret >= M)
				ret -= M;
		}
	}
	else {
		for (int i = 0; i < rg[u].size(); ++i) {
			ret += calc(rg[u][i], f);
			if (ret >= M)
				ret -= M;
		}
	}
	return ret;
}
int main()
{
	scanf("%d%d%d%d", &n, &m, &s, &t);
	--s; --t;
	g.resize(n);
	for (int i = 0, a, b, c; i < m; ++i) {
		scanf("%d%d%d", &a, &b, &c);
		--a; --b;
		g[a].push_back({ b,c });
		swap(a, b);
		g[a].push_back({ b,c });
	}
	Dijkstra();
	lg.resize(n);
	rg.resize(n);
	len = cost[t];
	memset(vis, 0, sizeof(vis));
	buildGraphs(t);
	memset(dp, -1, sizeof(dp));
	ll res = calc(s, false);
	calc(t, true);
	res = ((ll)res*res % M + M) % M;
	for (int i = 0; i < n; ++i) {
		if (cost[i] * 2 == len) {
			ll cur = (ll)calc(i, true)*calc(i, false) % M;
			res -= cur*cur%M;
			res = ((ll)res%M + M) % M;
		}
		for (int j = 0; j < lg[i].size(); ++j) {
			int u = i;
			int v = lg[i][j];
			if (cost[u] < (len + 1) / 2 && len - cost[v] < (len + 1) / 2) {
				ll cur= (ll)calc(u, true)*calc(v, false) % M;
				res -= cur*cur%M;
				res = ((ll)res%M + M) % M;
			}
		}
	}
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 32592
#include <iostream>
using namespace std;
using ll = long long;
#define in(v) v; cin >> v;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
constexpr ll INF = 5e18;

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

  ll dp[2] = {0, 1};
  rep(i, N.size()) {
    ll dp2[2] = {INF, INF};
    rep(carry, 2) {
      int n = (N[i]-'0') + carry;
      rep(j, 10)
        if (j >= n) dp2[carry] = min(dp2[carry], j + (j-n) + dp[false]);
        else dp2[carry] = min(dp2[carry], j + (10+j-n) + dp[true]);
    }
    swap(dp, dp2);
  }
  cout << dp[false] << endl;
  return 0;
}


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

#define maxn 500010
#define mp make_pair

using namespace std;

pair <int,int> drzewo[4*maxn];
bool czy[maxn];
priority_queue<int> prl;
int n,k,r=1;
int odp[maxn];

pair<int,int> find_max(int gdzie,int pp, int pk, int zp, int zk)
{
	//cout << gdzie << endl;
	if(zp>pk||zk<pp)
		return mp(0,-1);
	if(zp<=pp&&zk>=pk)
		return drzewo[gdzie];
	int sr=(pp+pk)/2;
	return max(find_max(2*gdzie,pp,sr,zp,zk),find_max(2*gdzie+1,sr+1,pk,zp,zk));
	
}

bool is_local_maximum(int x)
{
	//cout << x << endl;
	pair<int,int> a=find_max(1,1,r,x-k+1,x+k-1);
	return a.first==drzewo[x+r-1].first;
}

void inserty(int x)
{
	drzewo[x].first=0;
	x/=2;
	while(x!=0)
	{
		drzewo[x]=max(drzewo[2*x],drzewo[2*x+1]);
		x/=2;
	}
}

pair<int,int> find_segment(int x)
{
	return mp((x/k)*k,(x/k)*k+k-1);
}

int main()
{
	scanf("%d%d", &n, &k);
	while(r<n)
		r*=2;
	for(int i=0; i<n; ++i)
	{
		scanf("%d", &drzewo[i+r].first);
		drzewo[i+r].second=i;
	}
	for(int i=n+r; i<2*r; ++i)
		drzewo[i]=mp(0,-1);
	for(int i=r-1; i>0; --i)
		drzewo[i]=max(drzewo[2*i], drzewo[2*i+1]);
	//cout << "S" << endl;
	for(int i=0; i<n; ++i)
	{
		if(is_local_maximum(i+1))
		{
			prl.push(i);
			czy[i]=true;
			//cout << i << endl;
		}
	}
	int wsk=n;
	//cout << "S" << endl;
	while(!prl.empty())
	{
		odp[prl.top()]=wsk;
		--wsk;
		inserty(prl.top()+r);
		pair<int,int> a=find_segment(prl.top());
		a.first++;
		a.second++;
		prl.pop();
		pair<int,int> b=find_max(1,1,r,a.first,a.second);
		//cout << b.first << " " << b.second << endl;
		if(b.second!=-1&&b.first!=0)
		{
			if(!czy[b.second]&&is_local_maximum(b.second+1))
			{
				czy[b.second]=true;
				prl.push(b.second);
			}
		}
		b=find_max(1,1,r,a.first-k,a.second-k);
		if(b.second!=-1&&b.first!=0)
		{
			if(!czy[b.second]&&is_local_maximum(b.second+1))
			{
				czy[b.second]=true;
				prl.push(b.second);
			}
		}
		b=find_max(1,1,r,a.first+k,a.second+k);
		if(b.second!=-1&&b.first!=0)
		{
			if(!czy[b.second]&&is_local_maximum(b.second+1))
			{
				czy[b.second]=true;
				prl.push(b.second);
			}
		}
	}
	for(int i=0; i<n; ++i)
	printf("%d\n", odp[i]);
	return 0;
}



Measured memory_bytes: 17904
#include <iostream>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

int main()
{
	long long n,r;
	cin >> n >> r;

	if(n >= 10)
		cout << r << endl;
	else
		cout << r +(100*(10-n)) << endl;

	
}

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

int main() {
  int N; 
  cin >> N;
  vector<int> d(N);
  
  for (int i = 0; i < N; i++){
    cin >> d.at(i);
  }
  
  sort(d.begin(), d.end());
  
  int count = 1;
  
  for (int i = 1; i < N; i++){
    if (d.at(i) > d.at(i-1)){
      count++;
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace std;
#define int long long int 
#define double long double
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> new_data_set;
bool isprime(int n)
	{
    	if(n==1) return true;
    	for(int i = 2;i*i<=n;i++){
    		if(n%i==0) return false;
		}
		return true;
	}
int lcm(int a,int b){
	return (a*b)/__gcd(a,b);
}
int gcd(int a, int b) 
{ 
    if (b == 0){
    	return a;
	} 
    return gcd(b, a % b);  
      
} 
unsigned int factorial(unsigned int n) 
{ 
    if (n == 0) 
    return 1; 
    return n * factorial(n - 1); 
} 
const int inf=1e18;
int dsu[1000001],s[100005];
void init(int n,int m){
	for(int i=1;i<=n;i++){
		dsu[i]=i;
		s[i]=1;
	}
}
int root(int x){
	while(dsu[x]!=x){
		x = dsu[x];
	}
	return x;
}
void uni(int x,int y){
	int p = root(x);
	int q = root(y);
	if(p==q){
		return;
	}
	else{
		if(s[p]<s[q]){
			s[q]+=s[p];
			dsu[p] = q;
		}
		else{
			s[p]+=s[q];
			dsu[q] = p;
		}
	}
}
int power(int x, unsigned int y)  
{  
    int res = 1;
    x = x ; 
    if (x == 0) return 0;  
    while (y > 0){  
        if (y & 1)  
            res*=x;   
        y = y>>1;  
        x = (x*x);  
    }  
    return res;  
}
vector<int>graph[500001];
bool visit[51][51];
int flag;
char arr[51][51];
set<pair<int,int>>vp;
void dfs(int x,int y,int n,int m){
	if(x==n-1 && y==m-1){
		flag++;
		return;
	}
	
	visit[x][y]=true;
	if(x!=0 && arr[x-1][y]!='#' && !visit[x-1][y]){
		if(arr[x-1][y]=='G'){
			vp.erase({x-1,y});
		}
		dfs(x-1,y,n,m);
	}
	if(x!=n-1 && arr[x+1][y]!='#' && !visit[x+1][y]){
		if(arr[x+1][y]=='G'){
			vp.erase({x+1,y});
		}
		dfs(x+1,y,n,m);
	}
	if(y!=0 && arr[x][y-1]!='#' && !visit[x][y-1]){
		if(arr[x][y-1]=='G'){
			vp.erase({x,y-1});
		}
		dfs(x,y-1,n,m);
	}
	if(y!=m-1 && arr[x][y+1]!='#' && !visit[x][y+1]){
		if(arr[x][y+1]=='G'){
			vp.erase({x,y+1});
		}
		dfs(x,y+1,n,m);
	}
}
int a[401];
int sum(int l,int r){
	int sum=0;
	for(int i=l;i<=r;i++){
		sum+=a[i];
	}
	return sum;
}
signed main(){
	FAST
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int dp[n][n];
	for(int l=n-1;l>=0;l--){
		for(int r=l;r<n;r++){
			if(l==r){
				dp[l][r]=0;
			}
			else{
				dp[l][r]=inf;
				int s=sum(l,r);
				for(int i=l;i<r;i++){
					dp[l][r]=min(dp[l][r],dp[l][i]+dp[i+1][r]+s);
				}
			}
		}
	}
	cout<<dp[0][n-1];
}



Measured memory_bytes: 13824
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include<bits/stdc++.h>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>*/

#define sz(s) (int)(s.size())
#define all(s) s.begin(), s.end()
#define rep(a, b, c) for(int a = b; a <= c; ++a)
#define per(a, b, c) for(int a = b; a >= c; --a)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long

using namespace std;
//using namespace __gnu_pbds;

typedef unsigned long long ull;
typedef long long ll;
/*typedef tree<pair<int, int>, 
null_type, less<pair<int, int>>, 
rb_tree_tag, tree_order_statistics_node_update>
ordered_set;*/
//find_by_order() order_of_key()

const double eps = 1e-7;
const int mod = 1e9+7, MXN = 5e5+17;
const int dx[] = {0,0,1,-1}, dy[] = {1,-1,0,0};

template<typename T>inline bool updmin(T &a, const T &b) {return a > b ? a = b,1 : 0;}
template<typename T>inline bool updmax(T &a, const T &b) {return a < b ? a = b,1 : 0;}

int32_t main() { _
#ifdef DanQQQQQ
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	int n; cin >> n;
	int t[n+5]; memset(t,0,sizeof t);
	int a[n+5]; memset(a,0,sizeof a);
	rep(i,1,n) cin >> t[i] >> a[i];
	int T = 1, A = 1, kol = 1;
	rep(i,1,n) {
		kol = max((T+t[i]-1)/t[i],(A+a[i]-1)/a[i]);
		T = kol*t[i], A = kol*a[i];
	}
	cout << T+A << endl;
	return 0;
}


Measured memory_bytes: 256
/*input
10
15 12
13 10
9 6
11 8
9 6
11 8
14 12
7 6
15 14
9 8
*/
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout << "[" << #__VA_ARGS__ << ": " << __VA_ARGS__ << "]\n"
#define rd() abs((int)rng())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 105;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int n, nxt_id;
int arr[maxn], L[maxn], R[maxn], H[maxn], C[maxn];
vector<int>adj[maxn];
void build(int lo, int hi, int p)
{
	int id = ++nxt_id;
	if(p != 0)
		adj[p].pb(id);
	L[id] = lo, R[id] = hi;
	int mn = mod;
	for(int i = lo; i <= hi; i++)
		mn = min(mn, arr[i]);
	H[id] = mn;
	for(int i = lo; i <= hi; i++)
	{
		if(arr[i] > mn)
		{
			int j = i;
			while(j + 1 <= hi && arr[j + 1] > mn)
				++j;
			build(i, j, id);
			i = j;
		}
		else
			++C[id];
	}
}
ll pwr(ll a, ll pw)
{
	ll ret = 1;
	while(pw > 0)
	{
		if(pw & 1)
			ret = ret * a % mod;
		a = a * a % mod;
		pw >>= 1;
	}
	return ret;
}
ll dp1[maxn], dp2[maxn]; // dp1 - bottom row alternates, dp2 - total number of ways to color the histogram
void dfs(int v, int p)
{
	ll h = H[v] - H[p];
	ll p1 = 1, p12 = 1;
	for(int to : adj[v])
	{
		dfs(to, v);
		p1 = p1 * dp1[to] % mod;
		p12 = p12 * (dp1[to] + dp2[to]) % mod;
	}
	dp1[v] = pwr(2, h) * p1 % mod;
	dp2[v] = (pwr(2, C[v]) * p12 + (pwr(2, h) - 2) * p1) % mod;
}
int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> arr[i];
	build(1, n, 0);
	dfs(1, 0);
	cout << dp2[1] << "\n";
	return 0;
}

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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;

template <typename T>
struct TimeDegree {
    const double PI=3.14159265358979323846;
    T hour;
    T minute;

    TimeDegree(T h, T m) {
        hour = h;
        minute = m;
    }

    // 時計算(長針と短針のなす角)
    double getDegree() const {
        // 短針は0.5度/分
        double x = hour * 30 + minute * 0.5;
        // 長針は6度/分
        double y = minute * 6.0;
        return abs(x - y);
    }

    // 度をラジアンへ
    double getRadian() const {
        return getDegree() * PI / 180.0;
    }
};

int main() {
    double a, b; cin >> a >> b;
    int h, m; cin >> h >> m;
    TimeDegree<int> tg(h, m);
    double ans = pow(a, 2.0) + pow(b, 2.0) - 2 * a * b * cos(tg.getRadian());
    cout << setprecision(20) << sqrt(ans) << endl;
}


Measured memory_bytes: 4132
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m, K;
    cin >> n >> m >> K;

    if (m == 1) {
        if (K == 1) {
            cout << 1 << '\n';
        } else {
            cout << 0 << '\n';
        }
        return 0;
    }

    const long long MOD = 1000000007;

    int M = 1 << (m - 1);

    vector<long long> dp(m, 0);
    dp[0] = 1;
    auto ndp = dp;

    vector<vector<long long>> cnts(m, vector<long long>(3, 0));
    int total = 0;
    for (int i = 0; i < M; ++i) {
        if (i & (i >> 1)) {
            continue;
        }
        ++total;

        for (int j = 0; j < m - 1; ++j) {
            if (i & (1 << j)) {
                cnts[j + 1][0] += 1;
                cnts[j][2] += 1;
            }
        }
    }
    for (int i = 0; i < m; ++i) {
        cnts[i][1] = total - cnts[i][0] - cnts[i][2];
    }

    for (int _ = 0; _ < n; ++_) {
        fill(ndp.begin(), ndp.end(), 0);
        for (int i = 0; i < m; ++i) {
            for (int j = -1, k = 0; k <= 2; ++k, ++j) {
                int ni = i + j;
                if (ni >= 0 && ni < m) {
                    (ndp[ni] += (dp[i] * cnts[i][k]) % MOD) %= MOD;
                }
            }
        }
        swap(ndp, dp);
    }

    cout << dp[K - 1] << '\n';

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int a, b, c, d;

int main()
{
    cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c, d) << endl;
}


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

//O(E*V^2)

class Dinic {
private:
  struct edge {
    int to, cap, rev;
  };

  const int INF = 1e18;

  vector<vector<edge>> G;
  vector<int> level, iter;

  void add_edge(int from, int to, int cap) {
    G[from].push_back((edge){to, cap, (int)G[to].size()});
    G[to].push_back((edge){from, 0LL, (int)G[from].size() - 1LL});
  }

  void bfs(int s) {
    fill(level.begin(), level.end(), -1);
    queue<int> que;
    que.push(s);
    level[s] = 0;
    while (!que.empty()) {
      int v = que.front();
      que.pop();
      for (int i = 0; i < G[v].size(); i++) {
        edge &e = G[v][i];
        if (e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          que.push(e.to);
        }
      }
    }
  }

  int dfs(int v, int t, int f) {
    if (v == t)
      return f;
    for (int &i = iter[v]; i < G[v].size(); i++) {
      edge &e = G[v][i];
      if (e.cap > 0 && level[v] < level[e.to]) {
        int d = dfs(e.to, t, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

  int getMaxFlow(int s, int t) {
    int flow = 0;
    while (true) {
      bfs(s);
      if (level[t] < 0)
        return flow;
      fill(iter.begin(), iter.end(), 0);
      int f;
      while ((f = dfs(s, t, INF)) > 0) {
        flow += f;
      }
    }
  }

public:
  Dinic(int N) : G(N, vector<edge>()), level(N), iter(N) {}

  void addEdge(int from, int to, int cap) { add_edge(from, to, cap); }
  int maxFlow(int s, int t) { return getMaxFlow(s, t); }
};

signed main() {
  int V, E;
  cin >> V >> E;

  Dinic din(V);

  for (int i = 0; i < E; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    din.addEdge(u, v, c);
  }

  cout << din.maxFlow(0, V - 1) << endl;
  return 0;
}



Measured memory_bytes: 3260
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int s = Integer.parseInt(br.readLine());
        int hour = s / 3600;
        int minute = (s % 3600) / 60;
        int second = s - hour * 3600 - minute * 60;
        System.out.println(hour + ":" + minute + ":" + second);
    }
}

Measured memory_bytes: 24232
#include<iostream>
#include<map>
#include<vector>
#include<set>
#include<climits>
using namespace std;
#define NONE INT_MAX>>2
int main()
{
  int n,m,M[500][500];
  string s,p,g;
  while(cin>>n>>m>>s>>p>>g,n|m){
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)M[i][j]=NONE;
    map<string,int>id;
    for(int i=0,cnt=0;i<m;i++){
      string a,b;
      int d,t;
      cin>>a>>b>>d>>t;
      if(id.count(a)==0)id[a]=cnt++;
      if(id.count(b)==0)id[b]=cnt++;
      M[id[a]][id[b]]=M[id[b]][id[a]]=d/40+t;
    }

    // Dijkstra
    int start=id[p];
    set<int>used;
    set<int>::iterator it;
    vector<int>d(n,NONE);
    d[start]=0;
    used.insert(start);
    while(used.size()!=n){
      bool end=true;
      int min=NONE,next;
      for(int i=0;i<n;i++){
	if(used.count(i))continue;
	for(it=used.begin();it!=used.end();it++){
	  if(d[*it]+M[*it][i]<min){
	    min=d[*it]+M[*it][i];
	    next=i;
	  }
	}
	if(min!=NONE)end=false;
      }
      if(end)break;
      used.insert(next);
      d[next]=min;
    }

    cout<<(d[id[s]]+d[id[g]])<<endl;
  }
}

Measured memory_bytes: 1956
import Control.Monad
import Data.List
import Data.List.Split

leaps y = y `div` 4 - y `div` 100 + y `div` 400
isLeap 0 = False
isLeap y = y `mod` 4 == 0 && (y `mod` 100 /= 0 || y `mod` 400 == 0)
y2d y = y * 365 + leaps y

calendar = [31,28,31,30,31,30,31,31,30,31,30,31]
mon2d m = sum $ genericTake (m - 1) calendar

g2d y m d
 | isLeap y && m <= 2 = x - 1
 | otherwise = x
 where x = y2d y + mon2d m + d

divModIf x (y,z)
 | p == z = (p - 1, q + y)
 | otherwise = t
 where t@(p,q) = divMod x y

d2y x = (a * 400 + c * 100 + e * 4 + g, h)
 where 
  (a,b) = x `divMod` (365 * 400 + 100 - 4 + 1)
  (c,d) = b `divModIf` (365 * 100 + 25 - 1, 4)
  (e,f) = d `divMod` (365 * 4 + 1)
  (g,h) = f `divModIf` (365, 4)

d2mon x = f x 1 calendar
 where
  f x y (z:zs)
   | x <= z = (y, x)
   | otherwise = f (x - z) (y + 1) zs

leapDay = mon2d 3

d2g x
 | not (isLeap y) && a == 0 = [y - 1, 12, 31]
 | not (isLeap y) = [y, m, d]
 | a == leapDay = [y, 2, 29]
 | a > leapDay = [y, m, d]
 | otherwise = [y, m', d']
 where 
  (y,a) = d2y x
  (m,d) = d2mon a
  (m',d') = d2mon (a + 1)

n2xn _ ys [] = ys
n2xn x ys (z:zs) = n2xn p (q : ys) zs
 where (p,q) = divMod x z
xn2n ys zs = f 1 ys zs
 where
  f _ [] _ = 0
  f x (y:ys) (z:zs) = x * y + f (x * z) ys zs

mds = [20,18,20,20,13]
mbase = g2d 2012 12 21
m2d b ka t w ki = mbase + xn2n [ki,w,t,ka,b] mds
mmax = m2d 12 19 19 17 19 - mbase
d2m x = n2xn ((x - mbase) `mod` (mmax + 1)) [] mds

main = do
 l <- getLine
 when (l /= "#") $ do
  putStrLn $ intercalate "." $ map show $ 
   case map read $ splitOn "." $ l of
    [y,m,d] -> d2m $ g2d y m d 
    [b,ka,t,w,ki] -> d2g $ m2d b ka t w ki
  main

Measured memory_bytes: 4220
def main():
    N, Y = [int(x) for x in input().split()]
    all_pattern = ([i, j] for i in range(N+1) for j in range(i+1))
    for i, j in all_pattern:
        z, y, x = j, i - j, N - i
        if 10000 * x + 5000 * y + 1000 * z == Y:
            print(x, y, z)
            return
    print(-1, -1, -1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <stdio.h>
#define int long long

int f(int N){
	int ans = 0;
	while(1){
		ans ^= N;
		if(N % 4 == 0){
			return ans;
		}
		N--;
	}
}

signed main(){
	int A, B;
	scanf("%lld%lld", &A, &B);
	printf("%lld\n", f(A) ^ f(B) ^ A);
	return 0;
}

Measured memory_bytes: 128
-- https://github.com/minoki/my-atcoder-solutions
import Data.Char (isSpace)
import Data.List (unfoldr)
import qualified Data.ByteString.Char8 as BS

main = do
  [a,b,c] <- unfoldr (BS.readInteger . BS.dropWhile isSpace) <$> BS.getLine
  -- sqrt a + sqrt b < sqrt c
  -- <=> (sqrt a + sqrt b)^2 < c
  -- <=> a + b + 2 * sqrt a * sqrt b < c
  -- <=> 2 * sqrt a * sqrt b < c - a - b
  -- <=> 0 < c - a - b, 4 * a * b < (c - a - b)^2
  if 0 < c - a - b && 4 * a * b < (c - a - b)^2 then
    putStrLn "Yes"
  else
    putStrLn "No"


Measured memory_bytes: 380
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999

bool isSame(string s,string name,int start,int inter){
    string tmp="";
    while( tmp.size()<name.size() ){
        if(start>=s.size())return false;
        tmp+=s[start];
        start+=inter;
    }
    if(tmp==name)return true;
    return false;
}


bool solve(string s,string name){
    rep(start,s.size()){
        for(int inter=1;inter<s.size();inter++){
            if( isSame(s,name,start,inter) )return true;
        }
    }
    return false;
}

int main(){
    int c=0;
    int n;
    cin>>n;
    string name;
    cin>>name;
    rep(i,n){
        string s;
        cin>>s;
        if(solve(s,name))c++;
    }
    cout<<c<<endl;
}

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

#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(),(a).rend())
#define ll long long
#define pb(a) push_back(a)

#define PRINTV(v) {for(ll deB=0; deB<(v).size(); deB++){cout << (v)[deB] << " ";}cout << endl;}

int main(){
	
	
	ll X,Y;
	cin >> X >> Y;
	bool judge = false;
	REP(i, X+1){
		if(i*2+(X-i)*4==Y){
			judge = true;
			break;
		}
	}
	string s = (judge) ? "Yes" : "No";
	cout << s << endl;
	
	return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

int n,a,b;

int main(){
	while(cin>>n){
		if(n==0)return 0;
		int sa=0,sb=0;
		for(int i=0;i<n;i++){
			cin>>a>>b;
			if(a>b)sa+=a+b;
			else if(a<b)sb+=a+b;
			else {sa+=a;sb+=b;}
		}
		cout<<sa<<" "<<sb<<endl;
	}
}

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

int main(){
    int n;
    std::cin >> n;
    int l[n];
    for(int i=0;i<n;++i){
        std::cin >> l[i];
    }
    
    std::sort(l,l+n);
    
    int a,b,c;
    int ans=0;
    
    for(int i=0;i<n-2;++i){
        a=l[i];
        for(int j=i+1;j<n-1;++j){
            b=l[j];
            for(int k=j+1;k<n;++k){
                c=l[k];
                if((a<b+c)&&(b<c+a)&&(c<a+b)){
                    ans++;
                } else {
                    break;
                }
            }
        }
    }
    std::cout << ans << std::endl;
    
    return 0;
}


Measured memory_bytes: 256
n = int(input())
arr = list(map(int, input().split()))
cnt = [[0,0] for x in range(n-1)]
for i in range(1,n):
	if i == 1:
		cnt[i-1][0] = abs(arr[i-1]-arr[i])
		cnt[i-1][1] = 100000
	else:
		cnt[i-1][0] = abs(arr[i-1]-arr[i])
		cnt[i-1][1] = abs(arr[i-2]-arr[i])
for i in range(1,n-1):
	cnt[i][0] += min(cnt[i-1])
	if i != 1:
		cnt[i][1] += min(cnt[i-2])
print(min(cnt[-1]))


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

int main() {
	long long N, A;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A;
		if (A % 2 == 0 && A % 3 != 0 && A % 5 != 0) {
			cout << "DENIED" << endl;
			return 0;
		}
	}
	cout << "APPROVED" << endl;
}


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

int main(){
    int N, M;
    cin >> N >> M;
    int cnt[N] = {0};
    rep(i, M){
        rep(j, 2){
            int a;
            cin >> a;
            cnt[a-1]++;
        }
    }
    rep(i, N){
        cout << cnt[i] << endl;
    }
    // printf("%d\n", N);
    return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for(int i = 0; i < N; i++)
		cin >> A.at(i);

	bool ans = false;
	int res = 0;
	for(int i = 0; i < N; i++) {
		if(A.at(i) % 2 == 0) {
			if(A.at(i) % 3 == 0 || A.at(i) % 5 == 0)
				ans = true;
			else {
				ans = false;
				break;
			}
		}
		else
			res++;
	}
	if(res == N)
		ans = true;

	if(ans)
		cout << "APPROVED" << endl;
	else
		cout << "DENIED" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k;
  cin >>n >>k;
  vector<int>l(n);
  for(int i=0;i<n;i++){
    int L;
    cin >>L;
    l.at(i) = -L;
  }
  sort(l.begin(),l.end());
  int ans =0;
  for(int i =0;i<k;i++){
    ans += l.at(i);
  }
  cout << ans*(-1);
}

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

int main()
{
    int n, d = 100000;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        d = (int)ceil(d * 1.05 / 1000) * 1000;
    }
    cout << d << endl;
    return 0;
}


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

//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).end()) i=(c).end(); i!=(c).begin(); --i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())

#define PB(a) push_back(a)

#define FS first
#define SE second

#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal var
//------------------------------------------


int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------

  int N;
  cin >> N ;
  int ans = 0;
  VI V,C;
  REP(i,N){
    int tmp;
    cin >> tmp;
    V.PB(tmp);
  }
  REP(i,N){
    int tmp;
    cin >> tmp;
    C.PB(tmp);
  }
  REP(i,N){
    if(V[i]>C[i]) ans += V[i]-C[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
//幅優先探索　最短でいったぬる
//https://qiita.com/drken/items/996d80bcae64649a6580
import java.util.ArrayList;
import java.util.Scanner;

import java.util.*;
public class Main {
	static int maze[][] ; //短いものを入れておく
	static char c[][];
	static int H;
	static int N;
	static int W;
	static int sy;
	static int sx;
	static int gx;
	static int gy;
	static int dy[] = {0, 1, 0, -1};
	static int dx[] = {1, 0, -1, 0};
	static int box;
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		H = sc.nextInt();
		W = sc.nextInt();
		
		box = 0;
		c = new char[H][W];
		gx = W-1;
		gy = H-1;
		for(int i = 0; i < H; i++) {
			String s = sc.next();
			for(int j = 0; j < W; j++) {
				c[i][j] = s.charAt(j);
				if(s.charAt(j)=='#') {
					
					box++;
				}
			}
		}
		int ans = BFS();
		if(ans == 0 ){
			System.out.println(-1);
		}else {
			System.out.println(H*W - box - ans -1);
		}
	}
	
	public static int BFS() {
		int maze[][] = new int[H][W];
		Queue<Integer> queue_x = new ArrayDeque<>();
		Queue<Integer> queue_y = new ArrayDeque<>();
		
		queue_x.add(sx);
		queue_y.add(sy);
	
		int ans = 0;
		
	
		while(queue_x.size() != 0 && queue_y.size() != 0) {
		//キューの先頭を取り出す。
			int x = queue_x.poll();
			int y = queue_y.poll();
			// a上下左右に移動した場合、どうなるか
			for (int k = 0; k < 4; k++) {
					int xx = x + dx[k];
					int yy = y + dy[k];
					
					if (xx >= 0 && xx < W && yy >= 0 && yy < H) {
								
						if (c[yy][xx]=='.' && maze[yy][xx] == 0) {
								maze[yy][xx] = maze[y][x] + 1;
								queue_x.add(xx);
								queue_y.add(yy);
						}
					}
			}
		}
		return maze[gy][gx];		
	
	}
}
	

	

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int ans = 0;
  rep(i, n) {
    while (!(a[i] & 1)) {
      ans++;
      a[i] /= 2;
    }
  }
  cout << ans << endl;


  
  return 0;
}

Measured memory_bytes: 256
using System;

namespace agc030_a
{
    class Program
    {
        static void Main(string[] args)
        {
            var text = Console.ReadLine();
            var list = text.Split(' ');

            var a = Convert.ToInt32(list[0]);
            var b = Convert.ToInt32(list[1]);
            var c = Convert.ToInt32(list[2]);

            var isInner = false;
            if (a < b)
            {
                isInner = (a <= c) && (c <= b); 
            }
            else if (a == b)
            {
                isInner = (a == c); 
            }
            else
            {
                isInner = (a >= c) && (b <= c);
            }

            if (isInner)
            {
                Console.WriteLine("Yes");
            }
            else{
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    sort(A.begin(), A.end(), greater<int>());
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) {
            ans += A[i];
        } else {
            ans -= A[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
//OM
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define  x first
#define  y second
#define  pb push_back
#define  mp make_pair
#define  PI (acos(-1.0))
#define  mem(a,b) memset(a,b,sizeof(a))
#define  Sort(x) sort(x.begin(),x.end())
#define  FOR(i, b, e) for(int i = b; i <= (int)(e); i++)
#define  FORR(i, b, e) for(int i = b; i >=(int)(e); i--)
#define  FORI(i, s) for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)
#define  pr(x) cout<<x<<"\n"
#define  prs(x) cout<<x<<" "
#define  pr2(x,y) cout<<x<<" "<<y<<"\n"
#define  pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define  ppr(a) cout<<a.x<<" "<<a.y<<"\n"

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  vector <int> vi;
typedef  vector <pii> vpii;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction

#define  EPS 1e-9
#define  MAX 100007
int a[MAX];
int cilo[MAX];
int main()
{
    int T,n,m,x,y;
    scanf("%d",&n);
    scanf("%d",&m);
    FOR(i,1,n)a[i]=1;
    int red=0;
    cilo[1]=1;
    FOR(i,1,m)
    {
        scanf("%d%d",&x,&y);
        if(cilo[x]==1)
        {
            a[x]--;
            a[y]++;
            if(a[x]==0)cilo[x]=0;
            cilo[y]=1;
        }
        else
        {
            a[x]--;
            a[y]++;
        }
//        FOR(i,1,n)prs(a[i]);
//        pr("");
    }
    FOR(i,1,n)if(cilo[i]>0&&a[i]>0)red++;
    pr(red);

    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll n,k;
	cin>>n>>k;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n-i;j++){
			ll now=n-i-j;
			ll sum=i*10000+j*5000+now*1000;
			if(sum==k){
				cout << i <<" "<< j <<" "<<now;
				return 0;
			}
		}
	}
	cout << -1 <<" "<< -1 << " "<<-1;
	return 0;
}

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

#define rep(i,n) for (int i = 0; i< (n); i++)
using namespace std;
 
int main() {
  int N, M, ans = 0, wrong = 0;
  cin>>N>>M;
  
  vector<int> p(M);
  vector<string> S(M);
  vector<int> wcount(N+1, 0);
  vector<int> done(N+1, 0);
  
  rep(i, M){
  	cin>>p[i]>>S[i];
  }
  
  rep(i, M){
    if(done[p[i]]==0){
      if(S[i] == "AC"){
      	ans++;
        wrong += wcount[p[i]];
        done[p[i]] = 1;
      }
      else{
      	 wcount[p[i]]++;
      }
    }
  }  
  
  cout<<ans<<" "<<wrong<<endl;
}

Measured memory_bytes: 6912
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  for(int i = 0; i < N; i++){
    cin >> p.at(i);
  }
  sort(p.begin(), p.end());
  int ans = 0;
  for(int i = 0; i < K; i++){
    ans += p.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3684
#include<iostream>
#include<string>
using namespace std;
int main() {
	int e, y;
	cin >> e>>y;
	if (e == 0) {
		if (1868 <= y && y <= 1911) {
			cout << "M" << y - 1867 << endl;
		}
		if (1912 <= y && y <= 1925) {
			cout << "T" << y - 1911 << endl;
		}
		if (1926 <= y && y <= 1988) {
			cout << "S" << y - 1925 << endl;
		}
		if (1989 <= y && y <= 2016) {
			cout << "H" << y - 1988 << endl;
		}
	}
	if (e == 1) {
		cout << 1867 + y << endl;
	}
	if (e == 2) {
		cout << 1911 + y << endl;
	}
	if (e == 3) {
		cout << 1925 + y << endl;
	}
	if (e == 4) {
		cout << 1988 + y << endl;
	}
}


Measured memory_bytes: 3108
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>

using namespace std;

#define ll long long
#define el '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repi(i, a, b) for (int i = a; i >= b; i--)
#define VI vector<int>
#define VII vector<pair<int, int>>
#define PII pair<int, int>
#define MP make_pair
// #define log(fmt, ...) printf(fmt, ##__VA_ARGS__)
#define log(fmt, ...)
// #define check(...) assert(##__VA_ARGS__)
#define check(...)

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

    int n;
    cin >> n;
    ll ans = 0;
    rep(i, 1, n + 1) {
        if (i % 3 == 0 || i % 5 == 0) {
            continue;
        }
        log("%d ", i);
        ans += i;
    }
    cout << ans;
}


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

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

    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    ll sm_a = 0;
    ll sm_b = 0;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        sm_a += a[i];
    }
    for(int i = 0; i < n; ++i){
        cin >> b[i];
        sm_b += b[i];
    }

    ll cnt = sm_b - sm_a;

    ll c = 0;
    for(int i = 0; i < n; ++i){
        if(a[i] < b[i]) c += (b[i]-a[i]+1)/2;
    }

    if(c <= cnt) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3752
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

constexpr static int MAXN = 1e5 + 10;

int n, m;
int a[MAXN];
vector <int> adj[MAXN];

int c[MAXN];
vector <int> cv[MAXN];

void dfs(int u, int p, int color) {
    if (c[u] != -1)
        return;
    c[u] = color;
    for (int v : adj[u])
        if (v != p)
            dfs(v, u, color);
}

int64_t calc() {
    int color = 0;
    for (int i = 0; i < n; i++)
        if (c[i] == -1)
            dfs(i, -1, color++);
    if (color == 1)
        return 0;
    for (int i = 0; i < n; i++)
        cv[c[i]].push_back(a[i]);

    int64_t total = 0;
    vector <int> cextra;
    for (int k = 0; k < color; k++) {
        sort(cv[k].begin(), cv[k].end());
        for (int j = 1; j < cv[k].size(); j++)
            cextra.push_back(cv[k][j]);
        total += cv[k].front();
    }
    if (cextra.size() < color - 2)
        return -1;
    sort(cextra.begin(), cextra.end());
    for (int i = 0; i < color - 2; i++)
        total += cextra[i];
    return total;
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        c[i] = -1;
    }
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    int64_t r = calc();
    if (r == -1)
        cout << "Impossible" << endl;
    else
        cout << r << endl;
}


Measured memory_bytes: 10108
#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;

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

    vector<int> b = a;
    sort(b.begin(), b.end());

    int cnt = 0;
    for(int i=0; i<n; ++i){
        if(a[i] != b[i])
            ++ cnt;
    }

    if(cnt <= 2)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
n=int(input())
A,C,G,T,M=0,1,2,3,10**9+7
r=range
dp=[[[[0]*4for k in r(4)]for j in r(4)]for i in r(n+1)]
dp[0][T][T][T]=1
for i in r(1,n+1):
  for j in r(4):
    for k in r(4):
      for l in r(4):
        for m in r(4):
          if any(t==(k,l,m)for t in((A,G,C),(A,C,G),(G,A,C)))or(j,l,m)==(A,G,C)or(j,k,m)==(A,G,C):continue
          dp[i][k][l][m]=(dp[i][k][l][m]+dp[i-1][j][k][l])%M
print(sum(dp[n][i][j][k]for i in r(4)for j in r(4)for k in r(4))%M)

Measured memory_bytes: 52700
C = input()

alp = ["a","b","c","d","e","f","g","h","i","j","k","l",
       "m","n","o","p","q","r","s","t","u","w","x","y","z"]

index = alp.index(C)
if C == "z":
    print(alp[0])
else:
    print(alp[index+1])

Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solve();
	}

	private static void solve() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		int count = 0;
		for (int i = 0; i < n; i++) {
			int minIndex = i;
			for (int j = i; j < n; j++) {
				if (a[j] < a[minIndex]) {
					minIndex = j;
				}
			}
			if (minIndex != i) {
				int tmp = a[i];
				a[i] = a[minIndex];
				a[minIndex] = tmp;
				count++;
			}
		}

		for (int i = 0; i < n; i++) {
			System.out.print(a[i]);
			if (i != n - 1) {
				System.out.print(" ");
			}
		}
		System.out.print("\n");
		System.out.println(count);
	}
}

Measured memory_bytes: 26252
fun main(args : Array<String>) {
    val N = readLine()!!.toInt()
    val T = mutableListOf<Long>()
    (1..N).forEach {
        val t = readLine()!!.toLong()
        T.add(t)
    }

    val answer = T.reduce { acc, t -> lcm(acc, t) }
    println(answer)
}

fun lcm(a: Long, b: Long) : Long {
    return a  / gcd(a, b) * b
}


fun gcd(a: Long, b: Long) : Long {
    if (b == 0L) {
        return a
    }
    return gcd(b, a % b)
}

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

typedef long long ll;

#define PrintLn(X) cout << X << endl
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)

ll dp[500001][2];

int main(void)
{
	ll N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;
	N--;

	if(A > B) swap(A, B);
	B -= A;

	// dp[minus][min/max]
	dp[0][0] = C * N;
	dp[0][1] = D * N;

	for(int i = 1; i <= N; i++){
		dp[i][0] = dp[i - 1][0] - C - D;
		dp[i][1] = dp[i - 1][1] - D - C;
	}

	Rep(i, N + 1){
		if(dp[i][0] <= B && B <= dp[i][1]){
			PrintLn("YES");
			return 0;
		}
	}

	PrintLn("NO");
	return 0;
}


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

int main() {
	long long int n;
	cin>>n;
	long long int ABC[3][n];
	for(int i=0;i<n;i++){
		cin>>ABC[0][i]>>ABC[1][i]>>ABC[2][i];
	}
	long long int dp[n][3];
	long long int m=0;
	int abc;
	dp[0][0]=ABC[0][0];
	dp[0][1]=ABC[1][0];
	dp[0][2]=ABC[2][0];
	dp[1][0]=max(dp[0][1],dp[0][2])+ABC[0][1];
	dp[1][1]=max(dp[0][0],dp[0][2])+ABC[1][1];
	dp[1][2]=max(dp[0][1],dp[0][0])+ABC[2][1];
	for(int i=2;i<n;i++){
		for(int j=0;j<3;j++){
			m=0;
			for(int k=0;k<3;k++){
				if(k==j)continue;
				if(m<dp[i-1][k]){
					m=dp[i-1][k];
				}
			}
			dp[i][j]=m+ABC[j][i];
		}
	}
	int x=dp[n-1][0];
	if(x<dp[n-1][1])x=dp[n-1][1];
	if(x<dp[n-1][2])x=dp[n-1][2];
	cout<<x<<endl;
	return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <string.h>

int main(void)
{
    char s[4];
    scanf("%s", s);
    char a[4]="AAA";
    char b[4]="BBB";
    if(strcmp(s,a)==0||strcmp(s,b)==0){
        printf("No");
    }else{
        printf("Yes");
    }

    return 0;
}

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

using namespace std;

#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          N (int)2e5+5
#define          pb push_back
#define          mod 1000000007
#define          ld long double
#define          vi vector<int>
#define          eb emplace_back
#define          vpii vector<pii>
#define          mii map<int,int>
#define          int long long 
#define          pii pair<int,int>
#define          pq priority_queue
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          db(x) cout<<#x <<" : "<< x <<endl;
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          PI 3.141592653589793238462643383279502884197169399375105820974944592307816406286

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);   
	    freopen("output.txt","w",stdout);
	#endif 
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q,W;
string s;

int wt[101], val[101];
int dp[101][100001];
void go()
{
	cin >> n >> W;
	fo(i,1,n+1) cin >> wt[i] >> val[i];  

	// dp[i][j] --- using first i element  and j 'value' banai to kitne minimum wt laga
	int ans = 0;
	fo(i,0,n+1)
	{
		fo(j,0,100001)
		{
			if( i == 0 )
			{
				if( j == 0 ) dp[i][j] = 0;
				else dp[i][j] = inf;
				continue;
			}

			int a1 = INF;
			if( j - val[i] >= 0 ) a1 = wt[i] + dp[i-1][ j-val[i] ];
			int a2 = dp[i-1][j];

			dp[i][j] = min(a1, a2);
			if( dp[i][j] <= W ) ans = max(ans,  j);
		}
	}

	cout << ans;    

}

int32_t main()
{
	//INP(); 
	FAST;     
	int t=1; 
	// cin>>t;
	test(t) go();
}


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

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

    int n;
    cin >> n;
    float sum = 0;
    for (int i = 0; i < n; ++i) {
        float x;
        string u;
        cin >> x >> u;
        if (u == "JPY") {
            sum += x;
        } else {
            sum += x * 380000;
        }
    }
    
    cout << sum << '\n';

    return 0;
}


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

int main(){
  int p,five=0,seven=0;
  for(int i=1;i<=3;i++)
  {
    cin>>p;
    if(p==5)five++;
    else if(p==7)seven++;
  }
  if(five==2 && seven==1)cout<<"YES\n";
  else cout<<"NO\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

#include <set>
#include <unordered_map>
#include <stack>
#include <map>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T>bool chmaxj(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; }
void YesNo(bool y) { cout << (y ? "Yes" : "No") << endl; } //true==yes


#define INF 21474836

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


int main() {

	int N, M;
	cin >> N >> M;

	vector<int> H(N);
	rep(i, N)cin >> H[i];

	vector<int> A(M), B(M);
	rep(i, M) {
		cin >> A[i];
		cin >> B[i];
		A[i]--;
		B[i]--;
	}

	vector<bool> TE(N , true);

	rep(i, M) {
		if (H[A[i]] > H[B[i]]) {
			TE[B[i]] = false;
		}
		if (H[A[i]] < H[B[i]]) {
			TE[A[i]] = false;
		}
		if (H[A[i]] == H[B[i]]) {
			TE[A[i]] = false;
			TE[B[i]] = false;
		}
	}

	int ans = 0;
	rep(i, N) {
		if (TE[i])ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 4576
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <ctype.h>

using namespace std;
using ll=long long;
using ull=unsigned long long;

int main()
{
    int N;
    
    cin >> N;
    
    int ans = 0;

    // 愚直に足していく
#if 0
    while (N > 0)
    {
        ans += N--;
    }
#endif

    // 和の公式
    ans = N * (N + 1) / 2;
    
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
    ll N, M, A = 0;
    cin >> N >> M;
    rep(i,M) {
        ll tmp;
        cin >> tmp;
        A += tmp;
    }
    N -= A;
    if (N<0) {
        cout << -1 << endl;
    }
    else {
        cout << N << endl;
    }

    return 0;
}

Measured memory_bytes: 3184