akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(void){
	long int N, A, B;
	cin >> N >> A >> B;
	
	if(B < A)	cout << 0;
	else if(N == 1){
		if(A == B)	cout << 1;
		else		cout << 0;
	}else
		cout << (N - 2) * (B - A) + 1;
	
	cout << endl;
	return 0;
}

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

using namespace std;

int arr[10]={0,2,5,5,4,5,6,3,7,6};
int a[10];
bool mem[10004][5005],vis[10004][5005];
string ans;
int n,m;

bool go(int ind,int len)
{
	if(len<0 || ind<0) return 0;
	if(ind==0&&len==0) return 1;
	if(ind==0||len==0) return 0;
	if(vis[ind][len]) return mem[ind][len];
	vis[ind][len]=1;
	for(int i=0;i<m;i++)
		mem[ind][len]|=go(ind-arr[a[i]],len-1);
	return mem[ind][len];
}

void build(int ind,int len)
{
	if(ind==0&&len==0) return;
	for(int i=m-1;i>=0;i--)
		if(go(ind-arr[a[i]],len-1))
		{
			ans+=a[i]+'0';
			build(ind-arr[a[i]],len-1);
			return;
		}
}

int main()
{
	cin >> n >> m;
	for(int i=0;i<m;i++)
	{
		cin >> a[i];
	}
	sort(a,a+m);
	bool got=0;
	for(int i=n/2;i>=1;i--)
	{
		if(go(n,i))
		{
			got=1;
			build(n,i); break;
		}
	}
	assert(got); // ya nassab :'(
	cout << ans << endl;
}

Measured memory_bytes: 98176
#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;

static long long INF = (1LL<<62);

vector<LL> spf;
int ready = 0;
void init(LL N){
	spf.assign(N+1, 0);
	for(LL i=0; i<=N; i++){ spf[i] = i;}
	for(LL i=2; i<=N; i++){
		if(spf[i] == i){
			for(LL j=i*i; j<=N; j+=i){
				if(spf[j] == j){
					spf[j] = i;
				}
			}
		}
	}
	ready = 1;
}

void factorize(long long n, map<long long, int> &mp){
	if(ready == 0){
		init(n);
	}
	while(n != 1){
		mp[spf[n]]++;
		n /= spf[n];
	}
	return;
}

