akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	vector<Int> a(3);
	for (Int i = 0; i < 3; i++) {
		cin >> a[i];
	}

	Int ans = INF;
	Int temp;
	do {
		temp = abs(a[1] - a[0]) + abs(a[2] - a[1]);
		ans = min(ans, temp);
	} while (next_permutation(a.begin(),a.end()));

	cout << ans << "\n";
}


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



signed main() {
	
	
	int n,k;
	cin >> n >> k;
	int st[n];
	map<int,int> mp;
	for(int i=0;i<n;i++){
		cin >> st[i];
		mp[st[i]]=1;
	}
	sort(st,st+n);
	int dp[100010];
	dp[0]=0;
	for(int i=1;i<=k;i++){
		if(mp[i]==1){
			dp[i]=1;
		}
		else if(i<st[0]){
			dp[i]=2;
		}
		else if(i-st[0]<st[0]){
			dp[i]=1;
		}
		else{
			dp[i]=2;
			for(int j=0;j<n;j++){
				if(i>st[j]){
					if(dp[i-st[j]]==2){
						dp[i]=1;
						break;
					}
				}
			}
		}
	}
	if(dp[k]==1){
		cout << "First";
	}
	else{
		cout << "Second";
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 7296
#include<cstdio>
#include<algorithm>
using namespace std;

typedef long long ll;
const int Maxn=1e5;

int N,H,W;
struct Edge {
	int u,v,val;
};
bool operator < (Edge lhs,Edge rhs) {return lhs.val<rhs.val;}
Edge A[Maxn+5];

int fa[Maxn*2+5],siz[Maxn*2+5],cnt[Maxn*2+5];
void init() {
	for(int i=1;i<=Maxn*2;i++)
		fa[i]=i,siz[i]=1,cnt[i]=0;
}
int find(int x) {
	if(fa[x]==x)return fa[x];
	return fa[x]=find(fa[x]);
}

int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	scanf("%d %d %d",&N,&H,&W);
	for(int i=1;i<=N;i++) {
		scanf("%d %d %d",&A[i].u,&A[i].v,&A[i].val);
		A[i].v+=H;
	}
	sort(A+1,A+N+1);
	reverse(A+1,A+N+1);
	init();
	ll ans=0;
	for(int i=1;i<=N;i++) {
		int v1=find(A[i].u),v2=find(A[i].v);
		if(v1==v2) {
			if(siz[v1]==cnt[v1])continue;
			ans+=A[i].val,cnt[v1]++;
		} else {
			if(siz[v1]+siz[v2]<cnt[v1]+cnt[v2]+1)
				continue;
			else {
				fa[v2]=v1;
				siz[v1]+=siz[v2],cnt[v1]+=cnt[v2]+1;
				siz[v2]=cnt[v2]=0;
				ans+=A[i].val;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 2e5 + 123;
int n, a[N];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	ll res = 0;
	int j = 1, cur = 0;
	for (int i = 1; i <= n; i++) {
		cur ^= a[i - 1];
		while (j <= n && (a[j] & cur) == 0)
			cur ^= a[j], j++;
		res += j - i;
	}
	cout << res;
}


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

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

  vector<int> num(4);
  for(int i=0;i<4;i++) {
      if(N.at(i)=='0') num.at(i)=0;
      if(N.at(i)=='1') num.at(i)=1;
      if(N.at(i)=='2') num.at(i)=2;  
      if(N.at(i)=='3') num.at(i)=3;  
      if(N.at(i)=='4') num.at(i)=4;  
      if(N.at(i)=='5') num.at(i)=5;  
      if(N.at(i)=='6') num.at(i)=6;  
      if(N.at(i)=='7') num.at(i)=7;  
      if(N.at(i)=='8') num.at(i)=8;  
      if(N.at(i)=='9') num.at(i)=9;  
  }

  
  if(num.at(0)+num.at(1)+num.at(2)+num.at(3)==7) {
      cout << num.at(0) << "+" << num.at(1) << "+" << num.at(2) << "+" << num.at(3) << "=7" << endl;
      return 0;
  }
  if(num.at(0)-num.at(1)+num.at(2)+num.at(3)==7) {
      cout << num.at(0) << "-" << num.at(1) << "+" << num.at(2) << "+" << num.at(3) << "=7" << endl;
      return 0;
  }
  if(num.at(0)+num.at(1)-num.at(2)+num.at(3)==7) {
      cout << num.at(0) << "+" << num.at(1) << "-" << num.at(2) << "+" << num.at(3) << "=7" << endl;
      return 0;
  }
  if(num.at(0)-num.at(1)-num.at(2)+num.at(3)==7) {
      cout << num.at(0) << "-" << num.at(1) << "-" << num.at(2) << "+" << num.at(3) << "=7" << endl;
      return 0;
  }
  if(num.at(0)+num.at(1)+num.at(2)-num.at(3)==7) {
      cout << num.at(0) << "+" << num.at(1) << "+" << num.at(2) << "-" << num.at(3) << "=7" << endl;
      return 0;
  }
  if(num.at(0)-num.at(1)+num.at(2)-num.at(3)==7) {
      cout << num.at(0) << "-" << num.at(1) << "+" << num.at(2) << "-" << num.at(3) << "=7" << endl;
      return 0;
  }
  if(num.at(0)+num.at(1)-num.at(2)-num.at(3)==7) {
      cout << num.at(0) << "+" << num.at(1) << "-" << num.at(2) << "-" << num.at(3) << "=7" << endl;
      return 0;
  }
  if(num.at(0)-num.at(1)-num.at(2)-num.at(3)==7) {
      cout << num.at(0) << "-" << num.at(1) << "-" << num.at(2) << "-" << num.at(3) << "=7" << endl;
  }
  
}

Measured memory_bytes: 256
from collections import Counter

n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]

mc_s = Counter(s).most_common()
mc_t = Counter(t).most_common()

ans = []
for i in mc_s:
    for j in mc_t:
        if i[0] == j[0]:
            ans.append(i[1] - j[1])

ans = [0] * len(mc_s)
for i in range(len(mc_s)):
    ans[i] = mc_s[i][1]
    for j in range(len(mc_t)):
        if mc_s[i][0] == mc_t[j][0]:
            ans[i] = min(ans[i], mc_s[i][1] - mc_t[j][1])

ans.sort(reverse=True)
print(max(0,ans[0]))


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

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

    int W, H;
    while (cin >> W >> H, W || H) {
        vector<vector<int>> S(H, vector<int>(W));
        vector<PII> goals;

        int d[100][100][2] = {};
        fill(d[0][0], d[0][0] + 100 * 100 * 2, INF);

        rep(h, H) rep(w, W) {
            char T; cin >> T;
            if (T == 'S') {
                S[h][w] = 0;
                rep(i, 2) d[h][w][i] = 0;
            } else if (T == 'T') {
                S[h][w] = 0;
                goals.emplace_back(h, w);
            } else if (T == 'X') {
                S[h][w] = -1;
            } else {
                S[h][w] = T - '0';
            }
        }

        bool update = true;
        while (update) {
            update = false;
            rep(y, H) rep(x, W) rep(leg, 2) {
                if (d[y][x][leg] != INF) {
                    REP(ny, y-3, y+4) REP(nx, x-3, x+4) {
                        if (!in_range(nx, ny, W, H) || S[ny][nx] < 0 || abs(nx - x) + abs(ny - y) > 3) continue;
                        if ((leg == 0 && x < nx) || (leg == 1 && x > nx)) {
                            int nleg = 1 - leg;
                            if (d[ny][nx][nleg] > d[y][x][leg] + S[ny][nx]) {
                                update = true;

#ifdef DEBUG
                                cerr << "update: (x, y, leg) = (" << x << ", " << y << ", " << leg << ")" << endl;
                                cerr << d[ny][nx][nleg] << " -> " << d[y][x][leg] + S[ny][nx] << endl;
#endif

                                d[ny][nx][nleg] = d[y][x][leg] + S[ny][nx];

                            }
                        }
                    }
                }
            }
        }

        int ans = INF;
        for (auto g : goals) {
            rep(leg, 2) ans = min(ans, d[g.first][g.second][leg]);
        }

        cout << (ans == INF ? -1 : ans) << endl;
    }
}

Measured memory_bytes: 3216
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
 
using namespace std;
typedef long long LL;

const int MAX = 100010;
const int MOD = 1000000007;

LL mod_pow(LL x,LL n){
    LL ret = 1;

    while(n){
        if(n & 1)ret = ret * x % MOD;
        x = x * x % MOD;
        n /= 2;
    }

    return ret;
}

LL inv(LL n){
    return mod_pow(n,MOD - 2);
}

LL fact(LL n){
    LL ret = 1;
    for(int i = 1;i <= n;i++){
        ret = ret * i % MOD;
    }
    return ret;
}

int main(){
    LL N;
    LL A[MAX];
    LL sum[MAX] = {0};
    LL ans = 0;

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

    for(int i = 1;i <= N;i++){
        sum[i] = (sum[i-1] + inv(i)) % MOD;
    }

    for(int i = 0;i < N;i++){
        ans += A[i] * (sum[i + 1] + sum[N - i] - sum[1]) % MOD;
    }

    cout << ans % MOD * fact(N) % MOD << endl;

    return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> i_i;

int main(){

    int H,W,Ch,Cw,Dh,Dw;
    cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
    vector<string> S(H);
    for(int i=0;i<H;i++){
        cin >> S[i];
    }

    int nowcost;
    int dh_A[4] = {0,-1,0,1};
    int dw_A[4] = {1,0,-1,0};
    int dh_B[20] = {2,2,2,2,2,1,1,1,1,0,0,-1,-1,-1,-1,-2,-2,-2,-2,-2};
    int dw_B[20] = {-2,-1,0,1,2,-2,-1,1,2,-2,2,-2,-1,1,2,-2,-1,0,1,2};
    deque<i_i> deq;
    vector<vector<int>> cost(H,vector<int>(W,-1));
    cost[Ch-1][Cw-1] = 0;
    deq.push_back(make_pair(Ch-1,Cw-1));
    while(!deq.empty()){
        int h,w;
        i_i now = deq.front();
        deq.pop_front();
        nowcost = cost[now.first][now.second];
        for(int i=0;i<4;i++){ //move A
            h = now.first + dh_A[i];
            w = now.second + dw_A[i];
            if(h >= 0 && h < H && w >= 0 && w < W){
                if(S[h][w] == '.' && (cost[h][w] < 0 || cost[h][w] > nowcost)){
                    deq.push_front(make_pair(h,w));
                    cost[h][w] = nowcost;
                }
            }
        }
        for(int i=0;i<20;i++){ //move B
            h = now.first + dh_B[i];
            w = now.second + dw_B[i];
            if(h >= 0 && h < H && w >= 0 && w < W){
                if(S[h][w] == '.' && (cost[h][w] < 0 || cost[h][w] > nowcost + 1)){
                    deq.push_back(make_pair(h,w));
                    cost[h][w] = nowcost + 1;
                }
            }
        }
    }

    cout << cost[Dh-1][Dw-1];
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int[]> table = new List<int[]>();

            string input;

            while (!string.IsNullOrEmpty(input = Console.ReadLine()))
            {
                int[] temp = Array.ConvertAll(input.Split(','), int.Parse);
                table.Add(temp);
            }

            int m = table.Count / 2;

            for (int i = 1; i <= m; i++)
            {
                for (int j = 0; j < table[i].Length; j++)
                {
                    if (j == 0)
                    {
                        table[i][j] += table[i - 1][j];
                    }
                    else if (j == table[i].Length - 1)
                    {
                        table[i][j] += table[i - 1][j - 1];
                    }
                    else
                    {
                        int a = table[i][j] + table[i - 1][j - 1];
                        int b = table[i][j] + table[i - 1][j];
                        table[i][j] = Math.Max(a, b);
                    }
                }
            }

            for (int i = table.Count - 2; i >= m; i--)
            {
                for (int j = 0; j < table[i].Length; j++)
                {
                    if (j == 0)
                    {
                        table[i][j] += table[i + 1][j];
                    }
                    else if (j == table[i].Length - 1)
                    {
                        table[i][j] += table[i + 1][j - 1];
                    }
                    else
                    {
                        int a = table[i][j] + table[i + 1][j - 1];
                        int b = table[i][j] + table[i + 1][j];
                        table[i][j] = Math.Max(a, b);
                    }
                }
            }
            Console.WriteLine(table[m].Max());
        }
    }
}

