akhauriyash/Code-Regression huggingface dataset:
#coding: utf-8
N = input()
N_list = list(map(int,N))
N_str = str(N)

if (N_list[0] + N_list[1] + N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"+"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] + N_list[2] + N_list[3])==7:
    print(N_str[0] +"-"+ N_str[1] +"+"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] - N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"-"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] - N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"-"+  N_str[2] + "-" + N_str[3]+"=7")

elif (N_list[0] + N_list[1] - N_list[2] + N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"-"+  N_str[2] + "+" + N_str[3]+"=7")

elif (N_list[0] + N_list[1] - N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"-"+  N_str[2] + "-" + N_str[3]+"=7")

elif (N_list[0] + N_list[1] + N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"+"+ N_str[1] +"+"+  N_str[2] + "-" + N_str[3]+"=7")

elif (N_list[0] - N_list[1] + N_list[2] - N_list[3]) ==7:
    print(N_str[0] +"-"+ N_str[1] +"+"+  N_str[2] + "-" + N_str[3]+"=7")

Measured memory_bytes: 3064
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

times = list()
times.append(a)
times.append(b)
times.append(c)
times.append(d)
times.append(e)

time_sum = 0
small = 10
for time in times:
    if time % 10 == 0:
        time_sum += time
    else:
        time_sum += (time // 10 + 1) * 10
        small = min(small, time % 10)
print(time_sum - 10 + small)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void){
  int k,i;
  ll a,b;
  
  cin >> a >> b >> k;
  
  for (i=0;i<k;i++){
    if (i%2==0){
      b+=a/2;
      a/=2;
    }else{
      a+=b/2;
      b/=2;
    }
  }
  
  cout << a << ' ' << b << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define N 200010
#define LL long long
#define inf 1000000000000000007
LL a[N],s1[N],s2[N];
int main()
{
    int i,j,k,n;
    LL s,t,ans;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        a[i]=a[i]-i;
    }
    sort(a+1,a+n+1);
    s=0;
    s1[0]=0;
    for(i=1;i<=n;i++)
    {
        s1[i]=s1[i-1]+(a[i]<0?a[i]:0);
        s=s+abs(a[i]);
    }
    s2[n+1]=0;
    for(i=n;i>=1;i--)
        s2[i]=s2[i+1]+(a[i]>0?a[i]:0);
    ans=s;
    for(i=1;i<=n;i++)
    {
        if(a[i]<0)
        {
            t=abs(s1[i])+a[i]*i+(-a[i])*(n-i)+s1[n]-s1[i]+s2[i];
            ans=min(ans,t);
        }
        else
        {
            t=s2[i]-a[i]*(n-i+1)+abs(s1[i])+(i-1)*a[i]-(s2[1]-s2[i]);
            ans=min(ans,t);
        }
        //printf("%lld %lld %lld\n",a[i],t,ans);
    }
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std;

int n, m, cnt[2], ans = INT_MAX;
int z[705];
bool x[705][705], vis[705], y[705];
vector<int> v;
vector<pair<int,int>> vv;
int ta, tb;

bool dfs(int a) {
	vis[a] = 1;
	cnt[y[a]]++;
	for (int i = 1; i <= n; i++)
		if (!x[a][i])
			if (!vis[i]) {
				y[i] = y[a] ^ 1;
				if (!dfs(i))
					return 0;
			} else if (y[i] != (y[a] ^ 1))
				return 0;
	return 1;
}

int main() {
	z[0] = 1;
	v.push_back(0);
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)
		x[i][i] = 1;
	while (m--) {
		scanf("%d%d", &ta, &tb);
		x[ta][tb] = x[tb][ta] = 1;
	}
	for (int i = 1; i <= n; i++)
		if (!vis[i]) {
			cnt[0] = cnt[1] = 0;
			if (!dfs(i)) {
				printf("-1\n");
				return 0;
			}
			vv.clear();
			for (int j : v) {
				vv.push_back({j + cnt[0], z[j] + cnt[1]});
				vv.push_back({j + cnt[1], z[j] + cnt[0]});
				z[j] = 0;
			}
			v.clear();
			for (auto p : vv)
				if (z[p.first])
					z[p.first] = min(z[p.first], p.second);
				else {
					z[p.first] = p.second;
					v.push_back(p.first);
				}
		}
	for (int i : v)
		ans = min(ans, i * (i - 1) / 2 + (z[i] - 1) * (z[i] - 2) / 2);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 768
#include <cstdio>
#include <unordered_map>
using namespace std;
using T = long long;

int main() {
	T x, n, r = 0, s = 0;
	unordered_map<T, T> a;

	scanf("%lld", &n);
	for(T i = 0; i < n; i++)
		scanf("%lld", &x), a[r += x]++;
	
	for(pair<T, T> i : a) {
		T x = i.first, y = i.second;

		if(x == 0)
			s += y * (y + 1) / 2;
		else
			s += y * (y - 1) / 2;
	}
	
	printf("%lld", s);
}

Measured memory_bytes: 8520
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
typedef long long ll;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    for(int i = 0; i <= N; i++) {
        if((int)floor((double)i * 1.08) == N) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
	if(kaijo_memo.size() > n) return kaijo_memo[n];
	if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
	while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
	return kaijo_memo[n];
}
ll nCr(ll n, ll r){
	if(n < r || r < 0) return 0;
	ll ret = 1;
	ret *= kaijo(n); ret %= MOD;
	ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
	ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
	return ret;
}

int main(void){
	ll n,m,a,b;
	cin>>n>>m;
	vector<pair<ll,ll>> task;
	rep(i,n){
		cin>>a>>b;
		task.push_back(pair<ll,ll>{a,b});
	}
	sort(all(task));

	ll ans = 0;
	int ti = 0;
	priority_queue<ll> kouho;
	reps(i,m){
		a = task[ti].first;
		b = task[ti].second;
		while(ti < task.size() && a <= i){
			kouho.push(b);
			ti++;
			if(ti >= task.size()) break;
			a = task[ti].first;
			b = task[ti].second;
		}
		if(kouho.size() > 0){
			ans += kouho.top();kouho.pop();
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

int main() {
  ll X,K,D,f,ans=0;
  cin >> X >> K >> D;
  f=X/D;
  if(abs(f)>K){
    if(X>0) ans = abs(X-K*D);
    else ans = abs(X+K*D);
  }
  else{
  X=X-f*D;
  if((K-f)%2==0) ans = abs(X);
  else {
    if(X>0) ans = abs(X-D);
    else ans = abs(X+D);
  }
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
void dfs(int i,int last);
int n;
vector<int>node[100009];
long long dp[100009][3];

int main(){
  cin>>n;
  for(int i=0;i<n-1;i++){
    int x,y;
    cin>>x>>y;
    node[x].push_back(y);
    node[y].push_back(x);
  }

  dfs(1,0);

  cout<<(dp[1][0]+dp[1][1])%mod<<endl;
  return(0);
}

void dfs(int i,int last){
  dp[i][0]=dp[i][1]=1;
  for(int j=0;j<node[i].size();j++){
    int next=node[i][j];
    if(next==last)continue;
    dfs(next,i);
    dp[i][0]*=dp[next][0]+dp[next][1];
    dp[i][1]*=dp[next][0];
    dp[i][0]%=mod;
    dp[i][1]%=mod;
  }
}


Measured memory_bytes: 14976
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  int n;
  cin>>n;
  
  if(n%1000==0) cout<<0<<endl;
  else cout<<1000-n%1000<<endl;
  
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <queue>
#include <climits>
#include <algorithm>

struct Edge {
	int s;
	int t;
	int weight;
};

bool comp_s(const Edge& e, const Edge& f) { return e.s < f.s; }

struct Vertex {
	int id;
	int weight;
	std::vector<int> sink;
	std::vector<int> weight_to_sink;
	bool done;
};

typedef std::pair<int,int> W_ID;

int main ()
{
	int n, m, r;
	std::cin >> n >> m >> r;
	
	Edge* edge_list = new Edge[m];
	for (int i=0; i<m; i++) std::cin >> edge_list[i].s >> edge_list[i].t >> edge_list[i].weight;
	std::sort(edge_list, edge_list + m, comp_s);
	
	Vertex* vertex = new Vertex[n];
	int index = 0;
	for (int i=0; i<n; i++) {
		vertex[i].id = i;
		vertex[i].weight = INT_MAX;
		vertex[i].done = false;
		while (edge_list[index].s == i) {
			vertex[i].sink.push_back(edge_list[index].t);
			vertex[i].weight_to_sink.push_back(edge_list[index].weight);
			index++;
		}
	}
	vertex[r].weight = 0;
	
	std::priority_queue<W_ID, std::vector<W_ID>, std::greater<W_ID> > pq;
	pq.push( std::make_pair(0,r) );
	
	while (!pq.empty()) {
		int s = pq.top().second; pq.pop();
		vertex[s].done = true;
		for (int i=0; i<vertex[s].sink.size(); i++) {
			int t = vertex[s].sink[i];
			if (vertex[t].done) continue;
			int w = vertex[s].weight_to_sink[i];
			if (vertex[t].weight > vertex[s].weight + w) {
				vertex[t].weight = vertex[s].weight + w;
				pq.push ( std::make_pair(vertex[t].weight, t) );
			}
		}
	}
	
	for (int i=0; i<n; i++) {
		if(vertex[i].done) std::cout << vertex[i].weight << std::endl;
		else std::cout << "INF" << std::endl;
	}
	
	delete[] vertex;
	delete[] edge_list;
	
	return 0;
}



Measured memory_bytes: 23808
# Tap Dance

# input
S = input()

# solve
cond1 = sum([s == 'L' for s in S[::2]])
cond2 = sum([s == 'R' for s in S[1::2]])

# output
if cond1 == 0 and cond2 == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N,X;
    N = sc.nextInt();
    X = sc.nextInt();
    Integer x[] = new Integer[N];
    for(int i=0; i<N; i++) x[i] = sc.nextInt();
    int ans = Math.abs(X - x[0]);
    int tmp;
    for(int i=1; i<N; i++){
      tmp = Math.abs(X - x[i]);
      ans = gcd(ans, tmp);
    }
    System.out.println(ans);
  }
  
  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}



Measured memory_bytes: 59508
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<int, int>, // change type
//        null_type,
//        less<pair<int, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
const double PI = 3.14159265358979323846;
const double eps = (1e-8);




int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("facebook.txt", "w", stdout);
#endif
    int k, a, b;
    cin >> k >> a >> b;
    ++k;
    if (b > a + 1)
    {
        if (k < a)
        {
            cout << k;
            return 0;
        }
        k -= a; // make a biscuits and turn to yen

        cout << 1LL * (b - a) * (k/2 - 1) + b + (k&1);

    }
    else
    {
        cout << k;
    }
    return 0;
}

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

typedef long long ll;
const int N=3e5+10;
int n,K,cnt;
int a[N],b[N],c[N<<1],l[N],r[N];
ll ans,s[N],f[N];

int read()
{
	int ret=0;char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)) ret=ret*10+(c^48),c=getchar();
	return ret;
}

struct Segment
{
#define ls (x<<1)
#define rs (x<<1|1)
	int col[N<<2],tar[N<<2];
	void pushdown(int x)
	{
		if(!tar[x]) return;
		col[ls]=col[rs]=tar[ls]=tar[rs]=tar[x];tar[x]=0;
	}
	void update(int x,int l,int r,int L,int R,int v)
	{
		if(L>R) return;
		if(L<=l && r<=R){col[x]=tar[x]=v;return;}
		pushdown(x);
		int mid=(l+r)>>1;
		if(L<=mid) update(ls,l,mid,L,R,v);
		if(R>mid) update(rs,mid+1,r,L,R,v);
	}
	int querycol(int x,int l,int r,int p)
	{
		if(l==r) return col[x];
		pushdown(x);
		int mid=(l+r)>>1;
		if(p<=mid) return querycol(ls,l,mid,p);
		else return querycol(rs,mid+1,r,p);
	}
	ll query(int x)
	{
		int pos=querycol(1,1,cnt,x);
		return pos?f[pos]+(c[l[pos]]-c[x]+K)%K:0;
	}
#undef ls
#undef rs
}tr;

int main()
{
#ifdef Durant_Lee
	freopen("AGC011F.in","r",stdin);
	freopen("AGC011F.out","w",stdout);
#endif
	n=read();K=read();
	for(int i=1;i<=n;++i)
	{
		a[i]=read();b[i]=read();s[i]=s[i-1]+a[i];
		if(b[i]&1) l[i]=(K-s[i-1]*2%K)%K,r[i]=(K-s[i]*2%K)%K;
		else l[i]=0,r[i]=K-1;
		if(b[i]&1 && a[i]*2>K){puts("-1");return 0;}
		c[++cnt]=l[i];c[++cnt]=r[i];
	}
	sort(c+1,c+cnt+1);cnt=unique(c+1,c+cnt+1)-c-1;
	for(int i=1;i<=n;++i) l[i]=lower_bound(c+1,c+cnt+1,l[i])-c,r[i]=lower_bound(c+1,c+cnt+1,r[i])-c;
	for(int i=n;i;--i)
	{
		f[i]=tr.query(l[i]);
		if(l[i]>r[i]) tr.update(1,1,cnt,r[i]+1,l[i]-1,i);
		else tr.update(1,1,cnt,1,l[i]-1,i),tr.update(1,1,cnt,r[i]+1,cnt,i);
	}
	ans=f[1];
	for(int i=cnt;i;--i) ans=min(ans,tr.query(i));
	printf("%lld\n",ans+2*s[n]);
	return 0;
}

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

int main() {
  char in[2];
  cin >> in;

  in[0]++;

  cout << in << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000)
input = sys.stdin.readline

def chk(a):
	a_name = ''
	for k, v in globals().items():
		if id(v) == id(a):
			a_name = k
			break
	print(a_name+' = '+str(a), file=sys.stderr)

def mt(f):
	import time
	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		print(e - s, 'sec', file=sys.stderr)
		return ret
	return wrap

@mt
def slv(T, X):
	chk(T)
	chk(X)
	return T/X

T, X = [int(i) for i in input().split()]
print(slv(T, X))

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  vector<LD> p(n);
  for(int i=0;i<n;i++) cin >> p[i];
  vector<LD> dp(n+1,0);
  dp[0]=1;
  for(int i=1;i<=n;i++){
    for(int j=i;j>0;j--){
      dp[j]=dp[j]*(1-p[i-1])+dp[j-1]*p[i-1];
    }
    dp[0]=dp[0]*(1-p[i-1]);
  }
  LD ans=0;
  for(int i=(n+1)/2;i<=n;i++){
    ans+=dp[i];
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) solve();
}