LL calcdivN(map<LL, int> &mp){
	LL ret = 1;
	for(auto itr = mp.begin(); itr != mp.end(); itr++){
		int v = itr->second;
		ret *= (v+1);
	}
	return ret;
}

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

	LL N; cin >> N;
	init(N);

	LL ans = 0;
	for(LL i=1; i<N; i++){
		map<LL, int> mp ;
		factorize(i, mp);
		LL r = (LL)calcdivN(mp);
		ans += r;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 11116
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n,0);
    vector<int> b(n,0);
    vector<int> c(n,0);

    for (int i=0; i<n; i++) cin >> a[i];
    for (int i=0; i<n; i++) cin >> b[i];
    for (int i=0; i<n; i++) cin >> c[i];

    int ans = accumulate(b.begin(), b.end(), 0);
    for (int i=0; i<n; i++) {
        if (i<n-1 && a[i]+1 == a[i+1]) {
            ans += c[a[i]-1];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int n;
    cin>>n;
    int a[3];
    for(int i=0;i<n;i++){
		cin>>a[i];
	}
    for(int i=1;i<=100000000;i++){
		int b;
		for(b=0;b<n;b++){
			if(a[b]%i)break;
		}
		if(b==n){cout<<i<<endl;
		}
	}
return 0;
}


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

using namespace std;
typedef long long ll;

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

/*Solve*/

int main(){
    ll n,m;
    cin >> n >> m;
    vector<pair<ll,ll>> p;
    rep(i,n){
        ll a,b;
        cin >> a >> b;
        p.push_back({a,b});
    }
    sort(p.begin(),p.end());
    
    ll ans=0;
    ll idx=0;
    while(m>0){
        if(m>=p[idx].second){
            ans+=p[idx].first*p[idx].second;
            m-=p[idx].second;
            idx++;
        }else{
            ans+=p[idx].first*m;
            m=0;
        }
    }
    cout << ans;
}

Measured memory_bytes: 2420
n, k = map(int, input().split())
a = list(map(int, input().split()))
c = [0] * (n+1)
for i in range(n):
    c[i+1] = c[i] + a[i]

s = []
for i in range(n):
    for j in range(i+1, n+1):
        s.append(c[j]-c[i])
s.sort()

L = 40
b = [set() for _ in range(L)]
u = set(range(len(s)))
ans = 0

for i in range(L):
    for j, x in enumerate(s):
        if x >> i & 1:
            b[i].add(j)

for i in range(L)[::-1]:
    if len(u & b[i]) >= k:
        u &= b[i]
        ans += 2**i

print(ans)


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

const int MAX_N = int(5e3) + 10;
const int mod = int(1e9) + 7;

int add(int a, int b) {
	return (a + b) >= mod ? a + b - mod : a + b;
}

int mul(int a, int b) {
	return 1LL * a * b % mod;
}

int sub(int a, int b) {
	return a - b < 0 ? a - b + mod : a - b;
}

int n, a, b, g[MAX_N][2], f[MAX_N][2];

int main() {
	scanf("%d%d%d", &n, &a, &b);
	if (a > b) std::swap(a, b);
	int ans = 0;
	if (b > 1) {
		f[0][0] = f[0][1] = 1;
		for (int i = 1; i <= n; ++i)
			for (int k = 0; k < 2; ++k)
				for (int j = 1; j <= i; ++j) {
					if (k == 0 && j < a) continue;
					f[i][k] = add(f[i][k], f[i - j][k ^ 1]);
				}
		f[0][0] = 0;
		for (int i = 1; i < n; ++i) {
			if (i < a) g[i][0] = 1;
			for (int j = 1; j < std::min(i, a); ++j)
				g[i][0] = add(g[i][0], g[i - j][1]);
			if (i < b)
				g[i][1] = add(f[i - 1][0], f[i - 1][1]);
			for (int j = 1; j < std::min(i, b); ++j) {
				int coef = j == 1 ? 1 : add(f[j - 2][0], f[j - 2][1]);
				g[i][1] = add(g[i][1], mul(g[i - j][0], coef));
			}
			if (n - i < b)
				ans = add(ans, mul(g[i][0], add(f[n - i - 1][0], f[n - i - 1][1])));
			if (n - i < a)
				ans = add(ans, g[i][1]);
		}
	}
	int tot = 1;
	for (int i = 1; i <= n; ++i) tot = add(tot, tot);
	printf("%d\n", add(tot, mod - ans));
}

Measured memory_bytes: 3808
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <algorithm>
#include <functional>
#include <limits.h>
#include <bitset>

#include <tuple>
#include <unordered_map>

#define mp       make_pair
#define mt       make_tuple
#define pb       push_back
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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

struct edge{
  int tar;
  int cost;
  edge(){}
  edge(int tar, int cost): tar(tar), cost(cost){}
};
bool visit[MAX_N];
vector<edge> edges[MAX_N];
int dp[MAX_N][2];
int N;
int memo(int pos){
  visit[pos] = true;
  int res = 0;
  for (int i = 0; i < edges[pos].size(); i++){
    edge e = edges[pos][i];
    if (visit[e.tar])continue;
    res = max(res, memo(e.tar));

    if (dp[pos][0] < dp[e.tar][0] + e.cost){
      dp[pos][1] = dp[pos][0];
      dp[pos][0] = dp[e.tar][0] + e.cost;
    }else if(dp[pos][1] < dp[e.tar][0] + e.cost){
      dp[pos][1] = dp[e.tar][0] + e.cost;
    }
    res = max(res, dp[pos][0] + dp[pos][1]);
  }
  return res;
}

int main(){
  cin >> N;
  for (int i = 0; i < N - 1; i++){
    int s,t,w;
    cin >> s >> t >> w;
    edges[s].push_back(edge(t, w));
    edges[t].push_back(edge(s, w));
  }
  cout << memo(0) << endl;
  return 0;
}

Measured memory_bytes: 13792
// ------------------------------------
// Date:2018/ 2/26
// Problem:ABC 051 Haiku a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

#define MOD 1000000007

int main()
{
  string inputStr,tmp;
  cin >> inputStr;
  tmp = inputStr.substr(0,5);
  cout << tmp << " ";
  tmp = inputStr.substr(6,7);
  cout << tmp << " ";
  tmp = inputStr.substr(14,5);
  cout << tmp << endl;
  return 0;
}


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

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


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
using namespace std;
int main(){
	string s;
	cin>>s;
	if(s=="Sunny")
	cout<<"Cloudy"<<endl;
	else if(s=="Cloudy")
	cout<<"Rainy"<<endl;
	else 
	cout<<"Sunny"<<endl;
	return 0;
}

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

int main() {
ll n;
cin>>n;
ll a[n],i,b[n],c[n];
for(i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];
ll dp[n][3];

dp[0][0]=a[0];dp[0][1]=b[0];dp[0][2]=c[0];
for(i=1;i<n;i++)
{
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
    dp[i][1]=max(dp[i-1][2],dp[i-1][0])+b[i];
    dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c[i];
}
ll ans=max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
cout<<ans;
	return 0;
}


Measured memory_bytes: 4992
#!/usr/bin/env python3
import sys
from collections import Counter
INF = float("inf")


def solve(N: int, A: "List[int]"):
    counter = Counter(A)
    # 作れるか
    count = 0
    cand = []
    for k in counter:
        if counter[k] >= 4:
            cand.append(k)
            cand.append(k)
        elif counter[k] >= 2:
            cand.append(k)
    if len(cand) < 2:
        print(0)
        return
    else:
        cand.sort(reverse=True)
        area = cand[0]*cand[1]
        print(area)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 24868
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int years;
		int money=100000;
		Scanner scanner = new Scanner(System.in);
		years = scanner.nextInt();
		
		for(int i=0; i<years; i++){
			money *= 1.05;
			if(money % 1000 != 0){
				money = money / 1000;
				money = money * 1000;
				money += 1000;
			}
		}
		System.out.println(money);
	}

}