Measured memory_bytes: 9680
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<std::string, std::string>;

constexpr ll INF = 1ll<<60;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
std::string S;
std::map<P, ll> mp;
ll ans;

int main()
{
  std::cin >> N >> S;

  std::reverse( S.begin()+N, S.end() );

  rep( i, 1<<N )
  {
    std::string t[2];

    rep( j, N )
      t[i>>j&1] += S[j];

    ++mp[P( t[0], t[1] )];
  }

  rep( i, 1<<N )
  {
    std::string t[2];

    rep( j, N )
      t[i>>j&1] += S[N+j];

    ans += mp[P( t[0], t[1] )];
  }

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

  return 0;
}

Measured memory_bytes: 49408
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int N,Q;
  cin>>N>>Q;
  ll A[N+1]={},sum[N+1]={},evenSum[N+1]={};
  for(int i=1;i<=N;i++){
    cin>>A[i];
    sum[i]=sum[i-1]+A[i];
    evenSum[i]=evenSum[i-1];
    if(i%2==N%2) evenSum[i]+=A[i];
  }
  ll X[Q+1]={};
  for(int i=0;i<Q;i++) cin>>X[i];

  ll ans[Q+1]={};
  for(int k=0;k<Q;k++){
    int ng=0,ok=N;
    while(ok-ng>1){
      int mid=(ng+ok)/2;
      if(A[mid]<X[k]) ng=mid;
      else{
        int taka=N-mid+1;
        int z=lower_bound(A,A+N+1,max(1ll,X[k]-(A[mid]-X[k])))-A;
        int ao=mid-z+1;
        if(taka>ao) ng=mid;
        else ok=mid;
      }
    }

    ll res=sum[N]-sum[ok-1];
    int front=N-(N-ok+1)*2;
    if(front>0) res+=evenSum[front];

    ans[k]=res;
  }

  for(int i=0;i<Q;i++) cout<<ans[i]<<endl;

  return 0;
}