void solve() {
  string s;
  cin >> s;
  vector<int> v;
  rep(i, sz(s) - 1) {
    if (s[i] == 'R' && s[i + 1] == 'L') {
      v.eb(i);
    }
  }
  // cout << v << endl;
  map<int, int> mp;
  rep(i, sz(s)) {
    int it = lb(v, i);
    if (s[i] == 'L') it--;
    it = v[it];
    int pos = it + 1 + (abs(it - i) % 2);
    // cout << it << " " << pos << endl;
    mp[pos]++;
  }
  rep3(i, 1, sz(s) + 1) cout << mp[i] << " "; cout << endl;
}


Measured memory_bytes: 5452
#include <iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

void dijkstra(){
    int minv;
    int d[MAX], color[MAX];

    for(int i=0;i<n;i++){
        d[i]=INFTY;
        color[i]=WHITE;
    }

    d[0] = 0;
    color[0] = GRAY;

    while(1){
        minv = INFTY;
        int u=-1;
        for(int i=0;i<n;i++){
            if(minv > d[i] && color[i] != BLACK){
                u = i;
                minv = d[i];
            }
        }
        if(u==-1) break;
        color[u] = BLACK;
        for(int v=0;v<n;v++){
            if(color[v] != BLACK && M[u][v] != INFTY){
                if(d[v]>d[u]+M[u][v]){
                    d[v] = d[u] + M[u][v];
                    color[v]= GRAY;
                }
            }
        }
    }

    for(int i=0;i<n;i++){
        cout << i << " " << (d[i]==INFTY?-1:d[i]) << endl;
    }
}