Measured memory_bytes: 17156
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a, b) ((a < b) ? a : b)
#define _max(a, b) ((a < b) ? b : a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a) ? 1 : -1)
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    cout << fixed << setprecision(10);
    LLI a, b, k;
    cin >> a >> b >> k;

    cout << _max(a - k, 0) << " " << _max(b - (k - (a - _max(a - k, 0))), 0);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int a;
    while(scanf("%d",&a)!=EOF){
        int ans=a%39;
        if(ans==0){
            cout<<"3C39"<<endl;
        }else if(ans<10){
            cout<<"3C0"<<ans<<endl;
        }else{
            cout<<"3C"<<ans<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3152
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=1005;
const int INF=1e9;
int n,X[MAXN],Y[MAXN];
int bi[100],l,f[5];
void Print(int x,int y){
	for(int i=1;i<=l;i++){
		if(abs(x)>abs(y)){
			if(x<0)printf("D"),x+=bi[i];
			else printf("U"),x-=bi[i];
		}
		else{
			if(y<0)printf("L"),y+=bi[i];
			else printf("R"),y-=bi[i];
		}
	}
	puts("");
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&X[i],&Y[i]);
		f[(X[i]+Y[i])%2]=1;
	}
	if(f[0]==f[1]){
		printf("-1\n");
		return 0;
	}
	l=0;
	for(int i=30;i>=0;i--)
		bi[++l]=(1<<i);
	if(f[0])bi[++l]=1;
	printf("%d\n",l);
	for(int i=1;i<l;i++)
		printf("%d ",bi[i]);
	printf("%d\n",bi[l]);
	for(int i=1;i<=n;i++)
		Print(Y[i],X[i]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll INF = 1000000009;
ll MOD = 1000000007;

vector<ll> adj[100010];
bool visited[100010];
ll dist[100010];
ll dist2[100010];


void solve(){

    ll n;
    cin >> n;
    ll u,v;
    cin >> u >> v;
    u--;
    v--;
    rep(i,n-1){
        ll a,b;
        cin >> a >> b;
        a--;
        b--;
        adj[a].emplace_back(b);
        adj[b].emplace_back(a);
    }

    rep(i,100010){
        visited[i]=false;
        dist[i]=0;
    }

    stack<ll> st;
    st.push(v);
    visited[v]=true;
    while(!st.empty()){
        ll x = st.top();
        st.pop();
        for(auto e: adj[x]){
            if(visited[e]==true) continue;
            dist[e]=dist[x]+1;
            st.push(e);
            visited[e]=true;
        }
    }

    /*
    rep(i,n){
        cout << dist[i] << " ";
    }
    cout << endl;
    */

    rep(i,100010){
        visited[i]=false;
        dist2[i]=0;
    }

    stack<ll> st2;
    st2.push(u);
    visited[u]=true;
    while(!st2.empty()){
        ll x = st2.top();
        st2.pop();
        for(auto e: adj[x]){
            if(visited[e]==true) continue;
            dist2[e]=dist2[x]+1;
            st2.push(e);
            visited[e]=true;
        }
    }

    /*
    rep(i,n){
        cout << dist2[i] << " ";
    }
    cout << endl;
    */

    ll ans = 0;
    rep(i,n){
        if(dist[i]>dist2[i]) ans = max(ans, dist[i]-1);
    }

    if(ans!=0) cout << ans << endl;
    else cout << (dist[u])/2 << endl;

}

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


Measured memory_bytes: 8064
import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		while (true) {
			String s = sc.next();
			if (s.equals("-")) break;
			int n = sc.nextInt();
			for (int i=0; i<n; i++) {
				int pos = sc.nextInt();
				s = s.substring(pos,s.length()) + s.substring(0,pos);
			}
			System.out.println(s);
		}
		
	}
}


Measured memory_bytes: 26496
inf=10**9
n,m=map(int,input().split())
C=list(map(int,input().split()))

DP=[inf]*(n+1)
DP[0]=0
for i in range(n+1):
    for c in C:
        if 0<=i+c<=n:
            DP[i+c]=min(DP[i+c],DP[i]+1)
print(DP[n])