Measured memory_bytes: 5632
n,a,b=map(int,input().split())
def digitsum(k):
    s=str(k)
    array=list(map(int,s))
    return sum(array)
c=1
ans=0
while n>=c:
    if digitsum(c)>=a and digitsum(c) <=b:
        ans+=c
    c+=1
print(ans)

Measured memory_bytes: 3060
#include <iostream>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

typedef long long ll;

int N;

int main(void) {
    scanf("%d", &N);

    while ( N >= 0) {
    	if (N % 4 == 0) {
    		puts("Yes");
    		return 0;
    	}

    	N -= 7;
    }

    puts("No");

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
using ll = long long;

int N;
ll a[16][16];
bool visited[1 << 16];
ll dp[1 << 16];

ll rec(int s) {
    if (visited[s]) return dp[s];

    visited[s] = true;
    dp[s] = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            if (((s >> i) & 1) & ((s >> j) & 1)) dp[s] += a[i][j];
        }
    }

    for (int t = 1; t < s; ++t) {
        if (t != (t & s)) continue;
        dp[s] = max(dp[s], rec(t) + rec(s ^ t));
    }

    return dp[s];
}

int main() {
    cin >> N;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            cin >> a[i][j];
        }
    }

    cout << rec((1 << N) - 1) << endl;
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <cstdio>
#include <queue>
#include <cmath>
#include <random>
#include <fstream>
#include <string>
#include <tuple>
#include <deque>
#include <set>
#include <map>
#include <stack>

#define REP(i, N) for(int i = 0; i< N; i++)
using namespace std;
#define ll long long
const int INF = 1 << 29;
const ll llINF = 10000000000000000;

const int MOD = 1000000007;

#define MAX_N 100100
typedef pair<int, int> P;
typedef pair<ll, ll> llP;