int main(){
    cin >> n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++) M[i][j] = INFTY;
    }

    int k, c, u, v;

    for(int i=0;i<n;i++){
        cin >> u >> k;
        for(int j=0;j<k;j++){
            cin >> v >> c;
            M[u][v] = c;
        }
    }

    dijkstra();

    return 0;

}



Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
int a,b,sum[100002],j,k;
int main()
{
    sum[10000-1]=0;
    for(int i=10000; i<=99999; i++)
    {
        stringstream ss;
        ss << i;
        string s = ss.str();
        int f=0;
        for(j=0,k=s.size()-1; j<s.size(),k>=0; j++,k--)
        {
            if(s[j]!=s[k])
            {
                f=1;
                break;
            }
        }
        if(f==0)
            sum[i]=sum[i-1]+1;
        else
            sum[i]=sum[i-1];
    }
    cin>>a>>b;
    if(sum[a-1]!=sum[a])
        cout<<sum[b]-sum[a]+1<<endl;
    else
        cout<<sum[b]-sum[a]<<endl;
    
    return 0;
}

Measured memory_bytes: 640
#include <iostream>

 

using namespace std;

 

int main()
{
    int i, x;
    for(i=1; i<=10000; i++)
    {
       cin >> x;
    if(x==0)
        break;
    else
        cout << "Case " << i << ":" << " " << x << endl;
        
    }
}