Measured memory_bytes: 7256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
int n,x;
int a[100005];
ll ans;
int main(void){
    cin>>n>>x;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n-1;i++){
        if(a[i]+a[i+1]>x){
            ans+=a[i+1]+a[i]-x;
            a[i+1]=max(0,x-a[i]);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	var n int
	fmt.Scan(&n)
	ans := 0
	for i := 0; i < n; i++ {
		l, _ := scanInt(scanner)
		r, _ := scanInt(scanner)
		ans += r - l + 1
	}
	fmt.Println(ans)
}

func scanInt(scanner *bufio.Scanner) (int, error) {
	scanner.Scan()
	return strconv.Atoi(scanner.Text())
}

Measured memory_bytes: 640
//D
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+10;
ll raw[maxn],cnt[maxn];
int main(){
	int n;
	cin >> n;
	for(int i = 1;i <= n;i++){
		cin >> raw[i];
		cnt[raw[i]]++;
	}
	ll ans = 0;
	for(int i = 1;i <= n;i++)ans += cnt[i]*(cnt[i]-1)/2;
	for(int i = 1;i <= n;i++){
		ll c = cnt[raw[i]];
		ll d = c*(c-1)/2,d1 = (c-1)*(c-2)/2;
		cout << ans-d+d1 << endl;
	}
	return 0;
}


Measured memory_bytes: 4736
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;

int main(){

  int n;
  cin >> n;

  int a[100001]={};
  for(int i=1;i*(i-1)<=2*100000;i++){
    a[i*(i-1)/2]=i;
  }

  if(a[n]==0)cout << "No" << endl;
  else{
    int k=a[n];
    int b[k][k-1];
    int c=0;
    for(int i=0;i<k-1;i++){
      for(int j=i;j<k-1;j++){
        c++;
        b[i][j]=c;
        b[j+1][i]=c;
      }
    }
    cout << "Yes" << endl;
    cout << k << endl;
    for(int i=0;i<k;i++){
      cout << k-1 ;
      for(int j=0;j<k-1;j++){
        cout <<" "<< b[i][j];
      }
      cout << endl;
    }

  }

}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,T;
  cin>>n>>T;
  vector<long long> t(n);
  for(int i=0;i<n;i++)cin>>t.at(i);
  long long sum=n*T;
  for(int i=0;i<n-1;i++){
    if(T+t.at(i)>=t.at(i+1)){
      sum-=T+t.at(i)-t.at(i+1);
    }
  }
  cout<<sum<<endl;
  return 0;
}
    

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> P;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
	ll cost;
};
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
ll n, k;
vl p;
/******* define variable end *******/
int solve() {
	cin >> n >> k;
	p.resize(n);
	REP(i, n){
		cin >> p[i];
	}
	sort(ALL(p));
	ll ans = 0;
	REP(i, k){
		ans += p[i];
	}
	cout << ans << endl;
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


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

    int main(){
      long n, a , b, c , d;
      string str;
      cin >> n >> a >> b >> c >> d >> str;
      a -= 1;
      b -= 1;
      c -= 1;
      d -= 1;
      
      if(c < d || c < b ){
          for(long i = a  ; i < c - 1 ; i++ ){
              if(str[i] == '#' && str[i+1] == '#'){
                  cout << "No" << endl;
                  return 0;
              }
          }
          for(long i = b  ; i < d - 1  ; i++ ){
              if(str[i] == '#' && str[i+1] == '#'){
                  cout << "No" << endl;                  
                  return 0;
              }
          }
          cout << "Yes" << endl;
          return 0;
      }
      bool ans = false;
      for(long i = a  ; i < c - 1 ; i++ ){
          if(str[i] == '#' && str[i+1] == '#'){
              cout << "No" << endl;
              return 0;
          }
          if(i >= b - 1 && i <= d - 1){
              //cout << str[i+2];
              if(str[i] == '.' && str[i+1] == '.' && str[i+2] == '.')
              ans = true;
          }
      }
      if(ans){
          cout << "Yes" << endl;
      }else{
          cout << "No" << endl;
      }
      return 0;
    }

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    ll ans = 0;
    rep(i, n) {
        ll l, r;
        cin >> l >> r;
        r++;
        ans += r - l;
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int main() {
  int x, y, z;
  cin >> x >> y >> z;
  cout << z << " " << x << " " << y << endl;
  return 0;
}

Measured memory_bytes: 3580
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vs){
  for (const T& v : vs) os << v << " ";
  return os;
}

template<typename T>
std::map<T, int> prime_factorize(T x) {
  std::map<T, int> primes;
  for (T factor = 2; factor * factor <= x; factor++) {
    if (x % factor == 0) {
      T count = 0;
      while (x % factor == 0) {
          count++;
          x /= factor;
      }
      primes[factor] = count;
    }
  }
  if (x != 1) primes[x] = 1;
  return primes;
}

int main() {
  LL N; cin >> N;
  if (N == 1) {
    cout << 0 << endl;
    return 0;
  }

  auto m = prime_factorize(N);
  LL total = 0;
  vector<pair<int, int>> ps;
  for (auto [v, c] : m) {
    int cnt = 0;
    for (int i = 1;; ++i) {
      cnt += i;
      if (cnt > c) break;
      ++total;
    }
  }
  cout << total << endl;
}


Measured memory_bytes: 3632
input = gets.chomp.split(" ").map{|i|i.to_i}

n = input[0]
x = input[1]
t = input[2]

count_x = n / x
amari_x = n % x


if amari_x == 0
  total_time = count_x * t
else
  total_time = (count_x + 1) * t
end

puts total_time

Measured memory_bytes: 14212
#include<iostream>
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m;
char r[600][600],b[600][600],a[600][600];
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i+=2)
        for(int j=1;j<=m;j++)
            r[i][j]='#';
    for(int i=2;i<=n;i+=2)
        for(int j=1;j<=m;j++)
        {
            r[i][j]='.';
        }
    for(int i=2;i<=n;i+=2)
        for(int j=1;j<=m;j++)
            b[i][j]='#';
    for(int i=1;i<=n;i+=2)
        for(int j=1;j<=m;j++)
        {
            b[i][j]='.';
        }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            char cur;
            cin>>cur;
            if(cur=='#')
            {
                r[i][j]='#';
                b[i][j]='#';
            }
        }
    }
    for(int i=1;i<=n;i++)
        r[i][1]='#',b[i][1]='.';
    for(int i=1;i<=n;i++)
        r[i][m]='.',b[i][m]='#';
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
          cout<<r[i][j];
        cout<<endl;
    }
    cout<<endl;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
          cout<<b[i][j];
        cout<<endl;
    }
    return 0;
}//eqdxewfsd

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