class UnionFindTree{
private:
    int par[MAX_N];
    int urank[MAX_N];
    int size[MAX_N];
public:
    int init(int n);
    int find(int x);
    int unite(int x, int y);
    int same(int x, int y);
    int parnum(int x){return par[x];}
    int ranknum(int x){return urank[x];}
    int sizenum(int x){return size[find(x)];}
};

int UnionFindTree::init(int n){
    REP(i, n){
        par[i] = i;
        urank[i] = 0;
        size[i] = 1;
    }
    return 0;
}

int UnionFindTree::find(int x){
    if(par[x] == x)return x;
    else return par[x] = find(par[x]);
}

int UnionFindTree::unite(int x, int y){
    x = find(x);
    y = find(y);
    
    if(x == y)return 0;
    if(urank[x] < urank[y]){
        par[x] = y;
        size[y] += size[x];
    }else{
        par[y] = x;
        size[x] += size[y];
        if(urank[x] == urank[y])urank[x] ++;
    }
    return 0;
}

int UnionFindTree::same(int x, int y){
    return find(x) == find(y);
}


int bit[100100], N;
int S[100100];
int sum(int i){
    int s = 0;
    while(i  > 0){
        s += bit[i];
        i -= i & -i;
    }
    return s;
}
void add(int i, int x){
    while(i <= N){
        bit[i] += x;
        i += i & -i;
    }
}
int a[100100];

int main(){
    cin >> N;
    if(N % 2 == 0){
        printf("%d\n", (N / 2) * (N / 2));
    }else{
        printf("%d\n", ((N - 1) / 2 ) * ((N + 1) / 2));
    }
}


Measured memory_bytes: 888
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = null;
		try {
			sc = new Scanner(System.in);
			//?????°???????????????
			int lineNum = sc.nextInt();

			//???????????????
			int[] pliceList = new int[lineNum];
			for (int i = 0; i < pliceList.length; i++) {
				pliceList[i] = sc.nextInt();
			}

			//???????¨????(roop)
			int profit = pliceList[1] - pliceList[0];
			int minplice = pliceList[0];

			for (int i = 1; i < pliceList.length; i++) {
				//?????§???????????´??°
				profit = Math.max(pliceList[i] - minplice, profit);
				//????°????????±???????
				minplice = Math.min(pliceList[i], minplice);

			}
			//????????????
			System.out.println(profit);
		}catch (Exception e) {
			System.out.println(e);
		} finally {
			if (sc != null) {
				sc.close();
			}
		}

	}

}

Measured memory_bytes: 101604
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
    string s;
    cin>>s;
    int ans=0;
    for(int i=0; i<4; i++){
        if(s[i]=='+'){
            ans++;
        }else{
            ans--;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <chrono> 
 
using namespace std;
using namespace std::chrono; 
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
#define gcd(a,b) __gcd(a,b)
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vc vector<char>
#define pb(n) push_back(n)
#define pp pop_back()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define type(a) typeid(a).name();
#define print(arr) cout << "[" ;for(unsigned int i=0;i<(unsigned int) arr.size();i++){ (i==arr.size()-1)?cout << arr[i]:cout << arr[i] << ",";}cout << "]" << endl
#define Arr(arr,l) cout << "[" ;for(unsigned int i=0;i<(unsigned int) l;i++){ (i==l-1)?cout << arr[i]:cout << arr[i] << ",";}cout << "]" << endl
#define console(arr) cout << "["<<endl; for(ll i=0;i<(ll)arr.size();++i){cout << " [";for(ll j=0;j<(ll)arr[i].size();++j){(j==(int)arr[i].size()-1)?cout << arr[i][j]:cout << arr[i][j] << ",";}cout << "]"<<endl;} cout << "]"<<endl
#define starting() auto start = high_resolution_clock::now()
#define ending() auto stop = high_resolution_clock::now();auto duration = duration_cast<microseconds>(stop - start);cout << endl << endl << "Execution Time : "<<duration.count()/1000 << " ms" << endl
 
template <typename T1,typename T2>
void mapped(map<T1,T2>m){for(auto ite=m.begin();ite!=m.end();++ite){cout << "'" << ite->first << "'"<<" : "<<ite->second <<endl;}}
 
template <typename T1 , typename T2>
void mappedArr(map<T1,vector<T2>>m){for(auto ity=m.begin();ity!=m.end();++ity){cout << "'"<< ity->first <<"'"<<" : "<<"[";
for(int i=0;i<(int)ity->second.size();++i){(i==(int)ity->second.size()-1)?cout << ity->second[i]:cout << ity->second[i] << ",";}cout << "]"<<endl;}}
 
string int_to_string(int x){ stringstream ss; ss << x; string ni = ss.str(); return ni;}
int char_to_int(char c){ int n = (int)c - 48; return n; }
int string_to_int(string x){ int n; stringstream s(x); s >> n; return n; }
char upperCase(char a){int d = (int)a - 97 + 65;char c = (char)d;return c;} 
char lowerCase(char a){int d = (int)a - 65 + 97;char c = (char)d;return c;}  
bool isInt(char a){int d = (int)a - 48;if(d>=0 && d<=9){return true;}return false;}
//string char_to_string(char a){string d = (1,a);return d;}
 
template <typename T1,typename T2>
void ArrPair(vector<pair<T1,T2>>vp){for(int i=0;i<(int)vp.size();++i){
cout << "(" << vp[i].first << "," << vp[i].second << ")"<<endl ;}}
 
const int MOD = 1e9 + 7;
const ll INF = 1e18L + 5;
 
//unordered_map<int,int> um;
//unordered_set<int> us;
//set<int> s;
// v.front() gives the first element of vector 
// v.back()  gives the last element of vector
// insert erase substr

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

//bool f(vector<ll> a,vector<ll> b){
//	return a[1] > b[1];
//}

//swap(a,b);
 
int main(){
   int n;
   cin >> n;
   int cnt = n/100;
   int w = n%100;
   int e = w/5;
   int x = w%5;
   if(x!=0){
	   e++;
   }
   if(e<=cnt){
	   cout << 1;
   }else{
	   cout << 0;
   }
   
 return 0;
}








Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int h,a,b,i,cnt;
	cnt=0;
	cin>>h>>a>>b;
	for(i=a;i<=b;i++){
		if(h%i==0) cnt=cnt+1;
	}
	cout<<cnt<<endl;	
	return 0;
}



Measured memory_bytes: 3092
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>
#include<random>



#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
using namespace std;
int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 500050;



set<int>st;
vector<int>idx;
int ans[100010],cum[100010];
vector<int>v;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N; cin >> N;
	v.pb(0);
	REP(i, N) {
		int a; cin >> a;
		v.pb(a);
	}
	int mx = -1;
	REP(i, N+1) {
		if (v[i] > mx) {
			st.insert(v[i]);
			idx.pb(i);
			mx = v[i];
		}
	}
	VSORT(v);
	auto itr = st.find(mx);
	vector<int>res;
	bool debug = 0;
	REPR(i, N) {
		cum[i] = cum[i + 1] + v[i];
		if(debug)printf("*itr:%lld i:%lld cum[i]:%lld v[i]%lld\n",*itr, i, cum[i], v[i]);
		if (v[i] == *itr) {
			res.pb(cum[i] - v[i] * (N - i+1));
			itr--;
		}
	}
	VREVERSE(res);
	
	if (debug) {
		REP(i, res.size()) {
			pe(res[i]);
		}
		cout << endl;
	}
	REP(i, res.size() - 1) {
		res[i] -= res[i + 1];
		ans[idx[i+1]] = res[i];
	}
	FOR(i, 1, N + 1) {
		print(ans[i]);
	}
}