Measured memory_bytes: 3092
#include <bits/stdc++.h> 
#include<cmath>
#include<string>
#define pb push_back
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
//void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
// look for  all edge cases
//search for a pattern



signed main() {    
	ios::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	int cnt =0 ;
	bool ok = false;

	for(int i =0 ; i < n; i++){
		int f1 , f2;
		cin >> f1 >> f2;
		if(f1 == f2){
			cnt += 1;
		}
		else
			cnt = 0;
			
		if(cnt == 3){
			ok = true;
		}
	}
	
	if(ok)
		cout<<"Yes";
	else
		cout<<"No";
		
	return 0;
}


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

using namespace std;

#define int long long

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;

	vector<int> a(n);
	unordered_map<int, int> mp;

	for(int &x: a) {
		cin >> x;
		++mp[x];
	}

#define cal(x) ((x) * ((x) - 1) / 2)

	int sum = 0;
	for(int i = 1; i <= n; i++) {
		sum += cal(mp[i]);
	}

	for(int x: a) {
		sum -= cal(mp[x]);
		--mp[x];
		sum += cal(mp[x]);
		cout << sum << '\n';

		sum -= cal(mp[x]);
		++mp[x];
		sum += cal(mp[x]);
	}

#undef cal

	return 0;
}



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


int main()
{
	int n;
	int a[100005];
	cin >> n;
	a[0]=0;
	int f=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]+1==a[i-1]){
			a[i]++;
		}
		else if(a[i]+1<a[i-1]){
			f=1;
		}
	}
	if(f==0)printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

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

   scanf("%d %d %d", &a, &b, &c);

   tmp = a;
   a = b;
   b = tmp;

   tmp = a;
   a = c;
   c = tmp;
   printf("%d %d %d", a, b, c);
 }

Measured memory_bytes: 128
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
 
using namespace std;
 
#define int long long
//typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int x;
	cin >> x;
	int n = (int)sqrt((float)x * 2.0);
	if(n * (n + 1) / 2 < x) n++;
	cout << n << endl;
	return 0;
}

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

int main(){
  ll N,M;
  cin >> N >> M;
  vector<ll> flog(N);
  for(ll i=0;i<N;i++){
    cin >> flog[i];
  }
  ll inf=pow(10,10);
  vector<ll> dp(N,inf);
  dp[0]=0;
  for(ll i=0;i<N;i++){
    for(ll j=1;j<=M;j++){
      if(i+j>=N){
        break;
      }
      else{
        dp[i+j]=min(dp[i]+abs(flog[i]-flog[i+j]),dp[i+j]);
      }
    }
  }
  cout << dp[N-1] <<endl;
}



Measured memory_bytes: 4832
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define rloop(i,a,b) for(ll i=a;i>b;i--)
const int inf=1e5+7;
ll dp[inf];
vector<ll>edges[inf];
bool visited[inf];
ll dfs(ll i)
{
	if(!visited[i])
	{
			visited[i]=true;
		for(auto ver:edges[i])
		{
			
			dp[i]=max(dp[i],dfs(ver)+1);
		
			
		}
		
	}
	
	
	return dp[i];
	
}
int main()
{


int n,m;
cin>>n>>m;
loop(i,0,n)
dp[i]=0,visited[i]=false;
ll x,y;
		loop(i,0,m)
		{
			cin>>x>>y;
			edges[x].push_back(y);
			
		}
	
	
	loop(i,1,n+1)
	{
		
			if(!visited[i])
			dfs(i);
			
		
	}
	
	ll ans=0;
	loop(i,1,n+1)
	{
		for(auto child : edges[i])
		{
			dp[i]=max(dp[i],dp[child]);	
			
		}
		ans=max(dp[i],ans);
	}
	
		
		cout<<ans;
		

	
}