namespace ProblemE
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Console.ReadLine().Select(x => int.Parse(x.ToString())).ToArray();
            var N = 8;
            for (int i = 0; i < N; i++)
            {
                var res = read[0];
                string resStr = read[0].ToString();
                for (int j = 0; j < 3; j++)
                {
                    if ((i & 1 << (2 - j)) == 0)
                    {
                        res += read[j + 1];
                        resStr += "+" + read[j + 1];
                    }
                    else
                    {
                        res -= read[j + 1];
                        resStr += "-" + read[j + 1];

                    }

                }
                if(res == 7)
                {
                    Console.WriteLine(resStr + "=7");
                    break;
                }
            }
        }
    }
}


Measured memory_bytes: 28260
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H;
	while(cin>>N) {
		ll a = N/500;
		N -= a*500;
		ll b = N/5;
		ll ans = a*1000+b*5;
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 888
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N = 3e5 + 7;
int32_t main(){
    IOS;
    string s,t;
    cin >> s >> t;
    int x = s.size();
    int y = t.size();
    int ans = INT_MAX;
    for(int i=0; i<x-y+1; i++){
        int c = 0;
        for(int j = 0; j<y; j++){
            if(s[i+j] != t[j]) c++;
        }
        if(c < ans) ans = c;
    }
    cout << ans << endl;

     
    return 0;
}



Measured memory_bytes: 3676
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] ballCnt = new int[n];
        char[] color = new char[n];
        Arrays.fill(ballCnt, 1);
        Arrays.fill(color, 'w');
        color[0] = 'r';
        for(int i = 0; i < m; ++i) {
            int x = sc.nextInt() - 1;
            int y = sc.nextInt() - 1;
            if(color[y] == 'e') color[y] = color[x];
            else if(color[x] == 'r') color[y] = 'r';
            --ballCnt[x];
            ++ballCnt[y];
            if(ballCnt[x] == 0) color[x] = 'e';
        }
        
        int ans = 0;
        for(int i = 0; i < n; ++i) {
            if(color[i] == 'r') ++ans;
        }
        System.out.println(ans);
    }
}


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

int main(){
	long long n, l, r;
	cin >> n >> l >> r;
	n--;
	while(n--){
		long long t, a;
		cin >> t >> a;
		long long p = max((l + t - 1) / t, (r + a - 1) / a);
		l = t * p;
		r = a * p;
	}
	cout << l + r << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
#define ll long long
ll dp[2500][50];
ll a[50];
; int main()
{
	int n, ave;
	cin >> n >> ave;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	for (int i = 0; i < n; i++)
		for (int j = n * 50; j >= a[i]; j--)
			for (int k = 1; k <= n; k++)
				if (dp[j - a[i]][k - 1])
					dp[j][k] += dp[j - a[i]][k - 1];
	ll ans = 0;
	for (int i = 1; i <= n; i++)
		ans += dp[i * ave][i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1280
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = Math.abs(x-sc.nextInt());
        int b = Math.abs(x-sc.nextInt());
        System.out.println(a > b?'B':'A');
    } 
}

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

using namespace std;

const int maxN = 1e5;
int a[4 * maxN];

int main() {
    int n;
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 0; i < 3 * n; i++) {
        cin >> a[i];
    }
    sort(a, a + 3 * n);
    long long sum = 0;
    for (int i = n; i < 3 * n; i += 2) {
        sum += a[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <tuple>
#include <math.h>
#include <set>
#include <map>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end() 
const ll INF = 1e18 ;
const ll mod = 1e9+7 ;
const double pie = acos(-1); 
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,1,-1,0,1,1,1,0} ; 

void fix_cout(){cout << fixed << setprecision(20) ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
void chmax(ll &a,ll b){if(a<b) a = b ; }
void chmin(ll &a,ll b){if(a>b) a = b ; }

int main(){
	ll n,m,l ; 
	cin >> n >> m >> l ;
	vvll d(n,vll(n,INF)) ;
	for(int i=0;i<m;i++){
		ll a,b,c ; 
		cin >> a >> b >> c ;
		if(c>l) continue ;
		a-- ; b-- ;
		d.at(a).at(b) = d.at(b).at(a) = c ;
	}
	for(int i=0;i<n;i++) d.at(i).at(i) = 0 ;
	for(int k=0;k<n;k++){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				chmin(d.at(i).at(j),d.at(i).at(k)+d.at(k).at(j)) ;
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i==j) continue ;
			if(d.at(i).at(j)<=l) d.at(i).at(j) = 1 ;
		}
	}
	for(int k=0;k<n;k++){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				chmin(d.at(i).at(j),d.at(i).at(k)+d.at(k).at(j)) ;
			}
		}
	}
	ll q ; cin >> q ;
	while(q--){
		ll a,b ;
		cin >> a >> b ;
		a-- ; b-- ;
		cout << (d.at(a).at(b)!=INF?d.at(a).at(b)-1:-1) << endl ;
	}
}