Measured memory_bytes: 9716
#include <bits/stdc++.h>
  
using namespace std;
  
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))
  
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;
  
#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))
  
int F()
{
    char ch;
    int x, a;
    while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
    if (ch == '-') ch = getchar(), a = -1;
    else a = 1;
    x = ch - '0';
    while (ch = getchar(), ch >= '0' && ch <= '9')
        x = (x << 1) + (x << 3) + ch - '0';
    return a * x;
}
  
int n, m, a[110];
  
bool comp(const int &i, const int &j)
{
    return (i & 1) > (j & 1);
}
  
int b[110], ans;
  
int main()
{
    gii(n, m);
    int cnt = 0;
    for (int i = 1; i <= m; ++i) gi(a[i]);
    for (int i = 1; i <= m; ++i)
        if (a[i] & 1) ++cnt;
    if (cnt > 2)
    {
        puts("Impossible");
        return 0;
    }
    sort(a + 1, a + m + 1, comp);
    if (a[2] & 1) swap(a[2], a[m]);
    for (int i = 1; i <= m; ++i)
        printf("%d ", a[i]);
    puts("");
    if (m == 1)
    {
        if (a[1] - 1) printf("2\n%d %d \n", 1, a[1] - 1);
        else printf("1\n%d \n", 1);
        return 0;
    }
    if (a[1] - 1) b[++ans] = a[1] - 1;
    for (int i = 2; i < m; ++i)
        b[++ans] = a[i];
    b[++ans] = a[m] + 1;
    printf("%d\n", ans);
    for (int i = 1; i <= ans; ++i)
        printf("%d ", b[i]);
    puts("");
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
#define ll long long
#define cases ll t;cin>>t;while(t--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)


int main(){
    fast;
    ll i,j,n,m,r,u,v,k,x,y;
    string s,ans="ABC";
    cin>>s;
    if(s=="ABC") ans="ARC";
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <vector>
#include <numeric>
using namespace std;

int main() {
    int n, m;
    while(scanf("%d%d", &n, &m), n|m) {
        int tarou_ch=0, hanako_ch=0, min=201;
        int input;
        vector<int> tarou, hanako;
        for (int i=0; i<n; i++) {
            scanf("%d", &input);
            tarou.push_back(input);
        }
        for (int i=0; i<m; i++) {
            scanf("%d", &input);
            hanako.push_back(input);
        }
        vector<int>::iterator v1=tarou.begin(), v2=hanako.begin();
        int tarou_sum = accumulate( tarou.begin(), tarou.end(), 0);
        int hanako_sum = accumulate( hanako.begin(), hanako.end(), 0);
        for(int i=0; i<n; i++) {
            for(int j=0; j<m; j++) {
                // // printf("test:%d %d\n", tarou_sum-*v1+*v2, hanako_sum+*v1-*v2);
                // printf("test:%d %d\n", *v1, *v2);
                if ((tarou_sum-*v1+*v2) == (hanako_sum+*v1-*v2)) {
                    if (*v1+*v2<min) {
                        min=*v1+*v2; tarou_ch=*v1; hanako_ch=*v2;
                    }
                }
                v2++;
            }
            v1++;
            v2=hanako.begin();
        }
        if(min == 201) { printf("-1\n");}
        else printf("%d %d\n", tarou_ch, hanako_ch);
    }
}

Measured memory_bytes: 1216
N,X=map(int,input().split())
S=list(map(int,input().split()))

kakunin=10**10

if N==1:
    if X<S[0]:
        print(S[0]-X)
        exit()
    else:
        print(X-S[0])
        exit()

for i in range(N):
    S[i]=S[i]-X
    if abs(S[i])<kakunin:
        kakunin=abs(S[i])
        
ans=1
okflag=True
for i in range(2,kakunin+1):
    okflag=True
    for j in range(N):
        if S[j]%i!=0:
            okflag=False
           
            break
    if okflag==True:
        ans=i
print(ans)

Measured memory_bytes: 62576
#define SUBMIT

#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef SUBMIT
    auto& in = cin;
#else
    stringstream in(R"(aaaaaaaaab aaaaaaaaaa aaaaaaaaab
)");
#endif
    string a, b, c;
    in >> a >> b >> c;
    if (a[a.length() - 1] == b[0] && b[b.length() - 1] == c[0])
        cout << "YES";
    else
        cout << "NO";
    return 0;
}

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

typedef long long ll ;
using namespace std;

void solve(){
    int n;
    cin >> n;

    if (n % 10 == 3) cout << "bon" << endl;
    else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
}

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

    solve();

    return 0;
}


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

