akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

#define SIZE 320
#define NUM 320

typedef struct {
	int t, h;
	long long num;
} edge;

int main()
{
	int i, N, M, u, w, *adj[100001], deg[100001] = {}, q[100001] = {};
	long long *block[100001] = {};
	edge e[200001];
	scanf("%d %d", &N, &M);
	for (i = 0; i < N - 1; i++) {
		scanf("%d %d", &u, &w);
		e[i*2].t = u;
		e[i*2].h = w;
		e[i*2+1].t = w;
		e[i*2+1].h = u;
		e[i*2].num = -1;
		e[i*2+1].num = -1;
		deg[u]++;
		deg[w]++;
	}
	for (i = 1; i <= N; i++) {
		adj[i] = (int*)malloc(sizeof(int) * deg[i]);
		if (deg[i] > SIZE) block[i] = (long long*)malloc(sizeof(long long) * ((deg[i] + SIZE - 1) / SIZE));
	}
	for (i = 0; i < N - 1; i++) {
		u = e[i*2].t;
		w = e[i*2].h;
		adj[u][q[u]++] = i * 2;
		adj[w][q[w]++] = i * 2 + 1;
	}
	
	int par[100001] = {}, head, tail;
	long long dp[100001] = {};
	par[1] = 1;
	q[0] = 1;
	for (head = 0, tail = 1; head < tail; head++) {
		u = q[head];
		for (i = 0; i < deg[u]; i++) {
			w = e[adj[u][i]].h;
			if (par[w] == 0) {
				par[w] = u;
				q[tail++] = w;
			}
		}
	}
	for (head--; head >= 0; head--) {
		u = q[head];
		dp[u] = 1;
		for (i = 0; i < deg[u]; i++) {
			w = e[adj[u][i]].h;
			if (w == par[u]) continue;
			else {
				if (e[adj[u][i]].num == -1) e[adj[u][i]].num = dp[w];
				dp[u] = dp[u] * (e[adj[u][i]].num + 1) % M;
			}
		}
	}
	printf("%lld\n", dp[1]);
	
	int j, k;
	for (head = 0; head < tail; head++) {
		u = q[head];
		if (deg[u] > SIZE) {
			for (i = 0; i <= (deg[u] - 1) / SIZE; i++) {
				for (j = 0, block[u][i] = 1; j < SIZE && i * SIZE + j < deg[u]; j++) block[u][i] = block[u][i] * (e[adj[u][i*SIZE+j]].num + 1) % M;
			}
		}
		for (i = 0; i < deg[u]; i++) {
			if (e[adj[u][i]^1].num >= 0) continue;
			else e[adj[u][i]^1].num = 1;
			if (deg[u] > SIZE) {
				for (k = 0; k < i / SIZE; k++) e[adj[u][i]^1].num = e[adj[u][i]^1].num * block[u][k] % M;
				for (j = i / SIZE * SIZE; j < deg[u] && j < (i / SIZE + 1) * SIZE; j++) if (j != i) e[adj[u][i]^1].num = e[adj[u][i]^1].num * (e[adj[u][j]].num + 1) % M;
				for (k = i / SIZE + 1; k <= (deg[u] - 1) / SIZE; k++) e[adj[u][i]^1].num = e[adj[u][i]^1].num * block[u][k] % M;
			} else {
				for (j = 0; j < deg[u]; j++) if (j != i) e[adj[u][i]^1].num = e[adj[u][i]^1].num * (e[adj[u][j]].num + 1) % M;
			}
		}
	}
	
	long long ans;
	for (u = 2; u <= N; u++) {
		ans = 1;
		for (i = 0; i < deg[u]; i++) ans = ans * (e[adj[u][i]].num + 1) % M;
		printf("%lld\n", ans);
	}
	fflush(stdout);
	return 0;
}

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

int main() {
int a,b,c;
  cin>>a>>b>>c;
  int lop=0;
  lop=c/a;
  cout<<lop*b<<endl;
}

Measured memory_bytes: 256
require 'scanf'
n = scanf("%d").first
a = scanf("%d"*n)
cnt = Array.new(9, 0)
RG = [1..399, 400..799, 800..1199, 1200..1599, 1600..1999, 2000..2399, 2400..2799, 2800..3199]
outcnt = 0
a.each do |v|
    flag = false
    RG.each_with_index do |rg, idx|
      if rg.include?(v)
        flag = true
        cnt[idx] += 1
        break
      end
    end
    if !flag
      outcnt += 1
    end
end
cntc = 0
cnt.each do |e|
  cntc += 1 if e > 0
end
if cntc == 0
  if outcnt != 0
    puts "#{1} #{outcnt}"
    exit
  else
    puts "0 0"
    exit
  end
else 
  puts "#{cntc} #{cntc+outcnt}"
end


Measured memory_bytes: 2044
n = int(input())
s = input()
pos = {
    "R": [],
    "G": [],
    "B": []
}
for i in range(n):
    pos[s[i]].append(i)
# count of "X" after pos i
count = {
    "R": [0] * n,
    "G": [0] * n,
    "B": [0] * n
}
for i in range(n - 2, -1, -1):
    prevC = s[i + 1]
    for c in "RGB":
        count[c][i] = count[c][i + 1]
    count[prevC][i] += 1
#print(pos)
#print(count)
ans = 0
for i in range(n):
    if s[i] == "R":
        for p in pos["G"]:
            if p > i:
                d = p - i
                ans += count["B"][p]
                if p + d < n and s[p + d] == "B":
                    ans -= 1
        for p in pos["B"]:
            if p > i:
                d = p - i
                ans += count["G"][p]
                if p + d < n and s[p + d] == "G":
                    ans -= 1

    if s[i] == "G":
        for p in pos["R"]:
            if p > i:
                d = p - i
                ans += count["B"][p]
                if p + d < n and s[p + d] == "B":
                    ans -= 1
        for p in pos["B"]:
            if p > i:
                d = p - i
                ans += count["R"][p]
                if p + d < n and s[p + d] == "R":
                    ans -= 1

    if s[i] == "B":
        for p in pos["G"]:
            if p > i:
                d = p - i
                ans += count["R"][p]
                if p + d < n and s[p + d] == "R":
                    ans -= 1
        for p in pos["R"]:
            if p > i:
                d = p - i
                ans += count["G"][p]
                if p + d < n and s[p + d] == "G":
                    ans -= 1