Measured memory_bytes: 4344
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int maxn = 1000005;
const int mod = 998244353;
map<string,int>mp;
int main(){
    int n;cin >> n;
    int ans=0;
    for(int i=1;i<=n;i++) {
        string s;
        cin >> s;
        if(mp.count(s)) continue;
        ans++;
        mp[s]=1;
    }
    printf("%d\n",ans);
    return 0;
}




Measured memory_bytes: 19348
#include<stdio.h>
#include<math.h>

int main(){
  int n,i,j;
  double h,m,p,si,sum,g[1001];

  while(1){
    sum=0;
    si=0;
  scanf("%d",&n);
  
  if(n==0) break;
  
  for(i=0;i<n;i++){
    scanf("%lf",&g[i]);
    sum+=g[i];
  
    m=sum/n*1.0;
    
  }
    for(j=0;j<n;j++){
    si+=(g[j]-m)*(g[j]-m);
  }
  p=si/n;

  h=sqrt(p);
  printf("%f\n",h);
  
  }
  return 0;
}

Measured memory_bytes: 664
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String a[] = sc.next().split("");
    String b[] = sc.next().split("");
    for (int i = 0; i < b.length; i++){
      System.out.printf("%s%s", a[i], b[i]);
    }
    if (a.length > b.length){
      System.out.print(a[a.length-1]);
    }
  }
}


Measured memory_bytes: 35740
require 'prime'

n = gets.to_i
if n == 1
  puts '1'
  exit
end
M = 10 ** 9 + 7
h = Hash.new(0)
(1..n).to_a.each do |i|
  Prime.prime_division(i).each do |k, v|
    h[k] += v
  end
end
puts h.values.map{|i| (i + 1)}.inject{|u, v| u * v % M}

Measured memory_bytes: 2300
#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
const int MAXN = 1e5 + 7;
int tim = 1;
int prenum[MAXN], p[MAXN], lowest[MAXN];
vector <int> G[MAXN];
set <int> ans;
void dfs(int cur) {
	prenum[cur] = tim;
	lowest[cur] = tim;
	tim++;
	for (int i = 0; i < G[cur].size(); i++) {
		if (prenum[G[cur][i]] == 0) {
			p[G[cur][i]] = cur;
			dfs(G[cur][i]);
			lowest[cur] = min(lowest[cur], lowest[G[cur][i]]);
		}
		else if (G[cur][i] != p[cur]) lowest[cur] = min(lowest[cur], prenum[G[cur][i]]);
	}
}
int main() {
    int v, e;
    scanf("%d%d", &v, &e);
    while (e--) {
    	int s, t;
    	scanf("%d%d", &s, &t);
    	G[s].push_back(t);
    	G[t].push_back(s);
	}
	dfs(0);
	int cnt = 0;
	for (int i = 1; i < v; i++) {
		if (p[i] == 0) cnt++;
		else if (prenum[p[i]] <= lowest[i]) ans.insert(p[i]);
	}
	if (cnt > 1) ans.insert(0);
	for (set <int> :: iterator i = ans.begin(); i != ans.end(); ++i) {
		printf("%d\n", *i);
	}
	return 0;
}


Measured memory_bytes: 6432
#!/usr/bin/python3
# -*- coding: utf-8 -*-

if __name__ == "__main__":
    n = int(input())
    a = map(int, input().split())
    cnt = [0 for i in range(0, int(1e5 + 5))]
    for x in a:
        cnt[x] += 1
        cnt[x + 1] += 1
        if x > 0:
            cnt[x - 1] += 1
    print(max(cnt))


Measured memory_bytes: 10764
import sys

a = int(input())

b = [sys.maxsize for i in range(a)]