bool smaller(const int left, const int right) {
	return left>right;
}

int main()
{
	vector<int> num;
	for (int i=0; i<5; i++) {
		int tmp;
		cin >> tmp;
		num.push_back(tmp);
	}
	sort(num.begin(),num.end(),smaller);
	for (int i=0; i<4; i++) {
		cout << num[i] << ' ';
	}
	cout << num[4] << endl;
	return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
#define register rg
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
using namespace std;
typedef long long ll;
char
 a[1000001];
int main() {
	//file("a");
	int n,js=0,bj=0;
	cin>>n;
	scanf("%s",a);
	for(int i=0;i<n;i++)
	if(a[i]=='R')
	js++;
	else bj++;
	if(js>bj) cout<<"Yes";
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

class Program
{
    void Run()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int d = sc.NextInt();
        int[,] map = new int[n, d];
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < d; j++)
            {
                map[i, j] = sc.NextInt();
            }
        }
        int res = 0;
        for (int i = 0; i < n - 1; i++)
        {
            for (int j = i + 1; j < n; j++)
            {
                int sum = 0;
                for (int k = 0; k < d; k++)
                {
                    int dd = map[i, k] - map[j, k];
                    sum += dd * dd;
                }
                double s = Math.Sqrt(sum);
                if ((int)s == s) res++;
            }
        }
        Console.WriteLine(res);
    }

    static void Main(string[] args)
    {
        new Program().Run();
    }

    static long Gcd(long a, long b)

    {
        if (a < b) return Gcd(b, a);
        if (b == 0) return a;
        return Gcd(b, a % b);
    }

    static long Lcm(long a, long b)
    {
        long d = Gcd(a, b);
        return a / d * b;
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <queue>
using namespace std;

#define PI 3.14159265358979323846264338327950L

int res = 0;

int mindistance(int a, int b)
{
    if (a < b)
        return a;
    else
        return b;
}

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

    int N, K;
    int boll[110];
    cin >> N >> K;
    for (int i = 0; i < N; i++)
    {
        cin >> boll[i];
    }
    for (int i = 0; i < N; i++)
    {
        int d = mindistance(abs(boll[i]), abs(K - boll[i])) * 2;
        res += d;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int n=s.size();
    vector<char> v;
    for(int i=0;i<n;i++){
        switch(s[i]){
            case '0':
            v.push_back('0');
            break;
            case '1':
            v.push_back('1');
            break;
            case 'B':
            if(v.empty()){break;}
            v.pop_back();
        }
    }
    for(auto&& i:v){
        cout<<i;
    }
    puts("");
}

Measured memory_bytes: 256
import Control.Applicative
import Data.List
import Data.Array

partialSum :: (Num a) => [a] -> Int -> Int -> a
partialSum xs = \start -> \end -> (cumulative !end) - (cumulative !start)
    where cumulative = listArray (0, length xs) (scanl (+) 0 xs)

solve :: Int -> String -> Int
solve n s = minimum (map numNotFaceLeader [0..n-1])
    where indicatorW = fmap (\x -> if x == 'W' then 1 else 0) s
          indicatorE = fmap (\x -> if x == 'E' then 1 else 0) s
          partialSumW = partialSum indicatorW
          partialSumE = partialSum indicatorE
          numNotFaceLeader :: Int -> Int
          numNotFaceLeader leader = (partialSumW 0 leader) + (partialSumE (leader + 1) n)

main :: IO ()
main = do
    n <- readLn
    s <- getLine
    putStrLn $ show (solve n s)


Measured memory_bytes: 100732
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int n, pre[2009], nxt[2009], val[2009]; string a, b;
int main() {
	cin >> a >> b; n = a.size();
	if (b.find('1') == string::npos) cout << (a == b ? 0 : -1) << endl;
	else {
		int ret = 1 << 30;
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < n; j++) {
				if (a[j] == '0') {
					nxt[j] = pre[j] = 0;
					continue;
				}
				for (int k = 0; k < n; k++) {
					if (b[(j + k) % n] == '1') {
						nxt[j] = k;
						break;
					}
				}
				for (int k = 0; k < n; k++) {
					if (b[(j - k + n) % n] == '1') {
						pre[j] = k;
						break;
					}
				}
			}
			for (int j = 0; j < n; j++) val[j] = 0;
			for (int j = 0; j < n; j++) {
				val[pre[j]] = max(val[pre[j]], nxt[j]);
			}
			for (int j = n - 1; j >= 0; j--) val[j] = max(val[j], val[j + 1]);
			for (int j = 0; j < n; j++) {
				int cnt = 0;
				for (int k = 0; k < n; k++) {
					if (a[k] != b[(j + k) % n]) cnt++;
				}
				for (int k = 0; k < n; k++) {
					ret = min(ret, cnt + j + max(val[k + 1] - j, 0) * 2 + k * 2);
				}
			}
			reverse(a.begin(), a.end());
			reverse(b.begin(), b.end());
		}
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 256
A,B,C,X,Y = map(int,input().split())

ans = 10**9+7

for i in range(max(X,Y)+1):
    AB = i*2
    money = max(0,A*(X-i))+max(0,B*(Y-i))+C*AB
    ans = min(ans,money)
    
print(ans)

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

typedef long long ll;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int N, K, Q;
int A[2010];

int main(){

    cin >> N >> K >> Q;
    for(int i = 0; i < N; i++) cin >> A[i];
    int ans = 2000000000;
    for(int i = 0; i < N; i++){
        int X = A[i];
        vector<vector<int> > seqs;

        // Xより小さいものはフィルタする
        for(int j = 0; j < N; j++){
            if(X > A[j]) continue;
            vector<int> seq;
            while(j < N && A[j] >= X){
                seq.push_back(A[j]);
                j++;
            }
            sort(seq.begin(), seq.end());
            if((int)seq.size() >= K)
                seqs.push_back(seq);
        }
        
        vector<int> indices(seqs.size(), 0);
        priority_queue<pii, vector<pii>, greater<pii> > pq;
        for(int j = 0; j < (int)seqs.size(); j++){
            int index = indices[j];
            int v = seqs[j][index];
            pq.push(pii(v, j));
        }
        int Y = -1;
        bool ok = true;
        for(int cnt = 0; cnt < Q; cnt++){
            if(pq.size() == 0){
                ok = false;
                break;
            }
            else{
                Y = pq.top().first;
                int seq_num = pq.top().second; 
                pq.pop();
                vector<int> &seq = seqs[seq_num];
                if((int)seq.size() - (indices[seq_num] + 1) >= K){
                    indices[seq_num]++;
                    pq.push(pii(seq[indices[seq_num]], seq_num));
                }
            }
        }
        
        if(ok){
            ans = min(ans, Y - X);
        }
    }

    cout << ans << endl;
    

    return 0;
}


Measured memory_bytes: 256
function main (s) {
	s=s.split("\n");
	var x,a,b;
	x=parseInt(s[0]);
	a=parseInt(s[1]);
	b=parseInt(s[2]);
	console.log((x-a)%b);
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
using namespace std;
struct C{
	int w,d;
	C(int w,int d):w(w),d(d){}
	bool operator<(const C &r)const{
		return w*d<r.w*r.d;
	}
};
int main(){
	int n,w,d,p,s;
	while(cin>>n>>w>>d,w){
		vector<C> c; c.pb(C(w,d));
		rep(i,n){
			cin>>p>>s;
			p--;
			w=c[p].w,d=c[p].d,s%=w+d; c.erase(c.begin()+p);
			if(s>w)c.pb(min(C(w,d-s+w),C(w,s-w))),c.pb(max(C(w,d-s+w),C(w,s-w)));
			else c.pb(min(C(s,d),C(w-s,d))),c.pb(max(C(s,d),C(w-s,d)));
		}
		sort(c.begin(),c.end());
		rep(i,n+1)cout<<c[i].w*c[i].d<<(i==n?"\n":" ");
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {

    public static class Edge {
        long cost;
        int from, to;

        public Edge(int from, int to, long cost) {
            this.from = from;
            this.to = to;
            this.cost = cost;
        }
    }

    public static class Node {
        int id;
        long value;

        public Node(int id, long value) {
            this.id = id;
            this.value = value;
        }
    }

    private static int n;
    private static long[] dist;
    private static List<List<Edge>> graph;

    private static Comparator<Node> comparator = new Comparator<Node>() {
        @Override
        public int compare(Node node1, Node node2) {
            return (node1.value - node2.value) > 0 ? 1 : -1;
        }
    };

    public static void addEdge(int from, int to, int cost) {
        graph.get(from).add(new Edge(from, to, cost));
    }

    public static void dijkstra(int start) {
        dist = new long[n];
        Arrays.fill(dist, 100010);
        dist[start] = 0;

        PriorityQueue<Node> pq = new PriorityQueue<>(2 * n, comparator);
        pq.offer(new Node(start, 0));

        boolean[] visited = new boolean[n];

        while (!pq.isEmpty()) {
            Node node = pq.poll();
            visited[node.id] = true;

            if (dist[node.id] < node.value) continue;

            List<Edge> edges = graph.get(node.id);
            for (int i = 0; i < edges.size(); ++i) {
                Edge edge = edges.get(i);

                if (visited[edge.to]) continue;;

                long newDist = dist[edge.from] + edge.cost;
                if (newDist < dist[edge.to]) {
                    dist[edge.to] = newDist;
                    pq.offer(new Node(edge.to, dist[edge.to]));
                }
            }
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        graph = new ArrayList<>(n);
        for (int i = 0; i < n; ++i) graph.add(new ArrayList<>());

        for (int i = 0; i < n; ++i) {
            int id = sc.nextInt();
            int degree = sc.nextInt();
            for (int j = 0; j < degree; ++j) {
                int v = sc.nextInt();
                int c = sc.nextInt();
                addEdge(id, v, c);
            }
        }

        dijkstra(0);

        for (int i = 0; i < n; ++i) {
            System.out.println(i + " " + dist[i]);
        }
    }
}


Measured memory_bytes: 40112
from collections import deque

n, m = map(int, input().split())
adj_list = [[] for _ in range(3 * n)]
for _ in range(m):
  u, v = map(int, input().split())
  adj_list[3 * u - 3].append(3 * v - 2)
  adj_list[3 * u - 2].append(3 * v - 1)
  adj_list[3 * u - 1].append(3 * v - 3)

s, t = map(int, input().split())
dist = [-1] * (3 * n)
queue = deque([3 * s - 3])
dist[3 * s - 3] = 0
while queue:
  vertex = queue.popleft()
  for next_vertex in adj_list[vertex]:
    if dist[next_vertex] != -1:
      continue
    dist[next_vertex] = dist[vertex] + 1
    queue.append(next_vertex)
t_distance = dist[3 * t - 3]
if t_distance == -1:
  print(-1)
else:
  print(t_distance // 3)

Measured memory_bytes: 60164
#include<bits/stdc++.h>
#define ll long long int 
#define double /*long*/ double
#define endl '\n'
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vppll vector<pll,pll>
#define mp make_pair
#define pb push_back
#define mapll map<ll,ll>
#define fir first
#define sec second
#define _cin ios_base::sync_with_stdio(0);  cin.tie(0);
#define fo(i,b) for(i=0;i<b;i++)
#define repa(i,a,b) for(i=a;i<b;i++)
#define repb(i,a,b) for(i=a;i>=b;i--)
#define all(x) (x).begin(), (x).end()
#define s(v) v.size()
const long long int MAX = (ll)(1e18+1);
const long long int MIN = (ll)(-1e18-1);
const long long int mod = (ll)(1e9+7);
using namespace std;

ll max(ll a,ll b,ll c) {return max(max(a, b), c);}
ll min(ll a,ll b,ll c) { return min(min(a, b), c);}
ll max(ll a,ll b) {return (a>b) ? a : b;}
ll min(ll a,ll b) {return (a<b) ? a : b;}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power_mod(ll a, ll n, ll mod_){ ll p=1; while(n){ if(n%2){ p=(p*a)%mod_;} n/=2; a=(a*a)%mod_;} return p%mod_;}                      
                          /*Code Begins*/
ll dp[100005][201][2]; //0->pehle wala chota

int main(){
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
    _cin;
    // cout << setprecision(15);
    ll mn = MAX, mx = MIN;
    ll n, m, t,  k, i, j,  sum=0,  prev, flag=0, cnt=0;
    ll x=0, y=0, fx, diff, tot=0, l , r;
    int TC=1;
    // cin >> TC;
while(TC--){
	cin >> n >> k >> m;
	string s;
	cin >> s;
	vll pehle(n), baad(n);
	ll max_so=0;
	fo(i,n){
		if(i-m-1>=0) pehle[i]=pehle[i-m-1]+1;
		else pehle[i]=1;
		if(s[i]=='x'){
			pehle[i] = max_so;
		}else{
			max_so = max(max_so , pehle[i]);
		}
	}
	max_so=0;
	repb(i,n-1,0){
		if(i+m+1<n) baad[i]=baad[i+m+1]+1;
		else baad[i]=1;
		if(s[i]=='x') baad[i] = max_so;
		else max_so = max(max_so , baad[i]);
		
	}
	queue<ll> q;
	fo(i,m+1){
		if(s[i]=='o' and pehle[i]+baad[i]>=k+1) q.push(i);
	}
	vll ans;
	fo(i,n){
		if(q.front()==i-m-1) q.pop();
		if(s[i]=='o' and pehle[i]+baad[i]==k+1 and s(q)==1) ans.pb(i+1);
		if(i+m+1<n and s[i+m+1]=='o' and pehle[i+m+1]+baad[i+m+1]>=k+1) q.push(i+m+1);
	}
	// fo(i,n) cout << pehle[i] << ' ';
	// cout << endl;
	// fo(i,n) cout << baad[i] << ' ';
	// cout << endl;
    for(auto x : ans) cout << x << endl;

}


    return 0;
}


Measured memory_bytes: 6536
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] s = sc.next().toCharArray();
        int c = 1;
        for (int i = 0 ; i < n - 1 ; i++) {
            if (s[i] != s[i + 1]) c++;
        }
        System.out.println(c);
    }

}


Measured memory_bytes: 26324
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        new Program().Calc();
    }

    Scanner cin;

    public Program() { }

    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void Calc()
    {
        cin = new Scanner();

        int a = cin.nextInt();
        int b = cin.nextInt();
        int c = cin.nextInt();
        int k = cin.nextInt();

        int ans = 0;

        if (k <= a)
        {
            ans = k;
        }
        else if (k <= a + b)
        {
            ans = a;
        }
        else
        {
            ans = a - (k - (a + b));
        }

        WriteLine(ans);
    }
}

public static class StringExtension
{
    public static char GetChar1(this string str, int indexOneBase)
    {
        return str[indexOneBase - 1];
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            ans += lower_bound(v.begin(), v.end(), v[i] + v[j]) - (v.begin() + j) - 1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628