Measured memory_bytes: 7936
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }
        for(int i=0; i<n; i++){
            int min = i;
            for(int j=i; j<n; j++){
                if(b[min]>b[j]) min = j;
            }
            int tmp = b[i];
            b[i] = b[min];
            b[min] = tmp;
            tmp = a[i];
            a[i] = a[min];
            a[min] = tmp;
        }

        int max = 0;
        int INF = Integer.MAX_VALUE/10;
        int[][] dp = new int[n+1][n+1];
        for(int i=0; i<=n; i++) Arrays.fill(dp[i], INF);
        for(int i=0; i<=n; i++) dp[i][0] = 0;
        for(int i=1; i<=n; i++){
            for(int j=1; j<=n; j++){
                for(int k=0; k<i; k++){
                    dp[i][j] = Math.min(dp[i][j], dp[k][j]);
                    if(dp[k][j-1]!=INF && dp[k][j-1]+a[i-1]<=b[i-1]){
                        dp[i][j] = Math.min(dp[i][j], dp[k][j-1]+a[i-1]);
                    }
                    if(dp[i][j]!=INF) max = Math.max(max, j);
                }
            }
        }
        System.out.println(max);
    }

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

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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

int main()
{    
    

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li n,W;

    cin>>n>>W;

    vector<pi> v(n);

    f(i,0,n-1)
    {
        cin>>v[i].F>>v[i].S;
    }

    sort(v.B,v.E);

    li dp[n][W+1];

    f(i,0,W)
    {
        if(i>=v[0].F)
        {
            dp[0][i]=v[0].S;
        }
        else
            dp[0][i]=0;
    }

    f(i,1,n-1)
    {
        f(j,0,W)
        {
            if(j>=v[i].F)
            {
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-v[i].F]+v[i].S);
            }
            else
            {
                dp[i][j]=dp[i-1][j];
            }
        }
    }

    // f(i,0,n-1)
    // {
    //     f(j,0,W)
    //     {
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }

    cout<<dp[n-1][W];

    return 0;
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N;
  double a = 0;