c = list(map(int,input().split()))
b[0] = 0
b[1] = abs(c[0]-c[1])
for i in range(2,a):
	ma = min(b[i],b[i-1] + abs(c[i]-c[i-1]),b[i-2] + abs(c[i]-c[i-2]))
	b[i] = ma
print(b[-1])

Measured memory_bytes: 15032
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9

int main(){
	int n;
	while(cin>>n,n){
		vector<set<int>> sch(30),p(n);
		rep(i,n){
		    int t; cin>>t;
		    rep(j,t){
		        int p; cin>>p;
		        sch[p-1].insert(i);
		    }
		}
		rep(i,30){
		    set<int> t=sch[i],ans;
		    for(auto j:sch[i]){
		        set_union(all(t),all(p[j]),inserter(ans,ans.begin()));
		        t.swap(ans);
		    }
		    for(auto j:sch[i]){
		        p[j]=t;
		    }
		    if(t.size()==n){
		        cout<<i+1<<endl;
		        goto end;
		    }
		}
		cout<<-1<<endl;
		end:;
	}
	return 0;
}

Measured memory_bytes: 3260
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <climits>

using namespace std;

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

typedef long long LL;
typedef vector<int> VI;

void dfs2(int prev, int cursum, vector<vector<int>> &tree,
          vector<int> &sums, vector<int> &ans, vector<bool> &visited) {
  for (auto v : tree[prev]) {
    if (!visited[v]) {
      ans[v] += cursum;
      visited[v] = true;
      dfs2(v, cursum+sums[v], tree, sums, ans, visited);
    }
  }
}

int main() {
  int N, Q;
  cin >> N >> Q;
  vector<vector<int>> tree(N);
  int a, b;
  for (int i = 0; i < N-1; i++) {
    cin >> a >> b;
    a--;
    b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  vector<int> p(Q);
  vector<int> x(Q);
  for (int i = 0; i < Q; i++) {
    cin >> p[i] >> x[i];
    p[i]--;
  }
  vector<bool> visited(N);
  visited[0] = true;
  vector<int> sums(N);
  for (int i = 0; i < Q; i++) {
    sums[p[i]] += x[i];
  }
  vector<int> ans(N);
  for (int i = 0; i < N; i++) {
    ans[i] = sums[i];
  }
  dfs2(0, sums[0], tree, sums, ans, visited);
  for (auto a : ans) {
    cout << a << endl;
  }
  return 0;
}


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

using namespace std;
int a[100010];
int b[100010];
int main()
{
   int n;
   cin>>n;
   for(int i=0;i<n;i++){
    cin>>a[i];
   }
b[0]=0;
b[1]=abs(a[0]-a[1]);
for(int i=2;i<n;i++){
    int l=abs(a[i]-a[i-1])+b[i-1];
    int r=abs(a[i]-a[i-2])+b[i-2];
    b[i]=min(l,r);
}
cout<<b[n-1];

    return 0;
}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}

void solve()
{
	int n;
	cin >> n;
	int a[n];
	int sum = 0;
	rep(i, n) cin >> a[i], sum += a[i];
	int asum = sum / n;
	int bsum = (sum + n - 1) / n;
	int res = 0;
	int sres = 0;
	rep(i, n) res += (a[i] - asum) * (a[i] - asum), sres += (a[i] - bsum) *(a[i] - bsum);
	cout << min(res, sres);
}


 
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}

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

using namespace std;

using ll = long long;

const int N = 3e3 + 5, INF = 1e9 + 5;

int dp[N][N];
string lcs(string a, string b){
	int n = a.size(), m = b.size();
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(a[i - 1] == b[j - 1])	dp[i][j] = dp[i - 1][j - 1] + 1;
			else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		}
	}
	int i = n, j = m;
	string ans;
	while(i > 0 && j > 0){
		if(a[i - 1] == b[j - 1]){
			ans += a[i - 1];
			i--, j--;
		}
		else if(dp[i - 1][j] > dp[i][j - 1])
			i--;
		else 
			j--;
	}
	reverse(ans.begin(), ans.end());
	return ans;
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie();
	string a, b;	cin >> a >> b;
	cout << lcs(a, b) << "\n";

}