print(ans)



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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;

const int MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    string str = "";
    while (N != 0) {
        int r = N % 2;
        if (r < 0) r += 2;

        N = (N - r) / (-2);

        str += (char) ('0' + r);
    }

    reverse(str.begin(), str.end());
    if (str == "") str = "0";
    cout << str << endl;
}

Measured memory_bytes: 256
def main():
    N = input()

    if longest(N) >= 3:
        print('Yes')
    else:
        print('No')

def longest(seq):
    max_count = 0
    prev_char = None

    for current in seq:
        if prev_char != current:
            count = 1
        else:
            count += 1
        if count > max_count:
            max_count = count
        prev_char = current

    return max_count

main()


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

#define dcm(x) cerr << #x << ": " << x << endl;

using namespace std;

typedef long long int lli;
typedef vector<int> vi;

int main() {
    //clock_t start = clock();
    ios::sync_with_stdio(false); cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, l; cin >> n >> l;
    vector<string> ss;
    for (int i=0; i<n; ++i) {
        string s; cin >> s;
        ss.push_back(s);
    }
    sort(ss.begin(), ss.end());
    //set<string> set_ss(ss.begin(), ss.end());
    string res;
    for (int i=0; i<ss.size(); ++i) {
    //for (set<string>::iterator it=set_ss.begin(); it!=set_ss.end(); ++it) {
        //cout << ss[i] << endl;
        //res += *it;
        res += ss[i];
    }
    cout << res << endl;
    //clock_t stop = clock();
    //cout << (double)(stop-start)/CLOCKS_PER_SEC << " (s)" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ff first
#define ss second
#define ll long long
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define repr(i, a, n) for (ll i = (n); i >= (a); --i)
using namespace std;
const int INF(1 << 30);
const ll LLINF(1LL << 55LL);
const int pi = 3.1415926536;
const int MOD = 1000000007;
const int MAX = 510000;

void Main() {
  int n;
  cin >> n;
  cout << n / 3 << endl;
}

int main() {
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // CとC++の入出力出力を非同期
  std::cout << std::fixed << std::setprecision(15);  // 小数を10進数表示
  Main();
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using E = System.Linq.Enumerable;

class Program
{
    static readonly double INF = double.PositiveInfinity;

    static void Main(string[] args)
    {
        while (true)
        {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int N = input[0], M = input[1], P = input[2], A = input[3] - 1, B = input[4] - 1;
            if (N == 0) break;
            int[] nums = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            double[][] dist = E.Range(0, M).Select(i => E.Repeat(INF, M).ToArray()).ToArray();

            for (int i = 0; i < P; i++)
            {
                input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                dist[input[0] - 1][input[1] - 1] = input[2];
                dist[input[1] - 1][input[0] - 1] = input[2];
            }
            double[][] dp = E.Range(0, 1 << N).Select(i => E.Repeat(INF, M).ToArray()).ToArray();
            dp[0][A] = 0;
            for (int mask = 0; mask < (1 << N); mask++)
                foreach (int use in E.Range(0, N).Where(use => (mask >> use & 1) == 0))
                    foreach (int i in E.Range(0, M).Where(i => dp[mask][i] < INF))
                        foreach (int j in E.Range(0, M).Where(j => dist[i][j] < INF))
                        {
                            double cost = dp[mask][i] + dist[i][j] / nums[use];
                            int nextMask = mask | 1 << use;
                            dp[nextMask][j] = Math.Min(dp[nextMask][j], cost);
                        }

            double ans = INF;
            for (int mask = 0; mask < (1 << N); mask++) ans = Math.Min(ans, dp[mask][B]);
            Console.WriteLine((ans == INF) ? "Impossible" : ans.ToString("f3"));
        }
    }
}

Measured memory_bytes: 6356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
using Graph = vector<vector<int>>;
int n, m;
Graph G;

bool visited[1001000];
int dp[1001000];

int dfs(int x) {
  if (dp[x] != 0) return dp[x];
  int mx = 0;
  for (int i = 0; i < G[x].size(); i++) {
    mx = max(mx, dfs(G[x][i]) + 1);
  }
  dp[x] = mx;
  return mx;
}

int main() {
  cin >> n >> m;

  G.resize(n);

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
  }

  int ans = 0;

  for (int i = 0; i < n; i++) {
    if (dp[i] == 0) ans = max(ans, dfs(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 11292
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
#define int long long
#define INF 1245678912346
#define rep(i,n) for(int i = 0; i < n; i++)
#define MAX_VAL 0

signed main(){
	cout<<fixed<<setprecision(8);
	
	int a, b, c, d, e, f, g;
	int n , m , ans = 0, count = 0, k;
	bool flag = false;
	string str;
	
	cin>>a>>b>>c;
	
	cout<<(max(max(a*10+b+c,a+b*10+c),c*10+a+b))<<endl;
	
	
	// cout<<(flag?"Yes":"No")<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<functional>
#include<iostream>
#include<map>
#include<string>

int n;
std::multimap<int, std::string, std::greater<int> > m;

int main()
{
	bool fst = true;

	while( std::cin >> n, n )
	{
		m.clear();

		for( int i = 0; i != n; ++i )
		{
			std::string s;
			int a, b, c;
			std::cin >> s >> a >> b >> c;
			
			m.insert( std::make_pair( a * 3 + c, s ) );
		}

		if( !fst )
			std::cout << std::endl;
		for( auto it = m.begin(); it != m.end(); ++it )
			std::cout << it->second << ',' << it->first << std::endl;
	
		fst = false;
	}

	return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <functional>
#include <iomanip>

#include <queue>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

// #define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
const int MOD = 1e9+7;
const int INF = 1e9;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

// debug
template<class T>ostream& operator<<(ostream& os, vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}
#include<type_traits>
template<typename T,size_t SIZE,enable_if_t<!is_same<remove_cv_t<T>,char>::value,nullptr_t> = nullptr>ostream& operator<<(ostream& os,T(&arr)[SIZE]){os<<"{";for(size_t i=0;i<SIZE;++i)os<<(i?", ":"")<<arr[i];os<<"}";return os;}
#ifdef LOCAL
#define debug(v) cerr<<v<<"\n"
#else
#define debug(...) 42
#endif

int di[4] = {0, 1, 0, -1}, dj[4] = {1, 0, -1, 0};
int H, W;
vector<string> S;

int solve(pii start) {
  int distance[H][W];
  rep(i, H) rep(j, W) distance[i][j] = INF;

  queue<pii> q;
  q.push(start);
  distance[start.first][start.second] = 0;
  int max_i = start.first, max_j = start.second;
  while (!q.empty()) {
    int i = q.front().first,
        j = q.front().second;
    q.pop();
    if (distance[max_i][max_j] < distance[i][j])
      max_i = i, max_j = j;
    rep(d, 4) {
      if (!(0 <= i + di[d] && i + di[d] < H &&
            0 <= j + dj[d] && j + dj[d] < W))
        continue;
      if (S[i+di[d]][j+dj[d]] == '.' && distance[i+di[d]][j+dj[d]] == INF) {
        distance[i+di[d]][j+dj[d]] = distance[i][j] + 1;
        q.emplace(i+di[d], j+dj[d]);
      }
    }
  }
  return distance[max_i][max_j];
}

int main() {
  cin >> H >> W;
  pii start;
  S.resize(H);
  rep(i, H) {
    cin >> S[i];
  }

  int ans = 0;
  rep(i, H) rep(j, W) {
    if (S[i][j] == '.') {
      ans = max(ans, solve(pii(i, j)));
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
 int x;
  cin >> x;
  if(x<600) cout << "8" << endl;
  else if(x<800) cout << "7" << endl;
    else if(x<1000)cout << "6" << endl;
      else if(x<1200)cout << "5" << endl;
        else if(x<1400)cout << "4" << endl;
          else if(x<1600)cout << "3" << endl;
            else if(x<1800)cout << "2" << endl;
              else cout << "1" << endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>


using namespace std;

int H, W, A[100][100], B[100][100];

int dp[100][100][6500];
int INF = 999999;

int main(void) {

	cin >> H >> W;

	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {

			cin >> A[i][j];
		}
	}

	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			cin >> B[i][j];
		}
	}

	
	dp[1][1][abs(A[1][1] - B[1][1])] = 1;

	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			for (int k = 0; k <= 6400; k++) {
				if (i - 1 >= 1 && dp[i - 1][j][k] == 1) {
					int tmp = abs(A[i][j] - B[i][j]);
					dp[i][j][k + tmp] = 1;
					dp[i][j][abs(k - tmp)] = 1;
				}
				if (j - 1 >= 1 && dp[i][j - 1][k] == 1) {
					int tmp = abs(A[i][j] - B[i][j]);
					dp[i][j][k + tmp] = 1;
					dp[i][j][abs(k - tmp)] = 1;
				}
			}
		}
	}

	int ans = INF;

	for (int k = 0; k <= 6400; k++) {
		if (dp[H][W][k] == 1) { ans = k; break; }
	}

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

Measured memory_bytes: 207104
N, K = ARGF.gets.chomp.split.collect {|el| el.to_i}
AA = ARGF.gets.chomp.split.collect {|el| el.to_i}

i1 = 0
i2 = K

i2.upto(N - 1) do |ii|
  if AA[i1] < AA[ii]
    puts "Yes"
  else
    puts "No"
  end
  i1 += 1
end


Measured memory_bytes: 35972
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
#include <cmath>

using namespace std;

int go(int x) {
    int s = 0;
    while (x > 0) {
        s += x % 10;
        x /= 10;
    }
    return s;
}

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    int sum = 0;
    for (int i=1; i<=n; i++) {
        int l = go(i);
        if (l >= a and l <= b) sum += i;
    }
    cout << sum << '\n';
    
    return 0;
}

Measured memory_bytes: 3572
/**
*   @Author : MeGA
*   @InitTime :02/08/20 17:32:26
*   @Idea : 
*
*
*
*
*
*
*
**/
#include <bits/stdc++.h>
using namespace std;


int color[(int)1e5+7];
int vis[(int)1e5+7];
vector<pair<int,int> >adj[(int)1e5+7];
void dfs(int node){
     if(vis[node]){
        return;
     }
     vis[node]=1;
     for(pair<int,int>v:adj[node]){
         if((v.second)%2==0){
             color[v.first]=color[node];
         }else{
            color[v.first]=1-color[node];
         }
      //   cerr<<v.second<<" "<<dis[node]<<endl;
         dfs(v.first);
     }


} 
int main(){
#ifndef ONLINE_JUDGE
  // freopen("in","r",stdin);
  // freopen("out","w",stdout);
#endif

     ios::sync_with_stdio(false);
     cin.tie(0);
     int n;
     cin>>n;
     for(int i=1;i<=n;i++){
         int a,b,c;
         cin>>a>>b>>c;
         adj[a].push_back(make_pair(b,c));
         adj[b].push_back(make_pair(a,c));
     }
     color[1]=0;
     dfs(1);
     for(int i=1;i<=n;i++){
         cout<<color[i]<<endl;
     }

}

Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char aa[101],bb[101],cc[101],v;
    int i;
    queue<char> a,b,c;
    scanf("%s",aa);
    for(i=0;i<strlen(aa);i++)
    {
        a.push(aa[i]);
    }
    scanf("%s",bb);
    for(i=0;i<strlen(bb);i++)
    {
        b.push(bb[i]);
    }
    scanf("%s",cc);
    for(i=0;i<strlen(cc);i++)
    {
        c.push(cc[i]);
    }
    v=a.front();
    a.pop();
    while(1)
    {
        if(v=='a')
        {
            if(a.empty())
            {
                printf("A\n");
                break;
            }
            else
            {
                v=a.front();
                a.pop();
            }
        }
        if(v=='b')
        {
            if(b.empty())
            {
                printf("B\n");
                break;
            }
            else
            {
                v=b.front();
                b.pop();
            }
        }
        if(v=='c')
        {
            if(c.empty())
            {
                printf("C\n");
                break;
            }
            else
            {
                v=c.front();
                c.pop();
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
import itertools

ans = []
input_list = [int(input()) for i in range(5)]

c_list = itertools.permutations(input_list)

for el_list in c_list:
    time = 0
    count = 0
    #print(el_list)
    for el in el_list:
        time += el
        if count == 4:
            break
        elif time%10 != 0:
            while True:
                time+=1
                if time%10 == 0:
                    break
        count += 1
    #print(time)
    ans.append(time)

print(min(ans))
        


Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>
#define mod 1000000007

using namespace std;
typedef long long ll;

int n,l,r;
ll a,b,s[100001],f[100001],g[100001],ans;

int main()
{
	scanf("%d%lld%lld",&n,&a,&b);
	if(a>b) swap(a,b);
	for(int i=1;i<=n;i++) scanf("%lld",&s[i]);
	for(int i=3;i<=n;i++) 
		if(s[i]-s[i-2]<a) {putchar('0');return 0;}
	f[0]=g[0]=1;l=r=0;
	for(int i=1;i<=n;i++)
	{
		while(r<i-1 && s[i]-s[r+1]>=b) r++;
		if(l<=r) f[i]=(g[r]-(l?g[l-1]:0)+mod)%mod;
		g[i]=(g[i-1]+f[i])%mod;
		if(i>1 && s[i]-s[i-1]<a) l=i-1;
	}
	for(int i=n;i>=0;i--)
	{
		ans=(ans+f[i])%mod;
		if(i<n && s[i+1]-s[i]<a) break;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,ans=0;
    cin>>n>>m;
    if(n>=2) ans+=(n*(n-1))/2;
    if(m>=2) ans+=(m*(m-1))/2;
    cout<<ans<<"\n";
}


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 a;
	}else if(b%2==0){
		ll memo = mpow(a,b/2);
		return memo*memo%MOD;
	}else{
		return mpow(a,b-1) * a % MOD;
	}
}

int main(void){
	int n,l;
	cin>>n>>l;
	ll sum = 0;
	if(l <= 0 && l+n-1 >= 0){
		reps(i,n){
			sum += l+i-1;
		}
	}else{
		reps(i,n){
			sum += l+i-1;
		}
		if(l < 0){
			sum -= l+n-1;
		}else{
			sum -= l+1-1;
		}
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  string S;
  cin >> S;
  vector<vector<int>> DP(2,vector<int>(S.size(),0));
  if(S.at(0)=='0') DP.at(1).at(0)=1;
  else DP.at(0).at(0)=1;

  for(int i=1;i<S.size();i++){
    if(S.at(i)=='0'){
      DP.at(0).at(i)=DP.at(1).at(i-1);
      DP.at(1).at(i)=DP.at(0).at(i-1)+1;
    }
    else{
      DP.at(0).at(i)=DP.at(1).at(i-1)+1;
      DP.at(1).at(i)=DP.at(0).at(i-1);
    }
  }

  cout << min(DP.at(0).at(S.size()-1),DP.at(1).at(S.size()-1)) << endl;
  
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    int h,w,n;
    cin>>h>>w>>n;

    if(h>w){
        cout<<n/h+(n%h==0?0:1)<<endl;
    }else{
        cout<<n/w+(n%w==0?0:1)<<endl;
    }
    
return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while (true) {
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			int[] board = new int[n];
			int white_count = 0;
			for(int i = 0; i < n; i++){
				boolean is_white = sc.nextInt() == 0;
				
				if((i + 1) % 2 == 0){
					int push_color = is_white ? 1 : -1;
					
					int count = 0;
					for(int j = i - 1; j >= 0; j--){
						if(push_color == board[j]){
							break;
						}
						count++;
					}
					
					for(int j = 0; j <= count; j++){
						board[i - j] = push_color;
					}
					
					if(is_white){
						white_count += count + 1;
					}else{
						white_count -= count;
					}
				}else{
					board[i] = is_white ? 1 : -1;
					if(is_white){
						white_count++;
					}
				}
			}
			//System.out.println(Arrays.toString(board));
			
			System.out.println(white_count);
			
		}
	}

}

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

using namespace std;
typedef unsigned long long ull;

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

	int N;	//切れ込みの個数
	cin >> N;

	int *A = new int[N];	//各ピースの大きさを格納する配列
	ull total_size = 0;	//バームクーヘンの大きさ
	int i1_ini = 0;
	int A_max = 0;
	for(int i=0; i<N; i++){
		cin >> A[i];
		total_size += A[i];
		if (A[i] > A_max){
			A_max = A[i];
			i1_ini = i;
		}
	}
	ull one_third_size = total_size / 3;
	ull answer = 0;
	if (A_max > one_third_size){
		ull half_size = (total_size - A_max) / 2;
		ull tmp = 0;
		ull piece2 = 0;
		for (int i3 = i1_ini + 1; i3 < i1_ini + N - 1; i3++){
			piece2 = tmp;
			tmp += A[i3%N];
			if (tmp > half_size) break;
		}
		ull piece3 = total_size - A_max - tmp;
		answer = max(piece2, piece3);
		cout << answer << endl;
		return 0;
	}

	int i2 = i1_ini;
	ull piece1_s = 0;
	ull piece1_l = 0;
	for (; i2 < i1_ini + N - 2;){
		piece1_s = piece1_l;
		piece1_l += A[i2%N];
		i2++;
		if (piece1_l > one_third_size) break;
	}
	const int i1_fin = i2;

	int i3 = i1_ini + N;
	ull piece3_s = 0;
	ull piece3_l = 0;
	for (; i3 > i2 + 1;){
		piece3_s = piece3_l;
		i3--;
		piece3_l += A[i3%N];
		if (piece3_l > one_third_size) break;
	}
	i3++;

	ull tmp = 0;
	tmp = min(piece1_s, piece3_s);
	
	ull piece2 = 0;
	piece2 = total_size - piece1_s - piece3_l;
	tmp = max(tmp, min(piece1_s, piece2));

	piece2 = total_size - piece1_l - piece3_s;
	tmp = max(tmp, min(piece3_s, piece2));

	piece2 = total_size - piece1_l - piece3_l;
	tmp = max(tmp, piece2);

	answer = tmp;

	for (int i1 = i1_ini + 1; i1 < i1_fin; i1++){
		int A_tmp = A[(i1 - 1) % N];
		piece1_l -= A_tmp;
		if (piece1_l > one_third_size) piece1_s -= A_tmp;
		else{
			for (; i2 < i1 + N - 2;){
				piece1_s = piece1_l;
				piece1_l += A[i2%N];
				i2++;
				if (piece1_l > one_third_size) break;
			}
		}

		piece3_s += A_tmp;
		if (piece3_s <= one_third_size) piece3_l += A_tmp;
		else{
			for (; i3 < i1 + N - 1;){
				piece3_l = piece3_s;
				piece3_s -= A[i3%N];
				i3++;
				if (piece3_s <= one_third_size) break;
			}
		}

		tmp = min(piece1_s, piece3_s);

		piece2 = total_size - piece1_s - piece3_l;
		tmp = max(tmp, min(piece1_s, piece2));

		piece2 = total_size - piece1_l - piece3_s;
		tmp = max(tmp, min(piece3_s, piece2));

		piece2 = total_size - piece1_l - piece3_l;
		tmp = max(tmp, piece2);

		answer = max(answer, tmp);
	}

	cout << answer << endl;

	delete[] A;

	return 0;
}

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

int main(){
	int r,c,k;
	cin >> r >> c >> k;
	vector<vector<vector<ll>>> dp(r,vector<vector<ll>>(c,vector<ll>(4,0)));
	vector<vector<ll>> value(r,vector<ll>(c,0));
	for(int i = 0;i < k;i++){
		int rr,cc;
		cin >> rr >> cc;
		rr--,cc--;
		ll v;
		cin >> v;
		value[rr][cc] = v;
	}

	if(value[0][0] != 0){
		dp[0][0][1] = value[0][0];
	}

	for(int i = 0;i < c;i++){
		for(int j = 0;j < r;j++){
			for(int k = 0;k <= 3;k++){
				//i+1,jかi,j+1に移動.
				if(j + 1 < r){
					//別の行に移動.個数はリセットされる.
					dp[j+1][i][0] = max(dp[j][i][k],dp[j+1][i][0]);
					dp[j+1][i][1] = max(dp[j+1][i][1],dp[j][i][k] + value[j+1][i]);
				}
				if(i + 1 < c){
					//隣の列に移動.個数はリセットされない.
					dp[j][i+1][k] = max(dp[j][i+1][k],dp[j][i][k]);
					if(k + 1 <= 3)dp[j][i+1][k+1] = max(dp[j][i+1][k+1],dp[j][i][k] + value[j][i+1]);
				}
			}
		}
	}

	cout << max({dp[r-1][c-1][0],dp[r-1][c-1][1],dp[r-1][c-1][2],dp[r-1][c-1][3]}) << endl;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)



int main(){

    lli n;
    string s;

    cin>>n>>s;

    set<lli> pos[26];
    REP(i,0,s.size()){
        pos[s.at(i)-'a'].insert(i);
    }
    REP(i,0,26)pos[i].insert(INF);

    lli q;
    cin>>q;
    REP(i,0,q){
        lli tmp;
        cin>>tmp;
        if(tmp==1){
            lli p;
            char c;
            cin>>p>>c;
            p--;
            char beforeC = s.at(p);
            pos[beforeC-'a'].erase(p);
            pos[c-'a'].insert(p);
            s[p]=c;
        }
        else{
            lli st,en;
            cin>>st>>en;
            st--,en--;
            lli cnt=0;
            REP(i,0,26){
                auto itr = pos[i].lower_bound(st);
                if(*itr<=en)cnt++;
            }
            cout<<cnt<<endl;
        }
    }


    return 0;
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
typedef tuple<long long, long long, long long> tllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
bool compTuple(const tllint& arg1, const tllint& arg2) { return get<2>(arg1) > get<2>(arg2); }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void) {
    llint n, k;
    cin >> n >> k;

    vector<llint> a(n);
    vector<llint> atmp(n);
    for(llint in=0;in<n;++in) {
        cin >> a[in];
        atmp[in] = a[in];
    }

    llint cnt = 0, pow2 = 1;
    while(pow2<k) { 
        cnt++;
        pow2 *= 2;
    }

    llint x = 0, cnt0, cnt1;
    for(llint ic=cnt;ic>=0;--ic) {
        cnt1 = 0;
        cnt0 = 0;
        for(llint in=0;in<n;++in) {
            if((atmp[in]/pow2)&1) cnt1++;
            atmp[in] %= pow2;
        }
        cnt0 = n - cnt1;
        if(cnt0>cnt1&&x+pow2<=k) x += pow2;
        // cout << cnt0 << cnt1 << x << endl;
        pow2 /= 2;
    }

    llint ans = 0;
    for(auto ia:a) ans += ia ^ x;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4784
/*
        Author: Prokash
                CSE48, JU

*/

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

typedef long long ll;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
    FAST;
    ll n,t,in;
    vector<ll>v;
    map<ll,int>mp;
    map<ll,int>::iterator it;
    cin>>t;
    while(t--)
    {
        cin>>in;
        mp[in]++;
        if(mp[in]==2)
        {
            v.push_back(in);
            mp[in]=0;
        }
    }
//    for(it=mp.begin();it!=mp.end();it++)
//    {
//        if(it->second>=2)
//        {
//            v.push_back(it->first);
//        }
//    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    if(v.size()<2)
    {
        cout<<0<<endl;
    }
    else
    {
        cout<<v[0]*v[1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 6528
#C
import numpy as np
N = int(input())
P = np.array([input().split() for _ in range(N)], dtype=int)

LEN = np.zeros((N,N), dtype=float)

for i in range(N):
  for j in range(N):
    LEN[i,j] = sum((P[i] - P[j])**2)**0.5

rote = 0

# 探索経路の合計を返す
def getlen(before=(), after=()):
  if len(after) == 0:
    global rote
    rote += 1
    return sum([LEN[before[i], before[i+1]] for i in range(N-1)])
  t = 0
  for i in range(len(after)):
    t += getlen(before + (after[i],), after[:i] + after[i+1:])
  return t

t = getlen((), tuple(range(N)))

print(t / rote)

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

int main(){
    string S;
    cin >> S;
    int len = S.size();
    int half;
    int count = 0;
    half = len/2;
    for(int i=0 ;i < half;i++){
        if(S[i] != S[len-1-i]) count++;
    }   
    cout << count << endl;
    return 0;
}

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

int main()
{
    long long n,m,a,b;
    cin>>n>>m;
    a=min(n,m); b=max(n,m);
    if(a==1 && b==2) cout<<3<<endl;
    else if(a==1 && b==3) cout<<2<<endl;
    else if(a==2 && b==3) cout<<1<<endl;
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    ll dp[100];
    dp[0] = 2;
    dp[1] = 1;
    for(int i = 2; i <= n; i++){
        dp[i] = dp[i - 1] + dp[i - 2];
    }
    cout << dp[n];
}


Measured memory_bytes: 256
///******* In the name of Allah *******///

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

//long int ar[90013],br[100013];
//long int gcd(long int a, long int b)
//{
//    if(b==0)
//        return a;
//    return gcd(b,a%b);
//}
//long int sieve(long long int a)
//{
//    //long long int i,j,k = 0;
//    memset(ar,0,sizeof(ar));
//    ar[1] = 1;
//    for(i=2; i<=90013; i++)
//    {
//        if(ar[i]==0)
//        {
//            k++;
//            br[k] = i;
//            for(j=i+i; j<=90013; j+=i)
//            {
//                ar[j] = 1;
//            }
//        }
//    }
//    return br[a];
//}

void Ok()
{
    long int a[113],b,c,d,h,t,i,j,k,l,m,n;
    long int ans_1,ans_2,ans_3,ans_4,cnt = 0,Max,Min,flag,temp,sum_1,sum_2;
    double aa,bb,cc,dd,ee,ff,gg;
    char aaa[10013],bbb,ccc,ddd;
    string spc,in;

    memset(a,0,sizeof(a));
    cin>>n>>k;
    for(i=1;i<=k;i++)
    {
        cin>>m;
        for(j=1;j<=m;j++)
        {
            cin>>b;
            a[b] = 1;
        }
    }
    for(i=1;i<=n;i++)
    {
        if(a[i]==0)
            cnt++;
    }
    cout<<cnt<<endl;

    return;
}

int main()
{
    Ok();

    return 0;
}


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

int main()
{
    string str;
    cin >> str;
    
    if (str.find('7') != string::npos) {
    cout << "Yes" <<endl;
    }
    else{
    cout << "No" << endl;
    }
    
    return 0;
}


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

int main() {
 char S[3], T[3];

 for(int i = 0; i < 3; i++) {
	cin >> S[i];
 }
 for(int i = 0; i < 3; i++) {
	cin >> T[i];
 }

 int cnt = 0;

 for(int i = 0; i < 3; i++) {
	if(S[i] == T[i]) {
		cnt++;
	}
 }

 cout << cnt << endl;

}

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

int main() {
    int h, w;
    cin >> h >> w;
    int ans = 0;
    vector<vector<char>> s((h),vector<char> (w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> s[i][j];
        }
    }
    vector<vector<int>> l(h, vector<int>(w));
    vector<vector<int>> r(h, vector<int>(w));
    vector<vector<int>> d(h, vector<int>(w));
    vector<vector<int>> u(h, vector<int>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') {
                l[i][j] = 0;
            }
            else if (j == 0) {
                l[i][j] = 1;
            }
            else l[i][j] = l[i][j-1] + 1;
        }
    } 
    for (int i = 0; i < h; i++) {
        for (int j = w-1; j >= 0; j--) {
            if (s[i][j] == '#') {
                r[i][j] = 0;
            }
            else if (j == w-1) {
                r[i][j] = 1;
            }
            else r[i][j] = r[i][j+1] +1;
        }
    }
    for (int i = 0; i < w; i++) {
        for (int j = 0; j < h; j++) {
            if (s[j][i] == '#') {
                u[j][i] = 0;
            }
            else if (j == 0) {
                u[j][i] = 1;
            }
            else u[j][i] = u[j-1][i] + 1;
        }
    } 
    for (int i = 0; i < w; i++) {
        for (int j = h-1; j >= 0; j--) {
            if (s[j][i] == '#') {
                d[j][i] = 0;
            }
            else if (j == h-1) {
                d[j][i] = 1;
            }
            else d[j][i] = d[j+1][i] + 1;
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            ans = max(ans,l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 67072
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    int x;
    cin>>x;
    int happy=0;
    
    happy+=(x/500)*1000;
    x%=500;
    
    happy+=(x/5)*5;
    
    cout<<happy<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int H[100005];
int G[100005];
int main() {
  ios::sync_with_stdio(false);
  int N, M, A, B;
  cin >> N >> M;
  for (int i=1; i<=N; i++) {
    cin >> H[i];
  }
  for (int i=1; i<=M; i++) {
    cin >> A >> B;
    if (H[A] <= H[B]) G[A] = 1;
    if (H[B] <= H[A]) G[B] = 1;
  }
  int ret = 0;
  for (int i=1; i<=N; i++) {
    if (!G[i]) ret++;
  }
  cout << ret << endl;
}

Measured memory_bytes: 4388
D, G = map(int, input().split())
X = []
for i in range(D):
    p, c = map(int, input().split())
    X.append((p, c))

def calc(k):
    s = G
    a = 0
    for i in range(D):
        if k & (1<<i):
            a += X[i][0]
            s -= X[i][0] * (i+1) * 100 + X[i][1]
    if s <= 0:
        return a
    for i in range(D)[::-1]:
        if k & (1<<i) == 0:
            if s > X[i][0] * (i+1) * 100:
                return 1<<100
            else:
                a += -(-s//((i+1) * 100))
                break
    return a

mi = 1 << 100
for j in range(1<<D):
    mi = min(mi, calc(j))
print(mi)

Measured memory_bytes: 40176
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    int k = sc.nextInt();
    int[][] c = new int[h][w];
    for(int i = 0; i < h; i++) {
      String s = sc.next();
      for(int j = 0; j < w; j++) {
        if(s.charAt(j) == '#') c[i][j] = 1;
      }
    }
    int ans = 0;
    for(int i = 0; i < (int)Math.pow(2, h); i++) {
      for(int j = 0; j < (int)Math.pow(2, w); j++) {
        int p = 0;
        for(int s = 0; s < h; s++) {
          for(int t = 0; t < w; t++) {
            if(((i & (1 << s)) == 0) && ((j & (1 << t)) == 0) && (c[s][t] == 1)) p++; 
          }
        }
        if(p == k) ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 35816
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

inline int read(){
	int x = 0;
	char ch = getchar();
	
	while(ch < '0' || ch > '9')
		ch = getchar();
	
	while('0' <= ch && ch <= '9'){
		x = x*10 + ch - '0';
		ch = getchar();
	}
	
	return x;
}

int n;
int data[110];
int ans;

int main(){
	n = read();
	
	for(register int i=0; i<n; i++)
		data[i] = read();
	
	for(register int i=1; i<n; i++){
		if(data[i] == data[i-1]){
			data[i] = 0;
			ans++;
		}
	}
	
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
N = int(input())
S = list(input())
alp = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
S_a = ""
for s in S:
    n = alp.index(s)+N 
    if(alp.index(s)+N>=26):
        n -= 26
    S_a += alp[n]
print(S_a)

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

//-------------------------------------
const ll MAX_V = 100000;

// 行き先toとコストcost
struct edge
{
    ll to;
    ll cost;
};
typedef pair<ll, ll> P; // firstは最短距離、secondは頂点の番号

// int V;
// vector<edge> graph[MAX_V]; // グラフ(隣接リスト)
// int d[MAX_V];              //最短距離

void dijkstra(ll s, vector<vector<edge>> &graph, vector<ll> &d, ll V)
{
    priority_queue<P, vector<P>, greater<P>> pq;
    fill(d.begin(), d.begin() + V, LLINF);
    d[s] = 0;
    pq.push(P(0, s));

    while (!pq.empty())
    {
        P p = pq.top(); // 未確定の中から確定させた頂点
        pq.pop();
        ll v = p.second; // 取り出した頂点の番号
        // もう探索する必要のない経路がpqに残っていた場合は枝刈り
        if (d[v] < p.first)
        {
            continue;
        }

        for (ll i = 0; i < (ll)graph[v].size(); i++)
        {
            edge e = graph[v][i];
            if (d[e.to] > d[v] + e.cost)
            {
                d[e.to] = d[v] + e.cost;
                pq.push(P(d[e.to], e.to));
            }
        }
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<vector<edge>> graph(n);
    for (ll i = 0; i < n - 1; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        graph[a].push_back(edge{b, c});
        graph[b].push_back(edge{a, c});
    }
    ll q, k;
    cin >> q >> k;
    k--;
    vector<ll> d(n);
    dijkstra(k, graph, d, n);
    for (ll i = 0; i < q; i++)
    {
        ll x, y;
        cin >> x >> y;
        x--;
        y--;
        ll ans = d[x] + d[y];
        // cout << "dbg:" << d[k] << ' ' << dk[y] << endl;
        cout << ans << endl;
    }
}

Measured memory_bytes: 11120
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const ull B=100000007;
const int INF=1e9;
int main(){
      int w,h,n,ans=0;
      cin>>w>>h>>n;
      int bx,by,nx,ny;
      cin>>bx>>by;
      REP(i,n-1){
            cin>>nx>>ny;
            int dx=nx-bx,dy=ny-by;
            if(dx*dy>=0){
                  dx=abs(dx);
                  dy=abs(dy);
                  int sl=min(dx,dy);
                  ans+=dx+dy-sl;
            }else{
                  ans+=(abs(dx)+abs(dy));
            }
            bx=nx;by=ny;
      }
      cout<<ans<<endl;
}

Measured memory_bytes: 1160
#include <cstdio>

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

  int res = 0;
  for (int i = 0; i < N; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);
    res += r-l+1;
  }
  printf("%d\n", res);
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    otos=lambda x:"+" if x==1 else "-"
    abcd=int(input())
    abc,d=divmod(abcd,10)
    ab,c=divmod(abc,10)
    a,b=divmod(ab,10)
    for o1 in [1,-1]:
        for o2 in [1, -1]:
            for o3 in [1, -1]:
                s=a+o1*b+o2*c+o3*d
                if s==7:
                    ans=str(a)+otos(o1)+str(b)+otos(o2)+str(c)+otos(o3)+str(d)+"=7"
                    print(ans)
                    exit()

main()

Measured memory_bytes: 3188
#pragma GCC optimize("-O3")
#include<bits/stdc++.h>
using namespace std;
#define LocalTestAddress "test.txt"
//////////////////////////////////////////////////////////////////////////////
#define endl '\n'
void solve();
signed main(){
#ifdef Sprinkle
    clock_t clock_start=clock();assert(freopen(LocalTestAddress,"r",stdin));
#else
     ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#endif
    solve();
#ifdef Sprinkle
    cerr<<"Running Time: "<<((clock()-clock_start) *1.0 / CLOCKS_PER_SEC)<<"s\n";
#endif
    return 0;
}
#ifdef Sprinkle
void err(){cerr<<"\n";}template<typename T,typename...U>void err(const T&hd,const U&...tl){cerr<<hd<<(sizeof...(tl)?", ":"");err(tl...);}
#define debug(x...) cerr<<""#x" = ";err(x)
#else
#define debug(...) 0
#endif
//////////////////////////////////////////////////////////////////////////////

void solve(){
    long long a;
    long double b;
    cin>>a>>b;
    long long ans=a*b;
    cout<<ans<<endl;
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
					  cerr << "\n\n" << "Time elapsed: " << \
					  (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
					  return 0
#define ll long long int
#define ull unsigned long long int
#define db long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define pii pair<int , int>
#define pdd pair<db , db>
#define pll pair<ll , ll>
#define vpl vector<pll >
#define vll vector<ll >
#define mod 1000000007
#define inf 100000000000000007
#define eps 0.000001
#define stp fixed<<setprecision(20)
#define endl '\n'
 
ll p1=101,mod1=17093097961;
string dp[10005];
bool vis[10005];
bool act[10];
ll a[10]={0,2,5,5,4,5,6,3,7,6};
string s;
 
// inline void rec(pll node)
// {
// 	char c=node.ss+'0';
// 	s+=c;
// 	if(node.ff==0)
// 		return;
 
// 	rec(prv[node.ff]);
// }
 
int main()
{
	fastio;
	#ifdef APNA_IO
		start_routine();
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);
    #endif
 	
 	vis[0]=1;
 	ll n,m;cin>>n>>m;
 	for(ll i=0;i<m;i++)
 	{
 		ll x;cin>>x;
 		act[x]=1;
 	}
 	
 	for(ll i=1;i<=n;i++)
 	{
 		for(ll k=1;k<=9;k++)
 		{
 			if(act[k])
 			{
 				if(i-a[k]<0)
 					continue;
 
 				if(!vis[i-a[k]])
 					continue;
 
 				vis[i]=1;
 				char c=k+'0';
 				s=dp[i-a[k]]+c;
 				if(s.length()>dp[i].length())
 					dp[i]=s;
 				else if(s.length()==dp[i].length() && s>dp[i])
 					dp[i]=s;
 			}
 		}
 	}
 
 	// cout<<dp[4]<<endl;
 
 	// rec(prv[n]);
 	// sort(s.begin(), s.end());
 	// reverse(s.begin(), s.end());
 	// cout<<s;
 	cout<<dp[n];
 
 
	#ifdef APNA_IO
		end_routine();
    #endif
}
 

Measured memory_bytes: 42752
#include <iostream>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<fstream>
#include<queue>
#include<set>
#include<string>
using namespace std;
void fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(0);
}

int main()
{
	fast();

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (abs(a - b) <= d && abs(b - c) <= d)
		cout << "Yes" << endl;
	else if(abs(a - c) <= d)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}



Measured memory_bytes: 3536
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;
int n;
char s[nax];
int f[nax];
int p2[nax][2];
vector <int> ans;

int main () {
    scanf("%d", &n);
    scanf("%s", s);
    reverse(s, s + n);

    for (int i = 0 ; i < nax ; ++ i) {
        int x = i;
        while (x > 0) {
            int p = __builtin_popcount(x);
            x %= p;
            ++ f[i];
        }
    }


    int first = 0;

    for (int i = 0 ; i < n ; ++ i) {
        if (s[i] == '1') ++ first;
    }

    ++ first;
    int second = first - 2;


    p2[0][0] = p2[0][1] = 1;

    for (int i = 1 ; i < nax ; ++ i) {
        p2[i][0] = p2[i - 1][0] * 2 % first;
        if (second > 0)
        p2[i][1] = p2[i - 1][1] * 2 % second;
    }

    int first_sum = 0;
    int second_sum = 0;

    for (int i = 0 ; i < nax ; ++ i) {
        if (s[i] == '1') {
            first_sum += p2[i][0];
            second_sum += p2[i][1];
            first_sum %= first;
            if (second != 0)
            second_sum %= second;
        }
    }

    for (int i = 0 ; i < n ; ++ i) {
        int x;
        if (s[i] == '0') {
            x = (first_sum + p2[i][0]) % first;
            ans.push_back(f[x] + 1);
        } else {
            if (second == 0) {
                ans.push_back(0);
            }
            else {
                x = ((second_sum - p2[i][1]) % second + second) % second;
                ans.push_back(f[x] + 1);
            }
        }

    }

    reverse(ans.begin(), ans.end());

    for (int i : ans)
        printf("%d\n", i);
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 8020
#include <stdio.h>
#include <stdlib.h>

int partition(int,int);

int A[100000];
int main(){
  int i,j,n;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  
  j = partition(0,n-1);

  for(i=0;i<n;i++){
    if(i == j && i == n-1) printf("[%d]",A[i]);
    else if(i == j)printf("[%d] ",A[i]);
    else if(i == n-1)printf("%d",A[i]);
    else printf("%d ",A[i]);
  }
  printf("\n");
  
  return 0;
}

int partition(int p,int r){
  int i,j,x,ch;
  
  x = A[r];
  i = p-1;
  for(j=p;j<r;j++){
    if(A[j]<= x){
      i = i+1;
      ch = A[i];
      A[i] = A[j];
      A[j] = ch;
    }
  }
  ch = A[i+1];
  A[i+1] = A[r];
  A[r] = ch;
  
  return i+1;
}



Measured memory_bytes: 2128