cin >> N;
    if(N % 2 == 0){
      a=0.5;
    }
      
  if(N % 2 == 1){
    double b = N;
    a = (b/2+0.5)/b;
  
    
  }
  cout <<a<< endl;
 
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	int n, k;
	while(cin >> n >> k) {
		if(n == 0 && k == 0) break;

		vector<int> v;
		bool flag = false;
		rep(i, k) {
			int x;
			cin >> x;

			if(x == 0) {
				flag = true;
			} else {
				v.push_back(x);
			}
		}

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

		vector<P> p;
		int left = -1, right = -1;
		rep(i, v.size()) {
			left = v[i];
			right = v[i];
			REP(j, i+1, v.size()) {
				if(right + 1 == v[j]) {
					right = v[j];
					i++;
				} else break;
			}

			p.push_back(mp(left, right));
		}

		int ans = 0;
		rep(i, p.size()) {
			ans = max(ans, p[i].second - p[i].first + 1);
		}

		if(flag) {
			REP(i, 1, p.size()) {
				if(p[i].first - p[i-1].second == 2) {
					ans = max(ans, p[i].second - p[i-1].first + 1);
				}
			}
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1732
#include <iostream>
using namespace std;
int main(){
  string S;
  cin >> S;
  for(int i = 0; i < (1<<3); ++i){
    char op[3];
    int t = S[0]-'0';
    for(int j = 0; j < 3; ++j){
      if((i>>j)&1) t -= S[j+1]-'0', op[j] = '-';
      else t += S[j+1]-'0', op[j] = '+';
    }
    if(t == 7){
      printf("%c%c%c%c%c%c%c=7\n",S[0],op[0],S[1],op[1],S[2],op[2],S[3]);
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(s) cout << s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
   string n; cin>>n;
   if (n[0] == n[1] && n[1] == n[2] || n[1] == n[2] && n[2] == n[3]){
       cout << "Yes" << endl;
   }else{
       cout << "No" << endl;
   }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(n); i++)
using veci = vector<int>;
int main(){
    int n; cin >> n;
    veci s(n+1);
    rep(i, n) cin >> s[i];
    int q; cin >> q;
    veci t(q+1);
    rep(i, q) cin >> t[i];
    int i=0;
    int ans=0;
    t[q] = -1;
    s[n] = -1;
    while (t[i] != -1){
        int j=0;
        while (s[j] != t[i]&&j<n){
            j++;
        }
        if (j != n) {
            ans++;
        }
        i++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3116
n = int(input())
www = [input() for _ in range(n)]
ans = 'Yes'
if len(list(set(www))) != n:
    ans = 'No'
else:
    for i in range(1, n):
        if www[i][0] != www[i - 1][-1]:
            ans = 'No'
print(ans)

Measured memory_bytes: 9084
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

const int MAX_N = 30;

int par[MAX_N];
int rank[MAX_N];
//vector <P> G[MAX_N];

// n要素で初期化
int init_union_find (int n )
{
	rep (i, n ){
		par[i] = i;
		rank[i] = 0;
	} // end for
}

// 木の根を求める
int find (int x )
{
	if (par[x] == x )
		return x;

	// 親を遡る
	return par[x] = find (par[x] );
}

// xとyの属する集合をマージ
void unite (int x, int y )
{
	x = find (x);
	y = find (y);

	// 親が一緒なら何もしない
	if (x == y )
		return;

	// ランクが小さい方の木をぶら下げる
	if (rank[x] < rank[y] ){
		// x を y にぶら下げる
		par[x] = y;
	}else{
		// ランクが同じか rank[x] > rank[y]
		par[y] = x;
		if (rank[x] == rank[y] )
			rank[x]++;
	} // end if
}

// xとyが同じ集合に属するか否か
bool same (int x, int y )
{
	return (find (x) == find (y) );
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.koukyoukoukokukikou", "r", stdin );

	const char left[] =  { 'q', 'w', 'e', 'r', 't', 'a', 's', 'd', 'f', 'g', 'z', 'x', 'c', 'v', 'b' };
	const char right[] = { 'y', 'u', 'i', 'o', 'p', 'h', 'j', 'k', 'l', 'n', 'm' };
	init_union_find (26 );
	for  (int i = 1; i < sizeof (left)/sizeof(left[0] ); i++ ){
		unite ((int)(left[0] - 'a'), (int)(left[i] - 'a') );
	} // end for
	for (int i = 1; i < sizeof (right)/sizeof (right[0] ); i++ ){
		unite ((int)(right[0] - 'a'), (int)(right[i] - 'a' ) );
	} // end for

	string str = "";
	while (cin >> str && str != "#" ){
		char curr = str[0];
		int cnt = 0;
		int n = str.length();
		for (int i = 1; i < n; i++ ){
			if (same((int)(curr - 'a'), (int)(str[i] - 'a' ) ) ) continue;
			cnt++;
			curr = str[i];
		} // end for
		printf ("%d\n", cnt );
	} // end while
		
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int Nmax = 300000;
int N,M,L[Nmax],R[Nmax];

template <class T>
class Bit{
	vector<T> v;
	public:
	Bit(int n) {
		v = vector<T>(n);
	}
	T sum(int i){
		int s=0;
		while(i>0){
			s += v[i];
			i -= i & -i;
		}
		return s;
	}

	void add(int i, T x){
		while(i <= v.size()){
			v[i] += x;
			i += i & -i;
		}
	}
};

int main(){
	cin >> N >> M;
	for(int i=0; i<N; i++) cin >> L[i] >> R[i];

	vector<pair<int, int> > vec;
	for(int i=0; i<N; i++){
		vec.push_back(make_pair(R[i]-L[i]+1, i));
	}
	sort(vec.begin(), vec.end());

	vector<pair<int, int> >::iterator j=vec.begin();
	Bit<int> cnt(M+1);
	for(int i=1; i<=M; i++){
		while(j != vec.end() && j->first < i){
			cnt.add(L[j->second], 1);
			if(R[j->second]+1<=M)
				cnt.add(R[j->second]+1, -1);
			j++;
		}
		int ans = vec.end()-j;
		for(int j=0; i*j<=M; j++){
			ans += cnt.sum(i*j);
		}
		cout << ans << endl;
	}



	return 0;
}


Measured memory_bytes: 6896
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        for (int i = n; i >= 0; i--) {
            int a = (int)Math.sqrt(i);
            if (a * a == i) {
                System.out.println(i);
                return;
            }
        }
    }
}

Measured memory_bytes: 21972
#include <stdio.h>
#include <string.h>
#include <math.h>

#define max(x, y) ((x)>(y)?(x):(y))
#define sq(x) ((x)*(x))
#define dist(x, y, z, a, b, c) (sq(x-a)+sq(y-b)+sq(z-c))

double res,  L[21], a[21], b[21];
int v[1<<21], n, m;

int popcount(int n)
{
    int res=0;
    while (n>0) { n-=n&-n; ++res; }
    return res;
}

void dfs(int mask)
{
    int i, j;
    v[mask]=1;
    if (popcount(mask)==m) {
        double d=0;
        for(i=0;i<n;++i) if (mask&(1<<i))
            for(j=i+1;j<n;++j) if (mask&(1<<j))
                d+=dist(L[i],a[i],b[i],L[j],a[j],b[j]);
        res=max(res, d);
    }
    for(i=0;i<n;++i) if ((mask&(1<<i))==0 && !v[mask|(1<<i)]) dfs(mask|(1<<i));
}

int main(void)
{
    while (~scanf("%d%d", &n, &m)) {
        int i;
        memset(v, 0, sizeof(v));
        res=0;
        for(i=0;i<n;++i) scanf("%lf%lf%lf", L+i, a+i, b+i);
        dfs(0);
        printf("%.8f\n", res);
    }
    return 0;
}

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

int main() {
	int h,w;
	while(1){
		cin>>h>>w;
		if(h==0)
			break;
		else{
			for(int i=1; i<=h; i++){
				for(int j=1; j<=w; j++){
					cout<<'#';
				}
				cout<<endl;
			}
		cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1152
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 07/14/20 20:57:13
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n; cin>>n;
  vector<int> A(n),B(n);
  for (auto& a:A) cin>>a;
  for (auto& b:B) cin>>b;
  vector<int> F;
  ll needs = 0;
  int cntneeds = 0;
  for (int i = 0; i < n; i++) {
    if (A[i] > B[i])
      F.push_back(A[i]-B[i]);
    else if (B[i] > A[i]) {
      needs += B[i]-A[i];
      cntneeds++;
    }
  }
  sort(F.rbegin(), F.rend());
  int ans = 0;
  while (needs and ans < F.size()) {
    needs -= min((ll)F[ans], needs);
    ans++;
  }
  if (needs) {
    cout << -1 << endl;
  } else {
    cout << ans+cntneeds << endl;
  }

  return 0;
}


Measured memory_bytes: 4520
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
double ans;
ll n,m,q;
void solve()
{
    cin>>m;
    for(ll i=1;i<=m;i++)
    {
        double a;cin>>a;
        ans+=1/a;
    }
    cout<<1/ans<<endl;
}   

int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
   // int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}


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

#define repu(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a)    for(int i=0;i<a;i++)
#define ll long long
#define vi vector<int>
#define vll vector<ll>

using namespace std;

void calc(int x, vll &mx, vll &c, vi &p, int n, ll k)
{
    vi vis(n+1,0);
    vll val(n+1,0);
    int y=x;
    ll z=0;
    ll turn=1;
    while(vis[y]==0 && turn<=k)
    {
        vis[y]=turn;
        val[y]=z;
        z+=c[y];
        mx[x]=max(mx[x],z);
        y=p[y];
        turn++;
    }
    if(turn>k)
        return;
    ll nodes=turn-vis[y], left=k-turn+1, zz=left/nodes;
    // cout<<turn<<' '<<vis[y]<<endl;
    if(zz>0)
        zz--;
    z+=zz*(z-val[y]);
    left=left-zz*nodes;
    mx[x]=max(mx[x],z);
    while(left)
    {
        z+=c[y];
        y=p[y];
        mx[x]=max(mx[x],z);
        left--;
    }
    return;
}

int main() {
    int n;
    cin>>n;
    ll k;
    cin>>k;
    vi p(n+1);
    vector<ll> c(n+1), mx(n+1,0);
    repu(i,1,n)
        cin>>p[i];
    repu(i,1,n)
    {
        cin>>c[i];
        mx[i]=c[i];
    }
    ll ans=mx[1];
    repu(i,1,n)
    {
        calc(i,mx,c,p,n,k);
        ans=max(mx[i],ans);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
int main(){
    double a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << fixed << setprecision(10);
    cout << sqrt((c-a)*(c-a) + (d-b)*(d-b)) << endl;
    return 0;
}


Measured memory_bytes: 3292
#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[i];
  }
  int max = *max_element(A.begin(), A.end());
  int cnt = 0;
  int max_idx = 0;
  for (int i=0; i<N; i++){
    if (A[i] == max){
      cnt++;
      max_idx = i;
    }
  }
  if (cnt > 1){
    for (int i=0; i<N; i++){
      cout << max << endl;
    }
  } else{
    A[max_idx] = 0;
    int max_next = *max_element(A.begin(), A.end());
    for (int i=0; i<N; i++){
      if (i == max_idx){
        cout << max_next << endl;
      } else{
        cout << max << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 2432
#include <stdio.h>
#include <limits.h>
#define N 100
#define WHITE 0
#define BLACK 1
#define NIL -1

int main(void){

  int i,j,k,n,w,r=0,mincost;
  int G[N][N],d[N],pi[N],color[N];

  scanf("%d",&n);
    
  for(i=0;i<n;i++){
    d[i] = INT_MAX;
    pi[i] = NIL;
    color[i] = WHITE;
    for(j=0;j<n;j++){
      scanf("%d",&G[i][j]);
    }
  }
  d[0] = 0;

  while(1){
    mincost = INT_MAX;
    for(i=0;i<n;i++){
      if(color[i] != BLACK && d[i] < mincost){
	mincost = d[i];
	j = i;
      }
    }
    if(mincost == INT_MAX){
      break;
    }
    for(i=0;i<n;i++){
      if(G[j][i] != -1 ){
	if(color[i] != BLACK && G[j][i] < d[i]){
	  pi[i] = j;
	  d[i] = G[j][i];
	}
      }
    }
    color[j] = BLACK;
  }
  for(i=0;i<n;i++){
    r += d[i];
  }
  printf("%d\n",r);
  return 0;
}

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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int,string> Pis;

int main(){
  int n;
  cin>>n;
  int a[n];
  REP(i,n){
    cin>>a[i];
    if(a[i]%2==0){
      if(a[i]%3!=0&&a[i]%5!=0){
        cout<<"DENIED"<<endl;
        return 0;
      }
    }
  }
  cout<<"APPROVED"<<endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
L = {}
R = {}
ans = 0
for i in range(N):
  t = i + 1 + A[i]
  if t in L:
    L[t] += 1
  else:
    L[t] = 1
  t = i + 1 - A[i]
  if t > 0:
    if t in R:
      R[t] += 1
    else:
      R[t] = 1
for i in R:
  if i in L:
    ans += R[i] * L[i]
print(ans)

Measured memory_bytes: 41876
#include <bits/stdc++.h>
using namespace std;
using LL  = long long;
using VI  = vector<LL>;
using VVI = vector<VI>;
using VB  = vector<bool>;
using VS  = vector<string>;
using PII = pair<LL, LL>;
using VP  = vector<PII>;
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first < y.first;});
#define FRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first > y.first;});
#define SSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second < y.second;});
#define SRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second > y.second;});
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define $(x) {cout << #x << " = " << (x) << endl;}


int main() {
    LL N;
    cin >> N;
    VI h(N + 1);
    h[0] = LLONG_MAX;
    REP(i, N) {
        cin >> h[i + 1];
    }

    VI dp(N + 1);
    FOR(i, 2, N + 1) {
        dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]));
    }

    cout << dp[N] << endl;
	
    return 0;
}


Measured memory_bytes: 1792
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

K,A,B = IL()

cnt = 1
if B - A >= 2:
  cnt += A-1
  K -= A-1
  if K%2 == 0:
    cnt += (B-A)*K//2
  else:
    cnt += (B-A)*(K//2) +1
else:
  cnt += K

print(cnt)

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

int main(){
    int N,M,ma=0,mi=10000000;
    cin>>N>>M;
    vector<int> l(M),r(M);
    rep(i,M){
        cin >>l[i]>>r[i];
        ma = max(ma,l[i]);
        mi = min(mi,r[i]);
    }
    if(ma<=mi){
        cout<<mi-ma+1<<endl;
    }else{
        cout<<"0";
    }
}

Measured memory_bytes: 1024
import java.util.Scanner;

class Dice{
	public int Top;
	public int Front;
	public int Right;
	public int left;
	public int Back;
	public int Bottom;

	public void W() {
		int Topch = Top;
		int leftch = left;
		Top = Right;
		Right = Bottom;
		left = Topch;
		Bottom = leftch;
	}

	public void E() {
		int Topch = Top;
		int Rightch = Right;
		Top = left;
		Right = Topch;
		left = Bottom;
		Bottom = Rightch;
	}

	public void S() {
		int Topch = Top;
		int Frontch = Front;
		Top = Back;
		Front = Topch;
		Back = Bottom;
		Bottom = Frontch;
	}

	public void N() {
		int Topch = Top;
		int Backch = Back;
		Top = Front;
		Front = Bottom;
		Back = Topch;
		Bottom = Backch;
	}

}

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int i = 0, j = 0;
		Dice a[];
		int f=0;
		int n = sc.nextInt();
		a = new Dice[n];
		for (i = 0; i < n; i++)
			a[i] = new Dice();

		for (i = 0; i < n; i++) {
			a[i].Top = sc.nextInt();
			a[i].Front = sc.nextInt();
			a[i].Right = sc.nextInt();
			a[i].left = sc.nextInt();
			a[i].Back = sc.nextInt();
			a[i].Bottom = sc.nextInt();
		}

		for (i = 0; i < n - 1; i++) {
			for (j = i + 1; j < n; j++) {
				String str = "";
				int test1, test2;
				test1 = a[i].Top;
				test2 = a[i].Front;

				if (test1 == a[j].Front) {
					str = str + "N";
				} else if (test1 == a[j].Right) {
					str = str + "W";
				} else if (test1 == a[j].left) {
					str = str + "E";
				} else if (test1 == a[j].Back) {
					str = str + "S";
				} else if (test1 == a[j].Bottom) {
					str = str + "NN";
				} else if (test1 == a[j].Top) {
					str = "";
				} else {
				}

				char data[] = new char[str.length()];
				data = str.toCharArray();
				for (int t = 0; t < str.length(); t++) {
					switch (data[t]) {
					case 'W':
						a[j].W();
						break;
					case 'S':
						a[j].S();
						break;
					case 'N':
						a[j].N();
						break;
					case 'E':
						a[j].E();
						break;
					default:
						break;
					}
				}
				if (test2 == a[j].Right) {
					str = "WSE";
				} else if (test2 == a[j].left) {
					str = "ESW";
				} else if (test2 == a[j].Back) {
					str = "SSEE";
				} else if (test2 == a[j].Front) {
					str = "";
				} else {
				}
				data = str.toCharArray();
				for (int t = 0; t < str.length(); t++) {
					switch (data[t]) {
					case 'W':
						a[j].W();
						break;
					case 'S':
						a[j].S();
						break;
					case 'N':
						a[j].N();
						break;
					case 'E':
						a[j].E();
						break;
					default:
						break;
					}
				}
				if (test(a[i],a[j])) {
					//System.out.println("No");
					f=1;
					break;
				}
			}
			if (f==1)
				break;
		}
		if (f==0)System.out.println("Yes");
		else System.out.println("No");
		sc.close();
	}
	public static Boolean test(Dice a,Dice b) {
		if(a.Top==b.Top&&a.Front==b.Front&&a.Right==b.Right&&a.left==b.left&&a.Back==b.Back&&a.Bottom==b.Bottom) {
			return true;
		}else {
			return false;
		}

	}


}




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

int main(){
    int N;
    cin>>N;
    vector<int> A(N);
    long long ans = 0;

    for(int i=0; i<N; i++) cin>>A[i];

    for(int left = 0; left < N; ){
        int right = left;
        long long sum = 0;

        while(A[right] != 0 && right < N){
            sum += A[right];
            right++;
        }

        ans += sum /= 2;
        left = right+1;
    }

    cout<<ans<<endl;

    return 0;
}

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

int main(void){
    int A,B,cnt;
    cin >> A >> B;
    for(int i = A; i <= B;i++){
        int w,a,s,d;
        w = i % 10;//一の位
        a = (i / 10000) % 10;//万の位
        s = (i / 1000) % 10; //千の位
        d = (i / 10) % 10;//十の位
        if(a == w && s == d)
            cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LINE 8
#define st 1
#define YOKO 17
int main(){
    long long A,B;
    char OP;
    cin>>A>>OP>>B;
    if(OP=='+'){
        cout<<A+B;
    }else{
        cout<<A-B;
    }
    return 0;
}


Measured memory_bytes: 256