Measured memory_bytes: 38856
#include<bits/stdc++.h>
using namespace std;
int fx[]={1,-1,0,0},fy[]={0,0,1,-1};
struct node{
	int x,y;
};
int n,m,ans=0;
int d[25][25];
char p[25][25];
bool vis[25][25];
queue<node> q;
int main(){
	memset(p,0x3f,sizeof(p));
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%s",p[i]+1);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(p[i][j]=='#')continue;
			memset(d,0,sizeof(d));
			memset(vis,0,sizeof(vis));
			q.push((node){i,j});
			vis[i][j]=1;
			while(!q.empty()){
				node no=q.front();
				q.pop();
				for(int k=0;k<4;k++){
					int xx=no.x+fx[k],yy=no.y+fy[k];
					if(xx<=n && yy<=m && xx>0 && yy>0 && p[xx][yy]=='.' && !vis[xx][yy]){
						vis[xx][yy]=1;
						d[xx][yy]=d[no.x][no.y]+1;
						ans=max(d[xx][yy],ans);
						q.push((node){xx,yy});
					}
				}
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;

int main(){
  string s;cin >> s;
  string a;
  string b;
  int ans = 0;
  bool flag = false;
  do{
    s.pop_back();
    if(!(s.size()&1)){
      a = s.substr(0,s.size()/2);
      b = s.substr(s.size()/2,s.size()/2);
      if(a==b){
        flag = true;
        ans = a.size()*2;
      }
    }
  }while(!flag);
  cout << ans << endl;
}


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

int main()
{
    int n;
    std::cin>>n;
    std::map<int,int> mapo,mape;
    for(int i=0;i<n;i++){
        int tmp;
        std::cin>>tmp;
        if(i%2==0)mapo[tmp]++;
        else mape[tmp]++;
    }
    int mo1=0,mo2=0,me1=0,me2=0;
    int numo,nume;
    for(auto x:mapo){
        if(x.second>mo2)mo2=x.second;//二番目の値を更新
        if(mo1<mo2){
            std::swap(mo1,mo2);
            numo = x.first;
        }
    }
    for(auto x:mape){
        if(x.second>me2){
            me2 = x.second;
        }
        if(me2>me1){
            std::swap(me1,me2);
            nume =x.first;
        }
    }
    if(nume!=numo)std::cout<<n-mo1-me1<<std::endl;
    else std::cout<<std::min(n-mo1-me2,n-mo2-me1)<<std::endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
//Author: Ezio Sam
/* Shorthands */
#define ll long long
#define pb push_back 
#define mp make_pair
#define sp " "
#define cs "Case "
#define fi first
#define sn second 
#define po(x) x*x
/* STL */
#define vi vector<int>v
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mem(a,n) memset(a, n, sizeof(a));
#define all(x) x.begin(),x.end()
#define sz(x)  (int)x.size()
#define mx(v)  *max_element(v.begin(),v.end())
#define mxa(a) *max_element(a, a.size())
#define r(a) reverse(a.begin(),a.end())
/* loops */
#define fr(i,n)   for(__typeof(n) i=0;i<(n);i++)
#define fn(i,n)   for(__typeof(n)i=1;i<=(n);i++)
#define fa(i,a,n) for(__typeof(a)i=(a);i<=(b);i++)
/*Special*/
#define Ezio ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define db(something)   cerr<<#something<<" - "<<something<<"\n";         
int main()
{
  
   Ezio
   /*Variables*/
   /*Code*/
     ll a,b,c,d(0);
   cin>>a>>b>>c;
   swap(d,c);
   swap(a,b);
   swap(a,c);
   swap(a,d);
   
   cout<<a<<sp<<b<<sp<<c<<endl;
   return 0;
}
    

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int main()
{
    string a;
    string s;
    cin >> a;
    for(int i = 0;i <= 19; i++){
        if(i == 5 || i == 13){
        a[i] = ' ';
    }
    }
    s = a;
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>

using namespace std;

const int NMAX = 3000 + 5;
const int MMAX = 3000 + 5;
const int MOD = 1000000000 + 7;

int dp[2][2 * NMAX][2];

void upd(int &where, int val) {
    where += val;
    if (where >= MOD)
        where -= MOD;
}

int main()
{
    int N, M;
    cin >> N >> M;

    M *= 2;
    int L = 2 * N + 1;

    for (int i = 1; i <= L; i += 2)
        dp[0][i][i <= 2] = 1;
    for (int i = 0; i < M; ++ i) {
        memset(dp[(i + 1) & 1], 0, sizeof(dp[0]));
        for (int j = 1; j <= L; ++ j) {
            upd(dp[(i + 1) & 1][j - 1][(j - 1 <= 2)], dp[i & 1][j][0]);
            upd(dp[(i + 1) & 1][j + 1][0], dp[i & 1][j][0]);
            upd(dp[(i + 1) & 1][j - 1][1], dp[i & 1][j][1]);
            upd(dp[(i + 1) & 1][j + 1][1], dp[i & 1][j][1]);
        }
    }

    int ans = 0;
    for (int i = 1; i <= L; ++ i)
        upd(ans, dp[M & 1][i][1]);
    cout << ans << '\n';
    return 0;
}


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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;

int main() {
  int n;
  cin >> n;
  set<int> S;
  rep(i,n){
    int d;
    cin >> d;
    S.insert(d);
  }
  cout << S.size() << endl;
} 

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

main(){

  ll n;
  cin>>n;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];

  ll ans=0,cnt=0;
  rep(i,n-1){
    if(a[i]>=a[i+1])cnt++;
    else{
      ans=max(ans,cnt);
      cnt=0;
    }
  }
  ans=max(ans,cnt);
  cout<<(ans)<<endl;

}

Measured memory_bytes: 1024